diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/base/content/test/webrtc/browser_devices_get_user_media_screen_tab_close.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | browser/base/content/test/webrtc/browser_devices_get_user_media_screen_tab_close.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/browser/base/content/test/webrtc/browser_devices_get_user_media_screen_tab_close.js b/browser/base/content/test/webrtc/browser_devices_get_user_media_screen_tab_close.js new file mode 100644 index 0000000000..334397d58e --- /dev/null +++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_screen_tab_close.js @@ -0,0 +1,72 @@ +/* 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"; + +/** + * Tests that the given tab is the currently selected tab. + * @param {Element} aTab - Tab to test. + */ +function testSelected(aTab) { + is(aTab, gBrowser.selectedTab, "Tab is gBrowser.selectedTab"); + ok(aTab.hasAttribute("selected"), "Tab has attribute 'selected'"); + ok( + aTab.hasAttribute("visuallyselected"), + "Tab has attribute 'visuallyselected'" + ); +} + +/** + * Tests that when closing a tab with active screen sharing, the screen sharing + * ends and the tab closes properly. + */ +add_task(async function testScreenSharingTabClose() { + let initialTab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "https://example.com" + ); + + // Open another foreground tab and ensure its selected. + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE); + testSelected(tab); + + // Start screen sharing in active tab + await shareDevices(tab.linkedBrowser, false, false, SHARE_WINDOW); + ok(tab._sharingState.webRTC.screen, "Tab has webRTC screen sharing state"); + + let recordingEndedPromise = expectObserverCalled( + "recording-window-ended", + 1, + tab.linkedBrowser.browsingContext + ); + let tabClosedPromise = BrowserTestUtils.waitForCondition( + () => gBrowser.selectedTab == initialTab, + "Waiting for tab to close" + ); + + // Close tab + BrowserTestUtils.removeTab(tab, { animate: true }); + + // Wait for screen sharing to end + await recordingEndedPromise; + + // Wait for tab to be fully closed + await tabClosedPromise; + + // Test that we're back to the initial tab. + testSelected(initialTab); + + // There should be no active sharing for the selected tab. + ok( + !gBrowser.selectedTab._sharingState?.webRTC?.screen, + "Selected tab doesn't have webRTC screen sharing state" + ); + + BrowserTestUtils.removeTab(initialTab); +}); |