tor-browser

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

cross-document-traversal-same-document-traversal.html (4260B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Same-document traversals during cross-document traversals</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 
      7 <!--
      8  This case is not significantly different from
      9  cross-document-traversal-cross-document-traversal.html.
     10 -->
     11 
     12 <body>
     13 <script type="module">
     14 import { createIframe, waitForLoad, waitForHashchange, delay, waitForPotentialNetworkLoads } from "./resources/helpers.mjs";
     15 
     16 promise_test(async t => {
     17  const iframe = await createIframe(t);
     18 
     19  // Setup
     20  // Extra delay()s are necessary because if we navigate "inside" the load
     21  // handler (i.e. in a promise reaction for the load handler) then it will
     22  // be a replace navigation.
     23  iframe.contentWindow.location.search = "?1";
     24  await waitForLoad(iframe);
     25  await delay(t, 0);
     26  iframe.contentWindow.location.hash = "#2";
     27  await waitForHashchange(iframe.contentWindow);
     28  iframe.contentWindow.location.search = "?3";
     29  await waitForLoad(iframe);
     30  await delay(t, 0);
     31 
     32  iframe.contentWindow.history.back();
     33  assert_equals(iframe.contentWindow.location.search, "?3", "must not go back synchronously 1 (search)");
     34  assert_equals(iframe.contentWindow.location.hash, "#2", "must not go back synchronously 1 (hash)");
     35 
     36  iframe.contentWindow.history.back();
     37  assert_equals(iframe.contentWindow.location.search, "?3", "must not go back synchronously 2 (search)");
     38  assert_equals(iframe.contentWindow.location.hash, "#2", "must not go back synchronously 2 (hash)");
     39 
     40  await waitForLoad(iframe);
     41  assert_equals(iframe.contentWindow.location.search, "?1", "first load event must be going back (search)");
     42  assert_equals(iframe.contentWindow.location.hash, "", "first load event must be going back (hash)");
     43 
     44  iframe.contentWindow.onhashchange = t.unreached_func("hashchange event");
     45  iframe.onload = t.unreached_func("second load event");
     46 
     47  await waitForPotentialNetworkLoads(t);
     48  assert_equals(iframe.contentWindow.location.search, "?1", "must stay on ?1 (search)");
     49  assert_equals(iframe.contentWindow.location.hash, "", "must stay on ?1 (hash)");
     50 }, "traversals in the same (back) direction: coalesced");
     51 
     52 promise_test(async t => {
     53  const iframe = await createIframe(t);
     54 
     55  // Setup
     56  // Extra delay()s are necessary because if we navigate "inside" the load
     57  // handler (i.e. in a promise reaction for the load handler) then it will
     58  // be a replace navigation.
     59  iframe.contentWindow.location.search = "?1";
     60  await waitForLoad(iframe);
     61  await delay(t, 0);
     62  iframe.contentWindow.location.search = "?2";
     63  await waitForLoad(iframe);
     64  await delay(t, 0);
     65  iframe.contentWindow.location.hash = "#3";
     66  await waitForHashchange(iframe.contentWindow);
     67  iframe.contentWindow.history.back();
     68  await waitForHashchange(iframe.contentWindow);
     69  assert_equals(iframe.contentWindow.location.hash, "", "we made our way to ?2 for setup");
     70  iframe.contentWindow.history.back();
     71  await waitForLoad(iframe);
     72  await delay(t, 0);
     73  assert_equals(iframe.contentWindow.location.search, "?1", "we made our way to ?1 for setup");
     74 
     75  iframe.contentWindow.history.forward();
     76  assert_equals(iframe.contentWindow.location.search, "?1", "must not go forward synchronously 1 (search)");
     77  assert_equals(iframe.contentWindow.location.hash, "", "must not go forward synchronously 1 (hash)");
     78 
     79  iframe.contentWindow.history.forward();
     80  assert_equals(iframe.contentWindow.location.search, "?1", "must not go forward synchronously 2 (search)");
     81  assert_equals(iframe.contentWindow.location.hash, "", "must not go forward synchronously 2 (hash)");
     82 
     83  await waitForLoad(iframe);
     84  assert_equals(iframe.contentWindow.location.search, "?2", "first load event must be going forward (search)");
     85  assert_equals(iframe.contentWindow.location.hash, "#3", "first load event must be going forward (hash)");
     86 
     87  iframe.contentWindow.onhashchange = t.unreached_func("hashchange event");
     88  iframe.onload = t.unreached_func("second load event");
     89 
     90  await waitForPotentialNetworkLoads(t);
     91  assert_equals(iframe.contentWindow.location.search, "?2", "must stay on ?2");
     92  assert_equals(iframe.contentWindow.location.hash, "#3", "must stay on ?2");
     93 }, "traversals in the same (forward) direction: coalesced");
     94 </script>