Bug 1571412 - Update addon manager browser tests to use pushPrefEnv where appropriate. r=rpl
authorjayati <gaurijove@gmail.com>
Thu, 16 Apr 2020 17:38:14 +0000
changeset 524466 931f4791ca8919044752b372d2aec550d6fd6d13
parent 524465 85699ca47925d561adb983816419c12e5421d6b2
child 524467 4b37ed1b9347726da7ede3d117875b65fdd61d20
push id113204
push userapavel@mozilla.com
push dateThu, 16 Apr 2020 18:20:26 +0000
treeherderautoland@931f4791ca89 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrpl
bugs1571412
milestone77.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 1571412 - Update addon manager browser tests to use pushPrefEnv where appropriate. r=rpl Differential Revision: https://phabricator.services.mozilla.com/D70404
toolkit/mozapps/extensions/test/browser/browser_globalwarnings.js
toolkit/mozapps/extensions/test/browser/browser_history_navigation.js
toolkit/mozapps/extensions/test/browser/browser_installssl.js
toolkit/mozapps/extensions/test/browser/browser_updatessl.js
toolkit/mozapps/extensions/test/browser/browser_webapi.js
toolkit/mozapps/extensions/test/browser/browser_webapi_access.js
toolkit/mozapps/extensions/test/browser/browser_webapi_addon_listener.js
toolkit/mozapps/extensions/test/browser/browser_webapi_enable.js
toolkit/mozapps/extensions/test/browser/browser_webapi_uninstall.js
toolkit/mozapps/extensions/test/browser/browser_webext_incognito.js
--- a/toolkit/mozapps/extensions/test/browser/browser_globalwarnings.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_globalwarnings.js
@@ -88,17 +88,19 @@ add_task(async function checkCompatibili
   await extension.unload();
 });
 
 add_task(async function checkSecurity() {
   info("Testing update security checking warning");
 
   var pref = "extensions.checkUpdateSecurity";
   info("Setting " + pref + " pref to false");
-  Services.prefs.setBoolPref(pref, false);
+  await SpecialPowers.pushPrefEnv({
+    set: [[pref, false]],
+  });
 
   let id = "test-security@mochi.test";
   let extension = ExtensionTestUtils.loadExtension({
     manifest: { applications: { gecko: { id } } },
     useAddonManager: "temporary",
   });
   await extension.startup();
 
--- a/toolkit/mozapps/extensions/test/browser/browser_history_navigation.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_history_navigation.js
@@ -16,20 +16,16 @@ const { AddonTestUtils } = ChromeUtils.i
   "resource://testing-common/AddonTestUtils.jsm"
 );
 
 AddonTestUtils.initMochitest(this);
 
 const MAIN_URL = `https://example.com/${RELATIVE_DIR}discovery.html`;
 const DISCOAPI_URL = `http://example.com/${RELATIVE_DIR}/discovery/api_response_empty.json`;
 
-// Clearing this pref is currently done from a cleanup function registered
-// by the head.js file.
-Services.prefs.setCharPref(PREF_DISCOVERURL, MAIN_URL);
-
 var gProvider = new MockProvider();
 gProvider.createAddons([
   {
     id: "test1@tests.mozilla.org",
     name: "Test add-on 1",
     description: "foo",
   },
   {
--- a/toolkit/mozapps/extensions/test/browser/browser_installssl.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_installssl.js
@@ -31,20 +31,16 @@ function test() {
     var cos = Cc["@mozilla.org/security/certoverride;1"].getService(
       Ci.nsICertOverrideService
     );
     cos.clearValidityOverride("nocert.example.com", -1);
     cos.clearValidityOverride("self-signed.example.com", -1);
     cos.clearValidityOverride("untrusted.example.com", -1);
     cos.clearValidityOverride("expired.example.com", -1);
 
-    try {
-      Services.prefs.clearUserPref(PREF_INSTALL_REQUIREBUILTINCERTS);
-    } catch (e) {}
-
     if (gPendingInstall) {
       gTests = [];
       ok(
         false,
         "Timed out in the middle of downloading " +
           gPendingInstall.sourceURI.spec
       );
       try {
@@ -172,18 +168,20 @@ add_test(function() {
   add_install_test(EXPIRED, UNTRUSTED, NETWORK_FAILURE);
   add_install_test(EXPIRED, EXPIRED, NETWORK_FAILURE);
 
   run_install_tests(run_next_test);
 });
 
 // Runs tests without requiring built-in certificates, no certificate
 // exceptions and no hashes
-add_test(function() {
-  Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false);
+add_test(async function() {
+  await SpecialPowers.pushPrefEnv({
+    set: [[PREF_INSTALL_REQUIREBUILTINCERTS, false]],
+  });
 
   // Tests that a simple install works as expected.
   add_install_test(HTTP, null, SUCCESS);
   add_install_test(HTTPS, null, SUCCESS);
   add_install_test(NOCERT, null, NETWORK_FAILURE);
   add_install_test(SELFSIGNED, null, NETWORK_FAILURE);
   add_install_test(UNTRUSTED, null, NETWORK_FAILURE);
   add_install_test(EXPIRED, null, NETWORK_FAILURE);
@@ -241,18 +239,20 @@ add_test(function() {
 
 // Set up overrides for the next test.
 add_test(() => {
   addCertOverrides().then(run_next_test);
 });
 
 // Runs tests with built-in certificates required, all certificate exceptions
 // and no hashes
-add_test(function() {
-  Services.prefs.clearUserPref(PREF_INSTALL_REQUIREBUILTINCERTS);
+add_test(async function() {
+  await SpecialPowers.pushPrefEnv({
+    clear: [[PREF_INSTALL_REQUIREBUILTINCERTS]],
+  });
 
   // Tests that a simple install works as expected.
   add_install_test(HTTP, null, SUCCESS);
   add_install_test(HTTPS, null, NETWORK_FAILURE);
   add_install_test(NOCERT, null, NETWORK_FAILURE);
   add_install_test(SELFSIGNED, null, NETWORK_FAILURE);
   add_install_test(UNTRUSTED, null, NETWORK_FAILURE);
   add_install_test(EXPIRED, null, NETWORK_FAILURE);
@@ -305,18 +305,20 @@ add_test(function() {
   add_install_test(EXPIRED, UNTRUSTED, NETWORK_FAILURE);
   add_install_test(EXPIRED, EXPIRED, NETWORK_FAILURE);
 
   run_install_tests(run_next_test);
 });
 
 // Runs tests without requiring built-in certificates, all certificate
 // exceptions and no hashes
-add_test(function() {
-  Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false);
+add_test(async function() {
+  await SpecialPowers.pushPrefEnv({
+    set: [[PREF_INSTALL_REQUIREBUILTINCERTS, false]],
+  });
 
   // Tests that a simple install works as expected.
   add_install_test(HTTP, null, SUCCESS);
   add_install_test(HTTPS, null, SUCCESS);
   add_install_test(NOCERT, null, SUCCESS);
   add_install_test(SELFSIGNED, null, SUCCESS);
   add_install_test(UNTRUSTED, null, SUCCESS);
   add_install_test(EXPIRED, null, SUCCESS);
--- a/toolkit/mozapps/extensions/test/browser/browser_updatessl.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_updatessl.js
@@ -63,18 +63,16 @@ function test() {
   registerCleanupFunction(function() {
     observerService.removeObserver(HTTPObserver);
   });
 
   run_next_test();
 }
 
 function end_test() {
-  Services.prefs.clearUserPref(PREF_UPDATE_REQUIREBUILTINCERTS);
-
   var cos = Cc["@mozilla.org/security/certoverride;1"].getService(
     Ci.nsICertOverrideService
   );
   cos.clearValidityOverride("nocert.example.com", -1);
   cos.clearValidityOverride("self-signed.example.com", -1);
   cos.clearValidityOverride("untrusted.example.com", -1);
   cos.clearValidityOverride("expired.example.com", -1);
 
@@ -185,18 +183,20 @@ add_test(function() {
   add_update_test(EXPIRED, UNTRUSTED, DOWNLOAD_ERROR);
   add_update_test(EXPIRED, EXPIRED, DOWNLOAD_ERROR);
 
   run_update_tests(run_next_test);
 });
 
 // Runs tests without requiring built-in certificates and no certificate
 // exceptions.
-add_test(function() {
-  Services.prefs.setBoolPref(PREF_UPDATE_REQUIREBUILTINCERTS, false);
+add_test(async function() {
+  await SpecialPowers.pushPrefEnv({
+    set: [[PREF_UPDATE_REQUIREBUILTINCERTS, false]],
+  });
 
   // Tests that a simple update.json retrieval works as expected.
   add_update_test(HTTP, null, SUCCESS);
   add_update_test(HTTPS, null, SUCCESS);
   add_update_test(NOCERT, null, DOWNLOAD_ERROR);
   add_update_test(SELFSIGNED, null, DOWNLOAD_ERROR);
   add_update_test(UNTRUSTED, null, DOWNLOAD_ERROR);
   add_update_test(EXPIRED, null, DOWNLOAD_ERROR);
@@ -253,18 +253,20 @@ add_test(function() {
 });
 
 // Set up overrides for the next test.
 add_test(() => {
   addCertOverrides().then(run_next_test);
 });
 
 // Runs tests with built-in certificates required and all certificate exceptions.
-add_test(function() {
-  Services.prefs.clearUserPref(PREF_UPDATE_REQUIREBUILTINCERTS);
+add_test(async function() {
+  await SpecialPowers.pushPrefEnv({
+    clear: [[PREF_UPDATE_REQUIREBUILTINCERTS]],
+  });
 
   // Tests that a simple update.json retrieval works as expected.
   add_update_test(HTTP, null, SUCCESS);
   add_update_test(HTTPS, null, DOWNLOAD_ERROR);
   add_update_test(NOCERT, null, DOWNLOAD_ERROR);
   add_update_test(SELFSIGNED, null, DOWNLOAD_ERROR);
   add_update_test(UNTRUSTED, null, DOWNLOAD_ERROR);
   add_update_test(EXPIRED, null, DOWNLOAD_ERROR);
@@ -317,18 +319,20 @@ add_test(function() {
   add_update_test(EXPIRED, UNTRUSTED, DOWNLOAD_ERROR);
   add_update_test(EXPIRED, EXPIRED, DOWNLOAD_ERROR);
 
   run_update_tests(run_next_test);
 });
 
 // Runs tests without requiring built-in certificates and all certificate
 // exceptions.
-add_test(function() {
-  Services.prefs.setBoolPref(PREF_UPDATE_REQUIREBUILTINCERTS, false);
+add_test(async function() {
+  await SpecialPowers.pushPrefEnv({
+    set: [[PREF_UPDATE_REQUIREBUILTINCERTS, false]],
+  });
 
   // Tests that a simple update.json retrieval works as expected.
   add_update_test(HTTP, null, SUCCESS);
   add_update_test(HTTPS, null, SUCCESS);
   add_update_test(NOCERT, null, SUCCESS);
   add_update_test(SELFSIGNED, null, SUCCESS);
   add_update_test(UNTRUSTED, null, SUCCESS);
   add_update_test(EXPIRED, null, SUCCESS);
--- a/toolkit/mozapps/extensions/test/browser/browser_webapi.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_webapi.js
@@ -1,17 +1,18 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 const TESTPAGE = `${SECURE_TESTROOT}webapi_checkavailable.html`;
 
-Services.prefs.setBoolPref("extensions.webapi.testing", true);
-registerCleanupFunction(() => {
-  Services.prefs.clearUserPref("extensions.webapi.testing");
+add_task(async function setup() {
+  await SpecialPowers.pushPrefEnv({
+    set: [["extensions.webapi.testing", true]],
+  });
 });
 
 function testWithAPI(task) {
   return async function() {
     await BrowserTestUtils.withNewTab(TESTPAGE, task);
   };
 }
 
--- a/toolkit/mozapps/extensions/test/browser/browser_webapi_access.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_webapi_access.js
@@ -1,16 +1,12 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-registerCleanupFunction(() => {
-  Services.prefs.clearUserPref("extensions.webapi.testing");
-});
-
 function check_frame_availability(browser) {
   return check_availability(browser.browsingContext.children[0]);
 }
 
 function check_availability(browser) {
   return SpecialPowers.spawn(browser, [], async function() {
     return content.document.getElementById("result").textContent == "true";
   });
@@ -24,17 +20,19 @@ add_task(async function test_not_availab
       let available = await check_availability(browser);
       ok(!available, "API should not be available.");
     }
   );
 });
 
 // Test that with testing on the API is available in the test domain
 add_task(async function test_available() {
-  Services.prefs.setBoolPref("extensions.webapi.testing", true);
+  await SpecialPowers.pushPrefEnv({
+    set: [["extensions.webapi.testing", true]],
+  });
 
   await BrowserTestUtils.withNewTab(
     `${SECURE_TESTROOT}webapi_checkavailable.html`,
     async function test_not_available(browser) {
       let available = await check_availability(browser);
       ok(available, "API should be available.");
     }
   );
--- a/toolkit/mozapps/extensions/test/browser/browser_webapi_addon_listener.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_webapi_addon_listener.js
@@ -1,13 +1,14 @@
 const TESTPAGE = `${SECURE_TESTROOT}webapi_addon_listener.html`;
 
-Services.prefs.setBoolPref("extensions.webapi.testing", true);
-registerCleanupFunction(() => {
-  Services.prefs.clearUserPref("extensions.webapi.testing");
+add_task(async function setup() {
+  await SpecialPowers.pushPrefEnv({
+    set: [["extensions.webapi.testing", true]],
+  });
 });
 
 async function getListenerEvents(browser) {
   let result = await SpecialPowers.spawn(browser, [], async function() {
     return content.document.getElementById("result").textContent;
   });
 
   return result.split("\n").map(JSON.parse);
--- a/toolkit/mozapps/extensions/test/browser/browser_webapi_enable.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_webapi_enable.js
@@ -1,13 +1,14 @@
 const TESTPAGE = `${SECURE_TESTROOT}webapi_addon_listener.html`;
 
-Services.prefs.setBoolPref("extensions.webapi.testing", true);
-registerCleanupFunction(() => {
-  Services.prefs.clearUserPref("extensions.webapi.testing");
+add_task(async function setup() {
+  await SpecialPowers.pushPrefEnv({
+    set: [["extensions.webapi.testing", true]],
+  });
 });
 
 async function getListenerEvents(browser) {
   let result = await SpecialPowers.spawn(browser, [], async function() {
     return content.document.getElementById("result").textContent;
   });
 
   return result.split("\n").map(JSON.parse);
--- a/toolkit/mozapps/extensions/test/browser/browser_webapi_uninstall.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_webapi_uninstall.js
@@ -1,17 +1,18 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 const TESTPAGE = `${SECURE_TESTROOT}webapi_checkavailable.html`;
 
-Services.prefs.setBoolPref("extensions.webapi.testing", true);
-registerCleanupFunction(() => {
-  Services.prefs.clearUserPref("extensions.webapi.testing");
+add_task(async function setup() {
+  await SpecialPowers.pushPrefEnv({
+    set: [["extensions.webapi.testing", true]],
+  });
 });
 
 function testWithAPI(task) {
   return async function() {
     await BrowserTestUtils.withNewTab(TESTPAGE, task);
   };
 }
 
--- a/toolkit/mozapps/extensions/test/browser/browser_webext_incognito.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_webext_incognito.js
@@ -279,18 +279,16 @@ add_task(async function test_badge_and_t
         "action",
         "aboutAddons",
         "off",
         { ...expectedExtras, addonId: "@test-override-permanent" },
       ],
     ],
     { methods: ["action"] }
   );
-
-  Services.prefs.clearUserPref("extensions.allowPrivateBrowsingByDefault");
 });
 
 add_task(async function test_addon_preferences_button() {
   await SpecialPowers.pushPrefEnv({
     set: [["extensions.allowPrivateBrowsingByDefault", false]],
   });
 
   let addons = new Map([