diff options
Diffstat (limited to 'tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp')
-rw-r--r-- | tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp | 107 |
1 files changed, 90 insertions, 17 deletions
diff --git a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp index 6517c58670..f908633193 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp +++ b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qtest.h> #include <QQmlEngine> @@ -75,6 +75,7 @@ private slots: void statusText_data(); void responseText(); void responseText_data(); + void responseURL(); void responseXML_invalid(); void invalidMethodUsage(); void redirects(); @@ -89,6 +90,8 @@ private slots: void sendFileRequestNoRead(); #endif + void overrideMime(); + // WebDAV void sendPropfind(); void sendPropfind_data(); @@ -637,8 +640,6 @@ void tst_qqmlxmlhttprequest::send_options() void tst_qqmlxmlhttprequest::send_options_data() { - if (QLocale::system() != QLocale(QLocale::English, QLocale::UnitedStates)) - QSKIP("Test is locale dependent"); QTest::addColumn<QString>("url_suffix"); QTest::addColumn<QString>("file_expected"); QTest::addColumn<QString>("file_qml"); @@ -863,8 +864,6 @@ void tst_qqmlxmlhttprequest::getAllResponseHeaders_args() void tst_qqmlxmlhttprequest::getBinaryData() { - if (QLocale::system() != QLocale(QLocale::English, QLocale::UnitedStates)) - QSKIP("Test is locale dependent"); TestHTTPServer server; QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("receive_binary_data.expect"), @@ -877,15 +876,13 @@ void tst_qqmlxmlhttprequest::getBinaryData() object->setProperty("url", server.urlString("/gml_logo.png")); component.completeCreate(); - QFileInfo fileInfo("data/qml_logo.png"); + const QFileInfo fileInfo(testFile("qml_logo.png")); QTRY_COMPARE(object->property("readSize").toInt(), fileInfo.size()); QCOMPARE(object->property("status").toInt(), 200); } void tst_qqmlxmlhttprequest::getJsonData() { - if (QLocale::system() != QLocale(QLocale::English, QLocale::UnitedStates)) - QSKIP("Test is locale dependent"); TestHTTPServer server; QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("receive_json_data.expect"), @@ -1025,6 +1022,64 @@ void tst_qqmlxmlhttprequest::responseText_data() QTest::newRow("Internal server error") << testFileUrl("status.500.reply") << testFileUrl("testdocument.html") << "QML Rocks!\n"; } + +void tst_qqmlxmlhttprequest::responseURL() +{ + // 200 OK + { + TestHTTPServer server; + QVERIFY2(server.listen(), qPrintable(server.errorString())); + QVERIFY(server.wait(testFileUrl("status.expect"), + testFileUrl("status.200.reply"), + testFileUrl("testdocument.html"))); + + QQmlComponent component(engine.get(), testFileUrl("responseURL.qml")); + QScopedPointer<QObject> object(component.beginCreate(engine.get()->rootContext())); + QVERIFY(!object.isNull()); + object->setProperty("url", server.urlString("/testdocument.html")); + object->setProperty("expectedURL", server.urlString("/testdocument.html")); + component.completeCreate(); + + QTRY_VERIFY(object->property("dataOK").toBool()); + } + + // 200 OK with the exclude fragment flag set + { + TestHTTPServer server; + QVERIFY2(server.listen(), qPrintable(server.errorString())); + QVERIFY(server.wait(testFileUrl("status.expect"), + testFileUrl("status.200.reply"), + testFileUrl("testdocument.html"))); + + QQmlComponent component(engine.get(), testFileUrl("responseURL.qml")); + QScopedPointer<QObject> object(component.beginCreate(engine.get()->rootContext())); + QVERIFY(!object.isNull()); + object->setProperty("url", server.urlString("/testdocument.html#fragment")); + object->setProperty("expectedURL", server.urlString("/testdocument.html")); + component.completeCreate(); + + QTRY_VERIFY(object->property("dataOK").toBool()); + } + + // 302 Found + { + TestHTTPServer server; + QVERIFY2(server.listen(), qPrintable(server.errorString())); + server.addRedirect("redirect.html", server.urlString("/redirecttarget.html")); + server.serveDirectory(dataDirectory()); + + QQmlComponent component(engine.get(), testFileUrl("responseURL.qml")); + QScopedPointer<QObject> object(component.beginCreate(engine.get()->rootContext())); + QVERIFY(!object.isNull()); + object->setProperty("url", server.urlString("/redirect.html")); + object->setProperty("expectedURL", server.urlString("/redirecttarget.html")); + component.completeCreate(); + + QTRY_VERIFY(object->property("dataOK").toBool()); + } +} + + void tst_qqmlxmlhttprequest::nonUtf8() { QFETCH(QString, fileName); @@ -1076,7 +1131,7 @@ void tst_qqmlxmlhttprequest::doFileRequest(std::function<void(QObject *component QTemporaryFile writeFile; QTemporaryFile readFile; - writeFile.open(); + QVERIFY(writeFile.open()); writeFile.close(); QVERIFY(readFile.open()); @@ -1242,8 +1297,6 @@ void tst_qqmlxmlhttprequest::sendFileRequestNoRead() { void tst_qqmlxmlhttprequest::sendPropfind() { - if (QLocale::system() != QLocale(QLocale::English, QLocale::UnitedStates)) - QSKIP("Test is locale dependent"); const QString prefix = "WebDAV//"; QFETCH(QString, qml); @@ -1277,14 +1330,17 @@ void tst_qqmlxmlhttprequest::sendPropfind_data() QTest::addColumn<QString>("replyHeader"); QTest::addColumn<QString>("replyBody"); - QTest::newRow("Send PROPFIND for file (bigbox, author, DingALing, Random properties). Get response with responseXML.") + QTest::newRow("Send PROPFIND for file (bigbox, author, DingALing, Random properties). " + "Get response with responseXML.") << "sendPropfind.responseXML.qml" << "/file" << "propfind.file.expect" << "propfind.file.reply.header" << "propfind.file.reply.body"; - QTest::newRow("Send PROPFIND for file (bigbox, author, DingALing, Random properties). Get response with response.") + QTest::newRow("Send PROPFIND for file (bigbox, author, DingALing, Random properties). " + "Get response with response.") << "sendPropfind.response.qml" << "/file" << "propfind.file.expect" << "propfind.file.reply.header" << "propfind.file.reply.body"; QTest::newRow("Send PROPFIND \"allprop\" request for collection.") - << "sendPropfind.collection.allprop.qml" << "/container/" << "propfind.collection.allprop.expect" + << "sendPropfind.collection.allprop.qml" << "/container/" + << "propfind.collection.allprop.expect" << "propfind.file.reply.header" << "propfind.collection.allprop.reply.body"; } @@ -1323,7 +1379,6 @@ void tst_qqmlxmlhttprequest::redirects() QScopedPointer<QObject> object(component.beginCreate(engine.get()->rootContext())); QVERIFY(!object.isNull()); object->setProperty("url", server.urlString("/redirect.html")); - object->setProperty("expectedText", ""); component.completeCreate(); QTRY_VERIFY(object->property("done").toBool()); @@ -1340,7 +1395,6 @@ void tst_qqmlxmlhttprequest::redirects() QScopedPointer<QObject> object(component.beginCreate(engine.get()->rootContext())); QVERIFY(!object.isNull()); object->setProperty("url", server.urlString("/redirect.html")); - object->setProperty("expectedText", ""); component.completeCreate(); QTRY_VERIFY(object->property("done").toBool()); @@ -1357,7 +1411,6 @@ void tst_qqmlxmlhttprequest::redirects() QScopedPointer<QObject> object(component.beginCreate(engine.get()->rootContext())); QVERIFY(!object.isNull()); object->setProperty("url", server.urlString("/redirect.html")); - object->setProperty("expectedText", ""); component.completeCreate(); for (int ii = 0; ii < 60; ++ii) { @@ -1489,6 +1542,26 @@ void tst_qqmlxmlhttprequest::stateChangeCallingContext() QTRY_VERIFY(object->property("success").toBool()); } +void tst_qqmlxmlhttprequest::overrideMime() +{ + // overrideMimeType.reply sets the Content-Type to text/plain + // overrideMimeType.qml overrides it to text/xml and checks the responseXML property. + + TestHTTPServer server; + QVERIFY2(server.listen(), qPrintable(server.errorString())); + QVERIFY(server.wait(testFileUrl("text.expect"), + testFileUrl("overrideMimeType.reply"), + testFileUrl("text.xml"))); + + QQmlComponent component(engine.get(), testFileUrl("overrideMimeType.qml")); + QScopedPointer<QObject> object(component.beginCreate(engine.get()->rootContext())); + QVERIFY(!object.isNull()); + object->setProperty("url", server.urlString("/text.xml")); + component.completeCreate(); + + QTRY_VERIFY(object->property("dataOK").toBool()); +} + QTEST_MAIN(tst_qqmlxmlhttprequest) #include "tst_qqmlxmlhttprequest.moc" |