dom/base/test/test_postMessage_solidus.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial