Bug 997188 - Handle the experiments.manifest.uri pref correctly so so that it don't ping out to telemetry-experiments.cdn.mozilla.net by default or enable experiment code in the tests. This should also fix bug 994686. r=irving/gfritzsche
authorBenjamin Smedberg <benjamin@smedbergs.us>
Thu, 17 Apr 2014 11:08:35 -0400
changeset 179760 122a4087016c9481e7ac5ebd0e5fa4222a32f878
parent 179759 a5a009436c2d4cbf46f38e49505d7db687c26356
child 179761 9c542915cc4c075b2e7e02d249c4b2e48c1c7413
child 179781 1e27e759fa2c34128a1fc75e1d2f3d4e3bcd215b
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersirving, gfritzsche
bugs997188, 994686
milestone31.0a1
Bug 997188 - Handle the experiments.manifest.uri pref correctly so so that it don't ping out to telemetry-experiments.cdn.mozilla.net by default or enable experiment code in the tests. This should also fix bug 994686. r=irving/gfritzsche
testing/profiles/prefs_general.js
toolkit/mozapps/extensions/test/browser/browser_experiments.js
--- a/testing/profiles/prefs_general.js
+++ b/testing/profiles/prefs_general.js
@@ -46,18 +46,17 @@ user_pref("dom.undo_manager.enabled", tr
 user_pref("dom.webcomponents.enabled", true);
 // Set a future policy version to avoid the telemetry prompt.
 user_pref("toolkit.telemetry.prompted", 999);
 user_pref("toolkit.telemetry.notifiedOptOut", 999);
 // Existing tests assume there is no font size inflation.
 user_pref("font.size.inflation.emPerLine", 0);
 user_pref("font.size.inflation.minTwips", 0);
 
-// AddonManager tests require that the experiments feature be enabled.
-user_pref("experiments.enabled", true);
+// AddonManager tests require that the experiments provider be present.
 user_pref("experiments.supported", true);
 user_pref("experiments.logging.level", "Trace");
 // Point the manifest at something local so we don't risk it hitting production
 // data and installing experiments that may vary over time.
 user_pref("experiments.manifest.uri", "http://%(server)s/experiments-dummy/manifest");
 
 // Only load extensions from the application and user profile
 // AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION
--- a/toolkit/mozapps/extensions/test/browser/browser_experiments.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_experiments.js
@@ -5,31 +5,41 @@
 let {AddonTestUtils} = Components.utils.import("resource://testing-common/AddonManagerTesting.jsm", {});
 let {HttpServer} = Components.utils.import("resource://testing-common/httpd.js", {});
 
 let gManagerWindow;
 let gCategoryUtilities;
 let gExperiments;
 let gHttpServer;
 
+let gSavedManifestURI;
+
 function getExperimentAddons() {
   let deferred = Promise.defer();
   AddonManager.getAddonsByTypes(["experiment"], (addons) => {
     deferred.resolve(addons);
   });
   return deferred.promise;
 }
 
 add_task(function* initializeState() {
   gManagerWindow = yield open_manager();
   gCategoryUtilities = new CategoryUtilities(gManagerWindow);
 
   registerCleanupFunction(() => {
+    Services.prefs.clearUserPref("experiments.enabled");
     if (gHttpServer) {
       gHttpServer.stop(() => {});
+      Services.prefs.clearUserPref("experiments.manifest.cert.checkAttributes");
+      if (gSavedManifestURI !== undefined) {
+        Services.prefs.setCharPref("experments.manifest.uri", gSavedManifestURI);
+      }
+    }
+    if (gExperiments) {
+      gExperiments._policy.ignoreHashes = false;
     }
   });
 
   // The Experiments Manager will interfere with us by preventing installs
   // of experiments it doesn't know about. We remove it from the equation
   // because here we are only concerned with core Addon Manager operation,
   // not the superset Experiments Manager has imposed.
   if ("@mozilla.org/browser/experiments-service;1" in Components.classes) {
@@ -162,34 +172,16 @@ add_task(function* testButtonPresence() 
 // Remove the add-on we've been testing with.
 add_task(function* testCleanup() {
   yield AddonTestUtils.uninstallAddonByID("test-experiment1@experiments.mozilla.org");
   // Verify some conditions, just in case.
   let addons = yield getExperimentAddons();
   Assert.equal(addons.length, 0, "No experiment add-ons are installed.");
 });
 
-// We need to initialize the experiments service for the following tests.
-add_task(function* initializeExperiments() {
-  if (!gExperiments) {
-    return;
-  }
-
-  // We need to remove the cache file to help ensure consistent state.
-  yield OS.File.remove(gExperiments._cacheFilePath);
-
-  info("Initializing experiments service.");
-  yield gExperiments.init();
-  info("Experiments service finished first run.");
-
-  // Check conditions, just to be sure.
-  let experiments = yield gExperiments.getExperiments();
-  Assert.equal(experiments.length, 0, "No experiments known to the service.");
-});
-
 // The following tests should ideally live in browser/experiments/. However,
 // they rely on some of the helper functions from head.js, which can't easily
 // be consumed from other directories. So, they live here.
 
 add_task(function* testActivateExperiment() {
   if (!gExperiments) {
     info("Skipping experiments test because that feature isn't available.");
     return;
@@ -215,25 +207,34 @@ add_task(function* testActivateExperimen
         },
       ],
     }));
     response.processAsync();
     response.finish();
   });
 
   Services.prefs.setBoolPref("experiments.manifest.cert.checkAttributes", false);
+  gSavedManifestURI = Services.prefs.getCharPref("experiments.manifest.uri");
   Services.prefs.setCharPref("experiments.manifest.uri", root + "manifest");
-  registerCleanupFunction(() => {
-    Services.prefs.clearUserPref("experiments.manifest.cert.checkAttributes");
-    Services.prefs.clearUserPref("experiments.manifest.uri");
-  });
+
+  // We need to remove the cache file to help ensure consistent state.
+  yield OS.File.remove(gExperiments._cacheFilePath);
+
+  Services.prefs.setBoolPref("experiments.enabled", true);
+
+  info("Initializing experiments service.");
+  yield gExperiments.init();
+  info("Experiments service finished first run.");
+
+  // Check conditions, just to be sure.
+  let experiments = yield gExperiments.getExperiments();
+  Assert.equal(experiments.length, 0, "No experiments known to the service.");
 
   // This makes testing easier.
   gExperiments._policy.ignoreHashes = true;
-  registerCleanupFunction(() => { gExperiments._policy.ignoreHashes = false; });
 
   info("Manually updating experiments manifest.");
   yield gExperiments.updateManifest();
   info("Experiments update complete.");
 
   let deferred = Promise.defer();
   gHttpServer.stop(() => {
     gHttpServer = null;
@@ -264,16 +265,20 @@ add_task(function testDeactivateExperime
     "experiments": [],
   });
 
   yield gExperiments.disableExperiment("testing");
 });
 
 add_task(function* testCleanup() {
   if (gExperiments) {
+    Services.prefs.clearUserPref("experiments.enabled");
+    Services.prefs.clearUserPref("experiments.manifest.cert.checkAttributes");
+    Services.prefs.setCharPref("experiments.manifest.uri", gSavedManifestURI);
+
     // We perform the uninit/init cycle to purge any leftover state.
     yield OS.File.remove(gExperiments._cacheFilePath);
     yield gExperiments.uninit();
     yield gExperiments.init();
   }
 
   // Check post-conditions.
   let addons = yield getExperimentAddons();