Skip to content

Commit

Permalink
Prerender: Upstream a test for cookies in same-origin prerendered pages
Browse files Browse the repository at this point in the history
This CL upstreams a test for cookies in same-origin prerendered pages to
the WPT. The behavior of cookies is not defined in the spec yet, but we
already reached a consensus that the storage APIs including cookies in
same-origin prerendered pages are just allowed.

See the GitHub issue for details:
WICG/nav-speculation#7 (comment)

Bug: 1253158
Change-Id: I512a8e6b6f8a20f5464045900d67f8b2ef752266
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3232796
Reviewed-by: Lingqi Chi <[email protected]>
Commit-Queue: Hiroki Nakagawa <[email protected]>
Cr-Commit-Position: refs/heads/main@{#933299}
  • Loading branch information
nhiroki authored and Gabisampaio committed Nov 18, 2021
1 parent 221803d commit ac6a66f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
40 changes: 40 additions & 0 deletions speculation-rules/prerender/cookies.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<title>Same-origin prerendering can access cookies</title>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/utils.js"></script>
<body>
<script>

setup(() => assertSpeculationRulesIsSupported());

promise_test(async t => {
const bc = new BroadcastChannel('prerender-channel');

const gotMessage = new Promise(resolve => {
bc.addEventListener('message', e => {
resolve(e.data);
}, {
once: true
});
});

const initiator_cookie = 'initiator_cookie=exist';
const prerender_cookie = 'prerender_cookie=exist';

document.cookie = initiator_cookie;

// Start prerendering a page that attempts to access cookies.
startPrerendering(`resources/cookies-access.html`);
const result = await gotMessage;
assert_equals(
result, initiator_cookie,
'prerendering page should be able to read from document cookies.');
assert_equals(
document.cookie, initiator_cookie + '; ' + prerender_cookie,
'prerendering page should be able to write to document cookies');
}, 'prerendering page should be able to access cookies');

</script>
</body>
15 changes: 15 additions & 0 deletions speculation-rules/prerender/resources/cookies-access.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>

const bc = new BroadcastChannel('prerender-channel');
assert_true(document.prerendering);

const result = document.cookie;
document.cookie = "prerender_cookie=exist;path=/;";

bc.postMessage(result);
bc.close();

</script>

0 comments on commit ac6a66f

Please sign in to comment.