aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlxmlhttprequest
diff options
context:
space:
mode:
authorValery Kotov <kotov.valery@gmail.com>2015-04-07 20:34:44 +0300
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-04-16 17:44:29 +0000
commit43961057a973715856486c596959213bd911df73 (patch)
tree95a93b3f273a0540c5063331e942da738207bd27 /tests/auto/qml/qqmlxmlhttprequest
parent4930941197576c6017451856beb59a0ff8d045bd (diff)
QML Engine: JSON XHR response type support
Support for "json" response type for QQmlXMLHttpRequest was added. [ChangeLog][QtQml][QQmlXMLHttpRequest] QQmlXMLHttpRequest now supports "json" binary response type. Change-Id: I21b7659c02dfdc6b64a73e1d2003e269d90b3b23 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'tests/auto/qml/qqmlxmlhttprequest')
-rw-r--r--tests/auto/qml/qqmlxmlhttprequest/data/json.data6
-rw-r--r--tests/auto/qml/qqmlxmlhttprequest/data/receiveJsonData.qml22
-rw-r--r--tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.expect7
-rw-r--r--tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.reply3
-rw-r--r--tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp18
5 files changed, 56 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/json.data b/tests/auto/qml/qqmlxmlhttprequest/data/json.data
new file mode 100644
index 0000000000..7925375293
--- /dev/null
+++ b/tests/auto/qml/qqmlxmlhttprequest/data/json.data
@@ -0,0 +1,6 @@
+{"widget": {
+ "debug": "on",
+ "window": {
+ "name": "main_window",
+ "width": 500
+}}}
diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/receiveJsonData.qml b/tests/auto/qml/qqmlxmlhttprequest/data/receiveJsonData.qml
new file mode 100644
index 0000000000..3fc116e675
--- /dev/null
+++ b/tests/auto/qml/qqmlxmlhttprequest/data/receiveJsonData.qml
@@ -0,0 +1,22 @@
+import QtQuick 2.0
+
+QtObject {
+ property string url;
+ property bool result: false
+ property string correctjsondata : "{\"widget\":{\"debug\":\"on\",\"window\":{\"name\":\"main_window\",\"width\":500}}}"
+
+ Component.onCompleted: {
+ var request = new XMLHttpRequest();
+ request.open("GET", url, true);
+ request.responseType = "json";
+
+ request.onreadystatechange = function() {
+ if (request.readyState == XMLHttpRequest.DONE) {
+ var jsonData = JSON.stringify(request.response);
+ result = (correctjsondata == jsonData);
+ }
+ }
+
+ request.send(null);
+ }
+}
diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.expect b/tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.expect
new file mode 100644
index 0000000000..59a7806bc9
--- /dev/null
+++ b/tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.expect
@@ -0,0 +1,7 @@
+GET /json.data HTTP/1.1
+Accept-Language: en-US,*
+Content-Type: application/jsonrequest
+Connection: Keep-Alive
+Accept-Encoding: gzip, deflate
+User-Agent: Mozilla/5.0
+Host: 127.0.0.1:14445
diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.reply b/tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.reply
new file mode 100644
index 0000000000..f1ee73d623
--- /dev/null
+++ b/tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.reply
@@ -0,0 +1,3 @@
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: application/jsonrequest
diff --git a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp
index dd70f81d5e..d901c4dd14 100644
--- a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp
+++ b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp
@@ -88,6 +88,7 @@ private slots:
void getAllResponseHeaders_sent();
void getAllResponseHeaders_args();
void getBinaryData();
+ void getJsonData();
void status();
void status_data();
void statusText();
@@ -835,6 +836,23 @@ void tst_qqmlxmlhttprequest::getBinaryData()
QTRY_VERIFY(object->property("readSize").toInt() == fileInfo.size());
}
+void tst_qqmlxmlhttprequest::getJsonData()
+{
+ TestHTTPServer server;
+ QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString()));
+ QVERIFY(server.wait(testFileUrl("receive_json_data.expect"),
+ testFileUrl("receive_binary_data.reply"),
+ testFileUrl("json.data")));
+
+ QQmlComponent component(&engine, testFileUrl("receiveJsonData.qml"));
+ QScopedPointer<QObject> object(component.beginCreate(engine.rootContext()));
+ QVERIFY(!object.isNull());
+ object->setProperty("url", "http://127.0.0.1:14445/json.data");
+ component.completeCreate();
+
+ QTRY_VERIFY(object->property("result").toBool());
+}
+
void tst_qqmlxmlhttprequest::status()
{
QFETCH(QUrl, replyUrl);