File: back-forward-multiple-frames.html

package info (click to toggle)
firefox 142.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,591,884 kB
  • sloc: cpp: 7,451,570; javascript: 6,392,463; ansic: 3,712,584; python: 1,388,569; xml: 629,223; asm: 426,919; java: 184,857; sh: 63,439; makefile: 19,150; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,352; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (76 lines) | stat: -rw-r--r-- 4,149 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe id="i" src="/common/blank.html"></iframe>
<script>
promise_test(async t => {
  // Wait for after the load event so that the navigation doesn't get converted
  // into a replace navigation.
  let start_length = navigation.entries().length;
  let start_index = navigation.currentEntry.index;
  await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
  // Step 1
  assert_equals(navigation.entries().length, start_length, "step 1 outer entries() length");
  assert_equals(i.contentWindow.navigation.entries().length, 1, "step 1 iframe entries() length");
  await navigation.navigate("#top").committed;
  // Step 2: iframe at initial entry, top on second entry
  assert_equals(navigation.entries().length, start_length+1, "step 2 outer entries() length");
  assert_equals(i.contentWindow.navigation.entries().length, 1, "step 2 iframe entries() length");
  await i.contentWindow.navigation.navigate("#iframe").committed;

  // Step 3: Both windows on second entry.
  assert_equals(navigation.entries().length, start_length+1, "step 3 outer entries() length");
  assert_equals(i.contentWindow.navigation.entries().length, 2, "step 3 iframe entries() length");
  assert_equals(navigation.currentEntry.index, start_index+1, "step 3 outer index");
  assert_equals(i.contentWindow.navigation.currentEntry.index, 1, "step 1 iframe index");

  // NOTE: the order of navigation in the two windows is not guaranteed; we need to wait for both.

  // Going back in the iframe should go 3->2 (navigating iframe only)
  await Promise.all([
    i.contentWindow.navigation.back().committed,
    new Promise(resolve => i.contentWindow.onpopstate = resolve)
  ]);
  assert_equals(navigation.currentEntry.index, start_index+1, "after iframe back() outer index");
  assert_equals(i.contentWindow.navigation.currentEntry.index, 0, "after iframe back() iframe index");

  // Going forward in iframe should go 2->3
  await Promise.all([
    i.contentWindow.navigation.forward().commited,
    new Promise(resolve => i.contentWindow.onpopstate = resolve)
  ]);
  assert_equals(navigation.currentEntry.index, start_index+1, "after iframe forward() outer index");
  assert_equals(i.contentWindow.navigation.currentEntry.index, 1, "after iframe forward() iframe index");

  // Going back in top should go 3->1 (navigating both windows).
  await Promise.all([
    navigation.back().commited,
    new Promise(resolve => i.contentWindow.onpopstate = resolve)
  ]);
  assert_equals(navigation.currentEntry.index, start_index, "after outer back() outer index");
  assert_equals(i.contentWindow.navigation.currentEntry.index, 0, "after outer back() iframe index");

  // Next two should not navigate the iframe
  i.contentWindow.onpopstate = t.unreached_func("popstate must not be called");

  // Going forward in top should go 1->2 (navigating top only)
  await navigation.forward().committed;
  await new Promise(resolve => t.step_timeout(resolve, 0));
  assert_equals(navigation.currentEntry.index, start_index+1, "after outer forward() outer index");
  assert_equals(i.contentWindow.navigation.currentEntry.index, 0, "after outer forward() iframe index");

  // Going back in top should go 2->1
  await navigation.back().committed;
  await new Promise(resolve => t.step_timeout(resolve, 0));
  assert_equals(navigation.currentEntry.index, start_index, "after outer second back() outer index");
  assert_equals(i.contentWindow.navigation.currentEntry.index, 0, "after outer second back() iframe index");

  // Going forward in iframe should go 1->3 (navigating both windows)
  await Promise.all([
    i.contentWindow.navigation.forward().commited,
    new Promise(resolve => i.contentWindow.onpopstate = resolve)
  ]);
  assert_equals(navigation.currentEntry.index, start_index+1, "after iframe second forward() outer index");
  assert_equals(i.contentWindow.navigation.currentEntry.index, 1, "after iframe second forward() iframe index");
}, "navigation.back() and navigation.forward() can navigate multiple frames");
</script>