blob: 5a8a461f30eac5d6782ee91c6575a993b5a74096 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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>
|