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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// META: script=/common/get-host-info.sub.js
// META: script=/common/utils.js
// META: script=/common/dispatcher/dispatcher.js
// META: script=/html/cross-origin-embedder-policy/credentialless/resources/common.js
// META: script=./resources/common.js
// This test verifies the behavior of the initial empty document nested inside
// credentialless iframes.
//
// The following tree of frames and documents is used:
// A
// ├──B (credentialless)
// │ └──D (initial empty document)
// └──C (control)
// └──E (initial empty document)
//
// Storage used for D and E must be different.
promise_test(async test => {
const iframe_B = newIframeCredentialless(origin);
const iframe_C = newIframe(origin);
// Create iframe_D and store a value in localStorage.
const key_D = token();
const value_D = "value_D";
const queue_B = token();
send(iframe_B, `
const iframe_D = document.createElement("iframe");
document.body.appendChild(iframe_D);
iframe_D.contentWindow.localStorage.setItem("${key_D}","${value_D}");
send("${queue_B}", "Done");
`);
// Create iframe_E and store a value in localStorage.
const key_E = token();
const value_E = "value_E";
const queue_C = token();
send(iframe_C, `
const iframe_E = document.createElement("iframe");
document.body.appendChild(iframe_E);
iframe_E.contentWindow.localStorage.setItem("${key_E}","${value_E}");
send("${queue_C}", "Done");
`);
assert_equals(await receive(queue_B), "Done");
assert_equals(await receive(queue_C), "Done");
// Try to load both values from both contexts:
send(iframe_B, `
const iframe_D = document.querySelector("iframe");
const value_D = iframe_D.contentWindow.localStorage.getItem("${key_D}");
const value_E = iframe_D.contentWindow.localStorage.getItem("${key_E}");
send("${queue_B}", value_D);
send("${queue_B}", value_E);
`);
send(iframe_C, `
const iframe_E = document.querySelector("iframe");
const value_D = iframe_E.contentWindow.localStorage.getItem("${key_D}");
const value_E = iframe_E.contentWindow.localStorage.getItem("${key_E}");
send("${queue_C}", value_D);
send("${queue_C}", value_E);
`);
// Verify the credentialless iframe and the normal one do not have access to
// each other.
assert_equals(await receive(queue_B), value_D, // key_D
"Credentialless iframe can access credentialless context");
assert_equals(await receive(queue_B), "", // key_E
"Credentialless iframe can't access credentialled context");
assert_equals(await receive(queue_C), "", // key_D
"Credentialled iframe can't access credentialless context");
assert_equals(await receive(queue_C), value_E, // key_E
"Credentialled iframe can access credentialled context");
}, "Local storage is correctly partitioned with regards to credentialless " +
"iframe in initial empty documents.");
|