Bug 1372996 - Clear the URL bar when on ext newtab r=mixedpuppy
authorMark Striemer <mstriemer@mozilla.com>
Fri, 01 Sep 2017 09:39:24 -0500
changeset 430282 f2d3bce7e6dc49171bda39be7302b5997c591f66
parent 430281 228fbca07af3c3862fc7c465d0b0f4706f88dbf3
child 430283 95bcc263da5e74f605a9694427e29d970dade05a
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1372996
milestone57.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 1372996 - Clear the URL bar when on ext newtab r=mixedpuppy MozReview-Commit-ID: 2NNOK2kRPgl
browser/base/content/browser.js
browser/components/extensions/test/browser/browser_ext_identity_indication.js
browser/components/extensions/test/browser/browser_ext_url_overrides_newtab.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -296,16 +296,20 @@ var gInitialPages = [
   "about:blank",
   "about:newtab",
   "about:home",
   "about:privatebrowsing",
   "about:welcomeback",
   "about:sessionrestore"
 ];
 
+function isInitialPage(url) {
+  return gInitialPages.includes(url) || url == BROWSER_NEW_TAB_URL;
+}
+
 function* browserWindows() {
   let windows = Services.wm.getEnumerator("navigator:browser");
   while (windows.hasMoreElements())
     yield windows.getNext();
 }
 
 /**
 * We can avoid adding multiple load event listeners and save some time by adding
@@ -2746,29 +2750,33 @@ function URLBarSetURI(aURI) {
     let uri = aURI || gBrowser.currentURI;
     // Strip off "wyciwyg://" and passwords for the location bar
     try {
       uri = Services.uriFixup.createExposableURI(uri);
     } catch (e) {}
 
     // Replace initial page URIs with an empty string
     // only if there's no opener (bug 370555).
-    if (gInitialPages.includes(uri.spec) &&
+    if (isInitialPage(uri.spec) &&
         checkEmptyPageOrigin(gBrowser.selectedBrowser, uri)) {
       value = "";
     } else {
       // We should deal with losslessDecodeURI throwing for exotic URIs
       try {
         value = losslessDecodeURI(uri);
       } catch (ex) {
         value = "about:blank";
       }
     }
 
     valid = !isBlankPageURL(uri.spec) || uri.schemeIs("moz-extension");
+  } else if (isInitialPage(value) &&
+             checkEmptyPageOrigin(gBrowser.selectedBrowser)) {
+    value = "";
+    valid = true;
   }
 
   let isDifferentValidValue = valid && value != gURLBar.value;
   gURLBar.value = value;
   gURLBar.valueIsTyped = !valid;
   gURLBar.removeAttribute("usertyping");
   if (isDifferentValidValue) {
     gURLBar.selectionStart = gURLBar.selectionEnd = 0;
--- a/browser/components/extensions/test/browser/browser_ext_identity_indication.js
+++ b/browser/components/extensions/test/browser/browser_ext_identity_indication.js
@@ -84,14 +84,15 @@ add_task(async function testIdentityIndi
 
   await extension.startup();
 
   confirmDefaults();
 
   let url = await extension.awaitMessage("url");
   await BrowserTestUtils.withNewTab({gBrowser, url}, async function() {
     confirmExtensionPage();
+    is(gURLBar.value, "", "The URL bar is blank");
   });
 
   await extension.unload();
 
   confirmDefaults();
 });
--- a/browser/components/extensions/test/browser/browser_ext_url_overrides_newtab.js
+++ b/browser/components/extensions/test/browser/browser_ext_url_overrides_newtab.js
@@ -40,8 +40,57 @@ add_task(async function test_sending_mes
 
   let url = await extension.awaitMessage("from-newtab-page");
   ok(url.endsWith(NEWTAB_URI_1),
      "Newtab url is overriden by the extension.");
 
   await BrowserTestUtils.removeTab(gBrowser.selectedTab);
   await extension.unload();
 });
+
+/**
+ * Ensure we don't show the extension URL in the URL bar temporarily in new tabs
+ * while we're switching remoteness (when the URL we're loading and the
+ * default content principal are different).
+ */
+add_task(async function dontTemporarilyShowAboutExtensionPath() {
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      name: "Test Extension",
+      applications: {
+        gecko: {
+          id: "newtab@mochi.test",
+        },
+      },
+      chrome_url_overrides: {
+        newtab: "newtab.html",
+      },
+    },
+    background() {
+      browser.test.sendMessage("url", browser.runtime.getURL("newtab.html"));
+    },
+    files: {
+      "newtab.html": "<h1>New tab!</h1>",
+    },
+    useAddonManager: "temporary",
+  });
+
+  await extension.startup();
+  let url = await extension.awaitMessage("url");
+
+  let wpl = {
+    onLocationChange() {
+      is(gURLBar.value, "", "URL bar value should stay empty.");
+    },
+  };
+  gBrowser.addProgressListener(wpl);
+
+  let tab = await BrowserTestUtils.openNewForegroundTab({gBrowser, url});
+
+  gBrowser.removeProgressListener(wpl);
+  is(gURLBar.value, "", "URL bar value should be empty.");
+  ContentTask.spawn(tab.linkedBrowser, null, function() {
+    is(content.document.body.textContent, "New tab!", "New tab page is loaded.");
+  });
+
+  await BrowserTestUtils.removeTab(tab);
+  await extension.unload();
+});