Merge "Merge remote-tracking branch 'origin/5.4' into 5.5" into refs/staging/5.5

This commit is contained in:
Simon Hausmann 2015-04-27 13:18:05 +00:00 committed by The Qt Project
commit dee67b41b0
51 changed files with 441 additions and 280 deletions

49
dist/changes-5.4.2 vendored Normal file
View File

@ -0,0 +1,49 @@
Qt 5.4.2 is a bug-fix release. It maintains both forward and backward
compatibility (source and binary) with Qt 5.4.1.
For more details, refer to the online documentation included in this
distribution. The documentation is also available online:
http://doc.qt.io/qt-5.4
The Qt version 5.4 series is binary compatible with the 5.3.x series.
Applications compiled for 5.3 will continue to run with 5.4.
Some of the changes listed in this file include issue tracking numbers
corresponding to tasks in the Qt Bug Tracker:
http://bugreports.qt.io/
Each of these identifiers can be entered in the bug tracker to obtain more
information about a particular change.
****************************************************************************
* Library *
****************************************************************************
Qt Quick
--------
- [QTBUG-40920] Fix crash due to embedded QQuickView with WA_DeleteOnClose
- [QTBUG-43376] Fix crash due to deleted items in the dirty list
- [QTBUG-43129] Fix crash in overdraw and change visualizers
- [QTBUG-42913] Fix crash in QQuickWindow::updatePolish()
- [QTBUG-34351] Fix crash when removing items from QQmlDelegateModel
- [QTBUG-38528] Fix vertical positioning of the first image in Text
- [QTBUG-42878] Ensure that Canvas has correct size with complex bindings
- [QTBUG-42222] Fix crash in Canvas destructor
- [QTBUG-42861] Better text rendering in QQuickWidget on OS X
- [QTBUG-44049] Use @2x HiDPI images from QRC without a file extension
- [QTBUG-43847][QTBUG-40789] Scale mipmapped npot images when not supported
- Fix width/height property assignment during animations
- TextInput: update the baseline offset when vertical alignment changes
QtQml
-----
- [QTBUG-42759] Fix compilation on x32 ABI (don't use JIT)
- [QTBUG-43885][QTBUG-44039] Correct ToFixed rounding for 0 fraction digits
- [QTBUG-44026] Update Timer running property at the same time the
triggered signal is emitted
- Fix crash on FreeBSD when computing stack limits

View File

@ -516,7 +516,7 @@
#include <QtQml> to use this function.
Returns non-zero if the registration was sucessful.
Returns -1 if the registration was not successful.
*/
/*!

View File

@ -124,8 +124,14 @@ quintptr getStackLimit()
} else
size = pthread_get_stacksize_np(thread_self);
stackLimit -= size;
# elif defined(__hppa)
// On some architectures the stack grows upwards. All of these are rather exotic, so simply assume
// everything is fine there.
// Known examples:
// -HP PA-RISC
stackLimit = 0;
# else
void* stackBottom = 0;
pthread_attr_t attr;
#if HAVE(PTHREAD_NP_H) && OS(FREEBSD)
// on FreeBSD pthread_attr_init() must be called otherwise getting the attrs crashes
@ -133,7 +139,9 @@ quintptr getStackLimit()
#else
if (pthread_getattr_np(pthread_self(), &attr) == 0) {
#endif
void *stackBottom = Q_NULLPTR;
size_t stackSize = 0;
pthread_attr_getstack(&attr, &stackBottom, &stackSize);
pthread_attr_destroy(&attr);

View File

@ -193,7 +193,7 @@ void QQmlInstantiatorPrivate::_q_modelUpdated(const QQmlChangeSet &changeSet, bo
void QQmlInstantiatorPrivate::makeModel()
{
Q_Q(QQmlInstantiator);
QQmlDelegateModel* delegateModel = new QQmlDelegateModel(qmlContext(q));
QQmlDelegateModel* delegateModel = new QQmlDelegateModel(qmlContext(q), q);
instanceModel = delegateModel;
ownModel = true;
delegateModel->setDelegate(delegate);

View File

@ -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);

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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);
}

View File

@ -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);

View File

@ -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;

View File

@ -2512,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") << "" << "";
@ -2526,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());
@ -2548,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"
<< "";
@ -2571,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);
}
@ -2664,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);
@ -2682,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";
@ -2731,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);
@ -3331,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);
@ -3822,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);

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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

View File

@ -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}}

View File

@ -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}}

View File

@ -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}}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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}}

View File

@ -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}}

View File

@ -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}}

View File

@ -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}}

View File

@ -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}}

View File

@ -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}}

View File

@ -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');

View File

@ -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}}

View File

@ -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
@ -238,10 +238,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);
@ -268,10 +269,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
@ -290,9 +291,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();
@ -300,16 +303,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
@ -320,7 +330,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"));
@ -350,7 +360,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")));
@ -358,7 +368,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);
@ -368,7 +378,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")));
@ -376,7 +386,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);
@ -425,7 +435,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")));
@ -433,7 +443,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();
@ -451,7 +461,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")));
@ -459,7 +469,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);
@ -503,7 +513,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")));
@ -512,7 +522,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);
@ -520,7 +530,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()));
@ -529,7 +539,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);
@ -537,7 +547,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()));
@ -546,7 +556,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);
@ -560,7 +570,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")));
@ -568,7 +578,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);
@ -596,7 +606,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")));
@ -604,7 +614,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())
@ -671,7 +681,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")));
@ -679,8 +689,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);
@ -695,7 +708,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")));
@ -704,7 +717,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);
@ -762,7 +775,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")));
@ -770,7 +783,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);
@ -820,7 +833,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")));
@ -828,7 +841,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");
@ -841,7 +854,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")));
@ -849,7 +862,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();
@ -880,7 +893,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")));
@ -888,7 +901,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();
@ -920,7 +933,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));
@ -928,7 +941,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();
@ -1021,14 +1034,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();
@ -1038,14 +1051,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();
@ -1055,14 +1068,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();
@ -1157,12 +1170,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);
}

View File

@ -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);

View File

@ -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

View File

@ -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()
@ -137,8 +134,10 @@ void tst_qquickborderimage::imageSource()
TestHTTPServer server;
if (remote) {
QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString()));
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(dataDirectory());
source = server.urlString(source);
error.replace(QStringLiteral("{{ServerBaseUrl}}"), server.baseUrl().toString());
}
if (!error.isEmpty())
@ -280,13 +279,14 @@ void tst_qquickborderimage::sciSource()
{
QFETCH(QString, source);
QFETCH(bool, valid);
bool remote = source.startsWith("http");
QFETCH(bool, remote);
TestHTTPServer server;
if (remote) {
QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString()));
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(dataDirectory());
source = server.urlString(source);
server.registerFileNameForContentSubstitution(QUrl(source).path());
}
QString componentStr = "import QtQuick 2.0\nBorderImage { source: \"" + source + "\"; width: 300; height: 300 }";
@ -321,14 +321,15 @@ void tst_qquickborderimage::sciSource_data()
{
QTest::addColumn<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()
@ -414,7 +415,7 @@ void tst_qquickborderimage::statusChanges_data()
QTest::newRow("nofile") << "" << 0 << false << QQuickImageBase::Null;
QTest::newRow("nonexistent") << testFileUrl("thisfiledoesnotexist.png").toString() << 1 << false << QQuickImageBase::Error;
QTest::newRow("noprotocol") << QString("thisfiledoesnotexisteither.png") << 2 << false << QQuickImageBase::Error;
QTest::newRow("remote") << "http://localhost:14446/colors.png" << 2 << true << QQuickImageBase::Ready;
QTest::newRow("remote") << "/colors.png" << 2 << true << QQuickImageBase::Ready;
}
void tst_qquickborderimage::statusChanges()
@ -426,8 +427,9 @@ void tst_qquickborderimage::statusChanges()
TestHTTPServer server;
if (remote) {
QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString()));
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(dataDirectory());
source = server.urlString(source);
}
QString componentStr = "import QtQuick 2.0\nBorderImage { width: 300; height: 300 }";
@ -450,7 +452,7 @@ void tst_qquickborderimage::statusChanges()
void tst_qquickborderimage::sourceSizeChanges()
{
TestHTTPServer server;
QVERIFY2(server.listen(14449), qPrintable(server.errorString()));
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(dataDirectory());
QQmlEngine engine;
@ -490,19 +492,19 @@ void tst_qquickborderimage::sourceSizeChanges()
QTRY_COMPARE(sourceSizeSpy.count(), 3);
// Remote
ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/heart200.png"));
ctxt->setContextProperty("srcImage", server.url("/heart200.png"));
QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready);
QTRY_COMPARE(sourceSizeSpy.count(), 4);
ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/heart200.png"));
ctxt->setContextProperty("srcImage", server.url("/heart200.png"));
QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready);
QTRY_COMPARE(sourceSizeSpy.count(), 4);
ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/heart200_copy.png"));
ctxt->setContextProperty("srcImage", server.url("/heart200_copy.png"));
QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready);
QTRY_COMPARE(sourceSizeSpy.count(), 4);
ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/colors.png"));
ctxt->setContextProperty("srcImage", server.url("/colors.png"));
QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready);
QTRY_COMPARE(sourceSizeSpy.count(), 5);
@ -516,7 +518,7 @@ void tst_qquickborderimage::sourceSizeChanges()
void tst_qquickborderimage::progressAndStatusChanges()
{
TestHTTPServer server;
QVERIFY2(server.listen(14449), qPrintable(server.errorString()));
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(dataDirectory());
QQmlEngine engine;
@ -552,7 +554,7 @@ void tst_qquickborderimage::progressAndStatusChanges()
QTRY_COMPARE(statusSpy.count(), 1);
// Loading remote file
ctxt->setContextProperty("srcImage", "http://127.0.0.1:14449/heart200.png");
ctxt->setContextProperty("srcImage", server.url("/heart200.png"));
QTRY_VERIFY(obj->status() == QQuickBorderImage::Loading);
QTRY_VERIFY(obj->progress() == 0.0);
QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready);

View File

@ -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);

View File

@ -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"
}
}
}

View File

@ -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";
}
@ -173,9 +170,11 @@ void tst_qquickimage::imageSource()
TestHTTPServer server;
if (remote) {
QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString()));
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(dataDirectory());
server.addRedirect("oldcolors.png", SERVER_ADDR "/colors.png");
server.addRedirect("oldcolors.png", server.urlString("/colors.png"));
source = server.urlString(source);
error.replace(QStringLiteral("{{ServerBaseUrl}}"), server.baseUrl().toString());
}
if (!error.isEmpty())
@ -523,9 +522,9 @@ void tst_qquickimage::noLoading()
qRegisterMetaType<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();
@ -549,7 +548,7 @@ void tst_qquickimage::noLoading()
QTRY_COMPARE(statusSpy.count(), 1);
// Loading remote file
ctxt->setContextProperty("srcImage", QString(SERVER_ADDR) + "/rect.png");
ctxt->setContextProperty("srcImage", server.url("/rect.png"));
QTRY_VERIFY(obj->status() == QQuickImage::Loading);
QTRY_VERIFY(obj->progress() == 0.0);
QTRY_VERIFY(obj->status() == QQuickImage::Ready);
@ -560,7 +559,7 @@ void tst_qquickimage::noLoading()
// Loading remote file again - should not go through 'Loading' state.
ctxt->setContextProperty("srcImage", testFileUrl("green.png"));
ctxt->setContextProperty("srcImage", QString(SERVER_ADDR) + "/rect.png");
ctxt->setContextProperty("srcImage", server.url("/rect.png"));
QTRY_VERIFY(obj->status() == QQuickImage::Ready);
QTRY_VERIFY(obj->progress() == 1.0);
QTRY_COMPARE(sourceSpy.count(), 4);
@ -666,9 +665,13 @@ void tst_qquickimage::nullPixmapPaint()
window->show();
QVERIFY(QTest::qWaitForWindowExposed(window.data()));
TestHTTPServer server;
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(dataDirectory(), TestHTTPServer::Delay);
QQuickImage *image = qobject_cast<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"
@ -680,11 +683,13 @@ void tst_qquickimage::nullPixmapPaint()
void tst_qquickimage::imageCrash_QTBUG_22125()
{
TestHTTPServer server;
QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString()));
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(dataDirectory(), TestHTTPServer::Delay);
{
QQuickView view(testFileUrl("qtbug_22125.qml"));
QQuickView view;
view.rootContext()->setContextProperty(QStringLiteral("serverBaseUrl"), server.baseUrl());
view.setSource(testFileUrl("qtbug_22125.qml"));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
qApp->processEvents();
@ -749,7 +754,7 @@ void tst_qquickimage::sourceSize()
void tst_qquickimage::sourceSizeChanges()
{
TestHTTPServer server;
QVERIFY2(server.listen(14449), qPrintable(server.errorString()));
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(dataDirectory());
QQmlEngine engine;
@ -789,19 +794,19 @@ void tst_qquickimage::sourceSizeChanges()
QTRY_COMPARE(sourceSizeSpy.count(), 3);
// Remote
ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/heart.png"));
ctxt->setContextProperty("srcImage", server.url("/heart.png"));
QTRY_COMPARE(img->status(), QQuickImage::Ready);
QTRY_COMPARE(sourceSizeSpy.count(), 4);
ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/heart.png"));
ctxt->setContextProperty("srcImage", server.url("/heart.png"));
QTRY_COMPARE(img->status(), QQuickImage::Ready);
QTRY_COMPARE(sourceSizeSpy.count(), 4);
ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/heart_copy.png"));
ctxt->setContextProperty("srcImage", server.url("/heart_copy.png"));
QTRY_COMPARE(img->status(), QQuickImage::Ready);
QTRY_COMPARE(sourceSizeSpy.count(), 4);
ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/colors.png"));
ctxt->setContextProperty("srcImage", server.url("/colors.png"));
QTRY_COMPARE(img->status(), QQuickImage::Ready);
QTRY_COMPARE(sourceSizeSpy.count(), 5);
@ -815,7 +820,7 @@ void tst_qquickimage::sourceSizeChanges()
void tst_qquickimage::progressAndStatusChanges()
{
TestHTTPServer server;
QVERIFY2(server.listen(14449), qPrintable(server.errorString()));
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(dataDirectory());
QQmlEngine engine;
@ -851,7 +856,7 @@ void tst_qquickimage::progressAndStatusChanges()
QTRY_COMPARE(statusSpy.count(), 1);
// Loading remote file
ctxt->setContextProperty("srcImage", "http://127.0.0.1:14449/heart.png");
ctxt->setContextProperty("srcImage", server.url("/heart.png"));
QTRY_VERIFY(obj->status() == QQuickImage::Loading);
QTRY_VERIFY(obj->progress() == 0.0);
QTRY_VERIFY(obj->status() == QQuickImage::Ready);
@ -922,10 +927,6 @@ void tst_qquickimage::correctStatus()
void tst_qquickimage::highdpi()
{
TestHTTPServer server;
QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString()));
server.serveDirectory(dataDirectory());
QString componentStr = "import QtQuick 2.0\nImage { source: srcImage ; }";
QQmlComponent component(&engine);
component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));

View File

@ -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;
}
}

View File

@ -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());

View File

@ -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());

View File

@ -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'>"
}

View File

@ -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'>"
}

View File

@ -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"
}

View File

@ -50,9 +50,6 @@
DEFINE_BOOL_CONFIG_OPTION(qmlDisableDistanceField, QML_DISABLE_DISTANCEFIELD)
#define SERVER_PORT 14459
#define SERVER_ADDR "http://127.0.0.1:14459"
Q_DECLARE_METATYPE(QQuickText::TextFormat)
QT_BEGIN_NAMESPACE
@ -2049,7 +2046,7 @@ void tst_qquicktext::embeddedImages_data()
QTest::newRow("local") << testFileUrl("embeddedImagesLocalRelative.qml") << "";
QTest::newRow("remote") << testFileUrl("embeddedImagesRemote.qml") << "";
QTest::newRow("remote-error") << testFileUrl("embeddedImagesRemoteError.qml")
<< testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML Text: Error downloading " SERVER_ADDR "/notexists.png - server replied: Not found";
<< testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML Text: Error downloading {{ServerBaseUrl}}/notexists.png - server replied: Not found";
QTest::newRow("remote") << testFileUrl("embeddedImagesRemoteRelative.qml") << "";
}
@ -2061,13 +2058,16 @@ void tst_qquicktext::embeddedImages()
QFETCH(QString, error);
TestHTTPServer server;
QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString()));
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(testFile("http"));
error.replace(QStringLiteral("{{ServerBaseUrl}}"), server.baseUrl().toString());
if (!error.isEmpty())
QTest::ignoreMessage(QtWarningMsg, error.toLatin1());
QQuickView *view = new QQuickView(qmlfile);
QQuickView *view = new QQuickView;
view->rootContext()->setContextProperty(QStringLiteral("serverBaseUrl"), server.baseUrl());
view->setSource(qmlfile);
view->show();
view->requestActivate();
QVERIFY(QTest::qWaitForWindowActive(view));
@ -2777,22 +2777,33 @@ void tst_qquicktext::imgTagsBaseUrl_data()
<< 181.;
QTest::newRow("absolute remote")
<< QUrl(SERVER_ADDR "/images/heart200.png")
<< QUrl("http://testserver/images/heart200.png")
<< QUrl()
<< QUrl()
<< 181.;
QTest::newRow("relative remote base 1")
<< QUrl("images/heart200.png")
<< QUrl(SERVER_ADDR "/")
<< QUrl("http://testserver/")
<< testFileUrl("nonexistant/app.qml")
<< 181.;
QTest::newRow("relative remote base 2")
<< QUrl("heart200.png")
<< QUrl(SERVER_ADDR "/images/")
<< QUrl("http://testserver/images/")
<< testFileUrl("nonexistant/app.qml")
<< 181.;
}
static QUrl substituteTestServerUrl(const QUrl &serverUrl, const QUrl &testUrl)
{
QUrl result = testUrl;
if (result.host() == QStringLiteral("testserver")) {
result.setScheme(serverUrl.scheme());
result.setHost(serverUrl.host());
result.setPort(serverUrl.port());
}
return result;
}
void tst_qquicktext::imgTagsBaseUrl()
{
QFETCH(QUrl, src);
@ -2801,9 +2812,13 @@ void tst_qquicktext::imgTagsBaseUrl()
QFETCH(qreal, imgHeight);
TestHTTPServer server;
QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString()));
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(testFile(""));
src = substituteTestServerUrl(server.baseUrl(), src);
baseUrl = substituteTestServerUrl(server.baseUrl(), baseUrl);
contextUrl = substituteTestServerUrl(server.baseUrl(), contextUrl);
QByteArray baseUrlFragment;
if (!baseUrl.isEmpty())
baseUrlFragment = "; baseUrl: \"" + baseUrl.toEncoded() + "\"";

View File

@ -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'>"
}

View File

@ -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'>"
}

View File

@ -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"
}

View File

@ -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)
@ -2598,12 +2595,12 @@ void tst_qquicktextedit::cursorDelegate()
void tst_qquicktextedit::remoteCursorDelegate()
{
TestHTTPServer server;
QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString()));
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(dataDirectory(), TestHTTPServer::Delay);
QQuickView view;
QQmlComponent component(view.engine(), QUrl(SERVER_ADDR "/RemoteCursor.qml"));
QQmlComponent component(view.engine(), server.url("/RemoteCursor.qml"));
view.rootContext()->setContextProperty("contextDelegate", &component);
view.setSource(testFileUrl("cursorTestRemote.qml"));
@ -2726,8 +2723,8 @@ void tst_qquicktextedit::delegateLoading_data()
// import installed
QTest::newRow("pass") << "cursorHttpTestPass.qml" << "";
QTest::newRow("fail1") << "cursorHttpTestFail1.qml" << "http://localhost:42332/FailItem.qml: Remote host closed the connection";
QTest::newRow("fail2") << "cursorHttpTestFail2.qml" << "http://localhost:42332/ErrItem.qml:4:5: Fungus is not a type";
QTest::newRow("fail1") << "cursorHttpTestFail1.qml" << "{{ServerBaseUrl}}/FailItem.qml: Remote host closed the connection";
QTest::newRow("fail2") << "cursorHttpTestFail2.qml" << "{{ServerBaseUrl}}/ErrItem.qml:4:5: Fungus is not a type";
}
void tst_qquicktextedit::delegateLoading()
@ -2736,12 +2733,14 @@ void tst_qquicktextedit::delegateLoading()
QFETCH(QString, error);
TestHTTPServer server;
QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString()));
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(testFile("httpfail"), TestHTTPServer::Disconnect);
server.serveDirectory(testFile("httpslow"), TestHTTPServer::Delay);
server.serveDirectory(testFile("http"));
QQuickView view(QUrl(QLatin1String(SERVER_ADDR "/") + qmlfile));
error.replace(QStringLiteral("{{ServerBaseUrl}}"), server.baseUrl().toString());
QQuickView view(server.url(qmlfile));
view.show();
view.requestActivate();
@ -5221,8 +5220,8 @@ void tst_qquicktextedit::embeddedImages_data()
QTest::newRow("local") << testFileUrl("embeddedImagesLocalRelative.qml") << "";
QTest::newRow("remote") << testFileUrl("embeddedImagesRemote.qml") << "";
QTest::newRow("remote-error") << testFileUrl("embeddedImagesRemoteError.qml")
<< testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML TextEdit: Error downloading http://127.0.0.1:42332/notexists.png - server replied: Not found";
QTest::newRow("remote") << testFileUrl("embeddedImagesRemoteRelative.qml") << "";
<< testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML TextEdit: Error downloading {{ServerBaseUrl}}/notexists.png - server replied: Not found";
QTest::newRow("remote-relative") << testFileUrl("embeddedImagesRemoteRelative.qml") << "";
}
void tst_qquicktextedit::embeddedImages()
@ -5231,16 +5230,26 @@ void tst_qquicktextedit::embeddedImages()
QFETCH(QString, error);
TestHTTPServer server;
QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString()));
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(testFile("http"));
error.replace(QStringLiteral("{{ServerBaseUrl}}"), server.baseUrl().toString());
if (!error.isEmpty())
QTest::ignoreMessage(QtWarningMsg, error.toLatin1());
QQmlComponent textComponent(&engine, qmlfile);
QQuickTextEdit *textObject = qobject_cast<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"));

View File

@ -58,9 +58,6 @@
#include "../../shared/platformquirks.h"
#include "../../shared/platforminputcontext.h"
#define SERVER_PORT 14460
#define SERVER_ADDR "http://localhost:14460"
Q_DECLARE_METATYPE(QQuickTextInput::SelectionMode)
Q_DECLARE_METATYPE(QQuickTextInput::EchoMode)
Q_DECLARE_METATYPE(Qt::Key)
@ -2859,12 +2856,12 @@ void tst_qquicktextinput::cursorDelegate()
void tst_qquicktextinput::remoteCursorDelegate()
{
TestHTTPServer server;
QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString()));
QVERIFY2(server.listen(), qPrintable(server.errorString()));
server.serveDirectory(dataDirectory(), TestHTTPServer::Delay);
QQuickView view;
QQmlComponent component(view.engine(), QUrl(SERVER_ADDR "/RemoteCursor.qml"));
QQmlComponent component(view.engine(), server.url("/RemoteCursor.qml"));
view.rootContext()->setContextProperty("contextDelegate", &component);
view.setSource(testFileUrl("cursorTestRemote.qml"));

View File

@ -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());

View File

@ -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;