aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2011-10-06 14:37:09 +1000
committerQt by Nokia <qt-info@nokia.com>2011-10-06 08:17:18 +0200
commit0db214e51ac36d5ce5499c52cf4054b81e910bbb (patch)
tree58b0a9f1002d67df48ebc2a1f9390937917ef196 /tests
parente503a51856db7ecb93bdc02b00ba0e4d78273278 (diff)
QSGLoader shouldn't load component when active is false
Previously, QSGLoader still loaded the component specified, but didn't instantiate the item. This commit ensures that no component is loaded from the source, and that the onLoaded signal is emitted only when loading occurs (when the loader is active). Task-number: QTBUG-21710 Change-Id: I2d83603ef84d6942fb84141e9e146d2cf9654fc4 Reviewed-on: http://codereview.qt-project.org/5915 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qsgloader/data/active.7.qml14
-rw-r--r--tests/auto/declarative/qsgloader/data/active.8.qml13
-rw-r--r--tests/auto/declarative/qsgloader/tst_qsgloader.cpp29
3 files changed, 53 insertions, 3 deletions
diff --git a/tests/auto/declarative/qsgloader/data/active.7.qml b/tests/auto/declarative/qsgloader/data/active.7.qml
new file mode 100644
index 0000000000..a29e932f5e
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/active.7.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.0
+Rectangle {
+ id: root
+ color: "blue"
+ width: 100; height: 100
+ property bool success: true
+
+ Loader {
+ active: false
+ anchors.fill: parent
+ sourceComponent: Rectangle { color: "red" }
+ onLoaded: { root.success = false; } // shouldn't be triggered if active is false
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/active.8.qml b/tests/auto/declarative/qsgloader/data/active.8.qml
new file mode 100644
index 0000000000..3a66d3e99a
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/active.8.qml
@@ -0,0 +1,13 @@
+import QtQuick 2.0
+Rectangle {
+ id: root
+ color: "blue"
+ width: 100; height: 100
+ property bool success: false
+
+ Loader {
+ anchors.fill: parent
+ sourceComponent: Rectangle { color: "red" }
+ onLoaded: { root.success = true; } // should be triggered since active is true by default
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/tst_qsgloader.cpp b/tests/auto/declarative/qsgloader/tst_qsgloader.cpp
index cd4792532d..ba8d5e01d7 100644
--- a/tests/auto/declarative/qsgloader/tst_qsgloader.cpp
+++ b/tests/auto/declarative/qsgloader/tst_qsgloader.cpp
@@ -141,9 +141,14 @@ void tst_QSGLoader::sourceOrComponent()
QCOMPARE(static_cast<QSGItem*>(loader)->childItems().count(), error ? 0: 1);
if (!error) {
- QDeclarativeComponent *c = qobject_cast<QDeclarativeComponent*>(loader->children().at(0));
- QVERIFY(c);
- QCOMPARE(loader->sourceComponent(), c);
+ bool sourceComponentIsChildOfLoader = false;
+ for (int ii = 0; ii < loader->children().size(); ++ii) {
+ QDeclarativeComponent *c = qobject_cast<QDeclarativeComponent*>(loader->children().at(ii));
+ if (c && c == loader->sourceComponent()) {
+ sourceComponentIsChildOfLoader = true;
+ }
+ }
+ QVERIFY(sourceComponentIsChildOfLoader);
}
if (sourceOrComponent == "component") {
@@ -585,6 +590,24 @@ void tst_QSGLoader::active()
delete object;
}
+
+ // check that the component isn't loaded until active is set to true
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("active.7.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("success").toBool(), true);
+ delete object;
+ }
+
+ // check that the component is loaded if active is not set (true by default)
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("active.8.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("success").toBool(), true);
+ delete object;
+ }
}
void tst_QSGLoader::initialPropertyValues_data()