forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prerender: Upstream a test for cookies in same-origin prerendered pages
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
1 parent
221803d
commit ac6a66f
Showing
2 changed files
with
55 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,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> |
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,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> |