tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_postMessage_closed.html (1958B)


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