Bug 1459307 - Switching between menu options should maintain correct main action state when window sharing is requested. r=johannh
authorprathiksha <prathikshaprasadsuman@gmail.com>
Tue, 09 Oct 2018 14:38:36 +0000
changeset 499155 8d8c2a0e01b424c7719f76f553ff2923f1ddce69
parent 499154 29d9b2d2192d80733b6be89a31816d97ffda9163
child 499167 0de23e038872cb0986d7259e16ff966fcc050ae0
child 499168 c844033d55eb91acb4190ee202361b1b95062e0c
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1459307
milestone64.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 1459307 - Switching between menu options should maintain correct main action state when window sharing is requested. r=johannh Switching between menu options should maintain correct main action state when window sharing is requested. Differential Revision: https://phabricator.services.mozilla.com/D7742
browser/base/content/test/webrtc/browser_devices_get_user_media_screen.js
toolkit/modules/PopupNotifications.jsm
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_screen.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_screen.js
@@ -5,16 +5,17 @@
 // The rejection "The fetching process for the media resource was aborted by the
 // user agent at the user's request." is left unhandled in some cases. This bug
 // should be fixed, but for the moment this file is whitelisted.
 //
 // NOTE: Whitelisting a class of rejections should be limited. Normally you
 //       should use "expectUncaughtRejection" to flag individual failures.
 ChromeUtils.import("resource://testing-common/PromiseTestUtils.jsm", this);
 PromiseTestUtils.whitelistRejectionsGlobally(/aborted by the user agent/);
+ChromeUtils.import("resource:///modules/BrowserWindowTracker.jsm", this);
 
 const permissionError = "error: NotAllowedError: The request is not allowed " +
     "by the user agent or the platform in the current context.";
 
 const notFoundError =
     "error: NotFoundError: The object can not be found here.";
 
 var gTests = [
@@ -579,13 +580,44 @@ var gTests = [
       activateSecondaryAction(kActionDeny);
     });
     await expectObserverCalled("getUserMedia:response:deny");
     await expectObserverCalled("recording-window-ended");
     SitePermissions.remove(uri, "screen", browser);
   },
 },
 
+{
+  desc: "Switching between menu options maintains correct main action state while window sharing",
+  run: async function checkDoorhangerState() {
+    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 menulist = document.getElementById("webRTC-selectWindow-menulist");
+    let notification = PopupNotifications.panel.firstElementChild;
+    let checkbox = notification.checkbox;
+
+    menulist.getItemAtIndex(2).doCommand();
+    checkbox.click();
+    ok(checkbox.checked, "checkbox now checked");
+    ok(notification.button.disabled, "Allow button is disabled");
+    ok(!notification.hasAttribute("warninghidden"), "warning message is shown");
+
+    menulist.getItemAtIndex(3).doCommand();
+    ok(checkbox.checked, "checkbox still checked");
+    ok(notification.button.disabled, "Allow button remains disabled");
+    ok(!notification.hasAttribute("warninghidden"), "warning message is still shown");
+
+    win.close();
+  },
+},
+
 ];
 
 add_task(async function test() {
   await runTests(gTests);
 });
--- a/toolkit/modules/PopupNotifications.jsm
+++ b/toolkit/modules/PopupNotifications.jsm
@@ -1472,17 +1472,25 @@ PopupNotifications.prototype = {
     // Find notification like getNotificationFromElement but some nodes are non-anon
     while (notificationEl) {
       if (notificationEl.localName == "popupnotification") {
         break;
       }
       notificationEl =
         notificationEl.ownerDocument.getBindingParent(notificationEl) || notificationEl.parentNode;
     }
-    this._setNotificationUIState(notificationEl);
+
+    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);
+      }
+    }
   },
 
   _onButtonEvent(event, type, source = "button", notificationEl = null) {
     if (!notificationEl) {
       notificationEl = getNotificationFromElement(event.originalTarget);
     }
 
     if (!notificationEl)