From c370a6c7fe1965157fa47380bfe7fb4da5eae96b Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 26 Nov 2012 13:29:32 -0800 Subject: QML file loading: honor synchronous requests made through QNAM So that it can skip loading state when the underlying QNetworkReply is already finished. Parts-of-the-patch-by: Jeremy Nicholl Task-number: QTBUG-27723 backport of e5783b79887299d094e6976630373a4899bd7074 from qtquick1 Change-Id: I8f5ee61a754ddec81ec70f82eb39e727534a6049 Reviewed-by: Alan Alpert --- .../qdeclarativeengine/tst_qdeclarativeengine.cpp | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'tests') diff --git a/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp b/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp index c4d0ab1ce7..9c389c4bb8 100644 --- a/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp +++ b/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -70,6 +71,7 @@ private slots: void clearComponentCache(); void outputWarningsToStandardError(); void objectOwnership(); + void synchronousNetworkReply(); }; void tst_qdeclarativeengine::rootContext() @@ -328,6 +330,54 @@ void tst_qdeclarativeengine::objectOwnership() } +class MyReply : public QNetworkReply { + + Q_OBJECT + +public: + MyReply() { + setFinished(true); + } + virtual qint64 readData(char* buffer, qint64 number) { + return 0; + } + virtual void abort() { } +}; + +class MyManager : public QNetworkAccessManager { + + Q_OBJECT + +public: + MyManager(QObject *parent = 0) : QNetworkAccessManager(parent) { + } + + QNetworkReply *createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0) { + return new MyReply; + } +}; + +class MyFactory : public QDeclarativeNetworkAccessManagerFactory { + +public: + QNetworkAccessManager *create(QObject *parent) { + return new MyManager; + } +}; + +void tst_qdeclarativeengine::synchronousNetworkReply() +{ + MyFactory factory; + QDeclarativeEngine engine; + engine.setNetworkAccessManagerFactory(&factory); + QDeclarativeComponent c(&engine, QUrl("myScheme://test.qml")); + // we get an error, but we only care about whether we are finished or not in this test + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready"); + c.create(); + // reply is finished, so should not be in loading state. + QVERIFY(!c.isLoading()); +} + QTEST_MAIN(tst_qdeclarativeengine) #include "tst_qdeclarativeengine.moc" -- cgit v1.2.3