-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: update hr-time web platform tests
PR-URL: #44100 Reviewed-By: Feng Yu <F3n67u@outlook.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
- Loading branch information
1 parent
bcb94aa
commit ba1915d
Showing
13 changed files
with
170 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test/fixtures/wpt/hr-time/clamped-time-origin-isolated.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/clamped-time-origin.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
// Isolated contexts should be clamped to 5 microseconds. | ||
run_test(/*isolated=*/true); | ||
</script> | ||
</body> | ||
</html> |
2 changes: 2 additions & 0 deletions
2
test/fixtures/wpt/hr-time/clamped-time-origin-isolated.https.html.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Cross-Origin-Embedder-Policy: require-corp | ||
Cross-Origin-Opener-Policy: same-origin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/clamped-time-origin.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
// Non-isolated contexts should be clamped to 100 microseconds. | ||
run_test(/*isolated=*/false); | ||
</script> | ||
</body> | ||
</html> |
22 changes: 22 additions & 0 deletions
22
test/fixtures/wpt/hr-time/cross-origin-isolated-timing-attack.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!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 src="resources/timing-attack.js"></script> | ||
<script> | ||
run_test(/*isolated=*/true); | ||
</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> |
2 changes: 2 additions & 0 deletions
2
test/fixtures/wpt/hr-time/cross-origin-isolated-timing-attack.https.html.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Cross-Origin-Embedder-Policy: require-corp | ||
Cross-Origin-Opener-Policy: same-origin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// META: script=/resources/idlharness-shadowrealm.js | ||
idl_test_shadowrealm(["hr-time"], ["html", "dom"]); |
33 changes: 33 additions & 0 deletions
33
test/fixtures/wpt/hr-time/navigation-start-post-before-unload.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
function busyWait(millis) { | ||
const start = performance.now(); | ||
while (performance.now() < start + millis) {} | ||
} | ||
promise_test(async t => { | ||
const delay = 3000; | ||
const iframe = document.createElement('iframe'); | ||
iframe.src = './resources/now_frame.html'; | ||
document.body.appendChild(iframe); | ||
await new Promise(resolve => iframe.addEventListener('load', resolve)); | ||
iframe.contentWindow.addEventListener('beforeunload', () => { | ||
busyWait(delay); | ||
}); | ||
iframe.src = './resources/post.html'; | ||
await new Promise(resolve => this.addEventListener('message', ({data}) => { | ||
if (data === 'done') | ||
resolve(); | ||
})); | ||
|
||
const entry = iframe.contentWindow.performance.getEntriesByType('navigation')[0]; | ||
assert_less_than(entry.fetchStart, delay); | ||
}, 'timeOrigin should be set after beforeunload'); | ||
</script> | ||
</body> | ||
</html> |
30 changes: 30 additions & 0 deletions
30
test/fixtures/wpt/hr-time/resources/clamped-time-origin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const run_test = isolated => { | ||
// Multiplier to convert the clamped timestamps to microseconds. | ||
const multiplier = 1000; | ||
const windowOrigin = performance.timeOrigin; | ||
// Clamp to at least 5 microseconds in isolated contexts and at least 100 in | ||
// non-isolated ones. | ||
const resolution = isolated ? 5 : 100; | ||
|
||
const create_worker = () => { | ||
return new Promise(resolve => { | ||
const workerScript = 'postMessage({timeOrigin: performance.timeOrigin})'; | ||
const blob = new Blob([workerScript]); | ||
const worker = new Worker(URL.createObjectURL(blob)); | ||
worker.addEventListener('message', event => { | ||
resolve(event.data.timeOrigin); | ||
}); | ||
}); | ||
}; | ||
promise_test(async t => { | ||
assert_equals(self.crossOriginIsolated, isolated, | ||
"crossOriginIsolated is properly set"); | ||
let prev = windowOrigin; | ||
let current; | ||
for (let i = 1; i < 100; ++i) { | ||
current = await create_worker(); | ||
assert_true(current === prev || current - prev > resolution / 1000); | ||
prev = current; | ||
} | ||
}, 'timeOrigins are clamped.'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!DOCTYPE HTML> | ||
<script> | ||
window.parent.postMessage('done'); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
function run_test(isolated) { | ||
let resolution = 100; | ||
if (isolated) { | ||
resolution = 5; | ||
} | ||
test(function() { | ||
function check_resolutions(times, length) { | ||
const end = length - 2; | ||
|
||
// we compare each value with the following ones | ||
for (let i = 0; i < end; i++) { | ||
const h1 = times[i]; | ||
for (let j = i+1; j < end; j++) { | ||
const h2 = times[j]; | ||
const diff = h2 - h1; | ||
assert_true((diff === 0) || ((diff * 1000) >= resolution), | ||
"Differences smaller than ' + resolution + ' microseconds: " + diff); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
const times = new Array(10); | ||
let index = 0; | ||
let hrt1, hrt2, hrt; | ||
assert_equals(self.crossOriginIsolated, isolated, "Document cross-origin isolated value matches"); | ||
|
||
// 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 ' + resolution + ' microseconds.'); | ||
}, 'The recommended minimum resolution of the Performance interface has been set to ' + resolution + ' microseconds for cross-origin isolated contexts.'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters