|
1 |
|
2 <!DOCTYPE HTML> |
|
3 <html> |
|
4 <!-- |
|
5 https://bugzilla.mozilla.org/show_bug.cgi?id=949488 |
|
6 --> |
|
7 <head> |
|
8 <meta charset="utf-8"> |
|
9 <title>Test for Bug 949488 - basic support</title> |
|
10 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
12 </head> |
|
13 <body> |
|
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=949488">Mozilla Bug 949488</a> |
|
15 <div id="content"></div> |
|
16 <script type="application/javascript"> |
|
17 |
|
18 function selfMessage() { |
|
19 addEventListener('message', receiveMessage); |
|
20 function receiveMessage(evt) { |
|
21 is(evt.data, 1, "Message received"); |
|
22 removeEventListener('message', receiveMessage); |
|
23 runTest(); |
|
24 } |
|
25 |
|
26 postMessage(1, '/'); |
|
27 } |
|
28 |
|
29 function frameOk() { |
|
30 var ifr = document.createElement("iframe"); |
|
31 ifr.addEventListener("load", iframeLoaded, false); |
|
32 ifr.setAttribute('src', "iframe_postMessage_solidus.html"); |
|
33 |
|
34 var div = document.getElementById("content"); |
|
35 div.appendChild(ifr); |
|
36 |
|
37 function iframeLoaded() { |
|
38 addEventListener('message', receiveMessage); |
|
39 function receiveMessage(evt) { |
|
40 is(evt.data, 2, "Message received"); |
|
41 removeEventListener('message', receiveMessage); |
|
42 runTest(); |
|
43 } |
|
44 |
|
45 ifr.contentWindow.postMessage(2, '/'); |
|
46 } |
|
47 } |
|
48 |
|
49 function frameWrong() { |
|
50 var ifr = document.createElement("iframe"); |
|
51 ifr.addEventListener("load", iframeLoaded, false); |
|
52 ifr.setAttribute('src', "http://www.example.com/tests/dom/base/test/iframe_postMessage_solidus.html"); |
|
53 |
|
54 var div = document.getElementById("content"); |
|
55 div.appendChild(ifr); |
|
56 |
|
57 function iframeLoaded() { |
|
58 addEventListener('message', receiveMessage); |
|
59 function receiveMessage(evt) { |
|
60 ok(evt.data, 3, "Message received"); |
|
61 removeEventListener('message', receiveMessage); |
|
62 runTest(); |
|
63 } |
|
64 |
|
65 ifr.contentWindow.postMessage(4, '/'); |
|
66 SimpleTest.executeSoon(function() { |
|
67 ifr.contentWindow.postMessage(3, '*'); |
|
68 }); |
|
69 } |
|
70 } |
|
71 |
|
72 var tests = [ |
|
73 selfMessage, |
|
74 frameOk, |
|
75 frameWrong |
|
76 ]; |
|
77 |
|
78 function runTest() { |
|
79 if (!tests.length) { |
|
80 SimpleTest.finish(); |
|
81 return; |
|
82 } |
|
83 |
|
84 var test = tests.shift(); |
|
85 test(); |
|
86 } |
|
87 |
|
88 SimpleTest.waitForExplicitFinish(); |
|
89 runTest(); |
|
90 |
|
91 </script> |
|
92 </body> |
|
93 </html> |