tor-browser

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

test_NoAudioLoopBackData_Muted.html (3309B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>MSE: loop-back data not available yet (shorter MUTED audio)</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 <script class="testbody" type="text/javascript">
     11 
     12 /**
     13 * This test is used to check whether a looping video can loop back successfully
     14 * when it has a shorter MUTED audio track than its video track. When reaching
     15 * EOS for the shorter track, there is no loop-back data at the start position
     16 * (they are not appended yet) Even that, we should still be able to loop back
     17 * but the looping would become non-seamless in this situation.
     18 */
     19 SimpleTest.waitForExplicitFinish();
     20 
     21 runWithMSE(async (ms, el) => {
     22  await once(ms, "sourceopen");
     23  ok(true, "Receive a sourceopen event");
     24  const videosb = ms.addSourceBuffer("video/mp4");
     25  const audiosb = ms.addSourceBuffer("audio/mp4");
     26 
     27  // Here we create a shorter audio than video.
     28  info(`create different length source buffers`);
     29  await fetchAndLoad(videosb, "bipbop/bipbop_video", ["init"], ".mp4");
     30  await fetchAndLoad(videosb, "bipbop/bipbop_video", range(5, 8), ".m4s");
     31  audiosb.appendWindowEnd = videosb.buffered.end(0) - 0.2;
     32  await fetchAndLoad(audiosb, "bipbop/bipbop_audio", ["init"], ".mp4");
     33  await fetchAndLoad(audiosb, "bipbop/bipbop_audio", range(5, 8), ".m4s");
     34  ms.endOfStream();
     35  await Promise.all([once(el, "durationchange"), once(ms, "sourceended")]);
     36  info(`audio=[${audiosb.buffered.start(0)}-${audiosb.buffered.end(0)}], video=[${videosb.buffered.start(0)}-${videosb.buffered.end(0)}]`);
     37  ok(true, `endOfStream completed, buffer=[${el.buffered.start(0)}, ${el.buffered.end(0)}]`);
     38  ok(videosb.buffered.end(0) > audiosb.buffered.end(0), `video should be longer than audio`);
     39 
     40  info(`seek to the position where buffered data exists`);
     41  el.muted = true;
     42  el.loop = true;
     43  el.controls = true;
     44  el.currentTime = el.buffered.start(0);
     45  await el.play();
     46 
     47  info(`video should trigger seeking when reaching to the end`);
     48  let seekingCount = 0, seekedCount = 0;
     49  el.addEventListener("seeking", () => {
     50    is(++seekingCount, 1, "should only receive seeking once!");
     51  });
     52  el.addEventListener("seeked", () => {
     53    is(++seekedCount, 1, "should only receive seeked once!");
     54  });
     55  await once(el, "seeking");
     56 
     57  info(`trim old data before append new data`);
     58  let p = Promise.all([once(videosb, "updateend"), once(audiosb, "updateend")]);
     59  videosb.remove(videosb.buffered.start(0), videosb.buffered.end(0));
     60  audiosb.remove(audiosb.buffered.start(0), audiosb.buffered.end(0));
     61  await p;
     62 
     63  info(`append new data`);
     64  const seekedPromise = once(el, "seeked");
     65  p = Promise.all([once(videosb, "updateend"), once(audiosb, "updateend")]);
     66  await fetchAndLoad(videosb, "bipbop/bipbop_video", range(1, 2), ".m4s");
     67  await fetchAndLoad(audiosb, "bipbop/bipbop_audio", range(1, 2), ".m4s");
     68  await p;
     69  info(`audio=[${audiosb.buffered.start(0)}-${audiosb.buffered.end(0)}], video=[${videosb.buffered.start(0)}-${videosb.buffered.end(0)}]`);
     70 
     71  info(`now we should be able to finish seeking to the start position`);
     72  await seekedPromise;
     73 
     74  SimpleTest.finish(SimpleTest);
     75 });
     76 
     77 </script>
     78 </body>
     79 </html>