Skip to content

Commit

Permalink
Test that BroadcastChannel settings object is current, not incumbent
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Jul 14, 2020
1 parent bf309bb commit 74b3f3f
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
45 changes: 45 additions & 0 deletions webmessaging/multi-globals/broadcastchannel-current.sub.html
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>The current page being cross-origin must prevent the BroadcastChannel message from being seen</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<!-- This is the entry global -->

<iframe src="support/incumbent-document-domain.sub.html" id="incumbent"></iframe>
<iframe src="http://{{hosts[][www]}}:{{ports[http][0]}}/webmessaging/multi-globals/support/current-document-domain.sub.html" id="current"></iframe>

<script>
"use strict";
document.domain = "{{hosts[][]}}";

setup({ explicit_done: true });

const incumbentIframe = document.querySelector("#incumbent");
const currentIframe = document.querySelector("#current");

window.onload = () => {
promise_test(async t => {
const createdCrossOrigin = frames[0].createBroadcastChannel("current");
const createdSameOrigin = new BroadcastChannel("current");

createdSameOrigin.onmessage = t.unreached_func("message event fired");
createdSameOrigin.onmessageerror = t.unreached_func("messageerror event fired");

createdCrossOrigin.postMessage("the message");

// BroadcastChannel messages are guaranteed to be ordered within an event loop, as they all use
// the DOM manipulation task source. So, any messages from the "current" channel, if they are
// going to be erroneously delivered, would have to be delivered before those from this
// channel. I.e., if we recieve a message from this channel without first recieving one from
// the "current" channel, then the test passes.
const testEnder = new BroadcastChannel("current / test-ender");
const testEnder2 = new BroadcastChannel("current / test-ender");

testEnder.postMessage("end test");
await new Promise(resolve => testEnder2.onmessage = resolve);
});

done();
};
</script>
34 changes: 34 additions & 0 deletions webmessaging/multi-globals/broadcastchannel-incumbent.sub.html
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>The incumbent page being cross-origin must not prevent the BroadcastChannel message from being seen</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<!-- This is the entry global -->

<iframe src="http://{{hosts[][www]}}:{{ports[http][0]}}/webmessaging/multi-globals/support/incumbent-document-domain.sub.html" id="incumbent"></iframe>
<iframe src="support/current-document-domain.sub.html" id="current"></iframe>

<script>
"use strict";
document.domain = "{{hosts[][]}}";

setup({ explicit_done: true });

const incumbentIframe = document.querySelector("#incumbent");
const currentIframe = document.querySelector("#current");

window.onload = () => {
async_test(t => {
const createdThroughCrossOrigin = frames[0].createBroadcastChannel("incumbent");
const createdSameOrigin = new BroadcastChannel("incumbent");

createdSameOrigin.onmessage = () => t.done();
createdSameOrigin.onmessageerror = t.unreached_func("messageerror event fired");

createdThroughCrossOrigin.postMessage("the message");
});

done();
};
</script>
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Current page used as a test helper</title>

<h1>Current</h1>

<script>
"use strict";
document.domain = "{{hosts[][]}}";
</script>
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Incumbent page used as a test helper</title>

<h1>Incumbent</h1>

<script>
"use strict";
document.domain = "{{hosts[][]}}";

window.createBroadcastChannel = (...args) => {
return new parent.frames[1].BroadcastChannel(...args);
};
</script>

0 comments on commit 74b3f3f

Please sign in to comment.