tor-browser

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

iframe-src-aboutblank-wait-for-load.html (6559B)


      1 <!DOCTYPE html>
      2 <meta charset="UTF-8">
      3 <title>Navigations after iframe with src='about:blank' finished loading</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 an iframe is created with src="about:blank", it will stay on the initial
     11    empty document. These tests verify the behavior of navigations that happen
     12    immediately after the load event is fired on the iframe element, which
     13    should result in replacement.
     14  */
     15 "use strict";
     16 const url1 = "/common/blank.html?1";
     17 
     18 promise_test(async t => {
     19  const startingHistoryLength = history.length;
     20  // Create an iframe with src set to about:blank, and wait for it to finish
     21  // loading. This would trigger and commit a navigation to a non-initial
     22  // about:blank document.
     23  const iframe = await insertIframeWithAboutBlankSrcWaitForLoad(t);
     24  assert_equals(history.length, startingHistoryLength,
     25    "Inserting iframe with src='about:blank' must not change history.length");
     26 
     27  // Trigger a navigation to url1 through the iframe's src attribute.
     28  // The iframe should still be on the initial empty document, and the
     29  // navigation should do replacement.
     30  iframe.src = url1;
     31  // Wait for the latest navigation to finish.
     32  await waitForLoad(t, iframe, url1);
     33  assert_equals(history.length, startingHistoryLength,
     34    "history.length must not change after normal navigation on initial empty document");
     35 }, "Navigating to a different document with src");
     36 
     37 promise_test(async t => {
     38  const startingHistoryLength = history.length;
     39  // Create an iframe with src set to about:blank, and wait for it to finish
     40  // loading. This would trigger and commit a navigation to a non-initial
     41  // about:blank document.
     42  const iframe = await insertIframeWithAboutBlankSrcWaitForLoad(t);
     43  assert_equals(history.length, startingHistoryLength,
     44    "Inserting iframe with src='about:blank' must not change history.length");
     45 
     46  // Navigate away from the initial empty document through setting
     47  // location.href. The iframe should still be on the initial empty document,
     48  // and the navigation should do replacement.
     49  iframe.contentWindow.location.href = url1;
     50  await waitForLoad(t, iframe, url1);
     51  assert_equals(history.length, startingHistoryLength,
     52    "history.length must not change after normal navigation on initial empty document");
     53 }, "Navigating to a different document with location.href");
     54 
     55 promise_test(async t => {
     56  const startingHistoryLength = history.length;
     57  // Create an iframe with src set to about:blank, and wait for it to finish
     58  // loading. This would trigger and commit a navigation to a non-initial
     59  // about:blank document.
     60  const iframe = await insertIframeWithAboutBlankSrcWaitForLoad(t);
     61  assert_equals(history.length, startingHistoryLength,
     62    "Inserting iframe with src='about:blank' must not change history.length");
     63 
     64  // Navigate away from the initial empty document through setting
     65  // location.href. The iframe should still be on the initial empty document,
     66  // and the navigation should do replacement.
     67  iframe.contentWindow.location.href = url1;
     68  await waitForLoad(t, iframe, url1);
     69  assert_equals(history.length, startingHistoryLength,
     70    "history.length must not change after normal navigation on initial empty document");
     71 }, "Navigating to a different document with location.assign");
     72 
     73 promise_test(async t => {
     74  const startingHistoryLength = history.length;
     75  // Create an iframe with src set to about:blank, and wait for it to finish
     76  // loading. This would trigger and commit a navigation to a non-initial
     77  // about:blank document.
     78  const iframe = await insertIframeWithAboutBlankSrcWaitForLoad(t);
     79  assert_equals(history.length, startingHistoryLength,
     80    "Inserting iframe with src='about:blank' must not change history.length");
     81 
     82  // Navigate away from the initial empty document through window.open().
     83  // The iframe should still be on the initial empty document, and the
     84  // navigation should do replacement.
     85  iframe.contentWindow.open(url1, "_self");
     86  await waitForLoad(t, iframe, url1);
     87  assert_equals(history.length, startingHistoryLength,
     88    "history.length must not change after normal navigation on initial empty document");
     89 }, "Navigating to a different document with window.open");
     90 
     91 promise_test(async t => {
     92  const startingHistoryLength = history.length;
     93  // Create an iframe with src set to about:blank, and wait for it to finish
     94  // loading. This would trigger and commit a navigation to a non-initial
     95  // about:blank document.
     96  const iframe = await insertIframeWithAboutBlankSrcWaitForLoad(t);
     97  assert_equals(history.length, startingHistoryLength,
     98    "Inserting iframe with src='about:blank' must not change history.length");
     99 
    100  // Navigate away from the initial empty document through clicking an <a>
    101  // element. The iframe should still be on the initial empty document, and the
    102  // navigation should do replacement.
    103  const a = iframe.contentDocument.createElement("a");
    104  a.href = url1;
    105  iframe.contentDocument.body.appendChild(a);
    106  a.click();
    107  await waitForLoad(t, iframe, url1);
    108  assert_equals(history.length, startingHistoryLength,
    109    "history.length must not change after normal navigation on initial empty document");
    110 }, "Navigating to a different document with link click");
    111 
    112 promise_test(async t => {
    113  const startingHistoryLength = history.length;
    114  // Create an iframe with src set to about:blank which will commit an about:blank document that is not the initial empty document, and wait for it to load.
    115  const iframe = await insertIframeWithAboutBlankSrcWaitForLoad(t);
    116  assert_equals(history.length, startingHistoryLength,
    117    "Inserting iframe with src='about:blank' must not change history.length");
    118 
    119  // Navigate away from the initial empty document through form submission.
    120  // The iframe should still be on the initial empty document, and the
    121  // navigation should do replacement.
    122  const form = iframe.contentDocument.createElement("form");
    123  form.action = "/common/blank.html";
    124  iframe.contentDocument.body.appendChild(form);
    125  const input = iframe.contentDocument.createElement("input");
    126  input.type = "hidden";
    127  input.name = "1";
    128  form.append(input);
    129  form.submit();
    130  await waitForLoad(t, iframe, url1 + "=");
    131  assert_equals(history.length, startingHistoryLength,
    132    "history.length must not change after normal navigation on initial empty document");
    133 }, "Navigating to a different document with form submission");
    134 </script>