Skip to content

Commit 5465886

Browse files
anonrignodejs-github-bot
authored andcommitted
test: update hr-time web platform tests
PR-URL: #44100 Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 118f001 commit 5465886

13 files changed

+170
-38
lines changed

test/fixtures/wpt/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Last update:
1616
- dom/events: https://github.com/web-platform-tests/wpt/tree/f8821adb28/dom/events
1717
- encoding: https://github.com/web-platform-tests/wpt/tree/c1b24fce6e/encoding
1818
- FileAPI: https://github.com/web-platform-tests/wpt/tree/3b279420d4/FileAPI
19-
- hr-time: https://github.com/web-platform-tests/wpt/tree/9910784394/hr-time
19+
- hr-time: https://github.com/web-platform-tests/wpt/tree/34cafd797e/hr-time
2020
- html/webappapis/atob: https://github.com/web-platform-tests/wpt/tree/f267e1dca6/html/webappapis/atob
2121
- html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/2c5c3c4c27/html/webappapis/microtask-queuing
2222
- html/webappapis/structured-clone: https://github.com/web-platform-tests/wpt/tree/47d3fb280c/html/webappapis/structured-clone
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<script src="resources/clamped-time-origin.js"></script>
7+
</head>
8+
<body>
9+
<script>
10+
// Isolated contexts should be clamped to 5 microseconds.
11+
run_test(/*isolated=*/true);
12+
</script>
13+
</body>
14+
</html>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cross-Origin-Embedder-Policy: require-corp
2+
Cross-Origin-Opener-Policy: same-origin
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<script src="resources/clamped-time-origin.js"></script>
7+
</head>
8+
<body>
9+
<script>
10+
// Non-isolated contexts should be clamped to 100 microseconds.
11+
run_test(/*isolated=*/false);
12+
</script>
13+
</body>
14+
</html>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>window.performance.now should not enable timing attacks</title>
6+
<link rel="author" title="W3C" href="http://www.w3.org/" />
7+
<link rel="help" href="http://w3c.github.io/hr-time/#privacy-security"/>
8+
<script src="/resources/testharness.js"></script>
9+
<script src="/resources/testharnessreport.js"></script>
10+
<script src="resources/timing-attack.js"></script>
11+
<script>
12+
run_test(/*isolated=*/true);
13+
</script>
14+
</head>
15+
<body>
16+
<h1>Description</h1>
17+
<p>The recommended minimum resolution of the Performance interface should be set to 5 microseconds.</p>
18+
19+
<div id="log"></div>
20+
21+
</body>
22+
</html>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cross-Origin-Embedder-Policy: require-corp
2+
Cross-Origin-Opener-Policy: same-origin
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// META: script=/resources/idlharness-shadowrealm.js
2+
idl_test_shadowrealm(["hr-time"], ["html", "dom"]);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
</head>
7+
<body>
8+
<script>
9+
function busyWait(millis) {
10+
const start = performance.now();
11+
while (performance.now() < start + millis) {}
12+
}
13+
promise_test(async t => {
14+
const delay = 3000;
15+
const iframe = document.createElement('iframe');
16+
iframe.src = './resources/now_frame.html';
17+
document.body.appendChild(iframe);
18+
await new Promise(resolve => iframe.addEventListener('load', resolve));
19+
iframe.contentWindow.addEventListener('beforeunload', () => {
20+
busyWait(delay);
21+
});
22+
iframe.src = './resources/post.html';
23+
await new Promise(resolve => this.addEventListener('message', ({data}) => {
24+
if (data === 'done')
25+
resolve();
26+
}));
27+
28+
const entry = iframe.contentWindow.performance.getEntriesByType('navigation')[0];
29+
assert_less_than(entry.fetchStart, delay);
30+
}, 'timeOrigin should be set after beforeunload');
31+
</script>
32+
</body>
33+
</html>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const run_test = isolated => {
2+
// Multiplier to convert the clamped timestamps to microseconds.
3+
const multiplier = 1000;
4+
const windowOrigin = performance.timeOrigin;
5+
// Clamp to at least 5 microseconds in isolated contexts and at least 100 in
6+
// non-isolated ones.
7+
const resolution = isolated ? 5 : 100;
8+
9+
const create_worker = () => {
10+
return new Promise(resolve => {
11+
const workerScript = 'postMessage({timeOrigin: performance.timeOrigin})';
12+
const blob = new Blob([workerScript]);
13+
const worker = new Worker(URL.createObjectURL(blob));
14+
worker.addEventListener('message', event => {
15+
resolve(event.data.timeOrigin);
16+
});
17+
});
18+
};
19+
promise_test(async t => {
20+
assert_equals(self.crossOriginIsolated, isolated,
21+
"crossOriginIsolated is properly set");
22+
let prev = windowOrigin;
23+
let current;
24+
for (let i = 1; i < 100; ++i) {
25+
current = await create_worker();
26+
assert_true(current === prev || current - prev > resolution / 1000);
27+
prev = current;
28+
}
29+
}, 'timeOrigins are clamped.');
30+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!DOCTYPE HTML>
2+
<script>
3+
window.parent.postMessage('done');
4+
</script>

0 commit comments

Comments
 (0)