Bug 709531 - Addons Manager tests should have AMO-related prefs reset after each test to disallow network access. r=dtownsend,mfinkle a=akeybl
authorBlair McBride <bmcbride@mozilla.com>
Thu, 15 Dec 2011 14:00:19 +1300
changeset 81500 a7ca1d99832bd83eeba04740e86d1b6aea772b54
parent 81499 f13033788e0507ab8eb22b9f80fc2d1c17eae11e
child 81501 e9a9f792723a5aeba3ed51a96c77ba90bd13ef1f
push id434
push userclegnitto@mozilla.com
push dateWed, 21 Dec 2011 12:10:54 +0000
treeherdermozilla-beta@bddb6ed8dd47 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdtownsend, mfinkle, akeybl
bugs709531
milestone10.0a2
Bug 709531 - Addons Manager tests should have AMO-related prefs reset after each test to disallow network access. r=dtownsend,mfinkle a=akeybl
build/automation.py.in
mobile/chrome/tests/browser_addons.js
toolkit/mozapps/extensions/test/browser/browser_bug557956.js
toolkit/mozapps/extensions/test/browser/browser_bug581076.js
toolkit/mozapps/extensions/test/browser/browser_bug591465.js
toolkit/mozapps/extensions/test/browser/browser_discovery.js
toolkit/mozapps/extensions/test/browser/browser_eula.js
toolkit/mozapps/extensions/test/browser/browser_install.js
toolkit/mozapps/extensions/test/browser/browser_select_compatoverrides.js
toolkit/mozapps/extensions/test/browser/head.js
--- a/build/automation.py.in
+++ b/build/automation.py.in
@@ -452,16 +452,21 @@ user_pref("urlclassifier.updateinterval"
 user_pref("browser.safebrowsing.provider.0.gethashURL", "http://%(server)s/safebrowsing-dummy/gethash");
 user_pref("browser.safebrowsing.provider.0.keyURL", "http://%(server)s/safebrowsing-dummy/newkey");
 user_pref("browser.safebrowsing.provider.0.updateURL", "http://%(server)s/safebrowsing-dummy/update");
 // Point update checks to the local testing server for fast failures
 user_pref("extensions.update.url", "http://%(server)s/extensions-dummy/updateURL");
 user_pref("extensions.blocklist.url", "http://%(server)s/extensions-dummy/blocklistURL");
 // Make sure opening about:addons won't hit the network
 user_pref("extensions.webservice.discoverURL", "http://%(server)s/extensions-dummy/discoveryURL");
+// Make sure AddonRepository won't hit the network
+user_pref("extensions.getAddons.maxResults", 0);
+user_pref("extensions.getAddons.get.url", "http://%(server)s/extensions-dummy/repositoryGetURL");
+user_pref("extensions.getAddons.search.browseURL", "http://%(server)s/extensions-dummy/repositoryBrowseURL");
+user_pref("extensions.getAddons.search.url", "http://%(server)s/extensions-dummy/repositorySearchURL");
 """ % { "server" : self.webServer + ":" + str(self.httpPort) }
     prefs.append(part)
 
     if useServerLocations == False:
       part = """
 user_pref("capability.principal.codebase.p1.granted",
           "UniversalXPConnect UniversalBrowserRead UniversalBrowserWrite \
            UniversalPreferencesRead UniversalPreferencesWrite \
--- a/mobile/chrome/tests/browser_addons.js
+++ b/mobile/chrome/tests/browser_addons.js
@@ -75,28 +75,30 @@ function test() {
   requestLongerTimeout(2);
   Services.prefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED,      TESTROOT + "browser_install.xml");
   Services.prefs.setCharPref(PREF_GETADDONS_BROWSERECOMMENDED,   TESTROOT + "browser_install.xml");
   Services.prefs.setCharPref(PREF_GETADDONS_BROWSESEARCHRESULTS, TESTROOT + "browser_install.xml");
   Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS,    TESTROOT + "browser_install.xml");
   Services.prefs.setCharPref(PREF_GETADDONS_UPDATE,              TESTROOT + "browser_upgrade.rdf");
   Services.prefs.setBoolPref(PREF_ADDONS_SECURITY, false);
   Services.prefs.setBoolPref(PREF_ADDONS_LOGGING, true);
+  Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15);
   run_next_test();
 }
 
 function end_test() {
   close_manager();
   Services.prefs.clearUserPref(PREF_GETADDONS_GETRECOMMENDED);
   Services.prefs.clearUserPref(PREF_GETADDONS_BROWSERECOMMENDED);
   Services.prefs.clearUserPref(PREF_GETADDONS_BROWSESEARCHRESULTS);
   Services.prefs.clearUserPref(PREF_GETADDONS_GETSEARCHRESULTS);
   Services.prefs.clearUserPref(PREF_GETADDONS_UPDATE);
   Services.prefs.clearUserPref(PREF_ADDONS_SECURITY);
   Services.prefs.clearUserPref(PREF_ADDONS_LOGGING);
+  Services.prefs.clearUserPref(PREF_SEARCH_MAXRESULTS);
 }
 
 registerCleanupFunction(end_test);
 
 function add_test(test) {
   gPendingTests.push(test);
 }
 
