Bug 1478348 - Dont show doorhanger on about:newtab. r=johannh

MozReview-Commit-ID: EmHV3OS6Kra
This commit is contained in:
Dale Harvey
2018-08-24 16:43:22 +01:00
parent 609a3f271e
commit 02db992aaa
6 changed files with 61 additions and 12 deletions

View File

@@ -2656,8 +2656,11 @@ function BrowserPageInfo(documentURL, initialTab, imageElement, frameOuterWindow
*
* @param aURI [optional]
* nsIURI to set. If this is unspecified, the current URI will be used.
* @param updatePopupNotifications [optional]
* Passed though to SetPageProxyState, indicates whether the
* PopupNotifications need updated.
*/
function URLBarSetURI(aURI) {
function URLBarSetURI(aURI, updatePopupNotifications) {
var value = gBrowser.userTypedValue;
var valid = false;
@@ -2702,7 +2705,7 @@ function URLBarSetURI(aURI) {
gURLBar.selectionStart = gURLBar.selectionEnd = 0;
}
SetPageProxyState(valid ? "valid" : "invalid");
SetPageProxyState(valid ? "valid" : "invalid", updatePopupNotifications);
}
function losslessDecodeURI(aURI) {
@@ -2799,8 +2802,9 @@ function UpdateUrlbarSearchSplitterState() {
}
function UpdatePageProxyState() {
if (gURLBar && gURLBar.value != gLastValidURLStr)
SetPageProxyState("invalid");
if (gURLBar && gURLBar.value != gLastValidURLStr) {
SetPageProxyState("invalid", true);
}
}
/**
@@ -2813,8 +2817,12 @@ function UpdatePageProxyState() {
* related user interface elments should be shown because the URI in the
* location bar matches the loaded page. The string "invalid" indicates
* that the URI in the location bar is different than the loaded page.
* @param updatePopupNotifications
* Boolean that indicates whether we should update the PopupNotifications
* visibility due to this change, otherwise avoid doing so as it is being
* handled somewhere else.
*/
function SetPageProxyState(aState) {
function SetPageProxyState(aState, updatePopupNotifications) {
if (!gURLBar)
return;
@@ -2835,7 +2843,7 @@ function SetPageProxyState(aState) {
// After we've ensured that we've applied the listeners and updated the value
// of gLastValidURLStr, return early if the actual state hasn't changed.
if (oldPageProxyState == aState) {
if (oldPageProxyState == aState || !updatePopupNotifications) {
return;
}
@@ -4756,7 +4764,7 @@ var XULBrowserWindow = {
}
},
onLocationChange(aWebProgress, aRequest, aLocationURI, aFlags) {
onLocationChange(aWebProgress, aRequest, aLocationURI, aFlags, aIsSimulated) {
var location = aLocationURI ? aLocationURI.spec : "";
let pageTooltip = document.getElementById("aHTMLTooltip");
@@ -4808,7 +4816,11 @@ var XULBrowserWindow = {
this.reloadCommand.removeAttribute("disabled");
}
URLBarSetURI(aLocationURI);
// We want to update the popup visibility if we received this notification
// via simulated locationchange events such as switching between tabs, however
// if this is a document navigation then PopupNotifications will be updated
// via TabsProgressListener.onLocationChange and we do not want it called twice
URLBarSetURI(aLocationURI, aIsSimulated);
BookmarkingUI.onLocationChange();

View File

@@ -934,7 +934,7 @@ window._gBrowser = {
// Update the URL bar.
let webProgress = newBrowser.webProgress;
this._callProgressListeners(null, "onLocationChange",
[webProgress, null, newBrowser.currentURI, 0],
[webProgress, null, newBrowser.currentURI, 0, true],
true, false);
let securityUI = newBrowser.securityUI;

View File

@@ -11,6 +11,10 @@ support-files =
temporary_permissions_subframe.html
../webrtc/get_user_media.html
[browser_autoplay_blocked.js]
support-files =
browser_autoplay_blocked.html
../general/audio.ogg
[browser_autoplay_doorhanger.js]
support-files =
browser_autoplay_blocked.html
../general/audio.ogg

View File

@@ -0,0 +1,33 @@
/*
* Test that autoplay doorhanger is hidden when user clicks back to new tab page
*/
const AUTOPLAY_PAGE = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "https://example.com") + "browser_autoplay_blocked.html";
add_task(async function testHiddenAfterBack() {
Services.prefs.setIntPref("media.autoplay.default", Ci.nsIAutoplay.PROMPT);
await BrowserTestUtils.withNewTab("about:home", async function(browser) {
is(PopupNotifications.panel.state, "closed", "Doorhanger is hidden");
let shown = BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown");
let loaded = BrowserTestUtils.browserLoaded(browser);
BrowserTestUtils.loadURI(browser, AUTOPLAY_PAGE);
await loaded;
await shown;
is(PopupNotifications.panel.state, "open", "Doorhanger is shown");
let hidden = BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popuphidden");
let backPromise = BrowserTestUtils.browserStopped(browser);
EventUtils.synthesizeMouseAtCenter(document.getElementById("back-button"), {});
await backPromise;
await hidden;
is(PopupNotifications.panel.state, "closed", "Doorhanger is hidden");
});
Services.prefs.clearUserPref("media.autoplay.default");
});

View File

@@ -816,7 +816,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
// don't revert to last valid url unless page is NOT loading
// and user is NOT key-scrolling through autocomplete list
if (!XULBrowserWindow.isBusy && !isScrolling) {
URLBarSetURI();
URLBarSetURI(null, true);
// If the value isn't empty and the urlbar has focus, select the value.
if (this.value && this.hasAttribute("focused"))
@@ -1274,7 +1274,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
this.handleCommand(null, undefined, undefined, triggeringPrincipal);
// Force not showing the dropped URI immediately.
gBrowser.userTypedValue = null;
URLBarSetURI();
URLBarSetURI(null, true);
}
]]></body>
</method>

View File

@@ -577,7 +577,7 @@ async function test_tabNavigate() {
Services.perms.remove(makeURI("http://example.com/"), "install");
await loadPromise;
await removeTabAndWaitForNotificationClose();
await BrowserTestUtils.removeTab(gBrowser.selectedTab);
},
async function test_urlBar() {