File: send-network-error-async-events.sub.htm

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (47 lines) | stat: -rw-r--r-- 2,423 bytes parent folder | download | duplicates (29)
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>
<html>
<head>
    <link rel="help" href="https://xhr.spec.whatwg.org/#handler-xhr-onerror" data-tested-assertations="../.." />
    <link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="following::ol[1]/li[9]/ol/li[2] following::ol[1]/li[9]/ol/li[3]" />
    <link rel="help" href="https://xhr.spec.whatwg.org/#infrastructure-for-the-send()-method" data-tested-assertations="following::dt[4] following::dd[4]/p" />
    <link rel="help" href="https://xhr.spec.whatwg.org/#network-error" data-tested-assertations=".." />
    <link rel="help" href="https://xhr.spec.whatwg.org/#request-error" data-tested-assertations="following::ol[1]/li[4] following::ol[1]/li[6] following::ol[1]/li[7] following::ol[1]/li[7]/ol/li[3] following::ol[1]/li[7]/ol/li[4] following::ol[1]/li[9] following::ol[1]/li[10]" />
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <title>XMLHttpRequest: The send() method: Fire a progress event named error when Network error happens (synchronous flag is unset)</title>
</head>

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

    <script type="text/javascript">
        var test = async_test();

        test.step(function(){
            var xhr = new XMLHttpRequest();
            var expect =  ["loadstart", "upload.loadstart", 4, "upload.error", "upload.loadend", "error", "loadend"];
            var actual = [];

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

            xhr.onloadstart        = test.step_func(e => { actual.push(e.type); })
            xhr.onloadend          = test.step_func_done(e => {
                actual.push(e.type);
                assert_array_equals(actual, expect);
            })
            xhr.onerror            = test.step_func(e => { actual.push(e.type); })

            xhr.upload.onloadstart = test.step_func(e => { actual.push("upload." + e.type); })
            xhr.upload.onloadend   = test.step_func(e => { actual.push("upload." + e.type); })
            xhr.upload.onerror     = test.step_func(e => { actual.push("upload." + e.type); })

            xhr.open("POST", "http://nonexistent.{{host}}:{{ports[http][0]}}", true);
            xhr.send("Test Message");
        });
    </script>
</body>
</html>