Bug 1372996 - Clear the URL bar when on ext newtab r?mixedpuppy
MozReview-Commit-ID: 2NNOK2kRPgl
--- 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
@@ -2750,29 +2754,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();
+});