summaryrefslogtreecommitdiff
path: root/misc/openlayers/tests/Request/XMLHttpRequest.html
blob: fa628077cb4eb8fb5bde2e470c0bc2a2c4458ae8 (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
<html>
<head>
    <script src="../OLLoader.js"></script>
    <script type="text/javascript">
        function test_constructor(t) {
            t.plan(1);
            t.ok(new OpenLayers.Request.XMLHttpRequest(),
                 "constructor didn't fail and we trust the code is well tested in OpenLayers.Request methods");
        }
        function test_readyState(t) {
        // Verify compliance of the standard (a part) See: http://www.w3.org/TR/XMLHttpRequest/
        t.plan(9);
        // Case 1: Request-A: open & abort
            var requestA = new OpenLayers.Request.XMLHttpRequest();
            //requestA.onreadystatechange = function() {};
            t.eq(requestA.readyState, 0, "Request-A: readyState after new is 0-UNSENT");
            requestA.open("GET", ".", true);
            t.eq(requestA.readyState, 1, "Request-A: readyState after open is 1-OPENED");
            requestA.abort();
            t.eq(requestA.readyState, 0, "Request-A: readyState after abort is 0-UNSENT");

        // Case 2: Request-B: open & send
            var requestB = new OpenLayers.Request.XMLHttpRequest();
            requestB.onreadystatechange = function() {
                if (requestB.readyState == 4) {
                    t.ok(true, "Request-B: triggered the event onreadystatechange when 4-DONE");
                }
            };
            t.eq(requestB.readyState, 0, "Request-B: readyState after new is 0-UNSENT");
            requestB.open("GET", ".", true);
            t.eq(requestB.readyState, 1, "Request-B: readyState after open is 1-OPENED");
            requestB.send();

        // Case 3: Request-C: open, send & abort
            var requestC = new OpenLayers.Request.XMLHttpRequest();
            requestC.onreadystatechange = function() {
                if (requestC.readyState == 4) {
                    t.fail("Request-C: triggered the event onreadystatechange when 4-DONE after abort");
                }
            };
            t.eq(requestC.readyState, 0, "Request-C: readyState after new is 0-UNSENT");
            requestC.open("GET", ".", true);
            t.eq(requestC.readyState, 1, "Request-C: readyState after open is 1-OPENED");
            requestC.send();
            requestC.abort();
            t.eq(requestC.readyState, 0, "Request-C: readyState after abort is 0-UNSENT");

        // delay destroy
            t.delay_call( 
                2, function() {
                    // to await the end of requestB and requestC
                }
            );
        }
    </script>
</head>
<body>
</body>
</html>