tor-browser

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

test_timeOrigin.html (2468B)


      1 <!DOCTYPE HTML>
      2 <html>
      3  <head>
      4    <title>Test for performance.timeOrigin</title>
      5    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      6    <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  </head>
      8  <body>
      9    <script type="text/js-worker" id="worker-src">
     10      postMessage({ now: performance.now(), timeOrigin: performance.timeOrigin });
     11    </script>
     12 
     13    <script type="text/js-worker" id="shared-worker-src">
     14      onconnect = function(evt) {
     15        evt.ports[0].postMessage({ now: performance.now(), timeOrigin: performance.timeOrigin });
     16      };
     17    </script>
     18 
     19    <script class="testbody" type="text/javascript">
     20 
     21 function testBasic() {
     22  ok("timeOrigin" in performance, "Performance.timeOrigin exists.");
     23  ok(performance.timeOrigin > 0, "TimeOrigin must be greater than 0.");
     24  next();
     25 }
     26 
     27 function testWorker() {
     28  var now = performance.now();
     29 
     30  var blob = new Blob([ document.getElementById("worker-src").textContent ],
     31                      { type: "text/javascript" });
     32  var w = new Worker(URL.createObjectURL(blob));
     33  w.onmessage = function(e) {
     34    ok (e.data.now + e.data.timeOrigin > now + performance.timeOrigin, "Comparing worker.now and window.now");
     35    next();
     36  }
     37 }
     38 
     39 function testSharedWorker() {
     40  var now = performance.now();
     41 
     42  var blob = new Blob([ document.getElementById("shared-worker-src").textContent ],
     43                      { type: "text/javascript" });
     44  var w = new SharedWorker(URL.createObjectURL(blob));
     45  w.port.onmessage = function(e) {
     46    ok (e.data.now + e.data.timeOrigin > now + performance.timeOrigin, "Comparing worker.now and window.now");
     47    next();
     48  }
     49 }
     50 
     51 var tests = [ testBasic, testWorker, testSharedWorker ];
     52 function next() {
     53  if (!tests.length) {
     54    SpecialPowers.setBoolPref("privacy.reduceTimerPrecision", reduceTimePrecisionPrevPrefValue);
     55    SimpleTest.finish();
     56    return;
     57  }
     58 
     59  var test = tests.shift();
     60  test();
     61 }
     62 
     63 SimpleTest.waitForExplicitFinish();
     64 
     65 // It is a known issue that comparing time between a worker and a window
     66 // when timer clamping is in effect may cause time to go backwards.
     67 // Do not run this test with this preference set. For large values of
     68 // clamping you will see failures. For small values, it is intermitant.
     69 var reduceTimePrecisionPrevPrefValue = SpecialPowers.getBoolPref("privacy.reduceTimerPrecision");
     70 SpecialPowers.setBoolPref("privacy.reduceTimerPrecision", false);
     71 
     72 addLoadEvent(next);
     73      </script>
     74    </pre>
     75  </body>
     76 </html>