on xenial help sign in
Fix/update qml tests
commitcbdd1791197aeb3b147d9c3c3d86c2fca9dc6215 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateMon 4 Nov 2013, 13:00 (13 years ago) parent4bdd3ee
5 files changed+39
tests/qmltests/Components/tst_Stage.qml+5 tests/qmltests/Panel/tst_Indicators.qml+4 tests/qmltests/Panel/tst_Panel.qml+3 tests/qmltests/tst_Shell.qml+2 tests/utils/modules/Unity/Test/UnityTestCase.qml+25
tests/qmltests/Components/tst_Stage.qml+5
@@ -24,6 +24,7 @@ import Unity.Test 0.1 as UT
2424import "tst_Stage"
2525
2626Rectangle {
27+ id: root
2728 width: units.gu(70)
2829 height: stageRect.height
2930
@@ -205,6 +206,10 @@ Rectangle {
205206 && oldAppScreenshot.visible
206207 }
207208
209+ function initTestCase() {
210+ removeTimeConstraintsFromDirectionalDragAreas(root);
211+ }
212+
208213 function init() {
209214 redControl.checked = false;
210215 greenControl.checked = false;
tests/qmltests/Panel/tst_Indicators.qml+4
@@ -82,6 +82,10 @@ Item {
8282 name: "Indicators"
8383 when: windowShown
8484
85+ function initTestCase() {
86+ removeTimeConstraintsFromDirectionalDragAreas(shell);
87+ }
88+
8589 function init() {
8690 indicators.hide();
8791 tryCompare(indicators.hideAnimation, "running", false);
tests/qmltests/Panel/tst_Panel.qml+3
@@ -52,6 +52,9 @@ Item {
5252 {tag: "fullscreen", fullscreenFlag: true }
5353 ]}
5454
55+ function initTestCase() {
56+ removeTimeConstraintsFromDirectionalDragAreas(shell);
57+ }
5558
5659 function init() {
5760 searchClicked = false;
tests/qmltests/tst_Shell.qml+2
@@ -68,6 +68,8 @@ Item {
6868 // before it calls the test functions (otherwise findChild calls will fail).
6969 // The code above just didn't solve it.
7070 wait(2000);
71+
72+ removeTimeConstraintsFromDirectionalDragAreas(shell);
7173 }
7274
7375 function cleanup() {
tests/utils/modules/Unity/Test/UnityTestCase.qml+25
@@ -297,4 +297,29 @@ TestCase {
297297 event.release(0 /* touchId */, x, y)
298298 event.commit()
299299 }
300+
301+ /*
302+ In qmltests, sequences of touch events are sent all at once, unlike in "real life".
303+ Also qmltests might run really slowly, e.g. when run from inside virtual machines.
304+ Thus to remove a variable that qmltests cannot really control, namely time, this
305+ function removes all constraints from DirectionalDragAreas that are sensible to
306+ elapsed time.
307+
308+ This effectively makes DirectionalDragAreas easier to fool.
309+ */
310+ function removeTimeConstraintsFromDirectionalDragAreas(item) {
311+
312+ // use duck-typing to identify a DirectionalDragArea
313+ if (item.minSpeed != undefined
314+ && item.maxSilenceTime != undefined
315+ && item.compositionTime != undefined) {
316+ item.minSpeed = 0;
317+ item.maxSilenceTime = 60 * 60 * 1000;
318+ item.compositionTime = 0;
319+ } else {
320+ for (var i in item.children) {
321+ removeTimeConstraintsFromDirectionalDragAreas(item.children[i]);
322+ }
323+ }
324+ }
300325}