Skip to content

Commit

Permalink
Prerender2 WPT: Externalize Web Locks web platform test
Browse files Browse the repository at this point in the history
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
jkim-julie authored and chromium-wpt-export-bot committed Sep 15, 2022
1 parent d73231a commit 4fce7b2
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
23 changes: 23 additions & 0 deletions speculation-rules/prerender/resources/web-locks.html
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 speculation-rules/prerender/restriction-web-locks.https.html
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>

0 comments on commit 4fce7b2

Please sign in to comment.