Bug 1611320 [wpt PR 21400] - Gate Longtasks and PaintTiming tests under assert_precon...
[gecko.git] / testing / web-platform / tests / workers / SharedWorkerPerformanceNow.html
bloba784293b342ff43cb97d252d57330cfae48d4805
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>window.performance.now in shared workers</title>
5 <script src="/resources/testharness.js"></script>
6 <script src="/resources/testharnessreport.js"></script>
7 </head>
8 <body>
9 <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');
21 setupIframe();
22 });
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');
28 t.done();
30 function setupIframe() {
31 const iframe = document.createElement('iframe');
32 document.body.appendChild(iframe);
33 const script = iframe.contentWindow.document.createElement('script');
34 script.innerHTML =
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);' +
39 '};' +
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');
45 </script>
46 </body>
47 </html>