summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/xhr/send-timeout-events.htm
blob: eae25681077edeffe8671ef56f4c61ca8ed0b18b (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
<!DOCTYPE html>
<html>
<head>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <title>XMLHttpRequest: The send() method: timeout is not 0 </title>
</head>

<body>
    <div id="log"></div>

    <script type="text/javascript">
        async_test(t => {
            const xhr = new XMLHttpRequest(),
                  expect = [4, "", "upload.timeout", "upload.loadend", "timeout", "loadend"];
            let actual = [];

            xhr.onreadystatechange = t.step_func(() => {
                if (xhr.readyState == 4) {
                    actual.push(xhr.readyState, xhr.response);
                }
            });

            xhr.onloadend = t.step_func_done(e => {
                assert_equals(e.loaded, 0);
                assert_equals(e.total, 0);
                actual.push(e.type);
                assert_array_equals(actual, expect);
            });

            xhr.ontimeout = t.step_func(e => {
                assert_equals(e.loaded, 0);
                assert_equals(e.total, 0);
                actual.push(e.type);
            });


            xhr.upload.onloadend = t.step_func(e => {
                assert_equals(e.loaded, 0);
                assert_equals(e.total, 0);
                actual.push("upload." + e.type);
            });

            xhr.upload.ontimeout = t.step_func(e => {
                assert_equals(e.loaded, 0);
                assert_equals(e.total, 0);
                actual.push("upload." + e.type);
            });


            let content = "";
            for (var i = 0; i < 121026; i++) {
                content += "[" + i + "]";
            }

            xhr.open("POST", "./resources/trickle.py", true);
            xhr.timeout = 1;
            xhr.send(content);
        });
    </script>
</body>
</html>