File: dispose-same-document-intercept.html

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (73 lines) | stat: -rw-r--r-- 3,443 bytes parent folder | download | duplicates (12)
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
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async (t) => {
  // Wait for after the load event so that the navigation doesn't get converted
  // into a replace navigation.
  await new Promise(r => window.onload = () => t.step_timeout(r, 0));
  let start_length = navigation.entries().length;
  let start_index = navigation.currentEntry.index;

  location.hash = "#1";
  location.hash = "#2";
  location.hash = "#3";

  assert_equals(navigation.entries().length, start_length + 3);
  const [entry0, entry1, entry2, entry3] = navigation.entries().slice(start_index);
  assert_equals((new URL(entry2.url)).hash, "#2");
  assert_equals((new URL(entry3.url)).hash, "#3");

  let dispose2Called = false;
  entry2.ondispose = t.step_func(e => {
    dispose2Called = true;

    assert_equals(e.constructor, Event);
    assert_equals(e.bubbles, false);
    assert_equals(e.cancelable, false);
    assert_equals(e.composed, false);

    assert_array_equals(
      navigation.entries().slice(start_index),
      [entry0, entry1, navigation.currentEntry],
      "entries() is updated during dispose for entry 2");
    assert_not_equals(navigation.currentEntry, entry1, "current entry must be updated during dispose for entry 3");
    assert_true(navigation.canGoBack, "canGoBack is still true during dispose for entry 2");
    assert_false(navigation.canGoForward, "canGoForward is still false during beforedispose for entry 2");
    assert_equals(navigation.transition.navigationType, "push", "transition navigationType during dispose for entry 2");
    assert_equals(navigation.transition.from, entry1, "transition from during dispose for entry 2");
    assert_equals(location.hash, "#fork", "location.hash is updated during dispose for entry 2");
  });

  entry3.addEventListener("dispose", t.step_func_done(e => {
    assert_true(dispose2Called, "dispose for entry 2 must have happened before entry 3");

    assert_array_equals(
      navigation.entries().slice(start_index),
      [entry0, entry1, navigation.currentEntry],
      "entries() is updated during dispose for entry 3");
    assert_not_equals(navigation.currentEntry, entry1, "current entry must be updated during dispose for entry 3");
    assert_true(navigation.canGoBack, "canGoBack is still true during dispose for entry 3");
    assert_false(navigation.canGoForward, "canGoForward is still false during beforedispose for entry 3");
    assert_equals(navigation.transition.navigationType, "push", "transition navigationType during dispose for entry 3");
    assert_equals(navigation.transition.from, entry1, "transition from during dispose for entry 3");
    assert_equals(location.hash, "#fork", "location.hash is updated during dispose for entry 3");
  }));

  await navigation.traverseTo(entry1.key).committed;

  navigation.addEventListener("navigate", e => {
    e.intercept();
  });

  navigation.navigate("#fork");

  assert_equals(navigation.entries().length, start_length + 2);
  const [finalEntry0, finalEntry1, finalEntry2] = navigation.entries().slice(start_index);
  assert_equals(finalEntry0, entry0);
  assert_equals(finalEntry1, entry1);
  assert_not_equals(finalEntry2, entry2);
  assert_equals(navigation.currentEntry, finalEntry2);
  assert_equals((new URL(finalEntry2.url)).hash, "#fork");
}, "dispose events when forward-pruning same-document entries");
</script>