tor-browser

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

postMessage_clone_port.htm (859B)


      1 <!DOCTYPE html>
      2 <title> postMessage(): clone a port </title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <div id=log></div>
      6 <script>
      7 async_test(function(t) {
      8  var channelA = new MessageChannel();
      9  var channelB = new MessageChannel();
     10  var originalPort = channelB.port2;
     11  channelA.port2.onmessage = t.step_func(function(e) {
     12    assert_equals(e.data, "ports");
     13    var clonedPort = e.ports[0];
     14    assert_not_equals(clonedPort, originalPort, "new cloned port object should not equal to the original port!");
     15    clonedPort.onmessage = t.step_func_done(function(e) {
     16      assert_equals(e.data, "ping", "Data sent through remote port is received by the new cloned port");
     17    });
     18  });
     19  channelA.port1.postMessage("ports", [channelB.port2]);
     20  channelB.port1.postMessage("ping");
     21 });
     22 </script>