tor-browser

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

postMessage_MessagePorts_xorigin.sub.htm (2054B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title> postMessage to cross-origin iframe with MessagePort array [100 ports] </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: postMessage to cross-origin iframe with MessagePort array containing 100 ports.";
     19 
     20    var t = async_test(description);
     21 
     22    var TOTALPORTS = 100;
     23    var LocalPorts = [];
     24    var RemotePorts = [];
     25    var PassedResult = 0;
     26    var sum = 0;
     27    var TARGET = document.querySelector("iframe").contentWindow;
     28 
     29    function PostMessageTest()
     30    {
     31        test(function()
     32        {
     33            assert_own_property(window, "MessageChannel", "window");
     34 
     35            var channels = [];
     36 
     37            for (var i=0; i<TOTALPORTS; i++)
     38            {
     39                channels[i] = new MessageChannel();
     40                LocalPorts[i] = channels[i].port1;
     41                LocalPorts[i].foo = i;
     42                RemotePorts[i] = channels[i].port2;
     43 
     44                LocalPorts[i].onmessage = t.step_func(function(e)
     45                {
     46                    assert_equals(e.target.foo, e.data);
     47 
     48                    PassedResult++;
     49                    sum += e.data;
     50 
     51                    if (PassedResult == TOTALPORTS)
     52                    {
     53                        assert_equals(sum, 4950);
     54                        t.done();
     55                    }
     56                });
     57            }
     58 
     59            TARGET.postMessage("ports", "*", RemotePorts);
     60 
     61        }, "MessageChannel is supported.");
     62    }
     63 
     64    window.onmessage = function(e)
     65    {
     66        if (e.data === "ports")
     67        {
     68            for (var i=0; i<TOTALPORTS; i++)
     69            {
     70                LocalPorts[i].postMessage(LocalPorts[i].foo);
     71            }
     72        }
     73    }
     74 </script>
     75 </body>
     76 </html>