dom/tests/mochitest/whatwg/test_postMessage_closed.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 <head>
     4   <title>postMessage's interaction with closed windows</title>
     5   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
     6   <script type="text/javascript" src="browserFu.js"></script>
     7   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     8 </head>
     9 <body>
    10 <p><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=417075">Bug 417075</a></p>
    11 <p id="display"></p>
    12 <div id="content" style="display: none"></div>
    14 <div id="holder"></div>
    16 <pre id="test">
    17 <script class="testbody" type="application/javascript">
    19 SimpleTest.waitForExplicitFinish();
    21 function receiveMessage(evt)
    22 {
    23   is(evt.origin, "http://mochi.test:8888", "wrong origin");
    24   ok(evt.source === openedWindow, "wrong source");
    25   is(evt.lastEventId, "", "postMessage creates events with empty lastEventId");
    27   is(evt.data, "message", "wrong data");
    28   if (evt.data !== "message")
    29     return; // prevent recursion if bugs
    31   evt.source.close();
    33   function afterClose()
    34   {
    35     document.removeEventListener("message", receiveMessage, false);
    36     evt.source.postMessage("NOT-RECEIVED", "*");
    38     var iframe = document.createElement("iframe");
    39     iframe.id = "insertedIframe";
    40     $("holder").appendChild(iframe);
    41     iframe.addEventListener("load", iframeLoaded, false);
    42     iframe.src = "postMessage_closed_helper.html?parent";
    43   }
    45   setTimeout(afterClose, 0);
    46 }
    48 window.addEventListener("message", receiveMessage, false);
    50 function iframeLoaded(evt)
    51 {
    52   var iframe = $("insertedIframe");
    53   iframe.removeEventListener("load", iframeLoaded, false);
    55   var iframeWindow = iframe.contentWindow;
    56   $("holder").removeChild($("insertedIframe"));
    57   iframeWindow.postMessage("NOT-RECEIVED", "*");
    59   SimpleTest.finish();
    60 }
    62 var openedWindow;
    64 function run()
    65 {
    66   openedWindow = window.open("postMessage_closed_helper.html?opener", "foobar");
    67   if (!openedWindow)
    68   {
    69     ok(false, "this test must be run with popup blocking disabled");
    70     SimpleTest.finish();
    71   }
    72 }
    74 window.addEventListener("load", run, false);
    75 </script>
    76 </pre>
    77 </body>
    78 </html>

mercurial