Backed out changeset c844033d55eb (bug 1488914) for bc failures in /browser_ext_windows_create_cookieStoreId.js. CLOSED TREE
authorBrindusan Cristian <cbrindusan@mozilla.com>
Thu, 11 Oct 2018 21:58:59 +0300
changeset 489099 04fbac02c101394f6b344a695e81bdfb026151a1
parent 489098 07b8305bb7d444ba85a4fb77d9a5d13af0644f4e
child 489100 7a97fe41a34fabed6beeb3db2fc0a2c61623eeae
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
bugs1488914
milestone64.0a1
backs outc844033d55eb91acb4190ee202361b1b95062e0c
Backed out changeset c844033d55eb (bug 1488914) for bc failures in /browser_ext_windows_create_cookieStoreId.js. CLOSED TREE
browser/components/extensions/parent/ext-windows.js
browser/components/extensions/test/browser/browser_ext_tabs_create_url.js
--- a/browser/components/extensions/parent/ext-windows.js
+++ b/browser/components/extensions/parent/ext-windows.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";
 
-ChromeUtils.defineModuleGetter(this, "HomePage",
-                               "resource:///modules/HomePage.jsm");
+XPCOMUtils.defineLazyServiceGetter(this, "aboutNewTabService",
+                                   "@mozilla.org/browser/aboutnewtab-service;1",
+                                   "nsIAboutNewTabService");
 ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils",
                                "resource://gre/modules/PrivateBrowsingUtils.jsm");
 
 var {
   promiseObserved,
 } = ExtensionUtils;
 
 /**
@@ -146,16 +147,19 @@ this.windows = class extends ExtensionAP
             let tab = tabTracker.getTab(createData.tabId);
 
             // Private browsing tabs can only be moved to private browsing
             // windows.
             let incognito = PrivateBrowsingUtils.isBrowserPrivate(tab.linkedBrowser);
             if (createData.incognito !== null && createData.incognito != incognito) {
               return Promise.reject({message: "`incognito` property must match the incognito state of tab"});
             }
+            if (createData.incognito && !PrivateBrowsingUtils.enabled) {
+              return Promise.reject({message: "`incognito` cannot be used if incognito mode is disabled"});
+            }
             createData.incognito = incognito;
 
             if (createData.cookieStoreId && createData.cookieStoreId !== getCookieStoreIdForTab(createData, tab)) {
               return Promise.reject({message: "`cookieStoreId` must match the tab's cookieStoreId"});
             }
 
             args.appendElement(tab);
           } else if (createData.url !== null) {
@@ -164,24 +168,22 @@ this.windows = class extends ExtensionAP
               for (let url of createData.url) {
                 array.appendElement(mkstr(url));
               }
               args.appendElement(array);
             } else {
               args.appendElement(mkstr(createData.url));
             }
           } else {
-            let url = createData.incognito && !PrivateBrowsingUtils.permanentPrivateBrowsing ?
-              "about:privatebrowsing" : HomePage.get().split("|", 1)[0];
+            let url = aboutNewTabService.newTabURL;
             args.appendElement(mkstr(url));
 
-            if (url.startsWith("about:") &&
-                !context.checkLoadURL(url, {dontReportErrors: true})) {
-              // The extension principal cannot directly load about:-URLs,
-              // except for about:blank. So use the system principal instead.
+            if (url === "about:newtab") {
+              // The extension principal cannot directly load about:newtab,
+              // so use the system principal instead.
               principal = Services.scriptSecurityManager.getSystemPrincipal();
             }
           }
 
           args.appendElement(null); // unused
           args.appendElement(null); // referrer
           args.appendElement(null); // postData
           args.appendElement(null); // allowThirdPartyFixup
@@ -206,19 +208,16 @@ this.windows = class extends ExtensionAP
             features.push("dialog=no", "all");
           } else {
             // All other types create "popup"-type windows by default.
             features.push("dialog", "resizable", "minimizable", "centerscreen", "titlebar", "close");
           }
 
           if (createData.incognito !== null) {
             if (createData.incognito) {
-              if (!PrivateBrowsingUtils.enabled) {
-                return Promise.reject({message: "`incognito` cannot be used if incognito mode is disabled"});
-              }
               features.push("private");
             } else {
               features.push("non-private");
             }
           }
 
           let {allowScriptsToClose, url} = createData;
           if (allowScriptsToClose === null) {
--- a/browser/components/extensions/test/browser/browser_ext_tabs_create_url.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_create_url.js
@@ -1,32 +1,12 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-async function runWithDisabledPrivateBrowsing(callback) {
-  const {
-    EnterprisePolicyTesting,
-    PoliciesPrefTracker,
-  } = ChromeUtils.import("resource://testing-common/EnterprisePolicyTesting.jsm", {});
-
-  PoliciesPrefTracker.start();
-  await EnterprisePolicyTesting.setupPolicyEngineWithJson({
-    policies: {DisablePrivateBrowsing: true},
-  });
-
-  try {
-    await callback();
-  } finally {
-    await EnterprisePolicyTesting.setupPolicyEngineWithJson("");
-    EnterprisePolicyTesting.resetRunOnceState();
-    PoliciesPrefTracker.stop();
-  }
-}
-
 add_task(async function test_urlbar_focus() {
   // Disable preloaded new tab because the urlbar is automatically focused when
   // a preloaded new tab is opened, while this test is supposed to test that the
   // implementation of tabs.create automatically focuses the urlbar of new tabs.
   await SpecialPowers.pushPrefEnv({
     set: [["browser.newtab.preload", false]],
   });
 
@@ -75,117 +55,8 @@ add_task(async function test_urlbar_focu
   is(active.tagName, "html:input", "Input element focused");
   ok(active.classList.contains("urlbar-input"), "Urlbar focused");
 
   extension.sendMessage("remove", tab2.id);
   await extension.awaitMessage("result");
 
   await extension.unload();
 });
-
-add_task(async function default_url() {
-  const extension = ExtensionTestUtils.loadExtension({
-    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") {
-              browser.tabs.onUpdated.removeListener(listener);
-              resolve(tab);
-            }
-          });
-        });
-      }
-
-      browser.test.onMessage.addListener(async (msg, {incognito, expectedNewWindowUrl, expectedNewTabUrl}) => {
-        browser.test.assertEq("start", msg, `Start test, incognito=${incognito}`);
-
-        let tabPromise = promiseNonBlankTab();
-        let win;
-        try {
-          win = await browser.windows.create({incognito});
-          browser.test.assertEq(1, win.tabs.length, "Expected one tab in the new window.");
-        } catch (e) {
-          browser.test.assertEq(expectedNewWindowUrl, e.message, "Expected error");
-          browser.test.sendMessage("done");
-          return;
-        }
-        let tab = await tabPromise;
-        browser.test.assertEq(expectedNewWindowUrl, tab.url, "Expected default URL of new window");
-
-        tabPromise = promiseNonBlankTab();
-        await browser.tabs.create({windowId: win.id});
-        tab = await tabPromise;
-        browser.test.assertEq(expectedNewTabUrl, tab.url, "Expected default URL of new tab");
-
-        await browser.windows.remove(win.id);
-        browser.test.sendMessage("done");
-      });
-    },
-  });
-
-  await extension.startup();
-
-  extension.sendMessage("start", {
-    incognito: false,
-    expectedNewWindowUrl: "about:home",
-    expectedNewTabUrl: "about:newtab",
-  });
-  await extension.awaitMessage("done");
-  extension.sendMessage("start", {
-    incognito: true,
-    expectedNewWindowUrl: "about:privatebrowsing",
-    expectedNewTabUrl: "about:privatebrowsing",
-  });
-  await extension.awaitMessage("done");
-
-  info("Testing with multiple homepages.");
-  await SpecialPowers.pushPrefEnv({set: [["browser.startup.homepage", "about:robots|about:blank|about:home"]]});
-  extension.sendMessage("start", {
-    incognito: false,
-    expectedNewWindowUrl: "about:robots",
-    expectedNewTabUrl: "about:newtab",
-  });
-  await extension.awaitMessage("done");
-  extension.sendMessage("start", {
-    incognito: true,
-    expectedNewWindowUrl: "about:privatebrowsing",
-    expectedNewTabUrl: "about:privatebrowsing",
-  });
-  await extension.awaitMessage("done");
-  await SpecialPowers.popPrefEnv();
-
-  info("Testing with perma-private browsing mode.");
-  await SpecialPowers.pushPrefEnv({set: [["browser.privatebrowsing.autostart", true]]});
-  extension.sendMessage("start", {
-    incognito: false,
-    expectedNewWindowUrl: "about:home",
-    expectedNewTabUrl: "about:newtab",
-  });
-  await extension.awaitMessage("done");
-  extension.sendMessage("start", {
-    incognito: true,
-    expectedNewWindowUrl: "about:home",
-    expectedNewTabUrl: "about:newtab",
-  });
-  await extension.awaitMessage("done");
-  await SpecialPowers.popPrefEnv();
-
-  info("Testing with disabled private browsing mode.");
-  await runWithDisabledPrivateBrowsing(async () => {
-    extension.sendMessage("start", {
-      incognito: false,
-      expectedNewWindowUrl: "about:home",
-      expectedNewTabUrl: "about:newtab",
-    });
-    await extension.awaitMessage("done");
-    extension.sendMessage("start", {
-      incognito: true,
-      expectedNewWindowUrl: "`incognito` cannot be used if incognito mode is disabled",
-    });
-    await extension.awaitMessage("done");
-  });
-
-  await extension.unload();
-});