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>
9 <script type=
"text/js-worker" id=
"worker-src">
10 postMessage({ now: performance.now(), timeOrigin: performance.timeOrigin });
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 });
19 <script class=
"testbody" type=
"text/javascript">
21 function testBasic() {
22 ok(
"timeOrigin" in performance,
"Performance.timeOrigin exists.");
23 ok(performance.timeOrigin
> 0,
"TimeOrigin must be greater than 0.");
27 function testWorker() {
28 var now = performance.now();
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");
39 function testSharedWorker() {
40 var now = performance.now();
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");
51 var tests = [ testBasic, testWorker, testSharedWorker ];
54 SpecialPowers.setBoolPref(
"privacy.reduceTimerPrecision", reduceTimePrecisionPrevPrefValue);
59 var test = tests.shift();
63 SimpleTest.waitForExplicitFinish();
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);