tor-browser

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

test_TruncatedDuration.html (2011B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>MSE: truncating the media seeks to end of media and update buffered range</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <script type="text/javascript" src="mediasource.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10 <pre id="test">
     11 <script class="testbody" type="text/javascript">
     12 
     13 // This test append data to a mediasource and then seek to half the duration
     14 // of the video.
     15 // We then shorten the video to 1/3rd of its original size by modifying the
     16 // mediasource.duration attribute.
     17 // We ensure that the buffered range immediately reflect the truncation
     18 // and that we've seeked to the new end of the media as per W3C spec and
     19 // video.currentTime got updated.
     20 
     21 SimpleTest.waitForExplicitFinish();
     22 
     23 const round = n => Math.round(n * 1000) / 1000;
     24 
     25 runWithMSE(async (ms, v) => {
     26  await once(ms, "sourceopen");
     27  const sb = ms.addSourceBuffer("video/webm");
     28 
     29  sb.appendBuffer(new Uint8Array(await fetchWithXHR("seek.webm")));
     30  await once(sb, "updateend");
     31  v.currentTime = v.duration / 2;
     32  is(v.currentTime, v.duration / 2, "current time was updated");
     33  ok(v.seeking, "seeking is true");
     34  await once(v, "seeked");
     35  const duration = round(v.duration / 3);
     36  is(sb.updating, false, "sourcebuffer isn't updating");
     37  sb.remove(duration, Infinity);
     38  await once(sb, "updateend");
     39  ms.duration = duration;
     40  // frames aren't truncated, so duration may be slightly more.
     41  isfuzzy(v.duration, duration, 1 / 30, "element duration was updated");
     42  sb.abort(); // this shouldn't abort updating the duration (bug 1130826).
     43  ok(v.seeking, "seeking is true");
     44  // test playback position was updated (bug 1130839).
     45  is(v.currentTime, v.duration, "current time was updated");
     46  is(sb.buffered.length, 1, "One buffered range");
     47  // Truncated mediasource duration will cause the video element to seek.
     48  await once(v, "seeking");
     49  SimpleTest.finish();
     50 });
     51 
     52 </script>
     53 </pre>
     54 </body>
     55 </html>