OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset="utf-8" /> |
| 5 <title>window.performance.now in shared workers</title> |
| 6 <link rel="author" title="Google" href="http://www.google.com/" /> |
| 7 <link rel="help" href="https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HighRes
olutionTime2/Overview.html"/> |
| 8 <script src="/w3c/resources/testharness.js"></script> |
| 9 <script src="/w3c/resources/testharnessreport.js"></script> |
| 10 <script src="/w3c/webperf/resources/webperftestharness.js"></script> |
| 11 <link rel="stylesheet" href="/w3c/resources/testharness.css" /> |
| 12 <script> |
| 13 setup({explicit_done: true, timeout:10000}); |
| 14 |
| 15 var tests = [ |
| 16 '"performance" in self;', |
| 17 '"now" in self.performance;', |
| 18 'self.performance.now();', |
| 19 ]; |
| 20 |
| 21 var startTime = window.performance.now(); |
| 22 var worker = new SharedWorker("/w3c/webperf/resources/worker.js"); |
| 23 |
| 24 worker.port.onmessage = function(event) { |
| 25 var results = event.data; |
| 26 assert_true(results.length == 3); |
| 27 test_true(results[0], "self.performance is defined"); |
| 28 test_true(results[1], "self.performance.now is defined"); |
| 29 test_greater_than(startTime, results[2], "Time since origin time should be g
reater in the main document than the worker"); |
| 30 setupIframe(); |
| 31 } |
| 32 |
| 33 window.iframeStartTime = 0; |
| 34 window.test_iframe = function(event, iframeNow) { |
| 35 var workerTime = event.data; |
| 36 test_greater_than(workerTime, window.iframeStartTime, "Time since origin tim
e should be greater in the worker than the iframe", {}); |
| 37 worker.port.postMessage(["close();"]); |
| 38 done(); |
| 39 } |
| 40 |
| 41 function start() { |
| 42 worker.port.postMessage(tests); |
| 43 } |
| 44 |
| 45 function setupIframe() { |
| 46 var iframe = document.createElement("iframe"); |
| 47 var body = document.getElementsByTagName("body")[0]; |
| 48 body.appendChild(iframe); |
| 49 var script = iframe.contentWindow.document.createElement("script"); |
| 50 script.innerHTML = |
| 51 "window.top.iframeStartTime = window.performance.now();" + |
| 52 "var worker = new SharedWorker('/w3c/webperf/resources/worker.js');" + |
| 53 "worker.port.onmessage = function(event) {" + |
| 54 " window.top.test_iframe(event);" + |
| 55 "};" + |
| 56 "worker.port.postMessage(['self.performance.now();']);"; |
| 57 iframe.contentWindow.document.body.appendChild(script); |
| 58 } |
| 59 |
| 60 window.addEventListener("load", start); |
| 61 </script> |
| 62 </head> |
| 63 <body> |
| 64 <h1>Description</h1> |
| 65 <p>This test validates that performance.now() exists in shared workers and repor
ts reasonable times.</p> |
| 66 |
| 67 <div id="log"></div> |
| 68 |
| 69 </body> |
| 70 </html> |
OLD | NEW |