Skip to content

Commit 996c4b4

Browse files
recvfromchromium-wpt-export-bot
authored andcommitted
[BroadcastChannel] Add Partitioning WPT
This CL tests that BroadcastChannel is partitioned in third-party contexts (tentative, pending changes to the spec). For more info, see whatwg/html#5803 Bug: 1239274 Change-Id: I8d495ecb141847276aefd1bcc4a1af0ea1098db2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3424369 Reviewed-by: Ben Kelly <[email protected]> Reviewed-by: Mason Freed <[email protected]> Commit-Queue: Andrew Williams <[email protected]> Cr-Commit-Position: refs/heads/main@{#967421}
1 parent d6608a6 commit 996c4b4

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!DOCTYPE html>
2+
<meta charset=utf-8>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script src="/common/get-host-info.sub.js"></script>
6+
<script src="/common/utils.js"></script>
7+
<script src="/common/dispatcher/dispatcher.js"></script>
8+
<!-- Pull in executor_path needed by newPopup / newIframe -->
9+
<script src="/html/cross-origin-embedder-policy/credentialless/resources/common.js"></script>
10+
<!-- Pull in newPopup / newIframe -->
11+
<script src="/html/cross-origin-embedder-policy/anonymous-iframe/resources/common.js"></script>
12+
<body>
13+
<script>
14+
15+
const emit_script = (channel_name, message, done_queue_name) => `
16+
const bc = new BroadcastChannel("${channel_name}");
17+
bc.postMessage("${message}");
18+
send("${done_queue_name}", "done");
19+
`;
20+
21+
promise_test(async t => {
22+
const origin = get_host_info().HTTPS_ORIGIN;
23+
const not_same_site_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
24+
const response_queue_uuid = token();
25+
26+
const popup_init_script = `
27+
const importScript = ${importScript};
28+
await importScript("/html/cross-origin-embedder-policy/credentialless" +
29+
"/resources/common.js");
30+
await importScript("/html/cross-origin-embedder-policy/anonymous-iframe" +
31+
"/resources/common.js");
32+
await importScript("/common/utils.js");
33+
send("${response_queue_uuid}", newIframe("${origin}"));
34+
`;
35+
36+
// Create a same-origin iframe in a cross-site popup.
37+
const not_same_site_popup_uuid = newPopup(t, not_same_site_origin);
38+
send(not_same_site_popup_uuid, popup_init_script);
39+
const iframe_1_uuid = await receive(response_queue_uuid);
40+
41+
// Create a same-origin iframe in a same-site popup.
42+
const same_origin_popup_uuid = newPopup(t, origin);
43+
send(same_origin_popup_uuid, popup_init_script);
44+
const iframe_2_uuid = await receive(response_queue_uuid);
45+
46+
const channel_name = token();
47+
const bc = new BroadcastChannel(channel_name);
48+
bc.onmessage = t.step_func(e => {
49+
assert_equals(e.data, "msg from iframe2");
50+
t.done();
51+
});
52+
53+
// Instruct the not-same-top-level-site iframe to send a message on the BC
54+
// channel we are listening on. This message should not be received since
55+
// the iframe should be in a different partition.
56+
send(iframe_1_uuid,
57+
emit_script(channel_name, "msg from iframe1", response_queue_uuid));
58+
assert_equals(await receive(response_queue_uuid), "done");
59+
60+
// Now instruct the same-top-level-site iframe to send a BC message. By
61+
// the time we send the script to execute, have it send the BC message,
62+
// and then receive the BC message in our BC instance, it should be
63+
// reasonable to assume that the message from the first iframe would have
64+
// been delivered if it was going to be.
65+
send(iframe_2_uuid,
66+
emit_script(channel_name, "msg from iframe2", response_queue_uuid));
67+
assert_equals(await receive(response_queue_uuid), "done");
68+
69+
}, "BroadcastChannel messages aren't received from a cross-partition iframe");
70+
71+
</script>
72+
</body>

0 commit comments

Comments
 (0)