tor-browser

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

test_preload_suspend.html (2586B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for Bug 479863</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 function checkSuspendCount(evt) {
     15  var v = evt.target;
     16  ++v.suspendCount;
     17  is(v.networkState, v.NETWORK_IDLE, v.name + " got suspended, count=" + v.suspendCount);
     18  if (v.suspendCount == v.expectedSuspendCount) {
     19    removeNodeAndSource(v);
     20    manager.finished(v.name);
     21  }
     22  if (v.suspendCount > v.expectedSuspendCount) {
     23    ok(false, v.name + " got too many suspend events");
     24  }
     25 }
     26 
     27 var tests = [
     28  {
     29    name: 'v1',
     30    preload: 'none',
     31    expectedSuspendCount: 2,
     32    onsuspend(evt) {
     33      checkSuspendCount(evt);
     34      if (evt.target.suspendCount == 1) {
     35        evt.target.preload = 'auto';
     36      }
     37    }
     38  },
     39  {
     40    name: 'v2',
     41    preload: 'auto',
     42    expectedSuspendCount: 1,
     43    onsuspend: checkSuspendCount
     44  },
     45  {
     46    name: 'v3',
     47    preload: 'none',
     48    autoplay: true,
     49    expectedSuspendCount: 1,
     50    onsuspend: checkSuspendCount
     51  },
     52  {
     53    name: 'v4',
     54    preload: 'none',
     55    expectedSuspendCount: 2,
     56    onsuspend(evt) {
     57      checkSuspendCount(evt);
     58      if (evt.target.suspendCount == 1) {
     59        evt.target.play();
     60      }
     61    }
     62  },
     63  // disable v5 since media element doesn't support 'load' event anymore.
     64  /*{
     65    name: 'v5',
     66    preload: 'none',
     67    expectedSuspendCount: 2,
     68    onsuspend: function(evt) {
     69      checkSuspendCount(evt);
     70      if (evt.target.suspendCount == 1) {
     71        evt.target.currentTime = 0.1;
     72      }
     73    }
     74  },*/
     75  {
     76    name: 'v6',
     77    preload: 'none',
     78    expectedSuspendCount: 2,
     79    onsuspend(evt) {
     80      checkSuspendCount(evt);
     81      if (evt.target.suspendCount == 1) {
     82        evt.target.autoplay = true;
     83      }
     84    }
     85  }
     86 ];
     87 
     88 function startTest(test) {
     89  var v = document.createElement("video");
     90  v.name = test.name;
     91  var key = Math.random();
     92  v.src = "vp9.webm?key=" + key + "&id=" + v.name;
     93  v.preload = test.preload;
     94  v.suspendCount = 0;
     95  v.expectedSuspendCount = test.expectedSuspendCount;
     96  if (test.autoplay) {
     97    v.autoplay = true;
     98  }
     99  v.onsuspend = test.onsuspend;
    100  document.body.appendChild(v);
    101  manager.started(v.name);
    102 }
    103 
    104 SimpleTest.waitForExplicitFinish();
    105 SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]}, function() {
    106  manager.runTests(tests, startTest);
    107 });
    108 
    109 </script>
    110 </pre>
    111 </body>
    112 </html>