--- a/toolkit/mozapps/extensions/test/browser/browser_bug557956.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug557956.js
@@ -2,17 +2,16 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Test that the compatibility dialog that normally displays during startup
 // appears to work correctly.
 
 const URI_EXTENSION_UPDATE_DIALOG = "chrome://mozapps/content/extensions/update.xul";
 
-const PREF_GETADDONS_CACHE_ENABLED    = "extensions.getAddons.cache.enabled";
 const PREF_GETADDONS_BYIDS            = "extensions.getAddons.get.url";
 const PREF_MIN_PLATFORM_COMPAT        = "extensions.minCompatiblePlatformVersion";
 
 Services.prefs.setBoolPref(PREF_STRICT_COMPAT, true);
 
 /**
  * Test add-ons:
  *
@@ -30,20 +29,16 @@ Services.prefs.setBoolPref(PREF_STRICT_C
 
 function test() {
   requestLongerTimeout(2);
   waitForExplicitFinish();
 
   run_next_test();
 }
 
-registerCleanupFunction(function() {
-  Services.prefs.clearUserPref(PREF_GETADDONS_CACHE_ENABLED);
-});
-
 function end_test() {
   // Test generates a lot of available installs so just cancel them all
   AddonManager.getAllInstalls(function(aInstalls) {
     aInstalls.forEach(function(aInstall) {
       aInstall.cancel();
     });
 
     finish();
--- a/toolkit/mozapps/extensions/test/browser/browser_bug581076.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug581076.js
@@ -22,18 +22,16 @@ function test() {
 
   open_manager("addons://list/extension", function(aWindow) {
     gManagerWindow = aWindow;
     run_next_test();
   });
 }
 
 function end_test() {
-  Services.prefs.clearUserPref(PREF_GETADDONS_GETSEARCHRESULTS);
-
   // Test generates a lot of available installs so just cancel them all
   AddonManager.getAllInstalls(function(aInstalls) {
     aInstalls.forEach(function(aInstall) {
       aInstall.cancel();
     });
 
     close_manager(gManagerWindow, finish);
   });
--- a/toolkit/mozapps/extensions/test/browser/browser_bug591465.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug591465.js
@@ -68,17 +68,16 @@ function test() {
     gManagerWindow = aWindow;
     gContextMenu = aWindow.document.getElementById("addonitem-popup");
     run_next_test();
   });
 }
 
 
 function end_test() {
-  Services.prefs.clearUserPref(PREF_GETADDONS_GETSEARCHRESULTS);
   close_manager(gManagerWindow, finish);
 }
 
 
 function check_contextmenu(aIsTheme, aIsEnabled, aIsRemote, aIsDetails, aIsSingleItemCase) {
   if (aIsTheme || aIsEnabled || aIsRemote)
     is_element_hidden(gManagerWindow.document.getElementById("menuitem_enableItem"),
                        "'Enable' should be hidden");
--- a/toolkit/mozapps/extensions/test/browser/browser_discovery.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_discovery.js
@@ -1,15 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Tests that the discovery view loads properly
 
-const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled";
 const MAIN_URL = "https://example.com/" + RELATIVE_DIR + "discovery.html";
 
 var gManagerWindow;
 var gCategoryUtilities;
 var gProvider;
 
 var gLoadCompleteCallback = null;
 
@@ -35,20 +34,16 @@ var gProgressListener = {
 };
 
 function test() {
   // Switch to a known url
   Services.prefs.setCharPref(PREF_DISCOVERURL, MAIN_URL);
   // Temporarily enable caching
   Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true);
 
-  registerCleanupFunction(function() {
-    Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, false);
-  });
-
   waitForExplicitFinish();
 
   gProvider = new MockProvider();
 
   gProvider.createAddons([{
     id: "addon1@tests.mozilla.org",
     name: "Test add-on 1",
     type: "extension",
--- a/toolkit/mozapps/extensions/test/browser/browser_eula.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_eula.js
@@ -21,21 +21,17 @@ function test() {
   open_manager(null, function(aWindow) {
     gManagerWindow = aWindow;
     gCategoryUtilities = new CategoryUtilities(gManagerWindow);
     run_next_test();
   });
 }
 
 function end_test() {
-  close_manager(gManagerWindow, function() {
-    Services.prefs.clearUserPref("extensions.getAddons.search.url");
-
-    finish();
-  });
+  close_manager(gManagerWindow, finish);
 }
 
 function get_node(parent, anonid) {
   return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid);
 }
 
 function installSearchResult(aCallback) {
   var searchBox = gManagerWindow.document.getElementById("header-search");
--- a/toolkit/mozapps/extensions/test/browser/browser_install.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_install.js
@@ -24,17 +24,16 @@ function test() {
     gManagerWindow = aWindow;
     gCategoryUtilities = new CategoryUtilities(gManagerWindow);
     run_next_test();
   });
 }
 
 function end_test() {
   close_manager(gManagerWindow, function() {
-    Services.prefs.clearUserPref("extensions.getAddons.search.url");
     Services.prefs.clearUserPref("extensions.checkUpdateSecurity");
 
     AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
       aAddon.uninstall();
       finish();
     });
   });
 }
--- a/toolkit/mozapps/extensions/test/browser/browser_select_compatoverrides.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_select_compatoverrides.js
@@ -1,16 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Tests that compatibility overrides are refreshed when showing the addon
 // selection UI.
 
-const PREF_GETADDONS_CACHE_ENABLED    = "extensions.getAddons.cache.enabled";
 const PREF_GETADDONS_BYIDS            = "extensions.getAddons.get.url";
 const PREF_MIN_PLATFORM_COMPAT        = "extensions.minCompatiblePlatformVersion";
 
 var gTestAddon = null;
 
 function waitForView(aView, aCallback) {
   var view = gWin.document.getElementById(aView);
   if (view.parentNode.selectedPanel == view) {
@@ -40,18 +39,16 @@ function install_test_addon(aCallback) {
 }
 
 registerCleanupFunction(function() {
   if (gWin)
     gWin.close();
   if (gTestAddon)
     gTestAddon.uninstall();
 
-  Services.prefs.clearUserPref(PREF_GETADDONS_CACHE_ENABLED);
-  Services.prefs.clearUserPref(PREF_GETADDONS_BYIDS);
   Services.prefs.clearUserPref(PREF_MIN_PLATFORM_COMPAT);
 });
 
 function end_test() {
   finish();
 }
 
 
--- a/toolkit/mozapps/extensions/test/browser/head.js
+++ b/toolkit/mozapps/extensions/test/browser/head.js
@@ -16,47 +16,69 @@ pathParts.push("browser");
 
 const RELATIVE_DIR = pathParts.slice(4).join("/") + "/";
 
 const TESTROOT = "http://example.com/" + RELATIVE_DIR;
 const TESTROOT2 = "http://example.org/" + RELATIVE_DIR;
 const CHROMEROOT = pathParts.join("/") + "/";
 const PREF_DISCOVERURL = "extensions.webservice.discoverURL";
 const PREF_UPDATEURL = "extensions.update.url";
+const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled";
 
 const MANAGER_URI = "about:addons";
 const INSTALL_URI = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
 const PREF_LOGGING_ENABLED = "extensions.logging.enabled";
 const PREF_SEARCH_MAXRESULTS = "extensions.getAddons.maxResults";
 const PREF_STRICT_COMPAT = "extensions.strictCompatibility";
 
 var gPendingTests = [];
 var gTestsRun = 0;
 var gTestStart = null;
 
 var gUseInContentUI = !gTestInWindow && ("switchToTabHavingURI" in window);
 
-var gDiscoveryURL = Services.prefs.getCharPref(PREF_DISCOVERURL);
-var gUpdateURL = Services.prefs.getCharPref(PREF_UPDATEURL);
+var gRestorePrefs = [{name: PREF_LOGGING_ENABLED},
+                     {name: "extensions.webservice.discoverURL"},
+                     {name: "extensions.update.url"},
+                     {name: "extensions.getAddons.get.url"},
+                     {name: "extensions.getAddons.search.browseURL"},
+                     {name: "extensions.getAddons.search.url"},
+                     {name: "extensions.getAddons.cache.enabled"},
+                     {name: PREF_SEARCH_MAXRESULTS},
+                     {name: PREF_STRICT_COMPAT}];
+
+gRestorePrefs.forEach(function(aPref) {
+  if (!Services.prefs.prefHasUserValue(aPref.name)) {
+    aPref.type = "clear";
+    return;
+  }
+  aPref.type = Services.prefs.getPrefType(aPref.name);
+  if (aPref.type == Services.prefs.PREF_BOOL)
+    aPref.value = Services.prefs.getBoolPref(aPref.name);
+  else if (aPref.type == Services.prefs.PREF_INT)
+    aPref.value = Services.prefs.getIntPref(aPref.name);
+  else if (aPref.type == Services.prefs.PREF_STRING)
+    aPref.value = Services.prefs.getCharPref(aPref.name);
+});
 
 // Turn logging on for all tests
 Services.prefs.setBoolPref(PREF_LOGGING_ENABLED, true);
-// Turn off remote results in searches
-Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 0);
+
 registerCleanupFunction(function() {
-  Services.prefs.clearUserPref(PREF_LOGGING_ENABLED);
-  try {
-    Services.prefs.clearUserPref(PREF_SEARCH_MAXRESULTS);
-  } catch (e) {}
-  try {
-    Services.prefs.clearUserPref(PREF_STRICT_COMPAT);
-  } catch (e) {}
-
-  Services.prefs.setCharPref(PREF_DISCOVERURL, gDiscoveryURL);
-  Services.prefs.setCharPref(PREF_UPDATEURL, gUpdateURL);
+  // Restore prefs
+  gRestorePrefs.forEach(function(aPref) {
+    if (aPref.type == "clear")
+      Services.prefs.clearUserPref(aPref.name);
+    else if (aPref.type == Services.prefs.PREF_BOOL)
+      Services.prefs.setBoolPref(aPref.name, aPref.value);
+    else if (aPref.type == Services.prefs.PREF_INT)
+      Services.prefs.setIntPref(aPref.name, aPref.value);
+    else if (aPref.type == Services.prefs.PREF_STRING)
+      Services.prefs.setCharPref(aPref.name, aPref.value);
+  });
 
   // Throw an error if the add-ons manager window is open anywhere
   var windows = Services.wm.getEnumerator("Addons:Manager");
   if (windows.hasMoreElements())
     ok(false, "Found unexpected add-ons manager window still open");
   while (windows.hasMoreElements())
     windows.getNext().QueryInterface(Ci.nsIDOMWindow).close();