From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../browser_devices_get_user_media_tear_off_tab.js | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 browser/base/content/test/webrtc/browser_devices_get_user_media_tear_off_tab.js (limited to 'browser/base/content/test/webrtc/browser_devices_get_user_media_tear_off_tab.js') diff --git a/browser/base/content/test/webrtc/browser_devices_get_user_media_tear_off_tab.js b/browser/base/content/test/webrtc/browser_devices_get_user_media_tear_off_tab.js new file mode 100644 index 0000000000..ef69d15971 --- /dev/null +++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_tear_off_tab.js @@ -0,0 +1,100 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +var gTests = [ + { + desc: "getUserMedia: tearing-off a tab keeps sharing indicators", + skipObserverVerification: true, + run: async function checkTearingOff() { + await enableObserverVerification(); + + let promise = promisePopupNotificationShown("webRTC-shareDevices"); + let observerPromise = expectObserverCalled("getUserMedia:request"); + await promiseRequestDevice(true, true); + await promise; + await observerPromise; + checkDeviceSelectors(["microphone", "camera"]); + + let indicator = promiseIndicatorWindow(); + let observerPromise1 = expectObserverCalled( + "getUserMedia:response:allow" + ); + let observerPromise2 = expectObserverCalled("recording-device-events"); + await promiseMessage("ok", () => { + PopupNotifications.panel.firstElementChild.button.click(); + }); + await observerPromise1; + await observerPromise2; + Assert.deepEqual( + await getMediaCaptureState(), + { audio: true, video: true }, + "expected camera and microphone to be shared" + ); + + await indicator; + await checkSharingUI({ video: true, audio: true }); + + // Don't listen to observer notifications in the tab any more, as + // they will need to be switched to the new window. + await disableObserverVerification(); + + info("tearing off the tab"); + let win = gBrowser.replaceTabWithWindow(gBrowser.selectedTab); + await whenDelayedStartupFinished(win); + await checkSharingUI({ audio: true, video: true }, win); + + await enableObserverVerification(win.gBrowser.selectedBrowser); + + // Clicking the global sharing indicator should open the control center in + // the second window. + ok(permissionPopupHidden(win), "control center should be hidden"); + let activeStreams = webrtcUI.getActiveStreams(true, false, false); + webrtcUI.showSharingDoorhanger(activeStreams[0]); + // If the popup gets hidden before being shown, by stray focus/activate + // events, don't bother failing the test. It's enough to know that we + // started showing the popup. + let popup = win.gPermissionPanel._permissionPopup; + let hiddenEvent = BrowserTestUtils.waitForEvent(popup, "popuphidden"); + let shownEvent = BrowserTestUtils.waitForEvent(popup, "popupshown"); + let ev = await Promise.race([hiddenEvent, shownEvent]); + ok(ev.type, "Tried to show popup"); + win.gPermissionPanel._permissionPopup.hidePopup(); + + ok( + permissionPopupHidden(window), + "control center should be hidden in the first window" + ); + + await disableObserverVerification(); + + // Closing the new window should remove all sharing indicators. + let promises = [ + expectObserverCalledOnClose( + "recording-device-events", + 1, + win.gBrowser.selectedBrowser + ), + expectObserverCalledOnClose( + "recording-window-ended", + 1, + win.gBrowser.selectedBrowser + ), + ]; + + await BrowserTestUtils.closeWindow(win); + await Promise.all(promises); + await checkNotSharing(); + }, + }, +]; + +add_task(async function test() { + await SpecialPowers.pushPrefEnv({ set: [["dom.ipc.processCount", 1]] }); + + // An empty tab where we can load the content script without leaving it + // behind at the end of the test. + BrowserTestUtils.addTab(gBrowser); + + await runTests(gTests); +}); -- cgit v1.2.3