mirror of
https://github.com/servo/servo.git
synced 2025-09-02 19:18:23 +01:00
Update web-platform-tests to revision 8a2ceb5f18911302b7a5c1cd2791f4ab50ad4326
This commit is contained in:
parent
462c272380
commit
1f531f66ea
5377 changed files with 174916 additions and 84369 deletions
|
@ -15,17 +15,30 @@
|
|||
<div id="log"></div>
|
||||
|
||||
<pre id='untested_idl' style='display:none'>
|
||||
[PrimaryGlobal]
|
||||
interface Window {
|
||||
};
|
||||
|
||||
[Exposed=Worker]
|
||||
interface WorkerGlobalScope {
|
||||
[Exposed=Windows,Worker]
|
||||
interface WindowOrWorkerGlobalScope {
|
||||
};
|
||||
|
||||
[Exposed=(Window,Worker)]
|
||||
interface EventTarget {
|
||||
};
|
||||
|
||||
[Exposed=Window]
|
||||
interface PerformanceTiming {
|
||||
};
|
||||
|
||||
[Exposed=Window]
|
||||
interface PerformanceNavigation {
|
||||
};
|
||||
|
||||
// from nav-timing
|
||||
partial interface Performance {
|
||||
[SameObject]
|
||||
readonly attribute PerformanceTiming timing;
|
||||
[SameObject]
|
||||
readonly attribute PerformanceNavigation navigation;
|
||||
[Default] object toJSON();
|
||||
};
|
||||
</pre>
|
||||
|
||||
<pre id='idl'>
|
||||
|
@ -34,19 +47,14 @@ typedef double DOMHighResTimeStamp;
|
|||
[Exposed=(Window,Worker)]
|
||||
interface Performance : EventTarget {
|
||||
DOMHighResTimeStamp now();
|
||||
serializer = {attribute};
|
||||
readonly attribute DOMHighResTimeStamp timeOrigin;
|
||||
[Default] object toJSON();
|
||||
};
|
||||
|
||||
[NoInterfaceObject,
|
||||
Exposed=(Window,Worker)]
|
||||
interface GlobalPerformance {
|
||||
partial interface WindowOrWorkerGlobalScope {
|
||||
[Replaceable]
|
||||
readonly attribute Performance performance;
|
||||
};
|
||||
|
||||
Window implements GlobalPerformance;
|
||||
|
||||
WorkerGlobalScope implements GlobalPerformance;
|
||||
</pre>
|
||||
|
||||
<script>
|
||||
|
@ -57,7 +65,7 @@ WorkerGlobalScope implements GlobalPerformance;
|
|||
idl_array.add_untested_idls(document.getElementById("untested_idl").textContent);
|
||||
idl_array.add_idls(document.getElementById("idl").textContent);
|
||||
|
||||
idl_array.add_objects({Performance: ["window.performance"]});
|
||||
idl_array.add_objects({Performance: [window.performance]});
|
||||
|
||||
idl_array.test();
|
||||
})();
|
||||
|
|
45
tests/wpt/web-platform-tests/hr-time/timeOrigin.html
Normal file
45
tests/wpt/web-platform-tests/hr-time/timeOrigin.html
Normal file
|
@ -0,0 +1,45 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
const windowOrigin = performance.timeOrigin;
|
||||
|
||||
test(() => {
|
||||
// Use a 30ms cushion when comparing with Date() to account for inaccuracy.
|
||||
const startTime = Date.now();
|
||||
assert_greater_than_equal(startTime + 30, windowOrigin, 'Date.now() should be at least as large as the window timeOrigin.');
|
||||
const startNow = performance.now();
|
||||
assert_less_than_equal(startTime, windowOrigin + startNow + 30, 'Date.now() should be close to window timeOrigin.');
|
||||
}, 'Window timeOrigin is close to Date.now() when there is no system clock adjustment.');
|
||||
|
||||
const workerScript = 'postMessage({timeOrigin: performance.timeOrigin})';
|
||||
const blob = new Blob([workerScript]);
|
||||
|
||||
async_test(function(t) {
|
||||
const beforeWorkerCreation = performance.now();
|
||||
const worker = new Worker(URL.createObjectURL(blob));
|
||||
worker.addEventListener('message', t.step_func_done(function(event) {
|
||||
const workerOrigin = event.data.timeOrigin;
|
||||
assert_greater_than_equal(workerOrigin, windowOrigin + beforeWorkerCreation, 'Worker timeOrigin should be greater than the window timeOrigin.');
|
||||
const afterWorkerCreation = performance.now();
|
||||
assert_less_than_equal(workerOrigin - windowOrigin, afterWorkerCreation, 'Window and worker timeOrigins should be close.');
|
||||
}));
|
||||
}, 'Window and worker timeOrigins are close when created one after another.');
|
||||
|
||||
async_test(function(t) {
|
||||
this.step_timeout(function() {
|
||||
const workerCreation = performance.now();
|
||||
const worker = new Worker(URL.createObjectURL(blob));
|
||||
worker.addEventListener('message', t.step_func_done(function(event) {
|
||||
const workerOrigin = event.data.timeOrigin;
|
||||
assert_greater_than_equal(workerOrigin - windowOrigin, 200, 'We waited 200ms to spawn the second worker, so its timeOrigin should be greater than that of the window.');
|
||||
}));
|
||||
}, 200);
|
||||
}, 'Window and worker timeOrigins differ when worker is created after a delay.');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
55
tests/wpt/web-platform-tests/hr-time/timing-attack.html
Normal file
55
tests/wpt/web-platform-tests/hr-time/timing-attack.html
Normal file
|
@ -0,0 +1,55 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>window.performance.now should not enable timing attacks</title>
|
||||
<link rel="author" title="W3C" href="http://www.w3.org/" />
|
||||
<link rel="help" href="http://w3c.github.io/hr-time/#privacy-security"/>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
test(function() {
|
||||
function check_resolutions(times, length) {
|
||||
var end = length - 2;
|
||||
|
||||
// we compare each value with the following ones
|
||||
for (var i = 0; i < end; i++) {
|
||||
var h1 = times[i];
|
||||
for (var j = i+1; j < end; j++) {
|
||||
var h2 = times[j];
|
||||
var diff = h2 - h1;
|
||||
assert_true((diff === 0) || ((diff * 1000) >= 5),
|
||||
"Differences smaller than 5 microseconds: " + diff);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
var times = new Array(10);
|
||||
var index = 0;
|
||||
var hrt1, hrt2, hrt;
|
||||
|
||||
// rapid firing of performance.now
|
||||
hrt1 = performance.now();
|
||||
hrt2 = performance.now();
|
||||
times[index++] = hrt1;
|
||||
times[index++] = hrt2;
|
||||
|
||||
// ensure that we get performance.now() to return a different value
|
||||
do {
|
||||
hrt = performance.now();
|
||||
times[index++] = hrt;
|
||||
} while ((hrt - hrt1) === 0);
|
||||
|
||||
assert_true(check_resolutions(times, index), 'Difference should be at least 5 microseconds.');
|
||||
}, 'The recommended minimum resolution of the Performance interface has been set to 5 microseconds');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Description</h1>
|
||||
<p>The recommended minimum resolution of the Performance interface should be set to 5 microseconds.</p>
|
||||
|
||||
<div id="log"></div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,36 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>performance.now() time origin</title>
|
||||
<meta name="author" title="JosephPecoraro" href="mailto:joepeck@webkit.org">
|
||||
<meta name="assert" content="Time origin in Worker should be Worker's moment of creation.">
|
||||
<link rel="help" href="https://w3c.github.io/hr-time/#time-origin-1">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(function(t) {
|
||||
this.step_timeout(function() {
|
||||
var workerScript = 'postMessage({now: performance.now()})';
|
||||
var blob = new Blob([workerScript]);
|
||||
var worker = new Worker(URL.createObjectURL(blob));
|
||||
var windowWorkerCreationTime = performance.now();
|
||||
worker.addEventListener("message", t.step_func_done(function(event) {
|
||||
var workerNow = event.data.now;
|
||||
|
||||
// We waited 1s to spawn the worker. So verify the worker timestamp is at least less then 0.5 seconds.
|
||||
assert_less_than(workerNow, 500, "worker performance.now() must be very close to its creation time");
|
||||
|
||||
// We waited 1s to spawn the worker. Window's now is ~1000, Worker's now will be much lower.
|
||||
assert_greater_than(windowWorkerCreationTime - workerNow, 500, "window's time origin must be before worker's time origin");
|
||||
}));
|
||||
}, 1000);
|
||||
}, 'Worker time origin is approximately its creation time');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Description</h1>
|
||||
<p>This test validates that a Worker's time origin is its moment of creation and differs from its spawner's.</p>
|
||||
<div id="log"></div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,30 @@
|
|||
"use strict"
|
||||
// https://w3c.github.io/hr-time/#time-origin
|
||||
|
||||
async_test(function(test) {
|
||||
// Cache global time before starting worker
|
||||
const globalTimeOrigin = performance.timeOrigin;
|
||||
const globalNowBeforeWorkerStart = performance.now();
|
||||
|
||||
// Start worker and retrieve time
|
||||
const workerScript = "postMessage({timeOrigin: performance.timeOrigin, now: performance.now()})";
|
||||
const blob = new Blob([workerScript]);
|
||||
let worker = new Worker(URL.createObjectURL(blob));
|
||||
|
||||
worker.addEventListener("message", test.step_func_done(function(event) {
|
||||
const workerTimeOrigin = event.data.timeOrigin;
|
||||
const workerNow = event.data.now;
|
||||
|
||||
assert_not_equals(workerTimeOrigin, 0, "worker timeOrigin must not be 0");
|
||||
assert_not_equals(performance.timeOrigin, 0, "Document timeOrigin must not be 0");
|
||||
|
||||
assert_equals(globalTimeOrigin, performance.timeOrigin, "timeOrigin should not be changed in same document mode");
|
||||
assert_less_than(globalTimeOrigin, workerTimeOrigin, "Document timeOrigin must be earlier than worker timeOrigin");
|
||||
|
||||
// Document and worker's now() start from their respective timeOrigins.
|
||||
const timeDiff = workerTimeOrigin - globalTimeOrigin; // convert worker's time to Document time.
|
||||
assert_less_than(globalTimeOrigin + globalNowBeforeWorkerStart, globalTimeOrigin + timeDiff + workerNow, "Document old now is earlier than worker now.");
|
||||
|
||||
// Comparing timing between Document and worker threads could be delicate as it relies on the thread implementation and could be subject to race conditions.
|
||||
}));
|
||||
}, 'timeOrigin and now() should be correctly ordered between window and worker');
|
Loading…
Add table
Add a link
Reference in a new issue