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