diff options
author | Valery Kotov <kotov.valery@gmail.com> | 2014-08-18 22:06:38 +0300 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2014-09-15 10:29:12 +0200 |
commit | 2c54d85bf70e078ab1dfb1465567512aded5cf9d (patch) | |
tree | 39f6d24b70e5784e7619fa7114a9facd80090403 /tests/auto/qml/qqmlxmlhttprequest | |
parent | 404640392b28d253c24330eb8acc0c30d838af92 (diff) |
QML Engine: Support for "OPTIONS" method for XMLHTTPRequest was added.
Support for OPTIONS method was added to QQmlXMLHttpRequest. Tests for
OPTIONS method in XMLHttpRequest were added.
[ChangeLog][QtQml][QQmlXMLHttpRequest] QQmlXMLHttpRequest now
supports the OPTION method in HTTP requests.
Task-number: QTBUG-35892
Change-Id: Ibbcf3ecddeb8ced64d8c3e52b777dd6ec0ed98f7
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests/auto/qml/qqmlxmlhttprequest')
7 files changed, 118 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.10.expect b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.10.expect new file mode 100644 index 0000000000..b099ed205e --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.10.expect @@ -0,0 +1,10 @@ +OPTIONS /testdocument.html HTTP/1.1 +Accept-Language: en-US,* +Content-Type: text/plain;charset=UTF-8 +Content-Length: 12 +Connection: Keep-Alive +Accept-Encoding: gzip, deflate +User-Agent: Mozilla/5.0 +Host: 127.0.0.1:14445 + +My Sent Data
\ No newline at end of file diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.2.reply b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.2.reply new file mode 100644 index 0000000000..b4f5ecd429 --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.2.reply @@ -0,0 +1,3 @@ +HTTP/1.1 200 OK +Allow: GET,HEAD,POST,OPTIONS,TRACE +Content-Length: 0 diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.8.expect b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.8.expect new file mode 100644 index 0000000000..8462c40ba1 --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.8.expect @@ -0,0 +1,7 @@ +OPTIONS / HTTP/1.1 +Content-Length: 0 +Connection: Keep-Alive +Accept-Encoding: gzip, deflate +Accept-Language: en-US,* +User-Agent: Mozilla/5.0 +Host: 127.0.0.1:14445 diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.8.qml b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.8.qml new file mode 100644 index 0000000000..bda5871a18 --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.8.qml @@ -0,0 +1,24 @@ +import QtQuick 2.0 + +QtObject { + property string url + + property bool dataOK: false + property bool headerOK: false + + Component.onCompleted: { + var x = new XMLHttpRequest; + x.open("OPTIONS", url); + + // Test to the end + x.onreadystatechange = function() { + if (x.readyState == XMLHttpRequest.HEADERS_RECEIVED) { + headerOK = (x.getResponseHeader("Allow") == "GET,HEAD,POST,OPTIONS,TRACE"); + } else if (x.readyState == XMLHttpRequest.DONE) { + dataOK = (x.responseText == ""); + } + } + + x.send(); + } +} diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.9.expect b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.9.expect new file mode 100644 index 0000000000..02af8c99b8 --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.9.expect @@ -0,0 +1,7 @@ +OPTIONS /testdocument.html HTTP/1.1 +Content-Length: 0 +Connection: Keep-Alive +Accept-Encoding: gzip, deflate +Accept-Language: en-US,* +User-Agent: Mozilla/5.0 +Host: 127.0.0.1:14445 diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.9.qml b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.9.qml new file mode 100644 index 0000000000..834916f96c --- /dev/null +++ b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.9.qml @@ -0,0 +1,24 @@ +import QtQuick 2.0 + +QtObject { + property string url + + property bool dataOK: false + property bool headerOK: false + + Component.onCompleted: { + var x = new XMLHttpRequest; + x.open("OPTIONS", url); + + // Test to the end + x.onreadystatechange = function() { + if (x.readyState == XMLHttpRequest.HEADERS_RECEIVED) { + headerOK = (x.getResponseHeader("Allow") == "GET,HEAD,POST,OPTIONS,TRACE"); + } else if (x.readyState == XMLHttpRequest.DONE) { + dataOK = (x.responseText == ""); + } + } + + x.send("My Sent Data"); + } +} diff --git a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp index 9267c187bb..441893a853 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp +++ b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp @@ -73,6 +73,8 @@ private slots: void send_ignoreData(); void send_withdata(); void send_withdata_data(); + void send_options(); + void send_options_data(); void abort(); void abort_unsent(); void abort_opened(); @@ -552,6 +554,47 @@ void tst_qqmlxmlhttprequest::send_withdata_data() QTest::newRow("Correct content-type - no charset") << "send_data.1.expect" << "send_data.7.qml"; } +void tst_qqmlxmlhttprequest::send_options() +{ + QFETCH(QString, url_suffix); + QFETCH(QString, file_expected); + QFETCH(QString, file_qml); + QFETCH(QString, file_reply); + + TestHTTPServer server; + QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY(server.wait(testFileUrl(file_expected), + testFileUrl(file_reply), + testFileUrl("testdocument.html"))); + + QQmlComponent component(&engine, testFileUrl(file_qml)); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); + QString url = "http://127.0.0.1:14445"; + if (url_suffix != "/") + url.append("/"); + if (!url_suffix.isEmpty()) + url.append(url_suffix); + object->setProperty("url", url); + component.completeCreate(); + + QTRY_VERIFY(object->property("dataOK").toBool()); + QTRY_VERIFY(object->property("headerOK").toBool()); +} + +void tst_qqmlxmlhttprequest::send_options_data() +{ + QTest::addColumn<QString>("url_suffix"); + QTest::addColumn<QString>("file_expected"); + QTest::addColumn<QString>("file_qml"); + QTest::addColumn<QString>("file_reply"); + + QTest::newRow("OPTIONS (no data, no resource, no path)") << "" << "send_data.8.expect" << "send_data.8.qml" << "send_data.2.reply"; + QTest::newRow("OPTIONS (no data, no resource, path- \"/\")") << "/" << "send_data.8.expect" << "send_data.8.qml" << "send_data.2.reply"; + QTest::newRow("OPTIONS (no data, with resource)") << "testdocument.html" << "send_data.9.expect" << "send_data.8.qml" << "send_data.2.reply"; + QTest::newRow("OPTIONS (with data)") << "testdocument.html" << "send_data.10.expect" << "send_data.9.qml" << "send_data.2.reply"; +} + // Test abort() has no effect in unsent state void tst_qqmlxmlhttprequest::abort_unsent() { |