tor-browser

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

test_timeupdate_small_files.html (2761B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=495319
      5 -->
      6 
      7 <head>
      8  <title>Bug 495319 - playing back small audio files should fire timeupdate</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11  <script type="text/javascript" src="manifest.js"></script>
     12 </head>
     13 <body>
     14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=495319">Mozilla Bug 495319</a>
     15 <pre id="test">
     16 <script class="testbody" type="text/javascript">
     17 
     18 var manager = new MediaTestManager;
     19 
     20 function ended(e) {
     21  var v = e.target;
     22  ++v.counter.ended;
     23  is(v.counter.ended, 1, v._name + " should see ended only once");
     24  ok(v.counter.timeupdate > 0, v._name + " should see at least one timeupdate: " + v.currentTime);
     25 
     26  // Rest event counters for we don't allow events after ended.
     27  eventsToLog.forEach(function(event) {
     28    v.counter[event] = 0;
     29  });
     30 
     31  // Finish the test after 500ms. We shouldn't receive any timeupdate events
     32  // after the ended event, so this gives time for any pending timeupdate events
     33  // to fire so we can ensure we don't regress behaviour.
     34  setTimeout(
     35    function() {
     36      // Remove the event listeners before removing the video from the document.
     37      // We should receive a timeupdate and pause event when we remove the element
     38      // from the document (as the element is specified to behave as if pause() was
     39      // invoked when it's removed from a document), and we don't want those
     40      // confusing the test results.
     41      v.removeEventListener("ended", ended);
     42      eventsToLog.forEach(function(event) {
     43        v.removeEventListener(event, logEvent);
     44      });
     45      removeNodeAndSource(v);
     46      manager.finished(v.token);
     47    },
     48    500);
     49 }
     50 
     51 var eventsToLog = ["play", "canplay", "canplaythrough", "loadstart", "loadedmetadata",
     52  "loadeddata", "playing", "timeupdate", "error", "stalled", "emptied", "abort",
     53  "waiting", "pause"];
     54 
     55 function logEvent(event) {
     56  var v = event.target;
     57  ++v.counter[event.type];
     58  if (v.counter.ended > 0) {
     59    is(v.counter[event.type], 0, v._name + " got unexpected " + event.type + " after ended");
     60  }
     61 }
     62 
     63 function startTest(test, token) {
     64  var type = getMajorMimeType(test.type);
     65  var v = document.createElement(type);
     66  v.token = token;
     67  manager.started(token);
     68  v.src = test.name;
     69  v._name = test.name;
     70 
     71  // Keep how many events received for each event type.
     72  v.counter = {};
     73  eventsToLog.forEach(function(e) {
     74    v.addEventListener(e, logEvent);
     75    v.counter[e] = 0;
     76  });
     77  v.addEventListener("ended", ended);
     78  v.counter.ended = 0;
     79  document.body.appendChild(v);
     80  v.play();
     81 }
     82 
     83 manager.runTests(gSmallTests, startTest);
     84 
     85 </script>
     86 </pre>
     87 </body>
     88 </html>