blob: 18c4e0dc327919361af8bdd730ba25904263ff97 [file] [log] [blame]
Daleed38a582017-12-14 08:43:201<!DOCTYPE html>
2<html>
3<head>
4 <title>time origin value manual test</title>
5 <link rel="help" href="https://w3c.github.io/hr-time/#time-origin-1">
6 <link rel="prefetch" href="./resources/unload-a.html">
7 <link rel="prefetch" href="./resources/unload-b.html">
8 <link rel="prefetch" href="./resources/unload-c.html">
9</head>
10<body>
11 <script src="/resources/testharness.js"></script>
12 <script src="/resources/testharnessreport.js"></script>
13 <script>
14 setup({ explicit_timeout: true });
15
16 const ACCEPTABLE_VARIANCE = 400; // ms
17
18 const isRoughlyEqual = (a, b) => Math.abs(a - b) < ACCEPTABLE_VARIANCE;
19
20 const timings = { a: {}, b: {}, c: {} };
21 const t = async_test("hr-time time origin");
22
23 window.mark = msg => {
24 timings[msg.docName][msg.lifecycleEventName] = {
25 performanceNow: msg.performanceNow,
26 dateNow: msg.dateNow
27 };
28
29 if (msg.docName === "c" && msg.lifecycleEventName === "unload") {
30 setTimeout(makeAssertions, 0);
31 }
32 };
33
34 function makeAssertions () {
35 t.step(() => {
36 const loadTimeBetweenAandB = timings.b.load.dateNow - timings.a.unload.dateNow;
37 const loadTimeBetweenBandC = timings.c.load.dateNow - timings.b.unload.dateNow;
38
39 assert_true(
40 isRoughlyEqual(loadTimeBetweenAandB, timings.b.load.performanceNow),
41 "Document in reused window's time origin should be time of close of pop-up box."
42 );
43 assert_true(
44 isRoughlyEqual(loadTimeBetweenBandC, timings.c.load.performanceNow),
45 "Document in reused window's time origin should be time of close of pop-up box."
46 );
47 assert_true(
48 !isRoughlyEqual(timings.a.unload.performanceNow, 0),
49 "Time origin during unload event should match that of rest of document."
50 );
51 assert_true(
52 !isRoughlyEqual(timings.b.unload.performanceNow, 0),
53 "Time origin during unload event should match that of rest of document."
54 );
55 assert_true(
56 !isRoughlyEqual(timings.c.unload.performanceNow, 0),
57 "Time origin during unload event should match that of rest of document."
58 );
59 });
60 t.done();
61 }
62 </script>
63
64 <h2>Description</h2>
65 <p>This test validates the behavior of <code>performance.now()</code> with respect to its time origin.</p>
66 <div id="log">
67 <h2>Manual Test Steps</h2>
68 <ol>
69 <li><a href="resources/unload-a.html" target="_blank">Click here</a>
70 </ol>
71 </div>
72</body>
73<html>