tor-browser

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

test_streams_element_capture_twice.html (2952B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test that capturing a media element, then reloading and capturing again, works</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7  <script type="text/javascript" src="manifest.js"></script>
      8 </head>
      9 <body>
     10 <video id="v"></video>
     11 <pre id="test">
     12 <script class="testbody" type="text/javascript">
     13 SimpleTest.waitForExplicitFinish();
     14 
     15 const v = document.getElementById('v');
     16 
     17 function dumpEvent(event) {
     18  const video = event.target;
     19  info(video.name + " GOT EVENT " + event.type +
     20       " currentTime=" + video.currentTime +
     21       " paused=" + video.paused +
     22       " ended=" + video.ended +
     23       " readyState=" + video.readyState);
     24 }
     25 
     26 const events = ["timeupdate", "seeking", "seeked", "ended", "playing", "pause"];
     27 for (let i = 0; i < events.length; ++i) {
     28  v.addEventListener(events[i], dumpEvent);
     29 }
     30 
     31 async function startTest(src) {
     32  v.preload = "metadata";
     33  v.src = src;
     34  await new Promise(r => v.onloadedmetadata = r);
     35  const s1 = v.mozCaptureStream();
     36  const tracks = s1.getTracks();
     37  is(tracks.length, 2, "Expected total tracks, s1, capture 1");
     38  is(s1.getAudioTracks().length, 1, "Expected audio tracks, s1, capture 1");
     39  is(s1.getVideoTracks().length, 1, "Expected video tracks, s1, capture 1");
     40  is(s1.getAudioTracks()[0].readyState, "live", "Live audio, s1, capture 1");
     41  is(s1.getVideoTracks()[0].readyState, "live", "Live video, s1, capture 1");
     42 
     43  v.src = null;
     44  for (let i = 0; i < tracks.length; ++i) {
     45    await Promise.race(tracks.map(t => new Promise(r => t.onended = r)));
     46    await new Promise(r => s1.onremovetrack = r);
     47  }
     48  is(s1.getTracks().length, 0, "Expected total tracks, s1, metadata 2");
     49 
     50  v.src = src;
     51  await new Promise(r => v.onloadedmetadata = r);
     52  is(s1.getTracks().length, 2, "Expected total tracks, s1, metadata 2");
     53  is(s1.getAudioTracks().length, 1, "Expected audio tracks, s1, metadata 2");
     54  is(s1.getVideoTracks().length, 1, "Expected video tracks, s1, metadata 2");
     55  is(s1.getAudioTracks()[0].readyState, "live", "Live audio, s1, metadata 2");
     56  is(s1.getVideoTracks()[0].readyState, "live", "Live video, s1, metadata 2");
     57 
     58  const s2 = v.mozCaptureStream();
     59  is(s1.getTracks().length, 2, "Expected total tracks remains, s1, capture 2");
     60  is(s2.getTracks().length, 2, "Expected total tracks, s2, capture 2");
     61  is(s2.getAudioTracks().length, 1, "Expected audio tracks, s2, capture 2");
     62  is(s2.getVideoTracks().length, 1, "Expected video tracks, s2, capture 2");
     63  is(s2.getAudioTracks()[0].readyState, "live", "Live audio, s2, capture 2");
     64  is(s2.getVideoTracks()[0].readyState, "live", "Live video, s2, capture 2");
     65 }
     66 
     67 (async function() {
     68  try {
     69    await startTest("vp9cake.webm");
     70  } catch(e) {
     71    ok(false, `Caught error: ${e}${e.stack ? '\n' + e.stack : ''}`);
     72  } finally {
     73    SimpleTest.finish();
     74  }
     75 })();
     76 </script>
     77 </pre>
     78 </body>
     79 </html>