4bb5b1d657d3afe9eedc6e39b13458413b82dc58
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qdeclarativexmlhttprequest / data / open.qml
1 import QtQuick 1.0
2
3 QtObject {
4     property string url
5
6     property bool readyState: false
7     property bool openedState: false
8
9     property bool status: false
10     property bool statusText: false
11     property bool responseText: false
12     property bool responseXML: false
13
14     property bool dataOK: false
15
16     Component.onCompleted: {
17         var x = new XMLHttpRequest;
18
19         if (x.readyState == XMLHttpRequest.UNSENT)
20             readyState = true;
21
22         x.open("GET", url);
23         x.setRequestHeader("Accept-Language","en-US");
24
25         if (x.readyState  == XMLHttpRequest.OPENED)
26             openedState = true;
27
28         try {
29             var a = x.status;
30         } catch (error) {
31             if (error.code == DOMException.INVALID_STATE_ERR)
32                 status = true;
33         }
34         try {
35             var a = x.statusText;
36         } catch (error) {
37             if (error.code == DOMException.INVALID_STATE_ERR)
38                 statusText = true;
39         }
40         responseText = (x.responseText == "");
41         responseXML = (x.responseXML == null);
42
43         // Test to the end
44         x.onreadystatechange = function() {
45             if (x.readyState == XMLHttpRequest.DONE) {
46                 dataOK = (x.responseText == "QML Rocks!\n");
47             }
48         }
49
50
51         x.send()
52     }
53 }
54