Bug 1529394 fix tests for pref'ing on incognito not_allowed r=rpl
☠☠ backed out by f324b0fe2471 ☠ ☠
authorShane Caraveo <scaraveo@mozilla.com>
Fri, 01 Mar 2019 17:55:38 +0000
changeset 520159 3a8c338af709b1d911ba645f914d26ca87db0988
parent 520158 b58080db50e6d16aa2e9c8e83188435353a2ecdc
child 520160 7f3e254c982c86371a0dc92a78c929b9cabbc3c1
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrpl
bugs1529394
milestone67.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 1529394 fix tests for pref'ing on incognito not_allowed r=rpl This patch addresses remaining test issues when pref'ing on. These are tests that previously ran some tests in private contexts that now require the use of incognitoOverride. This also fixes an xpcshell test wrapper to set the permission when overridden. Differential Revision: https://phabricator.services.mozilla.com/D21300
browser/components/extensions/test/browser/browser_ext_incognito_popup.js
browser/components/extensions/test/browser/browser_ext_incognito_views.js
browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js
browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId_private.js
browser/components/extensions/test/browser/browser_ext_tabs_create_url.js
browser/components/extensions/test/browser/browser_ext_windows_create_cookieStoreId.js
browser/components/extensions/test/browser/browser_ext_windows_create_tabId.js
browser/components/preferences/in-content/tests/browser_extension_controlled.js
toolkit/components/extensions/ExtensionTestCommon.jsm
toolkit/components/extensions/ExtensionXPCShellUtils.jsm
toolkit/components/extensions/test/mochitest/test_ext_inIncognitoContext_window.html
toolkit/components/extensions/test/xpcshell/test_ext_downloads_download.js
toolkit/components/extensions/test/xpcshell/test_ext_incognito.js
toolkit/components/extensions/test/xpcshell/test_ext_permissions.js
toolkit/components/extensions/test/xpcshell/test_ext_proxy_config.js
toolkit/components/extensions/test/xpcshell/test_ext_proxy_settings.js
--- a/browser/components/extensions/test/browser/browser_ext_incognito_popup.js
+++ b/browser/components/extensions/test/browser/browser_ext_incognito_popup.js
@@ -1,14 +1,15 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 add_task(async function testIncognitoPopup() {
   let extension = ExtensionTestUtils.loadExtension({
+    incognitoOverride: "spanning",
     manifest: {
       "permissions": ["tabs"],
       "browser_action": {
         "default_popup": "popup.html",
       },
       "page_action": {
         "default_popup": "popup.html",
       },
--- a/browser/components/extensions/test/browser/browser_ext_incognito_views.js
+++ b/browser/components/extensions/test/browser/browser_ext_incognito_views.js
@@ -2,16 +2,17 @@
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 add_task(async function testIncognitoViews() {
   // Make sure the mouse isn't hovering over the browserAction widget.
   EventUtils.synthesizeMouseAtCenter(gURLBar.textbox, {type: "mouseover"}, window);
 
   let extension = ExtensionTestUtils.loadExtension({
+    incognitoOverride: "spanning",
     manifest: {
       "permissions": ["tabs"],
       "browser_action": {
         "default_popup": "popup.html",
       },
     },
 
     background: async function() {
--- a/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js
@@ -26,16 +26,17 @@ add_task(async function() {
     {privateTab: true, cookieStoreId: null, success: true, expectedCookieStoreId: "firefox-private"},
     {privateTab: true, cookieStoreId: "firefox-private", success: true, expectedCookieStoreId: "firefox-private"},
     {privateTab: true, cookieStoreId: "firefox-default", failure: "privateToDefault"},
     {privateTab: true, cookieStoreId: "firefox-container-1", failure: "privateToDefault"},
     {privateTab: true, cookieStoreId: "wow", failure: "illegal"},
   ];
 
   let extension = ExtensionTestUtils.loadExtension({
+    incognitoOverride: "spanning",
     manifest: {
       "permissions": ["tabs", "cookies"],
     },
 
     background: function() {
       function testTab(data, tab) {
         browser.test.assertTrue(data.success, "we want a success");
         browser.test.assertTrue(!!tab, "we have a tab");
--- a/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId_private.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId_private.js
@@ -7,16 +7,17 @@ add_task(async function perma_private_br
   await SpecialPowers.pushPrefEnv({"set": [
     ["privacy.userContext.enabled", true],
   ]});
 
   Assert.equal(Services.prefs.getBoolPref("browser.privatebrowsing.autostart"),
                true, "Permanent private browsing is enabled");
 
   let extension = ExtensionTestUtils.loadExtension({
+    incognitoOverride: "spanning",
     manifest: {
       "permissions": ["tabs", "cookies"],
     },
     async background() {
       let win = await browser.windows.create({});
       browser.test.assertTrue(win.incognito, "New window should be private when perma-PBM is enabled.");
       await browser.test.assertRejects(
         browser.tabs.create({cookieStoreId: "firefox-container-1", windowId: win.id}),
--- a/browser/components/extensions/test/browser/browser_ext_tabs_create_url.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_create_url.js
@@ -78,16 +78,17 @@ add_task(async function test_urlbar_focu
   extension.sendMessage("remove", tab2.id);
   await extension.awaitMessage("result");
 
   await extension.unload();
 });
 
 add_task(async function default_url() {
   const extension = ExtensionTestUtils.loadExtension({
+    incognitoOverride: "spanning",
     manifest: {
       permissions: ["tabs"],
     },
     background() {
       function promiseNonBlankTab() {
         return new Promise(resolve => {
           browser.tabs.onUpdated.addListener(function listener(tabId, changeInfo, tab) {
             if (changeInfo.status === "complete" && tab.url !== "about:blank") {
--- a/browser/components/extensions/test/browser/browser_ext_windows_create_cookieStoreId.js
+++ b/browser/components/extensions/test/browser/browser_ext_windows_create_cookieStoreId.js
@@ -23,16 +23,17 @@ add_task(async function no_cookies_permi
 });
 
 add_task(async function invalid_cookieStoreId() {
   await SpecialPowers.pushPrefEnv({"set": [
     ["privacy.userContext.enabled", true],
   ]});
 
   let extension = ExtensionTestUtils.loadExtension({
+    incognitoOverride: "spanning",
     manifest: {
       permissions: ["cookies"],
     },
     async background() {
       await browser.test.assertRejects(
         browser.windows.create({cookieStoreId: "not-firefox-container-1"}),
         /Illegal cookieStoreId/,
         "cookieStoreId must be valid");
@@ -59,16 +60,17 @@ add_task(async function invalid_cookieSt
   await extension.awaitMessage("done");
   await extension.unload();
 });
 
 add_task(async function perma_private_browsing_mode() {
   await SpecialPowers.pushPrefEnv({set: [["browser.privatebrowsing.autostart", true]]});
 
   let extension = ExtensionTestUtils.loadExtension({
+    incognitoOverride: "spanning",
     manifest: {
       "permissions": ["tabs", "cookies"],
     },
     async background() {
       await browser.test.assertRejects(
         browser.windows.create({cookieStoreId: "firefox-container-1"}),
         /Contextual identities are unavailable in permanent private browsing mode/,
         "cookieStoreId cannot be a container tab ID in perma-private browsing mode");
@@ -235,16 +237,17 @@ add_task(async function valid_cookieStor
 });
 
 add_task(async function cookieStoreId_and_tabId() {
   await SpecialPowers.pushPrefEnv({"set": [
     ["privacy.userContext.enabled", true],
   ]});
 
   let extension = ExtensionTestUtils.loadExtension({
+    incognitoOverride: "spanning",
     manifest: {
       permissions: ["cookies"],
     },
     async background() {
       for (let cookieStoreId of ["firefox-default", "firefox-container-1"]) {
         let {id: normalTabId} = await browser.tabs.create({cookieStoreId});
 
         await browser.test.assertRejects(
--- a/browser/components/extensions/test/browser/browser_ext_windows_create_tabId.js
+++ b/browser/components/extensions/test/browser/browser_ext_windows_create_tabId.js
@@ -134,16 +134,17 @@ add_task(async function testWindowCreate
       browser.test.notifyPass("window-create");
     } catch (e) {
       browser.test.fail(`${e} :: ${e.stack}`);
       browser.test.notifyFail("window-create");
     }
   }
 
   let extension = ExtensionTestUtils.loadExtension({
+    incognitoOverride: "spanning",
     manifest: {
       "permissions": ["tabs"],
     },
 
     background,
   });
 
   await extension.startup();
--- a/browser/components/preferences/in-content/tests/browser_extension_controlled.js
+++ b/browser/components/preferences/in-content/tests/browser_extension_controlled.js
@@ -841,18 +841,21 @@ add_task(async function testExtensionCon
   let panelDoc = panelObj.panel.document;
 
   verifyState(panelDoc, false);
 
   await closeProxyPanel(panelObj);
 
   verifyState(mainDoc, false);
 
-  // Install an extension that controls proxy settings.
+  // Install an extension that controls proxy settings. The extension needs
+  // incognitoOverride because controlling the proxy.settings requires private
+  // browsing access.
   let extension = ExtensionTestUtils.loadExtension({
+    incognitoOverride: "spanning",
     useAddonManager: "permanent",
     manifest: {
       name: "set_proxy",
       applications: {gecko: {id: EXTENSION_ID}},
       permissions: ["proxy"],
     },
     background,
   });
--- a/toolkit/components/extensions/ExtensionTestCommon.jsm
+++ b/toolkit/components/extensions/ExtensionTestCommon.jsm
@@ -335,16 +335,28 @@ ExtensionTestCommon = class ExtensionTes
       return;
     }
     if (addonData.incognitoOverride == "not_allowed") {
       return ExtensionPermissions.remove(id, {permissions: ["internal:privateBrowsingAllowed"], origins: []});
     }
     return ExtensionPermissions.add(id, {permissions: ["internal:privateBrowsingAllowed"], origins: []});
   }
 
+  static setExtensionID(data) {
+    try {
+      if (data.manifest.applications.gecko.id) {
+        return;
+      }
+    } catch (e) {
+      // No ID is set.
+    }
+    provide(data, ["manifest", "applications", "gecko", "id"],
+            uuidGen.generateUUID().number);
+  }
+
   /**
    * Generates a new extension using |Extension.generateXPI|, and initializes a
    * new |Extension| instance which will execute it.
    *
    * @param {object} data
    * @returns {Extension}
    */
   static generate(data) {
--- a/toolkit/components/extensions/ExtensionXPCShellUtils.jsm
+++ b/toolkit/components/extensions/ExtensionXPCShellUtils.jsm
@@ -581,22 +581,23 @@ class AOMExtensionWrapper extends Extens
 
     this.cleanupFiles.push(xpiFile);
 
     return this._install(xpiFile);
   }
 }
 
 class InstallableWrapper extends AOMExtensionWrapper {
-  constructor(testScope, xpiFile, installType, installTelemetryInfo) {
+  constructor(testScope, xpiFile, addonData = {}) {
     super(testScope);
 
     this.file = xpiFile;
-    this.installType = installType;
-    this.installTelemetryInfo = installTelemetryInfo;
+    this.addonData = addonData;
+    this.installType = addonData.useAddonManager || "temporary";
+    this.installTelemetryInfo = addonData.amInstallTelemetryInfo;
 
     this.cleanupFiles = [xpiFile];
   }
 
   destroy() {
     super.destroy();
 
     for (let file of this.cleanupFiles.splice(0)) {
@@ -612,17 +613,36 @@ class InstallableWrapper extends AOMExte
   maybeSetID(uri, id) {
     if (!this.id && uri instanceof Ci.nsIJARURI &&
         uri.JARFile.QueryInterface(Ci.nsIFileURL)
            .file.equals(this.file)) {
       this.id = id;
     }
   }
 
-  _install(xpiFile) {
+  _setIncognitoOverride() {
+    // this.id is not set yet so grab it from the manifest data to set
+    // the incognito permission.
+    let {addonData} = this;
+    if (addonData && addonData.incognitoOverride) {
+      try {
+        let {id} = addonData.manifest.applications.gecko;
+        if (id) {
+          return ExtensionTestCommon.setIncognitoOverride({id, addonData});
+        }
+      } catch (e) {}
+      throw new Error("Extension ID is required for setting incognito permission.");
+    }
+  }
+
+  async _install(xpiFile) {
+    // Timing here is different than in MockExtension so we need to handle
+    // incognitoOverride early.
+    await this._setIncognitoOverride();
+
     if (this.installType === "temporary") {
       return AddonManager.installTemporaryAddon(xpiFile).then(addon => {
         this.id = addon.id;
         this.addon = addon;
 
         return this.startupPromise;
       }).catch(e => {
         this.state = "unloaded";
@@ -778,28 +798,33 @@ var ExtensionTestUtils = {
 
     let manager = Cc["@mozilla.org/addons/integration;1"].getService(Ci.nsIObserver)
                                                          .QueryInterface(Ci.nsITimerCallback);
     manager.observe(null, "addons-startup", null);
   },
 
   loadExtension(data) {
     if (data.useAddonManager) {
+      // If we're using incognitoOverride, we'll need to ensure
+      // an ID is available before generating the XPI.
+      if (data.incognitoOverride) {
+        ExtensionTestCommon.setExtensionID(data);
+      }
       let xpiFile = ExtensionTestCommon.generateXPI(data);
 
-      return this.loadExtensionXPI(xpiFile, data.useAddonManager, data.amInstallTelemetryInfo);
+      return this.loadExtensionXPI(xpiFile, data);
     }
 
     let extension = ExtensionTestCommon.generate(data);
 
     return new ExtensionWrapper(this.currentScope, extension);
   },
 
-  loadExtensionXPI(xpiFile, useAddonManager = "temporary", installTelemetryInfo) {
-    return new InstallableWrapper(this.currentScope, xpiFile, useAddonManager, installTelemetryInfo);
+  loadExtensionXPI(xpiFile, data) {
+    return new InstallableWrapper(this.currentScope, xpiFile, data);
   },
 
   // Create a wrapper for a webextension that will be installed
   // by some external process (e.g., Normandy)
   expectExtension(id) {
     return new ExternallyInstalledWrapper(this.currentScope, id);
   },
 
--- a/toolkit/components/extensions/test/mochitest/test_ext_inIncognitoContext_window.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_inIncognitoContext_window.html
@@ -31,16 +31,17 @@ add_task(async function test_in_incognit
     background,
     files: {
       "tab.js": tabScript,
       "tab.html": `<!DOCTYPE html><html><head>
         <meta charset="utf-8">
         <script src="tab.js"><\/script>
       </head></html>`,
     },
+    incognitoOverride: "spanning",
   });
 
   await extension.startup();
   await extension.awaitFinish("inIncognitoContext");
   await extension.unload();
 });
 
 </script>
--- a/toolkit/components/extensions/test/xpcshell/test_ext_downloads_download.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_downloads_download.js
@@ -99,16 +99,17 @@ function remove(filename, recursive = fa
 add_task(async function test_downloads() {
   setup();
 
   let extension = ExtensionTestUtils.loadExtension({
     background: `(${backgroundScript})()`,
     manifest: {
       permissions: ["downloads"],
     },
+    incognitoOverride: "spanning",
   });
 
   function download(options) {
     extension.sendMessage("download.request", options);
     return extension.awaitMessage("download.done");
   }
 
   async function testDownload(options, localFile, expectedSize, description) {
--- a/toolkit/components/extensions/test/xpcshell/test_ext_incognito.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_incognito.js
@@ -52,16 +52,17 @@ add_task(async function test_extension_i
   await runIncognitoTest(extensionData, true, false);
 });
 
 // We only test spanning upgrades since that is the only allowed
 // incognito type prior to feature being turned on.
 add_task(async function test_extension_incognito_spanning_grandfathered() {
   await AddonTestUtils.promiseStartupManager();
   Services.prefs.setBoolPref("extensions.allowPrivateBrowsingByDefault", true);
+  Services.prefs.setBoolPref("extensions.incognito.migrated", false);
 
   // This extension gets disabled before the "upgrade", it should not
   // get grandfathered permissions.
   let disabledWrapper = ExtensionTestUtils.loadExtension({
     manifest: {
       applications: {gecko: {id: "@disabled"}},
       incognito: "spanning",
     },
@@ -122,9 +123,10 @@ add_task(async function test_extension_i
   equal(disabledPolicy.permissions.includes("internal:privateBrowsingAllowed"), false,
         "privateBrowsingAllowed is not in permissions for disabled addon");
   equal(disabledPolicy.privateBrowsingAllowed, false,
         "privateBrowsingAllowed in disabled addon");
 
   await wrapper.unload();
   await disabledWrapper.unload();
   Services.prefs.clearUserPref("extensions.allowPrivateBrowsingByDefault");
+  Services.prefs.clearUserPref("extensions.incognito.migrated");
 });
--- a/toolkit/components/extensions/test/xpcshell/test_ext_permissions.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_permissions.js
@@ -580,17 +580,17 @@ add_task(async function test_permissions
   let perms = perminfo.addon.userPermissions;
   deepEqual(perms.permissions, PERMS, "Update details includes only manifest api permissions");
   deepEqual(perms.origins, ORIGINS, "Update details includes only manifest origin permissions");
 
   await extension.unload();
 });
 
 // Check that internal permissions can not be set and are not returned by the API.
-add_task(async function test_internal_permisisons() {
+add_task(async function test_internal_permissions() {
   Services.prefs.setBoolPref("extensions.allowPrivateBrowsingByDefault", false);
 
   function background() {
     browser.test.onMessage.addListener(async (method, arg) => {
       try {
         if (method == "getAll") {
           let perms = await browser.permissions.getAll();
           browser.test.sendMessage("getAll.result", perms);
@@ -612,17 +612,16 @@ add_task(async function test_internal_pe
 
   let extension = ExtensionTestUtils.loadExtension({
     background,
     manifest: {
       name: "permissions test",
       description: "permissions test",
       manifest_version: 2,
       version: "1.0",
-
       permissions: [],
     },
     useAddonManager: "permanent",
     incognitoOverride: "spanning",
   });
 
   let perm = "internal:privateBrowsingAllowed";
 
--- a/toolkit/components/extensions/test/xpcshell/test_ext_proxy_config.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_proxy_config.js
@@ -63,16 +63,17 @@ add_task(async function test_browser_set
     }
   });
 
   let extension = ExtensionTestUtils.loadExtension({
     background,
     manifest: {
       permissions: ["proxy"],
     },
+    incognitoOverride: "spanning",
     useAddonManager: "temporary",
   });
 
   await promiseStartupManager();
   await extension.startup();
 
   async function testSetting(value, expected, expectedValue = value) {
     extension.sendMessage("set", value);
@@ -412,14 +413,15 @@ add_task(async function test_bad_value_p
       browser.test.sendMessage("done");
     };
 
   let extension = ExtensionTestUtils.loadExtension({
     background,
     manifest: {
       permissions: ["proxy"],
     },
+    incognitoOverride: "spanning",
   });
 
   await extension.startup();
   await extension.awaitMessage("done");
   await extension.unload();
 });
--- a/toolkit/components/extensions/test/xpcshell/test_ext_proxy_settings.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_proxy_settings.js
@@ -54,16 +54,17 @@ add_task(async function test_proxy_setti
     manifest: {
       applications: {gecko: {id: "proxy.settings@mochi.test"}},
       permissions: [
         "proxy",
         "webRequest",
         "<all_urls>",
       ],
     },
+    incognitoOverride: "spanning",
     useAddonManager: "temporary",
     background: `(${background})("${proxy.identity.primaryHost}", ${proxy.identity.primaryPort})`,
   });
 
   await promiseStartupManager();
   await extension.startup();
   await extension.awaitMessage("ready");
   equal(Services.prefs.getStringPref("network.proxy.http"), proxy.identity.primaryHost, "proxy address is set");