Bug 1580319 - Clear PopupNotifications UI state when no checkbox is present. r=prathiksha

In getUserMedia we didn't use to have prompts without a checkbox, thus this bug couldn't manifest.
Now we do hide the checkbox for iframes, so this code path is triggered and doesn't properly
reset the UI state between prompts.

Differential Revision: https://phabricator.services.mozilla.com/D45911

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Johann Hofmann 2019-09-16 09:44:07 +00:00
Родитель e00e2efe68
Коммит ff1911cf74
4 изменённых файлов: 50 добавлений и 13 удалений

Просмотреть файл

@ -715,14 +715,6 @@ var gXPInstallObserver = {
options.sourceURI = browser.currentURI;
options.eventCallback = function(aEvent) {
switch (aEvent) {
case "shown":
let notificationElement = [...this.owner.panel.children].find(
n => n.notification == this
);
if (notificationElement) {
notificationElement.setAttribute("mainactiondisabled", "true");
}
break;
case "removed":
options.contentWindow = null;
options.sourceURI = null;
@ -734,6 +726,7 @@ var gXPInstallObserver = {
accessKey: gNavigatorBundle.getString(
"addonInstall.acceptButton2.accesskey"
),
disabled: true,
callback: () => {},
};
let secondaryAction = {

Просмотреть файл

@ -784,7 +784,43 @@ var gTests = [
"warning message is still shown"
);
gBrowser.removeCurrentTab();
win.close();
await openNewTestTab();
},
},
{
desc: "Switching between tabs does not bleed state into other prompts",
run: async function checkSwitchingTabs() {
// Open a new window in the background to have a choice in the menulist.
let win = await BrowserTestUtils.openNewBrowserWindow();
await BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:newtab");
BrowserWindowTracker.orderedWindows[1].focus();
let promise = promisePopupNotificationShown("webRTC-shareDevices");
await promiseRequestDevice(false, true, null, "window");
await promise;
await expectObserverCalled("getUserMedia:request");
let notification = PopupNotifications.panel.firstElementChild;
ok(notification.button.disabled, "Allow button is disabled");
await openNewTestTab("get_user_media_in_xorigin_frame.html");
promise = promisePopupNotificationShown("webRTC-shareDevices");
await promiseRequestDevice(true, true, "frame1");
await promise;
await expectObserverCalled("getUserMedia:request");
notification = PopupNotifications.panel.firstElementChild;
ok(!notification.button.disabled, "Allow button is not disabled");
gBrowser.removeCurrentTab();
gBrowser.removeCurrentTab();
win.close();
await openNewTestTab();
},
},
];

Просмотреть файл

@ -663,21 +663,24 @@ function promiseReloadFrame(aFrameId) {
});
}
async function runTests(tests, options = {}) {
let leaf = options.relativeURI || "get_user_media.html";
async function openNewTestTab(leaf = "get_user_media.html") {
let rootDir = getRootDirectory(gTestPath);
rootDir = rootDir.replace(
"chrome://mochitests/content/",
"https://example.com/"
);
let absoluteURI = rootDir + leaf;
let cleanup = options.cleanup || (() => expectNoObserverCalled());
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, absoluteURI);
let browser = tab.linkedBrowser;
browser.messageManager.loadFrameScript(CONTENT_SCRIPT_HELPER, true);
return browser;
}
async function runTests(tests, options = {}) {
let cleanup = options.cleanup || (() => expectNoObserverCalled());
let browser = await openNewTestTab(options.relativeURI);
is(
PopupNotifications._currentNotifications.length,

Просмотреть файл

@ -404,6 +404,8 @@ PopupNotifications.prototype = {
* - "menucommand" if a menu was activated.
* - [optional] dismiss (boolean): If this is true, the notification
* will be dismissed instead of removed after running the callback.
* - [optional] disabled (boolean): If this is true, the button
* will be disabled.
* - [optional] disableHighlight (boolean): If this is true, the button
* will not apply the default highlight style.
* If null, the notification will have a default "OK" action button
@ -1138,7 +1140,8 @@ PopupNotifications.prototype = {
}
} else {
popupnotification.checkboxState = null;
popupnotification.setAttribute("warninghidden", "true");
// Reset the UI state to avoid previous state bleeding into this prompt.
this._setNotificationUIState(popupnotification);
}
this.panel.appendChild(popupnotification);
@ -1153,7 +1156,9 @@ PopupNotifications.prototype = {
},
_setNotificationUIState(notification, state = {}) {
let mainAction = notification.notification.mainAction;
if (
(mainAction && mainAction.disabled) ||
state.disableMainAction ||
notification.hasAttribute("invalidselection")
) {