on xenial help sign in
Update/Fix Drawer tests

This was going to be the interesting case since I'd recently made changes to the Drawer. * Make resetOldFocus reset focus and our knowledge of it * give appList an objectName, change tests to use it * DRY with openDrawerAndWait * Verify keyboard navigation correctly

commit3d5a91f9945d70c3fe8a69f4c71e8b59bf4942f8 authorDalton Durst <dalton@ubports.com> dateMon 13 May 2019, 20:15 (7 years ago) parentc1712df
2 files changed+68−47
qml/Launcher/Drawer.qml+4 tests/qmltests/Launcher/tst_Drawer.qml+64−47
qml/Launcher/Drawer.qml+4
@@ -105,6 +105,9 @@ FocusScope {
105105 hadFocus = false;
106106 oldSelectionStart = null;
107107 oldSelectionEnd = null;
108+ appList.currentIndex = 0;
109+ searchField.focus = false;
110+ appList.focus = false;
108111 }
109112
110113 function focusInput() {
@@ -258,6 +261,7 @@ FocusScope {
258261
259262 DrawerGridView {
260263 id: appList
264+ objectName: "drawerAppList"
261265 anchors {
262266 left: parent.left
263267 right: parent.right
tests/qmltests/Launcher/tst_Drawer.qml+64−47
@@ -112,6 +112,14 @@ StyledItem {
112112 return drawer;
113113 }
114114
115+ function openDrawerAndWait() {
116+ // Open the drawer by directly calling on the Launcher, then wait for it to animate in
117+ launcher.toggleDrawer(true);
118+ waitForRendering(launcher);
119+ waitUntilTransitionsEnd(launcher);
120+ return findChild(launcher, "drawer");
121+ }
122+
115123 function revealByEdgePush() {
116124 // Place the mouse against the window/screen edge and push beyond the barrier threshold
117125 // If the mouse did not move between two revealByEdgePush(), we need it to move out the
@@ -193,8 +201,8 @@ StyledItem {
193201 function test_launchAppFromDrawer() {
194202 dragDrawerIntoView();
195203
196− var drawerList = findChild(launcher, "drawerItemList");
197− var dialerApp = findChild(drawerList, "drawerItem_dialer-app");
204+ var appList = findChild(launcher, "drawerAppList");
205+ var dialerApp = findChild(appList, "drawerItem_dialer-app");
198206 mouseClick(dialerApp, dialerApp.width / 2, dialerApp.height / 2);
199207
200208 tryCompare(launcher, "lastSelectedApplication", "dialer-app");
@@ -207,8 +215,8 @@ StyledItem {
207215
208216 tryCompare(launcher, "focus", true);
209217
210− var drawerList = findChild(launcher, "drawerItemList");
211− var dialerApp = findChild(drawerList, "drawerItem_dialer-app");
218+ var appList = findChild(launcher, "drawerAppList");
219+ var dialerApp = findChild(appList, "drawerItem_dialer-app");
212220 mouseClick(dialerApp, dialerApp.width / 2, dialerApp.height / 2);
213221
214222 tryCompare(launcher, "focus", false);
@@ -289,58 +297,70 @@ StyledItem {
289297
290298 }
291299
292− function test_kbdNavigation() {
293− launcher.toggleDrawer(true);
294− waitForRendering(launcher);
295− waitUntilTransitionsEnd(launcher);
296− compare(launcher.lastSelectedApplication, "");
297−
298− var drawer = findChild(launcher, "drawer");
300+ function test_kbdSearch() {
301+ // Try out the keyboard navigation for the search field
302+ var drawer = openDrawerAndWait();
299303 var searchField = findChild(drawer, "searchField");
300− var sections = findChild(drawer, "drawerSections");
301− var header = findChild(drawer, "headerFocusScope");
302− var listLoader = findChild(drawer, "drawerListLoader");
303−
304− tryCompare(searchField, "activeFocus", true);
305− // for some reason, even when the searchField has activeFocus already,
306− // it won't react on key down events if they're coming in too early...
307− // let's repeat the press for a bit before giving up
308− tryCompareFunction(function() {
309− wait(10)
310− keyClick(Qt.Key_Down);
311− return sections.activeFocus;
312− }, true)
313304
314− keyClick(Qt.Key_Down);
315− tryCompare(header, "activeFocus", true);
305+ tryCompare(searchField, "focus", false);
306+ keyClick(Qt.Key_Up);
307+ tryCompare(searchField, "focus", true);
308+ keyClick(Qt.Key_Escape);
309+ tryCompare(searchField, "focus", false);
316310
317− keyClick(Qt.Key_Down);
318− tryCompare(listLoader, "activeFocus", true);
311+ // Make sure the focus doesn't get put back when reopening
312+ openDrawerAndWait();
313+ tryCompare(searchField, "focus", false);
314+ }
315+
316+ function test_kbdGrid() {
317+ // Try out the keyboard navigation around the grid
318+ var drawer = openDrawerAndWait();
319+ var searchField = findChild(drawer, "searchField");
320+ var appList = findChild(drawer, "drawerAppList");
321+
322+ tryCompare(searchField, "focus", false);
323+ tryCompare(appList, "focus", false);
324+ tryCompare(appList, "currentIndex", 0);
319325
320326 keyClick(Qt.Key_Down);
321− keyClick(Qt.Key_Left);
322− tryCompare(listLoader, "activeFocus", true);
327+ tryCompare(appList, "focus", true);
328+ tryCompare(appList, "currentIndex", 0);
323329
324− keyClick(Qt.Key_Enter);
330+ keyClick(Qt.Key_Right);
331+ tryCompare(appList, "currentIndex", 1);
325332
326− compare(launcher.lastSelectedApplication, "calendar-app");
333+ keyClick(Qt.Key_Escape);
334+ tryCompare(appList, "currentIndex", 0);
335+ tryCompare(appList, "focus", false);
327336 }
328337
329− function test_focusAppFromLauncherWhileDrawerIsOpen() {
330− // FIXME: Skipping this test because of a bug in Qt. Please enable
331− // once https://codereview.qt-project.org/#/c/184942/ is accepted
332− skip();
338+ function test_kbdFocusMoves() {
339+ // Make sure keyboard focus can move between the search field and grid
340+ var drawer = openDrawerAndWait();
341+ var searchField = findChild(drawer, "searchField");
342+ var appList = findChild(drawer, "drawerAppList");
333343
334− launcher.toggleDrawer(true);
335− waitForRendering(launcher);
336− waitUntilTransitionsEnd(launcher);
344+ keyClick(Qt.Key_Up);
345+ keyClick(Qt.Key_Down);
346+ tryCompare(appList, "focus", true);
347+ tryCompare(appList, "currentIndex", 0);
337348
349+ // Down once more to move the focus further into the app grid
350+ keyClick(Qt.Key_Down);
351+ keyClick(Qt.Key_Up);
352+ keyClick(Qt.Key_Up);
353+ tryCompare(searchField, "focus", true);
354+ }
355+
356+ function test_focusAppFromLauncherWhileDrawerIsOpen() {
357+ openDrawerAndWait();
338358 var appIcon = findChild(launcher, "launcherDelegate4")
339359
340− mouseMove(launcher, units.gu(4), launcher.height / 2)
360+ mouseMove(appIcon, appIcon.width / 2, appIcon.height / 2);
341361 mouseClick(appIcon, appIcon.width / 2, appIcon.height / 2);
342362
343− tryCompare(launcher, "state", "visibleTemporary");
363+ tryCompare(launcher, "state", "");
344364 }
345365
346366 function test_focusMovesCorrectlyBetweenLauncherAndDrawer() {
@@ -365,14 +385,11 @@ StyledItem {
365385 }
366386
367387 function test_closeWhileDragging() {
368− launcher.toggleDrawer(true);
369− waitForRendering(launcher);
370− waitUntilTransitionsEnd(launcher);
371−
372− var drawer = findChild(launcher, "drawer");
388+ var drawer = openDrawerAndWait();
389+ var handle = findChild(drawer, "drawerHandle");
373390 tryCompare(drawer.anchors, "rightMargin", -drawer.width);
374391
375− mousePress(drawer, drawer.width / 2, drawer.height / 2);
392+ mousePress(handle);
376393 mouseMove(drawer, drawer.width / 4, drawer.height / 2);
377394 tryCompare(drawer, "draggingHorizontally", true);
378395