tor-browser

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

window-open-nourl.html (3625B)


      1 <!DOCTYPE html>
      2 <meta charset="UTF-8">
      3 <title>Navigations on window.open() to URL that doesn't load a new document</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="resources/helpers.js"></script>
      7 <body></body>
      8 <script>
      9 /*
     10  When a new window is opened through window.open() it will contain the initial
     11  empty document. If the URL parameter is not set, it will stay on the initial
     12  empty document.
     13  These tests verify the behavior of navigations that happen on the initial
     14  empty document in that situation. They should all be converted to do a
     15  replacement.
     16 */
     17 "use strict";
     18 const url1 = "resources/code-injector.html?1&pipe=sub(none)&code=" + encodeURIComponent(postMessageToOpenerOnLoad);
     19 const url2 = "resources/code-injector.html?2&pipe=sub(none)&code=" + encodeURIComponent(postMessageToOpenerOnLoad);
     20 
     21 promise_test(async t => {
     22  // Open a new window with no URL, which will stay in the initial empty document until the navigation below.
     23  const openedWindow = windowOpenNoURL(t);
     24 
     25  // Navigate away from the initial empty document through setting
     26  // location.href. This should do a replacement.
     27  openedWindow.location.href = url1;
     28  await waitForMessage(t, "loaded");
     29  assert_equals(openedWindow.history.length, 1,
     30    "history.length should not increase after normal navigation away from initial empty document");
     31 
     32  // Navigate again using the same method, but this time it shouldn't do a
     33  // replacement since it's no longer on the initial empty document.
     34  openedWindow.location.href = url2;
     35  await waitForMessage(t, "loaded");
     36  assert_equals(openedWindow.history.length, 2,
     37    "history.length should increase after normal navigation away from non-initial empty document");
     38 }, "location.href");
     39 
     40 promise_test(async t => {
     41  // Open a new window with no URL, which will stay in the initial empty document until the navigation below.
     42  const openedWindow = windowOpenNoURL(t);
     43 
     44  // Navigate away from the initial empty document through location.assign().
     45  // This should do a replacement.
     46  openedWindow.location.assign(url1);
     47  await waitForMessage(t, "loaded");
     48  assert_equals(openedWindow.history.length, 1,
     49    "history.length should not increase after normal navigation away from initial empty document");
     50 
     51  // Navigate again using the same method, but this time it shouldn't do a
     52  // replacement since it's no longer on the initial empty document.
     53  openedWindow.location.assign(url2);
     54  await waitForMessage(t, "loaded");
     55  assert_equals(openedWindow.history.length, 2,
     56    "history.length should increase after normal navigation away from non-initial empty document");
     57 }, "location.assign");
     58 /*
     59 promise_test(async t => {
     60  // Open a new window with no URL, which will stay in the initial empty document until the navigation below.
     61  const openedWindow = windowOpenNoURL(t);
     62 
     63  // Navigate away from the initial empty document through setting
     64  // window.open(). This should do a replacement.
     65  openedWindow.open(url1, "_self");
     66  await waitForMessage(t, "loaded");
     67  assert_equals(openedWindow.history.length, 1,
     68    "history.length should not increase after normal navigation away from initial empty document");
     69 
     70  // Navigate again using the same method, but this time it shouldn't do a
     71  // replacement since it's no longer on the initial empty document.
     72  openedWindow.open(url2, "_self");
     73  await waitForMessage(t, "loaded");
     74  assert_equals(openedWindow.history.length, 2,
     75    "history.length should increase after normal navigation away from non-initial empty document");
     76 }, "window.open");
     77 */
     78 </script>