aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickimageprovider
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@nokia.com>2012-05-08 10:28:24 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-11 15:12:15 +0200
commit125f4ceb393886015574a3c3fd0fc264a4f2deb6 (patch)
treec552a05bd3030dd8c3d9a2c307e9dca0a1b9e7e9 /tests/auto/quick/qquickimageprovider
parent9b224d33216b0e21292b44743aa4594665ebf970 (diff)
Allow image providers to force their loading to be asynchronous
The request methods of an image provider are assumed to be synchronous, but sometimes the provider will be implemented in an async manner, eg. through network request or doing the I/O on a different thread. In that case, the provider can't expose this async behavior to clients, but needs to block in the request method. This is less then ideal for clients, since the default behvior of an image element is to load synchronously, so we introduce a new flag to image providers that let's the provider force the loading to happen on the async image loading thread. Similar to network requests (which are always async), this does not affect the 'asynchronous' property of the image element. Change-Id: I9542abbcc594b9aab565210bc3005a95592c1e9c Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@nokia.com> Reviewed-by: Michalina Ziemba <michalina.ziemba@nokia.com>
Diffstat (limited to 'tests/auto/quick/qquickimageprovider')
-rw-r--r--tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp b/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp
index 7f9a0efb33..b44fbfe0fc 100644
--- a/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp
+++ b/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp
@@ -61,6 +61,8 @@ private slots:
void requestImage_sync();
void requestImage_async_data();
void requestImage_async();
+ void requestImage_async_forced_data();
+ void requestImage_async_forced();
void requestPixmap_sync_data();
void requestPixmap_sync();
@@ -81,8 +83,9 @@ private:
class TestQImageProvider : public QQuickImageProvider
{
public:
- TestQImageProvider(bool *deleteWatch = 0)
- : QQuickImageProvider(Image), deleteWatch(deleteWatch)
+ TestQImageProvider(bool *deleteWatch = 0, bool forceAsync = false)
+ : QQuickImageProvider(Image, (forceAsync ? ForceAsynchronousImageLoading : Flags()))
+ , deleteWatch(deleteWatch)
{
}
@@ -231,7 +234,11 @@ void tst_qquickimageprovider::runTest(bool async, QQuickImageProvider *provider)
QQuickImage *obj = qobject_cast<QQuickImage*>(component.create());
QVERIFY(obj != 0);
- if (async)
+ // From this point on, treat forced async providers as async behaviour-wise
+ if (engine.imageProvider(QUrl(source).host()) == provider)
+ async |= provider->flags() & QQuickImageProvider::ForceAsynchronousImageLoading;
+
+ if (async)
QTRY_VERIFY(obj->status() == QQuickImage::Loading);
QCOMPARE(obj->source(), QUrl(source));
@@ -284,6 +291,18 @@ void tst_qquickimageprovider::requestImage_async()
QVERIFY(deleteWatch);
}
+void tst_qquickimageprovider::requestImage_async_forced_data()
+{
+ fillRequestTestsData("qimage|async_forced");
+}
+
+void tst_qquickimageprovider::requestImage_async_forced()
+{
+ bool deleteWatch = false;
+ runTest(false, new TestQImageProvider(&deleteWatch, true));
+ QVERIFY(deleteWatch);
+}
+
void tst_qquickimageprovider::requestPixmap_sync_data()
{
fillRequestTestsData("qpixmap");