tor-browser

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

test_chaining.html (2872B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Media test: chained ogg files.</title>
      5  <meta charset='utf-8'>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8  <script type="text/javascript" src="manifest.js"></script>
      9 </head>
     10 <body>
     11 <pre id="test">
     12 <script class="testbody" type="text/javascript">
     13 var manager = new MediaTestManager;
     14 
     15 function finish_test(element) {
     16  removeNodeAndSource(element);
     17  manager.finished(element.token);
     18 }
     19 
     20 function onended(e) {
     21  var t = e.target;
     22  is(t._metadataCount, t._links, "We should have received "+ t._links +
     23     " metadataloaded event. " + t.src);
     24 
     25  // If we encounter a file that has links with a different numbers of channel,
     26  // we stop the decoding at the end of the first link. Hence, we report normal
     27  // |seekable| and |buffered| values.
     28  if (t._links != 1) {
     29    is(t.seekable.length, 0, "No seekable ranges should be reported." + t.src);
     30    is(t.buffered.length, 0, "No buffered region should be reported." + t.src);
     31  }
     32 
     33  is(t.played.length, 1, "The played region should be continuous." + t.src);
     34 
     35  if (t._links != 1) {
     36    var oldCurrentTime = t.currentTime;
     37    t.currentTime = 0.0;
     38    is(t.currentTime, oldCurrentTime,
     39        "Seeking should be disabled when playing chained media." + t.src);
     40  }
     41 
     42  finish_test(t);
     43 }
     44 
     45 function onmetadataloaded(e) {
     46  var t = e.target;
     47  if (! t._metadataCount) {
     48    t._metadataCount = 0;
     49  }
     50 
     51  if (t._metadataCount > 1 && t._links === 1) {
     52    ok(false, "We should receive only one \"loadedmetadata\" event for a chained file we don't support.")
     53  }
     54 
     55  // We should be able to assert equality here, but somehow it fails (rarely but
     56  // still) on try. Instead, we give it a little slack and assert that the index
     57  // increases monotonically.
     58  ok(t.mozGetMetadata().index >= t._metadataCount || t._links === 1,
     59     "The metadata index value should increase." + t.src);
     60 
     61  ok(t.currentTime >= t._prevCurrentTime,
     62     "The currenttime should be increased correctly in new chained part.");
     63  t._prevCurrentTime = t.currentTime;
     64 
     65  // The files have all a user comment name 'index' that increments at each link
     66  // in the chained media.
     67  t._metadataCount++;
     68  if (!t.playing && !t.ended) {
     69    t.play();
     70  }
     71 }
     72 
     73 function startTest(test, token) {
     74  var elemType = /^audio/.test(test.type) ? "audio" : "video";
     75  var element = document.createElement(elemType);
     76  document.body.appendChild(element);
     77  manager.started(token);
     78  element._links= test.links;
     79  element.src = test.name;
     80  element.token = token;
     81  element.controls = true;
     82  element.addEventListener("loadedmetadata", onmetadataloaded);
     83  element.addEventListener("ended", onended);
     84  element.preload = "metadata";
     85  element._prevCurrentTime = 0;
     86 }
     87 
     88 manager.runTests(gChainingTests, startTest);
     89 </script>
     90 </pre>
     91 </body>
     92 </html>