summaryrefslogtreecommitdiffstats
path: root/dom/broadcastchannel/tests/test_ordering.html
blob: eab1f955e5bad9458a55f8862f0d315bfb153e81 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for BroadcastChannel.postMessage invalid State</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>

<div id="content"></div>

<script type="application/javascript">

let c1 = new BroadcastChannel('order');
let c2 = new BroadcastChannel('order');
let c3 = new BroadcastChannel('order');

let events = [];
let doneCount = 0;

function whichBC(bc) {
  if (bc == c1) return "c1";
  if (bc == c2) return "c2";
  if (bc == c3) return "c3";
  return "What?!?";
}

function handler(e) {
  events.push(e);
  if (e.data == 'done') {
    doneCount++;
    if (doneCount == 2) {
      is(events.length, 6, "Correct length");
      is(whichBC(events[0].target), "c2", 'target for event 0');
      is(events[0].data, 'from c1');
      is(whichBC(events[1].target), "c3", 'target for event 1');
      is(events[1].data, 'from c1');
      is(whichBC(events[2].target), "c1", 'target for event 2');
      is(events[2].data, 'from c3');
      is(whichBC(events[3].target), "c2", 'target for event 3');
      is(events[3].data, 'from c3');
      is(whichBC(events[4].target), "c1", 'target for event 4');
      is(events[4].data, 'done');
      is(whichBC(events[5].target), "c3", 'target for event 5');
      is(events[5].data, 'done');

      SimpleTest.finish();
    }
  }
}

c1.onmessage = handler;
c2.onmessage = handler;
c3.onmessage = handler;

c1.postMessage('from c1');
c3.postMessage('from c3');
c2.postMessage('done');

SimpleTest.waitForExplicitFinish();

</script>
</body>
</html>