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

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

mercurial