diff options
author | Alan Alpert <aalpert@rim.com> | 2013-02-28 09:13:23 -0800 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-04 19:47:38 +0100 |
commit | e65a7e2f9955bb873c569fcb7e40dd645d9846c2 (patch) | |
tree | 97c7166713efbab0dd9eb190c49ae487e80ce1e1 /tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | |
parent | 5be0938e28b656fecd5b2cb6a56de1716ae79c70 (diff) |
Work with synchronous replies from a custom QNetworkAccessManager
Forward port of e5783b79887299d094 from QtQuick 1.
Task-number: QTBUG-27723
Change-Id: I4332dd72bb9d65167307c1ac5ce24e93b14cff5f
Reviewed-by: Peter Hartmann <phartmann@rim.com>
Diffstat (limited to 'tests/auto/qml/qqmlengine/tst_qqmlengine.cpp')
-rw-r--r-- | tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index 4e1ac22337..9177ff58f7 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -48,6 +48,7 @@ #include <QStandardPaths> #include <QSignalSpy> #include <QDebug> +#include <QBuffer> #include <QQmlComponent> #include <QQmlNetworkAccessManagerFactory> #include <QQmlExpression> @@ -63,6 +64,7 @@ public: private slots: void rootContext(); void networkAccessManager(); + void synchronousNetworkAccessManager(); void baseUrl(); void contextForObject(); void offlineStoragePath(); @@ -127,6 +129,53 @@ void tst_qqmlengine::networkAccessManager() delete engine; } +class ImmediateReply : public QNetworkReply { + + Q_OBJECT + +public: + ImmediateReply() { + setFinished(true); + } + virtual qint64 readData(char* , qint64 ) { + return 0; + } + virtual void abort() { } +}; + +class ImmediateManager : public QNetworkAccessManager { + + Q_OBJECT + +public: + ImmediateManager(QObject *parent = 0) : QNetworkAccessManager(parent) { + } + + QNetworkReply *createRequest(Operation, const QNetworkRequest & , QIODevice * outgoingData = 0) { + Q_UNUSED(outgoingData); + return new ImmediateReply; + } +}; + +class ImmediateFactory : public QQmlNetworkAccessManagerFactory { + +public: + QNetworkAccessManager *create(QObject *) { + return new ImmediateManager; + } +}; + +void tst_qqmlengine::synchronousNetworkAccessManager() +{ + ImmediateFactory factory; + QQmlEngine engine; + engine.setNetworkAccessManagerFactory(&factory); + QQmlComponent c(&engine, QUrl("myScheme://test.qml")); + // reply is finished, so should not be in loading state. + QVERIFY(!c.isLoading()); +} + + void tst_qqmlengine::baseUrl() { QQmlEngine engine; |