browser_seek_captured_audio.js (1855B)
1 const PAGE_NON_AUTOPLAY_MEDIA = 2 "https://example.com/browser/dom/media/mediacontrol/tests/browser/file_non_autoplay.html"; 3 4 const testVideoId = "video"; 5 6 add_task(async function setupTestingPref() { 7 await SpecialPowers.pushPrefEnv({ 8 set: [["media.mediacontrol.testingevents.enabled", true]], 9 }); 10 }); 11 12 /** 13 * Seeking a captured audio media before it starts, and it should still be able 14 * to be controlled via media key after it starts playing. 15 */ 16 add_task(async function testSeekAudibleCapturedMedia() { 17 info(`open new non autoplay media page`); 18 const tab = await createLoadedTabWrapper(PAGE_NON_AUTOPLAY_MEDIA); 19 20 info(`perform seek on the captured media before it starts`); 21 await captureAudio(tab, testVideoId); 22 await seekAudio(tab, testVideoId); 23 24 info(`start captured media`); 25 await playMedia(tab, testVideoId); 26 27 info(`pressing 'pause' key, captured media should be paused`); 28 await generateMediaControlKeyEvent("pause"); 29 await checkOrWaitUntilMediaStoppedPlaying(tab, testVideoId); 30 31 info(`remove tab`); 32 await tab.close(); 33 }); 34 35 /** 36 * The following are helper functions. 37 */ 38 function captureAudio(tab, elementId) { 39 return SpecialPowers.spawn(tab.linkedBrowser, [elementId], Id => { 40 const video = content.document.getElementById(Id); 41 if (!video) { 42 ok(false, `can't get the media element!`); 43 } 44 const context = new content.AudioContext(); 45 // Capture audio from the media element to a MediaElementAudioSourceNode. 46 context.createMediaElementSource(video); 47 }); 48 } 49 50 function seekAudio(tab, elementId) { 51 return SpecialPowers.spawn(tab.linkedBrowser, [elementId], async Id => { 52 const video = content.document.getElementById(Id); 53 if (!video) { 54 ok(false, `can't get the media element!`); 55 } 56 video.currentTime = 0.0; 57 await new Promise(r => (video.onseeked = r)); 58 }); 59 }