Skip to content

Commit

Permalink
HTML: BroadcastChannel and SharedArrayBuffer success case revamp
Browse files Browse the repository at this point in the history
The original test could not work. This should be able to work and also adds COOP/COEP headers for future proofing. No browser passes still.

For whatwg/html#4734.
  • Loading branch information
annevk authored Jul 19, 2019
1 parent a5c4731 commit dedb45f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,27 @@
<link rel="author" title="Domenic Denicola" href="mailto:[email protected]">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script> <!-- Use token() to allow running tests in parallel -->

<div id="log"></div>

<script>
"use strict";

promise_test(t => {
const channelName = token();
return Promise.all([
createIFrame("resources/broadcastchannel-iframe.html"),
createIFrame("resources/broadcastchannel-iframe.html"),
createIFrame("resources/broadcastchannel-iframe.html")
createIFrame(`resources/broadcastchannel-iframe.html?channel=${channelName}&index=0`),
createIFrame(`resources/broadcastchannel-iframe.html?channel=${channelName}&index=1`),
createIFrame(`resources/broadcastchannel-iframe.html?channel=${channelName}&index=2`)
]).then(() => {
const sab = new SharedArrayBuffer(3);
const view = new Uint8Array(sab);
const channel = new BroadcastChannel("channel name");
const channel = new BroadcastChannel(channelName);

return new Promise(resolve => {
let soFar = 0;
channel.onmessage = t.step_func(({ data: { sab: broadcastSAB, i } }) => {
if (broadcastSAB) {
// We only care about "broadcasts" from the workers.
return;
}

channel.onmessage = t.step_func(({ data: { i } }) => {
assert_in_array(i, [0, 1, 2], "Any message events must come from expected sources");
++soFar;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

<script>
"use strict";
const channel = new BroadcastChannel("channel name");
const query = new URLSearchParams(location.search);
const channel = new BroadcastChannel(query.get("channel"));
const i = Number(query.get("index"));

channel.onmessage = ({ data: { sab, i }, source }) => {
if (!sab) {
channel.onmessage = e => {
const sab = e.data.sab;
if (sab === undefined) {
// We only care about "broadcasts" from the window
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cross-Origin-Embedder-Policy: require-corp

0 comments on commit dedb45f

Please sign in to comment.