-
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.
Prerender2 WPT: Externalize Web Locks web platform test
Bug: 1253158 Change-Id: Ie53aea533e024833a895c1e17436bef03970c277 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3895237 Reviewed-by: Lingqi Chi <[email protected]> Commit-Queue: Julie Jeongeun Kim <[email protected]> Cr-Commit-Position: refs/heads/main@{#1047309}
- Loading branch information
1 parent
d73231a
commit 4fce7b2
Showing
2 changed files
with
70 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/speculation-rules/prerender/resources/utils.js"></script> | ||
<script src="/speculation-rules/prerender/resources/deferred-promise-utils.js"></script> | ||
<script> | ||
|
||
const params = new URLSearchParams(location.search); | ||
|
||
// The main test page (restriction-web-locks.html) loads the initiator page, | ||
// then the initiator page will prerender itself with the `prerendering` | ||
// parameter. | ||
const isPrerendering = params.has('prerendering'); | ||
|
||
if (!isPrerendering) { | ||
loadInitiatorPage(); | ||
} else { | ||
const prerenderEventCollector = new PrerenderEventCollector(); | ||
const promise = navigator.locks.request('prerender-test-lock', lock => {}); | ||
prerenderEventCollector.start(promise, 'navigator.locks.request'); | ||
} | ||
|
||
</script> |
47 changes: 47 additions & 0 deletions
47
speculation-rules/prerender/restriction-web-locks.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,47 @@ | ||
<!DOCTYPE html> | ||
<title>Access to the Web Locks API is deferred</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('test-channel', uid); | ||
|
||
const gotMessage = new Promise(resolve => { | ||
bc.addEventListener('message', e => { | ||
resolve(e.data); | ||
}, { | ||
once: true | ||
}); | ||
}); | ||
const url = `resources/web-locks.html?uid=${uid}`; | ||
window.open(url, '_blank', 'noopener'); | ||
|
||
const result = await gotMessage; | ||
const expected = [ | ||
{event: 'started waiting navigator.locks.request', prerendering: true}, | ||
{event: 'prerendering change', prerendering: false}, | ||
{event: 'finished waiting navigator.locks.request', prerendering: false}, | ||
]; | ||
assert_equals(result.length, expected.length); | ||
for (let i = 0; i < result.length; i++) { | ||
assert_equals(result[i].event, expected[i].event, `event[${i}]`); | ||
assert_equals(result[i].prerendering, expected[i].prerendering, | ||
`prerendering[${i}]`); | ||
} | ||
bc.close(); | ||
|
||
// Send a close signal to PrerenderEventCollector on the prerendered page. | ||
new PrerenderChannel('close', uid).postMessage(''); | ||
}, `the access to the Web Locks API should be deferred until the prerendered | ||
page is activated`); | ||
|
||
</script> | ||
</body> |