tor-browser

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

iframe-src-204-fragment.html (7011B)


      1 <!DOCTYPE html>
      2 <meta charset="UTF-8">
      3 <title>Fragment navigations on iframe with src set to URL that doesn't load a document (HTTP 204)</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 it will contain the initial empty document. If the
     11  src is set to a URL that doesn't load a new document (e.g. it results in a
     12  HTTP 204 response), it will stay on the initial empty document. After fragment
     13  navigations happen on it, it should still stay on the initial empty document.
     14  These tests verifies the behavior of navigations that happen on the initial
     15  empty document in that situation. They should all be converted to do a
     16  replacement.
     17 */
     18 "use strict";
     19 const url1 = "about:blank#1";
     20 const url2 = "/common/blank.html?2";
     21 
     22 promise_test(async t => {
     23  const startingHistoryLength = history.length;
     24  // Create an iframe with src set to URL that doesn't load a new document, so
     25  // it will stay in the initial empty document.
     26  const iframe = insertIframeWith204Src(t);
     27  assert_equals(history.length, startingHistoryLength,
     28    "Inserting iframe with src set to URL that doesn't load a new document must not change history.length");
     29 
     30  // Do a fragment navigation within the initial empty document through iframe.src.
     31  iframe.src = url1;
     32  await new Promise(resolve => t.step_timeout(resolve, 100));
     33  assert_equals(iframe.contentWindow.location.href, url1);
     34  assert_equals(history.length, startingHistoryLength,
     35    "history.length must not change after fragment navigation on initial empty document");
     36 
     37  // Navigate away from the initial empty document through iframe.src.
     38  iframe.src = url2;
     39  await waitForLoad(t, iframe, url2);
     40  assert_equals(history.length, startingHistoryLength,
     41    "history.length must not change after normal navigation from initial empty document");
     42 }, "src");
     43 
     44 promise_test(async t => {
     45  const startingHistoryLength = history.length;
     46  // Create an iframe with src set to URL that doesn't load a new document, so
     47  // it will stay in the initial empty document.
     48  const iframe = insertIframeWith204Src(t);
     49  assert_equals(history.length, startingHistoryLength,
     50    "Inserting iframe with src set to URL that doesn't load a new document must not change history.length");
     51 
     52  // Do a fragment navigation within the initial empty document through setting location.href.
     53  // This should do a replacement.
     54  iframe.contentWindow.location.href = url1;
     55  await new Promise(resolve => t.step_timeout(resolve, 100));
     56  assert_equals(iframe.contentWindow.location.href, url1);
     57  assert_equals(history.length, startingHistoryLength,
     58    "history.length must not change after fragment navigation on initial empty document");
     59 
     60  // Navigate away from the initial empty document through setting location.href.
     61  // This should do a replacement.
     62  iframe.contentWindow.location.href = url2;
     63  await waitForLoad(t, iframe, url2);
     64  assert_equals(history.length, startingHistoryLength,
     65    "history.length must not change after normal navigation from initial empty document");
     66 }, "location.href");
     67 
     68 promise_test(async t => {
     69  const startingHistoryLength = history.length;
     70  // Create an iframe with src set to URL that doesn't load a new document, so
     71  // it will stay in the initial empty document.
     72  const iframe = insertIframeWith204Src(t);
     73  await new Promise(resolve => t.step_timeout(resolve, 100));
     74  assert_equals(history.length, startingHistoryLength,
     75    "Inserting iframe with src set to URL that doesn't load a new document must not change history.length");
     76 
     77  // Do a fragment navigation within the initial empty document through location.assign().
     78  // This should do a replacement.
     79  iframe.contentWindow.location.assign(url1);
     80  assert_equals(iframe.contentWindow.location.href, url1);
     81  assert_equals(history.length, startingHistoryLength,
     82    "history.length must not change after fragment navigation on initial empty document");
     83 
     84  // Navigate away from the initial empty document through location.assign().
     85  // This should do a replacement.
     86  iframe.contentWindow.location.assign(url2);
     87  await waitForLoad(t, iframe, url2);
     88  assert_equals(history.length, startingHistoryLength,
     89    "history.length must not change after normal navigation from initial empty document");
     90 }, "location.assign");
     91 
     92 promise_test(async t => {
     93  const startingHistoryLength = history.length;
     94  // Create an iframe with src set to URL that doesn't load a new document, so
     95  // it will stay in the initial empty document.
     96  const iframe = insertIframeWith204Src(t);
     97  await new Promise(resolve => t.step_timeout(resolve, 100));
     98  assert_equals(history.length, startingHistoryLength,
     99    "Inserting iframe with src set to URL that doesn't load a new document must not change history.length");
    100 
    101  // Do a fragment navigation within the initial empty document through window.open().
    102  // This should do a replacement.
    103  iframe.contentWindow.open(url1, "_self");
    104  assert_equals(iframe.contentWindow.location.href, url1);
    105  assert_equals(history.length, startingHistoryLength,
    106    "history.length must not change after fragment navigation on initial empty document");
    107 
    108  // Navigate away from the initial empty document through window.open().
    109  // This should do a replacement.
    110  iframe.contentWindow.open(url2, "_self");
    111  await waitForLoad(t, iframe, url2);
    112  assert_equals(history.length, startingHistoryLength,
    113    "history.length must not change after normal navigation from initial empty document");
    114 }, "window.open");
    115 
    116 promise_test(async t => {
    117  const startingHistoryLength = history.length;
    118  // Create an iframe with src set to URL that doesn't load a new document, so it will stay in the initial empty document.
    119  const iframe = insertIframeWith204Src(t);
    120  assert_equals(history.length, startingHistoryLength,
    121    "Inserting iframe with src set to URL that doesn't load a new document must not change history.length");
    122 
    123  // Do a fragment navigation within the initial empty document through clicking an <a> element.
    124  // This should do a replacement.
    125  const a1 = iframe.contentDocument.createElement("a");
    126  a1.href = url1;
    127  iframe.contentDocument.body.appendChild(a1);
    128  a1.click();
    129  await new Promise(resolve => t.step_timeout(resolve, 100));
    130  assert_equals(iframe.contentWindow.location.href, url1);
    131  assert_equals(history.length, startingHistoryLength,
    132    "history.length must not change after fragment navigation on initial empty document");
    133 
    134  // Navigate away from the initial empty document through clicking an <a> element.
    135  // This should do a replacement.
    136  const a2 = iframe.contentDocument.createElement("a");
    137  a2.href = url2;
    138  iframe.contentDocument.body.appendChild(a2);
    139  a2.click();
    140  await waitForLoad(t, iframe, url2);
    141  assert_equals(history.length, startingHistoryLength,
    142    "history.length must not change after normal navigation from initial empty document");
    143 }, "link click");
    144 </script>