tor-browser

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

event.ports.sub.htm (1550B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title> event.ports returns the MessagePort array sent with the message </title>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 </head>
      8 <body>
      9 <div id=log></div>
     10 
     11 <div style="display:none">
     12    <iframe width="70%" onload="PostMessageTest()" src="{{location[scheme]}}://{{domains[www1]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe>
     13 </div>
     14 
     15 <script>
     16 
     17 
     18    var description = "Test Description: event.ports returns the MessagePort array sent with the message.";
     19 
     20    var t = async_test(description);
     21 
     22    var DATA = {test: "e.source.postMessage(e.ports.toString(), '*', e.ports)"};
     23    var TARGET = document.querySelector("iframe");
     24    var ExpectedResult = "";
     25 
     26    function PostMessageTest()
     27    {
     28        test(function()
     29        {
     30            assert_own_property(window, "MessageChannel", "window");
     31 
     32            var channel = new MessageChannel();
     33            var ports = [channel.port1, channel.port2];
     34            ExpectedResult = ports.toString();
     35            TARGET.contentWindow.postMessage(DATA, "*", ports);
     36 
     37        }, "MessageChannel is supported.");
     38    }
     39 
     40    window.onmessage = t.step_func(function(e)
     41    {
     42        assert_equals(e.data, ExpectedResult, "e.data");
     43        assert_true(e.ports[0] instanceof MessagePort, e.ports[0] + " instanceof MessageChannel");
     44        assert_true(e.ports[1] instanceof MessagePort, e.ports[1] + " instanceof MessageChannel");
     45        t.done();
     46    });
     47 </script>
     48 </body>
     49 </html>