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_media_control_captured_audio.js | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 dom/media/mediacontrol/tests/browser/browser_media_control_captured_audio.js (limited to 'dom/media/mediacontrol/tests/browser/browser_media_control_captured_audio.js') diff --git a/dom/media/mediacontrol/tests/browser/browser_media_control_captured_audio.js b/dom/media/mediacontrol/tests/browser/browser_media_control_captured_audio.js new file mode 100644 index 0000000000..0da8acd62b --- /dev/null +++ b/dom/media/mediacontrol/tests/browser/browser_media_control_captured_audio.js @@ -0,0 +1,45 @@ +const PAGE_NON_AUTOPLAY_MEDIA = + "https://example.com/browser/dom/media/mediacontrol/tests/browser/file_non_autoplay.html"; + +const testVideoId = "video"; + +add_task(async function setupTestingPref() { + await SpecialPowers.pushPrefEnv({ + set: [["media.mediacontrol.testingevents.enabled", true]], + }); +}); + +/** + * When we capture audio from an media element to the web audio, if the media + * is audible, it should be controlled by media keys as well. + */ +add_task(async function testAudibleCapturedMedia() { + info(`open new non autoplay media page`); + const tab = await createLoadedTabWrapper(PAGE_NON_AUTOPLAY_MEDIA); + + info(`capture audio and start playing`); + await captureAudio(tab, testVideoId); + await playMedia(tab, testVideoId); + + info(`pressing 'pause' key, captured media should be paused`); + await generateMediaControlKeyEvent("pause"); + await checkOrWaitUntilMediaStoppedPlaying(tab, testVideoId); + + info(`remove tab`); + await tab.close(); +}); + +/** + * The following are helper functions. + */ +function captureAudio(tab, elementId) { + return SpecialPowers.spawn(tab.linkedBrowser, [elementId], Id => { + const video = content.document.getElementById(Id); + if (!video) { + ok(false, `can't get the media element!`); + } + const context = new content.AudioContext(); + // Capture audio from the media element to a MediaElementAudioSourceNode. + context.createMediaElementSource(video); + }); +} -- cgit v1.2.3