summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativexmlhttprequest/data/responseText.qml
blob: 22a9b96d107901b1fa085d6e3c18ba52ff61ba46 (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
import Qt 4.7

QtObject {
    property string url
    property string expectedText

    property bool unsent: false
    property bool opened: false
    property bool sent: false
    property bool headersReceived: false

    property bool loading: false
    property bool done: false

    property bool reset: false

    property bool dataOK: false

    Component.onCompleted: {
        var x = new XMLHttpRequest;

        unsent = (x.responseText == "");

        x.open("GET", url);
        x.setRequestHeader("Accept-Language", "en-US");

        opened = (x.responseText == "");

        // Test to the end
        x.onreadystatechange = function() {
            if (x.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
                headersReceived = (x.responseText == "");
            } else if (x.readyState == XMLHttpRequest.LOADING) {
                if (x.responseText == expectedText)
                    loading = true;
            } else if (x.readyState == XMLHttpRequest.DONE) {
                if (x.responseText == expectedText)
                    done = true;

                dataOK = (x.responseText == expectedText);

                x.open("GET", url);
                x.setRequestHeader("Accept-Language", "en-US");

                reset = (x.responseText == "");
            }
        }

        x.send()

        sent = (x.responseText == "");
    }
}