aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlxmlhttprequest
diff options
context:
space:
mode:
authorValery Kotov <kotov.valery@gmail.com>2015-03-04 21:57:14 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-03-09 19:41:41 +0000
commitd988310434b00cc0e159fdf6ff3f586eefc47eed (patch)
tree6dd1bdfb543a3ca8a2a1d0c51273b1e6a9fe5bb8 /tests/auto/qml/qqmlxmlhttprequest
parent0294702c9c174c67de563cfdea5c32548d111a58 (diff)
QML Engine: ArrayBuffer XHR response type support
Support for "arraybuffer" response type for QQmlXMLHttpRequest was added. [ChangeLog][QtQml][QQmlXMLHttpRequest] QQmlXMLHttpRequest now supports "arraybuffer" binary response type. Change-Id: I866e543cc7bc6ab037ffff1ef6628057b73daf90 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'tests/auto/qml/qqmlxmlhttprequest')
-rw-r--r--tests/auto/qml/qqmlxmlhttprequest/data/qml_logo.pngbin0 -> 27151 bytes
-rw-r--r--tests/auto/qml/qqmlxmlhttprequest/data/receiveBinaryData.qml27
-rw-r--r--tests/auto/qml/qqmlxmlhttprequest/data/receive_binary_data.expect7
-rw-r--r--tests/auto/qml/qqmlxmlhttprequest/data/receive_binary_data.reply3
-rw-r--r--tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp19
5 files changed, 56 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/qml_logo.png b/tests/auto/qml/qqmlxmlhttprequest/data/qml_logo.png
new file mode 100644
index 0000000000..681aef8aa2
--- /dev/null
+++ b/tests/auto/qml/qqmlxmlhttprequest/data/qml_logo.png
Binary files differ
diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/receiveBinaryData.qml b/tests/auto/qml/qqmlxmlhttprequest/data/receiveBinaryData.qml
new file mode 100644
index 0000000000..234d759284
--- /dev/null
+++ b/tests/auto/qml/qqmlxmlhttprequest/data/receiveBinaryData.qml
@@ -0,0 +1,27 @@
+import QtQuick 2.0
+
+QtObject {
+ property string url
+ property int readSize: 0
+
+ Component.onCompleted: {
+
+ var request = new XMLHttpRequest();
+ request.open("GET", url);
+ request.responseType = "arraybuffer";
+
+ request.onreadystatechange = function() {
+ if (request.readyState == XMLHttpRequest.DONE) {
+ var arrayBuffer = request.response;
+ if (arrayBuffer) {
+ var byteArray = new Uint8Array(arrayBuffer);
+ readSize = byteArray.byteLength;
+ }
+ }
+ }
+
+ request.send(null);
+
+ }
+}
+
diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/receive_binary_data.expect b/tests/auto/qml/qqmlxmlhttprequest/data/receive_binary_data.expect
new file mode 100644
index 0000000000..79a61383e3
--- /dev/null
+++ b/tests/auto/qml/qqmlxmlhttprequest/data/receive_binary_data.expect
@@ -0,0 +1,7 @@
+GET /gml_logo.png HTTP/1.1
+Accept-Language: en-US,*
+Content-Type: image/png
+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_binary_data.reply b/tests/auto/qml/qqmlxmlhttprequest/data/receive_binary_data.reply
new file mode 100644
index 0000000000..44ba138213
--- /dev/null
+++ b/tests/auto/qml/qqmlxmlhttprequest/data/receive_binary_data.reply
@@ -0,0 +1,3 @@
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: image/png
diff --git a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp
index fe1b8b1505..dd70f81d5e 100644
--- a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp
+++ b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp
@@ -87,6 +87,7 @@ private slots:
void getAllResponseHeaders_unsent();
void getAllResponseHeaders_sent();
void getAllResponseHeaders_args();
+ void getBinaryData();
void status();
void status_data();
void statusText();
@@ -816,6 +817,24 @@ void tst_qqmlxmlhttprequest::getAllResponseHeaders_args()
QTRY_VERIFY(object->property("exceptionThrown").toBool() == true);
}
+void tst_qqmlxmlhttprequest::getBinaryData()
+{
+ TestHTTPServer server;
+ QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString()));
+ QVERIFY(server.wait(testFileUrl("receive_binary_data.expect"),
+ testFileUrl("receive_binary_data.reply"),
+ testFileUrl("qml_logo.png")));
+
+ QQmlComponent component(&engine, testFileUrl("receiveBinaryData.qml"));
+ QScopedPointer<QObject> object(component.beginCreate(engine.rootContext()));
+ QVERIFY(!object.isNull());
+ object->setProperty("url", "http://127.0.0.1:14445/gml_logo.png");
+ component.completeCreate();
+
+ QFileInfo fileInfo("data/qml_logo.png");
+ QTRY_VERIFY(object->property("readSize").toInt() == fileInfo.size());
+}
+
void tst_qqmlxmlhttprequest::status()
{
QFETCH(QUrl, replyUrl);