on xenial help sign in
Use a fake timer as suggested by Daniel instead of using a very big interval
commit2d3055935507f6abcba3bb5d7fc69b3631e36172 authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 19 Jan 2016, 16:26 (11 years ago) parent303a347
2 files changed+39−39
qml/Launcher/Launcher.qml+18−19 tests/qmltests/Launcher/tst_Launcher.qml+21−20
qml/Launcher/Launcher.qml+18−19
@@ -51,9 +51,9 @@ Item {
5151
5252 onStateChanged: {
5353 if (state == "") {
54− dismissTimer.stop()
54+ panel.dismissTimer.stop()
5555 } else {
56− dismissTimer.restart()
56+ panel.dismissTimer.restart()
5757 }
5858 }
5959
@@ -96,21 +96,6 @@ Item {
9696 property string mode: "teasing"
9797 }
9898
99− Timer {
100− id: dismissTimer
101− objectName: "dismissTimer"
102− interval: 500
103− onTriggered: {
104− if (root.autohideEnabled) {
105− if (!panel.preventHiding) {
106− root.state = ""
107− } else {
108− dismissTimer.restart()
109− }
110− }
111− }
112− }
113−
11499 // Because the animation on x is disabled while dragging
115100 // switching state directly in the drag handlers would not animate
116101 // the completion of the hide/reveal gesture. Lets update the state
@@ -238,6 +223,20 @@ Item {
238223 visible: root.x > 0 || x > -width || dragArea.pressed
239224 model: LauncherModel
240225
226+ property var dismissTimer: Timer { interval: 500 }
227+ Connections {
228+ target: panel.dismissTimer
229+ onTriggered: {
230+ if (root.autohideEnabled) {
231+ if (!panel.preventHiding) {
232+ root.state = ""
233+ } else {
234+ panel.dismissTimer.restart()
235+ }
236+ }
237+ }
238+ }
239+
241240 property bool animate: true
242241
243242 onApplicationSelected: {
@@ -250,8 +249,8 @@ Item {
250249 }
251250
252251 onPreventHidingChanged: {
253− if (dismissTimer.running) {
254− dismissTimer.restart();
252+ if (panel.dismissTimer.running) {
253+ panel.dismissTimer.restart();
255254 }
256255 }
257256
tests/qmltests/Launcher/tst_Launcher.qml+21−20
@@ -159,6 +159,18 @@ Item {
159159 target: LauncherModel
160160 }
161161
162+ Item {
163+ id: fakeDismissTimer
164+ property bool running: false
165+ signal triggered
166+
167+ function stop() {
168+ }
169+
170+ function restart() {
171+ }
172+ }
173+
162174 UnityTestCase {
163175 id: testCase
164176 name: "Launcher"
@@ -177,6 +189,11 @@ Item {
177189 launcherLoader.active = true;
178190 }
179191 function init() {
192+ var panel = findChild(launcher, "launcherPanel");
193+ verify(!!panel);
194+
195+ panel.dismissTimer = fakeDismissTimer;
196+
180197 // Make sure we don't start the test with the mouse hovering the launcher
181198 mouseMove(root, root.width, root.height / 2);
182199
@@ -216,11 +233,6 @@ Item {
216233 }
217234
218235 function revealByEdgePush() {
219− // make the dismissTimer interval very big temporarily
220− var dismissTimer = findInvisibleChild(launcher, "dismissTimer");
221− var oldInterval = dismissTimer.interval;
222− dismissTimer.interval = 100000;
223−
224236 // Place the mouse against the window/screen edge and push beyond the barrier threshold
225237 mouseMove(root, 1, root.height / 2);
226238 launcher.pushEdge(EdgeBarrierSettings.pushThreshold * 1.1);
@@ -231,15 +243,6 @@ Item {
231243 // wait until it gets fully extended
232244 tryCompare(panel, "x", 0);
233245 tryCompare(launcher, "state", "visibleTemporary");
234−
235− // move the mouse a bit, this should not be needed but without it
236− // the mouse areas do not realize their containsMouse have changed
237− // i've tested in real life without moving the mouse at all and it works
238− // so it seems to be a test-only issue
239− mouseMove(root, 2, root.height / 2);
240−
241− // now that the launcher is out, bring the interval back
242− dismissTimer.interval = oldInterval;
243246 }
244247
245248 function waitUntilLauncherDisappears() {
@@ -906,15 +909,13 @@ Item {
906909 revealByEdgePush();
907910 compare(launcher.state, "visibleTemporary");
908911
909− // wait three times the dismiss timer to check the launcher still shown
910− // because the mouse is still over the launcher
911− var dismissTimer = findInvisibleChild(launcher, "dismissTimer");
912− wait(dismissTimer.interval * 3);
913− compare(panel.x, 0);
914−
915912 // Now move the mouse away and make sure it hides in less than a second
916913 mouseMove(root, root.width, root.height / 2)
917914
915+ // trigger the hide timer
916+ fakeDismissTimer.triggered();
917+ tryCompare(panel, "x", 0);
918+
918919 tryCompare(launcher, "state", "", 1000, "Launcher didn't hide after moving mouse away from it");
919920 waitUntilLauncherDisappears();
920921 }