|
9 | 9 | const www1Alt = "https://{{hosts[alt][www1]}}:{{ports[https][0]}}"; |
10 | 10 | const responder_html_load_ack = "/storage-access-api/resources/script-with-cookie-header.py?script=embedded_responder.js&should_ack_load=true"; |
11 | 11 |
|
12 | | - if (window === window.top) { |
13 | | - // Test the interaction between two (same-origin) iframes. |
14 | | - promise_test(async (t) => { |
15 | | - // Note: the web platform doesn't guarantee that each iframe has finished |
16 | | - // loading (and executing its script) by the time the CreateFrame promise |
17 | | - // resolves. Therefore the script will signal the parent when it's loaded |
18 | | - // and safe to proceed. Without this extra synchronization, frames can |
19 | | - // miss messages that are essential to the test, and cause the test to |
20 | | - // timeout. |
21 | | - const frame1_loaded = new Promise(r => { |
22 | | - onmessage = e => r(e.data); |
23 | | - }); |
24 | | - const frame1 = await CreateFrame(wwwAlt + responder_html_load_ack); |
25 | | - assert_equals(await frame1_loaded, "loaded"); |
26 | | - |
27 | | - const frame2_loaded = new Promise(r => { |
28 | | - onmessage = e => r(e.data); |
29 | | - }); |
30 | | - const frame2 = await CreateFrame(www1Alt + responder_html_load_ack); |
31 | | - assert_equals(await frame2_loaded, "loaded"); |
32 | | - |
33 | | - t.add_cleanup(async () => { |
34 | | - await SetPermissionInFrame(frame1, [{ name: 'storage-access' }, 'prompt']); |
35 | | - }); |
36 | | - |
37 | | - // Install observer on frame, and wait for acknowledgement that it is |
38 | | - // installed. |
39 | | - assert_equals(await ObservePermissionChange(frame2), |
40 | | - "permission_change_observer_installed"); |
41 | | - |
42 | | - const observed_event = new Promise(r => { |
43 | | - onmessage = e => r(e.data); |
44 | | - }); |
45 | | - await SetPermissionInFrame(frame1, [{ name: 'storage-access' }, 'granted']); |
46 | | - const state = await observed_event; |
47 | | - assert_equals(state, "granted"); |
48 | | - }, 'Permissions grants are observable across same-origin iframes'); |
49 | | - |
50 | | - promise_test(async (t) => { |
51 | | - // Note: the web platform doesn't guarantee that each iframe has finished |
52 | | - // loading (and executing its script) by the time the CreateFrame promise |
53 | | - // resolves. Therefore the script will signal the parent when it's loaded |
54 | | - // and safe to proceed. Without this extra synchronization, frames can |
55 | | - // miss messages that are essential to the test, and cause the test to |
56 | | - // timeout. |
57 | | - const frame1_loaded = new Promise(r => { |
58 | | - onmessage = e => r(e.data); |
59 | | - }); |
60 | | - const frame1 = await CreateFrame(wwwAlt + responder_html_load_ack); |
61 | | - assert_equals(await frame1_loaded, "loaded"); |
62 | | - |
63 | | - const frame2_loaded = new Promise(r => { |
64 | | - onmessage = e => r(e.data); |
65 | | - }); |
66 | | - const frame2 = await CreateFrame(www1Alt + responder_html_load_ack); |
67 | | - assert_equals(await frame2_loaded, "loaded"); |
68 | | - |
69 | | - t.add_cleanup(async () => { |
70 | | - await SetPermissionInFrame(frame1, [{ name: 'storage-access' }, 'prompt']); |
71 | | - }); |
72 | | - |
73 | | - // Install observer on frame, and wait for acknowledgement that it is |
74 | | - // installed. |
75 | | - assert_equals(await ObservePermissionChange(frame2), |
76 | | - "permission_change_observer_installed"); |
77 | | - |
78 | | - const observed_event = new Promise(r => { |
79 | | - onmessage = e => r(e.data); |
80 | | - }); |
81 | | - await SetPermissionInFrame(frame1, [{ name: 'storage-access' }, 'granted']); |
82 | | - const state = await observed_event; |
83 | | - assert_equals(state, "granted"); |
84 | | - }, "Permissions grants are observable across same-site iframes"); |
85 | | - |
86 | | - promise_test(async (t) => { |
87 | | - // Finally run the simple tests below in a separate cross-origin iframe. |
88 | | - await RunTestsInIFrame('https://{{domains[www]}}:{{ports[https][0]}}/storage-access-api/resources/permissions-iframe.https.html'); |
89 | | - }, "IFrame tests"); |
90 | | - return; |
| 12 | + function permissionChangeEvent() { |
| 13 | + return new Promise(resolve => { |
| 14 | + window.onmessage = e => { |
| 15 | + if (e.data.tag == 'observed_permission_change') { |
| 16 | + resolve(e.data.state); |
| 17 | + } |
| 18 | + }; |
| 19 | + }); |
91 | 20 | } |
92 | 21 |
|
93 | | - // We're in a cross-origin, same-site iframe test now. |
94 | | - test_driver.set_test_context(window.top); |
95 | | - |
96 | | - promise_test(async t => { |
97 | | - const permission = await navigator.permissions.query({name: "storage-access"}); |
98 | | - assert_equals(permission.name, "storage-access"); |
99 | | - assert_equals(permission.state, "prompt"); |
100 | | - }, "Permission default state can be queried"); |
101 | | - |
102 | | - promise_test(async t => { |
103 | | - t.add_cleanup(async () => { |
104 | | - await test_driver.set_permission({ name: 'storage-access' }, 'prompt'); |
| 22 | + // Test the interaction between two (same-origin) iframes. |
| 23 | + promise_test(async (t) => { |
| 24 | + // Note: the web platform doesn't guarantee that each iframe has finished |
| 25 | + // loading (and executing its script) by the time the CreateFrame promise |
| 26 | + // resolves. Therefore the script will signal the parent when it's loaded |
| 27 | + // and safe to proceed. Without this extra synchronization, frames can |
| 28 | + // miss messages that are essential to the test, and cause the test to |
| 29 | + // timeout. |
| 30 | + const frame1_loaded = new Promise(r => { |
| 31 | + onmessage = e => r(e.data); |
105 | 32 | }); |
106 | | - await test_driver.set_permission({ name: 'storage-access' }, 'granted'); |
| 33 | + const frame1 = await CreateFrame(wwwAlt + responder_html_load_ack); |
| 34 | + assert_equals(await frame1_loaded, "loaded"); |
107 | 35 |
|
108 | | - const permission = await navigator.permissions.query({name: "storage-access"}); |
109 | | - assert_equals(permission.name, "storage-access"); |
110 | | - assert_equals(permission.state, "granted"); |
111 | | - }, "Permission granted state can be queried"); |
| 36 | + const frame2_loaded = new Promise(r => { |
| 37 | + onmessage = e => r(e.data); |
| 38 | + }); |
| 39 | + const frame2 = await CreateFrame(www1Alt + responder_html_load_ack); |
| 40 | + assert_equals(await frame2_loaded, "loaded"); |
112 | 41 |
|
113 | | - promise_test(async t => { |
114 | 42 | t.add_cleanup(async () => { |
115 | | - await test_driver.set_permission({ name: 'storage-access' }, 'prompt'); |
| 43 | + await SetPermissionInFrame(frame1, [{ name: 'storage-access' }, 'prompt']); |
116 | 44 | }); |
117 | | - await test_driver.set_permission({ name: 'storage-access' }, 'denied'); |
118 | 45 |
|
119 | | - const permission = await navigator.permissions.query({name: "storage-access"}); |
120 | | - assert_equals(permission.name, "storage-access"); |
121 | | - assert_equals(permission.state, "prompt"); |
| 46 | + // Install observer on frame, and wait for acknowledgement that it is |
| 47 | + // installed. |
| 48 | + assert_equals(await ObservePermissionChange(frame2), |
| 49 | + "permission_change_observer_installed"); |
| 50 | + |
| 51 | + const observed_event = permissionChangeEvent(); |
| 52 | + await SetPermissionInFrame(frame1, [{ name: 'storage-access' }, 'granted']); |
| 53 | + const state = await observed_event; |
| 54 | + assert_equals(state, "granted"); |
| 55 | + }, 'Permissions grants are observable across same-origin iframes'); |
| 56 | + |
| 57 | + promise_test(async (t) => { |
| 58 | + // Note: the web platform doesn't guarantee that each iframe has finished |
| 59 | + // loading (and executing its script) by the time the CreateFrame promise |
| 60 | + // resolves. Therefore the script will signal the parent when it's loaded |
| 61 | + // and safe to proceed. Without this extra synchronization, frames can |
| 62 | + // miss messages that are essential to the test, and cause the test to |
| 63 | + // timeout. |
| 64 | + const frame1_loaded = new Promise(r => { |
| 65 | + onmessage = e => r(e.data); |
| 66 | + }); |
| 67 | + const frame1 = await CreateFrame(wwwAlt + responder_html_load_ack); |
| 68 | + assert_equals(await frame1_loaded, "loaded"); |
122 | 69 |
|
123 | | - await test_driver.set_permission({ name: 'storage-access' }, 'prompt'); |
124 | | - }, "Permission denied state is hidden"); |
| 70 | + const frame2_loaded = new Promise(r => { |
| 71 | + onmessage = e => r(e.data); |
| 72 | + }); |
| 73 | + const frame2 = await CreateFrame(www1Alt + responder_html_load_ack); |
| 74 | + assert_equals(await frame2_loaded, "loaded"); |
125 | 75 |
|
126 | | - promise_test(async t => { |
127 | 76 | t.add_cleanup(async () => { |
128 | | - await test_driver.set_permission({ name: 'storage-access' }, 'prompt'); |
| 77 | + await SetPermissionInFrame(frame1, [{ name: 'storage-access' }, 'prompt']); |
129 | 78 | }); |
130 | 79 |
|
131 | | - const permission = await navigator.permissions.query({name: "storage-access"}); |
132 | | - |
133 | | - const p = new Promise(resolve => { |
134 | | - permission.addEventListener("change", (event) => resolve(event), { once: true }); |
135 | | - }); |
| 80 | + // Install observer on frame, and wait for acknowledgement that it is |
| 81 | + // installed. |
| 82 | + assert_equals(await ObservePermissionChange(frame2), |
| 83 | + "permission_change_observer_installed"); |
136 | 84 |
|
137 | | - await test_driver.set_permission({ name: 'storage-access' }, 'granted'); |
138 | | - await document.requestStorageAccess(); |
| 85 | + const observed_event = permissionChangeEvent(); |
| 86 | + await SetPermissionInFrame(frame1, [{ name: 'storage-access' }, 'granted']); |
| 87 | + const state = await observed_event; |
| 88 | + assert_equals(state, "granted"); |
| 89 | + }, "Permissions grants are observable across same-site iframes"); |
139 | 90 |
|
140 | | - const event = await p; |
| 91 | + promise_test(async () => { |
| 92 | + // Finally run the simple tests below in a separate cross-origin iframe. |
| 93 | + await RunTestsInIFrame('https://{{domains[www]}}:{{ports[https][0]}}/storage-access-api/resources/permissions-iframe.https.html'); |
| 94 | + }, "IFrame tests"); |
141 | 95 |
|
142 | | - assert_equals(event.target.name, "storage-access"); |
143 | | - assert_equals(event.target.state, "granted"); |
144 | | - }, "Permission state can be observed"); |
145 | 96 | })(); |
0 commit comments