diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/media/mediacontrol/tests/browser/browser_only_control_non_real_time_media.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/mediacontrol/tests/browser/browser_only_control_non_real_time_media.js')
-rw-r--r-- | dom/media/mediacontrol/tests/browser/browser_only_control_non_real_time_media.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/dom/media/mediacontrol/tests/browser/browser_only_control_non_real_time_media.js b/dom/media/mediacontrol/tests/browser/browser_only_control_non_real_time_media.js new file mode 100644 index 0000000000..76cf8b0ffd --- /dev/null +++ b/dom/media/mediacontrol/tests/browser/browser_only_control_non_real_time_media.js @@ -0,0 +1,76 @@ +const PAGE_URL = + "https://example.com/browser/dom/media/mediacontrol/tests/browser/file_empty_title.html"; + +/** + * This test is used to ensure that real-time media won't be affected by the + * media control. Only non-real-time media would. + */ +add_task(async function setupTestingPref() { + await SpecialPowers.pushPrefEnv({ + set: [["media.mediacontrol.testingevents.enabled", true]], + }); +}); + +add_task(async function testOnlyControlNonRealTimeMedia() { + const tab = await createLoadedTabWrapper(PAGE_URL); + const controller = tab.linkedBrowser.browsingContext.mediaController; + await StartRealTimeMedia(tab); + ok( + !controller.isActive, + "starting a real-time media won't acivate controller" + ); + + info(`playing a non-real-time media would activate controller`); + await Promise.all([ + new Promise(r => (controller.onactivated = r)), + startNonRealTimeMedia(tab), + ]); + + info(`'pause' action should only pause non-real-time media`); + MediaControlService.generateMediaControlKey("pause"); + await new Promise(r => (controller.onplaybackstatechange = r)); + await checkIfMediaAreAffectedByMediaControl(tab); + + info(`remove tab`); + await tab.close(); +}); + +async function startNonRealTimeMedia(tab) { + return SpecialPowers.spawn(tab.linkedBrowser, [], async _ => { + let video = content.document.getElementById("video"); + if (!video) { + ok(false, `can not get the video element!`); + return; + } + await video.play(); + }); +} + +async function StartRealTimeMedia(tab) { + return SpecialPowers.spawn(tab.linkedBrowser, [], async _ => { + let videoRealTime = content.document.createElement("video"); + content.document.body.appendChild(videoRealTime); + videoRealTime.srcObject = await content.navigator.mediaDevices.getUserMedia( + { audio: true, fake: true } + ); + // We want to ensure that the checking of should the media be controlled by + // media control would be performed after the element finishes loading the + // media stream. Using `autoplay` would trigger the play invocation only + // after the element get enough data. + videoRealTime.autoplay = true; + await new Promise(r => (videoRealTime.onplaying = r)); + }); +} + +async function checkIfMediaAreAffectedByMediaControl(tab) { + return SpecialPowers.spawn(tab.linkedBrowser, [], async _ => { + const vids = content.document.getElementsByTagName("video"); + for (let vid of vids) { + if (!vid.srcObject) { + ok(vid.paused, "non-real-time media should be paused"); + } else { + ok(!vid.paused, "real-time media should not be affected"); + } + } + }); +} |