|
12 | 12 | <script> |
13 | 13 | "use strict"; |
14 | 14 |
|
15 | | -const origin = get_host_info().HTTPS_ORIGIN; |
16 | 15 | const noCorpURL = get_host_info().HTTPS_REMOTE_ORIGIN + "/html/document-isolation-policy/resources/nothing-no-corp.js"; |
17 | 16 | // The smallest valid WebAssembly module. |
18 | 17 | const emptyModuleBytes = new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]); |
19 | 18 |
|
20 | | -function executorURL(policy, uuid) { |
21 | | - return origin + executor_path + policy + `&uuid=${uuid}`; |
22 | | -} |
23 | | - |
24 | | -function createFrame(t, url) { |
25 | | - const frame = document.createElement("iframe"); |
26 | | - t.add_cleanup(() => frame.remove()); |
27 | | - const loaded = new Promise(resolve => frame.onload = resolve); |
28 | | - frame.src = url; |
29 | | - document.body.append(frame); |
30 | | - return loaded.then(() => frame); |
31 | | -} |
32 | | - |
33 | | -// Runs the body of an async function in the context identified by uuid and returns its result. |
34 | | -async function runInContext(uuid, body) { |
35 | | - const reply = token(); |
36 | | - send(uuid, ` |
37 | | - (async () => { |
38 | | - let result; |
39 | | - try { |
40 | | - result = await (async () => { ${body} })(); |
41 | | - } catch (e) { |
42 | | - result = e.name; |
43 | | - } |
44 | | - send("${reply}", JSON.stringify(result)); |
45 | | - })(); |
46 | | - `); |
47 | | - return JSON.parse(await receive(reply)); |
48 | | -} |
49 | | - |
50 | 19 | promise_test(async t => { |
51 | 20 | const uuid = token(); |
52 | 21 | const frame = await createFrame(t, executorURL(dip_require_corp, uuid)); |
|
59 | 28 | const uuid = token(); |
60 | 29 | await createFrame(t, executorURL(dip_require_corp, uuid)); |
61 | 30 | const result = await runInContext(uuid, ` |
62 | | - const child = document.createElement("iframe"); |
63 | | - const loaded = new Promise(resolve => child.onload = resolve); |
64 | | - child.src = ${JSON.stringify(executorURL(dip_none, token()))}; |
65 | | - document.body.append(child); |
66 | | - await loaded; |
| 31 | + ${appendFrameScript(executorURL(dip_none, token()))} |
67 | 32 | let access; |
68 | 33 | try { |
69 | 34 | access = typeof child.contentWindow.document; |
|
79 | 44 | const uuid = token(); |
80 | 45 | await createFrame(t, executorURL(dip_require_corp, uuid)); |
81 | 46 | const result = await runInContext(uuid, ` |
82 | | - const child = document.createElement("iframe"); |
83 | | - const loaded = new Promise(resolve => child.onload = resolve); |
84 | | - child.src = ${JSON.stringify(executorURL(dip_require_corp, token()))}; |
85 | | - document.body.append(child); |
86 | | - await loaded; |
| 47 | + ${appendFrameScript(executorURL(dip_require_corp, token()))} |
87 | 48 | return { contentDocument: child.contentDocument === null ? "null" : "document", access: typeof child.contentWindow.document }; |
88 | 49 | `); |
89 | 50 | assert_object_equals(result, { contentDocument: "document", access: "object" }); |
|
179 | 140 | document.body.append(frame); |
180 | 141 | await loaded; |
181 | 142 | const reply = token(); |
| 143 | + // A cross-document navigation can end the document before send() completes, so the result is also stored for its successor. |
182 | 144 | await runInContext(uuid, ` |
183 | | - navigation.onnavigate = event => send("${reply}", event.sourceElement ? "element" : "null"); |
| 145 | + navigation.onnavigate = event => { |
| 146 | + const sourceElement = event.sourceElement ? "element" : "null"; |
| 147 | + sessionStorage.setItem("${reply}", sourceElement); |
| 148 | + send("${reply}", sourceElement); |
| 149 | + }; |
184 | 150 | return "ready"; |
185 | 151 | `); |
186 | 152 | return { url: frame.src, reply }; |
|
207 | 173 | assert_equals(await receive(reply), "element"); |
208 | 174 | }, "A navigate event in a same-origin frame without a policy exposes a link of a document without one as its sourceElement"); |
209 | 175 |
|
| 176 | +promise_test(async t => { |
| 177 | + const name = token(); |
| 178 | + const { reply } = await createNamedFrameWithNavigateListener(t, name); |
| 179 | + const uuid = token(); |
| 180 | + await createFrame(t, executorURL(dip_require_corp, uuid)); |
| 181 | + const destination = token(); |
| 182 | + await runInContext(uuid, clickLinkScript(name, executorURL(dip_none, destination))); |
| 183 | + assert_equals(await runInContext(destination, `return sessionStorage.getItem("${reply}") ?? "no navigate event";`), "null"); |
| 184 | +}, "A cross-document navigate event in a same-origin frame without a policy does not expose a link of a document with one as its sourceElement"); |
| 185 | + |
210 | 186 | promise_test(async t => { |
211 | 187 | const uuid = token(); |
212 | 188 | // The body arrives two seconds after the headers, so the fragment navigation happens while the reload is waiting for it. |
213 | | - const frame = await createFrame(t, origin + executor_path + dip_require_corp + "|trickle(d2)" + `&uuid=${uuid}`); |
| 189 | + const frame = await createFrame(t, executorURL(dip_require_corp + "|trickle(d2)", uuid)); |
214 | 190 | const reloaded = new Promise(resolve => frame.onload = resolve); |
215 | 191 | await runInContext(uuid, ` |
216 | 192 | location.reload(); |
|
249 | 225 | // Opens a cross-origin isolated popup and returns its uuid. |
250 | 226 | function openCrossOriginIsolatedPopup(t) { |
251 | 227 | const uuid = token(); |
252 | | - window.open(origin + executor_path + coopSameOrigin + coepRequireCorp + `&uuid=${uuid}`); |
| 228 | + window.open(executorURL(coopSameOrigin + coepRequireCorp, uuid)); |
253 | 229 | t.add_cleanup(() => send(uuid, "window.close();")); |
254 | 230 | return uuid; |
255 | 231 | } |
256 | 232 |
|
257 | | -function appendFrameScript(url) { |
258 | | - return ` |
259 | | - const child = document.createElement("iframe"); |
260 | | - const loaded = new Promise(resolve => child.onload = resolve); |
261 | | - child.src = ${JSON.stringify(url)}; |
262 | | - document.body.append(child); |
263 | | - await loaded; |
264 | | - `; |
265 | | -} |
266 | | - |
267 | 233 | promise_test(async t => { |
268 | 234 | const topUUID = openCrossOriginIsolatedPopup(t); |
269 | 235 | const childUUID = token(); |
270 | 236 | const result = await runInContext(topUUID, ` |
271 | | - ${appendFrameScript(origin + executor_path + coepRequireCorp + dip_require_corp + `&uuid=${childUUID}`)} |
| 237 | + ${appendFrameScript(executorURL(coepRequireCorp + dip_require_corp, childUUID))} |
272 | 238 | window.child = child; |
273 | 239 | let access; |
274 | 240 | try { |
|
298 | 264 | const topUUID = openCrossOriginIsolatedPopup(t); |
299 | 265 | const frameUUID = token(); |
300 | 266 | await runInContext(topUUID, ` |
301 | | - ${appendFrameScript(remoteOrigin + executor_path + coepRequireCorp + corp_cross_origin + dip_require_corp + `&uuid=${frameUUID}`)} |
| 267 | + ${appendFrameScript(executorURL(coepRequireCorp + corp_cross_origin + dip_require_corp, frameUUID, remoteOrigin))} |
302 | 268 | return "loaded"; |
303 | 269 | `); |
304 | 270 | const accessChild = policy => ` |
305 | | - ${appendFrameScript(remoteOrigin + executor_path + coepRequireCorp + policy + `&uuid=${token()}`)} |
| 271 | + ${appendFrameScript(executorURL(coepRequireCorp + policy, token(), remoteOrigin))} |
306 | 272 | try { |
307 | 273 | return typeof child.contentWindow.document; |
308 | 274 | } catch (e) { |
|
316 | 282 | promise_test(async t => { |
317 | 283 | const uuid = token(); |
318 | 284 | // The opener has no Cross-Origin-Opener-Policy, so the response switches the popup to another browsing context group. |
319 | | - window.open(origin + executor_path + coopSameOrigin + dip_require_corp + `&uuid=${uuid}`); |
| 285 | + window.open(executorURL(coopSameOrigin + dip_require_corp, uuid)); |
320 | 286 | t.add_cleanup(() => send(uuid, "window.close();")); |
321 | 287 | const result = await runInContext(uuid, ` |
322 | 288 | let fetchResult; |
|
326 | 292 | } catch (e) { |
327 | 293 | fetchResult = "blocked"; |
328 | 294 | } |
329 | | - return { originAgentCluster, fetchResult }; |
| 295 | + return { originAgentCluster, crossOriginIsolated, fetchResult }; |
330 | 296 | `); |
331 | | - assert_object_equals(result, { originAgentCluster: true, fetchResult: "blocked" }); |
| 297 | + assert_object_equals(result, { originAgentCluster: true, crossOriginIsolated: true, fetchResult: "blocked" }); |
332 | 298 | }, "A popup with a policy keeps it when its response switches browsing context groups"); |
333 | 299 | </script> |
0 commit comments