Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
11 <script type="application/javascript" 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 runTest() {
17 var channel = new MessageChannel();
19 var tests = [
20 {},
21 { data: 42 },
22 { data: {} },
23 { data: true, origin: 'wow' },
24 { data: [], lastEventId: 'wow2' },
25 { data: null, source: null },
26 { data: window, source: window },
27 { data: window, source: channel.port1 },
28 { data: window, source: channel.port1, ports: [ channel.port1, channel.port2 ] },
29 { data: null, ports: null },
30 ];
32 while (tests.length) {
33 var test = tests.shift();
35 var e = new MessageEvent('message', test);
36 ok(e, "MessageEvent created");
37 is(e.type, 'message', 'MessageEvent.type is right');
39 is(e.data, 'data' in test ? test.data : undefined, 'MessageEvent.data is ok');
40 is(e.origin, 'origin' in test ? test.origin : '', 'MessageEvent.origin is ok');
41 is(e.lastEventId, 'lastEventId' in test ? test.lastEventId : '', 'MessageEvent.lastEventId is ok');
42 is(e.source, 'source' in test ? test.source : undefined, 'MessageEvent.source is ok');
44 if (test.ports != undefined) {
45 is(e.ports.length, test.ports.length, 'MessageEvent.ports is ok');
46 is(e.ports, e.ports, 'MessageEvent.ports is ok');
47 } else {
48 ok(!('ports' in test) || test.ports == null, 'MessageEvent.ports is ok');
49 }
50 }
52 try {
53 var e = new MessageEvent('foobar', { source: 42 });
54 ok(false, "Source has to be a window or a port");
55 } catch(e) {
56 ok(true, "Source has to be a window or a port");
57 }
59 SimpleTest.finish();
60 }
62 SimpleTest.waitForExplicitFinish();
63 SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
64 </script>
65 </body>
66 </html>