tor-browser

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

file_autoplay_gv_play_request_window.html (2204B)


      1 <!DOCTYPE HTML>
      2 <html>
      3  <head>
      4    <title>GV autoplay play request test</title>
      5    <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6    <script src="/tests/SimpleTest/EventUtils.js"></script>
      7    <script type="text/javascript" src="manifest.js"></script>
      8    <script type="text/javascript" src="AutoplayTestUtils.js"></script>
      9  </head>
     10 <body>
     11 <script>
     12 /**
     13 * The test info sent from the parent window will determine what kinds of media
     14 * should start, where it should start, the result of the play request and
     15 * whether the document is activated by user gesture.
     16 */
     17 nextWindowMessage().then(
     18  async (event) => {
     19    let testInfo = event.data;
     20    testInfo.parentWindow = event.source;
     21    await setupTestEnvironment(testInfo);
     22    await startPlaybackAndReturnMessage(testInfo);
     23  });
     24 
     25 /**
     26 * The following are helper functions.
     27 */
     28 async function setupTestEnvironment(testInfo) {
     29  if (testInfo.activatedDocument != undefined) {
     30    info(`activate document`);
     31    SpecialPowers.wrap(document).notifyUserGestureActivation();
     32  }
     33  if (testInfo.iframe != undefined) {
     34    info(`create child frame`);
     35    testInfo.childFrame = await createChildFrame(testInfo);
     36  }
     37 }
     38 
     39 async function createChildFrame(testInfo) {
     40  let frame = document.createElement("iframe");
     41  let origin = testInfo.iframe == "same-orgin"
     42    ? "http://mochi.test:8888" : "http://example.org";
     43  frame.src = origin + "/tests/dom/media/autoplay/test/mochitest/file_autoplay_gv_play_request_frame.html";
     44  document.body.appendChild(frame);
     45  info(`waiting for iframe loading`);
     46  is((await nextWindowMessage()).data, "ready", "iframe has finished loading");
     47  return frame;
     48 }
     49 
     50 async function startPlaybackAndReturnMessage({muted, iframe, parentWindow, childFrame}) {
     51  if (iframe == undefined) {
     52    info(`start playback`);
     53    playAndPostResult(muted, parentWindow);
     54  } else {
     55    info("start autoplay from " +  (iframe == "same-origin" ? "same" : "cross")  + " origin child frame");
     56    childFrame.contentWindow.postMessage("play", "*");
     57    info(`waiting for media calling play from child frame`);
     58    let result = await nextWindowMessage();
     59    parentWindow.postMessage(result.data, "*");
     60  }
     61 }
     62 
     63 </script>
     64 </body>
     65 </html>