Bug 709531 - Addons Manager tests should have AMO-related prefs reset after each test to disallow network access. r=dtownsend a=mbrubeck
authorBlair McBride <bmcbride@mozilla.com>
Thu, 15 Dec 2011 14:00:19 +1300
changeset 84245 243ff1422033a5cac674f83c4bdd7718692f1d7a
parent 84244 3404df37a347ce0eea40d1b161ec71e3b564214d
child 84246 0afa7a488c75ead57a4fdb79ade397b06da1a2d5
child 84643 e8ff5ef91e3167b00217e8d718ead45a87aea53c
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdtownsend, mbrubeck
bugs709531
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 709531 - Addons Manager tests should have AMO-related prefs reset after each test to disallow network access. r=dtownsend a=mbrubeck
browser/base/content/test/Makefile.in
build/automation.py.in
toolkit/mozapps/extensions/test/Makefile.in
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/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -127,16 +127,17 @@ endif
                  browser_bug495058.js \
                  browser_bug517902.js \
                  browser_bug519216.js \
                  browser_bug520538.js \
                  browser_bug521216.js \
                  browser_bug533232.js \
                  browser_bug537474.js \
                  browser_bug550565.js \
+                 browser_bug553455.js \
                  browser_bug555224.js \
                  browser_bug555767.js \
                  browser_bug556061.js \
                  browser_bug559991.js \
                  browser_bug561623.js \
                  browser_bug561636.js \
                  browser_bug562649.js \
                  browser_bug563588.js \
@@ -150,16 +151,17 @@ endif
                  browser_bug580638.js \
                  browser_bug580956.js \
                  browser_bug581242.js \
                  browser_bug581253.js \
                  browser_bug581947.js \
                  browser_bug585785.js \
                  browser_bug585830.js \
                  browser_bug590206.js \
+                 browser_bug592338.js \
                  browser_bug594131.js \
                  browser_bug595507.js \
                  browser_bug596687.js \
                  browser_bug597218.js \
                  browser_bug598923.js \
                  browser_bug599325.js \
                  browser_bug609700.js \
                  browser_bug616836.js \
--- a/build/automation.py.in
+++ b/build/automation.py.in
@@ -393,16 +393,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/toolkit/mozapps/extensions/test/Makefile.in
+++ b/toolkit/mozapps/extensions/test/Makefile.in
@@ -46,16 +46,18 @@ TESTROOT = $(CURDIR)/$(DEPTH)/_tests/xpc
 TESTXPI = $(TESTROOT)/xpcshell/addons
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE = test_extensionmanager
 
 ifneq (mobile,$(MOZ_BUILD_APP))
  DIRS +=  \
+    xpinstall \
+    browser \
     mochitest \
     $(NULL)
 endif
 
 XPCSHELL_TESTS = \
   xpcshell \
   xpcshell-unpack \
   $(NULL)
--- 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();