aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/testlib
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@digia.com>2014-09-23 10:36:22 +0200
committerMitch Curtis <mitch.curtis@digia.com>2014-09-29 12:24:46 +0200
commit29b77e5e0759472ab1f7da1dd756b857d3b2ddd7 (patch)
tree37a57566d8ebbbd239eb6ad131b54edc2f8920a5 /src/imports/testlib
parent2bd7438d77c8544d263c51be432206970eae5ccf (diff)
Also search for visual children in TestCase::findChild().
It previously used QObject::findChild(), which won't work in all cases, because items like ListView don't seem to make their delegate items QObject children, while simple nested Items do. Change-Id: I1a8ed1fb55493212cb25abf595d016437812a80f Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/imports/testlib')
-rw-r--r--src/imports/testlib/TestCase.qml32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml
index 8d9f6822f4..700c9112eb 100644
--- a/src/imports/testlib/TestCase.qml
+++ b/src/imports/testlib/TestCase.qml
@@ -633,17 +633,45 @@ Item {
\since 5.4
\qmlmethod QtObject TestCase::findChild(parent, objectName)
- Returns the first child of \a parent with \a objectName,
- or \c null if no such item exists. Children are searched recursively.
+ Returns the first child of \a parent with \a objectName, or \c null if
+ no such item exists. Both visual and non-visual children are searched
+ recursively, with visual children being searched first.
\code
compare(findChild(item, "childObject"), expectedChildObject);
\endcode
*/
function findChild(parent, objectName) {
+ // First, search the visual item hierarchy.
+ var child = qtest_findVisualChild(parent, objectName);
+ if (child)
+ return child;
+
+ // If it's not a visual child, it might be a QObject child.
return qtest_results.findChild(parent, objectName);
}
+ /*! \internal */
+ function qtest_findVisualChild(parent, objectName) {
+ if (!parent || parent.children === undefined)
+ return null;
+
+ for (var i = 0; i < parent.children.length; ++i) {
+ // Is this direct child of ours the child we're after?
+ var child = parent.children[i];
+ if (child.objectName === objectName)
+ return child;
+ }
+
+ for (i = 0; i < parent.children.length; ++i) {
+ // Try the direct child's children.
+ child = qtest_findVisualChild(parent.children[i], objectName);
+ if (child)
+ return child;
+ }
+ return null;
+ }
+
/*!
\qmlmethod TestCase::tryCompare(obj, property, expected, timeout = 5000, message = "")