tor-browser

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

navigation-traverseTo-navigates-top-and-same-doc-child-and-cross-doc-child.html (2390B)


      1 <!doctype html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <iframe id="i1" src="/common/blank.html"></iframe>
      5 <iframe id="i2" src="/common/blank.html"></iframe>
      6 <script>
      7 promise_test(async t => {
      8  let start_length = navigation.entries().length;
      9  let start_index = navigation.currentEntry.index;
     10 
     11  // Wait for after the load event so that the navigation doesn't get converted
     12  // into a replace navigation.
     13  await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
     14  await navigation.navigate("#").finished;
     15  await i1.contentWindow.navigation.navigate("#").finished;
     16  i2.contentWindow.navigation.navigate("?");
     17  await new Promise(resolve => i2.onload = () => t.step_timeout(resolve, 0));
     18 
     19  assert_equals(navigation.entries().length, start_length + 1);
     20  assert_equals(i1.contentWindow.navigation.entries().length, 2);
     21  assert_equals(i2.contentWindow.navigation.entries().length, 2);
     22  assert_equals(navigation.currentEntry.index, start_index + 1);
     23  assert_equals(i1.contentWindow.navigation.currentEntry.index, 1);
     24  assert_equals(i2.contentWindow.navigation.currentEntry.index, 1);
     25 
     26  let navigate_event_count = 0;
     27  navigation.onnavigate = t.step_func(e => {
     28    assert_equals(navigate_event_count, 0);
     29    navigate_event_count++;
     30    assert_true(e.cancelable);
     31  });
     32  i1.contentWindow.navigation.onnavigate = t.step_func(e => {
     33    assert_true(navigate_event_count > 0);
     34    navigate_event_count++;
     35    assert_false(e.cancelable);
     36  });
     37  i2.contentWindow.navigation.onnavigate = t.step_func(e => {
     38    assert_true(navigate_event_count > 0);
     39    navigate_event_count++;
     40    assert_false(e.cancelable);
     41  });
     42 
     43  await navigation.traverseTo(navigation.entries()[start_index].key).finished;
     44  // The top window will finish quickly, becuase it is same-document traversal.
     45  // i2 will be slower because it is cross-document, so wait for its onload.
     46  await new Promise(resolve => i2.onload = () => t.step_timeout(resolve, 0));
     47  assert_equals(navigate_event_count, 3);
     48  assert_equals(navigation.currentEntry.index, start_index);
     49  assert_equals(i1.contentWindow.navigation.currentEntry.index, 0);
     50  assert_equals(i2.contentWindow.navigation.currentEntry.index, 0);
     51 }, "navigation.traverseTo() can navigate 3 frames of different types with correct navigate event cancelable values");
     52 </script>