tor-browser

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

Channel_postMessage_transfer_xsite_incoming_messages.window.js (1174B)


      1 // META: script=/common/get-host-info.sub.js
      2 
      3 async_test(function(t) {
      4  var channel1 = new MessageChannel();
      5  var host = get_host_info();
      6  let iframe = document.createElement('iframe');
      7  iframe.src = host.HTTP_NOTSAMESITE_ORIGIN + "/webmessaging/support/ChildWindowPostMessage.htm";
      8  document.body.appendChild(iframe);
      9  var TARGET = document.querySelector("iframe").contentWindow;
     10  iframe.onload = t.step_func(function() {
     11    // Enable the port.
     12    channel1.port1.onmessage = t.step_func(function (evt) {
     13      assert_equals(Number(evt.data), 0);
     14 
     15      // Send a message, expecting it to be received in the iframe.
     16      channel1.port2.postMessage(1)
     17 
     18      // Transfer the port.
     19      TARGET.postMessage("ports", "*", [channel1.port1]);
     20    });
     21 
     22    // Send a message, expecting it to be received here.
     23    channel1.port2.postMessage(0)
     24 
     25    channel1.port2.onmessage = t.step_func(function (evt) {
     26        assert_equals(Number(evt.data), 1);
     27        t.done();
     28      });
     29  });
     30 }, `Tasks enqueued on the port-message-queue of an enabled port,
     31  are transferred along with the port, when the transfer happens in the same task
     32  during which postMessage is called`);