tor-browser

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

messageport-current.html (1639B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Making the current page become non-active must prevent message transmission</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 
      7 <!-- This is the entry global -->
      8 
      9 <iframe src="support/incumbent.html" id="incumbent"></iframe>
     10 <iframe src="support/current.html" id="current"></iframe>
     11 
     12 <script>
     13 "use strict";
     14 const incumbentIframe = document.querySelector("#incumbent");
     15 const currentIframe = document.querySelector("#current");
     16 
     17 window.addEventListener("load", () => {
     18  promise_test(async t => {
     19    // This will invoke the constructor from currentIframe, but with incumbentIframe as the incumbent.
     20    const messageChannel = incumbentIframe.contentWindow.createMessageChannel();
     21 
     22    await new Promise((resolve, reject) => {
     23      currentIframe.onload = () => resolve();
     24      currentIframe.onerror = () => reject(new Error("Could not navigate the iframe"));
     25      currentIframe.src = "/common/blank.html";
     26    });
     27 
     28    messageChannel.port1.onmessage = t.unreached_func("message event recieved");
     29    messageChannel.port1.onmessageerror = t.unreached_func("messageerror event recieved");
     30    messageChannel.port2.postMessage("boo");
     31 
     32    // We are testing that neither of the above two events fire. We assume that a 3 second timeout
     33    // is good enough. We can't use any other API for an end condition because each MessagePort has
     34    // its own independent port message queue, which has no ordering guarantees relative to other
     35    // APIs.
     36    await new Promise(resolve => t.step_timeout(resolve, 3000));
     37  });
     38 });
     39 </script>