aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlxmlhttprequest
diff options
context:
space:
mode:
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..97b016f50a
--- /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: {{ServerHostUrl}}
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 c159dc8420..ad78fafc67 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();
@@ -848,6 +849,23 @@ void tst_qqmlxmlhttprequest::getBinaryData()
QTRY_VERIFY(object->property("readSize").toInt() == fileInfo.size());
}
+void tst_qqmlxmlhttprequest::getJsonData()
+{
+ TestHTTPServer server;
+ QVERIFY2(server.listen(), 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", server.urlString("/json.data"));
+ component.completeCreate();
+
+ QTRY_VERIFY(object->property("result").toBool());
+}
+
void tst_qqmlxmlhttprequest::status()
{
QFETCH(QUrl, replyUrl);