|
1 <!DOCTYPE html> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage |
|
5 --> |
|
6 <head> |
|
7 <title>postMessage override test</title> |
|
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
10 </head> |
|
11 <body> |
|
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage">Mozilla Bug 387706</a> |
|
13 <p id="display"></p> |
|
14 <div id="content" style="display: none"></div> |
|
15 |
|
16 <iframe src="http://example.org:8000/tests/dom/tests/mochitest/whatwg/postMessage_override_helper.html"></iframe> |
|
17 |
|
18 |
|
19 <pre id="test"> |
|
20 <script class="testbody" type="application/javascript"> |
|
21 /** Test for Bug 387706 **/ |
|
22 |
|
23 SimpleTest.waitForExplicitFinish(); |
|
24 |
|
25 var count = 0; |
|
26 |
|
27 function test(callback) |
|
28 { |
|
29 try |
|
30 { |
|
31 count++; |
|
32 switch (count) |
|
33 { |
|
34 case 1: |
|
35 window.frames[0].postMessage("PASS 1", "http://example.org:8000"); |
|
36 break; |
|
37 |
|
38 case 2: |
|
39 window.frames[0].postMessage("PASS 2", "http://example.org:8000"); |
|
40 break; |
|
41 |
|
42 default: |
|
43 ok(false, "unexpected"); |
|
44 } |
|
45 } |
|
46 catch (e) |
|
47 { |
|
48 ok(false, "error running test " + count + ": " + e); |
|
49 } |
|
50 |
|
51 // Waiting for sent postMessage event to be processed... |
|
52 setTimeout(function() |
|
53 { |
|
54 // Waiting for responding postMessage event to be processed... |
|
55 setTimeout(function() |
|
56 { |
|
57 // We have our response! |
|
58 callback(); |
|
59 }, 0); |
|
60 }, 0); |
|
61 } |
|
62 |
|
63 function messageReceiver(evt) |
|
64 { |
|
65 var expect; |
|
66 |
|
67 switch (count) |
|
68 { |
|
69 case 1: |
|
70 expect = "PASS 1"; |
|
71 break; |
|
72 |
|
73 case 2: |
|
74 expect = "PASS 2"; |
|
75 break; |
|
76 |
|
77 default: |
|
78 expect = "unexpected"; |
|
79 break; |
|
80 } |
|
81 |
|
82 is(evt.data, expect, |
|
83 "uh-oh, we (" + count + ") didn't get the right postMessage!"); |
|
84 } |
|
85 |
|
86 window.addEventListener("message", messageReceiver, false); |
|
87 |
|
88 function run() |
|
89 { |
|
90 test(function() |
|
91 { |
|
92 test(function() |
|
93 { |
|
94 SimpleTest.finish(); |
|
95 }, 0); |
|
96 }); |
|
97 } |
|
98 |
|
99 window.addEventListener("load", run, false); |
|
100 </script> |
|
101 </pre> |
|
102 </body> |
|
103 </html> |