2 * Copyright (C) 2013 Canonical, Ltd.
5 * Daniel d'Andrada <daniel.dandrada@canonical.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23import Unity.Application 0.1
24import Unity.Test 0.1 as UT
34 id: applicationArguments
36 function hasGeometry() {
57 function initTestCase() {
60 var maxAttempts = 1000;
62 // Qt loads a qml scene asynchronously. So early on, some findChild() calls made in
63 // tests may fail because the desired child item wasn't loaded yet.
64 // Thus here we try to ensure the scene has been fully loaded before proceeding with the tests.
65 // As I couldn't find an API in QQuickView & friends to tell me that the scene is 100% loaded
66 // (all items instantiated, etc), I resort to checking the existence of some key items until
67 // repeatedly until they're all there.
69 var dashContentList = findChild(shell, "dashContentList");
70 waitForRendering(dashContentList);
71 var homeLoader = findChild(dashContentList, "clickscope loader");
72 ok = homeLoader !== null
73 && homeLoader.item !== undefined;
75 var greeter = findChild(shell, "greeter");
76 ok &= greeter !== null;
78 var launcherPanel = findChild(shell, "launcherPanel");
79 ok &= launcherPanel !== null;
83 console.log("Attempt " + attempts + " failed. Waiting a bit before trying again.");
84 // wait a bit before retrying
87 console.log("All seem fine after " + attempts + " attempts.");
89 } while (!ok && attempts <= maxAttempts);
97 // If a test invoked the greeter, make sure we swipe it away again
98 var greeter = findChild(shell, "greeter");
103 // kill all (fake) running apps
104 killApps(ApplicationManager);
106 var dashContent = findChild(shell, "dashContent");
107 dashContent.closePreview();
109 var dashHome = findChild(shell, "clickscope loader");
110 swipeUntilScopeViewIsReached(dashHome);
115 function killApps(apps) {
117 while (apps.count > 0) {
118 ApplicationManager.stopApplication(apps.get(0).appId);
120 compare(ApplicationManager.count, 0)
124 Test the effect of a right-edge drag on the dash in 3 situations:
125 1 - when no application has been launched yet
126 2 - when there's a minimized application
127 3 - after the last running application has been closed/stopped
129 The behavior of Dash on 3 should be the same as on 1.
131 function test_rightEdgeDrag() {
132 checkRightEdgeDragWithNoRunningApps();
134 dragLauncherIntoView();
136 // Launch an app from the launcher
137 tapOnAppIconInLauncher();
138 waitUntilApplicationWindowIsFullyVisible();
140 // Minimize the application we just launched
141 swipeFromLeftEdge(units.gu(27));
145 checkRightEdgeDragWithMinimizedApp();
147 // Minimize that application once again
148 swipeFromLeftEdge(units.gu(27));
150 // Right edge behavior should now be the same as before that app,
151 // was launched. Manually cleanup beforehand to get to initial
155 checkRightEdgeDragWithNoRunningApps();
158 function test_leftEdgeDrag_data() {
160 {tag: "without launcher", revealLauncher: false, swipeLength: units.gu(27), appHides: true},
161 {tag: "with launcher", revealLauncher: true, swipeLength: units.gu(27), appHides: true},
162 {tag: "small swipe", revealLauncher: false, swipeLength: units.gu(25), appHides: false},
163 {tag: "long swipe", revealLauncher: false, swipeLength: units.gu(27), appHides: true}
167 function test_leftEdgeDrag(data) {
168 dragLauncherIntoView();
169 tapOnAppIconInLauncher();
170 waitUntilApplicationWindowIsFullyVisible();
172 if (data.revealLauncher) {
173 dragLauncherIntoView();
176 swipeFromLeftEdge(data.swipeLength);
178 waitUntilApplicationWindowIsFullyHidden();
180 waitUntilApplicationWindowIsFullyVisible();
183 function test_suspend() {
184 var greeter = findChild(shell, "greeter");
186 // Launch an app from the launcher
187 dragLauncherIntoView();
188 tapOnAppIconInLauncher();
189 waitUntilApplicationWindowIsFullyVisible();
191 var mainAppId = ApplicationManager.focusedApplicationId;
192 verify(mainAppId != "");
193 var mainApp = ApplicationManager.findApplication(mainAppId);
195 tryCompare(mainApp, "state", ApplicationInfo.Running);
197 // Try to suspend while proximity is engaged...
198 Powerd.displayPowerStateChange(Powerd.Off, Powerd.Proximity);
199 tryCompare(greeter, "showProgress", 0);
201 // Now really suspend
203 Powerd.displayPowerStateChange(Powerd.Off, 0);
204 print("done suspending")
205 tryCompare(greeter, "showProgress", 1);
207 tryCompare(ApplicationManager, "suspended", true);
208 compare(mainApp.state, ApplicationInfo.Suspended);
211 Powerd.displayPowerStateChange(Powerd.On, 0);
212 tryCompare(greeter, "showProgress", 1);
214 // Swipe away greeter to focus app
216 tryCompare(ApplicationManager, "suspended", false);
217 compare(mainApp.state, ApplicationInfo.Running);
218 tryCompare(ApplicationManager, "focusedApplicationId", mainAppId);
221 function swipeAwayGreeter() {
222 var greeter = findChild(shell, "greeter");
223 tryCompare(greeter, "showProgress", 1);
225 var touchX = shell.width - (shell.edgeSize / 2);
226 var touchY = shell.height / 2;
227 touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY);
229 // wait until the animation has finished
230 tryCompare(greeter, "showProgress", 0);
234 Perform a right-edge drag when the Dash is being show and there are
235 no running/minimized apps to be restored.
237 The expected behavior is that an animation should be played to hint the
238 user that his right-edge drag gesture has been successfully recognized
239 but there is no application to be brought to foreground.
241 function checkRightEdgeDragWithNoRunningApps() {
242 var touchX = shell.width - (shell.edgeSize / 2);
243 var touchY = shell.height / 2;
245 var dash = findChild(shell, "dash");
246 // check that dash has normal scale and opacity
247 tryCompare(dash, "contentScale", 1.0);
248 tryCompare(dash, "opacity", 1.0);
250 touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY,
251 true /* beginTouch */, false /* endTouch */, units.gu(10), 50);
253 // check that Dash has been scaled down and had its opacity reduced
254 tryCompareFunction(function() { return dash.contentScale <= 0.9; }, true);
255 tryCompareFunction(function() { return dash.opacity <= 0.5; }, true);
257 touchRelease(shell, shell.width * 0.1, touchY);
259 // and now everything should have gone back to normal
260 tryCompare(dash, "contentScale", 1.0);
261 tryCompare(dash, "opacity", 1.0);
265 Perform a right-edge drag when the Dash is being show and there is
266 a running/minimized app to be restored.
268 The expected behavior is that the dash should fade away and ultimately be
269 made invisible once the gesture is finished as the restored app will now
272 function checkRightEdgeDragWithMinimizedApp() {
273 var touchX = shell.width - (shell.edgeSize / 2);
274 var touchY = shell.height / 2;
276 var dash = findChild(shell, "dash");
277 // check that dash has normal scale and opacity
278 tryCompare(dash, "contentScale", 1.0);
279 tryCompare(dash, "opacity", 1.0);
281 touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY,
282 true /* beginTouch */, false /* endTouch */, units.gu(10), 50);
284 // check that Dash has been scaled down and had its opacity reduced
285 tryCompareFunction(function() { return dash.contentScale <= 0.9; }, true);
286 tryCompareFunction(function() { return dash.opacity <= 0.5; }, true);
288 touchRelease(shell, shell.width * 0.1, touchY);
290 // dash should have gone away, now that the app is on foreground
291 tryCompare(dash, "visible", false);
295 Regression test for bug https://bugs.launchpad.net/touch-preview-images/+bug/1193419
297 When the user minimizes an application (left-edge swipe) he should always end up in the "Running Apps"
298 category of the "Applications" scope view.
302 - scroll to the bottom
303 - reveal launcher and launch an app
304 - perform long left edge swipe to go minimize the app and go back to the dash.
307 - apps lens shown and Running Apps visible on screen
309 function test_minimizingAppTakesToRunningApps() {
310 var dashApps = findChild(shell, "clickscope");
311 swipeUntilScopeViewIsReached(dashApps);
313 // swipe finger up until the running/recent apps section (which we assume
314 // it's the first one) is as far from view as possible.
315 // We also assume that DashApps is tall enough that it's scrollable
316 var appsCategoryListView = findChild(dashApps, "categoryListView");
317 while (!appsCategoryListView.atYEnd) {
319 tryCompare(appsCategoryListView, "moving", false);
322 // Switch away from the Applications scope.
323 swipeRightFromCenter();
324 waitUntilItemStopsMoving(dashApps);
325 verify(!itemIsOnScreen(dashApps));
327 dragLauncherIntoView();
329 // Launch an app from the launcher
330 tapOnAppIconInLauncher();
332 waitUntilApplicationWindowIsFullyVisible();
334 // Dragging launcher into view with a little bit of gap (units.gu(1)) should switch to Apps scope
335 dragLauncherIntoView();
336 verify(itemIsOnScreen(dashApps));
338 // Minimize the application we just launched
339 swipeFromLeftEdge(units.gu(27));
341 // Wait for the whole UI to settle down
342 waitUntilApplicationWindowIsFullyHidden();
343 waitUntilItemStopsMoving(dashApps);
344 tryCompare(appsCategoryListView, "moving", false);
346 verify(itemIsOnScreen(dashApps));
348 var runningApplicationsGrid = findChild(appsCategoryListView, "running.apps.category");
349 verify(runningApplicationsGrid);
350 verify(itemIsOnScreen(runningApplicationsGrid));
353 // Wait for the whole UI to settle down
354 function waitForUIToSettle() {
355 waitUntilApplicationWindowIsFullyHidden();
356 var dashContentList = findChild(shell, "dashContentList");
357 tryCompare(dashContentList, "moving", false);
360 function dragLauncherIntoView() {
361 var launcherPanel = findChild(shell, "launcherPanel");
362 verify(launcherPanel.x = - launcherPanel.width);
365 var touchStartY = shell.height / 2;
366 touchFlick(shell, touchStartX, touchStartY, launcherPanel.width + units.gu(1), touchStartY);
368 tryCompare(launcherPanel, "x", 0);
371 function tapOnAppIconInLauncher() {
372 var launcherPanel = findChild(shell, "launcherPanel");
374 // pick the first icon, the one at the bottom.
375 var appIcon = findChild(launcherPanel, "launcherDelegate0")
377 // Swipe upwards over the launcher to ensure that this icon
378 // at the bottom is not folded and faded away.
379 var touchStartX = launcherPanel.width / 2;
380 var touchStartY = launcherPanel.height / 2;
381 touchFlick(launcherPanel, touchStartX, touchStartY, touchStartX, 0);
382 tryCompare(launcherPanel, "moving", false);
384 // NB tapping (i.e., using touch events) doesn't activate the icon... go figure...
385 mouseClick(appIcon, appIcon.width / 2, appIcon.height / 2);
388 function showIndicators() {
389 var indicators = findChild(shell, "indicators");
391 tryCompare(indicators, "fullyOpened", true);
394 function hideIndicators() {
395 var indicators = findChild(shell, "indicators");
396 if (indicators.fullyOpened) {
401 function waitUntilApplicationWindowIsFullyVisible() {
402 var underlay = findChild(shell, "underlay");
403 tryCompare(underlay, "visible", false);
406 function waitUntilApplicationWindowIsFullyHidden() {
407 var stages = findChild(shell, "stages");
408 tryCompare(stages, "fullyHidden", true);
411 function swipeUntilScopeViewIsReached(scopeView) {
412 while (!itemIsOnScreen(scopeView)) {
413 if (itemIsToLeftOfScreen(scopeView)) {
414 swipeRightFromCenter();
416 swipeLeftFromCenter();
418 waitUntilItemStopsMoving(scopeView);
422 function swipeFromLeftEdge(swipeLength) {
424 var touchStartY = shell.height / 2;
425 touchFlick(shell, touchStartX, touchStartY, swipeLength, touchStartY);
428 function swipeLeftFromCenter() {
429 var touchStartX = shell.width * 3 / 4;
430 var touchStartY = shell.height / 2;
431 touchFlick(shell, touchStartX, touchStartY, 0, touchStartY);
434 function swipeRightFromCenter() {
435 var touchStartX = shell.width * 3 / 4;
436 var touchStartY = shell.height / 2;
437 touchFlick(shell, touchStartX, touchStartY, shell.width, touchStartY);
440 function swipeUpFromCenter() {
441 var touchStartX = shell.width / 2;
442 var touchStartY = shell.height / 2;
443 touchFlick(shell, touchStartX, touchStartY, touchStartX, 0);
446 function itemIsOnScreen(item) {
447 var itemRectInShell = item.mapToItem(shell, 0, 0, item.width, item.height);
449 return itemRectInShell.x >= 0
450 && itemRectInShell.y >= 0
451 && itemRectInShell.x + itemRectInShell.width <= shell.width
452 && itemRectInShell.y + itemRectInShell.height <= shell.height;
455 function itemIsToLeftOfScreen(item) {
456 var itemRectInShell = item.mapToItem(shell, 0, 0, item.width, item.height);
457 return itemRectInShell.x < 0;
460 function waitUntilItemStopsMoving(item) {
461 var itemRectInShell = item.mapToItem(shell, 0, 0, item.width, item.height);
462 var previousX = itemRectInShell.x;
463 var previousY = itemRectInShell.y;
468 itemRectInShell = item.mapToItem(shell, 0, 0, item.width, item.height);
469 if (itemRectInShell.x == previousX && itemRectInShell.y == previousY) {
472 previousX = itemRectInShell.x;
473 previousY = itemRectInShell.y;
478 function test_DashShown_data() {
480 {tag: "in focus", greeter: false, app: false, launcher: false, indicators: false, expectedShown: true},
481 {tag: "under greeter", greeter: true, app: false, launcher: false, indicators: false, expectedShown: false},
482 {tag: "under app", greeter: false, app: true, launcher: false, indicators: false, expectedShown: false},
483 {tag: "under launcher", greeter: false, app: false, launcher: true, indicators: false, expectedShown: true},
484 {tag: "under indicators", greeter: false, app: false, launcher: false, indicators: true, expectedShown: true},
488 function test_DashShown(data) {
490 // Swipe the greeter in
491 var greeter = findChild(shell, "greeter");
492 Powerd.displayPowerStateChange(Powerd.Off, 0);
493 tryCompare(greeter, "showProgress", 1);
497 dragLauncherIntoView();
498 tapOnAppIconInLauncher();
502 dragLauncherIntoView();
505 if (data.indicators) {
509 var dash = findChild(shell, "dash");
510 tryCompare(dash, "shown", data.expectedShown);
513 function test_focusRequestedHidesGreeter() {
514 var greeter = findChild(shell, "greeter")
517 tryCompare(greeter, "showProgress", 1)
519 ApplicationManager.focusRequested("notes-app")
520 tryCompare(greeter, "showProgress", 0)
521 waitUntilApplicationWindowIsFullyVisible()
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list