4 https://bugzilla.mozilla.org/show_bug.cgi?id=848294
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"/>
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');
29 ok(!('ports' in test) || test.ports == null, 'MessageEvent.ports is ok');
34 var channel = new MessageChannel();
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);
66 var e = new MessageEvent('foobar', { source:
42 });
67 ok(false,
"Source has to be a window or a port");
69 ok(true,
"Source has to be a window or a port");
75 SimpleTest.waitForExplicitFinish();