Skip to content

Commit

Permalink
Bug 1564940 [wpt PR 17760] - HTML: BroadcastChannel and SharedArrayBu…
Browse files Browse the repository at this point in the history
…ffer success case revamp, a=testonly

Automatic update from web-platform-tests
HTML: BroadcastChannel and SharedArrayBuffer success case revamp

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.
--

wpt-commits: dedb45f5f20e0ac884ac59634cceb8659cdcff7d
wpt-pr: 17760
  • Loading branch information
annevk authored and moz-wptsync-bot committed Jul 31, 2019
1 parent 60139b0 commit 47ec301
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:d@domenic.me">
<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 47ec301

Please sign in to comment.