summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webmessaging/multi-globals/broadcastchannel-current.sub.html
blob: ae2369394e7e182b136a9341d148a5cb33f24600 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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>