1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/test/iframe_messageChannel_pingpong.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,33 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<body> 1.7 + <script type="application/javascript"> 1.8 + 1.9 + function ok(what, msg) { 1.10 + window.parent.postMessage({type: what ? 'OK' : 'KO', msg: msg }, '*'); 1.11 + } 1.12 + 1.13 + window.addEventListener('message', receiveMessage, false); 1.14 + function receiveMessage(evt) { 1.15 + if (evt.data.type == 'PORT') { 1.16 + var port = evt.data.port; 1.17 + var counter = 0; 1.18 + port.onmessage = function(evt) { 1.19 + if (counter++ == 0) { 1.20 + ok(!(evt.data % 2), "The number " + evt.data + " has been received correctly by the iframe"); 1.21 + 1.22 + window.parent.postMessage({ type: 'PORT', port: port }, '*', [port]); 1.23 + } 1.24 + else { 1.25 + ok(false, "Wrong message!"); 1.26 + } 1.27 + } 1.28 + } else { 1.29 + ok(false, "Unknown message"); 1.30 + } 1.31 + } 1.32 + 1.33 + </script> 1.34 +</body> 1.35 +</html> 1.36 +