aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickloader/tst_qquickloader.cpp
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2012-03-29 11:14:59 +1000
committerQt by Nokia <qt-info@nokia.com>2012-04-05 09:50:05 +0200
commit5f1b7bf39298dafdd07e576eec2a6a367e80b264 (patch)
tree4ecbeb5377c6ed19f7d2a1905c96a27fe72258bf /tests/auto/quick/qquickloader/tst_qquickloader.cpp
parent99fb61587da6b7e4707858d4188f0ccd24077504 (diff)
Fix erroneous signal emission in Loader
Previously, the incubator wasn't cleared when a Loader was deactivated. This commit clears it on deactivate, and also ensures that the loadedSignal isn't emitted on error. Finally, it re-enables a network-loading-related unit test. Change-Id: I5dac92aead2c221c5d45011accf59077f7c9b402 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto/quick/qquickloader/tst_qquickloader.cpp')
-rw-r--r--tests/auto/quick/qquickloader/tst_qquickloader.cpp53
1 files changed, 47 insertions, 6 deletions
diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
index ea35897004..3bb06f737b 100644
--- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp
+++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
@@ -92,7 +92,7 @@ private slots:
void noResize();
void networkRequestUrl();
void failNetworkRequest();
-// void networkComponent();
+ void networkComponent();
void active();
void initialPropertyValues_data();
void initialPropertyValues();
@@ -111,6 +111,7 @@ private slots:
void asynchronous();
void asynchronous_clear();
void simultaneousSyncAsync();
+ void loadedSignal();
void parented();
void sizeBound();
@@ -442,21 +443,21 @@ void tst_QQuickLoader::networkRequestUrl()
delete loader;
}
-/* XXX Component waits until all dependencies are loaded. Is this actually possible?
+/* XXX Component waits until all dependencies are loaded. Is this actually possible? */
void tst_QQuickLoader::networkComponent()
{
TestHTTPServer server(SERVER_PORT);
QVERIFY(server.isValid());
- server.serveDirectory("slowdata", TestHTTPServer::Delay);
+ server.serveDirectory(dataDirectory(), TestHTTPServer::Delay);
QQmlComponent component(&engine);
component.setData(QByteArray(
"import QtQuick 2.0\n"
"import \"http://127.0.0.1:14450/\" as NW\n"
"Item {\n"
- " Component { id: comp; NW.SlowRect {} }\n"
+ " Component { id: comp; NW.Rect120x60 {} }\n"
" Loader { sourceComponent: comp } }")
- , dataDirectoryUrl());
+ , dataDirectory());
QQuickItem *item = qobject_cast<QQuickItem*>(component.create());
QVERIFY(item);
@@ -472,7 +473,6 @@ void tst_QQuickLoader::networkComponent()
delete loader;
}
-*/
void tst_QQuickLoader::failNetworkRequest()
{
@@ -1000,6 +1000,47 @@ void tst_QQuickLoader::simultaneousSyncAsync()
delete root;
}
+void tst_QQuickLoader::loadedSignal()
+{
+ {
+ // ensure that triggering loading (by setting active = true)
+ // and then immediately setting active to false, causes the
+ // loader to be deactivated, including disabling the incubator.
+ QQmlComponent component(&engine, testFileUrl("loadedSignal.qml"));
+ QObject *obj = component.create();
+
+ QMetaObject::invokeMethod(obj, "triggerLoading");
+ QTest::qWait(100); // ensure that loading would have finished if it wasn't deactivated
+ QCOMPARE(obj->property("loadCount").toInt(), 0);
+ QVERIFY(obj->property("success").toBool());
+
+ QMetaObject::invokeMethod(obj, "triggerLoading");
+ QTest::qWait(100);
+ QCOMPARE(obj->property("loadCount").toInt(), 0);
+ QVERIFY(obj->property("success").toBool());
+
+ QMetaObject::invokeMethod(obj, "triggerMultipleLoad");
+ QTest::qWait(100);
+ QCOMPARE(obj->property("loadCount").toInt(), 1); // only one loaded signal should be emitted.
+ QVERIFY(obj->property("success").toBool());
+
+ delete obj;
+ }
+
+ {
+ // ensure that an error doesn't result in the onLoaded signal being emitted.
+ QQmlComponent component(&engine, testFileUrl("loadedSignal.2.qml"));
+ QObject *obj = component.create();
+
+ QMetaObject::invokeMethod(obj, "triggerLoading");
+ QTest::qWait(100);
+ QCOMPARE(obj->property("loadCount").toInt(), 0);
+ QVERIFY(obj->property("success").toBool());
+
+ delete obj;
+ }
+}
+
void tst_QQuickLoader::parented()
{
QQmlComponent component(&engine, testFileUrl("parented.qml"));