summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/portals/history/resources/portal-manipulate-history.html
blob: 3e25f0e6f232f6fdc4a5ea60beb4d76e78638ec4 (plain)
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
<!DOCTYPE html>
<script src="portal-harness.js"></script>
<body>
<script>
  function testHistoryPushStateInPortal() {
    assert(history.length == 1, 'Initial history length');
    assert(!history.state, 'Initial history state');

    history.pushState('teststate', null, null);

    assert(history.length == 1, 'History length unchanged');
    assert(history.state == 'teststate', 'Update state');
  }

  function testHistoryReplaceStateInPortal() {
    assert(history.length == 1, 'Initial history length');
    assert(!history.state, 'Initial history state');

    history.replaceState('teststate', null, null);

    assert(history.length == 1, 'History length unchanged');
    assert(history.state == 'teststate', 'Update state');
  }

  function testLocationAssignInPortal() {
    assert(history.length == 1, 'Initial history length');
    let initialLocation = location.href;
    location.assign('#test');

    assert(history.length == 1, 'History length unchanged');
    assert(location.href != initialLocation, 'Update location');
  }

  function testLocationReplaceInPortal() {
    assert(history.length == 1, 'Initial history length');
    let initialLocation = location.href;
    location.replace('#test');

    assert(history.length == 1, 'History length unchanged');
    assert(location.href != initialLocation, 'Update location');
  }

  function testSetLocationHrefInPortal() {
    assert(history.length == 1, 'Initial history length');
    let initialLocation = location.href;
    location.href = '#test';

    assert(history.length == 1, 'History length unchanged');
    assert(location.href != initialLocation, 'Update location');
  }

  function testSyntheticAnchorClickInPortal() {
    assert(history.length == 1, 'Initial history length');
    let initialLocation = location.href;

    var anchor = document.createElement('a');
    anchor.href = '#test';
    document.body.appendChild(anchor);

    anchor.click();

    assert(history.length == 1, 'History length unchanged');
    assert(location.href != initialLocation, 'Update location');
  }
</script>
</body>