summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/browsing-the-web/history-traversal/PopStateEvent.html
blob: 9ee75762493b04360af01cd3966ecf3500d03041 (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
<!doctype html>
<meta charset=utf-8>
<title>Synthetic popstate events</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
test(function() {
  assert_throws_js(
    TypeError,
    () => PopStateEvent(''),
    "Calling PopStateEvent constructor without 'new' must throw"
  );
}, "PopStateEvent constructor called as normal function");

test(function () {
  assert_false('initPopStateEvent' in PopStateEvent.prototype,
               'There should be no PopStateEvent#initPopStateEvent');
}, 'initPopStateEvent');

test(function () {
  var popStateEvent = new PopStateEvent("popstate");
  assert_equals(popStateEvent.state, null, "the PopStateEvent.state");
}, "Initial value of PopStateEvent.state must be null");

test(function () {
  var popStateEvent = new PopStateEvent("popstate");
  assert_false(popStateEvent.hasUAVisualTransition, "the PopStateEvent.hasUAVisualTransition");
}, "Initial value of PopStateEvent.hasUAVisualTransition must be false");

test(function () {
  var state = history.state;
  var data;
  var hasUAVisualTransition = false;
  window.addEventListener('popstate', function (e) {
    data = e.state;
    hasUAVisualTransition = e.hasUAVisualTransition;
  });
  window.dispatchEvent(new PopStateEvent('popstate', {
    'state': {testdata:true},
    'hasUAVisualTransition': true
  }));
  assert_true(data.testdata,'state data was corrupted');
  assert_equals(history.state, state, "history.state was NOT set by dispatching the event");
  assert_true(hasUAVisualTransition, 'hasUAVisualTransition not set correctly');
}, 'Dispatching a synthetic PopStateEvent');
</script>