Skip to content

Commit

Permalink
Prerender: Externalize idle-detection web platform test
Browse files Browse the repository at this point in the history
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
hyowon-igalia authored and chromium-wpt-export-bot committed Aug 26, 2022
1 parent 092176b commit ad92e64
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
27 changes: 27 additions & 0 deletions speculation-rules/prerender/resources/idle-detection.https.html
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 speculation-rules/prerender/restriction-idle-detection.https.html
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>

0 comments on commit ad92e64

Please sign in to comment.