blob: cd14685054f0cd007e53b68e2b72693b88afc5e6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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>
|