aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qsgloader
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2011-08-17 17:46:54 +1000
committerQt by Nokia <qt-info@nokia.com>2011-08-31 10:11:56 +0200
commit16f60d8ab6cdddeff860c3e2179cf2189908fc3e (patch)
tree22d6cef562033d364eba96a13e709f5e7b30d7ed /tests/auto/declarative/qsgloader
parent8b38efd412c8b340a4c078b5f2012c0da26f17ac (diff)
Allow initial property values to be defined with QSGLoader
This commit adds an "active" property to QSGLoader, which can be used to delay instantiation of the item until the user wishes to activate the loader. The property is true by default in order to maintain compatibility with previous behaviour. The commit also adds a "setSource(v8object)" function to QSGLoader, which behaves identically to setSource() property mutator except that it takes a JavaScript object parameter which defines the initial property values of the item (in a manner similar to that of QDeclarativeComponent::createObject()). Task-number: QTBUG-17009 Change-Id: Ifd824b518b60ef7aa3017c384835abb552e65cf1 Reviewed-on: http://codereview.qt.nokia.com/3364 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qsgloader')
-rw-r--r--tests/auto/declarative/qsgloader/data/ActiveComponent.qml11
-rw-r--r--tests/auto/declarative/qsgloader/data/InitialPropertyValuesComponent.qml11
-rw-r--r--tests/auto/declarative/qsgloader/data/InvalidSourceComponent.qml5
-rw-r--r--tests/auto/declarative/qsgloader/data/active.1.qml31
-rw-r--r--tests/auto/declarative/qsgloader/data/active.2.qml18
-rw-r--r--tests/auto/declarative/qsgloader/data/active.3.qml18
-rw-r--r--tests/auto/declarative/qsgloader/data/active.4.qml26
-rw-r--r--tests/auto/declarative/qsgloader/data/active.5.qml18
-rw-r--r--tests/auto/declarative/qsgloader/data/active.6.qml21
-rw-r--r--tests/auto/declarative/qsgloader/data/initialPropertyValues.1.qml22
-rw-r--r--tests/auto/declarative/qsgloader/data/initialPropertyValues.2.qml20
-rw-r--r--tests/auto/declarative/qsgloader/data/initialPropertyValues.3.qml18
-rw-r--r--tests/auto/declarative/qsgloader/data/initialPropertyValues.4.qml22
-rw-r--r--tests/auto/declarative/qsgloader/data/initialPropertyValues.5.qml20
-rw-r--r--tests/auto/declarative/qsgloader/data/initialPropertyValues.6.qml25
-rw-r--r--tests/auto/declarative/qsgloader/data/initialPropertyValues.7.qml29
-rw-r--r--tests/auto/declarative/qsgloader/data/initialPropertyValues.binding.qml21
-rw-r--r--tests/auto/declarative/qsgloader/data/initialPropertyValues.error.1.qml14
-rw-r--r--tests/auto/declarative/qsgloader/data/initialPropertyValues.error.2.qml14
-rw-r--r--tests/auto/declarative/qsgloader/data/initialPropertyValues.error.3.qml14
-rw-r--r--tests/auto/declarative/qsgloader/data/initialPropertyValues.error.4.qml15
-rw-r--r--tests/auto/declarative/qsgloader/tst_qsgloader.cpp238
22 files changed, 631 insertions, 0 deletions
diff --git a/tests/auto/declarative/qsgloader/data/ActiveComponent.qml b/tests/auto/declarative/qsgloader/data/ActiveComponent.qml
new file mode 100644
index 0000000000..24c6f7ad91
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/ActiveComponent.qml
@@ -0,0 +1,11 @@
+import QtQuick 2.0
+
+Item {
+ id: behaviorCounter
+ property int behaviorCount: 0
+ property int canary: 0
+
+ Behavior on canary {
+ NumberAnimation { target: behaviorCounter; property: "behaviorCount"; to: (behaviorCounter.behaviorCount + 1); duration: 0 }
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/InitialPropertyValuesComponent.qml b/tests/auto/declarative/qsgloader/data/InitialPropertyValuesComponent.qml
new file mode 100644
index 0000000000..24c6f7ad91
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/InitialPropertyValuesComponent.qml
@@ -0,0 +1,11 @@
+import QtQuick 2.0
+
+Item {
+ id: behaviorCounter
+ property int behaviorCount: 0
+ property int canary: 0
+
+ Behavior on canary {
+ NumberAnimation { target: behaviorCounter; property: "behaviorCount"; to: (behaviorCounter.behaviorCount + 1); duration: 0 }
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/InvalidSourceComponent.qml b/tests/auto/declarative/qsgloader/data/InvalidSourceComponent.qml
new file mode 100644
index 0000000000..7efa4a5f61
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/InvalidSourceComponent.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+Item {
+ RandomError
+}
diff --git a/tests/auto/declarative/qsgloader/data/active.1.qml b/tests/auto/declarative/qsgloader/data/active.1.qml
new file mode 100644
index 0000000000..2dbd1a0887
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/active.1.qml
@@ -0,0 +1,31 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ active: false
+ }
+
+ Component {
+ id: inlineTestComponent
+ Item {
+ id: inlineTestItem
+ property int someProperty: 5
+ }
+ }
+
+ function doSetSource() {
+ loader.source = "ActiveComponent.qml";
+ }
+
+ function doSetSourceComponent() {
+ loader.sourceComponent = inlineTestComponent;
+ }
+
+ function doSetActive() {
+ loader.active = true;
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/active.2.qml b/tests/auto/declarative/qsgloader/data/active.2.qml
new file mode 100644
index 0000000000..e561744c63
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/active.2.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ source: "ActiveComponent.qml";
+
+ property int statusChangedCount: 0
+ onStatusChanged: statusChangedCount = statusChangedCount + 1
+ }
+
+ function doSetInactive() {
+ loader.active = false;
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/active.3.qml b/tests/auto/declarative/qsgloader/data/active.3.qml
new file mode 100644
index 0000000000..0fbba959bb
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/active.3.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ source: "ActiveComponent.qml";
+
+ property int sourceChangedCount: 0
+ onSourceChanged: sourceChangedCount = sourceChangedCount + 1
+ }
+
+ function doSetInactive() {
+ loader.active = false;
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/active.4.qml b/tests/auto/declarative/qsgloader/data/active.4.qml
new file mode 100644
index 0000000000..63fd46e2da
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/active.4.qml
@@ -0,0 +1,26 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+
+ Component {
+ id: inlineTestComponent
+ Item {
+ id: inlineTestItem
+ property int someProperty: 5
+ }
+ }
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ sourceComponent: inlineTestComponent
+
+ property int sourceComponentChangedCount: 0
+ onSourceComponentChanged: sourceComponentChangedCount = sourceComponentChangedCount + 1
+ }
+
+ function doSetInactive() {
+ loader.active = false;
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/active.5.qml b/tests/auto/declarative/qsgloader/data/active.5.qml
new file mode 100644
index 0000000000..903f458a41
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/active.5.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ source: "ActiveComponent.qml";
+
+ property int itemChangedCount: 0
+ onItemChanged: itemChangedCount = itemChangedCount + 1
+ }
+
+ function doSetInactive() {
+ loader.active = false;
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/active.6.qml b/tests/auto/declarative/qsgloader/data/active.6.qml
new file mode 100644
index 0000000000..f769a4e184
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/active.6.qml
@@ -0,0 +1,21 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+
+ Loader {
+ id: loader
+ objectName: "loader"
+
+ property int activeChangedCount: 0
+ onActiveChanged: activeChangedCount = activeChangedCount + 1
+ }
+
+ function doSetActive() {
+ loader.active = true;
+ }
+
+ function doSetInactive() {
+ loader.active = false;
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/initialPropertyValues.1.qml b/tests/auto/declarative/qsgloader/data/initialPropertyValues.1.qml
new file mode 100644
index 0000000000..ae371797ce
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/initialPropertyValues.1.qml
@@ -0,0 +1,22 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+ property int initialValue: 0
+ property int behaviorCount: 0
+
+ Loader {
+ id: loader
+ objectName: "loader"
+
+ onLoaded: {
+ loader.item.canary = 1; // will trigger the behavior, setting behaviorCount -> 1
+ }
+ }
+
+ Component.onCompleted: {
+ loader.source = "InitialPropertyValuesComponent.qml";
+ root.initialValue = loader.item.canary; // should be one, since onLoaded will have triggered by now
+ root.behaviorCount = loader.item.behaviorCount; // should be one, since onLoaded will have triggered by now
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/initialPropertyValues.2.qml b/tests/auto/declarative/qsgloader/data/initialPropertyValues.2.qml
new file mode 100644
index 0000000000..76c7bc2fd6
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/initialPropertyValues.2.qml
@@ -0,0 +1,20 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+ property int initialValue: 0
+ property int behaviorCount: 0
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ onLoaded: {
+ root.initialValue = loader.item.canary; // should be two
+ root.behaviorCount = loader.item.behaviorCount; // should be zero
+ }
+ }
+
+ Component.onCompleted: {
+ loader.setSource("InitialPropertyValuesComponent.qml", {"canary": 2});
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/initialPropertyValues.3.qml b/tests/auto/declarative/qsgloader/data/initialPropertyValues.3.qml
new file mode 100644
index 0000000000..3b08e6ee42
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/initialPropertyValues.3.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+ property int initialValue: 0
+ property int behaviorCount: 0
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ active: false
+ }
+
+ Component.onCompleted: {
+ loader.setSource("InitialPropertyValuesComponent.qml", {"canary": 3});
+ root.initialValue = loader.item.canary; // error - item should not yet exist.
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/initialPropertyValues.4.qml b/tests/auto/declarative/qsgloader/data/initialPropertyValues.4.qml
new file mode 100644
index 0000000000..e8310044e8
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/initialPropertyValues.4.qml
@@ -0,0 +1,22 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+ property int initialValue: 0
+ property int behaviorCount: 0
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ active: false
+ onLoaded: {
+ root.initialValue = loader.item.canary; // should be four
+ root.behaviorCount = loader.item.behaviorCount; // should be zero
+ }
+ }
+
+ Component.onCompleted: {
+ loader.setSource("InitialPropertyValuesComponent.qml", {"canary": 4});
+ loader.active = true
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/initialPropertyValues.5.qml b/tests/auto/declarative/qsgloader/data/initialPropertyValues.5.qml
new file mode 100644
index 0000000000..03ee599aba
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/initialPropertyValues.5.qml
@@ -0,0 +1,20 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+ property int initialValue: 0
+ property int behaviorCount: 0
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ onLoaded: {
+ root.initialValue = loader.item.canary; // should be zero, but no error
+ root.behaviorCount = loader.item.behaviorCount; // should be zero
+ }
+ }
+
+ Component.onCompleted: {
+ loader.setSource("InitialPropertyValuesComponent.qml");
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/initialPropertyValues.6.qml b/tests/auto/declarative/qsgloader/data/initialPropertyValues.6.qml
new file mode 100644
index 0000000000..66452b512b
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/initialPropertyValues.6.qml
@@ -0,0 +1,25 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+ property int initialValue: 0
+ property int behaviorCount: 0
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ onLoaded: {
+ root.initialValue = loader.item.canary; // should be six
+ root.behaviorCount = loader.item.behaviorCount; // should be zero
+ }
+ }
+
+ Item {
+ id: child
+ property int bindable: 6
+ }
+
+ Component.onCompleted: {
+ loader.setSource("InitialPropertyValuesComponent.qml", {"canary": child.bindable});
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/initialPropertyValues.7.qml b/tests/auto/declarative/qsgloader/data/initialPropertyValues.7.qml
new file mode 100644
index 0000000000..02349f7ddf
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/initialPropertyValues.7.qml
@@ -0,0 +1,29 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+ property int loaderValue: 0
+ property int createObjectValue: 0
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ onLoaded: {
+ root.loaderValue = loader.item.canary; // should still be one
+ }
+ }
+
+ Item {
+ id: child
+ property int bindable: 1;
+ }
+
+ property InitialPropertyValuesComponent ipvc
+ Component.onCompleted: {
+ loader.setSource("InitialPropertyValuesComponent.qml", {"canary": child.bindable});
+ var dynComp = Qt.createComponent("InitialPropertyValuesComponent.qml");
+ ipvc = dynComp.createObject(root, {"canary": child.bindable});
+ child.bindable = 7; // won't cause re-evaluation, since not used in a binding.
+ root.createObjectValue = ipvc.canary; // should still be one
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/initialPropertyValues.binding.qml b/tests/auto/declarative/qsgloader/data/initialPropertyValues.binding.qml
new file mode 100644
index 0000000000..e0df50a74a
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/initialPropertyValues.binding.qml
@@ -0,0 +1,21 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+
+ property InitialPropertyValuesComponent testInstance
+ testInstance: loader.item
+
+ property int bindable: 1
+ property int canaryValue: testInstance.canary
+ property int behaviorCount: testInstance.behaviorCount
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ }
+
+ Component.onCompleted: {
+ loader.setSource("InitialPropertyValuesComponent.qml", {"canary": (function() { return root.bindable })});
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/initialPropertyValues.error.1.qml b/tests/auto/declarative/qsgloader/data/initialPropertyValues.error.1.qml
new file mode 100644
index 0000000000..f324dbddac
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/initialPropertyValues.error.1.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ }
+
+ Component.onCompleted: {
+ loader.setSource("InitialPropertyValuesComponent.qml", 3); // invalid initial properties object
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/initialPropertyValues.error.2.qml b/tests/auto/declarative/qsgloader/data/initialPropertyValues.error.2.qml
new file mode 100644
index 0000000000..89aba313c7
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/initialPropertyValues.error.2.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ }
+
+ Component.onCompleted: {
+ loader.setSource("NonexistentSourceComponent.qml", {"canary":3});
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/initialPropertyValues.error.3.qml b/tests/auto/declarative/qsgloader/data/initialPropertyValues.error.3.qml
new file mode 100644
index 0000000000..c862007402
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/initialPropertyValues.error.3.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ }
+
+ Component.onCompleted: {
+ loader.setSource("InvalidSourceComponent.qml", {"canary":3});
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/data/initialPropertyValues.error.4.qml b/tests/auto/declarative/qsgloader/data/initialPropertyValues.error.4.qml
new file mode 100644
index 0000000000..9a80b2156d
--- /dev/null
+++ b/tests/auto/declarative/qsgloader/data/initialPropertyValues.error.4.qml
@@ -0,0 +1,15 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+ property int canary: loader.item.canary
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ }
+
+ Component.onCompleted: {
+ loader.setSource("InitialPropertyValuesComponent.qml", 3); // invalid initial properties object
+ }
+}
diff --git a/tests/auto/declarative/qsgloader/tst_qsgloader.cpp b/tests/auto/declarative/qsgloader/tst_qsgloader.cpp
index c7e01da7ba..daf9e2a58a 100644
--- a/tests/auto/declarative/qsgloader/tst_qsgloader.cpp
+++ b/tests/auto/declarative/qsgloader/tst_qsgloader.cpp
@@ -41,6 +41,7 @@
#include <qtest.h>
#include <QSignalSpy>
+
#include <QtDeclarative/qdeclarativeengine.h>
#include <QtDeclarative/qdeclarativecomponent.h>
#include <private/qsgloader_p.h>
@@ -79,6 +80,12 @@ private slots:
void networkRequestUrl();
void failNetworkRequest();
// void networkComponent();
+ void active();
+ void initialPropertyValues_data();
+ void initialPropertyValues();
+ void initialPropertyValuesBinding();
+ void initialPropertyValuesError_data();
+ void initialPropertyValuesError();
void deleteComponentCrash();
void nonItem();
@@ -465,6 +472,237 @@ void tst_QSGLoader::failNetworkRequest()
delete loader;
}
+void tst_QSGLoader::active()
+{
+ // check that the item isn't instantiated until active is set to true
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("active.1.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QSGLoader *loader = object->findChild<QSGLoader*>("loader");
+
+ QVERIFY(loader->active() == false); // set manually to false
+ QVERIFY(loader->item() == 0);
+ QMetaObject::invokeMethod(object, "doSetSourceComponent");
+ QVERIFY(loader->item() == 0);
+ QMetaObject::invokeMethod(object, "doSetSource");
+ QVERIFY(loader->item() == 0);
+ QMetaObject::invokeMethod(object, "doSetActive");
+ QVERIFY(loader->item() != 0);
+
+ delete object;
+ }
+
+ // check that the status is Null if active is set to false
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("active.2.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QSGLoader *loader = object->findChild<QSGLoader*>("loader");
+
+ QVERIFY(loader->active() == true); // active is true by default
+ QCOMPARE(loader->status(), QSGLoader::Ready);
+ int currStatusChangedCount = loader->property("statusChangedCount").toInt();
+ QMetaObject::invokeMethod(object, "doSetInactive");
+ QCOMPARE(loader->status(), QSGLoader::Null);
+ QCOMPARE(loader->property("statusChangedCount").toInt(), (currStatusChangedCount+1));
+
+ delete object;
+ }
+
+ // check that the source is not cleared if active is set to false
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("active.3.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QSGLoader *loader = object->findChild<QSGLoader*>("loader");
+
+ QVERIFY(loader->active() == true); // active is true by default
+ QVERIFY(!loader->source().isEmpty());
+ int currSourceChangedCount = loader->property("sourceChangedCount").toInt();
+ QMetaObject::invokeMethod(object, "doSetInactive");
+ QVERIFY(!loader->source().isEmpty());
+ QCOMPARE(loader->property("sourceChangedCount").toInt(), currSourceChangedCount);
+
+ delete object;
+ }
+
+ // check that the sourceComponent is not cleared if active is set to false
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("active.4.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QSGLoader *loader = object->findChild<QSGLoader*>("loader");
+
+ QVERIFY(loader->active() == true); // active is true by default
+ QVERIFY(loader->sourceComponent() != 0);
+ int currSourceComponentChangedCount = loader->property("sourceComponentChangedCount").toInt();
+ QMetaObject::invokeMethod(object, "doSetInactive");
+ QVERIFY(loader->sourceComponent() != 0);
+ QCOMPARE(loader->property("sourceComponentChangedCount").toInt(), currSourceComponentChangedCount);
+
+ delete object;
+ }
+
+ // check that the item is released if active is set to false
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("active.5.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QSGLoader *loader = object->findChild<QSGLoader*>("loader");
+
+ QVERIFY(loader->active() == true); // active is true by default
+ QVERIFY(loader->item() != 0);
+ int currItemChangedCount = loader->property("itemChangedCount").toInt();
+ QMetaObject::invokeMethod(object, "doSetInactive");
+ QVERIFY(loader->item() == 0);
+ QCOMPARE(loader->property("itemChangedCount").toInt(), (currItemChangedCount+1));
+
+ delete object;
+ }
+
+ // check that the activeChanged signal is emitted correctly
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("active.6.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QSGLoader *loader = object->findChild<QSGLoader*>("loader");
+
+ QVERIFY(loader->active() == true); // active is true by default
+ loader->setActive(true); // no effect
+ QCOMPARE(loader->property("activeChangedCount").toInt(), 0);
+ loader->setActive(false); // change signal should be emitted
+ QCOMPARE(loader->property("activeChangedCount").toInt(), 1);
+ loader->setActive(false); // no effect
+ QCOMPARE(loader->property("activeChangedCount").toInt(), 1);
+ loader->setActive(true); // change signal should be emitted
+ QCOMPARE(loader->property("activeChangedCount").toInt(), 2);
+ loader->setActive(false); // change signal should be emitted
+ QCOMPARE(loader->property("activeChangedCount").toInt(), 3);
+ QMetaObject::invokeMethod(object, "doSetActive");
+ QCOMPARE(loader->property("activeChangedCount").toInt(), 4);
+ QMetaObject::invokeMethod(object, "doSetActive");
+ QCOMPARE(loader->property("activeChangedCount").toInt(), 4);
+ QMetaObject::invokeMethod(object, "doSetInactive");
+ QCOMPARE(loader->property("activeChangedCount").toInt(), 5);
+ loader->setActive(true); // change signal should be emitted
+ QCOMPARE(loader->property("activeChangedCount").toInt(), 6);
+
+ delete object;
+ }
+}
+
+void tst_QSGLoader::initialPropertyValues_data()
+{
+ QTest::addColumn<QUrl>("qmlFile");
+ QTest::addColumn<QStringList>("expectedWarnings");
+ QTest::addColumn<QStringList>("propertyNames");
+ QTest::addColumn<QVariantList>("propertyValues");
+
+ QTest::newRow("source url with value set in onLoaded, initially active = true") << TEST_FILE("initialPropertyValues.1.qml")
+ << QStringList()
+ << (QStringList() << "initialValue" << "behaviorCount")
+ << (QVariantList() << 1 << 1);
+
+ QTest::newRow("set source with initial property values specified, active = true") << TEST_FILE("initialPropertyValues.2.qml")
+ << QStringList()
+ << (QStringList() << "initialValue" << "behaviorCount")
+ << (QVariantList() << 2 << 0);
+
+ QTest::newRow("set source with initial property values specified, active = false") << TEST_FILE("initialPropertyValues.3.qml")
+ << (QStringList() << QString(QLatin1String("file://") + TEST_FILE("initialPropertyValues.3.qml").toLocalFile() + QLatin1String(":16: TypeError: Cannot read property 'canary' of null")))
+ << (QStringList())
+ << (QVariantList());
+
+ QTest::newRow("set source with initial property values specified, active = false, with active set true later") << TEST_FILE("initialPropertyValues.4.qml")
+ << QStringList()
+ << (QStringList() << "initialValue" << "behaviorCount")
+ << (QVariantList() << 4 << 0);
+
+ QTest::newRow("set source without initial property values specified, active = true") << TEST_FILE("initialPropertyValues.5.qml")
+ << QStringList()
+ << (QStringList() << "initialValue" << "behaviorCount")
+ << (QVariantList() << 0 << 0);
+
+ QTest::newRow("set source with initial property values specified with binding, active = true") << TEST_FILE("initialPropertyValues.6.qml")
+ << QStringList()
+ << (QStringList() << "initialValue" << "behaviorCount")
+ << (QVariantList() << 6 << 0);
+
+ QTest::newRow("ensure initial property value semantics mimic createObject") << TEST_FILE("initialPropertyValues.7.qml")
+ << QStringList()
+ << (QStringList() << "loaderValue" << "createObjectValue")
+ << (QVariantList() << 1 << 1);
+}
+
+void tst_QSGLoader::initialPropertyValues()
+{
+ QFETCH(QUrl, qmlFile);
+ QFETCH(QStringList, expectedWarnings);
+ QFETCH(QStringList, propertyNames);
+ QFETCH(QVariantList, propertyValues);
+
+ foreach (const QString &warning, expectedWarnings)
+ QTest::ignoreMessage(QtWarningMsg, warning.toAscii().constData());
+
+ QDeclarativeComponent component(&engine, qmlFile);
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ for (int i = 0; i < propertyNames.size(); ++i)
+ QCOMPARE(object->property(propertyNames.at(i).toAscii().constData()), propertyValues.at(i));
+
+ delete object;
+}
+
+void tst_QSGLoader::initialPropertyValuesBinding()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("initialPropertyValues.binding.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QVERIFY(object->setProperty("bindable", QVariant(8)));
+ QCOMPARE(object->property("canaryValue").toInt(), 8);
+
+ delete object;
+}
+
+void tst_QSGLoader::initialPropertyValuesError_data()
+{
+ QTest::addColumn<QUrl>("qmlFile");
+ QTest::addColumn<QStringList>("expectedWarnings");
+
+ QTest::newRow("invalid initial property values object") << TEST_FILE("initialPropertyValues.error.1.qml")
+ << (QStringList() << QString(TEST_FILE("initialPropertyValues.error.1.qml").toString() + ":6:5: QML Loader: setSource: value is not an object"));
+
+ QTest::newRow("nonexistent source url") << TEST_FILE("initialPropertyValues.error.2.qml")
+ << (QStringList() << QString(TEST_FILE("NonexistentSourceComponent.qml").toString() + ": File not found"));
+
+ QTest::newRow("invalid source url") << TEST_FILE("initialPropertyValues.error.3.qml")
+ << (QStringList() << QString(TEST_FILE("InvalidSourceComponent.qml").toString() + ":5:1: Syntax error"));
+
+ QTest::newRow("invalid initial property values object with invalid property access") << TEST_FILE("initialPropertyValues.error.4.qml")
+ << (QStringList() << QString(TEST_FILE("initialPropertyValues.error.4.qml").toString() + ":7:5: QML Loader: setSource: value is not an object")
+ << QString(TEST_FILE("initialPropertyValues.error.4.qml").toString() + ":5: TypeError: Cannot read property 'canary' of null"));
+}
+
+void tst_QSGLoader::initialPropertyValuesError()
+{
+ QFETCH(QUrl, qmlFile);
+ QFETCH(QStringList, expectedWarnings);
+
+ foreach (const QString &warning, expectedWarnings)
+ QTest::ignoreMessage(QtWarningMsg, warning.toUtf8().constData());
+
+ QDeclarativeComponent component(&engine, qmlFile);
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QSGLoader *loader = object->findChild<QSGLoader*>("loader");
+ QVERIFY(loader != 0);
+ QVERIFY(loader->item() == 0);
+ delete object;
+}
+
// QTBUG-9241
void tst_QSGLoader::deleteComponentCrash()
{