tor-browser

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

test_current_inner_window.html (2063B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test that current inner window checks are correct after navigations/discards</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      8 </head>
      9 <body>
     10 
     11 <iframe id="frame"></iframe>
     12 
     13 <script type="application/javascript">
     14 "use strict";
     15 
     16 const TEST_FILE = "file_current_inner_window.html";
     17 const BASE_PATH = location.pathname.replace(/[^\/]+$/, "");
     18 
     19 let frame = document.getElementById("frame");
     20 
     21 function loadInFrame(url) {
     22  return new Promise(resolve => {
     23    frame.addEventListener("load", resolve, { once: true });
     24    frame.contentWindow.location = url;
     25  });
     26 }
     27 
     28 add_task(async function() {
     29  await loadInFrame(TEST_FILE);
     30 
     31  // Store the check function from the window before we navigate. After that,
     32  // its bare word property accesses will continue referring to the same inner
     33  // window no matter how many times the frame navigates.
     34  let check1 = frame.contentWindow.isCurrentWinnerWindow;
     35  ok(check1(),
     36     "Initial inner window should be current before we navigate away");
     37 
     38  await loadInFrame(`http://example.com/${BASE_PATH}/${TEST_FILE}`);
     39  ok(!check1(),
     40     "Initial inner window should no longer be current after we navigate away");
     41  await SpecialPowers.spawn(frame, [], () => {
     42    Assert.ok(this.content.wrappedJSObject.isCurrentWinnerWindow(),
     43              "Remote inner window should be current after before we navigate away");
     44  });
     45 
     46  await loadInFrame(TEST_FILE);
     47  ok(!check1(),
     48     "Initial inner window should still not be current after we back to current process");
     49  let check2 = frame.contentWindow.isCurrentWinnerWindow;
     50  ok(check2(),
     51     "Second in-process inner window should be current before we remove the frame");
     52 
     53  frame.remove();
     54  ok(!check1(),
     55     "Initial inner window should still not be current after we remove the frame");
     56  ok(check2(),
     57     "Second in-process inner window should still be current after we remove the frame");
     58 });
     59 </script>
     60 </body>
     61 </html>