@@ -109,6 +109,7 @@ Rectangle {
109109 property bool itemDestroyed: false
110110 sourceComponent: Component {
111111 Shell {
112+ id: __shell
112113 property string shellMode: "full-greeter" /* default */
113114
114115 usageScenario: usageScenarioSelector.model[usageScenarioSelector.selectedIndex]
@@ -118,6 +119,10 @@ Rectangle {
118119 Component.onDestruction: {
119120 shellLoader.itemDestroyed = true;
120121 }
122+ Component.onCompleted: {
123+ var keyMapper = testCase.findChild(__shell, "physicalKeysMapper");
124+ keyMapper.controlInsteadOfAlt = true;
125+ }
121126 }
122127 }
123128 }
@@ -327,6 +332,20 @@ Rectangle {
327332 waitForGreeterToStabilize();
328333 }
329334
335+ function loadDesktopShellWithApps() {
336+ loadShell("desktop");
337+ shell.usageScenario = "desktop"
338+ waitForRendering(root)
339+ var app1 = ApplicationManager.startApplication("dialer-app")
340+ var app2 = ApplicationManager.startApplication("webbrowser-app")
341+ var app3 = ApplicationManager.startApplication("camera-app")
342+ var app4 = ApplicationManager.startApplication("facebook-webapp")
343+ var app5 = ApplicationManager.startApplication("calendar-app")
344+ var app6 = ApplicationManager.startApplication("gallery-app")
345+ var app7 = ApplicationManager.startApplication("camera-app")
346+ waitUntilAppWindowIsFullyLoaded(app7);
347+ }
348+
330349 function waitForGreeterToStabilize() {
331350 var greeter = findChild(shell, "greeter");
332351 verify(greeter);
@@ -1287,5 +1306,143 @@ Rectangle {
12871306 var launcher = findChild(shell, "launcher");
12881307 compare(launcher.inverted, data.launcherInverted);
12891308 }
1309+
1310+ function test_altTabSwitchesFocus() {
1311+ loadShell("desktop");
1312+ shell.usageScenario = "desktop"
1313+ waitForRendering(root)
1314+
1315+ var desktopStage = findChild(shell, "stage");
1316+ verify(desktopStage != null)
1317+
1318+ var app1 = ApplicationManager.startApplication("dialer-app")
1319+ waitUntilAppWindowIsFullyLoaded(app1);
1320+ var app2 = ApplicationManager.startApplication("webbrowser-app")
1321+ waitUntilAppWindowIsFullyLoaded(app2);
1322+ var app3 = ApplicationManager.startApplication("camera-app")
1323+ waitUntilAppWindowIsFullyLoaded(app3);
1324+
1325+ // Do a quick alt-tab and see if focus changes
1326+ tryCompare(app3.session.surface, "activeFocus", true)
1327+ keyClick(Qt.Key_Tab, Qt.ControlModifier)
1328+ tryCompare(app2.session.surface, "activeFocus", true)
1329+
1330+
1331+ tryCompare(desktopStage, "state", "")
1332+
1333+ // Just press Alt, make sure the spread comes up
1334+ keyPress(Qt.Key_Control);
1335+ keyClick(Qt.Key_Tab);
1336+ tryCompare(desktopStage, "state", "altTab")
1337+
1338+ // Release control, check if spread disappears
1339+ keyRelease(Qt.Key_Control)
1340+ tryCompare(desktopStage, "state", "")
1341+
1342+ // Focus should have switched back now
1343+ tryCompare(app3.session.surface, "activeFocus", true)
1344+ }
1345+
1346+ function test_altTabWrapAround() {
1347+ loadDesktopShellWithApps();
1348+
1349+ var desktopStage = findChild(shell, "stage");
1350+ verify(desktopStage !== null)
1351+
1352+ var appRepeater = findInvisibleChild(shell, "appRepeater")
1353+ verify(appRepeater !== null)
1354+
1355+ // remember the focused appId
1356+ var focused = ApplicationManager.get(ApplicationManager.findApplication(ApplicationManager.focusedApplicationId));
1357+
1358+ tryCompare(desktopStage, "state", "")
1359+
1360+ // Just press Alt, make sure the spread comes up
1361+ keyPress(Qt.Key_Control);
1362+ keyClick(Qt.Key_Tab);
1363+ tryCompare(desktopStage, "state", "altTab")
1364+ tryCompare(appRepeater, "highlightedIndex", 1)
1365+ waitForRendering(shell)
1366+
1367+ // Now press and hold Tab, make sure the highlight moves all the way but stops at the last one
1368+ // We can't simulate a pressed key with keyPress() currently, so let's inject the events
1369+ // at API level. Jump for 10 times, verify that it's still at the last one and didn't wrap around.
1370+ for (var i = 0; i < 10; i++) {
1371+ desktopStage.altTabNext(true);
1372+ wait(0); // Trigger the event loop to make sure all the things happen
1373+ }
1374+ tryCompare(appRepeater, "highlightedIndex", 6)
1375+
1376+ // Now release it once, and verify that it does wrap around with an additional Tab press
1377+ keyRelease(Qt.Key_Tab);
1378+ keyClick(Qt.Key_Tab);
1379+ tryCompare(appRepeater, "highlightedIndex", 0)
1380+
1381+ // Release control, check if spread disappears
1382+ keyRelease(Qt.Key_Control)
1383+ tryCompare(desktopStage, "state", "")
1384+
1385+ // Make sure that after wrapping around once, we have the same one focused as at the beginning
1386+ tryCompare(focused.session.surface, "activeFocus", true)
1387+ }
1388+
1389+ function test_altBackTabNavigation() {
1390+ loadDesktopShellWithApps();
1391+
1392+ var appRepeater = findInvisibleChild(shell, "appRepeater");
1393+ verify(appRepeater !== null);
1394+
1395+ keyPress(Qt.Key_Control)
1396+ keyClick(Qt.Key_Tab);
1397+ tryCompare(appRepeater, "highlightedIndex", 1);
1398+
1399+ keyClick(Qt.Key_Tab);
1400+ tryCompare(appRepeater, "highlightedIndex", 2);
1401+
1402+ keyClick(Qt.Key_Tab);
1403+ tryCompare(appRepeater, "highlightedIndex", 3);
1404+
1405+ keyClick(Qt.Key_Tab);
1406+ tryCompare(appRepeater, "highlightedIndex", 4);
1407+
1408+ keyClick(Qt.Key_Backtab);
1409+ tryCompare(appRepeater, "highlightedIndex", 3);
1410+
1411+ keyClick(Qt.Key_Backtab);
1412+ tryCompare(appRepeater, "highlightedIndex", 2);
1413+
1414+ keyClick(Qt.Key_Backtab);
1415+ tryCompare(appRepeater, "highlightedIndex", 1);
1416+
1417+ keyRelease(Qt.Key_Control);
1418+ }
1419+
1420+ function test_highlightFollowsMouse() {
1421+ loadDesktopShellWithApps()
1422+
1423+ var appRepeater = findInvisibleChild(shell, "appRepeater");
1424+ verify(appRepeater !== null);
1425+
1426+ keyPress(Qt.Key_Control)
1427+ keyClick(Qt.Key_Tab);
1428+
1429+ tryCompare(appRepeater, "highlightedIndex", 1);
1430+
1431+ var x = 0;
1432+ var y = shell.height * .75;
1433+ mouseMove(shell, x, y)
1434+
1435+ for (var i = 0; i < 7; i++) {
1436+ while (appRepeater.highlightedIndex != i && x <= 4000) {
1437+ x+=10;
1438+ mouseMove(shell, x, y)
1439+ waitForRendering(shell)
1440+ }
1441+ }
1442+
1443+ verify(y < 4000);
1444+
1445+ keyRelease(Qt.Key_Control);
1446+ }
12901447 }
12911448}