diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-04-28 10:57:34 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-04-28 14:29:59 +0200 |
commit | 94db5de2acefb6e96d4f6cfda2df14905a5e63c5 (patch) | |
tree | c361f5dd4989ee0743e2a9f94b64dbb2127e5dea /tests | |
parent | 11f67b80c4eab4b1e3eb8e6b1e8b69e7a60e42a9 (diff) | |
parent | dee67b41b031791c7b6313e935e622ef8d594686 (diff) |
Merge remote-tracking branch 'origin/5.5' into dev
Conflicts:
tests/auto/quick/qquicktext/tst_qquicktext.cpp
Change-Id: I075e742da8396a268d97d3ab34bcd9e0c0cf001f
Diffstat (limited to 'tests')
53 files changed, 493 insertions, 301 deletions
diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp index d6eb9d3f25..bb159d5931 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 @@ -313,12 +311,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); @@ -333,13 +331,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 def04765a0..eb25eb70f4 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -4203,12 +4203,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/qqmlinstantiator/data/createMultipleAsync.qml b/tests/auto/qml/qqmlinstantiator/data/createMultipleAsync.qml new file mode 100644 index 0000000000..8d1ab0ed6a --- /dev/null +++ b/tests/auto/qml/qqmlinstantiator/data/createMultipleAsync.qml @@ -0,0 +1,10 @@ +import QtQml 2.1 + +Instantiator { + model: 10 + asynchronous: true + delegate: QtObject { + property bool success: true + property int idx: index + } +} diff --git a/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp b/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp index b6ca50cc78..7ee33b1e58 100644 --- a/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp +++ b/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp @@ -38,6 +38,7 @@ #include <QtQml/qqmlcomponent.h> #include <QtQml/private/qqmlinstantiator_p.h> #include <QtQml/qqmlcontext.h> +#include <QtQml/qqmlincubator.h> #include "../../shared/util.h" #include "stringmodel.h" @@ -53,6 +54,9 @@ private slots: void activeProperty(); void intModelChange(); void createAndRemove(); + + void asynchronous_data(); + void asynchronous(); }; void tst_qqmlinstantiator::createNone() @@ -209,6 +213,45 @@ void tst_qqmlinstantiator::createAndRemove() QCOMPARE(object->property("datum").toString(), names[i]); } } + +void tst_qqmlinstantiator::asynchronous_data() +{ + QTest::addColumn<bool>("asyncIncubator"); + QTest::addColumn<QString>("fileName"); + + QTest::newRow("Asynchronous Instantiator") << false << "createMultipleAsync.qml"; + QTest::newRow("Nested-asynchronous Instantiator") << true << "createMultiple.qml"; +} + +void tst_qqmlinstantiator::asynchronous() +{ + QFETCH(bool, asyncIncubator); + QFETCH(QString, fileName); + + QQmlEngine engine; + QQmlIncubationController incubationController; + engine.setIncubationController(&incubationController); + QQmlComponent component(&engine, testFileUrl(fileName)); + QQmlIncubator incubator(asyncIncubator ? QQmlIncubator::Asynchronous : QQmlIncubator::Synchronous); + component.create(incubator); + while (!incubator.isReady()) + incubationController.incubateFor(10); + QQmlInstantiator *instantiator = qobject_cast<QQmlInstantiator *>(incubator.object()); + while (incubationController.incubatingObjectCount() > 0) + incubationController.incubateFor(10); + QVERIFY(instantiator != 0); + QCOMPARE(instantiator->isActive(), true); + QCOMPARE(instantiator->count(), 10); + + for (int i=0; i<10; i++) { + QObject *object = instantiator->objectAt(i); + QVERIFY(object); + QCOMPARE(object->parent(), instantiator); + QCOMPARE(object->property("success").toBool(), true); + QCOMPARE(object->property("idx").toInt(), i); + } +} + QTEST_MAIN(tst_qqmlinstantiator) #include "tst_qqmlinstantiator.moc" diff --git a/tests/auto/qml/qqmllanguage/data/nestedCustomParsers.qml b/tests/auto/qml/qqmllanguage/data/nestedCustomParsers.qml new file mode 100644 index 0000000000..77b93e8594 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/nestedCustomParsers.qml @@ -0,0 +1,8 @@ +import Test 1.0 +import QtQml 2.0 +SimpleObjectWithCustomParser { + customProperty: 42 + property var nested: SimpleObjectWithCustomParser { + customNestedProperty: 42 + } +} 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 922abd9761..08da779d90 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -229,6 +229,7 @@ private slots: void customParserEvaluateEnum(); void customParserProperties(); void customParserWithExtendedObject(); + void nestedCustomParsers(); void preservePropertyCacheOnGroupObjects(); void propertyCacheInSync(); @@ -2511,7 +2512,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 +2526,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 +2550,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 +2573,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 +2668,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 +2686,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 +2735,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); @@ -3330,11 +3338,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); @@ -3821,10 +3829,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); @@ -3930,6 +3946,20 @@ void tst_qqmllanguage::customParserWithExtendedObject() QCOMPARE(returnValue.toInt(), 1584); } +void tst_qqmllanguage::nestedCustomParsers() +{ + QQmlComponent component(&engine, testFile("nestedCustomParsers.qml")); + VERIFY_ERRORS(0); + QScopedPointer<QObject> o(component.create()); + QVERIFY(!o.isNull()); + SimpleObjectWithCustomParser *testObject = qobject_cast<SimpleObjectWithCustomParser*>(o.data()); + QVERIFY(testObject); + QCOMPARE(testObject->customBindingsCount(), 1); + SimpleObjectWithCustomParser *nestedObject = qobject_cast<SimpleObjectWithCustomParser*>(testObject->property("nested").value<QObject*>()); + QVERIFY(nestedObject); + QCOMPARE(nestedObject->customBindingsCount(), 1); +} + void tst_qqmllanguage::preservePropertyCacheOnGroupObjects() { QQmlComponent component(&engine, testFile("preservePropertyCacheOnGroupObjects.qml")); diff --git a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp index 87136aa6de..0e326abad9 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/receive_binary_data.expect b/tests/auto/qml/qqmlxmlhttprequest/data/receive_binary_data.expect index 79a61383e3..112ac4e207 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/receive_binary_data.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/receive_binary_data.expect @@ -4,4 +4,4 @@ Content-Type: image/png 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/receive_json_data.expect b/tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.expect index 59a7806bc9..97b016f50a 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/receive_json_data.expect @@ -4,4 +4,4 @@ Content-Type: application/jsonrequest 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.10.expect b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.10.expect index b099ed205e..8d83a00549 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.10.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.10.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_data.8.expect b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.8.expect index 8462c40ba1..e93c019dd5 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.8.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.8.expect @@ -4,4 +4,4 @@ Connection: Keep-Alive Accept-Encoding: gzip, deflate Accept-Language: en-US,* User-Agent: Mozilla/5.0 -Host: 127.0.0.1:14445 +Host: {{ServerHostUrl}} diff --git a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.9.expect b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.9.expect index 02af8c99b8..da38968e9a 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/data/send_data.9.expect +++ b/tests/auto/qml/qqmlxmlhttprequest/data/send_data.9.expect @@ -4,4 +4,4 @@ Connection: Keep-Alive Accept-Encoding: gzip, deflate Accept-Language: en-US,* User-Agent: Mozilla/5.0 -Host: 127.0.0.1:14445 +Host: {{ServerHostUrl}} 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 d901c4dd14..ad78fafc67 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp +++ b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp @@ -38,11 +38,11 @@ #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 @@ -239,10 +239,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); @@ -269,10 +270,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 @@ -291,9 +292,11 @@ class TestThreadedHTTPServer : public QObject public: TestThreadedHTTPServer(const QUrl &expectUrl, const QUrl &replyUrl, const QUrl &bodyUrl) : m_server(Q_NULLPTR) { + QMutexLocker locker(&m_lock); moveToThread(&m_thread); m_thread.start(); QMetaObject::invokeMethod(this, "start", Qt::QueuedConnection, Q_ARG(QUrl, expectUrl), Q_ARG(QUrl, replyUrl), Q_ARG(QUrl, bodyUrl)); + m_startupCondition.wait(&m_lock); } ~TestThreadedHTTPServer() { m_server->deleteLater(); @@ -301,16 +304,23 @@ public: m_thread.wait(); } + QUrl serverBaseUrl; + private slots: void start(const QUrl &expectUrl, const QUrl &replyUrl, const QUrl &bodyUrl) { + QMutexLocker locker(&m_lock); m_server = new TestHTTPServer; - QVERIFY2(m_server->listen(SERVER_PORT), qPrintable(m_server->errorString())); + QVERIFY2(m_server->listen(), qPrintable(m_server->errorString())); + serverBaseUrl = m_server->baseUrl(); QVERIFY(m_server->wait(expectUrl, replyUrl, bodyUrl)); + m_startupCondition.wakeAll(); } private: TestHTTPServer *m_server; QThread m_thread; + QMutex m_lock; + QWaitCondition m_startupCondition; }; // Test that calling XMLHttpRequest.open() with sync @@ -321,7 +331,7 @@ void tst_qqmlxmlhttprequest::open_sync() QQmlComponent component(&engine, testFileUrl("open_sync.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.serverBaseUrl.resolved(QStringLiteral("/testdocument.html")).toString()); component.completeCreate(); QCOMPARE(object->property("responseText").toString(), QStringLiteral("QML Rocks!\n")); @@ -351,7 +361,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"))); @@ -359,7 +369,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); @@ -369,7 +379,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"))); @@ -377,7 +387,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); @@ -426,7 +436,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"))); @@ -434,7 +444,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(); @@ -452,7 +462,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"))); @@ -460,7 +470,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); @@ -504,7 +514,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"))); @@ -513,7 +523,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); @@ -521,7 +531,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())); @@ -530,7 +540,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); @@ -538,7 +548,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())); @@ -547,7 +557,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); @@ -561,7 +571,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"))); @@ -569,7 +579,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); @@ -597,7 +607,7 @@ void tst_qqmlxmlhttprequest::send_options() QFETCH(QString, file_reply); TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl(file_expected), testFileUrl(file_reply), testFileUrl("testdocument.html"))); @@ -605,7 +615,7 @@ void tst_qqmlxmlhttprequest::send_options() QQmlComponent component(&engine, testFileUrl(file_qml)); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - QString url = "http://127.0.0.1:14445"; + QString url = server.baseUrl().toString(); if (url_suffix != "/") url.append("/"); if (!url_suffix.isEmpty()) @@ -672,7 +682,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"))); @@ -680,8 +690,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); @@ -696,7 +709,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"))); @@ -705,7 +718,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); @@ -763,7 +776,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"))); @@ -771,7 +784,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); @@ -821,7 +834,7 @@ void tst_qqmlxmlhttprequest::getAllResponseHeaders_args() void tst_qqmlxmlhttprequest::getBinaryData() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("receive_binary_data.expect"), testFileUrl("receive_binary_data.reply"), testFileUrl("qml_logo.png"))); @@ -829,7 +842,7 @@ void tst_qqmlxmlhttprequest::getBinaryData() QQmlComponent component(&engine, testFileUrl("receiveBinaryData.qml")); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("url", "http://127.0.0.1:14445/gml_logo.png"); + object->setProperty("url", server.urlString("/gml_logo.png")); component.completeCreate(); QFileInfo fileInfo("data/qml_logo.png"); @@ -839,7 +852,7 @@ void tst_qqmlxmlhttprequest::getBinaryData() void tst_qqmlxmlhttprequest::getJsonData() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); QVERIFY(server.wait(testFileUrl("receive_json_data.expect"), testFileUrl("receive_binary_data.reply"), testFileUrl("json.data"))); @@ -847,7 +860,7 @@ void tst_qqmlxmlhttprequest::getJsonData() QQmlComponent component(&engine, testFileUrl("receiveJsonData.qml")); QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); QVERIFY(!object.isNull()); - object->setProperty("url", "http://127.0.0.1:14445/json.data"); + object->setProperty("url", server.urlString("/json.data")); component.completeCreate(); QTRY_VERIFY(object->property("result").toBool()); @@ -859,7 +872,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"))); @@ -867,7 +880,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(); @@ -898,7 +911,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"))); @@ -906,7 +919,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(); @@ -938,7 +951,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)); @@ -946,7 +959,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(); @@ -1039,14 +1052,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(); @@ -1056,14 +1069,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(); @@ -1073,14 +1086,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(); @@ -1175,12 +1188,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); } diff --git a/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp b/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp index c42000d418..a0accfcd58 100644 --- a/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp +++ b/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp @@ -253,11 +253,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<QQuickAnimatedImage *>(component.create()); @@ -318,7 +318,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; @@ -358,19 +358,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); @@ -384,7 +384,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; @@ -396,7 +396,7 @@ void tst_qquickanimatedimage::qtbug_16520() QQuickAnimatedImage *anim = root->findChild<QQuickAnimatedImage*>("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); @@ -407,7 +407,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; @@ -443,7 +443,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 9ba773cfea..2a96bd1501 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 << "<Unknown File>: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 - << "<Unknown File>: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 + << "<Unknown File>:2:1: QML BorderImage: Error downloading {{ServerBaseUrl}}/no-such-file.png - server replied: Not found"; } void tst_qquickborderimage::imageSource() @@ -144,8 +141,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()) @@ -287,13 +286,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 }"; @@ -328,14 +328,15 @@ void tst_qquickborderimage::sciSource_data() { QTest::addColumn<QString>("source"); QTest::addColumn<bool>("valid"); + QTest::addColumn<bool>("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() @@ -421,7 +422,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() @@ -433,8 +434,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 }"; @@ -457,7 +459,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; @@ -497,19 +499,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); @@ -523,7 +525,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; @@ -559,7 +561,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 09d346c9a6..a084c86a95 100644 --- a/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp +++ b/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp @@ -41,9 +41,6 @@ #include <QtQuick/QQuickView> #include <QtQuick/QQuickItem> -#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, "<Unknown File>: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 = "<Unknown File>: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<QQuickFontLoader*>(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 b8ab60ff6a..91ef921141 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 << "<Unknown File>: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 << "<Unknown File>: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 << "<Unknown File>: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 << "<Unknown File>:2:1: QML Image: Error downloading {{ServerBaseUrl}}/no-such-file.png - server replied: Not found"; } @@ -185,9 +182,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()) @@ -535,9 +534,9 @@ void tst_qquickimage::noLoading() qRegisterMetaType<QQuickImageBase::Status>(); 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(); @@ -561,7 +560,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); @@ -573,7 +572,7 @@ void tst_qquickimage::noLoading() // Loading remote file again - should not go through 'Loading' state. progressSpy.clear(); 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); @@ -679,9 +678,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<QQuickImage*>(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" @@ -693,11 +696,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(); @@ -762,7 +767,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; @@ -802,19 +807,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); @@ -828,7 +833,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; @@ -864,7 +869,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); @@ -935,10 +940,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 6984f59a15..3dd2551d9d 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<QQuickLoader*>(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<QQuickLoader*>(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<QQuickLoader*>("loader"); QTRY_VERIFY(loader->item()); diff --git a/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp b/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp index c8c01fc6cf..b9f93a4dcf 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<void> future = QtConcurrent::run(createNetworkServer); + TestHTTPServer server; + QVERIFY2(server.listen(), qPrintable(server.errorString())); + QFuture<void> 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: "<img src='http://127.0.0.1:14459/exists.png'>" + text: "<img src='" + serverBaseUrl + "/exists.png'>" } 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: "<img src='http://127.0.0.1:14459/notexists.png'>" + text: "<img src='" + serverBaseUrl + "/notexists.png'>" } 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: "<img src='exists.png'>" - 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 ad21d177df..00c3957bad 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 @@ -2051,7 +2048,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-relative") << testFileUrl("embeddedImagesRemoteRelative.qml") << ""; } @@ -2071,13 +2068,16 @@ void tst_qquicktext::embeddedImages() #endif 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)); @@ -2787,22 +2787,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); @@ -2811,9 +2822,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: "<img src='http://127.0.0.1:42332/exists.png'>" + text: "<img src='" + serverBaseUrl + "/exists.png'>" } 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: "<img src='http://127.0.0.1:42332/notexists.png'>" + text: "<img src='" + serverBaseUrl + "/notexists.png'>" } 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: "<img src='exists.png'>" - 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 256e5b4bd5..e5c4d0aba5 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -62,9 +62,6 @@ #include <Carbon/Carbon.h> #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) @@ -2602,12 +2599,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")); @@ -2730,8 +2727,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() @@ -2740,12 +2737,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(); @@ -5272,8 +5271,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() @@ -5282,16 +5281,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<QQuickTextEdit*>(textComponent.create()); - + QQuickTextEdit *textObject = qobject_cast<QQuickTextEdit*>(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 38d87f0c79..bc5e6031cb 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -59,9 +59,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) @@ -2861,12 +2858,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 96655f1541..7235246fc0 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 559d78c148..0c0e799d8e 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<QPair<QString, Mode> > dirs; QHash<QTcpSocket *, QByteArray> dataCache; QList<QPair<QTcpSocket *, QByteArray> > toSend; + QSet<QString> contentSubstitutedFileNames; struct WaitData { QList <QByteArray>headers; diff --git a/tests/manual/scenegraph_lancelot/hostinfo.sh b/tests/manual/scenegraph_lancelot/hostinfo.sh index ac22ce8d22..7f486efb76 100644 --- a/tests/manual/scenegraph_lancelot/hostinfo.sh +++ b/tests/manual/scenegraph_lancelot/hostinfo.sh @@ -45,15 +45,14 @@ printProperty () # printEnvVar(): prints a key-value pair from given environment variable name. # key is printed as "Env_<varname>". -# If the variable is undefined, value is printed as UNDEFINED. +# If the variable is undefined, nothing is printed. # Arguments: $1: varname printEnvVar () { key=Env_$1 val=`eval 'echo $'$1` - [ -z "$val" ] && val='[undefined]' - echo $key: $val + [ -n "$val" ] && echo $key: $val } diff --git a/tests/manual/scenegraph_lancelot/scenegrabber/main.cpp b/tests/manual/scenegraph_lancelot/scenegrabber/main.cpp index 35328b44f3..d8eedd5afb 100644 --- a/tests/manual/scenegraph_lancelot/scenegrabber/main.cpp +++ b/tests/manual/scenegraph_lancelot/scenegrabber/main.cpp @@ -43,12 +43,11 @@ // Timeout values: // A valid screen grab requires the scene to not change -// for SCENE_STABLE_TIME ms (default 500) -#define SCENE_STABLE_TIME 500 +// for SCENE_STABLE_TIME ms +#define SCENE_STABLE_TIME 200 // Give up after SCENE_TIMEOUT ms -#define SCENE_TIMEOUT 16000 - +#define SCENE_TIMEOUT 6000 //#define GRABBERDEBUG @@ -58,30 +57,44 @@ class GrabbingView : public QQuickView public: GrabbingView(const QString &outputFile) - : ofile(outputFile), frames(0), isGrabbing(false) + : ofile(outputFile), grabNo(0), isGrabbing(false), initDone(false) { - connect(this, SIGNAL(afterRendering()), SLOT(renderingDone())); + grabTimer = new QTimer(this); + grabTimer->setSingleShot(true); + grabTimer->setInterval(SCENE_STABLE_TIME); + connect(grabTimer, SIGNAL(timeout()), SLOT(grab())); + + connect(this, SIGNAL(afterRendering()), SLOT(startGrabbing())); + QTimer::singleShot(SCENE_TIMEOUT, this, SLOT(timedOut())); - stableSceneTimer.setSingleShot(true); - connect(&stableSceneTimer, SIGNAL(timeout()), SLOT(sceneStabilized())); } private slots: - void renderingDone() + void startGrabbing() + { + if (!initDone) { + initDone = true; + grabTimer->start(); + } + } + + void grab() { if (isGrabbing) return; isGrabbing = true; - frames++; + grabNo++; #ifdef GRABBERDEBUG - printf("...frame %i\n", frames); + printf("grab no. %i\n", grabNo); #endif QImage img = grabWindow(); - //qDebug() << "Rendering done, grab is" << !img.isNull() << "timer valid:" << stableSceneTimer.isActive() << "same as last:" << (img == lastGrab); - if (!img.isNull() && img != lastGrab) { + if (!img.isNull() && img == lastGrab) { + sceneStabilized(); + } else { lastGrab = img; - stableSceneTimer.start(SCENE_STABLE_TIME); + grabTimer->start(); } + isGrabbing = false; } @@ -104,7 +117,6 @@ private slots: return; } } - QGuiApplication::exit(0); #ifdef GRABBERDEBUG printf("...sceneStabilized OUT\n"); @@ -113,16 +125,17 @@ private slots: void timedOut() { - qWarning() << "Error: timed out waiting for scene to stabilize." << frames << "frame(s) received. Last grab was" << (lastGrab.isNull() ? "invalid." : "valid."); + qWarning() << "Error: timed out waiting for scene to stabilize." << grabNo << "grab(s) done. Last grab was" << (lastGrab.isNull() ? "invalid." : "valid."); QGuiApplication::exit(3); } private: QImage lastGrab; - QTimer stableSceneTimer; + QTimer *grabTimer; QString ofile; - int frames; + int grabNo; bool isGrabbing; + bool initDone; }; |