diff options
Diffstat (limited to 'tests/auto/qml')
23 files changed, 129 insertions, 102 deletions
diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp index 3e681b1b84..1e02eb8376 100644 --- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp +++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp @@ -44,8 +44,6 @@ #include "../../shared/util.h" #include "testhttpserver.h" -#define SERVER_PORT 14450 - class MyIC : public QObject, public QQmlIncubationController { Q_OBJECT @@ -260,12 +258,12 @@ void tst_qqmlcomponent::qmlCreateParentReference() void tst_qqmlcomponent::async() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); QQmlComponent component(&engine); ComponentWatcher watcher(&component); - component.loadUrl(QUrl("http://127.0.0.1:14450/TestComponent.qml"), QQmlComponent::Asynchronous); + component.loadUrl(server.url("/TestComponent.qml"), QQmlComponent::Asynchronous); QCOMPARE(watcher.loading, 1); QTRY_VERIFY(component.isReady()); QCOMPARE(watcher.ready, 1); @@ -280,13 +278,13 @@ void tst_qqmlcomponent::async() void tst_qqmlcomponent::asyncHierarchy() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); // ensure that the item hierarchy is compiled correctly. QQmlComponent component(&engine); ComponentWatcher watcher(&component); - component.loadUrl(QUrl("http://127.0.0.1:14450/TestComponent.2.qml"), QQmlComponent::Asynchronous); + component.loadUrl(server.url("/TestComponent.2.qml"), QQmlComponent::Asynchronous); QCOMPARE(watcher.loading, 1); QTRY_VERIFY(component.isReady()); QCOMPARE(watcher.ready, 1); diff --git a/tests/auto/qml/qqmlecmascript/data/include_remote.js b/tests/auto/qml/qqmlecmascript/data/include_remote.js index 4331cb79d0..4b5e153736 100644 --- a/tests/auto/qml/qqmlecmascript/data/include_remote.js +++ b/tests/auto/qml/qqmlecmascript/data/include_remote.js @@ -1,8 +1,8 @@ var myvar = 10; -function go() +function go(serverBaseUrl) { - var a = Qt.include("http://127.0.0.1:8111/remote_file.js", + var a = Qt.include(serverBaseUrl + "/remote_file.js", function(o) { test2 = o.status == o.OK test3 = a.status == a.OK @@ -13,7 +13,7 @@ function go() test1 = a.status == a.LOADING - var b = Qt.include("http://127.0.0.1:8111/exception.js", + var b = Qt.include(serverBaseUrl + "/exception.js", function(o) { test7 = o.status == o.EXCEPTION test8 = b.status == a.EXCEPTION diff --git a/tests/auto/qml/qqmlecmascript/data/include_remote.qml b/tests/auto/qml/qqmlecmascript/data/include_remote.qml index fe020a55df..7742b621a9 100644 --- a/tests/auto/qml/qqmlecmascript/data/include_remote.qml +++ b/tests/auto/qml/qqmlecmascript/data/include_remote.qml @@ -17,5 +17,7 @@ QtObject { property bool test9: false property bool test10: false - Component.onCompleted: IncludeTest.go(); + property string serverBaseUrl; + + Component.onCompleted: IncludeTest.go(serverBaseUrl); } diff --git a/tests/auto/qml/qqmlecmascript/data/include_remote_missing.js b/tests/auto/qml/qqmlecmascript/data/include_remote_missing.js index 27dd63badf..5ebc1aadf0 100644 --- a/tests/auto/qml/qqmlecmascript/data/include_remote_missing.js +++ b/tests/auto/qml/qqmlecmascript/data/include_remote_missing.js @@ -1,6 +1,6 @@ -function go() +function go(serverBaseUrl) { - var a = Qt.include("http://127.0.0.1:8111/missing.js", + var a = Qt.include(serverBaseUrl + "/missing.js", function(o) { test2 = o.status == o.NETWORK_ERROR test3 = a.status == a.NETWORK_ERROR diff --git a/tests/auto/qml/qqmlecmascript/data/include_remote_missing.qml b/tests/auto/qml/qqmlecmascript/data/include_remote_missing.qml index e8ef609fed..eb75bd676f 100644 --- a/tests/auto/qml/qqmlecmascript/data/include_remote_missing.qml +++ b/tests/auto/qml/qqmlecmascript/data/include_remote_missing.qml @@ -8,5 +8,7 @@ QtObject { property bool test2: false property bool test3: false - Component.onCompleted: IncludeTest.go(); + property string serverBaseUrl; + + Component.onCompleted: IncludeTest.go(serverBaseUrl); } diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 38a2affe3a..839f71b8f8 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -4204,12 +4204,12 @@ void tst_qqmlecmascript::importScripts() QFETCH(QVariantList, propertyValues); TestHTTPServer server; - QVERIFY2(server.listen(8111), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory() + "/remote"); QStringList importPathList = engine.importPathList(); - QString remotePath(QLatin1String("http://127.0.0.1:8111/")); + QString remotePath(server.urlString("/")); engine.addImportPath(remotePath); QQmlComponent component(&engine, testfile); @@ -6055,12 +6055,14 @@ void tst_qqmlecmascript::include() // Remote - error { TestHTTPServer server; - QVERIFY2(server.listen(8111), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); QQmlComponent component(&engine, testFileUrl("include_remote_missing.qml")); - QObject *o = component.create(); + QObject *o = component.beginCreate(engine.rootContext()); QVERIFY(o != 0); + o->setProperty("serverBaseUrl", server.baseUrl().toString()); + component.completeCreate(); QTRY_VERIFY(o->property("done").toBool() == true); @@ -6097,12 +6099,14 @@ void tst_qqmlecmascript::includeRemoteSuccess() // Remote - success TestHTTPServer server; - QVERIFY2(server.listen(8111), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); QQmlComponent component(&engine, testFileUrl("include_remote.qml")); - QObject *o = component.create(); + QObject *o = component.beginCreate(engine.rootContext()); QVERIFY(o != 0); + o->setProperty("serverBaseUrl", server.baseUrl().toString()); + component.completeCreate(); QTRY_VERIFY(o->property("done").toBool() == true); QTRY_VERIFY(o->property("done2").toBool() == true); diff --git a/tests/auto/qml/qqmllanguage/data/singletonTest15.qml b/tests/auto/qml/qqmllanguage/data/singletonTest15.qml index 183d52d259..955abab6ba 100644 --- a/tests/auto/qml/qqmllanguage/data/singletonTest15.qml +++ b/tests/auto/qml/qqmllanguage/data/singletonTest15.qml @@ -1,5 +1,5 @@ import QtQuick 2.0 -import "http://127.0.0.1:14447/singleton/remote" +import "{{ServerBaseUrl}}/singleton/remote" Item { property int value1: RemoteSingletonType2.testProp1; diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 12d2f53596..88c3a54bed 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -2511,7 +2511,7 @@ void tst_qqmllanguage::basicRemote_data() QTest::addColumn<QString>("type"); QTest::addColumn<QString>("error"); - QString serverdir = "http://127.0.0.1:14447/qtest/qml/qqmllanguage/"; + QString serverdir = "/qtest/qml/qqmllanguage/"; QTest::newRow("no need for qmldir") << QUrl(serverdir+"Test.qml") << "" << ""; QTest::newRow("absent qmldir") << QUrl(serverdir+"/noqmldir/Test.qml") << "" << ""; @@ -2525,9 +2525,11 @@ void tst_qqmllanguage::basicRemote() QFETCH(QString, error); TestHTTPServer server; - QVERIFY2(server.listen(14447), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); + url = server.baseUrl().resolved(url); + QQmlComponent component(&engine, url); QTRY_VERIFY(!component.isLoading()); @@ -2547,7 +2549,7 @@ void tst_qqmllanguage::importsRemote_data() QTest::addColumn<QString>("type"); QTest::addColumn<QString>("error"); - QString serverdir = "http://127.0.0.1:14447/qtest/qml/qqmllanguage"; + QString serverdir = "{{ServerBaseUrl}}/qtest/qml/qqmllanguage"; QTest::newRow("remote import") << "import \""+serverdir+"\"\nTest {}" << "QQuickRectangle" << ""; @@ -2570,9 +2572,11 @@ void tst_qqmllanguage::importsRemote() QFETCH(QString, error); TestHTTPServer server; - QVERIFY2(server.listen(14447), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); + qml.replace(QStringLiteral("{{ServerBaseUrl}}"), server.baseUrl().toString()); + testType(qml,type,error); } @@ -2663,10 +2667,10 @@ void tst_qqmllanguage::importsInstalledRemote() QFETCH(QString, error); TestHTTPServer server; - QVERIFY2(server.listen(14447), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); - QString serverdir = "http://127.0.0.1:14447/lib/"; + QString serverdir = server.urlString("/lib/"); engine.setImportPathList(QStringList(defaultImportPathList) << serverdir); testType(qml,type,error); @@ -2681,43 +2685,43 @@ void tst_qqmllanguage::importsPath_data() QTest::addColumn<QString>("value"); QTest::newRow("local takes priority normal") - << (QStringList() << testFile("lib") << "http://127.0.0.1:14447/lib2/") + << (QStringList() << testFile("lib") << "{{ServerBaseUrl}}/lib2/") << "import testModule 1.0\n" "Test {}" << "foo"; QTest::newRow("local takes priority reversed") - << (QStringList() << "http://127.0.0.1:14447/lib/" << testFile("lib2")) + << (QStringList() << "{{ServerBaseUrl}}/lib/" << testFile("lib2")) << "import testModule 1.0\n" "Test {}" << "bar"; QTest::newRow("earlier takes priority 1") - << (QStringList() << "http://127.0.0.1:14447/lib/" << "http://127.0.0.1:14447/lib2/") + << (QStringList() << "{{ServerBaseUrl}}/lib/" << "{{ServerBaseUrl}}/lib2/") << "import testModule 1.0\n" "Test {}" << "foo"; QTest::newRow("earlier takes priority 2") - << (QStringList() << "http://127.0.0.1:14447/lib2/" << "http://127.0.0.1:14447/lib/") + << (QStringList() << "{{ServerBaseUrl}}/lib2/" << "{{ServerBaseUrl}}/lib/") << "import testModule 1.0\n" "Test {}" << "bar"; QTest::newRow("major version takes priority over unversioned") - << (QStringList() << "http://127.0.0.1:14447/lib/" << "http://127.0.0.1:14447/lib3/") + << (QStringList() << "{{ServerBaseUrl}}/lib/" << "{{ServerBaseUrl}}/lib3/") << "import testModule 1.0\n" "Test {}" << "baz"; QTest::newRow("major version takes priority over minor") - << (QStringList() << "http://127.0.0.1:14447/lib4/" << "http://127.0.0.1:14447/lib3/") + << (QStringList() << "{{ServerBaseUrl}}/lib4/" << "{{ServerBaseUrl}}/lib3/") << "import testModule 1.0\n" "Test {}" << "baz"; QTest::newRow("minor version takes priority over unversioned") - << (QStringList() << "http://127.0.0.1:14447/lib/" << "http://127.0.0.1:14447/lib4/") + << (QStringList() << "{{ServerBaseUrl}}/lib/" << "{{ServerBaseUrl}}/lib4/") << "import testModule 1.0\n" "Test {}" << "qux"; @@ -2730,9 +2734,12 @@ void tst_qqmllanguage::importsPath() QFETCH(QString, value); TestHTTPServer server; - QVERIFY2(server.listen(14447), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); + for (int i = 0; i < importPath.count(); ++i) + importPath[i].replace(QStringLiteral("{{ServerBaseUrl}}"), server.baseUrl().toString()); + engine.setImportPathList(QStringList(defaultImportPathList) << importPath); QQmlComponent component(&engine); @@ -3325,11 +3332,11 @@ void tst_qqmllanguage::registeredCompositeType() void tst_qqmllanguage::remoteLoadCrash() { TestHTTPServer server; - QVERIFY2(server.listen(14448), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); QQmlComponent component(&engine); - component.setData("import QtQuick 2.0; Text {}", QUrl("http://127.0.0.1:14448/remoteLoadCrash.qml")); + component.setData("import QtQuick 2.0; Text {}", server.url("/remoteLoadCrash.qml")); while (component.isLoading()) QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents, 50); @@ -3816,10 +3823,18 @@ void tst_qqmllanguage::compositeSingletonQmlDirError() void tst_qqmllanguage::compositeSingletonRemote() { TestHTTPServer server; - QVERIFY2(server.listen(14447), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); - QQmlComponent component(&engine, testFile("singletonTest15.qml")); + QFile f(testFile("singletonTest15.qml")); + QVERIFY(f.open(QIODevice::ReadOnly)); + QByteArray contents = f.readAll(); + f.close(); + + contents.replace(QByteArrayLiteral("{{ServerBaseUrl}}"), server.baseUrl().toString().toUtf8()); + + QQmlComponent component(&engine); + component.setData(contents, testFileUrl("singletonTest15.qml")); while (component.isLoading()) QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents, 50); diff --git a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp index 0a8090ab07..521ed335b2 100644 --- a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp +++ b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp @@ -44,9 +44,6 @@ #include "../../shared/testhttpserver.h" #include "../../shared/util.h" -#define SERVER_ADDR "http://127.0.0.1:14456" -#define SERVER_PORT 14456 - // Note: this test does not use module identifier directives in the qmldir files, because // it would result in repeated attempts to insert types into the same namespace. // This occurs because type registration is process-global, while the test @@ -240,12 +237,13 @@ void tst_qqmlmoduleplugin::importPluginWithQmlFile() void tst_qqmlmoduleplugin::remoteImportWithQuotedUrl() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(m_dataImportsDirectory); QQmlEngine engine; QQmlComponent component(&engine); - component.setData("import \"" SERVER_ADDR "/org/qtproject/PureQmlModule\" \nComponentA { width: 300; ComponentB{} }", QUrl()); + const QString qml = "import \"" + server.urlString("/org/qtproject/PureQmlModule") + "\" \nComponentA { width: 300; ComponentB{} }"; + component.setData(qml.toUtf8(), QUrl()); QTRY_COMPARE(component.status(), QQmlComponent::Ready); QObject *object = component.create(); @@ -261,7 +259,7 @@ void tst_qqmlmoduleplugin::remoteImportWithQuotedUrl() void tst_qqmlmoduleplugin::remoteImportWithUnquotedUri() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(m_dataImportsDirectory); QQmlEngine engine; diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/TestComponent.qml b/tests/auto/qml/qqmlxmlhttprequest/data/TestComponent.qml index c4ecbd8912..a631daf9e3 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/TestComponent.qml +++ b/tests/auto/qml/qqmlxmlhttprequest/data/TestComponent.qml @@ -17,7 +17,7 @@ Item { var o = Qt.createQmlObject(seqComponent,root); } } - doc.open("GET", "http://127.0.0.1:14445/TestComponent3.qml"); + doc.open("GET", serverBaseUrl + "/TestComponent3.qml"); doc.send(); } } diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/abort.expect b/tests/auto/qml/qqmlxmlhttprequest/data/abort.expect index d6951a8255..7e1edeb2a3 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/abort.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/abort.expect @@ -5,6 +5,6 @@ Content-Length: 9 Connection: Keep-Alive Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 -Host: 127.0.0.1:14445 +Host: {{ServerHostUrl}} Test Data
\ No newline at end of file diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/getResponseHeader.expect b/tests/auto/qml/qqmlxmlhttprequest/data/getResponseHeader.expect index cf5830ed0c..bc40e5ea0f 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/getResponseHeader.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/getResponseHeader.expect @@ -3,5 +3,5 @@ Accept-Language: en-US Connection: Keep-Alive Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 -Host: 127.0.0.1:14445 +Host: {{ServerHostUrl}} diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/open_network.expect b/tests/auto/qml/qqmlxmlhttprequest/data/open_network.expect index cf5830ed0c..bc40e5ea0f 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/open_network.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/open_network.expect @@ -3,5 +3,5 @@ Accept-Language: en-US Connection: Keep-Alive Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 -Host: 127.0.0.1:14445 +Host: {{ServerHostUrl}} diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.1.expect b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.1.expect index 9c07d4b633..144f0f6e98 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.1.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.1.expect @@ -5,6 +5,6 @@ Content-Length: 12 Connection: Keep-Alive Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 -Host: 127.0.0.1:14445 +Host: {{ServerHostUrl}} My Sent Data
\ No newline at end of file diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.4.expect b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.4.expect index c2aba77881..b53764fd97 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.4.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.4.expect @@ -5,6 +5,6 @@ Content-Length: 12 Connection: Keep-Alive Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 -Host: 127.0.0.1:14445 +Host: {{ServerHostUrl}} My Sent Data
\ No newline at end of file diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.6.expect b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.6.expect index b09b1bcec5..5f365b42af 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.6.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.6.expect @@ -5,6 +5,6 @@ Content-Length: 12 Connection: Keep-Alive Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 -Host: 127.0.0.1:14445 +Host: {{ServerHostUrl}} My Sent Data
\ No newline at end of file diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/send_ignoreData_DELETE.expect b/tests/auto/qml/qqmlxmlhttprequest/data/send_ignoreData_DELETE.expect index dd86b837f4..672dc60021 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/send_ignoreData_DELETE.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/send_ignoreData_DELETE.expect @@ -3,5 +3,5 @@ Accept-Language: en-US Connection: Keep-Alive Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 -Host: 127.0.0.1:14445 +Host: {{ServerHostUrl}} diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/send_ignoreData_GET.expect b/tests/auto/qml/qqmlxmlhttprequest/data/send_ignoreData_GET.expect index cf5830ed0c..bc40e5ea0f 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/send_ignoreData_GET.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/send_ignoreData_GET.expect @@ -3,5 +3,5 @@ Accept-Language: en-US Connection: Keep-Alive Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 -Host: 127.0.0.1:14445 +Host: {{ServerHostUrl}} diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/send_ignoreData_HEAD.expect b/tests/auto/qml/qqmlxmlhttprequest/data/send_ignoreData_HEAD.expect index 7b7b282660..2a642e4292 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/send_ignoreData_HEAD.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/send_ignoreData_HEAD.expect @@ -3,5 +3,5 @@ Accept-Language: en-US Connection: Keep-Alive Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 -Host: 127.0.0.1:14445 +Host: {{ServerHostUrl}} diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/setRequestHeader.expect b/tests/auto/qml/qqmlxmlhttprequest/data/setRequestHeader.expect index e7f8e10780..94b3016490 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/setRequestHeader.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/setRequestHeader.expect @@ -5,5 +5,5 @@ Test-header2: value,value2 Connection: Keep-Alive Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 -Host: 127.0.0.1:14445 +Host: {{ServerHostUrl}} diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/stateChangeCallingContext.qml b/tests/auto/qml/qqmlxmlhttprequest/data/stateChangeCallingContext.qml index b35c31d513..97feeb9324 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/stateChangeCallingContext.qml +++ b/tests/auto/qml/qqmlxmlhttprequest/data/stateChangeCallingContext.qml @@ -5,6 +5,7 @@ Item { property int whichCount: 0 property bool success: false + property string serverBaseUrl; SequentialAnimation { id: anim @@ -23,7 +24,7 @@ Item { function updateList() { var xhr = new XMLHttpRequest(); - xhr.open("GET","http://127.0.0.1:14445/testlist"); // list of components + xhr.open("GET",serverBaseUrl + "/testlist"); // list of components xhr.onreadystatechange = function () { if (xhr.readyState == XMLHttpRequest.DONE) { var components = xhr.responseText.split('\n'); diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/status.expect b/tests/auto/qml/qqmlxmlhttprequest/data/status.expect index cf5830ed0c..bc40e5ea0f 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/status.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/status.expect @@ -3,5 +3,5 @@ Accept-Language: en-US Connection: Keep-Alive Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 -Host: 127.0.0.1:14445 +Host: {{ServerHostUrl}} diff --git a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp index 9267c187bb..90cf8f5ec1 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp +++ b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp @@ -37,11 +37,12 @@ #include <QDebug> #include <QScopedPointer> #include <QNetworkCookieJar> +#include <QThread> +#include <QMutex> +#include <QWaitCondition> #include "testhttpserver.h" #include "../../shared/util.h" -#define SERVER_PORT 14445 - class tst_qqmlxmlhttprequest : public QQmlDataTest { Q_OBJECT @@ -234,10 +235,11 @@ void tst_qqmlxmlhttprequest::open() TestHTTPServer server; if (remote) { - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("open_network.expect"), testFileUrl("open_network.reply"), testFileUrl("testdocument.html"))); + url = server.urlString(url); } QQmlComponent component(&engine, qmlFile); @@ -264,10 +266,10 @@ void tst_qqmlxmlhttprequest::open_data() QTest::newRow("Relative url)") << testFileUrl("open.qml") << "testdocument.html" << false; QTest::newRow("Absolute url)") << testFileUrl("open.qml") << testFileUrl("testdocument.html").toString() << false; - QTest::newRow("Absolute network url)") << testFileUrl("open.qml") << "http://127.0.0.1:14445/testdocument.html" << true; + QTest::newRow("Absolute network url)") << testFileUrl("open.qml") << "/testdocument.html" << true; // ### Check that the username/password were sent to the server - QTest::newRow("User/pass") << testFileUrl("open_user.qml") << "http://127.0.0.1:14445/testdocument.html" << true; + QTest::newRow("User/pass") << testFileUrl("open_user.qml") << "/testdocument.html" << true; } // Test that calling XMLHttpRequest.open() with an invalid method raises an exception @@ -314,7 +316,7 @@ void tst_qqmlxmlhttprequest::open_arg_count() void tst_qqmlxmlhttprequest::setRequestHeader() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("setRequestHeader.expect"), testFileUrl("setRequestHeader.reply"), testFileUrl("testdocument.html"))); @@ -322,7 +324,7 @@ void tst_qqmlxmlhttprequest::setRequestHeader() QQmlComponent component(&engine, testFileUrl("setRequestHeader.qml")); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("url", server.urlString("/testdocument.html")); component.completeCreate(); QTRY_VERIFY(object->property("dataOK").toBool() == true); @@ -332,7 +334,7 @@ void tst_qqmlxmlhttprequest::setRequestHeader() void tst_qqmlxmlhttprequest::setRequestHeader_caseInsensitive() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("setRequestHeader.expect"), testFileUrl("setRequestHeader.reply"), testFileUrl("testdocument.html"))); @@ -340,7 +342,7 @@ void tst_qqmlxmlhttprequest::setRequestHeader_caseInsensitive() QQmlComponent component(&engine, testFileUrl("setRequestHeader_caseInsensitive.qml")); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("url", server.urlString("/testdocument.html")); component.completeCreate(); QTRY_VERIFY(object->property("dataOK").toBool() == true); @@ -389,7 +391,7 @@ void tst_qqmlxmlhttprequest::setRequestHeader_illegalName() QFETCH(QString, name); TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("open_network.expect"), testFileUrl("open_network.reply"), testFileUrl("testdocument.html"))); @@ -397,7 +399,7 @@ void tst_qqmlxmlhttprequest::setRequestHeader_illegalName() QQmlComponent component(&engine, testFileUrl("setRequestHeader_illegalName.qml")); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("url", server.urlString("/testdocument.html")); object->setProperty("header", name); component.completeCreate(); @@ -415,7 +417,7 @@ void tst_qqmlxmlhttprequest::setRequestHeader_illegalName() void tst_qqmlxmlhttprequest::setRequestHeader_sent() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("open_network.expect"), testFileUrl("open_network.reply"), testFileUrl("testdocument.html"))); @@ -423,7 +425,7 @@ void tst_qqmlxmlhttprequest::setRequestHeader_sent() QQmlComponent component(&engine, testFileUrl("setRequestHeader_sent.qml")); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("url", server.urlString("/testdocument.html")); component.completeCreate(); QCOMPARE(object->property("test").toBool(), true); @@ -467,7 +469,7 @@ void tst_qqmlxmlhttprequest::send_ignoreData() { { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("send_ignoreData_GET.expect"), testFileUrl("send_ignoreData.reply"), testFileUrl("testdocument.html"))); @@ -476,7 +478,7 @@ void tst_qqmlxmlhttprequest::send_ignoreData() QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); object->setProperty("reqType", "GET"); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("url", server.urlString("/testdocument.html")); component.completeCreate(); QTRY_VERIFY(object->property("dataOK").toBool() == true); @@ -484,7 +486,7 @@ void tst_qqmlxmlhttprequest::send_ignoreData() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("send_ignoreData_HEAD.expect"), testFileUrl("send_ignoreData.reply"), QUrl())); @@ -493,7 +495,7 @@ void tst_qqmlxmlhttprequest::send_ignoreData() QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); object->setProperty("reqType", "HEAD"); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("url", server.urlString("/testdocument.html")); component.completeCreate(); QTRY_VERIFY(object->property("dataOK").toBool() == true); @@ -501,7 +503,7 @@ void tst_qqmlxmlhttprequest::send_ignoreData() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("send_ignoreData_DELETE.expect"), testFileUrl("send_ignoreData.reply"), QUrl())); @@ -510,7 +512,7 @@ void tst_qqmlxmlhttprequest::send_ignoreData() QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); object->setProperty("reqType", "DELETE"); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("url", server.urlString("/testdocument.html")); component.completeCreate(); QTRY_VERIFY(object->property("dataOK").toBool() == true); @@ -524,7 +526,7 @@ void tst_qqmlxmlhttprequest::send_withdata() QFETCH(QString, file_qml); TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl(file_expected), testFileUrl("send_data.reply"), testFileUrl("testdocument.html"))); @@ -532,7 +534,7 @@ void tst_qqmlxmlhttprequest::send_withdata() QQmlComponent component(&engine, testFileUrl(file_qml)); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("url", server.urlString("/testdocument.html")); component.completeCreate(); QTRY_VERIFY(object->property("dataOK").toBool() == true); @@ -594,7 +596,7 @@ void tst_qqmlxmlhttprequest::abort_opened() void tst_qqmlxmlhttprequest::abort() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("abort.expect"), testFileUrl("abort.reply"), testFileUrl("testdocument.html"))); @@ -602,8 +604,11 @@ void tst_qqmlxmlhttprequest::abort() QQmlComponent component(&engine, testFileUrl("abort.qml")); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("urlDummy", "http://127.0.0.1:14449/testdocument.html"); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + const QUrl url = server.url("/testdocument.html"); + QUrl dummyUrl = url; + dummyUrl.setPort(dummyUrl.port() - 1); + object->setProperty("urlDummy", dummyUrl.toString()); + object->setProperty("url", url.toString()); component.completeCreate(); QCOMPARE(object->property("seenDone").toBool(), true); @@ -618,7 +623,7 @@ void tst_qqmlxmlhttprequest::getResponseHeader() QQmlEngine engine; // Avoid cookie contamination TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("getResponseHeader.expect"), testFileUrl("getResponseHeader.reply"), testFileUrl("testdocument.html"))); @@ -627,7 +632,7 @@ void tst_qqmlxmlhttprequest::getResponseHeader() QQmlComponent component(&engine, testFileUrl("getResponseHeader.qml")); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("url", server.urlString("/testdocument.html")); component.completeCreate(); QCOMPARE(object->property("unsentException").toBool(), true); @@ -685,7 +690,7 @@ void tst_qqmlxmlhttprequest::getAllResponseHeaders() QQmlEngine engine; // Avoid cookie contamination TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("getResponseHeader.expect"), testFileUrl("getResponseHeader.reply"), testFileUrl("testdocument.html"))); @@ -693,7 +698,7 @@ void tst_qqmlxmlhttprequest::getAllResponseHeaders() QQmlComponent component(&engine, testFileUrl("getAllResponseHeaders.qml")); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("url", server.urlString("/testdocument.html")); component.completeCreate(); QCOMPARE(object->property("unsentException").toBool(), true); @@ -746,7 +751,7 @@ void tst_qqmlxmlhttprequest::status() QFETCH(int, status); TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("status.expect"), replyUrl, testFileUrl("testdocument.html"))); @@ -754,7 +759,7 @@ void tst_qqmlxmlhttprequest::status() QQmlComponent component(&engine, testFileUrl("status.qml")); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("url", server.urlString("/testdocument.html")); object->setProperty("expectedStatus", status); component.completeCreate(); @@ -785,7 +790,7 @@ void tst_qqmlxmlhttprequest::statusText() QFETCH(QString, statusText); TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("status.expect"), replyUrl, testFileUrl("testdocument.html"))); @@ -793,7 +798,7 @@ void tst_qqmlxmlhttprequest::statusText() QQmlComponent component(&engine, testFileUrl("statusText.qml")); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("url", server.urlString("/testdocument.html")); object->setProperty("expectedStatus", statusText); component.completeCreate(); @@ -825,7 +830,7 @@ void tst_qqmlxmlhttprequest::responseText() QFETCH(QString, responseText); TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("status.expect"), replyUrl, bodyUrl)); @@ -833,7 +838,7 @@ void tst_qqmlxmlhttprequest::responseText() QQmlComponent component(&engine, testFileUrl("responseText.qml")); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + object->setProperty("url", server.urlString("/testdocument.html")); object->setProperty("expectedText", responseText); component.completeCreate(); @@ -926,14 +931,14 @@ void tst_qqmlxmlhttprequest::redirects() { { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); - server.addRedirect("redirect.html", "http://127.0.0.1:14445/redirecttarget.html"); + QVERIFY2(server.listen(), qPrintable(server.errorString())); + server.addRedirect("redirect.html", server.urlString("/redirecttarget.html")); server.serveDirectory(dataDirectory()); QQmlComponent component(&engine, testFileUrl("redirects.qml")); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("url", "http://127.0.0.1:14445/redirect.html"); + object->setProperty("url", server.urlString("/redirect.html")); object->setProperty("expectedText", ""); component.completeCreate(); @@ -943,14 +948,14 @@ void tst_qqmlxmlhttprequest::redirects() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); - server.addRedirect("redirect.html", "http://127.0.0.1:14445/redirectmissing.html"); + QVERIFY2(server.listen(), qPrintable(server.errorString())); + server.addRedirect("redirect.html", server.urlString("/redirectmissing.html")); server.serveDirectory(dataDirectory()); QQmlComponent component(&engine, testFileUrl("redirectError.qml")); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("url", "http://127.0.0.1:14445/redirect.html"); + object->setProperty("url", server.urlString("/redirect.html")); object->setProperty("expectedText", ""); component.completeCreate(); @@ -960,14 +965,14 @@ void tst_qqmlxmlhttprequest::redirects() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); - server.addRedirect("redirect.html", "http://127.0.0.1:14445/redirect.html"); + QVERIFY2(server.listen(), qPrintable(server.errorString())); + server.addRedirect("redirect.html", server.urlString("/redirect.html")); server.serveDirectory(dataDirectory()); QQmlComponent component(&engine, testFileUrl("redirectRecur.qml")); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("url", "http://127.0.0.1:14445/redirect.html"); + object->setProperty("url", server.urlString("/redirect.html")); object->setProperty("expectedText", ""); component.completeCreate(); @@ -1062,12 +1067,14 @@ void tst_qqmlxmlhttprequest::stateChangeCallingContext() // without a valid calling context. TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory(), TestHTTPServer::Delay); QQmlComponent component(&engine, testFileUrl("stateChangeCallingContext.qml")); - QScopedPointer<QObject> object(component.create()); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); + object->setProperty("serverBaseUrl", server.baseUrl().toString()); + component.completeCreate(); server.sendDelayedItem(); QTRY_VERIFY(object->property("success").toBool() == true); } |