tor-browser

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

restriction-media-auto-play-attribute.https.html (2369B)


      1 <!DOCTYPE html>
      2 <!--
      3 The test aligns with the spec on which behavior is deferred. The test asserts
      4 that media resources are not loaded during prerendering, but it's possible the
      5 spec will allow loading and only disallow playback.
      6 -->
      7 <title>Access to the Autoplay of the Media is deferred</title>
      8 <meta name="variant" content="?target_hint=_self">
      9 <meta name="variant" content="?target_hint=_blank">
     10 <meta name="timeout" content="long">
     11 <script src="/resources/testharness.js"></script>
     12 <script src="/resources/testharnessreport.js"></script>
     13 <script src="/common/utils.js"></script>
     14 <script src="../resources/utils.js"></script>
     15 <script src="resources/utils.js"></script>
     16 
     17 <body>
     18 <script>
     19 setup(() => assertSpeculationRulesIsSupported());
     20 
     21 function RunTest(type, description) {
     22  promise_test(async t => {
     23    const uid = token();
     24    const bc = new PrerenderChannel('test-channel', uid);
     25    t.add_cleanup(_ => bc.close());
     26 
     27    const gotMessage = new Promise(resolve => {
     28      bc.addEventListener('message', e => {
     29        resolve(e.data);
     30      }, {
     31        once: true
     32      });
     33    });
     34    const url = `resources/media-autoplay-attribute.html?type=${type}&uid=${uid}&target_hint=${getTargetHint()}`;
     35    window.open(url, '_blank', 'noopener');
     36 
     37    const result = await gotMessage;
     38    const expected = [
     39      {
     40        event: 'started waiting Autoplay',
     41        prerendering: true
     42      },
     43      {
     44        event: 'prerendering change',
     45        prerendering: false
     46      },
     47      {
     48        event: 'fired loadedmetadata event after prerendering is activated',
     49        prerendering: false
     50      },
     51      {
     52        event: 'finished waiting Autoplay',
     53        prerendering: false
     54      },
     55    ];
     56    assert_equals(result.length, expected.length, `${type}`);
     57    for (let i = 0; i < result.length; i++) {
     58      assert_equals(result[i].event, expected[i].event, `event${i}`);
     59      assert_equals(result[i].prerendering, expected[i].prerendering,
     60          `prerendering${i}`);
     61    }
     62 
     63    // Send a close signal to PrerenderEventCollector on the prerendered page.
     64    new PrerenderChannel('close', uid).postMessage('');
     65  }, description);
     66 }
     67 
     68 RunTest('audio', `autoplay of the audio media should be deferred until the prerendered page is activated`);
     69 
     70 RunTest('video', `autoplay of the video media should be deferred until the prerendered page is activated`);
     71 </script>