on xenial help sign in
Fix/update qml tests
cbdd179Daniel d'Andrada
tests/qmltests/Components/tst_Stage.qml+5
@@ -24,6 +24,7 @@ import Unity.Test 0.1 as UT
24import "tst_Stage"
24import "tst_Stage"
25
25
26Rectangle {
26Rectangle {
27+ id: root
27 width: units.gu(70)
28 width: units.gu(70)
28 height: stageRect.height
29 height: stageRect.height
29
30
@@ -205,6 +206,10 @@ Rectangle {
205 && oldAppScreenshot.visible
206 && oldAppScreenshot.visible
206 }
207 }
207
208
209+ function initTestCase() {
210+ removeTimeConstraintsFromDirectionalDragAreas(root);
211+ }
212+
208 function init() {
213 function init() {
209 redControl.checked = false;
214 redControl.checked = false;
210 greenControl.checked = false;
215 greenControl.checked = false;
tests/qmltests/Panel/tst_Indicators.qml+4
@@ -82,6 +82,10 @@ Item {
82 name: "Indicators"
82 name: "Indicators"
83 when: windowShown
83 when: windowShown
84
84
85+ function initTestCase() {
86+ removeTimeConstraintsFromDirectionalDragAreas(shell);
87+ }
88+
85 function init() {
89 function init() {
86 indicators.hide();
90 indicators.hide();
87 tryCompare(indicators.hideAnimation, "running", false);
91 tryCompare(indicators.hideAnimation, "running", false);
tests/qmltests/Panel/tst_Panel.qml+3
@@ -52,6 +52,9 @@ Item {
52 {tag: "fullscreen", fullscreenFlag: true }
52 {tag: "fullscreen", fullscreenFlag: true }
53 ]}
53 ]}
54
54
55+ function initTestCase() {
56+ removeTimeConstraintsFromDirectionalDragAreas(shell);
57+ }
55
58
56 function init() {
59 function init() {
57 searchClicked = false;
60 searchClicked = false;
tests/qmltests/tst_Shell.qml+2
@@ -68,6 +68,8 @@ Item {
68 // before it calls the test functions (otherwise findChild calls will fail).
68 // before it calls the test functions (otherwise findChild calls will fail).
69 // The code above just didn't solve it.
69 // The code above just didn't solve it.
70 wait(2000);
70 wait(2000);
71+
72+ removeTimeConstraintsFromDirectionalDragAreas(shell);
71 }
73 }
72
74
73 function cleanup() {
75 function cleanup() {
tests/utils/modules/Unity/Test/UnityTestCase.qml+25
@@ -297,4 +297,29 @@ TestCase {
297 event.release(0 /* touchId */, x, y)
297 event.release(0 /* touchId */, x, y)
298 event.commit()
298 event.commit()
299 }
299 }
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+ }
300}
325}