-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prerender: Externalize idle-detection web platform test
Bug: 1253158 Change-Id: Ide3e6e6a78c75c606ea56865d6f5d91ba66af64a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3858725 Reviewed-by: Lingqi Chi <lingqi@chromium.org> Commit-Queue: Hyowon Kim <hyowon@igalia.com> Cr-Commit-Position: refs/heads/main@{#1039739}
- Loading branch information
1 parent
092176b
commit ad92e64
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
speculation-rules/prerender/resources/idle-detection.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,27 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/speculation-rules/prerender/resources/utils.js"></script> | ||
<script> | ||
|
||
assert_true(document.prerendering); | ||
|
||
const params = new URLSearchParams(location.search); | ||
const uid = params.get('uid'); | ||
|
||
async function requestIdleDetectionPermission() { | ||
const bc = new PrerenderChannel('prerender-channel', uid); | ||
|
||
try { | ||
const _ = await IdleDetector.requestPermission(); | ||
bc.postMessage('unexpected success'); | ||
} catch (err){ | ||
bc.postMessage(err.name); | ||
} finally { | ||
bc.close(); | ||
} | ||
} | ||
|
||
requestIdleDetectionPermission(); | ||
|
||
</script> |
35 changes: 35 additions & 0 deletions
35
speculation-rules/prerender/restriction-idle-detection.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,35 @@ | ||
<!DOCTYPE html> | ||
<title>Prerendering cannot invoke the Idle Detection API</title> | ||
<meta name="timeout" content="long"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/utils.js"></script> | ||
<script src="/speculation-rules/prerender/resources/utils.js"></script> | ||
<body> | ||
<script> | ||
|
||
setup(() => assertSpeculationRulesIsSupported()); | ||
|
||
promise_test(async t => { | ||
const uid = token(); | ||
const bc = new PrerenderChannel('prerender-channel', uid); | ||
|
||
const gotMessage = new Promise(resolve => { | ||
bc.addEventListener('message', e => { | ||
resolve(e.data); | ||
}, { | ||
once: true | ||
}); | ||
}); | ||
|
||
// Start prerendering a page that attempts to invoke the Idle Detection API. | ||
// This API is activation-gated so it's expected to fail: | ||
// https://wicg.github.io/nav-speculation/prerendering.html#activation-gated | ||
startPrerendering(`resources/idle-detection.https.html?uid=${uid}`); | ||
const result = await gotMessage; | ||
assert_equals(result, 'NotAllowedError'); | ||
bc.close(); | ||
}, `prerendering pages should not be able to invoke the Idle Detection API`); | ||
|
||
</script> | ||
</body> |