@@ -20,6 +20,7 @@
2020import QtQuick 2.0
2121import QtTest 1.0
2222import Unity.Test 0.1 as UT
23+import Ubuntu.Application 0.1
2324
2425import "../.."
2526
@@ -35,10 +36,23 @@ Shell {
3536 var touchY = shell.height / 2;
3637 touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY);
3738
38− var dash = findChild(shell, "dash");
3939 // wait until the animation has finished
40+
41+ var dash = findChild(shell, "dash");
4042 tryCompare(dash, "contentScale", 1.0);
4143 tryCompare(dash, "opacity", 1.0);
44+
45+ var greeter = findChild(shell, "greeter");
46+ tryCompare(greeter, "x", -greeter.width);
47+ }
48+
49+ function cleanup() {
50+ // kill all (fake) running apps
51+ ApplicationManager.mainStageApplications.clear();
52+ ApplicationManager.sideStageApplications.clear();
53+
54+ var dashHome = findChild(shell, "DashHome");
55+ swipeUntilScopeViewIsReached(dashHome);
4256 }
4357
4458 /*
@@ -71,5 +85,159 @@ Shell {
7185 tryCompare(dash, "contentScale", 1.0);
7286 tryCompare(dash, "opacity", 1.0);
7387 }
88+
89+ /*
90+ Regression test for bug https://bugs.launchpad.net/touch-preview-images/+bug/1193419
91+
92+ When the user minimizes an application (left-edge swipe) he should always end up in the "Running Apps"
93+ category of the "Applications" scope view.
94+
95+ Steps:
96+ - go to apps lens
97+ - scroll to the bottom
98+ - reveal launcher and launch an app
99+ - perform long left edge swipe to go minimize the app and go back to the dash.
100+
101+ Expected Results
102+ - apps lens shown and Running Apps visible on screen
103+ */
104+ function test_minimizingAppTakesToRunningApps() {
105+ var dashApps = findChild(shell, "DashApps");
106+
107+ swipeUntilScopeViewIsReached(dashApps);
108+
109+ // swipe finger up until the running/recent apps section (which we assume
110+ // it's the first one) is as far from view as possible.
111+ var appsCategoryListView = findChild(dashApps, "categoryListView");
112+ while (!appsCategoryListView.atYEnd) {
113+ swipeUpFromCenter();
114+ tryCompare(appsCategoryListView, "moving", false);
115+ }
116+
117+ // Switch away from the Applications scope.
118+ swipeRightFromCenter();
119+ waitUntilItemStopsMoving(dashApps);
120+ verify(!itemIsOnScreen(dashApps));
121+
122+ dragLauncherIntoView();
123+
124+ // Launch an app from the launcher
125+ tapOnAppIconInLauncher();
126+
127+ waitUntilApplicationWindowIsFullyVisible();
128+
129+ // Minimize the application we just launched
130+ swipeFromLeftEdge();
131+
132+ // Wait for the whole UI to settle down
133+ waitUntilApplicationWindowIsFullyHidden();
134+ waitUntilItemStopsMoving(dashApps);
135+ tryCompare(appsCategoryListView, "moving", false);
136+
137+ verify(itemIsOnScreen(dashApps));
138+ var runningApplicationsGrid = findChild(dashApps, "runningApplicationsGrid");
139+ verify(itemIsOnScreen(runningApplicationsGrid));
140+ }
141+
142+ function dragLauncherIntoView() {
143+ var launcherPanel = findChild(shell, "launcherPanel");
144+ verify(launcherPanel.x = - launcherPanel.width);
145+ swipeFromLeftEdge();
146+ tryCompare(launcherPanel, "x", 0);
147+ }
148+
149+ function tapOnAppIconInLauncher() {
150+ var launcherPanel = findChild(shell, "launcherPanel");
151+
152+ // pick the first icon, the one at the bottom.
153+ var appIcon = findChild(launcherPanel, "launcherDelegate0")
154+
155+ // Swipe upwards over the launcher to ensure that this icon
156+ // at the bottom is not folded and faded away.
157+ var touchStartX = launcherPanel.width / 2;
158+ var touchStartY = launcherPanel.height / 2;
159+ touchFlick(launcherPanel, touchStartX, touchStartY, touchStartX, 0);
160+ tryCompare(launcherPanel, "moving", false);
161+
162+ // NB tapping (i.e., using touch events) doesn't activate the icon... go figure...
163+ mouseClick(appIcon, appIcon.width / 2, appIcon.height / 2);
164+ }
165+
166+ function waitUntilApplicationWindowIsFullyVisible() {
167+ var underlay = findChild(shell, "underlay");
168+ tryCompare(underlay, "visible", false);
169+ }
170+
171+ function waitUntilApplicationWindowIsFullyHidden() {
172+ var stages = findChild(shell, "stages");
173+ tryCompare(stages, "fullyHidden", true);
174+ }
175+
176+ function swipeUntilScopeViewIsReached(scopeView) {
177+ while (!itemIsOnScreen(scopeView)) {
178+ if (itemIsToLeftOfScreen(scopeView)) {
179+ swipeRightFromCenter();
180+ } else {
181+ swipeLeftFromCenter();
182+ }
183+ waitUntilItemStopsMoving(scopeView);
184+ }
185+ }
186+
187+ function swipeFromLeftEdge() {
188+ var touchStartX = 2;
189+ var touchStartY = shell.height / 2;
190+ touchFlick(shell, touchStartX, touchStartY, shell.width * 0.75, touchStartY);
191+ }
192+
193+ function swipeLeftFromCenter() {
194+ var touchStartX = shell.width / 2;
195+ var touchStartY = shell.height / 2;
196+ touchFlick(shell, touchStartX, touchStartY, 0, touchStartY);
197+ }
198+
199+ function swipeRightFromCenter() {
200+ var touchStartX = shell.width / 2;
201+ var touchStartY = shell.height / 2;
202+ touchFlick(shell, touchStartX, touchStartY, shell.width, touchStartY);
203+ }
204+
205+ function swipeUpFromCenter() {
206+ var touchStartX = shell.width / 2;
207+ var touchStartY = shell.height / 2;
208+ touchFlick(shell, touchStartX, touchStartY, touchStartX, 0);
209+ }
210+
211+ function waitUntilItemStopsMoving(item) {
212+ var itemRectInShell = item.mapToItem(shell, 0, 0, item.width, item.height);
213+ var previousX = itemRectInShell.x;
214+ var previousY = itemRectInShell.y;
215+ var isStill = false;
216+
217+ do {
218+ wait(100);
219+ itemRectInShell = item.mapToItem(shell, 0, 0, item.width, item.height);
220+ if (itemRectInShell.x == previousX && itemRectInShell.y == previousY) {
221+ isStill = true;
222+ } else {
223+ previousX = itemRectInShell.x;
224+ previousY = itemRectInShell.y;
225+ }
226+ } while (!isStill);
227+ }
228+
229+ function itemIsOnScreen(item) {
230+ var itemRectInShell = item.mapToItem(shell, 0, 0, item.width, item.height);
231+
232+ return itemRectInShell.x >= 0
233+ && itemRectInShell.y >= 0
234+ && itemRectInShell.x + itemRectInShell.width <= shell.width
235+ && itemRectInShell.y + itemRectInShell.height <= shell.height;
236+ }
237+
238+ function itemIsToLeftOfScreen(item) {
239+ var itemRectInShell = item.mapToItem(shell, 0, 0, item.width, item.height);
240+ return itemRectInShell.x < 0;
241+ }
74242 }
75243}