2 dump("OK: " + !!a + " => " + a + ": " + msg + "\n");
3 postMessage({ type: "status", status: !!a, msg: a + ": " + msg });
6 function workerTestDone() {
7 postMessage({ type: "finish" });
10 ok(self.performance, "Performance object should exist.");
12 typeof self.performance.now == "function",
13 "Performance object should have a 'now' method."
15 var n = self.performance.now(),
17 ok(n >= 0, "The value of now() should be equal to or greater than 0.");
19 self.performance.now() >= n,
20 "The value of now() should monotonically increase."
23 // Spin on setTimeout() until performance.now() increases. Due to recent
24 // security developments, the hr-time working group has not yet reached
25 // consensus on what the recommend minimum clock resolution should be:
26 // https://w3c.github.io/hr-time/#clock-resolution
27 // Since setTimeout might return too early/late, our goal is for
28 // performance.now() to increase before a 2 ms deadline rather than specific
29 // number of setTimeout(N) invocations.
30 // See bug 749894 (intermittent failures of this test)
31 setTimeout(checkAfterTimeout, 1);
35 function checkAfterTimeout() {
38 var n2 = self.performance.now();
40 // Spin on setTimeout() until performance.now() increases. Abort the test
41 // if it runs for more than 2 ms or 50 timeouts.
42 let elapsedTime = d2 - d;
43 let elapsedPerf = n2 - n;
44 if (elapsedPerf == 0 && elapsedTime < 2 && checks < 50) {
45 setTimeout(checkAfterTimeout, 1);
49 // Our implementation provides 1 ms resolution (bug 1451790), but we
50 // can't assert that elapsedPerf >= 1 ms because this worker test runs with
51 // "privacy.reduceTimerPrecision" == false so performance.now() is not
52 // limited to 1 ms resolution.
55 `Loose - the value of now() should increase after 2ms. ` +
56 `delta now(): ${elapsedPerf} ms`
59 // If we need more than 1 iteration, then either performance.now() resolution
60 // is shorter than 1 ms or setTimeout() is returning too early.
63 `Strict - the value of now() should increase after one setTimeout. ` +
64 `iters: ${checks}, dt: ${elapsedTime}, now(): ${n2}`