summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/navigation-timing/navigation-type-post-backforward.html
blob: 1fbdf1ae9bf870a6456127a5c876ae86f43dea76 (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
<!DOCTYPE html>
<html>

<head>
  <title>Navigation Type Post Back Forward</title>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
</head>

<body>
  <script>
    function execute_helper(fn, args) {
      return new Promise(resolve => {
        frame.addEventListener('load', () => {
          resolve(frame);
        }, { once: true });
        fn.apply(null, args);
      });
    }

    // Create an iframe.
    function create_iframe(url) {
      const frame = document.createElement('iframe');
      frame.src = url;
      return frame;
    }

    // Attach an iframe.
    function attach_iframe(frame) {
      document.body.appendChild(frame);
    }

    // Post by submit method.
    function submit_form(frame) {
      frame.contentWindow.document.getElementsByTagName("form")[0].submit();
    }

    // Navigate away by simulating a click on the link.
    function navigate_away(frame) {
      frame.contentWindow.document.getElementsByTagName("a")[0].click();
    }

    // Navigate back.
    function navigate_back(frame) {
      frame.contentWindow.history.back();
    }

    promise_test(async t => {
      // Add an iframe and Load page in the iframe.
      let url = 'resources/navigation-type-post-back.html';

      frame = create_iframe(url);
      await execute_helper(attach_iframe, [frame]);
      await execute_helper(submit_form, [frame]);
      await execute_helper(navigate_away, [frame]);
      await execute_helper(navigate_back, [frame]);

      assert_equals(frame.contentWindow.performance.getEntriesByType('navigation')[0].type,
        'back_forward');
    }, "Navigation type after posting and navigating away and back should be back_forward.");
  </script>
</body>

</html>