|
1 <!DOCTYPE html> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage |
|
5 --> |
|
6 <head> |
|
7 <title>MessageEvent tests</title> |
|
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <script type="text/javascript" src="browserFu.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
11 </head> |
|
12 <body> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage">Mozilla Bug 387706</a> |
|
14 <p id="display"></p> |
|
15 <div id="content" style="display: none"> |
|
16 |
|
17 </div> |
|
18 |
|
19 <button id="target">target</button> |
|
20 |
|
21 <pre id="test"> |
|
22 <script class="testbody" type="application/javascript"> |
|
23 /** Test for Bug 387706 **/ |
|
24 |
|
25 SimpleTest.waitForExplicitFinish(); |
|
26 |
|
27 var data = "foobar"; |
|
28 var origin = "http://cool.example.com"; |
|
29 var bubbles = true, cancelable = true; |
|
30 var lastEventId = "lastEventId"; |
|
31 |
|
32 var target; |
|
33 |
|
34 var count = 0; |
|
35 |
|
36 function sendMsg() |
|
37 { |
|
38 try |
|
39 { |
|
40 var evt = new MessageEvent('message', { |
|
41 bubbles: bubbles, cancelable: cancelable, data: data, |
|
42 origin: origin, lastEventId: lastEventId, source: window}); |
|
43 ok(evt instanceof MessageEvent, "I ordered a MessageEvent!"); |
|
44 |
|
45 is(evt.data, data, "unexpected data"); |
|
46 is(evt.origin, origin, "unexpected origin"); |
|
47 is(evt.lastEventId, lastEventId, "unexpected lastEventId"); |
|
48 |
|
49 is(evt.cancelable, cancelable, "wrong cancelable property"); |
|
50 is(evt.bubbles, bubbles, "wrong bubbling property"); |
|
51 is(evt.source, window, "wrong source"); |
|
52 |
|
53 return target.dispatchEvent(evt); |
|
54 } |
|
55 catch (e) |
|
56 { |
|
57 ok(false, "exception thrown: " + e); |
|
58 return false; |
|
59 } |
|
60 } |
|
61 |
|
62 function recvMsg(evt) |
|
63 { |
|
64 is(evt.data, data, "unexpected data"); |
|
65 is(evt.origin, origin, "unexpected origin"); |
|
66 is(evt.lastEventId, lastEventId, "unexpected lastEventId"); |
|
67 |
|
68 is(evt.cancelable, cancelable, "wrong cancelable property"); |
|
69 is(evt.bubbles, bubbles, "wrong bubbling property"); |
|
70 is(evt.source, window, "wrong source"); |
|
71 |
|
72 is(evt.target, target, "wrong target"); |
|
73 |
|
74 if (target == evt.currentTarget) |
|
75 { |
|
76 is(Event.AT_TARGET, evt.eventPhase, "this listener was on the target"); |
|
77 } |
|
78 else |
|
79 { |
|
80 is(evt.currentTarget, document, "should have gotten this at the window"); |
|
81 is(Event.BUBBLING_PHASE, evt.eventPhase, "wrong phase"); |
|
82 } |
|
83 |
|
84 count++; |
|
85 } |
|
86 |
|
87 function setup() |
|
88 { |
|
89 target = $("target"); |
|
90 target.addEventListener("message", recvMsg, false); |
|
91 document.addEventListener("message", recvMsg, false); |
|
92 var res = sendMsg(); |
|
93 ok(res === true, "nothing canceled this"); |
|
94 is(count, 2, "listener not called twice"); |
|
95 SimpleTest.finish(); |
|
96 } |
|
97 |
|
98 addLoadEvent(setup); |
|
99 |
|
100 </script> |
|
101 </pre> |
|
102 </body> |
|
103 </html> |