tor-browser

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

test_play_twice.html (2383B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test playback of media files that should play OK</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 <pre id="test">
     11 <script class="testbody" type="text/javascript">
     12 
     13 var manager = new MediaTestManager;
     14 
     15 function startTest(test, token) {
     16  const video = document.createElement('video');
     17  video.token = token;
     18  manager.started(token);
     19  video.src = test.name;
     20  video.name = test.name;
     21  video.playingCount = 0;
     22  video._playedOnce = false;
     23 
     24  var check = function() {
     25    checkMetadata(test.name, video, test);
     26  };
     27 
     28  var noLoad = function() {
     29    ok(false, test.name + " should not fire 'load' event");
     30  };
     31 
     32  function finish(v) {
     33    removeNodeAndSource(v);
     34    manager.finished(v.token);
     35  }
     36 
     37  function mayFinish(v) {
     38    if (v.seenEnded && v.seenSuspend) {
     39      finish(v);
     40    }
     41  }
     42 
     43  var checkEnded = function() {
     44    if (test.duration) {
     45      ok(Math.abs(video.currentTime - test.duration) < 0.1,
     46         test.name + " current time at end: " + video.currentTime);
     47    }
     48 
     49    is(video.readyState, video.HAVE_CURRENT_DATA, test.name + " checking readyState");
     50    ok(video.ended, test.name + " checking playback has ended");
     51    ok(video.playingCount > 0, "Expect at least one playing event");
     52    video.playingCount = 0;
     53 
     54    if (video._playedOnce) {
     55      video.seenEnded = true;
     56      mayFinish(video);
     57    } else {
     58      video._playedOnce = true;
     59      video.play();
     60    }
     61  };
     62 
     63  var checkSuspended = function() {
     64    if (video.seenSuspend) {
     65      return;
     66    }
     67 
     68    video.seenSuspend = true;
     69    ok(true, test.name + " got suspend");
     70    mayFinish(video);
     71  };
     72 
     73  var checkPlaying = function() {
     74    is(test.name, video.name, "Should be testing file we think we're testing...");
     75    video.playingCount++;
     76  };
     77 
     78  video.addEventListener("load", noLoad);
     79  video.addEventListener("loadedmetadata", check);
     80  video.addEventListener("playing", checkPlaying);
     81 
     82  // We should get "ended" and "suspend" events for every resource
     83  video.addEventListener("ended", checkEnded);
     84  video.addEventListener("suspend", checkSuspended);
     85 
     86  document.body.appendChild(video);
     87  video.play();
     88 }
     89 
     90 manager.runTests(gReplayTests, startTest);
     91 
     92 </script>
     93 </pre>
     94 </body>
     95 </html>