dom/base/test/iframe_messageChannel_pingpong.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 <body>
     4   <script type="application/javascript">
     6   function ok(what, msg) {
     7     window.parent.postMessage({type: what ? 'OK' : 'KO', msg: msg }, '*');
     8   }
    10   window.addEventListener('message', receiveMessage, false);
    11   function receiveMessage(evt) {
    12     if (evt.data.type == 'PORT') {
    13       var port = evt.data.port;
    14       var counter = 0;
    15       port.onmessage = function(evt) {
    16         if (counter++ == 0) {
    17           ok(!(evt.data % 2), "The number " + evt.data + " has been received correctly by the iframe");
    19           window.parent.postMessage({ type: 'PORT', port: port }, '*', [port]);
    20         }
    21         else {
    22           ok(false, "Wrong message!");
    23         }
    24       }
    25     } else {
    26       ok(false, "Unknown message");
    27     }
    28   }
    30   </script>
    31 </body>
    32 </html>

mercurial