on xenial help sign in
Stabilize PreviewExpandableTest::test_all_widgets_height
commitdc1888cc285e330c367b9fcc352cb1b45cb80c09 authorAlbert Astals Cid <albert.astals@canonical.com> dateWed 11 May 2016, 16:23 (10 years ago) parentacf340b
3 files changed+41−4
tests/qmltests/Dash/Previews/tst_PreviewExpandable.qml+23−4 tests/utils/modules/Unity/Test/testutil.cpp+17 tests/utils/modules/Unity/Test/testutil.h+1
tests/qmltests/Dash/Previews/tst_PreviewExpandable.qml+23−4
@@ -299,6 +299,20 @@ Rectangle {
299299 compare (repeater.itemAt(3).expanded, false);
300300 }
301301
302+ function waitForLazyImage(obj)
303+ {
304+ if (UT.Util.isInstanceOf(obj, "LazyImage")) {
305+ tryCompareFunction(function() { return obj.state != "default" && obj.state != "loading"; }, true);
306+ for (var i in obj.transitions) {
307+ tryCompare(obj.transitions[i], "running", false);
308+ }
309+ }
310+
311+ for (var i in obj.data) {
312+ waitForLazyImage(obj.data[i]);
313+ }
314+ }
315+
302316 function test_all_widgets_height() {
303317 previewExpandable.widgetData = allWidgetsData;
304318
@@ -319,14 +333,19 @@ Rectangle {
319333 previewWidgetFactory.widgetType = allWidgetsModel.get(i).type;
320334 previewWidgetFactory.active = true;
321335
322− // Wait for the height ot settle by waiting four times the time of the
323− // longest of the height behaviour animations
324− wait(UbuntuAnimation.SnapDuration * 4);
336+ waitForRendering(repeater.itemAt(i));
337+ waitForRendering(previewWidgetFactory);
338+
339+ waitForLazyImage(previewWidgetFactory);
340+ waitForLazyImage(repeater.itemAt(i));
341+
342+ UT.Util.waitForBehaviors(previewWidgetFactory);
343+ UT.Util.waitForBehaviors(repeater.itemAt(i));
325344
326345 // Check the item inside the expandable has the same height
327346 // as the one straight from the factory
328347 verify(repeater.itemAt(i).height > 0);
329− tryCompare(repeater.itemAt(i), "height", previewWidgetFactory.height);
348+ compare(repeater.itemAt(i).height, previewWidgetFactory.height);
330349 }
331350
332351 mouseClick(expandButton);
tests/utils/modules/Unity/Test/testutil.cpp+17
@@ -20,6 +20,8 @@
2020#include <qpa/qwindowsysteminterface.h>
2121#include <QtGui/QGuiApplication>
2222#include <QQuickView>
23+#include <private/qquickbehavior_p.h>
24+#include <private/qquickanimation_p.h>
2325
2426// UbuntuGestures lib
2527#include <TouchRegistry.h>
@@ -56,6 +58,21 @@ TestUtil::isInstanceOf(QObject *obj, QString name)
5658 return result;
5759}
5860
61+void
62+TestUtil::waitForBehaviors(QObject *obj)
63+{
64+ if (!obj) return;
65+
66+ Q_FOREACH(auto c, obj->children()) {
67+ if (auto *b = dynamic_cast<QQuickBehavior*>(c)) {
68+ if (b->animation()) {
69+ QTRY_COMPARE(b->animation()->isRunning(), false);
70+ }
71+ }
72+ waitForBehaviors(c);
73+ }
74+}
75+
5976TouchEventSequenceWrapper *TestUtil::touchEvent(QQuickItem *item)
6077{
6178 ensureTargetWindow();
tests/utils/modules/Unity/Test/testutil.h+1
@@ -33,6 +33,7 @@ public:
3333 ~TestUtil();
3434
3535 Q_INVOKABLE bool isInstanceOf(QObject*, QString);
36+ Q_INVOKABLE void waitForBehaviors(QObject *obj);
3637 Q_INVOKABLE TouchEventSequenceWrapper *touchEvent(QQuickItem *item);
3738
3839private: