dom/tests/mochitest/whatwg/test_postMessage_override.html

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 <!DOCTYPE html>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>postMessage override test</title>
michael@0 8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage">Mozilla Bug 387706</a>
michael@0 13 <p id="display"></p>
michael@0 14 <div id="content" style="display: none"></div>
michael@0 15
michael@0 16 <iframe src="http://example.org:8000/tests/dom/tests/mochitest/whatwg/postMessage_override_helper.html"></iframe>
michael@0 17
michael@0 18
michael@0 19 <pre id="test">
michael@0 20 <script class="testbody" type="application/javascript">
michael@0 21 /** Test for Bug 387706 **/
michael@0 22
michael@0 23 SimpleTest.waitForExplicitFinish();
michael@0 24
michael@0 25 var count = 0;
michael@0 26
michael@0 27 function test(callback)
michael@0 28 {
michael@0 29 try
michael@0 30 {
michael@0 31 count++;
michael@0 32 switch (count)
michael@0 33 {
michael@0 34 case 1:
michael@0 35 window.frames[0].postMessage("PASS 1", "http://example.org:8000");
michael@0 36 break;
michael@0 37
michael@0 38 case 2:
michael@0 39 window.frames[0].postMessage("PASS 2", "http://example.org:8000");
michael@0 40 break;
michael@0 41
michael@0 42 default:
michael@0 43 ok(false, "unexpected");
michael@0 44 }
michael@0 45 }
michael@0 46 catch (e)
michael@0 47 {
michael@0 48 ok(false, "error running test " + count + ": " + e);
michael@0 49 }
michael@0 50
michael@0 51 // Waiting for sent postMessage event to be processed...
michael@0 52 setTimeout(function()
michael@0 53 {
michael@0 54 // Waiting for responding postMessage event to be processed...
michael@0 55 setTimeout(function()
michael@0 56 {
michael@0 57 // We have our response!
michael@0 58 callback();
michael@0 59 }, 0);
michael@0 60 }, 0);
michael@0 61 }
michael@0 62
michael@0 63 function messageReceiver(evt)
michael@0 64 {
michael@0 65 var expect;
michael@0 66
michael@0 67 switch (count)
michael@0 68 {
michael@0 69 case 1:
michael@0 70 expect = "PASS 1";
michael@0 71 break;
michael@0 72
michael@0 73 case 2:
michael@0 74 expect = "PASS 2";
michael@0 75 break;
michael@0 76
michael@0 77 default:
michael@0 78 expect = "unexpected";
michael@0 79 break;
michael@0 80 }
michael@0 81
michael@0 82 is(evt.data, expect,
michael@0 83 "uh-oh, we (" + count + ") didn't get the right postMessage!");
michael@0 84 }
michael@0 85
michael@0 86 window.addEventListener("message", messageReceiver, false);
michael@0 87
michael@0 88 function run()
michael@0 89 {
michael@0 90 test(function()
michael@0 91 {
michael@0 92 test(function()
michael@0 93 {
michael@0 94 SimpleTest.finish();
michael@0 95 }, 0);
michael@0 96 });
michael@0 97 }
michael@0 98
michael@0 99 window.addEventListener("load", run, false);
michael@0 100 </script>
michael@0 101 </pre>
michael@0 102 </body>
michael@0 103 </html>

mercurial