diff options
Diffstat (limited to 'dom')
-rw-r--r-- | dom/events/test/test_eventTimeStamp.html | 36 | ||||
-rw-r--r-- | dom/performance/tests/mochitest.ini | 1 | ||||
-rw-r--r-- | dom/performance/tests/test_timeOrigin.html | 68 |
3 files changed, 86 insertions, 19 deletions
diff --git a/dom/events/test/test_eventTimeStamp.html b/dom/events/test/test_eventTimeStamp.html index 107a21f872..056203e920 100644 --- a/dom/events/test/test_eventTimeStamp.html +++ b/dom/events/test/test_eventTimeStamp.html @@ -17,7 +17,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=77992 <script type="text/js-worker" id="worker-src"> // Simply returns the event timestamp onmessage = function(evt) { - postMessage(evt.timeStamp); + postMessage(evt.timeStamp + performance.timeOrigin); } </script> <script type="text/js-worker" id="shared-worker-src"> @@ -25,7 +25,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=77992 onconnect = function(evt) { var port = evt.ports[0]; port.onmessage = function(messageEvt) { - port.postMessage(messageEvt.timeStamp); + port.postMessage(messageEvt.timeStamp + performance.timeOrigin); }; }; </script> @@ -57,9 +57,9 @@ function testRegularEvents() { finishTests(); return; } - var timeBeforeEvent = window.performance.now(); - window.addEventListener("load", function(evt) { - var timeAfterEvent = window.performance.now(); + var timeBeforeEvent = performance.now(); + addEventListener("load", function(evt) { + var timeAfterEvent = performance.now(); ok(evt.timeStamp >= timeBeforeEvent && evt.timeStamp <= timeAfterEvent, "Event timestamp (" + evt.timeStamp + ") is in expected range: (" + @@ -71,19 +71,18 @@ function testRegularEvents() { function testWorkerEvents() { var blob = new Blob([ document.getElementById("worker-src").textContent ], { type: "text/javascript" }); - var worker = new Worker(window.URL.createObjectURL(blob)); + var worker = new Worker(URL.createObjectURL(blob)); worker.onmessage = function(evt) { - var timeAfterEvent = window.performance.now(); - // Comparing times across timelines may break now - // ok(evt.data >= timeBeforeEvent && - // evt.data <= timeAfterEvent, + var timeAfterEvent = performance.now() + performance.timeOrigin; + ok(evt.data >= timeBeforeEvent && + evt.data <= timeAfterEvent, // "Event timestamp in dedicated worker (" + evt.data + // ") is in expected range: (" + // timeBeforeEvent + ", " + timeAfterEvent + ")"); worker.terminate(); testSharedWorkerEvents(); }; - var timeBeforeEvent = window.performance.now(); + var timeBeforeEvent = performance.now() + performance.timeOrigin; worker.postMessage(""); } @@ -93,17 +92,16 @@ function testSharedWorkerEvents() { { type: "text/javascript" }); // Delay creation of worker slightly so it is easier to distinguish // shared worker creation time from this document's navigation start - window.setTimeout(function() { - var timeBeforeWorkerCreation = window.performance.now(); - var worker = new SharedWorker(window.URL.createObjectURL(blob)); + setTimeout(function() { + var timeBeforeEvent = performance.now() + performance.timeOrigin; + var worker = new SharedWorker(URL.createObjectURL(blob)); worker.port.onmessage = function(evt) { - var timeAfterEvent = window.performance.now(); - // Comparing times across timelines may break now - // ok(evt.data >= 0 && - // evt.data <= timeAfterEvent - timeBeforeWorkerCreation, + var timeAfterEvent = performance.now() + performance.timeOrigin; + ok(evt.data >= timeBeforeEvent && + evt.data <= timeAfterEvent, // "Event timestamp in shared worker (" + evt.data + // ") is in expected range: (0, " + - // (timeAfterEvent - timeBeforeWorkerCreation) + ")"); + // timeBeforeEvent + ", " + timeAfterEvent + ")"); worker.port.close(); finishTests(); }; diff --git a/dom/performance/tests/mochitest.ini b/dom/performance/tests/mochitest.ini index 7005637e1b..bee0b2e700 100644 --- a/dom/performance/tests/mochitest.ini +++ b/dom/performance/tests/mochitest.ini @@ -13,3 +13,4 @@ support-files = [test_worker_observer.html] [test_sharedWorker_performance_user_timing.html] [test_worker_performance_now.html] +[test_timeOrigin.html] diff --git a/dom/performance/tests/test_timeOrigin.html b/dom/performance/tests/test_timeOrigin.html new file mode 100644 index 0000000000..5a8a461f30 --- /dev/null +++ b/dom/performance/tests/test_timeOrigin.html @@ -0,0 +1,68 @@ +<!DOCTYPE HTML> +<html> + <head> + <title>Test for performance.timeOrigin</title> + <meta http-equiv="content-type" content="text/html; charset=UTF-8"> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <script type="text/javascript" src="test_performance_user_timing.js"></script> + </head> + <body> + <script type="text/js-worker" id="worker-src"> + postMessage({ now: performance.now(), timeOrigin: performance.timeOrigin }); + </script> + + <script type="text/js-worker" id="shared-worker-src"> + onconnect = function(evt) { + evt.ports[0].postMessage({ now: performance.now(), timeOrigin: performance.timeOrigin }); + }; + </script> + + <script class="testbody" type="text/javascript"> + +function testBasic() { + ok("timeOrigin" in performance, "Performance.timeOrigin exists."); + ok(performance.timeOrigin > 0, "TimeOrigin must be greater than 0."); + next(); +} + +function testWorker() { + var now = performance.now(); + + var blob = new Blob([ document.getElementById("worker-src").textContent ], + { type: "text/javascript" }); + var w = new Worker(URL.createObjectURL(blob)); + w.onmessage = function(e) { + ok (e.now + e.timeOrigin > now + performance.now, "Comparing worker.now and window.now"); + next(); + } +} + +function testSharedWorker() { + var now = performance.now(); + + var blob = new Blob([ document.getElementById("shared-worker-src").textContent ], + { type: "text/javascript" }); + var w = new SharedWorker(URL.createObjectURL(blob)); + w.port.onmessage = function(e) { + ok (e.now + e.timeOrigin > now + performance.now, "Comparing worker.now and window.now"); + next(); + } +} + +var tests = [ testBasic, testWorker, testSharedWorker ]; +function next() { + if (!tests.length) { + SimpleTest.finish(); + return; + } + + var test = tests.shift(); + test(); +} + +SimpleTest.waitForExplicitFinish(); +addLoadEvent(next); + </script> + </pre> + </body> +</html> |