diff options
author | Moonchild <mcwerewolf@gmail.com> | 2018-04-29 14:44:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-29 14:44:39 +0200 |
commit | 64aec5a353b4eb58e075c01b2d6d948aa142e6ff (patch) | |
tree | d1e865c31c0864837f47f2eb1c99edd3a011c5d8 /dom/performance/tests | |
parent | 6fe08dcf34417e825b7b9b6b33141a4a3b46ba24 (diff) | |
parent | 306db80410e802b0fe9a3b5273d4cf29586a1b17 (diff) | |
download | UXP-64aec5a353b4eb58e075c01b2d6d948aa142e6ff.tar UXP-64aec5a353b4eb58e075c01b2d6d948aa142e6ff.tar.gz UXP-64aec5a353b4eb58e075c01b2d6d948aa142e6ff.tar.lz UXP-64aec5a353b4eb58e075c01b2d6d948aa142e6ff.tar.xz UXP-64aec5a353b4eb58e075c01b2d6d948aa142e6ff.zip |
Merge pull request #294 from janekptacijarabaci/js_dom_performance-resource-timing_2
moebius#161: The Performance Resource Timing (make timestamps be relative to startTime)
Diffstat (limited to 'dom/performance/tests')
-rw-r--r-- | dom/performance/tests/mochitest.ini | 1 | ||||
-rw-r--r-- | dom/performance/tests/test_performance_user_timing.js | 21 | ||||
-rw-r--r-- | dom/performance/tests/test_timeOrigin.html | 68 |
3 files changed, 81 insertions, 9 deletions
diff --git a/dom/performance/tests/mochitest.ini b/dom/performance/tests/mochitest.ini index 7005637e1..bee0b2e70 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_performance_user_timing.js b/dom/performance/tests/test_performance_user_timing.js index cd8261bbd..a15dbebb6 100644 --- a/dom/performance/tests/test_performance_user_timing.js +++ b/dom/performance/tests/test_performance_user_timing.js @@ -126,15 +126,18 @@ var steps = [ }, // Test measure function () { - ok(true, "Running measure addition with no start/end time test"); - performance.measure("test"); - var measures = performance.getEntriesByType("measure"); - is(measures.length, 1, "number of measures should be 1"); - var measure = measures[0]; - is(measure.name, "test", "measure name should be 'test'"); - is(measure.entryType, "measure", "measure type should be 'measure'"); - is(measure.startTime, 0, "measure start time should be zero"); - ok(measure.duration >= 0, "measure duration should not be negative"); + // We don't have navigationStart in workers. + if ("window" in self) { + ok(true, "Running measure addition with no start/end time test"); + performance.measure("test", "navigationStart"); + var measures = performance.getEntriesByType("measure"); + is(measures.length, 1, "number of measures should be 1"); + var measure = measures[0]; + is(measure.name, "test", "measure name should be 'test'"); + is(measure.entryType, "measure", "measure type should be 'measure'"); + is(measure.startTime, 0, "measure start time should be zero"); + ok(measure.duration >= 0, "measure duration should not be negative"); + } }, function () { ok(true, "Running measure addition with only start time test"); diff --git a/dom/performance/tests/test_timeOrigin.html b/dom/performance/tests/test_timeOrigin.html new file mode 100644 index 000000000..5a8a461f3 --- /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> |