summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/navigation-timing/test-timing-attributes-dependent-on-document-load.html
blob: 9eac7bd0333ddb95a6a3cd4de3f020d54a286997 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Navigation Timing 2 WPT</title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script>
        setup({ single_test: true });
        var reload_frame;

        // Array of navigation timing entries dependent on Document Load Timing.
        var navTimingAttributes = [
          'fetchStart',
          'loadEventEnd',
          'loadEventStart',
          'redirectCount',
          'redirectEnd',
          'redirectStart',
          'responseEnd',
          'unloadEventEnd',
          'unloadEventStart',
        ];

        // Function to run the test when the page loads.
        function onload_test() {
            reload_frame = document.getElementById("frameContext");
            reload_frame.onload = function() {
                step_timeout(do_test, 0);
            }
            step_timeout(reload_the_frame, 0);
        }

        /*
          Function to reload the iframe and observe values for navigation timing entries:
          redirectStart, redirectEnd and redirectCount dependent on Document Load Timing.
        */
        function reload_the_frame() {
            reload_frame.contentWindow.location.href =
            "/common/redirect.py?location=/navigation-timing/resources/blank-page-green.html";
        }

        /*
          Function to obtain navigation timing entries and,
          check if the values are greater than 0.
        */
        function do_test() {
            var nav_frame = document.getElementById("frameContext").contentWindow;
            var pnt1 = nav_frame.performance.getEntriesByType("navigation")[0];
            for (i in navTimingAttributes) {
                assert_greater_than(pnt1[navTimingAttributes[i]], 0,
                `Expected navigation timing entries: ${navTimingAttributes[i]} greater than 0`);
            }
            step_timeout(remove, 0);
            done(); // Avoids scripting errors
        }

        /*
         Function to remove the iframe from the parent body and,
         check if the navigation timing entries of detached iframe are 0.
         */
        function remove() {
            var nav_frame = document.getElementById("frameContext").contentWindow;
            var pnt1 = nav_frame.performance.getEntriesByType("navigation")[0];
            document.body.removeChild(document.getElementById("frameContext"));
            for (i in navTimingAttributes) {
                assert_equals(pnt1[navTimingAttributes[i]], 0,
                `${navTimingAttributes[i]} dependent on Document Load Timing: returns 0`);
            }
        }
    </script>
</head>
<body onload="onload_test();">
    <h1>Description</h1>
    <p>This test observes values of navigation timing entries,</p>
    <p>dependent on Document Load Timing for a detached iframe.</p>
    <br />
    <p>This page should be loaded with a green background frame below,</p>
    <p>which disappears after the iframe is detached.</p>
    <br />
    <iframe id="frameContext"
            src="/navigation-timing/resources/blank-page-green.html"
            style="width: 250px; height: 250px;"></iframe>
</body>
</html>