tor-browser

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

test_playback_and_bfcache.html (2534B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test media playback and bfcache</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
      8  <script>
      9    SimpleTest.requestFlakyTimeout("Need some timer to wait for the audio to play");
     10    SimpleTest.waitForExplicitFinish();
     11    var duration = 0;
     12 
     13    // The test opens a page and another page with a media element is loaded.
     14    // The media element plays an audio file and starts again and sends
     15    // statistics about it and then history.back() is called. The test waits
     16    // for 1s + duration of the audio file and goes forward. The audio playback
     17    // shouldn't have progressed while the page was in the bfcache.
     18    function test() {
     19      let bc1 = new BroadcastChannel("bc1");
     20      let pageshow1Count = 0;
     21      bc1.onmessage = function(e) {
     22        if (e.data == "pageshow") {
     23          ++pageshow1Count;
     24          info("Page 1 pageshow " + pageshow1Count);
     25          if (pageshow1Count == 1) {
     26            bc1.postMessage("loadNext");
     27          } else if (pageshow1Count == 2) {
     28            setTimeout(function() {
     29                bc1.postMessage("forward");
     30                bc1.close();
     31              }, (Math.round(duration) + 1) * 1000);
     32          }
     33        }
     34      };
     35 
     36      let bc2 = new BroadcastChannel("bc2");
     37      let pageshow2Count = 0;
     38      let statisticsCount = 0;
     39      bc2.onmessage = function(e) {
     40        if (e.data.event == "pageshow") {
     41          ++pageshow2Count;
     42          info("Page 2 pageshow " + pageshow2Count);
     43          if (pageshow2Count == 2) {
     44            ok(e.data.persisted, "Should have persisted the page.");
     45            bc2.postMessage("statistics");
     46          }
     47        } else {
     48          ++statisticsCount;
     49          if (statisticsCount == 1) {
     50            duration = e.data.duration;
     51            bc2.postMessage("back");
     52          } else {
     53            is(statisticsCount, 2, "Should got two play events.");
     54            ok(e.data.currentTime < e.data.duration,
     55               "Should have stopped the playback while the page was in bfcache." +
     56               "currentTime: " + e.data.currentTime + " duration: " + e.data.duration);
     57            bc2.close();
     58            SimpleTest.finish();
     59          }
     60        }
     61      };
     62 
     63      window.open("file_playback_and_bfcache.html", "", "noopener");
     64    }
     65  </script>
     66 </head>
     67 <body onload="test()">
     68 <p id="display"></p>
     69 <div id="content" style="display: none"></div>
     70 <pre id="test"></pre>
     71 </body>
     72 </html>