test_messageChannel_post.html (1931B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=677638 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 677638 - port cloning</title> 9 <script src="/tests/SimpleTest/SimpleTest.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=677638">Mozilla Bug 677638</a> 14 <div id="content"></div> 15 <pre id="test"> 16 </pre> 17 <script type="application/javascript"> 18 19 function start() { 20 var a = new MessageChannel(); 21 ok(a, "MessageChannel created"); 22 23 window.addEventListener('message', receiveMessage); 24 function receiveMessage(evt) { 25 if (evt.data.status == 'READY') { 26 runTest(); 27 } else { 28 ok(false, "Unknown message"); 29 } 30 } 31 32 var div = document.getElementById("content"); 33 ok(div, "Parent exists"); 34 35 var ifr = document.createElement("iframe"); 36 ifr.addEventListener("load", iframeLoaded); 37 ifr.setAttribute('src', "iframe_messageChannel_post.html"); 38 div.appendChild(ifr); 39 40 function iframeLoaded() { 41 ifr.contentWindow.postMessage({ port: a.port2 }, '*', [a.port2]); 42 } 43 44 var tests = [ 42, 45 null, 46 undefined, 47 "hello world", 48 new Blob([]), 49 true ]; 50 51 a.port1.onmessage = function(evt) { 52 ok(tests.length, "We are waiting for a message"); 53 if (typeof(tests[0]) == 'object') { 54 is(typeof(tests[0]), typeof(evt.data), "Value ok: " + tests[0]); 55 } else { 56 is(tests[0], evt.data, "Value ok: " + tests[0]); 57 } 58 tests.shift(); 59 runTest(); 60 } 61 62 function runTest() { 63 if (!tests.length) { 64 SimpleTest.finish(); 65 return; 66 } 67 68 a.port1.postMessage(tests[0]); 69 } 70 } 71 72 SimpleTest.waitForExplicitFinish(); 73 start(); 74 </script> 75 </body> 76 </html>