tor-browser

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

browser_media_control_keys_event.js (2125B)


      1 const PAGE =
      2  "https://example.com/browser/dom/media/mediacontrol/tests/browser/file_non_autoplay.html";
      3 const testVideoId = "video";
      4 
      5 /**
      6 * This test is used to generate platform-independent media control keys event
      7 * and see if media can be controlled correctly and current we only support
      8 * `play`, `pause`, `playPause` and `stop` events.
      9 */
     10 add_task(async function setupTestingPref() {
     11  await SpecialPowers.pushPrefEnv({
     12    set: [["media.mediacontrol.testingevents.enabled", true]],
     13  });
     14 });
     15 
     16 add_task(async function testPlayPauseAndStop() {
     17  info(`open page and start media`);
     18  const tab = await createLoadedTabWrapper(PAGE);
     19  await playMedia(tab, testVideoId);
     20 
     21  info(`pressing 'pause' key`);
     22  MediaControlService.generateMediaControlKey("pause");
     23  await checkOrWaitUntilMediaStoppedPlaying(tab, testVideoId);
     24 
     25  info(`pressing 'play' key`);
     26  MediaControlService.generateMediaControlKey("play");
     27  await checkOrWaitUntilMediaStartedPlaying(tab, testVideoId);
     28 
     29  info(`pressing 'stop' key`);
     30  MediaControlService.generateMediaControlKey("stop");
     31  await checkOrWaitUntilMediaStoppedPlaying(tab, testVideoId);
     32 
     33  info(`Has stopped controlling media, pressing 'play' won't resume it`);
     34  MediaControlService.generateMediaControlKey("play");
     35  await checkOrWaitUntilMediaStoppedPlaying(tab, testVideoId);
     36 
     37  info(`remove tab`);
     38  await tab.close();
     39 });
     40 
     41 add_task(async function testPlayPause() {
     42  info(`open page and start media`);
     43  const tab = await createLoadedTabWrapper(PAGE);
     44  await playMedia(tab, testVideoId);
     45 
     46  info(`pressing 'playPause' key, media should stop`);
     47  MediaControlService.generateMediaControlKey("playpause");
     48  await Promise.all([
     49    new Promise(r => (tab.controller.onplaybackstatechange = r)),
     50    checkOrWaitUntilMediaStoppedPlaying(tab, testVideoId),
     51  ]);
     52 
     53  info(`pressing 'playPause' key, media should start`);
     54  MediaControlService.generateMediaControlKey("playpause");
     55  await Promise.all([
     56    new Promise(r => (tab.controller.onplaybackstatechange = r)),
     57    checkOrWaitUntilMediaStartedPlaying(tab, testVideoId),
     58  ]);
     59 
     60  info(`remove tab`);
     61  await tab.close();
     62 });