summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/execorder.html
blob: 6a7513dc1361de0716584df8a5e7c8b3df2b69f3 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!doctype html>
<html>
<head>
    <title>html-script-module-execOrder</title>
    <meta name=timeout content=long>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script>

        var execCounts = [
            0, // test_parsedOrdered
            0, // test_dynamicOrdered
        ];
        function assert_execCount(set, expected, description)
        {
            if (!execCounts[set])
            {
                execCounts[set] = 0;
            }
            assert_equals(++execCounts[set], expected, description);
        }

        function create_script(src, opts)
        {
            var element = document.createElement("script");
            element.src = src;
            element.async = (opts.asyncOrdered ? false : true);
            element.type = (opts.module ? "module" : "text/javascript");
            document.body.appendChild(element);
        }

    </script>
</head>
<body>
    <h1>html-script-module-execOrder</h1>
    <script>

        /////
        // Start test_parsedUnordered*
        /////
        var test_parsedUnordered1 = async_test("Unordered module script execution (parsed, unordered #1)");
        var test_parsedUnordered2 = async_test("Unordered module script execution (parsed, unordered #2)");
    </script>
    <script type="module" src="execorder-parsedunordered1.js"></script>
    <script type="module" src="execorder-parsedunordered2.js"></script>
    <script>
        /////
        // End test_parsedUnordered*
        /////

        /////
        // Start test_dynamicUnordered*
        /////
        var test_dynamicUnordered1 = async_test("Unordered module script execution (dynamic, unordered #1)");
        var test_dynamicUnordered2 = async_test("Unordered module script execution (dynamic, unordered #2)");
        create_script("execorder-dynamicunordered1.js", { module: true });
        create_script("execorder-dynamicunordered2.js", { module: true });
        /////
        // End test_dynamicUnordered*
        /////

        /////
        // Begin test_parsedOrdered
        /////
        var test_parsedOrdered = async_test("Interlaced module/non-module script execution (parsed, async-ordered)");
        window.addEventListener("load", test_parsedOrdered.step_func(function() {
            assert_execCount(0, 5, "onload should have fired fifth");
            test_parsedOrdered.done();
        }));
    </script>
    <script src="execorder-parsedordered2.js" defer></script>
    <script type="module">
        test_parsedOrdered.step(function() {
            assert_execCount(0, 3, "Inline module-typed script element should have fired third");
        });
    </script>
    <script src="execorder-parsedordered4.js" defer></script>
    <script>
        test_parsedOrdered.step(function() {
            assert_execCount(0, 1, "Inline untyped script element should have fired first");
        });
        /////
        // End test_parsedOrdered
        /////

        /////
        // Start test_dynamicOrdered
        /////
        var test_dynamicOrdered = async_test("Interlaced module/non-module script execution (dynamic, async-ordered)");
        window.addEventListener("load", test_dynamicOrdered.step_func(function() {
            assert_execCount(1, 5, "onload should have fired fifth (last)");
            test_dynamicOrdered.done();
        }));
        create_script("execorder-dynamicordered2.js", { asyncOrdered: true, module: false });
        create_script("execorder-dynamicordered3.js", { asyncOrdered: true, module: true });
        create_script("execorder-dynamicordered4.js", { asyncOrdered: true, module: false });
        test_dynamicOrdered.step(function() {
            assert_execCount(1, 1, "Inline untyped script element should have fired first");
        });
        /////
        // End test_dynamicOrdered
        /////

    </script>
</body>
</html>