11cb0ef41Sopenharmony_ci<!DOCTYPE html>
21cb0ef41Sopenharmony_ci<meta charset=utf-8>
31cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script>
41cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script>
51cb0ef41Sopenharmony_ci<script src="/common/get-host-info.sub.js"></script>
61cb0ef41Sopenharmony_ci<script src="/common/utils.js"></script>
71cb0ef41Sopenharmony_ci<script src="/common/dispatcher/dispatcher.js"></script>
81cb0ef41Sopenharmony_ci<!-- Pull in executor_path needed by newPopup / newIframe -->
91cb0ef41Sopenharmony_ci<script src="/html/cross-origin-embedder-policy/credentialless/resources/common.js"></script>
101cb0ef41Sopenharmony_ci<!-- Pull in newPopup / newIframe -->
111cb0ef41Sopenharmony_ci<script src="/html/cross-origin-embedder-policy/anonymous-iframe/resources/common.js"></script>
121cb0ef41Sopenharmony_ci<body>
131cb0ef41Sopenharmony_ci<script>
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciconst emit_script = (channel_name, message, done_queue_name) => `
161cb0ef41Sopenharmony_ci  const bc = new BroadcastChannel("${channel_name}");
171cb0ef41Sopenharmony_ci  bc.postMessage("${message}");
181cb0ef41Sopenharmony_ci  send("${done_queue_name}", "done");
191cb0ef41Sopenharmony_ci`;
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_cipromise_test(async t => {
221cb0ef41Sopenharmony_ci  const origin = get_host_info().HTTPS_ORIGIN;
231cb0ef41Sopenharmony_ci  const not_same_site_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
241cb0ef41Sopenharmony_ci  const response_queue_uuid = token();
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  const popup_init_script = `
271cb0ef41Sopenharmony_ci    const importScript = ${importScript};
281cb0ef41Sopenharmony_ci    await importScript("/html/cross-origin-embedder-policy/credentialless" +
291cb0ef41Sopenharmony_ci                       "/resources/common.js");
301cb0ef41Sopenharmony_ci    await importScript("/html/cross-origin-embedder-policy/anonymous-iframe" +
311cb0ef41Sopenharmony_ci                       "/resources/common.js");
321cb0ef41Sopenharmony_ci    await importScript("/common/utils.js");
331cb0ef41Sopenharmony_ci    send("${response_queue_uuid}", newIframe("${origin}"));
341cb0ef41Sopenharmony_ci  `;
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  // Create a same-origin iframe in a cross-site popup.
371cb0ef41Sopenharmony_ci  const not_same_site_popup_uuid = newPopup(t, not_same_site_origin);
381cb0ef41Sopenharmony_ci  send(not_same_site_popup_uuid, popup_init_script);
391cb0ef41Sopenharmony_ci  const iframe_1_uuid = await receive(response_queue_uuid);
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  // Create a same-origin iframe in a same-site popup.
421cb0ef41Sopenharmony_ci  const same_origin_popup_uuid = newPopup(t, origin);
431cb0ef41Sopenharmony_ci  send(same_origin_popup_uuid, popup_init_script);
441cb0ef41Sopenharmony_ci  const iframe_2_uuid = await receive(response_queue_uuid);
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci  const channel_name = token();
471cb0ef41Sopenharmony_ci  const bc = new BroadcastChannel(channel_name);
481cb0ef41Sopenharmony_ci  bc.onmessage = t.step_func(e => {
491cb0ef41Sopenharmony_ci    assert_equals(e.data, "msg from iframe2");
501cb0ef41Sopenharmony_ci    t.done();
511cb0ef41Sopenharmony_ci  });
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci  // Instruct the not-same-top-level-site iframe to send a message on the BC
541cb0ef41Sopenharmony_ci  // channel we are listening on. This message should not be received since
551cb0ef41Sopenharmony_ci  // the iframe should be in a different partition.
561cb0ef41Sopenharmony_ci  send(iframe_1_uuid,
571cb0ef41Sopenharmony_ci       emit_script(channel_name, "msg from iframe1", response_queue_uuid));
581cb0ef41Sopenharmony_ci  assert_equals(await receive(response_queue_uuid), "done");
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci  // Now instruct the same-top-level-site iframe to send a BC message. By
611cb0ef41Sopenharmony_ci  // the time we send the script to execute, have it send the BC message,
621cb0ef41Sopenharmony_ci  // and then receive the BC message in our BC instance, it should be
631cb0ef41Sopenharmony_ci  // reasonable to assume that the message from the first iframe would have
641cb0ef41Sopenharmony_ci  // been delivered if it was going to be.
651cb0ef41Sopenharmony_ci  send(iframe_2_uuid,
661cb0ef41Sopenharmony_ci       emit_script(channel_name, "msg from iframe2", response_queue_uuid));
671cb0ef41Sopenharmony_ci  assert_equals(await receive(response_queue_uuid), "done");
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ci}, "BroadcastChannel messages aren't received from a cross-partition iframe");
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci</script>
721cb0ef41Sopenharmony_ci</body>
73