From 79d56651edc05133ebae13bb93733373b10380f9 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 22 Apr 2015 17:15:30 +0200 Subject: Prospective fix for flakey "network" related QML tests Replace hard-coded server ports with dynamically allocated ports. Change-Id: Iab8f9a88343a9f2c49af3cd700c954c13c3bf121 Reviewed-by: Frederik Gladhorn --- tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp | 10 +-- .../auto/qml/qqmlecmascript/data/include_remote.js | 6 +- .../qml/qqmlecmascript/data/include_remote.qml | 4 +- .../qqmlecmascript/data/include_remote_missing.js | 4 +- .../qqmlecmascript/data/include_remote_missing.qml | 4 +- .../auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 16 ++-- .../auto/qml/qqmllanguage/data/singletonTest15.qml | 2 +- tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 51 ++++++++---- .../qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp | 10 +-- .../qml/qqmlxmlhttprequest/data/TestComponent.qml | 2 +- .../auto/qml/qqmlxmlhttprequest/data/abort.expect | 2 +- .../data/getResponseHeader.expect | 2 +- .../qqmlxmlhttprequest/data/open_network.expect | 2 +- .../qml/qqmlxmlhttprequest/data/send_data.1.expect | 2 +- .../qml/qqmlxmlhttprequest/data/send_data.4.expect | 2 +- .../qml/qqmlxmlhttprequest/data/send_data.6.expect | 2 +- .../data/send_ignoreData_DELETE.expect | 2 +- .../data/send_ignoreData_GET.expect | 2 +- .../data/send_ignoreData_HEAD.expect | 2 +- .../data/setRequestHeader.expect | 2 +- .../data/stateChangeCallingContext.qml | 3 +- .../auto/qml/qqmlxmlhttprequest/data/status.expect | 2 +- .../qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp | 97 ++++++++++++---------- .../tst_qquickanimatedimage.cpp | 22 ++--- .../qquickborderimage/data/colors-round-remote.sci | 2 +- .../qquickborderimage/tst_qquickborderimage.cpp | 54 ++++++------ .../qquickfontloader/tst_qquickfontloader.cpp | 18 ++-- tests/auto/quick/qquickimage/data/qtbug_22125.qml | 18 ++-- tests/auto/quick/qquickimage/tst_qquickimage.cpp | 59 ++++++------- .../qquickloader/data/initialPropertyValues.8.qml | 3 +- tests/auto/quick/qquickloader/tst_qquickloader.cpp | 42 ++++++---- .../qquickpixmapcache/tst_qquickpixmapcache.cpp | 40 ++++----- .../quick/qquicktext/data/embeddedImagesRemote.qml | 2 +- .../qquicktext/data/embeddedImagesRemoteError.qml | 2 +- .../data/embeddedImagesRemoteRelative.qml | 2 +- tests/auto/quick/qquicktext/tst_qquicktext.cpp | 35 +++++--- .../qquicktextedit/data/embeddedImagesRemote.qml | 3 +- .../data/embeddedImagesRemoteError.qml | 3 +- .../data/embeddedImagesRemoteRelative.qml | 3 +- .../quick/qquicktextedit/tst_qquicktextedit.cpp | 37 +++++---- .../quick/qquicktextinput/tst_qquicktextinput.cpp | 7 +- tests/auto/shared/testhttpserver.cpp | 39 ++++++++- tests/auto/shared/testhttpserver.h | 8 +- 43 files changed, 363 insertions(+), 267 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("type"); QTest::addColumn("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("type"); QTest::addColumn("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("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 #include #include +#include +#include +#include #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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 object(component.create()); + QScopedPointer 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); } diff --git a/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp b/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp index c378430d47..3bce95a46d 100644 --- a/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp +++ b/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp @@ -252,11 +252,11 @@ void tst_qquickanimatedimage::remote() QFETCH(bool, paused); TestHTTPServer server; - QVERIFY2(server.listen(14449), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); QQmlEngine engine; - QQmlComponent component(&engine, QUrl("http://127.0.0.1:14449/" + fileName)); + QQmlComponent component(&engine, server.url(fileName)); QTRY_VERIFY(component.isReady()); QQuickAnimatedImage *anim = qobject_cast(component.create()); @@ -317,7 +317,7 @@ void tst_qquickanimatedimage::invalidSource() void tst_qquickanimatedimage::sourceSizeChanges() { TestHTTPServer server; - QVERIFY2(server.listen(14449), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); QQmlEngine engine; @@ -357,19 +357,19 @@ void tst_qquickanimatedimage::sourceSizeChanges() QTRY_VERIFY(sourceSizeSpy.count() == 3); // Remote - ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/hearts.gif")); + ctxt->setContextProperty("srcImage", server.url("/hearts.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); QTRY_VERIFY(sourceSizeSpy.count() == 4); - ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/hearts.gif")); + ctxt->setContextProperty("srcImage", server.url("/hearts.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); QTRY_VERIFY(sourceSizeSpy.count() == 4); - ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/hearts_copy.gif")); + ctxt->setContextProperty("srcImage", server.url("/hearts_copy.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); QTRY_VERIFY(sourceSizeSpy.count() == 4); - ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/colors.gif")); + ctxt->setContextProperty("srcImage", server.url("/colors.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); QTRY_VERIFY(sourceSizeSpy.count() == 5); @@ -383,7 +383,7 @@ void tst_qquickanimatedimage::sourceSizeChanges() void tst_qquickanimatedimage::qtbug_16520() { TestHTTPServer server; - QVERIFY2(server.listen(14449), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); QQmlEngine engine; @@ -395,7 +395,7 @@ void tst_qquickanimatedimage::qtbug_16520() QQuickAnimatedImage *anim = root->findChild("anim"); QVERIFY(anim != 0); - anim->setProperty("source", "http://127.0.0.1:14449/stickman.gif"); + anim->setProperty("source", server.urlString("/stickman.gif")); QTRY_VERIFY(anim->opacity() == 0); QTRY_VERIFY(anim->opacity() == 1); @@ -406,7 +406,7 @@ void tst_qquickanimatedimage::qtbug_16520() void tst_qquickanimatedimage::progressAndStatusChanges() { TestHTTPServer server; - QVERIFY2(server.listen(14449), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); QQmlEngine engine; @@ -442,7 +442,7 @@ void tst_qquickanimatedimage::progressAndStatusChanges() QTRY_COMPARE(statusSpy.count(), 1); // Loading remote file - ctxt->setContextProperty("srcImage", "http://127.0.0.1:14449/stickman.gif"); + ctxt->setContextProperty("srcImage", server.url("/stickman.gif")); QTRY_VERIFY(obj->status() == QQuickImage::Loading); QTRY_VERIFY(obj->progress() == 0.0); QTRY_VERIFY(obj->status() == QQuickImage::Ready); diff --git a/tests/auto/quick/qquickborderimage/data/colors-round-remote.sci b/tests/auto/quick/qquickborderimage/data/colors-round-remote.sci index c673bed598..ce28333dfa 100644 --- a/tests/auto/quick/qquickborderimage/data/colors-round-remote.sci +++ b/tests/auto/quick/qquickborderimage/data/colors-round-remote.sci @@ -4,4 +4,4 @@ border.right:30 border.bottom:40 horizontalTileRule:Round verticalTileRule:Repeat -source:http://127.0.0.1:14446/colors.png +source:{{ServerBaseUrl}}/colors.png diff --git a/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp b/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp index ed01dad272..aabc6cf7ed 100644 --- a/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp +++ b/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp @@ -50,9 +50,6 @@ #include "../../shared/testhttpserver.h" #include "../../shared/util.h" -#define SERVER_PORT 14446 -#define SERVER_ADDR "http://127.0.0.1:14446" - Q_DECLARE_METATYPE(QQuickImageBase::Status) class tst_qquickborderimage : public QQmlDataTest @@ -124,9 +121,9 @@ void tst_qquickborderimage::imageSource_data() QTest::newRow("local") << testFileUrl("colors.png").toString() << false << ""; QTest::newRow("local not found") << testFileUrl("no-such-file.png").toString() << false << ":2:1: QML BorderImage: Cannot open: " + testFileUrl("no-such-file.png").toString(); - QTest::newRow("remote") << SERVER_ADDR "/colors.png" << true << ""; - QTest::newRow("remote not found") << SERVER_ADDR "/no-such-file.png" << true - << ":2:1: QML BorderImage: Error downloading " SERVER_ADDR "/no-such-file.png - server replied: Not found"; + QTest::newRow("remote") << "/colors.png" << true << ""; + QTest::newRow("remote not found") << "/no-such-file.png" << true + << ":2:1: QML BorderImage: Error downloading {{ServerBaseUrl}}/no-such-file.png - server replied: Not found"; } void tst_qquickborderimage::imageSource() @@ -137,8 +134,10 @@ void tst_qquickborderimage::imageSource() TestHTTPServer server; if (remote) { - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); + source = server.urlString(source); + error.replace(QStringLiteral("{{ServerBaseUrl}}"), server.baseUrl().toString()); } if (!error.isEmpty()) @@ -280,13 +279,14 @@ void tst_qquickborderimage::sciSource() { QFETCH(QString, source); QFETCH(bool, valid); - - bool remote = source.startsWith("http"); + QFETCH(bool, remote); TestHTTPServer server; if (remote) { - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); + source = server.urlString(source); + server.registerFileNameForContentSubstitution(QUrl(source).path()); } QString componentStr = "import QtQuick 2.0\nBorderImage { source: \"" + source + "\"; width: 300; height: 300 }"; @@ -321,14 +321,15 @@ void tst_qquickborderimage::sciSource_data() { QTest::addColumn("source"); QTest::addColumn("valid"); + QTest::addColumn("remote"); - QTest::newRow("local") << testFileUrl("colors-round.sci").toString() << true; - QTest::newRow("local quoted filename") << testFileUrl("colors-round-quotes.sci").toString() << true; - QTest::newRow("local not found") << testFileUrl("no-such-file.sci").toString() << false; - QTest::newRow("remote") << SERVER_ADDR "/colors-round.sci" << true; - QTest::newRow("remote filename quoted") << SERVER_ADDR "/colors-round-quotes.sci" << true; - QTest::newRow("remote image") << SERVER_ADDR "/colors-round-remote.sci" << true; - QTest::newRow("remote not found") << SERVER_ADDR "/no-such-file.sci" << false; + QTest::newRow("local") << testFileUrl("colors-round.sci").toString() << true << /*remote*/false; + QTest::newRow("local quoted filename") << testFileUrl("colors-round-quotes.sci").toString() << true << /*remote*/false; + QTest::newRow("local not found") << testFileUrl("no-such-file.sci").toString() << false << /*remote*/false; + QTest::newRow("remote") << "/colors-round.sci" << true << /*remote*/true; + QTest::newRow("remote filename quoted") << "/colors-round-quotes.sci" << true << /*remote*/true; + QTest::newRow("remote image") << "/colors-round-remote.sci" << true << /*remote*/true; + QTest::newRow("remote not found") << "/no-such-file.sci" << false << /*remote*/true; } void tst_qquickborderimage::invalidSciFile() @@ -414,7 +415,7 @@ void tst_qquickborderimage::statusChanges_data() QTest::newRow("nofile") << "" << 0 << false << QQuickImageBase::Null; QTest::newRow("nonexistent") << testFileUrl("thisfiledoesnotexist.png").toString() << 1 << false << QQuickImageBase::Error; QTest::newRow("noprotocol") << QString("thisfiledoesnotexisteither.png") << 2 << false << QQuickImageBase::Error; - QTest::newRow("remote") << "http://localhost:14446/colors.png" << 2 << true << QQuickImageBase::Ready; + QTest::newRow("remote") << "/colors.png" << 2 << true << QQuickImageBase::Ready; } void tst_qquickborderimage::statusChanges() @@ -426,8 +427,9 @@ void tst_qquickborderimage::statusChanges() TestHTTPServer server; if (remote) { - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); + source = server.urlString(source); } QString componentStr = "import QtQuick 2.0\nBorderImage { width: 300; height: 300 }"; @@ -450,7 +452,7 @@ void tst_qquickborderimage::statusChanges() void tst_qquickborderimage::sourceSizeChanges() { TestHTTPServer server; - QVERIFY2(server.listen(14449), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); QQmlEngine engine; @@ -490,19 +492,19 @@ void tst_qquickborderimage::sourceSizeChanges() QTRY_COMPARE(sourceSizeSpy.count(), 3); // Remote - ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/heart200.png")); + ctxt->setContextProperty("srcImage", server.url("/heart200.png")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); QTRY_COMPARE(sourceSizeSpy.count(), 4); - ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/heart200.png")); + ctxt->setContextProperty("srcImage", server.url("/heart200.png")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); QTRY_COMPARE(sourceSizeSpy.count(), 4); - ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/heart200_copy.png")); + ctxt->setContextProperty("srcImage", server.url("/heart200_copy.png")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); QTRY_COMPARE(sourceSizeSpy.count(), 4); - ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/colors.png")); + ctxt->setContextProperty("srcImage", server.url("/colors.png")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); QTRY_COMPARE(sourceSizeSpy.count(), 5); @@ -516,7 +518,7 @@ void tst_qquickborderimage::sourceSizeChanges() void tst_qquickborderimage::progressAndStatusChanges() { TestHTTPServer server; - QVERIFY2(server.listen(14449), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); QQmlEngine engine; @@ -552,7 +554,7 @@ void tst_qquickborderimage::progressAndStatusChanges() QTRY_COMPARE(statusSpy.count(), 1); // Loading remote file - ctxt->setContextProperty("srcImage", "http://127.0.0.1:14449/heart200.png"); + ctxt->setContextProperty("srcImage", server.url("/heart200.png")); QTRY_VERIFY(obj->status() == QQuickBorderImage::Loading); QTRY_VERIFY(obj->progress() == 0.0); QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready); diff --git a/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp b/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp index 0445ba9e4a..21693f4804 100644 --- a/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp +++ b/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp @@ -41,9 +41,6 @@ #include #include -#define SERVER_PORT 14457 -#define SERVER_ADDR "http://localhost:14457" - class tst_qquickfontloader : public QQmlDataTest { Q_OBJECT @@ -75,7 +72,7 @@ void tst_qquickfontloader::initTestCase() { QQmlDataTest::initTestCase(); server.serveDirectory(dataDirectory()); - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); } void tst_qquickfontloader::noFont() @@ -135,7 +132,7 @@ void tst_qquickfontloader::failLocalFont() void tst_qquickfontloader::webFont() { - QString componentStr = "import QtQuick 2.0\nFontLoader { source: \"" SERVER_ADDR "/tarzeau_ocr_a.ttf\" }"; + QString componentStr = "import QtQuick 2.0\nFontLoader { source: \"" + server.baseUrl().toString() + "/tarzeau_ocr_a.ttf\" }"; QQmlComponent component(&engine); component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); @@ -151,7 +148,7 @@ void tst_qquickfontloader::redirWebFont() { server.addRedirect("olddir/oldname.ttf","../tarzeau_ocr_a.ttf"); - QString componentStr = "import QtQuick 2.0\nFontLoader { source: \"" SERVER_ADDR "/olddir/oldname.ttf\" }"; + QString componentStr = "import QtQuick 2.0\nFontLoader { source: \"" + server.baseUrl().toString() + "/olddir/oldname.ttf\" }"; QQmlComponent component(&engine); component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); @@ -165,8 +162,9 @@ void tst_qquickfontloader::redirWebFont() void tst_qquickfontloader::failWebFont() { - QString componentStr = "import QtQuick 2.0\nFontLoader { source: \"" SERVER_ADDR "/nonexist.ttf\" }"; - QTest::ignoreMessage(QtWarningMsg, ":2:1: QML FontLoader: Cannot load font: \"" SERVER_ADDR "/nonexist.ttf\""); + QString componentStr = "import QtQuick 2.0\nFontLoader { source: \"" + server.baseUrl().toString() + "/nonexist.ttf\" }"; + const QString expectedError = ":2:1: QML FontLoader: Cannot load font: \"" + server.baseUrl().toString() + "/nonexist.ttf\""; + QTest::ignoreMessage(QtWarningMsg, expectedError.toUtf8()); QQmlComponent component(&engine); component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickFontLoader *fontObject = qobject_cast(component.create()); @@ -196,7 +194,7 @@ void tst_qquickfontloader::changeFont() QCOMPARE(statusSpy.count(), 0); QTRY_COMPARE(fontObject->name(), QString("OCRA")); - ctxt->setContextProperty("font", SERVER_ADDR "/daniel.ttf"); + ctxt->setContextProperty("font", server.urlString("/daniel.ttf")); QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Loading); QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); QCOMPARE(nameSpy.count(), 1); @@ -209,7 +207,7 @@ void tst_qquickfontloader::changeFont() QCOMPARE(statusSpy.count(), 2); QTRY_COMPARE(fontObject->name(), QString("OCRA")); - ctxt->setContextProperty("font", SERVER_ADDR "/daniel.ttf"); + ctxt->setContextProperty("font", server.urlString("/daniel.ttf")); QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); QCOMPARE(nameSpy.count(), 3); QCOMPARE(statusSpy.count(), 2); diff --git a/tests/auto/quick/qquickimage/data/qtbug_22125.qml b/tests/auto/quick/qquickimage/data/qtbug_22125.qml index 9b68c0a125..30c0b1d7fb 100644 --- a/tests/auto/quick/qquickimage/data/qtbug_22125.qml +++ b/tests/auto/quick/qquickimage/data/qtbug_22125.qml @@ -8,7 +8,7 @@ Item { GridView { anchors.fill: parent delegate: Image { - source: imagePath; + source: serverBaseUrl + imagePath; asynchronous: true smooth: true width: 200 @@ -16,28 +16,28 @@ Item { } model: ListModel { ListElement { - imagePath: "http://127.0.0.1:14451/big256.png" + imagePath: "/big256.png" } ListElement { - imagePath: "http://127.0.0.1:14451/big256.png" + imagePath: "/big256.png" } ListElement { - imagePath: "http://127.0.0.1:14451/big256.png" + imagePath: "/big256.png" } ListElement { - imagePath: "http://127.0.0.1:14451/colors.png" + imagePath: "/colors.png" } ListElement { - imagePath: "http://127.0.0.1:14451/colors1.png" + imagePath: "/colors1.png" } ListElement { - imagePath: "http://127.0.0.1:14451/big.jpeg" + imagePath: "/big.jpeg" } ListElement { - imagePath: "http://127.0.0.1:14451/heart.png" + imagePath: "/heart.png" } ListElement { - imagePath: "http://127.0.0.1:14451/green.png" + imagePath: "/green.png" } } } diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp index f69c135b72..0bcc2471f7 100644 --- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp +++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp @@ -55,9 +55,6 @@ #include "../../shared/testhttpserver.h" #include "../shared/visualtestutil.h" -#define SERVER_PORT 14451 -#define SERVER_ADDR "http://127.0.0.1:14451" - using namespace QQuickVisualTestUtil; @@ -150,14 +147,14 @@ void tst_qquickimage::imageSource_data() << false << true << ":2:1: QML Image: Cannot open: " + testFileUrl("no-such-file.png").toString(); QTest::newRow("local async not found") << testFileUrl("no-such-file-1.png").toString() << 0.0 << 0.0 << false << true << true << ":2:1: QML Image: Cannot open: " + testFileUrl("no-such-file-1.png").toString(); - QTest::newRow("remote") << SERVER_ADDR "/colors.png" << 120.0 << 120.0 << true << false << true << ""; - QTest::newRow("remote redirected") << SERVER_ADDR "/oldcolors.png" << 120.0 << 120.0 << true << false << false << ""; + QTest::newRow("remote") << "/colors.png" << 120.0 << 120.0 << true << false << true << ""; + QTest::newRow("remote redirected") << "/oldcolors.png" << 120.0 << 120.0 << true << false << false << ""; if (QImageReader::supportedImageFormats().contains("svg")) - QTest::newRow("remote svg") << SERVER_ADDR "/heart.svg" << 550.0 << 500.0 << true << false << false << ""; + QTest::newRow("remote svg") << "/heart.svg" << 550.0 << 500.0 << true << false << false << ""; if (QImageReader::supportedImageFormats().contains("svgz")) - QTest::newRow("remote svgz") << SERVER_ADDR "/heart.svgz" << 550.0 << 500.0 << true << false << false << ""; - QTest::newRow("remote not found") << SERVER_ADDR "/no-such-file.png" << 0.0 << 0.0 << true - << false << true << ":2:1: QML Image: Error downloading " SERVER_ADDR "/no-such-file.png - server replied: Not found"; + QTest::newRow("remote svgz") << "/heart.svgz" << 550.0 << 500.0 << true << false << false << ""; + QTest::newRow("remote not found") << "/no-such-file.png" << 0.0 << 0.0 << true + << false << true << ":2:1: QML Image: Error downloading {{ServerBaseUrl}}/no-such-file.png - server replied: Not found"; } @@ -173,9 +170,11 @@ void tst_qquickimage::imageSource() TestHTTPServer server; if (remote) { - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); - server.addRedirect("oldcolors.png", SERVER_ADDR "/colors.png"); + server.addRedirect("oldcolors.png", server.urlString("/colors.png")); + source = server.urlString(source); + error.replace(QStringLiteral("{{ServerBaseUrl}}"), server.baseUrl().toString()); } if (!error.isEmpty()) @@ -523,9 +522,9 @@ void tst_qquickimage::noLoading() qRegisterMetaType(); TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); - server.addRedirect("oldcolors.png", SERVER_ADDR "/colors.png"); + server.addRedirect("oldcolors.png", server.urlString("/colors.png")); QString componentStr = "import QtQuick 2.0\nImage { source: srcImage; cache: true }"; QQmlContext *ctxt = engine.rootContext(); @@ -549,7 +548,7 @@ void tst_qquickimage::noLoading() QTRY_COMPARE(statusSpy.count(), 1); // Loading remote file - ctxt->setContextProperty("srcImage", QString(SERVER_ADDR) + "/rect.png"); + ctxt->setContextProperty("srcImage", server.url("/rect.png")); QTRY_VERIFY(obj->status() == QQuickImage::Loading); QTRY_VERIFY(obj->progress() == 0.0); QTRY_VERIFY(obj->status() == QQuickImage::Ready); @@ -560,7 +559,7 @@ void tst_qquickimage::noLoading() // Loading remote file again - should not go through 'Loading' state. ctxt->setContextProperty("srcImage", testFileUrl("green.png")); - ctxt->setContextProperty("srcImage", QString(SERVER_ADDR) + "/rect.png"); + ctxt->setContextProperty("srcImage", server.url("/rect.png")); QTRY_VERIFY(obj->status() == QQuickImage::Ready); QTRY_VERIFY(obj->progress() == 1.0); QTRY_COMPARE(sourceSpy.count(), 4); @@ -666,9 +665,13 @@ void tst_qquickimage::nullPixmapPaint() window->show(); QVERIFY(QTest::qWaitForWindowExposed(window.data())); + TestHTTPServer server; + QVERIFY2(server.listen(), qPrintable(server.errorString())); + server.serveDirectory(dataDirectory(), TestHTTPServer::Delay); + QQuickImage *image = qobject_cast(window->rootObject()); QTRY_VERIFY(image != 0); - image->setSource(SERVER_ADDR + QString("/no-such-file.png")); + image->setSource(server.url("/no-such-file.png")); QQmlTestMessageHandler messageHandler; // used to print "QTransform::translate with NaN called" @@ -680,11 +683,13 @@ void tst_qquickimage::nullPixmapPaint() void tst_qquickimage::imageCrash_QTBUG_22125() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory(), TestHTTPServer::Delay); { - QQuickView view(testFileUrl("qtbug_22125.qml")); + QQuickView view; + view.rootContext()->setContextProperty(QStringLiteral("serverBaseUrl"), server.baseUrl()); + view.setSource(testFileUrl("qtbug_22125.qml")); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); qApp->processEvents(); @@ -749,7 +754,7 @@ void tst_qquickimage::sourceSize() void tst_qquickimage::sourceSizeChanges() { TestHTTPServer server; - QVERIFY2(server.listen(14449), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); QQmlEngine engine; @@ -789,19 +794,19 @@ void tst_qquickimage::sourceSizeChanges() QTRY_COMPARE(sourceSizeSpy.count(), 3); // Remote - ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/heart.png")); + ctxt->setContextProperty("srcImage", server.url("/heart.png")); QTRY_COMPARE(img->status(), QQuickImage::Ready); QTRY_COMPARE(sourceSizeSpy.count(), 4); - ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/heart.png")); + ctxt->setContextProperty("srcImage", server.url("/heart.png")); QTRY_COMPARE(img->status(), QQuickImage::Ready); QTRY_COMPARE(sourceSizeSpy.count(), 4); - ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/heart_copy.png")); + ctxt->setContextProperty("srcImage", server.url("/heart_copy.png")); QTRY_COMPARE(img->status(), QQuickImage::Ready); QTRY_COMPARE(sourceSizeSpy.count(), 4); - ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/colors.png")); + ctxt->setContextProperty("srcImage", server.url("/colors.png")); QTRY_COMPARE(img->status(), QQuickImage::Ready); QTRY_COMPARE(sourceSizeSpy.count(), 5); @@ -815,7 +820,7 @@ void tst_qquickimage::sourceSizeChanges() void tst_qquickimage::progressAndStatusChanges() { TestHTTPServer server; - QVERIFY2(server.listen(14449), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); QQmlEngine engine; @@ -851,7 +856,7 @@ void tst_qquickimage::progressAndStatusChanges() QTRY_COMPARE(statusSpy.count(), 1); // Loading remote file - ctxt->setContextProperty("srcImage", "http://127.0.0.1:14449/heart.png"); + ctxt->setContextProperty("srcImage", server.url("/heart.png")); QTRY_VERIFY(obj->status() == QQuickImage::Loading); QTRY_VERIFY(obj->progress() == 0.0); QTRY_VERIFY(obj->status() == QQuickImage::Ready); @@ -922,10 +927,6 @@ void tst_qquickimage::correctStatus() void tst_qquickimage::highdpi() { - TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); - server.serveDirectory(dataDirectory()); - QString componentStr = "import QtQuick 2.0\nImage { source: srcImage ; }"; QQmlComponent component(&engine); component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); diff --git a/tests/auto/quick/qquickloader/data/initialPropertyValues.8.qml b/tests/auto/quick/qquickloader/data/initialPropertyValues.8.qml index fff67f361e..040924a5a4 100644 --- a/tests/auto/quick/qquickloader/data/initialPropertyValues.8.qml +++ b/tests/auto/quick/qquickloader/data/initialPropertyValues.8.qml @@ -3,6 +3,7 @@ import QtQuick 2.0 Item { id: root property int initialValue: 0 + property string serverBaseUrl; Loader { id: loader @@ -14,7 +15,7 @@ Item { } Component.onCompleted: { - loader.setSource("http://127.0.0.1:14458/InitialPropertyValuesComponent.qml", {"canary": 6}); + loader.setSource(serverBaseUrl + "/InitialPropertyValuesComponent.qml", {"canary": 6}); loader.active = true; } } diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp index 8b014ccd37..39f9c9dd9f 100644 --- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp +++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp @@ -41,9 +41,6 @@ #include "testhttpserver.h" #include "../../shared/util.h" -#define SERVER_PORT 14458 -#define SERVER_ADDR "http://localhost:14458" - class SlowComponent : public QQmlComponent { Q_OBJECT @@ -439,11 +436,12 @@ void tst_QQuickLoader::noResize() void tst_QQuickLoader::networkRequestUrl() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); QQmlComponent component(&engine); - component.setData(QByteArray("import QtQuick 2.0\nLoader { property int signalCount : 0; source: \"" SERVER_ADDR "/Rect120x60.qml\"; onLoaded: signalCount += 1 }"), testFileUrl("../dummy.qml")); + const QString qml = "import QtQuick 2.0\nLoader { property int signalCount : 0; source: \"" + server.baseUrl().toString() + "/Rect120x60.qml\"; onLoaded: signalCount += 1 }"; + component.setData(qml.toUtf8(), testFileUrl("../dummy.qml")); if (component.isError()) qDebug() << component.errors(); QQuickLoader *loader = qobject_cast(component.create()); @@ -463,17 +461,16 @@ void tst_QQuickLoader::networkRequestUrl() void tst_QQuickLoader::networkComponent() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory(), TestHTTPServer::Delay); QQmlComponent component(&engine); - component.setData(QByteArray( - "import QtQuick 2.0\n" - "import \"" SERVER_ADDR "/\" as NW\n" - "Item {\n" - " Component { id: comp; NW.Rect120x60 {} }\n" - " Loader { sourceComponent: comp } }") - , dataDirectory()); + const QString qml = "import QtQuick 2.0\n" + "import \"" + server.baseUrl().toString() + "/\" as NW\n" + "Item {\n" + " Component { id: comp; NW.Rect120x60 {} }\n" + " Loader { sourceComponent: comp } }"; + component.setData(qml.toUtf8(), dataDirectory()); QCOMPARE(component.status(), QQmlComponent::Loading); server.sendDelayedItem(); QTRY_COMPARE(component.status(), QQmlComponent::Ready); @@ -496,13 +493,14 @@ void tst_QQuickLoader::networkComponent() void tst_QQuickLoader::failNetworkRequest() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); - QTest::ignoreMessage(QtWarningMsg, SERVER_ADDR "/IDontExist.qml: File not found"); + QTest::ignoreMessage(QtWarningMsg, QString(server.baseUrl().toString() + "/IDontExist.qml: File not found").toUtf8()); QQmlComponent component(&engine); - component.setData(QByteArray("import QtQuick 2.0\nLoader { property int did_load: 123; source: \"" SERVER_ADDR "/IDontExist.qml\"; onLoaded: did_load=456 }"), QUrl(QString(SERVER_ADDR "/dummy.qml"))); + const QString qml = "import QtQuick 2.0\nLoader { property int did_load: 123; source: \"" + server.baseUrl().toString() + "/IDontExist.qml\"; onLoaded: did_load=456 }"; + component.setData(qml.toUtf8(), server.url("/dummy.qml")); QTRY_COMPARE(component.status(), QQmlComponent::Ready); QQuickLoader *loader = qobject_cast(component.create()); QVERIFY(loader != 0); @@ -711,15 +709,23 @@ void tst_QQuickLoader::initialPropertyValues() QFETCH(QVariantList, propertyValues); TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory()); foreach (const QString &warning, expectedWarnings) QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); QQmlComponent component(&engine, qmlFile); - QObject *object = component.create(); + QObject *object = component.beginCreate(engine.rootContext()); QVERIFY(object != 0); + + const int serverBaseUrlPropertyIndex = object->metaObject()->indexOfProperty("serverBaseUrl"); + if (serverBaseUrlPropertyIndex != -1) { + QMetaProperty prop = object->metaObject()->property(serverBaseUrlPropertyIndex); + QVERIFY(prop.write(object, server.baseUrl().toString())); + } + + component.completeCreate(); if (expectedWarnings.isEmpty()) { QQuickLoader *loader = object->findChild("loader"); QTRY_VERIFY(loader->item()); diff --git a/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp b/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp index 83c678214d..470ed34b43 100644 --- a/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp +++ b/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp @@ -108,7 +108,7 @@ void tst_qquickpixmapcache::initTestCase() { QQmlDataTest::initTestCase(); - QVERIFY2(server.listen(14452), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); // This avoids a race condition/deadlock bug in network config // manager when it is accessed by the HTTP server thread before @@ -133,8 +133,8 @@ void tst_qquickpixmapcache::single_data() // File URLs are optimized QTest::newRow("local") << testFileUrl("exists.png") << localfile_optimized << true << false; QTest::newRow("local") << testFileUrl("notexists.png") << localfile_optimized << false << false; - QTest::newRow("remote") << QUrl("http://127.0.0.1:14452/exists.png") << false << true << false; - QTest::newRow("remote") << QUrl("http://127.0.0.1:14452/notexists.png") << false << false << true; + QTest::newRow("remote") << server.url("/exists.png") << false << true << false; + QTest::newRow("remote") << server.url("/notexists.png") << false << false << true; } void tst_qquickpixmapcache::single() @@ -201,26 +201,26 @@ void tst_qquickpixmapcache::parallel_data() << -1; QTest::newRow("remote") - << QUrl("http://127.0.0.1:14452/exists2.png") - << QUrl("http://127.0.0.1:14452/exists3.png") + << server.url("/exists2.png") + << server.url("/exists3.png") << 0 << -1; QTest::newRow("remoteagain") - << QUrl("http://127.0.0.1:14452/exists2.png") - << QUrl("http://127.0.0.1:14452/exists3.png") + << server.url("/exists2.png") + << server.url("/exists3.png") << 2 << -1; QTest::newRow("remotecopy") - << QUrl("http://127.0.0.1:14452/exists4.png") - << QUrl("http://127.0.0.1:14452/exists4.png") + << server.url("/exists4.png") + << server.url("/exists4.png") << 0 << -1; QTest::newRow("remotecopycancel") - << QUrl("http://127.0.0.1:14452/exists5.png") - << QUrl("http://127.0.0.1:14452/exists5.png") + << server.url("/exists5.png") + << server.url("/exists5.png") << 0 << 0; } @@ -332,7 +332,7 @@ void tst_qquickpixmapcache::massive() // QTBUG-12729 void tst_qquickpixmapcache::cancelcrash() { - QUrl url("http://127.0.0.1:14452/cancelcrash_notexist.png"); + QUrl url = server.url("/cancelcrash_notexist.png"); for (int ii = 0; ii < 1000; ++ii) { QQuickPixmap pix(&engine, url); } @@ -370,12 +370,10 @@ void tst_qquickpixmapcache::shrinkcache() #ifndef QT_NO_CONCURRENT -void createNetworkServer() +void createNetworkServer(TestHTTPServer *server) { QEventLoop eventLoop; - TestHTTPServer server; - QVERIFY2(server.listen(14453), qPrintable(server.errorString())); - server.serveDirectory(QQmlDataTest::instance()->testFile("http")); + server->serveDirectory(QQmlDataTest::instance()->testFile("http")); QTimer::singleShot(100, &eventLoop, SLOT(quit())); eventLoop.exec(); } @@ -384,11 +382,13 @@ void createNetworkServer() // QT-3957 void tst_qquickpixmapcache::networkCrash() { - QFuture future = QtConcurrent::run(createNetworkServer); + TestHTTPServer server; + QVERIFY2(server.listen(), qPrintable(server.errorString())); + QFuture future = QtConcurrent::run(createNetworkServer, &server); QQmlEngine engine; for (int ii = 0; ii < 100 ; ++ii) { QQuickPixmap* pixmap = new QQuickPixmap; - pixmap->load(&engine, QUrl(QString("http://127.0.0.1:14453/exists.png"))); + pixmap->load(&engine, server.url("/exists.png")); QTest::qSleep(1); pixmap->clear(); delete pixmap; @@ -403,14 +403,14 @@ void tst_qquickpixmapcache::networkCrash() void tst_qquickpixmapcache::lockingCrash() { TestHTTPServer server; - QVERIFY2(server.listen(14453), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(testFile("http"), TestHTTPServer::Delay); { QQuickPixmap* p = new QQuickPixmap; { QQmlEngine e; - p->load(&e, QUrl(QString("http://127.0.0.1:14453/exists6.png"))); + p->load(&e, server.url("/exists6.png")); } p->clear(); QVERIFY(p->isNull()); diff --git a/tests/auto/quick/qquicktext/data/embeddedImagesRemote.qml b/tests/auto/quick/qquicktext/data/embeddedImagesRemote.qml index 5d241f9231..8ae91876a3 100644 --- a/tests/auto/quick/qquicktext/data/embeddedImagesRemote.qml +++ b/tests/auto/quick/qquicktext/data/embeddedImagesRemote.qml @@ -2,5 +2,5 @@ import QtQuick 2.0 Text { textFormat: Text.RichText - text: "" + text: "" } diff --git a/tests/auto/quick/qquicktext/data/embeddedImagesRemoteError.qml b/tests/auto/quick/qquicktext/data/embeddedImagesRemoteError.qml index adeed8834d..9263fa40c2 100644 --- a/tests/auto/quick/qquicktext/data/embeddedImagesRemoteError.qml +++ b/tests/auto/quick/qquicktext/data/embeddedImagesRemoteError.qml @@ -2,5 +2,5 @@ import QtQuick 2.0 Text { textFormat: Text.RichText - text: "" + text: "" } diff --git a/tests/auto/quick/qquicktext/data/embeddedImagesRemoteRelative.qml b/tests/auto/quick/qquicktext/data/embeddedImagesRemoteRelative.qml index 2835d813db..583f0f9834 100644 --- a/tests/auto/quick/qquicktext/data/embeddedImagesRemoteRelative.qml +++ b/tests/auto/quick/qquicktext/data/embeddedImagesRemoteRelative.qml @@ -3,5 +3,5 @@ import QtQuick 2.0 Text { textFormat: Text.RichText text: "" - baseUrl: "http://127.0.0.1:14459/text.html" + baseUrl: serverBaseUrl + "/text.html" } diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index 7453268f63..c26cf85b37 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -50,9 +50,6 @@ DEFINE_BOOL_CONFIG_OPTION(qmlDisableDistanceField, QML_DISABLE_DISTANCEFIELD) -#define SERVER_PORT 14459 -#define SERVER_ADDR "http://127.0.0.1:14459" - Q_DECLARE_METATYPE(QQuickText::TextFormat) QT_BEGIN_NAMESPACE @@ -2049,7 +2046,7 @@ void tst_qquicktext::embeddedImages_data() QTest::newRow("local") << testFileUrl("embeddedImagesLocalRelative.qml") << ""; QTest::newRow("remote") << testFileUrl("embeddedImagesRemote.qml") << ""; QTest::newRow("remote-error") << testFileUrl("embeddedImagesRemoteError.qml") - << testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML Text: Error downloading " SERVER_ADDR "/notexists.png - server replied: Not found"; + << testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML Text: Error downloading {{ServerBaseUrl}}/notexists.png - server replied: Not found"; QTest::newRow("remote") << testFileUrl("embeddedImagesRemoteRelative.qml") << ""; } @@ -2061,13 +2058,16 @@ void tst_qquicktext::embeddedImages() QFETCH(QString, error); TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(testFile("http")); + error.replace(QStringLiteral("{{ServerBaseUrl}}"), server.baseUrl().toString()); if (!error.isEmpty()) QTest::ignoreMessage(QtWarningMsg, error.toLatin1()); - QQuickView *view = new QQuickView(qmlfile); + QQuickView *view = new QQuickView; + view->rootContext()->setContextProperty(QStringLiteral("serverBaseUrl"), server.baseUrl()); + view->setSource(qmlfile); view->show(); view->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(view)); @@ -2777,22 +2777,33 @@ void tst_qquicktext::imgTagsBaseUrl_data() << 181.; QTest::newRow("absolute remote") - << QUrl(SERVER_ADDR "/images/heart200.png") + << QUrl("http://testserver/images/heart200.png") << QUrl() << QUrl() << 181.; QTest::newRow("relative remote base 1") << QUrl("images/heart200.png") - << QUrl(SERVER_ADDR "/") + << QUrl("http://testserver/") << testFileUrl("nonexistant/app.qml") << 181.; QTest::newRow("relative remote base 2") << QUrl("heart200.png") - << QUrl(SERVER_ADDR "/images/") + << QUrl("http://testserver/images/") << testFileUrl("nonexistant/app.qml") << 181.; } +static QUrl substituteTestServerUrl(const QUrl &serverUrl, const QUrl &testUrl) +{ + QUrl result = testUrl; + if (result.host() == QStringLiteral("testserver")) { + result.setScheme(serverUrl.scheme()); + result.setHost(serverUrl.host()); + result.setPort(serverUrl.port()); + } + return result; +} + void tst_qquicktext::imgTagsBaseUrl() { QFETCH(QUrl, src); @@ -2801,9 +2812,13 @@ void tst_qquicktext::imgTagsBaseUrl() QFETCH(qreal, imgHeight); TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(testFile("")); + src = substituteTestServerUrl(server.baseUrl(), src); + baseUrl = substituteTestServerUrl(server.baseUrl(), baseUrl); + contextUrl = substituteTestServerUrl(server.baseUrl(), contextUrl); + QByteArray baseUrlFragment; if (!baseUrl.isEmpty()) baseUrlFragment = "; baseUrl: \"" + baseUrl.toEncoded() + "\""; diff --git a/tests/auto/quick/qquicktextedit/data/embeddedImagesRemote.qml b/tests/auto/quick/qquicktextedit/data/embeddedImagesRemote.qml index a823882692..6fc12edf35 100644 --- a/tests/auto/quick/qquicktextedit/data/embeddedImagesRemote.qml +++ b/tests/auto/quick/qquicktextedit/data/embeddedImagesRemote.qml @@ -1,6 +1,7 @@ import QtQuick 2.0 TextEdit { + property string serverBaseUrl; textFormat: TextEdit.RichText - text: "" + text: "" } diff --git a/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteError.qml b/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteError.qml index c6172b68dc..7ac59e2db4 100644 --- a/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteError.qml +++ b/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteError.qml @@ -1,6 +1,7 @@ import QtQuick 2.0 TextEdit { + property string serverBaseUrl; textFormat: TextEdit.RichText - text: "" + text: "" } diff --git a/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteRelative.qml b/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteRelative.qml index ee39e089ea..12894ec741 100644 --- a/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteRelative.qml +++ b/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteRelative.qml @@ -1,7 +1,8 @@ import QtQuick 2.0 TextEdit { + property string serverBaseUrl; textFormat: TextEdit.RichText text: "" - baseUrl: "http://127.0.0.1:42332/text.html" + baseUrl: serverBaseUrl + "/text.html" } diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index c61504ef99..c6c54a4e42 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -62,9 +62,6 @@ #include #endif -#define SERVER_PORT 42332 -#define SERVER_ADDR "http://localhost:42332" - Q_DECLARE_METATYPE(QQuickTextEdit::SelectionMode) Q_DECLARE_METATYPE(Qt::Key) DEFINE_BOOL_CONFIG_OPTION(qmlDisableDistanceField, QML_DISABLE_DISTANCEFIELD) @@ -2598,12 +2595,12 @@ void tst_qquicktextedit::cursorDelegate() void tst_qquicktextedit::remoteCursorDelegate() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory(), TestHTTPServer::Delay); QQuickView view; - QQmlComponent component(view.engine(), QUrl(SERVER_ADDR "/RemoteCursor.qml")); + QQmlComponent component(view.engine(), server.url("/RemoteCursor.qml")); view.rootContext()->setContextProperty("contextDelegate", &component); view.setSource(testFileUrl("cursorTestRemote.qml")); @@ -2726,8 +2723,8 @@ void tst_qquicktextedit::delegateLoading_data() // import installed QTest::newRow("pass") << "cursorHttpTestPass.qml" << ""; - QTest::newRow("fail1") << "cursorHttpTestFail1.qml" << "http://localhost:42332/FailItem.qml: Remote host closed the connection"; - QTest::newRow("fail2") << "cursorHttpTestFail2.qml" << "http://localhost:42332/ErrItem.qml:4:5: Fungus is not a type"; + QTest::newRow("fail1") << "cursorHttpTestFail1.qml" << "{{ServerBaseUrl}}/FailItem.qml: Remote host closed the connection"; + QTest::newRow("fail2") << "cursorHttpTestFail2.qml" << "{{ServerBaseUrl}}/ErrItem.qml:4:5: Fungus is not a type"; } void tst_qquicktextedit::delegateLoading() @@ -2736,12 +2733,14 @@ void tst_qquicktextedit::delegateLoading() QFETCH(QString, error); TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(testFile("httpfail"), TestHTTPServer::Disconnect); server.serveDirectory(testFile("httpslow"), TestHTTPServer::Delay); server.serveDirectory(testFile("http")); - QQuickView view(QUrl(QLatin1String(SERVER_ADDR "/") + qmlfile)); + error.replace(QStringLiteral("{{ServerBaseUrl}}"), server.baseUrl().toString()); + + QQuickView view(server.url(qmlfile)); view.show(); view.requestActivate(); @@ -5221,8 +5220,8 @@ void tst_qquicktextedit::embeddedImages_data() QTest::newRow("local") << testFileUrl("embeddedImagesLocalRelative.qml") << ""; QTest::newRow("remote") << testFileUrl("embeddedImagesRemote.qml") << ""; QTest::newRow("remote-error") << testFileUrl("embeddedImagesRemoteError.qml") - << testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML TextEdit: Error downloading http://127.0.0.1:42332/notexists.png - server replied: Not found"; - QTest::newRow("remote") << testFileUrl("embeddedImagesRemoteRelative.qml") << ""; + << testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML TextEdit: Error downloading {{ServerBaseUrl}}/notexists.png - server replied: Not found"; + QTest::newRow("remote-relative") << testFileUrl("embeddedImagesRemoteRelative.qml") << ""; } void tst_qquicktextedit::embeddedImages() @@ -5231,16 +5230,26 @@ void tst_qquicktextedit::embeddedImages() QFETCH(QString, error); TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(testFile("http")); + error.replace(QStringLiteral("{{ServerBaseUrl}}"), server.baseUrl().toString()); + if (!error.isEmpty()) QTest::ignoreMessage(QtWarningMsg, error.toLatin1()); QQmlComponent textComponent(&engine, qmlfile); - QQuickTextEdit *textObject = qobject_cast(textComponent.create()); - + QQuickTextEdit *textObject = qobject_cast(textComponent.beginCreate(engine.rootContext())); QVERIFY(textObject != 0); + + const int baseUrlPropertyIndex = textObject->metaObject()->indexOfProperty("serverBaseUrl"); + if (baseUrlPropertyIndex != -1) { + QMetaProperty prop = textObject->metaObject()->property(baseUrlPropertyIndex); + QVERIFY(prop.write(textObject, server.baseUrl().toString())); + } + + textComponent.completeCreate(); + QTRY_COMPARE(QQuickTextEditPrivate::get(textObject)->document->resourcesLoading(), 0); QPixmap pm(testFile("http/exists.png")); diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 5c8d86f840..f2cc619f41 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -58,9 +58,6 @@ #include "../../shared/platformquirks.h" #include "../../shared/platforminputcontext.h" -#define SERVER_PORT 14460 -#define SERVER_ADDR "http://localhost:14460" - Q_DECLARE_METATYPE(QQuickTextInput::SelectionMode) Q_DECLARE_METATYPE(QQuickTextInput::EchoMode) Q_DECLARE_METATYPE(Qt::Key) @@ -2859,12 +2856,12 @@ void tst_qquicktextinput::cursorDelegate() void tst_qquicktextinput::remoteCursorDelegate() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory(), TestHTTPServer::Delay); QQuickView view; - QQmlComponent component(view.engine(), QUrl(SERVER_ADDR "/RemoteCursor.qml")); + QQmlComponent component(view.engine(), server.url("/RemoteCursor.qml")); view.rootContext()->setContextProperty("contextDelegate", &component); view.setSource(testFileUrl("cursorTestRemote.qml")); diff --git a/tests/auto/shared/testhttpserver.cpp b/tests/auto/shared/testhttpserver.cpp index ff7bb54a64..eeffc27f51 100644 --- a/tests/auto/shared/testhttpserver.cpp +++ b/tests/auto/shared/testhttpserver.cpp @@ -87,9 +87,28 @@ TestHTTPServer::TestHTTPServer() } -bool TestHTTPServer::listen(quint16 port) +bool TestHTTPServer::listen() { - return server.listen(QHostAddress::LocalHost, port); + return server.listen(QHostAddress::LocalHost, 0); +} + +QUrl TestHTTPServer::baseUrl() const +{ + QUrl url; + url.setScheme(QStringLiteral("http")); + url.setHost(QStringLiteral("127.0.0.1")); + url.setPort(server.serverPort()); + return url; +} + +QUrl TestHTTPServer::url(const QString &documentPath) const +{ + return baseUrl().resolved(documentPath); +} + +QString TestHTTPServer::urlString(const QString &documentPath) const +{ + return url(documentPath).toString(); } QString TestHTTPServer::errorString() const @@ -117,6 +136,11 @@ void TestHTTPServer::addRedirect(const QString &filename, const QString &redirec redirects.insert(filename, redirectName); } +void TestHTTPServer::registerFileNameForContentSubstitution(const QString &fileName) +{ + contentSubstitutedFileNames.insert(fileName); +} + bool TestHTTPServer::wait(const QUrl &expect, const QUrl &reply, const QUrl &body) { m_state = AwaitingHeader; @@ -135,6 +159,8 @@ bool TestHTTPServer::wait(const QUrl &expect, const QUrl &reply, const QUrl &bod bodyData = bodyFile.readAll(); } + const QByteArray serverHostUrl = QByteArrayLiteral("127.0.0.1:") + QByteArray::number(server.serverPort()); + QByteArray line; bool headers_done = false; while (!(line = expectFile.readLine()).isEmpty()) { @@ -143,10 +169,12 @@ bool TestHTTPServer::wait(const QUrl &expect, const QUrl &reply, const QUrl &bod headers_done = true; continue; } - if (headers_done) + if (headers_done) { waitData.body.append(line); - else + } else { + line.replace("{{ServerHostUrl}}", serverHostUrl); waitData.headers.append(line); + } } /* while (waitData.endsWith('\n')) @@ -277,6 +305,9 @@ bool TestHTTPServer::reply(QTcpSocket *socket, const QByteArray &fileName) return true; QByteArray data = file.readAll(); + if (contentSubstitutedFileNames.contains("/" + fileName)) { + data.replace(QByteArrayLiteral("{{ServerBaseUrl}}"), baseUrl().toString().toUtf8()); + } QByteArray response = "HTTP/1.0 200 OK\r\nContent-type: text/html; charset=UTF-8\r\nContent-length: "; response += QByteArray::number(data.count()); diff --git a/tests/auto/shared/testhttpserver.h b/tests/auto/shared/testhttpserver.h index 829d8ac24a..ca5542087e 100644 --- a/tests/auto/shared/testhttpserver.h +++ b/tests/auto/shared/testhttpserver.h @@ -45,7 +45,10 @@ class TestHTTPServer : public QObject public: TestHTTPServer(); - bool listen(quint16 port); + bool listen(); + QUrl baseUrl() const; + QUrl url(const QString &documentPath) const; + QString urlString(const QString &documentPath) const; QString errorString() const; enum Mode { Normal, Delay, Disconnect }; @@ -57,6 +60,8 @@ public: void addAlias(const QString &filename, const QString &aliasName); void addRedirect(const QString &filename, const QString &redirectName); + void registerFileNameForContentSubstitution(const QString &fileName); + // In Delay mode, each item needs one call to this function to be sent void sendDelayedItem(); @@ -79,6 +84,7 @@ private: QList > dirs; QHash dataCache; QList > toSend; + QSet contentSubstitutedFileNames; struct WaitData { QList headers; -- cgit v1.2.3