on xenial help sign in
Stabilize PreviewExpandableTest::test_all_widgets_height
dc1888cAlbert Astals Cid
tests/qmltests/Dash/Previews/tst_PreviewExpandable.qml+23−4
@@ -299,6 +299,20 @@ Rectangle {
299 compare (repeater.itemAt(3).expanded, false);
299 compare (repeater.itemAt(3).expanded, false);
300 }
300 }
301
301
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+
302 function test_all_widgets_height() {
316 function test_all_widgets_height() {
303 previewExpandable.widgetData = allWidgetsData;
317 previewExpandable.widgetData = allWidgetsData;
304
318
@@ -319,14 +333,19 @@ Rectangle {
319 previewWidgetFactory.widgetType = allWidgetsModel.get(i).type;
333 previewWidgetFactory.widgetType = allWidgetsModel.get(i).type;
320 previewWidgetFactory.active = true;
334 previewWidgetFactory.active = true;
321
335
322− // Wait for the height ot settle by waiting four times the time of the
336+ waitForRendering(repeater.itemAt(i));
323− // longest of the height behaviour animations
337+ waitForRendering(previewWidgetFactory);
324− wait(UbuntuAnimation.SnapDuration * 4);
338+
339+ waitForLazyImage(previewWidgetFactory);
340+ waitForLazyImage(repeater.itemAt(i));
341+
342+ UT.Util.waitForBehaviors(previewWidgetFactory);
343+ UT.Util.waitForBehaviors(repeater.itemAt(i));
325
344
326 // Check the item inside the expandable has the same height
345 // Check the item inside the expandable has the same height
327 // as the one straight from the factory
346 // as the one straight from the factory
328 verify(repeater.itemAt(i).height > 0);
347 verify(repeater.itemAt(i).height > 0);
329− tryCompare(repeater.itemAt(i), "height", previewWidgetFactory.height);
348+ compare(repeater.itemAt(i).height, previewWidgetFactory.height);
330 }
349 }
331
350
332 mouseClick(expandButton);
351 mouseClick(expandButton);
tests/utils/modules/Unity/Test/testutil.cpp+17
@@ -20,6 +20,8 @@
20#include <qpa/qwindowsysteminterface.h>
20#include <qpa/qwindowsysteminterface.h>
21#include <QtGui/QGuiApplication>
21#include <QtGui/QGuiApplication>
22#include <QQuickView>
22#include <QQuickView>
23+#include <private/qquickbehavior_p.h>
24+#include <private/qquickanimation_p.h>
23
25
24// UbuntuGestures lib
26// UbuntuGestures lib
25#include <TouchRegistry.h>
27#include <TouchRegistry.h>
@@ -56,6 +58,21 @@ TestUtil::isInstanceOf(QObject *obj, QString name)
56 return result;
58 return result;
57}
59}
58
60
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+
59TouchEventSequenceWrapper *TestUtil::touchEvent(QQuickItem *item)
76TouchEventSequenceWrapper *TestUtil::touchEvent(QQuickItem *item)
60{
77{
61 ensureTargetWindow();
78 ensureTargetWindow();
tests/utils/modules/Unity/Test/testutil.h+1
@@ -33,6 +33,7 @@ public:
33 ~TestUtil();
33 ~TestUtil();
34
34
35 Q_INVOKABLE bool isInstanceOf(QObject*, QString);
35 Q_INVOKABLE bool isInstanceOf(QObject*, QString);
36+ Q_INVOKABLE void waitForBehaviors(QObject *obj);
36 Q_INVOKABLE TouchEventSequenceWrapper *touchEvent(QQuickItem *item);
37 Q_INVOKABLE TouchEventSequenceWrapper *touchEvent(QQuickItem *item);
37
38
38private:
39private: