4 <title>window.performance.now in shared workers
</title>
5 <script src=
"/resources/testharness.js"></script>
6 <script src=
"/resources/testharnessreport.js"></script>
10 async_test(function(t
) {
11 const worker
= new SharedWorker('support/WorkerSendingPerformanceNow.js');
12 worker
.port
.onmessage
= t
.step_func(event
=> {
13 const results
= event
.data
;
14 assert_true(results
.length
== 4);
15 assert_equals(results
[0], 'undefined',
16 'workerStart not defined on the Worker object');
17 assert_equals(results
[1], 'object', 'self.performance is defined');
18 assert_equals(results
[2], 'function', 'self.performance.now is defined');
19 assert_greater_than(results
[3], 0, 'Time in the worker should be positive');
20 assert_greater_than(window
.performance
.now(), results
[3], 'Time in the worker should be before the current time in the main document');
23 window
.iframeStartTime
= 0;
24 window
.test_iframe = function(event
) {
25 const workerTime
= event
.data
[3];
26 assert_greater_than(workerTime
, window
.iframeStartTime
,
27 'Time since origin time should be greater in the shared worker than the iframe');
30 function setupIframe() {
31 const iframe
= document
.createElement('iframe');
32 document
.body
.appendChild(iframe
);
33 const script
= iframe
.contentWindow
.document
.createElement('script');
35 'window.top.iframeStartTime = window.performance.now();' +
36 'const worker = new SharedWorker("support/WorkerSendingPerformanceNow.js");' +
37 'worker.port.onmessage = function(event) {' +
38 ' window.top.test_iframe(event);' +
40 'worker.port.postMessage("");';
41 iframe
.contentWindow
.document
.body
.appendChild(script
);
43 worker
.port
.postMessage('');
44 }, 'performance.now() exists in shared workers and reports reasonable times');