diff options
Diffstat (limited to 'testing/web-platform/tests/speculation-rules/prerender/local-storage.html')
-rw-r--r-- | testing/web-platform/tests/speculation-rules/prerender/local-storage.html | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/testing/web-platform/tests/speculation-rules/prerender/local-storage.html b/testing/web-platform/tests/speculation-rules/prerender/local-storage.html new file mode 100644 index 0000000000..cd14685054 --- /dev/null +++ b/testing/web-platform/tests/speculation-rules/prerender/local-storage.html @@ -0,0 +1,49 @@ +<!DOCTYPE html> +<title>Same-origin prerendering can access localStorage</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="/common/dispatcher/dispatcher.js"></script> +<script src="resources/utils.js"></script> +<body> +<script> + +setup(() => assertSpeculationRulesIsSupported()); + +promise_test(async t => { + const uid1 = token(); + const uid2 = token(); + + // A promise to wait until a prerendered page writes data with the "prerender" + // key in the local storage. + const write_promise = new Promise((resolve, reject) => { + window.addEventListener("storage", event => { + if (event.key !== 'prerender') { + reject("wrong key"); + } else { + resolve(); + } + }, { once: true }); + }); + + window.localStorage.setItem('initial', uid1); + const {exec} = await create_prerendered_page(t); + const result = await exec(uid2 => { + window.localStorage.setItem('prerender', uid2); + return window.localStorage.getItem('initial'); + }, [uid2]) + + // Start prerendering a page that attempts to access localStorage API. + assert_equals( + result, uid1, + 'prerendering page should be able to read from local storage'); + + await write_promise; + assert_equals( + window.localStorage.getItem('prerender'), uid2, + 'prerendering page should be able to write to local storage'); +}, 'prerendering page should be able to access local storage'); + +</script> +</body> |