B2G/gecko/browser/components/test/browser_bug538331.js
// Test the defaultArgs returned by nsBrowserContentHandler after an update
Test the defaultArgs returned by nsBrowserContentHandler after an update
Test the defaultArgs returned by nsBrowserContentHandler after an update
function testDefaultArgs()
{
  Cc["@mozilla.org/browser/clh;1"].getService(Ci.nsIBrowserHandler).defaultArgs;
  let originalMstone = gPrefService.getCharPref(PREF_MSTONE);
  gPrefService.setCharPref(PREF_OVERRIDE_URL, DEFAULT_PREF_URL);
  writeUpdatesToXMLFile(XML_EMPTY);
  reloadUpdateManagerData();
  for (let i = 0; i < BCH_TESTS.length; i++) {
    let test = BCH_TESTS[i];
    ok(true, "Test nsBrowserContentHandler " + (i + 1) + ": " + test.description);
    if (test.actions) {
      let actionsXML = " actions=\"" + test.actions + "\"";
      if (test.openURL) {
        actionsXML += " openURL=\"" + test.openURL + "\"";
      }
      writeUpdatesToXMLFile(XML_PREFIX + actionsXML + XML_SUFFIX);
    } else {
      writeUpdatesToXMLFile(XML_EMPTY);
    }
    reloadUpdateManagerData();
    let noOverrideArgs = Cc["@mozilla.org/browser/clh;1"].
                         getService(Ci.nsIBrowserHandler).defaultArgs;
    let overrideArgs = "";
    if (test.prefURL) {
      overrideArgs = test.prefURL;
    } else if (test.openURL) {
      overrideArgs = test.openURL;
    }
    if (overrideArgs == "" && noOverrideArgs) {
      overrideArgs = noOverrideArgs;
    } else if (noOverrideArgs) {
      overrideArgs += "|" + noOverrideArgs;
    }
    if (test.noMstoneChange === undefined) {
      gPrefService.setCharPref(PREF_MSTONE, "PreviousMilestone");
    }
    if (test.noPostUpdatePref == undefined) {
      gPrefService.setBoolPref(PREF_POSTUPDATE, true);
    }
    let defaultArgs = Cc["@mozilla.org/browser/clh;1"].
                      getService(Ci.nsIBrowserHandler).defaultArgs;
    is(defaultArgs, overrideArgs, "correct value returned by defaultArgs");
    if (test.noMstoneChange === undefined || test.noMstoneChange != true) {
      let newMstone = gPrefService.getCharPref(PREF_MSTONE);
      is(originalMstone, newMstone, "preference " + PREF_MSTONE +
         " should have been updated");
    }
    if (gPrefService.prefHasUserValue(PREF_POSTUPDATE)) {
      gPrefService.clearUserPref(PREF_POSTUPDATE);
    }
  }
  testShowNotification();
}
function testDefaultArgs ( ) { Cc [ "@mozilla.org/browser/clh;1" ] . getService ( Ci . nsIBrowserHandler ) . defaultArgs ; let originalMstone = gPrefService . getCharPref ( PREF_MSTONE ) ; gPrefService . setCharPref ( PREF_OVERRIDE_URL , DEFAULT_PREF_URL ) ; writeUpdatesToXMLFile ( XML_EMPTY ) ; reloadUpdateManagerData ( ) ; for ( let i = 0 ; i < BCH_TESTS . length ; i ++ ) { let test = BCH_TESTS [ i ] ; ok ( true , "Test nsBrowserContentHandler " + ( i + 1 ) + ": " + test . description ) ; if ( test . actions ) { let actionsXML = " actions=\"" + test . actions + "\"" ; if ( test . openURL ) { actionsXML += " openURL=\"" + test . openURL + "\"" ; } writeUpdatesToXMLFile ( XML_PREFIX + actionsXML + XML_SUFFIX ) ; } else { writeUpdatesToXMLFile ( XML_EMPTY ) ; } reloadUpdateManagerData ( ) ; let noOverrideArgs = Cc [ "@mozilla.org/browser/clh;1" ] . getService ( Ci . nsIBrowserHandler ) . defaultArgs ; let overrideArgs = "" ; if ( test . prefURL ) { overrideArgs = test . prefURL ; } else if ( test . openURL ) { overrideArgs = test . openURL ; } if ( overrideArgs == "" && noOverrideArgs ) { overrideArgs = noOverrideArgs ; } else if ( noOverrideArgs ) { overrideArgs += "|" + noOverrideArgs ; } if ( test . noMstoneChange === undefined ) { gPrefService . setCharPref ( PREF_MSTONE , "PreviousMilestone" ) ; } if ( test . noPostUpdatePref == undefined ) { gPrefService . setBoolPref ( PREF_POSTUPDATE , true ) ; } let defaultArgs = Cc [ "@mozilla.org/browser/clh;1" ] . getService ( Ci . nsIBrowserHandler ) . defaultArgs ; is ( defaultArgs , overrideArgs , "correct value returned by defaultArgs" ) ; if ( test . noMstoneChange === undefined || test . noMstoneChange != true ) { let newMstone = gPrefService . getCharPref ( PREF_MSTONE ) ; is ( originalMstone , newMstone , "preference " + PREF_MSTONE + " should have been updated" ) ; } if ( gPrefService . prefHasUserValue ( PREF_POSTUPDATE ) ) { gPrefService . clearUserPref ( PREF_POSTUPDATE ) ; } } testShowNotification ( ) ; }
Test the defaultArgs returned by nsBrowserContentHandler after an update
Test the defaultArgs returned by nsBrowserContentHandler after an update
// Clear any pre-existing override in defaultArgs that are hanging around. // This will also set the browser.startup.homepage_override.mstone preference // if it isn't already set.