on xenial help sign in
Fix up shell tests

* Use initTestCase for first-test setup * Move the mouse to a neutral position before running a test * Reorder functions so all tests are contiguous * Turn on an accidentally disabled test (test_highlightFollowsMouse) and update it for the newest changes * Wait for longer and use tryCompare more often to allow asynchronous events to fire

commit7755dd42838c91473d95fdfcd5db2d9384dd927c authorDalton Durst <dalton@ubports.com> dateTue 14 May 2019, 13:30 (7 years ago) parent5d4d0aa
1 file changed+121−118
tests/qmltests/tst_Shell.qml+121−118
tests/qmltests/tst_Shell.qml+121−118
@@ -558,12 +558,12 @@ Rectangle {
558558
559559 property Item shell: shellLoader.status === Loader.Ready ? shellLoader.item : null
560560
561+ function initTestCase() {
562+ tearDown();
563+ }
564+
561565 function init() {
562− if (shellLoader.active) {
563− // happens for the very first test function as shell
564− // is loaded by default
565− tearDown();
566− }
566+ mouseMove(root, 0, 0);
567567 }
568568
569569 function cleanup() {
@@ -679,6 +679,103 @@ Rectangle {
679679 tryCompareFunction(function() { return root.topLevelSurfaceList.inputMethodSurface !== null }, true);
680680 }
681681
682+ function addSnapDecisionNotification() {
683+ var n = {
684+ type: Notification.SnapDecision,
685+ hints: {"x-canonical-private-affirmative-tint": "true"},
686+ summary: "Tom Ato",
687+ body: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.",
688+ icon: Qt.resolvedUrl("../graphics/avatars/funky.png"),
689+ secondaryIcon: Qt.resolvedUrl("../graphics/applicationIcons/facebook.png"),
690+ actions: [{ id: "ok_id", label: "Ok"},
691+ { id: "cancel_id", label: "Cancel"},
692+ { id: "notreally_id", label: "Not really"},
693+ { id: "noway_id", label: "messages:No way"},
694+ { id: "nada_id", label: "messages:Nada"}]
695+ }
696+
697+ mockNotificationsModel.append(n)
698+ }
699+
700+ function swipeAwayGreeter() {
701+ var greeter = findChild(shell, "greeter");
702+
703+ if (!greeter.shown) {
704+ console.log("Greeter not shown. Not swiping.");
705+ return;
706+ }
707+
708+ tryCompare(greeter, "fullyShown", true);
709+ waitForGreeterToStabilize();
710+ removeTimeConstraintsFromSwipeAreas(greeter);
711+
712+ var touchX = shell.width - (shell.edgeSize / 2);
713+ var touchY = shell.height / 2;
714+ touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY);
715+
716+ // wait until the animation has finished
717+ tryCompare(greeter, "shown", false);
718+ waitForRendering(greeter);
719+ }
720+
721+ function selectUserAtIndex(i) {
722+ // We could be anywhere in list; find target index to know which direction
723+ var greeter = findChild(shell, "greeter")
724+ var userlist = findChild(greeter, "userList")
725+ if (userlist.currentIndex == i)
726+ keyClick(Qt.Key_Escape) // Reset state if we're not moving
727+ while (userlist.currentIndex != i) {
728+ var next = userlist.currentIndex + 1
729+ var key = Qt.Key_Down;
730+ if (userlist.currentIndex > i) {
731+ next = userlist.currentIndex - 1
732+ key = Qt.Key_Up;
733+ }
734+ keyPress(key);
735+ tryCompare(userlist, "currentIndex", next)
736+ }
737+ tryCompare(userlist, "movingInternally", false);
738+ tryCompare(shell, "waitingOnGreeter", false); // wait for PAM to settle
739+ }
740+
741+ function selectUser(name) {
742+ // Find index of user with the right name
743+ for (var i = 0; i < LightDM.Users.count; i++) {
744+ if (LightDM.Users.data(i, LightDM.UserRoles.NameRole) == name) {
745+ break
746+ }
747+ }
748+ if (i == LightDM.Users.count) {
749+ fail("Didn't find name")
750+ return -1
751+ }
752+ selectUserAtIndex(i)
753+ return i
754+ }
755+
756+ function clickPasswordInput(isButton) {
757+ var greeter = findChild(shell, "greeter")
758+ tryCompare(greeter, "fullyShown", true);
759+
760+ var promptButton = findChild(greeter, "promptButton");
761+ tryCompare(promptButton, "visible", isButton);
762+
763+ var promptField = findChild(greeter, "promptField");
764+ tryCompare(promptField, "visible", !isButton);
765+
766+ mouseClick(promptButton);
767+ }
768+
769+ function confirmLoggedIn(loggedIn) {
770+ var greeter = findChild(shell, "greeter");
771+ tryCompare(greeter, "shown", loggedIn ? false : true);
772+ verify(loggedIn ? sessionSpy.count > 0 : sessionSpy.count === 0);
773+ }
774+
775+ function setLightDMMockMode(mode) {
776+ LightDMController.userMode = mode;
777+ }
778+
682779 function test_snapDecisionDismissalReturnsFocus() {
683780 loadShell("phone");
684781 swipeAwayGreeter();
@@ -722,24 +819,6 @@ Rectangle {
722819 compare(stage.interactive, true, "Stages not interactive again after modal notification has closed");
723820 }
724821
725− function addSnapDecisionNotification() {
726− var n = {
727− type: Notification.SnapDecision,
728− hints: {"x-canonical-private-affirmative-tint": "true"},
729− summary: "Tom Ato",
730− body: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.",
731− icon: Qt.resolvedUrl("../graphics/avatars/funky.png"),
732− secondaryIcon: Qt.resolvedUrl("../graphics/applicationIcons/facebook.png"),
733− actions: [{ id: "ok_id", label: "Ok"},
734− { id: "cancel_id", label: "Cancel"},
735− { id: "notreally_id", label: "Not really"},
736− { id: "noway_id", label: "messages:No way"},
737− { id: "nada_id", label: "messages:Nada"}]
738− }
739−
740− mockNotificationsModel.append(n)
741− }
742−
743822 function test_suspend() {
744823 loadShell("phone");
745824 swipeAwayGreeter();
@@ -810,86 +889,6 @@ Rectangle {
810889
811890 }
812891
813−
814− function swipeAwayGreeter() {
815− var greeter = findChild(shell, "greeter");
816−
817− if (!greeter.shown) {
818− console.log("Greeter not shown. Not swiping.");
819− return;
820− }
821−
822− tryCompare(greeter, "fullyShown", true);
823− waitForGreeterToStabilize();
824− removeTimeConstraintsFromSwipeAreas(greeter);
825−
826− var touchX = shell.width - (shell.edgeSize / 2);
827− var touchY = shell.height / 2;
828− touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY);
829−
830− // wait until the animation has finished
831− tryCompare(greeter, "shown", false);
832− waitForRendering(greeter);
833− }
834−
835− function selectUserAtIndex(i) {
836− // We could be anywhere in list; find target index to know which direction
837− var greeter = findChild(shell, "greeter")
838− var userlist = findChild(greeter, "userList")
839− if (userlist.currentIndex == i)
840− keyClick(Qt.Key_Escape) // Reset state if we're not moving
841− while (userlist.currentIndex != i) {
842− var next = userlist.currentIndex + 1
843− var key = Qt.Key_Down;
844− if (userlist.currentIndex > i) {
845− next = userlist.currentIndex - 1
846− key = Qt.Key_Up;
847− }
848− keyPress(key);
849− tryCompare(userlist, "currentIndex", next)
850− }
851− tryCompare(userlist, "movingInternally", false);
852− tryCompare(shell, "waitingOnGreeter", false); // wait for PAM to settle
853− }
854−
855− function selectUser(name) {
856− // Find index of user with the right name
857− for (var i = 0; i < LightDM.Users.count; i++) {
858− if (LightDM.Users.data(i, LightDM.UserRoles.NameRole) == name) {
859− break
860− }
861− }
862− if (i == LightDM.Users.count) {
863− fail("Didn't find name")
864− return -1
865− }
866− selectUserAtIndex(i)
867− return i
868− }
869−
870− function clickPasswordInput(isButton) {
871− var greeter = findChild(shell, "greeter")
872− tryCompare(greeter, "fullyShown", true);
873−
874− var promptButton = findChild(greeter, "promptButton");
875− tryCompare(promptButton, "visible", isButton);
876−
877− var promptField = findChild(greeter, "promptField");
878− tryCompare(promptField, "visible", !isButton);
879−
880− mouseClick(promptButton);
881− }
882−
883− function confirmLoggedIn(loggedIn) {
884− var greeter = findChild(shell, "greeter");
885− tryCompare(greeter, "shown", loggedIn ? false : true);
886− verify(loggedIn ? sessionSpy.count > 0 : sessionSpy.count === 0);
887− }
888−
889− function setLightDMMockMode(mode) {
890− LightDMController.userMode = mode;
891− }
892−
893892 function test_showInputMethod() {
894893 loadShell("phone");
895894 swipeAwayGreeter();
@@ -1691,26 +1690,26 @@ Rectangle {
16911690 keyRelease(Qt.Key_Alt);
16921691 }
16931692
1694− function otest_highlightFollowsMouse() {
1693+ function test_highlightFollowsMouse() {
16951694 loadDesktopShellWithApps()
16961695
1697− var spreadRepeater = findInvisibleChild(shell, "spreadRepeater");
1698− verify(spreadRepeater !== null);
1696+ var spreadItem = findChild(shell, "spreadItem");
1697+ verify(spreadItem !== null);
16991698
17001699 keyPress(Qt.Key_Alt)
17011700 keyClick(Qt.Key_Tab);
17021701
1703− tryCompare(spreadRepeater, "highlightedIndex", 1);
1702+ tryCompare(spreadItem, "highlightedIndex", 1);
17041703
17051704 var x = 0;
17061705 var y = shell.height * .75;
17071706 mouseMove(shell, x, y)
17081707
17091708 for (var i = 0; i < 7; i++) {
1710− while (spreadRepeater.highlightedIndex != i && x <= 4000) {
1709+ while (spreadItem.highlightedIndex != i && x <= 4000) {
17111710 x+=10;
17121711 mouseMove(shell, x, y)
1713− wait(0); // spin the loop so bindings get evaluated
1712+ wait(10); // spin the loop so bindings get evaluated
17141713 }
17151714 }
17161715
@@ -1742,7 +1741,7 @@ Rectangle {
17421741 while (spreadItem.highlightedIndex !== 2 && x <= 4000) {
17431742 x+=10;
17441743 mouseMove(shell, x, y)
1745− wait(0); // spin the loop so bindings get evaluated
1744+ wait(1); // spin the loop so bindings get evaluated
17461745 }
17471746 tryCompare(closeMouseArea, "enabled", true)
17481747
@@ -1750,7 +1749,10 @@ Rectangle {
17501749 verify(topLevelSurfaceList.indexForId(surfaceId) === 2);
17511750
17521751 // Close the app using the close button
1753− mouseClick(closeMouseArea, closeMouseArea.width / 2, closeMouseArea.height / 2)
1752+ // The button doesn't appear until the mouse is over the surface
1753+ mouseMove(closeMouseArea, closeMouseArea.width / 2, closeMouseArea.height / 2, 10);
1754+ tryCompare(closeMouseArea, "visible", true);
1755+ mouseClick(closeMouseArea, closeMouseArea.width / 2, closeMouseArea.height / 2);
17541756
17551757 tryCompare(topLevelSurfaceList, "count", countBeforeClickingCloseButton - 1);
17561758 verify(topLevelSurfaceList.indexForId(surfaceId) === -1);
@@ -1791,7 +1793,7 @@ Rectangle {
17911793 while (spreadItem.highlightedIndex !== 2 && x <= 4000) {
17921794 x+=10;
17931795 mouseMove(shell, x, y)
1794− wait(0); // spin the loop so bindings get evaluated
1796+ wait(1); // spin the loop so bindings get evaluated
17951797 }
17961798 tryCompare(decoratedWindow, "showHighlight", true);
17971799
@@ -1811,21 +1813,22 @@ Rectangle {
18111813 var appRepeater = findInvisibleChild(shell, "appRepeater");
18121814 verify(appRepeater !== null);
18131815
1814− keyPress(Qt.Key_Alt)
1816+ keyPress(Qt.Key_Alt);
18151817 keyClick(Qt.Key_Tab);
18161818
1817− var spreadFlickable = findChild(shell, "spreadFlickable")
1819+ var spreadFlickable = findChild(shell, "spreadFlickable");
1820+ waitForRendering(spreadFlickable);
18181821
18191822 compare(spreadFlickable.contentX, 0);
18201823
18211824 // Move the mouse to the right and make sure it scrolls the Flickable
18221825 var x = 0;
1823− var y = shell.height * .5
1826+ var y = shell.height * .5;
18241827 mouseMove(shell, x, y)
18251828 while (x <= shell.width) {
18261829 x+=10;
1827− mouseMove(shell, x, y)
1828− wait(0); // spin the loop so bindings get evaluated
1830+ mouseMove(shell, x, y);
1831+ wait(1); // spin the loop so bindings get evaluated
18291832 }
18301833 tryCompare(spreadFlickable, "contentX", spreadFlickable.contentWidth - spreadFlickable.width);
18311834
@@ -1833,7 +1836,7 @@ Rectangle {
18331836 while (x > 0) {
18341837 x-=10;
18351838 mouseMove(shell, x, y)
1836− wait(0); // spin the loop so bindings get evaluated
1839+ wait(1); // spin the loop so bindings get evaluated
18371840 }
18381841 tryCompare(spreadFlickable, "contentX", 0);
18391842