|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <body> |
|
4 <script type="application/javascript"> |
|
5 |
|
6 function ok(what, msg) { |
|
7 window.parent.postMessage({type: what ? 'OK' : 'KO', msg: msg }, '*'); |
|
8 } |
|
9 |
|
10 window.addEventListener('message', receiveMessage, false); |
|
11 function receiveMessage(evt) { |
|
12 if (evt.data.type == 'PORT') { |
|
13 var port = evt.data.port; |
|
14 var counter = 0; |
|
15 port.onmessage = function(evt) { |
|
16 if (counter++ == 0) { |
|
17 ok(!(evt.data % 2), "The number " + evt.data + " has been received correctly by the iframe"); |
|
18 |
|
19 window.parent.postMessage({ type: 'PORT', port: port }, '*', [port]); |
|
20 } |
|
21 else { |
|
22 ok(false, "Wrong message!"); |
|
23 } |
|
24 } |
|
25 } else { |
|
26 ok(false, "Unknown message"); |
|
27 } |
|
28 } |
|
29 |
|
30 </script> |
|
31 </body> |
|
32 </html> |
|
33 |