dom/tests/mochitest/whatwg/test_postMessage_override.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

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

mercurial