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_anim.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_anim.js | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js b/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js new file mode 100644 index 0000000000..dd20a672c3 --- /dev/null +++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js @@ -0,0 +1,106 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +var gTests = [ + { + desc: "device sharing animation on background tabs", + run: async function checkAudioVideo() { + async function getStreamAndCheckBackgroundAnim(aAudio, aVideo, aSharing) { + // Get a stream + let observerPromise = expectObserverCalled("getUserMedia:request"); + let popupPromise = promisePopupNotificationShown("webRTC-shareDevices"); + await promiseRequestDevice(aAudio, aVideo); + await popupPromise; + await observerPromise; + + let observerPromise1 = expectObserverCalled( + "getUserMedia:response:allow" + ); + let observerPromise2 = expectObserverCalled("recording-device-events"); + await promiseMessage("ok", () => { + PopupNotifications.panel.firstElementChild.button.click(); + }); + await observerPromise1; + await observerPromise2; + let expected = {}; + if (aVideo) { + expected.video = true; + } + if (aAudio) { + expected.audio = true; + } + Assert.deepEqual( + await getMediaCaptureState(), + expected, + "expected " + Object.keys(expected).join(" and ") + " to be shared" + ); + + // Check the attribute on the tab, and check there's no visible + // sharing icon on the tab + let tab = gBrowser.selectedTab; + is( + tab.getAttribute("sharing"), + aSharing, + "the tab has the attribute to show the " + aSharing + " icon" + ); + let icon = tab.sharingIcon; + is( + window.getComputedStyle(icon).display, + "none", + "the animated sharing icon of the tab is hidden" + ); + + // After selecting a new tab, check the attribute is still there, + // and the icon is now visible. + await BrowserTestUtils.switchTab( + gBrowser, + BrowserTestUtils.addTab(gBrowser) + ); + is( + gBrowser.selectedTab.getAttribute("sharing"), + "", + "the new tab doesn't have the 'sharing' attribute" + ); + is( + tab.getAttribute("sharing"), + aSharing, + "the tab still has the 'sharing' attribute" + ); + isnot( + window.getComputedStyle(icon).display, + "none", + "the animated sharing icon of the tab is now visible" + ); + + // Ensure the icon disappears when selecting the tab. + BrowserTestUtils.removeTab(gBrowser.selectedTab); + ok(tab.selected, "the tab with ongoing sharing is selected again"); + is( + window.getComputedStyle(icon).display, + "none", + "the animated sharing icon is gone after selecting the tab again" + ); + + // And finally verify the attribute is removed when closing the stream. + await closeStream(); + + // TODO(Bug 1304997): Fix the race in closeStream() and remove this + // TestUtils.waitForCondition(). + await TestUtils.waitForCondition(() => !tab.getAttribute("sharing")); + is( + tab.getAttribute("sharing"), + "", + "the tab no longer has the 'sharing' attribute after closing the stream" + ); + } + + await getStreamAndCheckBackgroundAnim(true, true, "camera"); + await getStreamAndCheckBackgroundAnim(false, true, "camera"); + await getStreamAndCheckBackgroundAnim(true, false, "microphone"); + }, + }, +]; + +add_task(async function test() { + await runTests(gTests); +}); |