tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_media_control_captured_audio.js (1434B)


      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 * When we capture audio from an media element to the web audio, if the media
     14 * is audible, it should be controlled by media keys as well.
     15 */
     16 add_task(async function testAudibleCapturedMedia() {
     17  info(`open new non autoplay media page`);
     18  const tab = await createLoadedTabWrapper(PAGE_NON_AUTOPLAY_MEDIA);
     19 
     20  info(`capture audio and start playing`);
     21  await captureAudio(tab, testVideoId);
     22  await playMedia(tab, testVideoId);
     23 
     24  info(`pressing 'pause' key, captured media should be paused`);
     25  await generateMediaControlKeyEvent("pause");
     26  await checkOrWaitUntilMediaStoppedPlaying(tab, testVideoId);
     27 
     28  info(`remove tab`);
     29  await tab.close();
     30 });
     31 
     32 /**
     33 * The following are helper functions.
     34 */
     35 function captureAudio(tab, elementId) {
     36  return SpecialPowers.spawn(tab.linkedBrowser, [elementId], Id => {
     37    const video = content.document.getElementById(Id);
     38    if (!video) {
     39      ok(false, `can't get the media element!`);
     40    }
     41    const context = new content.AudioContext();
     42    // Capture audio from the media element to a MediaElementAudioSourceNode.
     43    context.createMediaElementSource(video);
     44  });
     45 }