|
1 import Qt 4.7 |
|
2 |
|
3 QtObject { |
|
4 property string url |
|
5 property string expectedStatus |
|
6 |
|
7 property bool unsentException: false; |
|
8 property bool openedException: false; |
|
9 property bool sentException: false; |
|
10 |
|
11 property bool headersReceived: false |
|
12 property bool loading: false |
|
13 property bool done: false |
|
14 |
|
15 property bool resetException: false |
|
16 |
|
17 property bool dataOK: false |
|
18 |
|
19 Component.onCompleted: { |
|
20 var x = new XMLHttpRequest; |
|
21 |
|
22 try { |
|
23 var a = x.statusText; |
|
24 } catch (e) { |
|
25 if (e.code == DOMException.INVALID_STATE_ERR) |
|
26 unsentException = true; |
|
27 } |
|
28 |
|
29 x.open("GET", url); |
|
30 x.setRequestHeader("Accept-Language", "en-US"); |
|
31 |
|
32 try { |
|
33 var a = x.statusText; |
|
34 } catch (e) { |
|
35 if (e.code == DOMException.INVALID_STATE_ERR) |
|
36 openedException = true; |
|
37 } |
|
38 |
|
39 // Test to the end |
|
40 x.onreadystatechange = function() { |
|
41 if (x.readyState == XMLHttpRequest.HEADERS_RECEIVED) { |
|
42 if (x.statusText == expectedStatus) |
|
43 headersReceived = true; |
|
44 } else if (x.readyState == XMLHttpRequest.LOADING) { |
|
45 if (x.statusText == expectedStatus) |
|
46 loading = true; |
|
47 } else if (x.readyState == XMLHttpRequest.DONE) { |
|
48 if (x.statusText == expectedStatus) |
|
49 done = true; |
|
50 |
|
51 if (expectedStatus != "OK") { |
|
52 dataOK = (x.responseText == ""); |
|
53 } else { |
|
54 dataOK = (x.responseText == "QML Rocks!\n"); |
|
55 } |
|
56 |
|
57 x.open("GET", url); |
|
58 x.setRequestHeader("Accept-Language", "en-US"); |
|
59 |
|
60 try { |
|
61 var a = x.statusText; |
|
62 } catch (e) { |
|
63 if (e.code == DOMException.INVALID_STATE_ERR) |
|
64 resetException = true; |
|
65 } |
|
66 |
|
67 } |
|
68 } |
|
69 |
|
70 x.send() |
|
71 |
|
72 try { |
|
73 var a = x.statusText; |
|
74 } catch (e) { |
|
75 if (e.code == DOMException.INVALID_STATE_ERR) |
|
76 sentException = true; |
|
77 } |
|
78 } |
|
79 } |