on xenial help sign in
Fix LauncherPanel tests with Qt 5.12

The tests' previous method of checking for LauncherDelegate's wiggling assumed that the wiggle animation's running property was true throughout the animation's visual lifecycle. Unfortunately, since the running property is set externally and the animation uses runUntilComplete, it could be running visually long after its running property became false. Fix this by watching for the "started" and "stopped" signals instead. Some tests failed because of a mistaken check inside the LauncherPanel's peekingAnimation. This mistaken check also caused a filed bug, so this fixes https://github.com/ubports/ubuntu-touch/issues/1441

commit627bd76e70ff6e3d5ab427a7103d8e0039be8c2e authorDalton Durst <dalton@ubports.com> dateThu 14 Jan 2021, 22:14 (6 years ago) parentbd0786a
3 files changed+87−30
qml/Launcher/LauncherDelegate.qml+1−3 qml/Launcher/LauncherPanel.qml+2−1 tests/qmltests/Launcher/tst_Launcher.qml+84−26
qml/Launcher/LauncherDelegate.qml+1−3
@@ -37,7 +37,6 @@ Item {
3737
3838 readonly property int effectiveHeight: Math.cos(angle * Math.PI / 180) * itemHeight
3939 readonly property real foldedHeight: Math.cos(maxAngle * Math.PI / 180) * itemHeight
40− readonly property alias wiggling: root.alerting
4140
4241 property int itemWidth
4342 property int itemHeight
@@ -56,8 +55,7 @@ Item {
5655 property real wiggleAngle: 0
5756 }
5857
59− SequentialAnimation {
60− id: wiggleAnim
58+ readonly property var wiggleAnim: SequentialAnimation {
6159
6260 running: alerting
6361 loops: 1
qml/Launcher/LauncherPanel.qml+2−1
@@ -260,6 +260,7 @@ Rectangle {
260260
261261 SequentialAnimation {
262262 id: peekingAnimation
263+ objectName: "peekingAnimation" + index
263264
264265 // revealing
265266 PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 1 : 0 }
@@ -285,7 +286,7 @@ Rectangle {
285286 }
286287
287288 PropertyAction { target: launcherListViewItem; property: "clip"; value: 1 }
288− PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 0 : 1 }
289+ PropertyAction { target: root; property: "visible"; value: (launcher.visibleWidth === 0) ? 1 : 0 }
289290 PropertyAction { target: launcherListView; property: "peekingIndex"; value: -1 }
290291 }
291292
tests/qmltests/Launcher/tst_Launcher.qml+84−26
@@ -253,6 +253,24 @@ Rectangle {
253253 target: clickThroughTester
254254 }
255255
256+ SignalSpy {
257+ id: startedSpy
258+ target: null
259+ signalName: "started"
260+ }
261+
262+ SignalSpy {
263+ id: stoppedSpy
264+ target: null
265+ signalName: "stopped"
266+ }
267+
268+ SignalSpy {
269+ id: stoppedSpy2
270+ target: null
271+ signalName: "stopped"
272+ }
273+
256274 Item {
257275 id: fakeDismissTimer
258276 property bool running: false
@@ -276,6 +294,12 @@ Rectangle {
276294 function cleanup() {
277295 signalSpy.clear();
278296 clickThroughSpy.clear();
297+ startedSpy.clear();
298+ startedSpy.target = null;
299+ stoppedSpy.clear();
300+ stoppedSpy.target = null;
301+ stoppedSpy2.clear();
302+ stoppedSpy2.target = null;
279303 launcherLoader.active = false;
280304 // Loader.status might be Loader.Null and Loader.item might be null but the Loader
281305 // item might still be alive. So if we set Loader.active back to true
@@ -358,16 +382,6 @@ Rectangle {
358382 tryCompare(panel, "x", -panel.width, 1000);
359383 }
360384
361− function waitForWiggleToStart(appIcon) {
362− verify(appIcon != undefined)
363− tryCompare(appIcon, "wiggling", true, 1000, "wiggle-anim should not be in stopped state")
364− }
365−
366− function waitForWiggleToStop(appIcon) {
367− verify(appIcon != undefined)
368− tryCompare(appIcon, "wiggling", false, 1000, "wiggle-anim should not be in running state")
369− }
370−
371385 function positionLauncherListAtBeginning() {
372386 var listView = testCase.findChild(launcherLoader.item, "launcherListView");
373387 var moveAnimation = findInvisibleChild(listView, "moveAnimation")
@@ -1090,10 +1104,13 @@ Rectangle {
10901104 verify(listView != undefined)
10911105 var appIcon6 = findChild(launcher, "launcherDelegate6")
10921106 verify(appIcon6 != undefined)
1107+
1108+ startedSpy.target = appIcon6.wiggleAnim
1109+ stoppedSpy.target = appIcon6.wiggleAnim
10931110 LauncherModel.setAlerting(LauncherModel.get(6).appId, true)
1094− waitForWiggleToStart(appIcon6)
1111+ tryCompare(startedSpy, "count", 1);
10951112 LauncherModel.setAlerting(LauncherModel.get(6).appId, false)
1096− waitForWiggleToStop(appIcon6)
1113+ tryCompare(stoppedSpy, "count", 1);
10971114 tryCompare(appIcon6, "x", 0, 1000, "x-value of appId #6 should not be non-zero")
10981115 waitForRendering(listView)
10991116 }
@@ -1139,49 +1156,60 @@ Rectangle {
11391156 function test_alertMoveIconIntoView() {
11401157 dragLauncherIntoView();
11411158 var appIcon1 = findChild(launcher, "launcherDelegate1");
1159+ verify(appIcon1);
11421160 var appIcon7 = findChild(launcher, "launcherDelegate7");
1161+ verify(appIcon7);
1162+ stoppedSpy.target = appIcon1.wiggleAnim;
1163+ stoppedSpy2.target = appIcon7.wiggleAnim;
1164+
1165+ startedSpy.target = appIcon1.wiggleAnim;
11431166 LauncherModel.setAlerting(LauncherModel.get(1).appId, true)
11441167 tryCompare(appIcon1, "angle", 0, 1000, "angle of appId #1 should not be non-zero")
1145− waitForWiggleToStart(appIcon1)
1168+ tryCompare(startedSpy, "count", 1);
1169+ startedSpy.clear();
1170+
1171+ startedSpy.target = appIcon7.wiggleAnim;
11461172 LauncherModel.setAlerting(LauncherModel.get(7).appId, true)
11471173 tryCompare(appIcon7, "angle", 0, 1000, "angle of appId #7 should not be non-zero")
1148− waitForWiggleToStart(appIcon7)
1174+ tryCompare(startedSpy, "count", 1);
11491175 LauncherModel.setAlerting(LauncherModel.get(1).appId, false)
1150− waitForWiggleToStop(appIcon1)
11511176 LauncherModel.setAlerting(LauncherModel.get(7).appId, false)
1152− waitForWiggleToStop(appIcon7)
1177+ tryCompare(stoppedSpy, "count", 1);
1178+ tryCompare(stoppedSpy2, "count", 1);
11531179 }
11541180
11551181 function test_alertWigglePeekDrag() {
11561182 var appIcon5 = findChild(launcher, "launcherDelegate5");
1157− var listView = findChild(launcher, "launcherListView")
1183+ var listView = findChild(launcher, "launcherListView");
1184+ startedSpy.target = appIcon5.wiggleAnim;
1185+ stoppedSpy.target = appIcon5.wiggleAnim;
1186+
11581187 verify(listView != undefined)
11591188 LauncherModel.setAlerting(LauncherModel.get(5).appId, true)
11601189 tryCompare(listView, "peekingIndex", 5, 1000, "Wrong appId set as peeking-index")
1161− waitForWiggleToStart(appIcon5)
1162− tryCompare(appIcon5, "wiggling", true, 1000, "appId #6 should not be still")
1190+ tryCompare(startedSpy, "count", 1, 1000, "appId #6 should have wiggled")
11631191 dragLauncherIntoView();
11641192 tryCompare(listView, "peekingIndex", -1, 1000, "peeking-index should be -1")
11651193 LauncherModel.setAlerting(LauncherModel.get(5).appId, false)
1166− waitForWiggleToStop(appIcon5)
1167− tryCompare(appIcon5, "wiggling", false, 1000, "appId #1 should not be wiggling")
1194+ tryCompare(stoppedSpy, "count", 1, 1000, "appId #6 should have stopped wiggling");
11681195 }
11691196
11701197 function test_alertViaCountAndCountVisible() {
11711198 dragLauncherIntoView();
11721199 var appIcon1 = findChild(launcher, "launcherDelegate1")
11731200 var oldCount = LauncherModel.get(1).count
1201+ startedSpy.target = appIcon1.wiggleAnim;
11741202 LauncherModel.setCount(LauncherModel.get(1).appId, 42)
1175− tryCompare(appIcon1, "wiggling", false, 1000, "appId #1 should be still")
1203+ tryCompare(appIcon1.wiggleAnim, "running", false, 1000, "appId #1 should be still")
11761204 LauncherModel.setCountVisible(LauncherModel.get(1).appId, 1)
1177− tryCompare(appIcon1, "wiggling", true, 1000, "appId #1 should not be still")
1205+ tryCompare(startedSpy, "count", 1);
11781206 LauncherModel.setAlerting(LauncherModel.get(1).appId, false)
1179− waitForWiggleToStop(appIcon1)
1207+ appIcon1.wiggleAnim.complete();
11801208
11811209 LauncherModel.setCount(LauncherModel.get(1).appId, 4711)
1182− tryCompare(appIcon1, "wiggling", true, 1000, "appId #1 should not be still")
1210+ tryCompare(startedSpy, "count", 2);
11831211 LauncherModel.setAlerting(LauncherModel.get(1).appId, false)
1184− waitForWiggleToStop(appIcon1)
1212+ appIcon1.wiggleAnim.complete();
11851213 LauncherModel.setCountVisible(LauncherModel.get(1).appId, 0)
11861214 LauncherModel.setCount(LauncherModel.get(1).appId, oldCount)
11871215 }
@@ -1561,5 +1589,35 @@ Rectangle {
15611589
15621590 tryCompare(quickList, "selectedIndex", -1)
15631591 }
1592+
1593+ // Regression test for https://github.com/ubports/ubuntu-touch/issues/1441
1594+ // Short problem description: If the Launcher is dragged out while the
1595+ // Peek animation is running, the Launcher disappears after the peek
1596+ // animation ends. The Launcher does not appear until it is dismissed.
1597+ // To check for a regression: Start the peek animation and show the
1598+ // Launcher while it's running. Once the animation is done, check if
1599+ // it's still visible.
1600+ function test_peekCompletionDoesNotHideLauncher() {
1601+ var launcherPanel = findChild(launcher, "launcherPanel");
1602+ verify(launcherPanel);
1603+ var peekingAnimation = findInvisibleChild(launcherPanel, "peekingAnimation5");
1604+ verify(peekingAnimation);
1605+ startedSpy.target = peekingAnimation;
1606+
1607+ LauncherModel.setAlerting(LauncherModel.get(5).appId, true);
1608+ // The timing of this test is very exact! The animation still needs
1609+ // to be running when the Launcher is out...
1610+ tryCompare(startedSpy, "count", 1);
1611+ launcher.show();
1612+ // ...the Launcher should be visible while the animation is
1613+ // running...
1614+ compare(peekingAnimation.running, true);
1615+ compare(launcherPanel.visible, true);
1616+ tryCompare(peekingAnimation, "running", false);
1617+ // ..and we need to make sure the Launcher completes its next frame
1618+ // after the animation completes
1619+ waitForRendering(launcherPanel);
1620+ compare(launcherPanel.visible, true);
1621+ }
15641622 }
15651623}