Bug 1313420 - Implement Performance.timeOrigin - part 2 - tests, r=bz

This commit is contained in:
Andrea Marchesini 2016-11-17 10:00:26 +01:00
Родитель b0435b9411
Коммит ad23bdeed0
3 изменённых файлов: 86 добавлений и 17 удалений

Просмотреть файл

@ -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,18 +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();
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("");
}
@ -92,16 +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();
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();
};

Просмотреть файл

@ -15,3 +15,4 @@ support-files =
[test_worker_observer.html]
[test_sharedWorker_performance_user_timing.html]
[test_worker_performance_now.html]
[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>