Bug 1880216 - Migrate Fenix docs into Sphinx. r=owlish,geckoview-reviewers,android...
[gecko.git] / dom / events / test / test_messageEvent.html
blobac12bbc99b176664474b193a7691faedffd55e58
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=848294
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test for Bug 848294</title>
9 <script src="/tests/SimpleTest/SimpleTest.js"></script>
10 <script src="/tests/SimpleTest/EventUtils.js"></script>
11 <script src="/tests/SimpleTest/WindowSnapshot.js"></script>
12 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
13 </head>
14 <body>
15 <script type="application/javascript">
16 function testMessageEvent(e, test) {
17 ok(e, "MessageEvent created");
18 is(e.type, 'message', 'MessageEvent.type is right');
20 is(e.data, 'data' in test ? test.data : null, 'MessageEvent.data is ok');
21 is(e.origin, 'origin' in test ? test.origin : '', 'MessageEvent.origin is ok');
22 is(e.lastEventId, 'lastEventId' in test ? test.lastEventId : '', 'MessageEvent.lastEventId is ok');
23 is(e.source, 'source' in test ? test.source : null, 'MessageEvent.source is ok');
25 if (test.ports != undefined) {
26 is(e.ports.length, test.ports.length, 'MessageEvent.ports is ok');
27 is(e.ports, e.ports, 'MessageEvent.ports is ok');
28 } else {
29 ok(!('ports' in test) || test.ports == null, 'MessageEvent.ports is ok');
33 function runTest() {
34 var channel = new MessageChannel();
36 var tests = [
37 {},
38 { data: 42 },
39 { data: {} },
40 { data: true, origin: 'wow' },
41 { data: [], lastEventId: 'wow2' },
42 { data: null, source: null },
43 { data: window, source: window },
44 { data: window, source: channel.port1 },
45 { data: window, source: channel.port1, ports: [ channel.port1, channel.port2 ] },
46 { data: null, ports: [] },
49 while (tests.length) {
50 var test = tests.shift();
52 var e = new MessageEvent('message', test);
53 testMessageEvent(e, test);
55 e = new MessageEvent('message');
56 e.initMessageEvent('message', true, true,
57 'data' in test ? test.data : null,
58 'origin' in test ? test.origin : '',
59 'lastEventId' in test ? test.lastEventId : '',
60 'source' in test ? test.source : null,
61 'ports' in test ? test.ports : []);
62 testMessageEvent(e, test);
65 try {
66 var e = new MessageEvent('foobar', { source: 42 });
67 ok(false, "Source has to be a window or a port");
68 } catch(ex) {
69 ok(true, "Source has to be a window or a port");
72 SimpleTest.finish();
75 SimpleTest.waitForExplicitFinish();
76 runTest();
77 </script>
78 </body>
79 </html>