From 98b640b8d99fd64bf4edbefae09abb6b6e5b98b5 Mon Sep 17 00:00:00 2001 From: Mike Conley Date: Fri, 17 Jul 2020 01:22:23 +0000 Subject: [PATCH] Bug 1649032 - Add a test that ensures that we stop all streams if the WebRTC indicator is closed. r=pbz Differential Revision: https://phabricator.services.mozilla.com/D82990 --- browser/base/content/test/webrtc/browser.ini | 1 + ...browser_stop_streams_on_indicator_close.js | 145 ++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 browser/base/content/test/webrtc/browser_stop_streams_on_indicator_close.js diff --git a/browser/base/content/test/webrtc/browser.ini b/browser/base/content/test/webrtc/browser.ini index 180238181e0a..dfdd7345e7d1 100644 --- a/browser/base/content/test/webrtc/browser.ini +++ b/browser/base/content/test/webrtc/browser.ini @@ -33,6 +33,7 @@ skip-if = (os == 'linux') # Bug 1503991 skip-if = (os == "win" && bits == 64) # win8: bug 1334752 [browser_devices_get_user_media_unprompted_access_queue_request.js] [browser_notification_silencing.js] +[browser_stop_streams_on_indicator_close.js] [browser_tab_switch_warning.js] [browser_webrtc_hooks.js] [browser_devices_get_user_media_queue_request.js] diff --git a/browser/base/content/test/webrtc/browser_stop_streams_on_indicator_close.js b/browser/base/content/test/webrtc/browser_stop_streams_on_indicator_close.js new file mode 100644 index 000000000000..714e7e15bb1a --- /dev/null +++ b/browser/base/content/test/webrtc/browser_stop_streams_on_indicator_close.js @@ -0,0 +1,145 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const TEST_ROOT = getRootDirectory(gTestPath).replace( + "chrome://mochitests/content/", + "https://example.com/" +); +const TEST_PAGE = TEST_ROOT + "get_user_media.html"; + +/** + * Given a browser from a tab in this window, chooses to share + * some combination of camera, mic or screen. + * + * @param { { + PopupNotifications.panel.firstElementChild.button.click(); + }); + + await observerPromise1; + await observerPromise2; + await promise; + } + + if (screen) { + let promise = promisePopupNotificationShown( + "webRTC-shareDevices", + null, + window + ); + + await promiseRequestDevice(false, true, null, "screen", browser); + await promise; + + checkDeviceSelectors(false, false, true, window); + + let document = window.document; + + // Select one of the windows / screens. It doesn't really matter which. + let menulist = document.getElementById("webRTC-selectWindow-menulist"); + menulist.getItemAtIndex(menulist.itemCount - 1).doCommand(); + let notification = window.PopupNotifications.panel.firstElementChild; + + let observerPromise1 = expectObserverCalled("getUserMedia:response:allow"); + let observerPromise2 = expectObserverCalled("recording-device-events"); + await promiseMessage( + "ok", + () => { + notification.button.click(); + }, + 1, + browser + ); + await observerPromise1; + await observerPromise2; + } +} + +/** + * Tests that if the indicator is closed somehow by the user when streams + * still ongoing, that all of those streams are stopped, and the most recent + * tab that a stream was shared with is selected. + */ +add_task(async function test_close_indicator() { + let prefs = [ + [PREF_PERMISSION_FAKE, true], + [PREF_AUDIO_LOOPBACK, ""], + [PREF_VIDEO_LOOPBACK, ""], + [PREF_FAKE_STREAMS, true], + [PREF_FOCUS_SOURCE, false], + ]; + await SpecialPowers.pushPrefEnv({ set: prefs }); + + let indicatorPromise = promiseIndicatorWindow(); + + info("Opening first tab"); + let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE); + info("Sharing camera, microphone and screen"); + await shareDevices(tab1.linkedBrowser, true, true, true); + + info("Opening second tab"); + let tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE); + info("Sharing camera and screen"); + await shareDevices(tab2.linkedBrowser, true, false, true); + + info("Opening third tab"); + let tab3 = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE); + info("Sharing screen"); + await shareDevices(tab3.linkedBrowser, false, false, true); + + info("Opening fourth tab"); + let tab4 = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "https://example.com" + ); + + Assert.equal( + gBrowser.selectedTab, + tab4, + "Most recently opened tab is selected" + ); + + let indicator = await indicatorPromise; + + indicator.close(); + + await checkNotSharing(); + + Assert.equal( + webrtcUI.activePerms.size, + 0, + "There shouldn't be any active stream permissions." + ); + + Assert.equal( + gBrowser.selectedTab, + tab3, + "Most recently tab that streams were shared with is selected" + ); + BrowserTestUtils.removeTab(tab1); + BrowserTestUtils.removeTab(tab2); + BrowserTestUtils.removeTab(tab3); + BrowserTestUtils.removeTab(tab4); +});