Bug 1390738 - Await for pref change if containers aren't enabled. r?aswan
MozReview-Commit-ID: GOf1py5uZkh
--- 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) {