|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <qtest.h> |
|
43 #include <QDeclarativeEngine> |
|
44 #include <QDeclarativeComponent> |
|
45 #include <QDebug> |
|
46 #include <QNetworkCookieJar> |
|
47 #include "testhttpserver.h" |
|
48 |
|
49 #define SERVER_PORT 14445 |
|
50 |
|
51 class tst_qdeclarativexmlhttprequest : public QObject |
|
52 { |
|
53 Q_OBJECT |
|
54 public: |
|
55 tst_qdeclarativexmlhttprequest() {} |
|
56 |
|
57 private slots: |
|
58 void domExceptionCodes(); |
|
59 void callbackException(); |
|
60 void callbackException_data(); |
|
61 void staticStateValues(); |
|
62 void instanceStateValues(); |
|
63 void constructor(); |
|
64 void defaultState(); |
|
65 void open(); |
|
66 void open_data(); |
|
67 void open_invalid_method(); |
|
68 void open_sync(); |
|
69 void open_arg_count(); |
|
70 void setRequestHeader(); |
|
71 void setRequestHeader_unsent(); |
|
72 void setRequestHeader_illegalName_data(); |
|
73 void setRequestHeader_illegalName(); |
|
74 void setRequestHeader_sent(); |
|
75 void setRequestHeader_args(); |
|
76 void send_unsent(); |
|
77 void send_alreadySent(); |
|
78 void send_ignoreData(); |
|
79 void send_withdata(); |
|
80 void send_withdata_data(); |
|
81 void abort(); |
|
82 void abort_unsent(); |
|
83 void abort_opened(); |
|
84 void getResponseHeader(); |
|
85 void getResponseHeader_unsent(); |
|
86 void getResponseHeader_sent(); |
|
87 void getResponseHeader_args(); |
|
88 void getAllResponseHeaders(); |
|
89 void getAllResponseHeaders_unsent(); |
|
90 void getAllResponseHeaders_sent(); |
|
91 void getAllResponseHeaders_args(); |
|
92 void status(); |
|
93 void status_data(); |
|
94 void statusText(); |
|
95 void statusText_data(); |
|
96 void responseText(); |
|
97 void responseText_data(); |
|
98 void responseXML_invalid(); |
|
99 void invalidMethodUsage(); |
|
100 void redirects(); |
|
101 void nonUtf8(); |
|
102 |
|
103 // Attributes |
|
104 void document(); |
|
105 void element(); |
|
106 void attr(); |
|
107 void text(); |
|
108 void cdata(); |
|
109 |
|
110 // Crashes |
|
111 // void outstanding_request_at_shutdown(); |
|
112 |
|
113 // void network_errors() |
|
114 // void readyState() |
|
115 |
|
116 private: |
|
117 QDeclarativeEngine engine; |
|
118 }; |
|
119 |
|
120 inline QUrl TEST_FILE(const QString &filename) |
|
121 { |
|
122 return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename); |
|
123 } |
|
124 |
|
125 // Test that the dom exception codes are correct |
|
126 void tst_qdeclarativexmlhttprequest::domExceptionCodes() |
|
127 { |
|
128 QDeclarativeComponent component(&engine, TEST_FILE("domExceptionCodes.qml")); |
|
129 QObject *object = component.create(); |
|
130 QVERIFY(object != 0); |
|
131 |
|
132 QCOMPARE(object->property("index_size_err").toInt(), 1); |
|
133 QCOMPARE(object->property("domstring_size_err").toInt(), 2); |
|
134 QCOMPARE(object->property("hierarchy_request_err").toInt(), 3); |
|
135 QCOMPARE(object->property("wrong_document_err").toInt(), 4); |
|
136 QCOMPARE(object->property("invalid_character_err").toInt(), 5); |
|
137 QCOMPARE(object->property("no_data_allowed_err").toInt(), 6); |
|
138 QCOMPARE(object->property("no_modification_allowed_err").toInt(), 7); |
|
139 QCOMPARE(object->property("not_found_err").toInt(), 8); |
|
140 QCOMPARE(object->property("not_supported_err").toInt(), 9); |
|
141 QCOMPARE(object->property("inuse_attribute_err").toInt(), 10); |
|
142 QCOMPARE(object->property("invalid_state_err").toInt(), 11); |
|
143 QCOMPARE(object->property("syntax_err").toInt(), 12); |
|
144 QCOMPARE(object->property("invalid_modification_err").toInt(), 13); |
|
145 QCOMPARE(object->property("namespace_err").toInt(), 14); |
|
146 QCOMPARE(object->property("invalid_access_err").toInt(), 15); |
|
147 QCOMPARE(object->property("validation_err").toInt(), 16); |
|
148 QCOMPARE(object->property("type_mismatch_err").toInt(), 17); |
|
149 |
|
150 delete object; |
|
151 } |
|
152 |
|
153 #define TRY_WAIT(expr) \ |
|
154 do { \ |
|
155 for (int ii = 0; ii < 6; ++ii) { \ |
|
156 if ((expr)) break; \ |
|
157 QTest::qWait(50); \ |
|
158 } \ |
|
159 QVERIFY((expr)); \ |
|
160 } while (false) |
|
161 |
|
162 |
|
163 void tst_qdeclarativexmlhttprequest::callbackException_data() |
|
164 { |
|
165 QTest::addColumn<QString>("which"); |
|
166 QTest::addColumn<int>("line"); |
|
167 |
|
168 QTest::newRow("on-opened") << "1" << 15; |
|
169 QTest::newRow("on-loading") << "3" << 15; |
|
170 QTest::newRow("on-done") << "4" << 15; |
|
171 } |
|
172 |
|
173 void tst_qdeclarativexmlhttprequest::callbackException() |
|
174 { |
|
175 // Test exception reporting for exceptions thrown at various points. |
|
176 |
|
177 QFETCH(QString, which); |
|
178 QFETCH(int, line); |
|
179 |
|
180 QString expect = TEST_FILE("callbackException.qml").toString() + ":"+QString::number(line)+": Error: Exception from Callback"; |
|
181 QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); |
|
182 |
|
183 QDeclarativeComponent component(&engine, TEST_FILE("callbackException.qml")); |
|
184 QObject *object = component.beginCreate(engine.rootContext()); |
|
185 QVERIFY(object != 0); |
|
186 object->setProperty("url", "testdocument.html"); |
|
187 object->setProperty("which", which); |
|
188 component.completeCreate(); |
|
189 |
|
190 TRY_WAIT(object->property("threw").toBool() == true); |
|
191 |
|
192 delete object; |
|
193 } |
|
194 |
|
195 // Test that the state value properties on the XMLHttpRequest constructor have the correct values. |
|
196 // ### WebKit does not do this, but it seems to fit the standard and QML better |
|
197 void tst_qdeclarativexmlhttprequest::staticStateValues() |
|
198 { |
|
199 QDeclarativeComponent component(&engine, TEST_FILE("staticStateValues.qml")); |
|
200 QObject *object = component.create(); |
|
201 QVERIFY(object != 0); |
|
202 |
|
203 QCOMPARE(object->property("unsent").toInt(), 0); |
|
204 QCOMPARE(object->property("opened").toInt(), 1); |
|
205 QCOMPARE(object->property("headers_received").toInt(), 2); |
|
206 QCOMPARE(object->property("loading").toInt(), 3); |
|
207 QCOMPARE(object->property("done").toInt(), 4); |
|
208 |
|
209 delete object; |
|
210 } |
|
211 |
|
212 // Test that the state value properties on instances have the correct values. |
|
213 void tst_qdeclarativexmlhttprequest::instanceStateValues() |
|
214 { |
|
215 QDeclarativeComponent component(&engine, TEST_FILE("instanceStateValues.qml")); |
|
216 QObject *object = component.create(); |
|
217 QVERIFY(object != 0); |
|
218 |
|
219 QCOMPARE(object->property("unsent").toInt(), 0); |
|
220 QCOMPARE(object->property("opened").toInt(), 1); |
|
221 QCOMPARE(object->property("headers_received").toInt(), 2); |
|
222 QCOMPARE(object->property("loading").toInt(), 3); |
|
223 QCOMPARE(object->property("done").toInt(), 4); |
|
224 |
|
225 delete object; |
|
226 } |
|
227 |
|
228 // Test calling constructor |
|
229 void tst_qdeclarativexmlhttprequest::constructor() |
|
230 { |
|
231 QDeclarativeComponent component(&engine, TEST_FILE("constructor.qml")); |
|
232 QObject *object = component.create(); |
|
233 QVERIFY(object != 0); |
|
234 |
|
235 QCOMPARE(object->property("calledAsConstructor").toBool(), true); |
|
236 QCOMPARE(object->property("calledAsFunction").toBool(), true); |
|
237 |
|
238 delete object; |
|
239 } |
|
240 |
|
241 // Test that all the properties are set correctly before any request is sent |
|
242 void tst_qdeclarativexmlhttprequest::defaultState() |
|
243 { |
|
244 QDeclarativeComponent component(&engine, TEST_FILE("defaultState.qml")); |
|
245 QObject *object = component.create(); |
|
246 QVERIFY(object != 0); |
|
247 |
|
248 QCOMPARE(object->property("readState").toInt(), 0); |
|
249 QCOMPARE(object->property("statusIsException").toBool(), true); |
|
250 QCOMPARE(object->property("statusTextIsException").toBool(), true); |
|
251 QCOMPARE(object->property("responseText").toString(), QString()); |
|
252 QCOMPARE(object->property("responseXMLIsNull").toBool(), true); |
|
253 |
|
254 delete object; |
|
255 } |
|
256 |
|
257 // Test valid XMLHttpRequest.open() calls |
|
258 void tst_qdeclarativexmlhttprequest::open() |
|
259 { |
|
260 QFETCH(QUrl, qmlFile); |
|
261 QFETCH(QString, url); |
|
262 QFETCH(bool, remote); |
|
263 |
|
264 TestHTTPServer *server = 0; |
|
265 if (remote) { |
|
266 server = new TestHTTPServer(SERVER_PORT); |
|
267 QVERIFY(server->isValid()); |
|
268 QVERIFY(server->wait(TEST_FILE("open_network.expect"), |
|
269 TEST_FILE("open_network.reply"), |
|
270 TEST_FILE("testdocument.html"))); |
|
271 } |
|
272 |
|
273 QDeclarativeComponent component(&engine, qmlFile); |
|
274 QObject *object = component.beginCreate(engine.rootContext()); |
|
275 QVERIFY(object != 0); |
|
276 object->setProperty("url", url); |
|
277 component.completeCreate(); |
|
278 |
|
279 QCOMPARE(object->property("readyState").toBool(), true); |
|
280 QCOMPARE(object->property("openedState").toBool(), true); |
|
281 QCOMPARE(object->property("status").toBool(), true); |
|
282 QCOMPARE(object->property("statusText").toBool(), true); |
|
283 QCOMPARE(object->property("responseText").toBool(), true); |
|
284 QCOMPARE(object->property("responseXML").toBool(), true); |
|
285 |
|
286 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
287 |
|
288 delete server; |
|
289 delete object; |
|
290 } |
|
291 |
|
292 void tst_qdeclarativexmlhttprequest::open_data() |
|
293 { |
|
294 QTest::addColumn<QUrl>("qmlFile"); |
|
295 QTest::addColumn<QString>("url"); |
|
296 QTest::addColumn<bool>("remote"); |
|
297 |
|
298 QTest::newRow("Relative url)") << TEST_FILE("open.qml") << "testdocument.html" << false; |
|
299 QTest::newRow("Absolute url)") << TEST_FILE("open.qml") << TEST_FILE("testdocument.html").toString() << false; |
|
300 QTest::newRow("Absolute network url)") << TEST_FILE("open.qml") << "http://127.0.0.1:14445/testdocument.html" << true; |
|
301 |
|
302 // ### Check that the username/password were sent to the server |
|
303 QTest::newRow("User/pass") << TEST_FILE("open_user.qml") << "http://127.0.0.1:14445/testdocument.html" << true; |
|
304 } |
|
305 |
|
306 // Test that calling XMLHttpRequest.open() with an invalid method raises an exception |
|
307 void tst_qdeclarativexmlhttprequest::open_invalid_method() |
|
308 { |
|
309 QDeclarativeComponent component(&engine, TEST_FILE("open_invalid_method.qml")); |
|
310 QObject *object = component.create(); |
|
311 QVERIFY(object != 0); |
|
312 |
|
313 QCOMPARE(object->property("exceptionThrown").toBool(), true); |
|
314 |
|
315 delete object; |
|
316 } |
|
317 |
|
318 // Test that calling XMLHttpRequest.open() with sync raises an exception |
|
319 void tst_qdeclarativexmlhttprequest::open_sync() |
|
320 { |
|
321 QDeclarativeComponent component(&engine, TEST_FILE("open_sync.qml")); |
|
322 QObject *object = component.create(); |
|
323 QVERIFY(object != 0); |
|
324 |
|
325 QCOMPARE(object->property("exceptionThrown").toBool(), true); |
|
326 |
|
327 delete object; |
|
328 } |
|
329 |
|
330 // Calling with incorrect arg count raises an exception |
|
331 void tst_qdeclarativexmlhttprequest::open_arg_count() |
|
332 { |
|
333 { |
|
334 QDeclarativeComponent component(&engine, TEST_FILE("open_arg_count.1.qml")); |
|
335 QObject *object = component.create(); |
|
336 QVERIFY(object != 0); |
|
337 |
|
338 QCOMPARE(object->property("exceptionThrown").toBool(), true); |
|
339 |
|
340 delete object; |
|
341 } |
|
342 |
|
343 { |
|
344 QDeclarativeComponent component(&engine, TEST_FILE("open_arg_count.2.qml")); |
|
345 QObject *object = component.create(); |
|
346 QVERIFY(object != 0); |
|
347 |
|
348 QCOMPARE(object->property("exceptionThrown").toBool(), true); |
|
349 |
|
350 delete object; |
|
351 } |
|
352 } |
|
353 |
|
354 // Test valid setRequestHeader() calls |
|
355 void tst_qdeclarativexmlhttprequest::setRequestHeader() |
|
356 { |
|
357 TestHTTPServer server(SERVER_PORT); |
|
358 QVERIFY(server.isValid()); |
|
359 QVERIFY(server.wait(TEST_FILE("setRequestHeader.expect"), |
|
360 TEST_FILE("setRequestHeader.reply"), |
|
361 TEST_FILE("testdocument.html"))); |
|
362 |
|
363 QDeclarativeComponent component(&engine, TEST_FILE("setRequestHeader.qml")); |
|
364 QObject *object = component.beginCreate(engine.rootContext()); |
|
365 QVERIFY(object != 0); |
|
366 object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); |
|
367 component.completeCreate(); |
|
368 |
|
369 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
370 |
|
371 delete object; |
|
372 } |
|
373 |
|
374 // Test setting headers before open() throws exception |
|
375 void tst_qdeclarativexmlhttprequest::setRequestHeader_unsent() |
|
376 { |
|
377 QDeclarativeComponent component(&engine, TEST_FILE("setRequestHeader_unsent.qml")); |
|
378 QObject *object = component.create(); |
|
379 QVERIFY(object != 0); |
|
380 |
|
381 QCOMPARE(object->property("test").toBool(), true); |
|
382 |
|
383 delete object; |
|
384 } |
|
385 |
|
386 void tst_qdeclarativexmlhttprequest::setRequestHeader_illegalName_data() |
|
387 { |
|
388 QTest::addColumn<QString>("name"); |
|
389 |
|
390 QTest::newRow("Accept-Charset") << "AccePT-CHArset"; |
|
391 QTest::newRow("Accept-Encoding") << "AccEpt-EnCOding"; |
|
392 QTest::newRow("Connection") << "ConnECtion"; |
|
393 QTest::newRow("Content-Length") << "ContEnt-LenGth"; |
|
394 QTest::newRow("Cookie") << "CookIe"; |
|
395 QTest::newRow("Cookie2") << "CoOkie2"; |
|
396 QTest::newRow("Content-Transfer-Encoding") << "ConteNT-tRANSFER-eNCOding"; |
|
397 QTest::newRow("Date") << "DaTE"; |
|
398 QTest::newRow("Expect") << "ExPect"; |
|
399 QTest::newRow("Host") << "HoST"; |
|
400 QTest::newRow("Keep-Alive") << "KEEP-aLive"; |
|
401 QTest::newRow("Referer") << "ReferEr"; |
|
402 QTest::newRow("TE") << "Te"; |
|
403 QTest::newRow("Trailer") << "TraILEr"; |
|
404 QTest::newRow("Transfer-Encoding") << "tRANsfer-Encoding"; |
|
405 QTest::newRow("Upgrade") << "UpgrADe"; |
|
406 QTest::newRow("User-Agent") << "uSEr-Agent"; |
|
407 QTest::newRow("Via") << "vIa"; |
|
408 QTest::newRow("Proxy-") << "ProXy-"; |
|
409 QTest::newRow("Sec-") << "SeC-"; |
|
410 QTest::newRow("Proxy-*") << "Proxy-BLAH"; |
|
411 QTest::newRow("Sec-*") << "Sec-F"; |
|
412 } |
|
413 |
|
414 // Tests that using illegal header names has no effect |
|
415 void tst_qdeclarativexmlhttprequest::setRequestHeader_illegalName() |
|
416 { |
|
417 QFETCH(QString, name); |
|
418 |
|
419 TestHTTPServer server(SERVER_PORT); |
|
420 QVERIFY(server.isValid()); |
|
421 QVERIFY(server.wait(TEST_FILE("open_network.expect"), |
|
422 TEST_FILE("open_network.reply"), |
|
423 TEST_FILE("testdocument.html"))); |
|
424 |
|
425 QDeclarativeComponent component(&engine, TEST_FILE("setRequestHeader_illegalName.qml")); |
|
426 QObject *object = component.beginCreate(engine.rootContext()); |
|
427 QVERIFY(object != 0); |
|
428 object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); |
|
429 object->setProperty("header", name); |
|
430 component.completeCreate(); |
|
431 |
|
432 QCOMPARE(object->property("readyState").toBool(), true); |
|
433 QCOMPARE(object->property("openedState").toBool(), true); |
|
434 QCOMPARE(object->property("status").toBool(), true); |
|
435 QCOMPARE(object->property("statusText").toBool(), true); |
|
436 QCOMPARE(object->property("responseText").toBool(), true); |
|
437 QCOMPARE(object->property("responseXML").toBool(), true); |
|
438 |
|
439 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
440 |
|
441 delete object; |
|
442 } |
|
443 |
|
444 // Test that attempting to set a header after a request is sent throws an exception |
|
445 void tst_qdeclarativexmlhttprequest::setRequestHeader_sent() |
|
446 { |
|
447 TestHTTPServer server(SERVER_PORT); |
|
448 QVERIFY(server.isValid()); |
|
449 QVERIFY(server.wait(TEST_FILE("open_network.expect"), |
|
450 TEST_FILE("open_network.reply"), |
|
451 TEST_FILE("testdocument.html"))); |
|
452 |
|
453 QDeclarativeComponent component(&engine, TEST_FILE("setRequestHeader_sent.qml")); |
|
454 QObject *object = component.beginCreate(engine.rootContext()); |
|
455 QVERIFY(object != 0); |
|
456 object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); |
|
457 component.completeCreate(); |
|
458 |
|
459 QCOMPARE(object->property("test").toBool(), true); |
|
460 |
|
461 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
462 |
|
463 delete object; |
|
464 } |
|
465 |
|
466 // Invalid arg count throws exception |
|
467 void tst_qdeclarativexmlhttprequest::setRequestHeader_args() |
|
468 { |
|
469 QDeclarativeComponent component(&engine, TEST_FILE("setRequestHeader_args.qml")); |
|
470 QObject *object = component.create(); |
|
471 QVERIFY(object != 0); |
|
472 |
|
473 QCOMPARE(object->property("exceptionThrown").toBool(), true); |
|
474 |
|
475 delete object; |
|
476 } |
|
477 |
|
478 // Test that calling send() in UNSENT state throws an exception |
|
479 void tst_qdeclarativexmlhttprequest::send_unsent() |
|
480 { |
|
481 QDeclarativeComponent component(&engine, TEST_FILE("send_unsent.qml")); |
|
482 QObject *object = component.create(); |
|
483 QVERIFY(object != 0); |
|
484 |
|
485 QCOMPARE(object->property("test").toBool(), true); |
|
486 |
|
487 delete object; |
|
488 } |
|
489 |
|
490 // Test attempting to resend a sent request throws an exception |
|
491 void tst_qdeclarativexmlhttprequest::send_alreadySent() |
|
492 { |
|
493 QDeclarativeComponent component(&engine, TEST_FILE("send_alreadySent.qml")); |
|
494 QObject *object = component.create(); |
|
495 QVERIFY(object != 0); |
|
496 |
|
497 QCOMPARE(object->property("test").toBool(), true); |
|
498 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
499 |
|
500 delete object; |
|
501 } |
|
502 |
|
503 // Test that send for a GET or HEAD ignores data |
|
504 void tst_qdeclarativexmlhttprequest::send_ignoreData() |
|
505 { |
|
506 { |
|
507 TestHTTPServer server(SERVER_PORT); |
|
508 QVERIFY(server.isValid()); |
|
509 QVERIFY(server.wait(TEST_FILE("send_ignoreData_GET.expect"), |
|
510 TEST_FILE("send_ignoreData.reply"), |
|
511 TEST_FILE("testdocument.html"))); |
|
512 |
|
513 QDeclarativeComponent component(&engine, TEST_FILE("send_ignoreData.qml")); |
|
514 QObject *object = component.beginCreate(engine.rootContext()); |
|
515 QVERIFY(object != 0); |
|
516 object->setProperty("reqType", "GET"); |
|
517 object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); |
|
518 component.completeCreate(); |
|
519 |
|
520 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
521 |
|
522 delete object; |
|
523 } |
|
524 |
|
525 { |
|
526 TestHTTPServer server(SERVER_PORT); |
|
527 QVERIFY(server.isValid()); |
|
528 QVERIFY(server.wait(TEST_FILE("send_ignoreData_PUT.expect"), |
|
529 TEST_FILE("send_ignoreData.reply"), |
|
530 TEST_FILE("testdocument.html"))); |
|
531 |
|
532 QDeclarativeComponent component(&engine, TEST_FILE("send_ignoreData.qml")); |
|
533 QObject *object = component.beginCreate(engine.rootContext()); |
|
534 QVERIFY(object != 0); |
|
535 object->setProperty("reqType", "HEAD"); |
|
536 object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); |
|
537 component.completeCreate(); |
|
538 |
|
539 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
540 |
|
541 delete object; |
|
542 } |
|
543 } |
|
544 |
|
545 // Test that send()'ing data works |
|
546 void tst_qdeclarativexmlhttprequest::send_withdata() |
|
547 { |
|
548 QFETCH(QString, file_expected); |
|
549 QFETCH(QString, file_qml); |
|
550 |
|
551 TestHTTPServer server(SERVER_PORT); |
|
552 QVERIFY(server.isValid()); |
|
553 QVERIFY(server.wait(TEST_FILE(file_expected), |
|
554 TEST_FILE("send_data.reply"), |
|
555 TEST_FILE("testdocument.html"))); |
|
556 |
|
557 QDeclarativeComponent component(&engine, TEST_FILE(file_qml)); |
|
558 QObject *object = component.beginCreate(engine.rootContext()); |
|
559 QVERIFY(object != 0); |
|
560 object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); |
|
561 component.completeCreate(); |
|
562 |
|
563 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
564 |
|
565 delete object; |
|
566 } |
|
567 |
|
568 void tst_qdeclarativexmlhttprequest::send_withdata_data() |
|
569 { |
|
570 QTest::addColumn<QString>("file_expected"); |
|
571 QTest::addColumn<QString>("file_qml"); |
|
572 |
|
573 QTest::newRow("No content-type") << "send_data.1.expect" << "send_data.1.qml"; |
|
574 QTest::newRow("Correct content-type") << "send_data.1.expect" << "send_data.2.qml"; |
|
575 QTest::newRow("Incorrect content-type") << "send_data.1.expect" << "send_data.3.qml"; |
|
576 QTest::newRow("Correct content-type - out of order") << "send_data.4.expect" << "send_data.4.qml"; |
|
577 QTest::newRow("Incorrect content-type - out of order") << "send_data.4.expect" << "send_data.5.qml"; |
|
578 QTest::newRow("PUT") << "send_data.6.expect" << "send_data.6.qml"; |
|
579 QTest::newRow("Correct content-type - no charset") << "send_data.1.expect" << "send_data.7.qml"; |
|
580 } |
|
581 |
|
582 // Test abort() has no effect in unsent state |
|
583 void tst_qdeclarativexmlhttprequest::abort_unsent() |
|
584 { |
|
585 QDeclarativeComponent component(&engine, TEST_FILE("abort_unsent.qml")); |
|
586 QObject *object = component.beginCreate(engine.rootContext()); |
|
587 QVERIFY(object != 0); |
|
588 object->setProperty("url", "testdocument.html"); |
|
589 component.completeCreate(); |
|
590 |
|
591 QCOMPARE(object->property("readyState").toBool(), true); |
|
592 QCOMPARE(object->property("openedState").toBool(), true); |
|
593 QCOMPARE(object->property("status").toBool(), true); |
|
594 QCOMPARE(object->property("statusText").toBool(), true); |
|
595 QCOMPARE(object->property("responseText").toBool(), true); |
|
596 QCOMPARE(object->property("responseXML").toBool(), true); |
|
597 |
|
598 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
599 |
|
600 delete object; |
|
601 } |
|
602 |
|
603 // Test abort() cancels an open (but unsent) request |
|
604 void tst_qdeclarativexmlhttprequest::abort_opened() |
|
605 { |
|
606 QDeclarativeComponent component(&engine, TEST_FILE("abort_opened.qml")); |
|
607 QObject *object = component.beginCreate(engine.rootContext()); |
|
608 QVERIFY(object != 0); |
|
609 object->setProperty("url", "testdocument.html"); |
|
610 component.completeCreate(); |
|
611 |
|
612 QCOMPARE(object->property("readyState").toBool(), true); |
|
613 QCOMPARE(object->property("openedState").toBool(), true); |
|
614 QCOMPARE(object->property("status").toBool(), true); |
|
615 QCOMPARE(object->property("statusText").toBool(), true); |
|
616 QCOMPARE(object->property("responseText").toBool(), true); |
|
617 QCOMPARE(object->property("responseXML").toBool(), true); |
|
618 |
|
619 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
620 |
|
621 delete object; |
|
622 } |
|
623 |
|
624 // Test abort() aborts in progress send |
|
625 void tst_qdeclarativexmlhttprequest::abort() |
|
626 { |
|
627 TestHTTPServer server(SERVER_PORT); |
|
628 QVERIFY(server.isValid()); |
|
629 QVERIFY(server.wait(TEST_FILE("abort.expect"), |
|
630 TEST_FILE("abort.reply"), |
|
631 TEST_FILE("testdocument.html"))); |
|
632 |
|
633 QDeclarativeComponent component(&engine, TEST_FILE("abort.qml")); |
|
634 QObject *object = component.beginCreate(engine.rootContext()); |
|
635 QVERIFY(object != 0); |
|
636 object->setProperty("urlDummy", "http://127.0.0.1:14449/testdocument.html"); |
|
637 object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); |
|
638 component.completeCreate(); |
|
639 |
|
640 QCOMPARE(object->property("seenDone").toBool(), true); |
|
641 QCOMPARE(object->property("didNotSeeUnsent").toBool(), true); |
|
642 QCOMPARE(object->property("endStateUnsent").toBool(), true); |
|
643 |
|
644 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
645 |
|
646 delete object; |
|
647 } |
|
648 |
|
649 void tst_qdeclarativexmlhttprequest::getResponseHeader() |
|
650 { |
|
651 QDeclarativeEngine engine; // Avoid cookie contamination |
|
652 |
|
653 TestHTTPServer server(SERVER_PORT); |
|
654 QVERIFY(server.isValid()); |
|
655 QVERIFY(server.wait(TEST_FILE("getResponseHeader.expect"), |
|
656 TEST_FILE("getResponseHeader.reply"), |
|
657 TEST_FILE("testdocument.html"))); |
|
658 |
|
659 |
|
660 QDeclarativeComponent component(&engine, TEST_FILE("getResponseHeader.qml")); |
|
661 QObject *object = component.beginCreate(engine.rootContext()); |
|
662 QVERIFY(object != 0); |
|
663 object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); |
|
664 component.completeCreate(); |
|
665 |
|
666 QCOMPARE(object->property("unsentException").toBool(), true); |
|
667 QCOMPARE(object->property("openedException").toBool(), true); |
|
668 QCOMPARE(object->property("readyState").toBool(), true); |
|
669 QCOMPARE(object->property("openedState").toBool(), true); |
|
670 |
|
671 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
672 |
|
673 QCOMPARE(object->property("headersReceivedState").toBool(), true); |
|
674 QCOMPARE(object->property("headersReceivedNullHeader").toBool(), true); |
|
675 QCOMPARE(object->property("headersReceivedValidHeader").toBool(), true); |
|
676 QCOMPARE(object->property("headersReceivedMultiValidHeader").toBool(), true); |
|
677 QCOMPARE(object->property("headersReceivedCookieHeader").toBool(), true); |
|
678 |
|
679 QCOMPARE(object->property("doneState").toBool(), true); |
|
680 QCOMPARE(object->property("doneNullHeader").toBool(), true); |
|
681 QCOMPARE(object->property("doneValidHeader").toBool(), true); |
|
682 QCOMPARE(object->property("doneMultiValidHeader").toBool(), true); |
|
683 QCOMPARE(object->property("doneCookieHeader").toBool(), true); |
|
684 |
|
685 delete object; |
|
686 } |
|
687 |
|
688 // Test getResponseHeader throws an exception in an invalid state |
|
689 void tst_qdeclarativexmlhttprequest::getResponseHeader_unsent() |
|
690 { |
|
691 QDeclarativeComponent component(&engine, TEST_FILE("getResponseHeader_unsent.qml")); |
|
692 QObject *object = component.create(); |
|
693 QVERIFY(object != 0); |
|
694 |
|
695 QCOMPARE(object->property("test").toBool(), true); |
|
696 |
|
697 delete object; |
|
698 } |
|
699 |
|
700 // Test getResponseHeader throws an exception in an invalid state |
|
701 void tst_qdeclarativexmlhttprequest::getResponseHeader_sent() |
|
702 { |
|
703 QDeclarativeComponent component(&engine, TEST_FILE("getResponseHeader_sent.qml")); |
|
704 QObject *object = component.create(); |
|
705 QVERIFY(object != 0); |
|
706 |
|
707 QCOMPARE(object->property("test").toBool(), true); |
|
708 |
|
709 delete object; |
|
710 } |
|
711 |
|
712 // Invalid arg count throws exception |
|
713 void tst_qdeclarativexmlhttprequest::getResponseHeader_args() |
|
714 { |
|
715 QDeclarativeComponent component(&engine, TEST_FILE("getResponseHeader_args.qml")); |
|
716 QObject *object = component.create(); |
|
717 QVERIFY(object != 0); |
|
718 |
|
719 TRY_WAIT(object->property("exceptionThrown").toBool() == true); |
|
720 |
|
721 delete object; |
|
722 } |
|
723 |
|
724 void tst_qdeclarativexmlhttprequest::getAllResponseHeaders() |
|
725 { |
|
726 QDeclarativeEngine engine; // Avoid cookie contamination |
|
727 |
|
728 TestHTTPServer server(SERVER_PORT); |
|
729 QVERIFY(server.isValid()); |
|
730 QVERIFY(server.wait(TEST_FILE("getResponseHeader.expect"), |
|
731 TEST_FILE("getResponseHeader.reply"), |
|
732 TEST_FILE("testdocument.html"))); |
|
733 |
|
734 QDeclarativeComponent component(&engine, TEST_FILE("getAllResponseHeaders.qml")); |
|
735 QObject *object = component.beginCreate(engine.rootContext()); |
|
736 QVERIFY(object != 0); |
|
737 object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); |
|
738 component.completeCreate(); |
|
739 |
|
740 QCOMPARE(object->property("unsentException").toBool(), true); |
|
741 QCOMPARE(object->property("openedException").toBool(), true); |
|
742 QCOMPARE(object->property("readyState").toBool(), true); |
|
743 QCOMPARE(object->property("openedState").toBool(), true); |
|
744 |
|
745 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
746 |
|
747 QCOMPARE(object->property("headersReceivedState").toBool(), true); |
|
748 QCOMPARE(object->property("headersReceivedHeader").toBool(), true); |
|
749 |
|
750 QCOMPARE(object->property("doneState").toBool(), true); |
|
751 QCOMPARE(object->property("doneHeader").toBool(), true); |
|
752 |
|
753 delete object; |
|
754 } |
|
755 |
|
756 // Test getAllResponseHeaders throws an exception in an invalid state |
|
757 void tst_qdeclarativexmlhttprequest::getAllResponseHeaders_unsent() |
|
758 { |
|
759 QDeclarativeComponent component(&engine, TEST_FILE("getAllResponseHeaders_unsent.qml")); |
|
760 QObject *object = component.create(); |
|
761 QVERIFY(object != 0); |
|
762 |
|
763 QCOMPARE(object->property("test").toBool(), true); |
|
764 |
|
765 delete object; |
|
766 } |
|
767 |
|
768 // Test getAllResponseHeaders throws an exception in an invalid state |
|
769 void tst_qdeclarativexmlhttprequest::getAllResponseHeaders_sent() |
|
770 { |
|
771 QDeclarativeComponent component(&engine, TEST_FILE("getAllResponseHeaders_sent.qml")); |
|
772 QObject *object = component.create(); |
|
773 QVERIFY(object != 0); |
|
774 |
|
775 QCOMPARE(object->property("test").toBool(), true); |
|
776 |
|
777 delete object; |
|
778 } |
|
779 |
|
780 // Invalid arg count throws exception |
|
781 void tst_qdeclarativexmlhttprequest::getAllResponseHeaders_args() |
|
782 { |
|
783 QDeclarativeComponent component(&engine, TEST_FILE("getAllResponseHeaders_args.qml")); |
|
784 QObject *object = component.create(); |
|
785 QVERIFY(object != 0); |
|
786 |
|
787 TRY_WAIT(object->property("exceptionThrown").toBool() == true); |
|
788 |
|
789 delete object; |
|
790 } |
|
791 |
|
792 void tst_qdeclarativexmlhttprequest::status() |
|
793 { |
|
794 QFETCH(QUrl, replyUrl); |
|
795 QFETCH(int, status); |
|
796 |
|
797 TestHTTPServer server(SERVER_PORT); |
|
798 QVERIFY(server.isValid()); |
|
799 QVERIFY(server.wait(TEST_FILE("status.expect"), |
|
800 replyUrl, |
|
801 TEST_FILE("testdocument.html"))); |
|
802 |
|
803 QDeclarativeComponent component(&engine, TEST_FILE("status.qml")); |
|
804 QObject *object = component.beginCreate(engine.rootContext()); |
|
805 QVERIFY(object != 0); |
|
806 object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); |
|
807 object->setProperty("expectedStatus", status); |
|
808 component.completeCreate(); |
|
809 |
|
810 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
811 |
|
812 QCOMPARE(object->property("unsentException").toBool(), true); |
|
813 QCOMPARE(object->property("openedException").toBool(), true); |
|
814 QCOMPARE(object->property("sentException").toBool(), true); |
|
815 QCOMPARE(object->property("headersReceived").toBool(), true); |
|
816 QCOMPARE(object->property("loading").toBool(), true); |
|
817 QCOMPARE(object->property("done").toBool(), true); |
|
818 QCOMPARE(object->property("resetException").toBool(), true); |
|
819 |
|
820 delete object; |
|
821 } |
|
822 |
|
823 void tst_qdeclarativexmlhttprequest::status_data() |
|
824 { |
|
825 QTest::addColumn<QUrl>("replyUrl"); |
|
826 QTest::addColumn<int>("status"); |
|
827 |
|
828 QTest::newRow("OK") << TEST_FILE("status.200.reply") << 200; |
|
829 QTest::newRow("Not Found") << TEST_FILE("status.404.reply") << 404; |
|
830 } |
|
831 |
|
832 void tst_qdeclarativexmlhttprequest::statusText() |
|
833 { |
|
834 QFETCH(QUrl, replyUrl); |
|
835 QFETCH(QString, statusText); |
|
836 |
|
837 TestHTTPServer server(SERVER_PORT); |
|
838 QVERIFY(server.isValid()); |
|
839 QVERIFY(server.wait(TEST_FILE("status.expect"), |
|
840 replyUrl, |
|
841 TEST_FILE("testdocument.html"))); |
|
842 |
|
843 QDeclarativeComponent component(&engine, TEST_FILE("statusText.qml")); |
|
844 QObject *object = component.beginCreate(engine.rootContext()); |
|
845 QVERIFY(object != 0); |
|
846 object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); |
|
847 object->setProperty("expectedStatus", statusText); |
|
848 component.completeCreate(); |
|
849 |
|
850 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
851 |
|
852 QCOMPARE(object->property("unsentException").toBool(), true); |
|
853 QCOMPARE(object->property("openedException").toBool(), true); |
|
854 QCOMPARE(object->property("sentException").toBool(), true); |
|
855 QCOMPARE(object->property("headersReceived").toBool(), true); |
|
856 QCOMPARE(object->property("loading").toBool(), true); |
|
857 QCOMPARE(object->property("done").toBool(), true); |
|
858 QCOMPARE(object->property("resetException").toBool(), true); |
|
859 |
|
860 delete object; |
|
861 } |
|
862 |
|
863 void tst_qdeclarativexmlhttprequest::statusText_data() |
|
864 { |
|
865 QTest::addColumn<QUrl>("replyUrl"); |
|
866 QTest::addColumn<QString>("statusText"); |
|
867 |
|
868 QTest::newRow("OK") << TEST_FILE("status.200.reply") << "OK"; |
|
869 QTest::newRow("Not Found") << TEST_FILE("status.404.reply") << "Document not found"; |
|
870 } |
|
871 |
|
872 void tst_qdeclarativexmlhttprequest::responseText() |
|
873 { |
|
874 QFETCH(QUrl, replyUrl); |
|
875 QFETCH(QUrl, bodyUrl); |
|
876 QFETCH(QString, responseText); |
|
877 |
|
878 TestHTTPServer server(SERVER_PORT); |
|
879 QVERIFY(server.isValid()); |
|
880 QVERIFY(server.wait(TEST_FILE("status.expect"), |
|
881 replyUrl, |
|
882 bodyUrl)); |
|
883 |
|
884 QDeclarativeComponent component(&engine, TEST_FILE("responseText.qml")); |
|
885 QObject *object = component.beginCreate(engine.rootContext()); |
|
886 QVERIFY(object != 0); |
|
887 object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); |
|
888 object->setProperty("expectedText", responseText); |
|
889 component.completeCreate(); |
|
890 |
|
891 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
892 |
|
893 QCOMPARE(object->property("unsent").toBool(), true); |
|
894 QCOMPARE(object->property("opened").toBool(), true); |
|
895 QCOMPARE(object->property("sent").toBool(), true); |
|
896 QCOMPARE(object->property("headersReceived").toBool(), true); |
|
897 QCOMPARE(object->property("loading").toBool(), true); |
|
898 QCOMPARE(object->property("done").toBool(), true); |
|
899 QCOMPARE(object->property("reset").toBool(), true); |
|
900 |
|
901 delete object; |
|
902 } |
|
903 |
|
904 void tst_qdeclarativexmlhttprequest::responseText_data() |
|
905 { |
|
906 QTest::addColumn<QUrl>("replyUrl"); |
|
907 QTest::addColumn<QUrl>("bodyUrl"); |
|
908 QTest::addColumn<QString>("responseText"); |
|
909 |
|
910 QTest::newRow("OK") << TEST_FILE("status.200.reply") << TEST_FILE("testdocument.html") << "QML Rocks!\n"; |
|
911 QTest::newRow("empty body") << TEST_FILE("status.200.reply") << QUrl() << ""; |
|
912 QTest::newRow("Not Found") << TEST_FILE("status.404.reply") << TEST_FILE("testdocument.html") << ""; |
|
913 } |
|
914 |
|
915 void tst_qdeclarativexmlhttprequest::nonUtf8() |
|
916 { |
|
917 QDeclarativeComponent component(&engine, TEST_FILE("utf16.qml")); |
|
918 QObject *object = component.create(); |
|
919 QVERIFY(object != 0); |
|
920 |
|
921 QString uc; |
|
922 uc.resize(3); |
|
923 uc[0] = QChar(0x10e3); |
|
924 uc[1] = QChar(' '); |
|
925 uc[2] = QChar(0x03a3); |
|
926 QString xml = "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone='yes'?>\n<root>\n" + uc + "\n</root>\n"; |
|
927 |
|
928 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
929 |
|
930 QString responseText = object->property("responseText").toString(); |
|
931 QCOMPARE(responseText, xml); |
|
932 |
|
933 QString responseXmlText = object->property("responseXmlRootNodeValue").toString(); |
|
934 QCOMPARE(responseXmlText, '\n' + uc + '\n'); |
|
935 |
|
936 delete object; |
|
937 } |
|
938 |
|
939 // Test that calling hte XMLHttpRequest methods on a non-XMLHttpRequest object |
|
940 // throws an exception |
|
941 void tst_qdeclarativexmlhttprequest::invalidMethodUsage() |
|
942 { |
|
943 QDeclarativeComponent component(&engine, TEST_FILE("invalidMethodUsage.qml")); |
|
944 QObject *object = component.create(); |
|
945 QVERIFY(object != 0); |
|
946 |
|
947 QCOMPARE(object->property("onreadystatechange").toBool(), true); |
|
948 QCOMPARE(object->property("readyState").toBool(), true); |
|
949 QCOMPARE(object->property("status").toBool(), true); |
|
950 QCOMPARE(object->property("statusText").toBool(), true); |
|
951 QCOMPARE(object->property("responseText").toBool(), true); |
|
952 QCOMPARE(object->property("responseXML").toBool(), true); |
|
953 |
|
954 QCOMPARE(object->property("open").toBool(), true); |
|
955 QCOMPARE(object->property("setRequestHeader").toBool(), true); |
|
956 QCOMPARE(object->property("send").toBool(), true); |
|
957 QCOMPARE(object->property("abort").toBool(), true); |
|
958 QCOMPARE(object->property("getResponseHeader").toBool(), true); |
|
959 QCOMPARE(object->property("getAllResponseHeaders").toBool(), true); |
|
960 |
|
961 delete object; |
|
962 } |
|
963 |
|
964 // Test that XMLHttpRequest transparently redirects |
|
965 void tst_qdeclarativexmlhttprequest::redirects() |
|
966 { |
|
967 { |
|
968 TestHTTPServer server(SERVER_PORT); |
|
969 QVERIFY(server.isValid()); |
|
970 server.addRedirect("redirect.html", "http://127.0.0.1:14445/redirecttarget.html"); |
|
971 server.serveDirectory(SRCDIR "/data"); |
|
972 |
|
973 QDeclarativeComponent component(&engine, TEST_FILE("redirects.qml")); |
|
974 QObject *object = component.beginCreate(engine.rootContext()); |
|
975 QVERIFY(object != 0); |
|
976 object->setProperty("url", "http://127.0.0.1:14445/redirect.html"); |
|
977 object->setProperty("expectedText", ""); |
|
978 component.completeCreate(); |
|
979 |
|
980 TRY_WAIT(object->property("done").toBool() == true); |
|
981 QCOMPARE(object->property("dataOK").toBool(), true); |
|
982 |
|
983 delete object; |
|
984 } |
|
985 |
|
986 { |
|
987 TestHTTPServer server(SERVER_PORT); |
|
988 QVERIFY(server.isValid()); |
|
989 server.addRedirect("redirect.html", "http://127.0.0.1:14445/redirectmissing.html"); |
|
990 server.serveDirectory(SRCDIR "/data"); |
|
991 |
|
992 QDeclarativeComponent component(&engine, TEST_FILE("redirectError.qml")); |
|
993 QObject *object = component.beginCreate(engine.rootContext()); |
|
994 QVERIFY(object != 0); |
|
995 object->setProperty("url", "http://127.0.0.1:14445/redirect.html"); |
|
996 object->setProperty("expectedText", ""); |
|
997 component.completeCreate(); |
|
998 |
|
999 TRY_WAIT(object->property("done").toBool() == true); |
|
1000 QCOMPARE(object->property("dataOK").toBool(), true); |
|
1001 |
|
1002 delete object; |
|
1003 } |
|
1004 |
|
1005 { |
|
1006 TestHTTPServer server(SERVER_PORT); |
|
1007 QVERIFY(server.isValid()); |
|
1008 server.addRedirect("redirect.html", "http://127.0.0.1:14445/redirect.html"); |
|
1009 server.serveDirectory(SRCDIR "/data"); |
|
1010 |
|
1011 QDeclarativeComponent component(&engine, TEST_FILE("redirectRecur.qml")); |
|
1012 QObject *object = component.beginCreate(engine.rootContext()); |
|
1013 QVERIFY(object != 0); |
|
1014 object->setProperty("url", "http://127.0.0.1:14445/redirect.html"); |
|
1015 object->setProperty("expectedText", ""); |
|
1016 component.completeCreate(); |
|
1017 |
|
1018 for (int ii = 0; ii < 60; ++ii) { |
|
1019 if (object->property("done").toBool()) break; |
|
1020 QTest::qWait(50); |
|
1021 } |
|
1022 QVERIFY(object->property("done").toBool() == true); |
|
1023 |
|
1024 QCOMPARE(object->property("dataOK").toBool(), true); |
|
1025 |
|
1026 delete object; |
|
1027 } |
|
1028 } |
|
1029 |
|
1030 void tst_qdeclarativexmlhttprequest::responseXML_invalid() |
|
1031 { |
|
1032 QDeclarativeComponent component(&engine, TEST_FILE("responseXML_invalid.qml")); |
|
1033 QObject *object = component.create(); |
|
1034 QVERIFY(object != 0); |
|
1035 |
|
1036 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
1037 |
|
1038 QCOMPARE(object->property("xmlNull").toBool(), true); |
|
1039 |
|
1040 delete object; |
|
1041 } |
|
1042 |
|
1043 // Test the Document DOM element |
|
1044 void tst_qdeclarativexmlhttprequest::document() |
|
1045 { |
|
1046 QDeclarativeComponent component(&engine, TEST_FILE("document.qml")); |
|
1047 QObject *object = component.create(); |
|
1048 QVERIFY(object != 0); |
|
1049 |
|
1050 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
1051 |
|
1052 QCOMPARE(object->property("xmlTest").toBool(), true); |
|
1053 |
|
1054 delete object; |
|
1055 } |
|
1056 |
|
1057 // Test the Element DOM element |
|
1058 void tst_qdeclarativexmlhttprequest::element() |
|
1059 { |
|
1060 QDeclarativeComponent component(&engine, TEST_FILE("element.qml")); |
|
1061 QObject *object = component.create(); |
|
1062 QVERIFY(object != 0); |
|
1063 |
|
1064 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
1065 |
|
1066 QCOMPARE(object->property("xmlTest").toBool(), true); |
|
1067 |
|
1068 delete object; |
|
1069 } |
|
1070 |
|
1071 // Test the Attr DOM element |
|
1072 void tst_qdeclarativexmlhttprequest::attr() |
|
1073 { |
|
1074 QDeclarativeComponent component(&engine, TEST_FILE("attr.qml")); |
|
1075 QObject *object = component.create(); |
|
1076 QVERIFY(object != 0); |
|
1077 |
|
1078 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
1079 |
|
1080 QCOMPARE(object->property("xmlTest").toBool(), true); |
|
1081 |
|
1082 delete object; |
|
1083 } |
|
1084 |
|
1085 // Test the Text DOM element |
|
1086 void tst_qdeclarativexmlhttprequest::text() |
|
1087 { |
|
1088 QDeclarativeComponent component(&engine, TEST_FILE("text.qml")); |
|
1089 QObject *object = component.create(); |
|
1090 QVERIFY(object != 0); |
|
1091 |
|
1092 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
1093 |
|
1094 QCOMPARE(object->property("xmlTest").toBool(), true); |
|
1095 |
|
1096 delete object; |
|
1097 } |
|
1098 |
|
1099 // Test the CDataSection DOM element |
|
1100 void tst_qdeclarativexmlhttprequest::cdata() |
|
1101 { |
|
1102 QDeclarativeComponent component(&engine, TEST_FILE("cdata.qml")); |
|
1103 QObject *object = component.create(); |
|
1104 QVERIFY(object != 0); |
|
1105 |
|
1106 TRY_WAIT(object->property("dataOK").toBool() == true); |
|
1107 |
|
1108 QCOMPARE(object->property("xmlTest").toBool(), true); |
|
1109 |
|
1110 delete object; |
|
1111 } |
|
1112 |
|
1113 QTEST_MAIN(tst_qdeclarativexmlhttprequest) |
|
1114 |
|
1115 #include "tst_qdeclarativexmlhttprequest.moc" |