summaryrefslogtreecommitdiffstats
path: root/dom/media/mediacontrol/tests/browser/browser_seek_captured_audio.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /dom/media/mediacontrol/tests/browser/browser_seek_captured_audio.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/mediacontrol/tests/browser/browser_seek_captured_audio.js')
-rw-r--r--dom/media/mediacontrol/tests/browser/browser_seek_captured_audio.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/dom/media/mediacontrol/tests/browser/browser_seek_captured_audio.js b/dom/media/mediacontrol/tests/browser/browser_seek_captured_audio.js
new file mode 100644
index 0000000000..3dbbee065e
--- /dev/null
+++ b/dom/media/mediacontrol/tests/browser/browser_seek_captured_audio.js
@@ -0,0 +1,59 @@
+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]],
+ });
+});
+
+/**
+ * Seeking a captured audio media before it starts, and it should still be able
+ * to be controlled via media key after it starts playing.
+ */
+add_task(async function testSeekAudibleCapturedMedia() {
+ info(`open new non autoplay media page`);
+ const tab = await createLoadedTabWrapper(PAGE_NON_AUTOPLAY_MEDIA);
+
+ info(`perform seek on the captured media before it starts`);
+ await captureAudio(tab, testVideoId);
+ await seekAudio(tab, testVideoId);
+
+ info(`start captured media`);
+ 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);
+ });
+}
+
+function seekAudio(tab, elementId) {
+ return SpecialPowers.spawn(tab.linkedBrowser, [elementId], async Id => {
+ const video = content.document.getElementById(Id);
+ if (!video) {
+ ok(false, `can't get the media element!`);
+ }
+ video.currentTime = 0.0;
+ await new Promise(r => (video.onseeked = r));
+ });
+}