Bug 1590479 - Reset notification UI state for PopupNotifications doorhangers without checkbox. r=nhnt11

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Johann Hofmann 2019-10-25 16:27:05 +00:00
parent 5f68f13a19
commit 64b16f5ca3
3 changed files with 86 additions and 14 deletions

View File

@ -31,7 +31,9 @@ var gTests = [
ok(!checkbox.checked, "checkbox not checked");
let indicator = promiseIndicatorWindow();
await promiseMessage("ok", () => notification.button.click());
await promiseMessage("ok", () =>
EventUtils.synthesizeMouseAtCenter(notification.button, {})
);
await expectObserverCalled("getUserMedia:response:allow");
await expectObserverCalled("recording-device-events");
Assert.deepEqual(
@ -48,6 +50,73 @@ var gTests = [
PermissionTestUtils.remove(origin, "microphone");
},
},
{
desc: "'Always Allow' disabled when sharing screen in third party iframes",
run: async function checkScreenSharing() {
let promise = promisePopupNotificationShown("webRTC-shareDevices");
await promiseRequestDevice(false, true, "frame1", "screen");
await promise;
await expectObserverCalled("getUserMedia:request");
checkDeviceSelectors(false, false, true);
let notification = PopupNotifications.panel.firstElementChild;
let iconclass = notification.getAttribute("iconclass");
ok(iconclass.includes("screen-icon"), "panel using screen icon");
// Ensure that the 'Remember this decision' checkbox is absent.
let checkbox = notification.checkbox;
ok(!!checkbox, "checkbox is present");
ok(checkbox.hidden, "checkbox is not visible");
ok(!checkbox.checked, "checkbox not checked");
let menulist = document.getElementById("webRTC-selectWindow-menulist");
let count = menulist.itemCount;
ok(
count >= 4,
"There should be the 'Select Window or Screen' item, a separator and at least one window and one screen"
);
let noWindowOrScreenItem = menulist.getItemAtIndex(0);
ok(
noWindowOrScreenItem.hasAttribute("selected"),
"the 'Select Window or Screen' item is selected"
);
is(
menulist.selectedItem,
noWindowOrScreenItem,
"'Select Window or Screen' is the selected item"
);
is(menulist.value, -1, "no window or screen is selected by default");
ok(
noWindowOrScreenItem.disabled,
"'Select Window or Screen' item is disabled"
);
ok(notification.button.disabled, "Allow button is disabled");
ok(
notification.hasAttribute("invalidselection"),
"Notification is marked as invalid"
);
menulist.getItemAtIndex(count - 1).doCommand();
ok(!notification.button.disabled, "Allow button is enabled");
let indicator = promiseIndicatorWindow();
await promiseMessage("ok", () =>
EventUtils.synthesizeMouseAtCenter(notification.button, {})
);
await expectObserverCalled("getUserMedia:response:allow");
await expectObserverCalled("recording-device-events");
Assert.deepEqual(
await getMediaCaptureState(),
{ screen: "Screen" },
"expected screen to be shared"
);
await indicator;
await checkSharingUI({ screen: "Screen" });
await closeStream(false, "frame1");
},
},
];
add_task(async function test() {

View File

@ -55,7 +55,7 @@ function closeStream() {
message("closed");
}
</script>
<iframe id="frame1" allow="camera;microphone" src="https://test1.example.com/browser/browser/base/content/test/webrtc/get_user_media.html"></iframe>
<iframe id="frame1" allow="camera;microphone;display-capture" src="https://test1.example.com/browser/browser/base/content/test/webrtc/get_user_media.html"></iframe>
<iframe id="frame2" allow="camera;microphone" src="https://test1.example.com/browser/browser/base/content/test/webrtc/get_user_media.html"></iframe>
</body>
</html>

View File

@ -1795,18 +1795,21 @@ PopupNotifications.prototype = {
let notificationEl = getNotificationFromElement(event.target);
let notification = notificationEl.notification;
if (notification.options.checkbox) {
if (notificationEl.checkbox.checked) {
this._setNotificationUIState(
notificationEl,
notification.options.checkbox.checkedState
);
} else {
this._setNotificationUIState(
notificationEl,
notification.options.checkbox.uncheckedState
);
}
if (!notification.options.checkbox) {
this._setNotificationUIState(notificationEl);
return;
}
if (notificationEl.checkbox.checked) {
this._setNotificationUIState(
notificationEl,
notification.options.checkbox.checkedState
);
} else {
this._setNotificationUIState(
notificationEl,
notification.options.checkbox.uncheckedState
);
}
},