tor-browser

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

test_playback_hls.html (2523B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test playback of HLS with simple m3u8 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 var manager = new MediaTestManager;
     13 
     14 gTestPrefs.push(["media.hls.enabled", true]);
     15 
     16 function startTest(test, token) {
     17  const video = document.createElement('video');
     18  video.preload = "metadata";
     19  video.token = token;
     20  video.prevTime = 0;
     21  video.seenEnded = false;
     22 
     23  var handler = {
     24    "ontimeout": function() {
     25      Log(token, "timed out: ended=" + video.seenEnded);
     26    }
     27  };
     28  manager.started(token, handler);
     29 
     30  video.src = test.name;
     31  video.name = test.name;
     32 
     33  var check = function() {
     34    is(test.name, video.name, test.name + ": Name should match #1");
     35    checkMetadata(test.name, video, test);
     36  };
     37 
     38  var noLoad = function() {
     39    ok(false, test.name + " should not fire 'load' event");
     40  };
     41 
     42  var finish = function() {
     43    video.finished = true;
     44    video.removeEventListener("timeupdate", timeUpdate);
     45    removeNodeAndSource(video);
     46    manager.finished(video.token);
     47  };
     48 
     49  // We should get "ended" events to finish the test.
     50  var mayFinish = function() {
     51    if (video.seenEnded) {
     52      finish();
     53    }
     54  };
     55 
     56  var checkEnded = function() {
     57    is(test.name, video.name, test.name + ": Name should match #2");
     58    checkMetadata(test.name, video, test);
     59    is(video.readyState, video.HAVE_CURRENT_DATA, test.name + " checking readyState");
     60    ok(video.ended, test.name + " checking playback has ended");
     61    ok(!video.finished, test.name + " shouldn't be finished");
     62    ok(!video.seenEnded, test.name + " shouldn't be ended");
     63 
     64    video.seenEnded = true;
     65    mayFinish();
     66  };
     67 
     68  var timeUpdate = function() {
     69    if (video.prevTime > video.currentTime) {
     70      ok(false, test.name + " time should run forwards: p=" +
     71                video.prevTime + " c=" + video.currentTime);
     72    }
     73    video.prevTime = video.currentTime;
     74  };
     75 
     76  video.addEventListener("load", noLoad);
     77  video.addEventListener("loadedmetadata", check);
     78  video.addEventListener("timeupdate", timeUpdate);
     79 
     80  // We should get "ended" events for the hls resource
     81  video.addEventListener("ended", checkEnded);
     82 
     83  document.body.appendChild(video);
     84  video.play();
     85 }
     86 
     87 manager.runTests(gHLSTests, startTest);
     88 
     89 </script>
     90 </pre>
     91 </body>
     92 </html>