tor-browser

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

back-forward-multiple-frames.html (4149B)


      1 <!doctype html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <iframe id="i" src="/common/blank.html"></iframe>
      5 <script>
      6 promise_test(async t => {
      7  // Wait for after the load event so that the navigation doesn't get converted
      8  // into a replace navigation.
      9  let start_length = navigation.entries().length;
     10  let start_index = navigation.currentEntry.index;
     11  await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
     12  // Step 1
     13  assert_equals(navigation.entries().length, start_length, "step 1 outer entries() length");
     14  assert_equals(i.contentWindow.navigation.entries().length, 1, "step 1 iframe entries() length");
     15  await navigation.navigate("#top").committed;
     16  // Step 2: iframe at initial entry, top on second entry
     17  assert_equals(navigation.entries().length, start_length+1, "step 2 outer entries() length");
     18  assert_equals(i.contentWindow.navigation.entries().length, 1, "step 2 iframe entries() length");
     19  await i.contentWindow.navigation.navigate("#iframe").committed;
     20 
     21  // Step 3: Both windows on second entry.
     22  assert_equals(navigation.entries().length, start_length+1, "step 3 outer entries() length");
     23  assert_equals(i.contentWindow.navigation.entries().length, 2, "step 3 iframe entries() length");
     24  assert_equals(navigation.currentEntry.index, start_index+1, "step 3 outer index");
     25  assert_equals(i.contentWindow.navigation.currentEntry.index, 1, "step 1 iframe index");
     26 
     27  // NOTE: the order of navigation in the two windows is not guaranteed; we need to wait for both.
     28 
     29  // Going back in the iframe should go 3->2 (navigating iframe only)
     30  await Promise.all([
     31    i.contentWindow.navigation.back().committed,
     32    new Promise(resolve => i.contentWindow.onpopstate = resolve)
     33  ]);
     34  assert_equals(navigation.currentEntry.index, start_index+1, "after iframe back() outer index");
     35  assert_equals(i.contentWindow.navigation.currentEntry.index, 0, "after iframe back() iframe index");
     36 
     37  // Going forward in iframe should go 2->3
     38  await Promise.all([
     39    i.contentWindow.navigation.forward().commited,
     40    new Promise(resolve => i.contentWindow.onpopstate = resolve)
     41  ]);
     42  assert_equals(navigation.currentEntry.index, start_index+1, "after iframe forward() outer index");
     43  assert_equals(i.contentWindow.navigation.currentEntry.index, 1, "after iframe forward() iframe index");
     44 
     45  // Going back in top should go 3->1 (navigating both windows).
     46  await Promise.all([
     47    navigation.back().commited,
     48    new Promise(resolve => i.contentWindow.onpopstate = resolve)
     49  ]);
     50  assert_equals(navigation.currentEntry.index, start_index, "after outer back() outer index");
     51  assert_equals(i.contentWindow.navigation.currentEntry.index, 0, "after outer back() iframe index");
     52 
     53  // Next two should not navigate the iframe
     54  i.contentWindow.onpopstate = t.unreached_func("popstate must not be called");
     55 
     56  // Going forward in top should go 1->2 (navigating top only)
     57  await navigation.forward().committed;
     58  await new Promise(resolve => t.step_timeout(resolve, 0));
     59  assert_equals(navigation.currentEntry.index, start_index+1, "after outer forward() outer index");
     60  assert_equals(i.contentWindow.navigation.currentEntry.index, 0, "after outer forward() iframe index");
     61 
     62  // Going back in top should go 2->1
     63  await navigation.back().committed;
     64  await new Promise(resolve => t.step_timeout(resolve, 0));
     65  assert_equals(navigation.currentEntry.index, start_index, "after outer second back() outer index");
     66  assert_equals(i.contentWindow.navigation.currentEntry.index, 0, "after outer second back() iframe index");
     67 
     68  // Going forward in iframe should go 1->3 (navigating both windows)
     69  await Promise.all([
     70    i.contentWindow.navigation.forward().commited,
     71    new Promise(resolve => i.contentWindow.onpopstate = resolve)
     72  ]);
     73  assert_equals(navigation.currentEntry.index, start_index+1, "after iframe second forward() outer index");
     74  assert_equals(i.contentWindow.navigation.currentEntry.index, 1, "after iframe second forward() iframe index");
     75 }, "navigation.back() and navigation.forward() can navigate multiple frames");
     76 </script>