Bug 1390738 - Await for pref change if containers aren't enabled. r?aswan draft
authorJonathan Kingston <jkt@mozilla.com>
Thu, 07 Sep 2017 22:20:47 -0700
changeset 661193 27ae4431931c31534ab94bc9d404e8442099d6d6
parent 661153 604fd3302562dc2059a8de3231818a1b618b8ffe
child 730491 6a7dd9f9cd43d44cdb9cf2c90db4f84559b4ca0f
push id78672
push userbmo:jkt@mozilla.com
push dateFri, 08 Sep 2017 05:21:46 +0000
reviewersaswan
bugs1390738
milestone57.0a1
Bug 1390738 - Await for pref change if containers aren't enabled. r?aswan MozReview-Commit-ID: GOf1py5uZkh
toolkit/components/extensions/test/xpcshell/test_ext_contextual_identities.js
--- a/toolkit/components/extensions/test/xpcshell/test_ext_contextual_identities.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_contextual_identities.js
@@ -1,14 +1,26 @@
 "use strict";
 
 do_get_profile();
 
 XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
                                   "resource://modules/AddonManager.jsm");
+
+function waitForPrefChange(pref) {
+  return new Promise(resolve => {
+    function observeChange() {
+      Services.prefs.removeObserver(pref, observeChange);
+      resolve();
+    }
+
+    Services.prefs.addObserver(pref, observeChange);
+  });
+}
+
 add_task(async function startup() {
   await ExtensionTestUtils.startAddonManager();
 });
 
 add_task(async function test_contextualIdentities_without_permissions() {
   function background() {
     browser.test.assertTrue(!browser.contextualIdentities,
                             "contextualIdentities API is not available when the contextualIdentities permission is not required");
@@ -202,17 +214,21 @@ add_task(async function test_contextualI
       },
     });
   }
 
   let extension = makeExtension("containers-test@mozilla.org");
   await extension.startup();
   await extension.awaitFinish("contextualIdentities");
   equal(Services.prefs.getBoolPref(CONTAINERS_PREF), true, "Pref should now be enabled, whatever it's initial state");
+  const prefChange = waitForPrefChange(CONTAINERS_PREF);
   await extension.unload();
+  if (initial === false) {
+    await prefChange;
+  }
   equal(Services.prefs.getBoolPref(CONTAINERS_PREF), initial, "Pref should now be initial state");
 
   Services.prefs.clearUserPref(CONTAINERS_PREF);
 });
 
 add_task(async function test_contextualIdentity_extensions_enable_containers() {
   const CONTAINERS_PREF = "privacy.userContext.enabled";
   const initial = Services.prefs.getBoolPref(CONTAINERS_PREF);
@@ -230,27 +246,16 @@ add_task(async function test_contextualI
         applications: {
           gecko: {id},
         },
         permissions: ["contextualIdentities"],
       },
     });
   }
 
-  function waitForPrefChange(pref) {
-    return new Promise(resolve => {
-      function observeChange() {
-        Services.prefs.removeObserver(pref, observeChange);
-        resolve();
-      }
-
-      Services.prefs.addObserver(pref, observeChange);
-    });
-  }
-
   let extension = makeExtension("containers-test@mozilla.org");
   await extension.startup();
   await extension.awaitFinish("contextualIdentities");
   equal(Services.prefs.getBoolPref(CONTAINERS_PREF), true, "Pref should now be enabled, whatever it's initial state");
   const prefChange = waitForPrefChange(CONTAINERS_PREF);
   await extension.unload();
   // If pref was false we should wait for the pref to change back here.
   if (initial === false) {