@@ -0,0 +1,248 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Daniel d'Andrada <daniel.dandrada@canonical.com>
6+ *
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.
10+ *
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.
15+ *
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/>.
18+ */
19+
20+import QtQuick 2.0
21+import QtTest 1.0
22+import Unity.Test 0.1 as UT
23+import Ubuntu.Application 0.1
24+import GSettings 1.0
25+
26+import "../.."
27+
28+Shell {
29+ id: shell
30+ UT.UnityTestCase {
31+ name: "Shell"
32+ when: windowShown
33+
34+ function initTestCase() {
35+ // swipe away the greeter/lockscreen
36+ var touchX = shell.width - (shell.edgeSize / 2);
37+ var touchY = shell.height / 2;
38+ touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY);
39+
40+ // wait until the animation has finished
41+
42+ var dash = findChild(shell, "dash");
43+ tryCompare(dash, "contentScale", 1.0);
44+ tryCompare(dash, "opacity", 1.0);
45+
46+ var greeter = findChild(shell, "greeter");
47+ tryCompare(greeter, "x", -greeter.width);
48+ }
49+
50+ function cleanup() {
51+ // kill all (fake) running apps
52+ ApplicationManager.mainStageApplications.clear();
53+ ApplicationManager.sideStageApplications.clear();
54+
55+ var dashHome = findChild(shell, "DashHome");
56+ swipeUntilScopeViewIsReached(dashHome);
57+ }
58+
59+ /*
60+ Perform a right-edge drag when the Dash is being show and there are
61+ no running/minimized apps to be restored.
62+
63+ The expected behavior is that an animation should be played to hint the
64+ user that his right-edge drag gesture has been successfully recognized
65+ but there is no application to be brought to foreground.
66+ */
67+ function test_rightEdgeDragWithNoRunningApps() {
68+ var touchX = shell.width - (shell.edgeSize / 2);
69+ var touchY = shell.height / 2;
70+
71+ var dash = findChild(shell, "dash");
72+ // check that dash has normal scale and opacity
73+ compare(dash.contentScale, 1.0);
74+ compare(dash.opacity, 1.0);
75+
76+ touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY,
77+ true /* beginTouch */, false /* endTouch */);
78+
79+ // check that Dash has been scaled down and had its opacity reduced
80+ tryCompareFunction(function() { return dash.contentScale <= 0.9; }, true);
81+ tryCompareFunction(function() { return dash.opacity <= 0.5; }, true);
82+
83+ touchRelease(shell, shell.width * 0.1, touchY);
84+
85+ // and now everything should have gone back to normal
86+ tryCompare(dash, "contentScale", 1.0);
87+ tryCompare(dash, "opacity", 1.0);
88+ }
89+
90+ /*
91+ Regression test for bug https://bugs.launchpad.net/touch-preview-images/+bug/1193419
92+
93+ When the user minimizes an application (left-edge swipe) he should always end up in the "Running Apps"
94+ category of the "Applications" scope view.
95+
96+ Steps:
97+ - go to apps lens
98+ - scroll to the bottom
99+ - reveal launcher and launch an app
100+ - perform long left edge swipe to go minimize the app and go back to the dash.
101+
102+ Expected Results
103+ - apps lens shown and Running Apps visible on screen
104+ */
105+ function test_minimizingAppTakesToRunningApps() {
106+ var dashApps = findChild(shell, "DashApps");
107+
108+ swipeUntilScopeViewIsReached(dashApps);
109+
110+ // swipe finger up until the running/recent apps section (which we assume
111+ // it's the first one) is as far from view as possible.
112+ var appsCategoryListView = findChild(dashApps, "categoryListView");
113+ while (!appsCategoryListView.atYEnd) {
114+ swipeUpFromCenter();
115+ tryCompare(appsCategoryListView, "moving", false);
116+ }
117+
118+ // Switch away from the Applications scope.
119+ swipeRightFromCenter();
120+ waitUntilItemStopsMoving(dashApps);
121+ verify(!itemIsOnScreen(dashApps));
122+
123+ dragLauncherIntoView();
124+
125+ // Launch an app from the launcher
126+ tapOnAppIconInLauncher();
127+
128+ waitUntilApplicationWindowIsFullyVisible();
129+
130+ // Minimize the application we just launched
131+ swipeFromLeftEdge();
132+
133+ // Wait for the whole UI to settle down
134+ waitUntilApplicationWindowIsFullyHidden();
135+ waitUntilItemStopsMoving(dashApps);
136+ tryCompare(appsCategoryListView, "moving", false);
137+
138+ verify(itemIsOnScreen(dashApps));
139+ var runningApplicationsGrid = findChild(dashApps, "runningApplicationsGrid");
140+ verify(itemIsOnScreen(runningApplicationsGrid));
141+ }
142+
143+ function dragLauncherIntoView() {
144+ var launcherPanel = findChild(shell, "launcherPanel");
145+ verify(launcherPanel.x = - launcherPanel.width);
146+ swipeFromLeftEdge();
147+ tryCompare(launcherPanel, "x", 0);
148+ }
149+
150+ function tapOnAppIconInLauncher() {
151+ var launcherPanel = findChild(shell, "launcherPanel");
152+
153+ // pick the first icon, the one at the bottom.
154+ var appIcon = findChild(launcherPanel, "launcherDelegate0")
155+
156+ // Swipe upwards over the launcher to ensure that this icon
157+ // at the bottom is not folded and faded away.
158+ var touchStartX = launcherPanel.width / 2;
159+ var touchStartY = launcherPanel.height / 2;
160+ touchFlick(launcherPanel, touchStartX, touchStartY, touchStartX, 0);
161+ tryCompare(launcherPanel, "moving", false);
162+
163+ // NB tapping (i.e., using touch events) doesn't activate the icon... go figure...
164+ mouseClick(appIcon, appIcon.width / 2, appIcon.height / 2);
165+ }
166+
167+ function waitUntilApplicationWindowIsFullyVisible() {
168+ var underlay = findChild(shell, "underlay");
169+ tryCompare(underlay, "visible", false);
170+ }
171+
172+ function waitUntilApplicationWindowIsFullyHidden() {
173+ var stages = findChild(shell, "stages");
174+ tryCompare(stages, "fullyHidden", true);
175+ }
176+
177+ function swipeUntilScopeViewIsReached(scopeView) {
178+ while (!itemIsOnScreen(scopeView)) {
179+ if (itemIsToLeftOfScreen(scopeView)) {
180+ swipeRightFromCenter();
181+ } else {
182+ swipeLeftFromCenter();
183+ }
184+ waitUntilItemStopsMoving(scopeView);
185+ }
186+ }
187+
188+ function swipeFromLeftEdge() {
189+ var touchStartX = 2;
190+ var touchStartY = shell.height / 2;
191+ touchFlick(shell, touchStartX, touchStartY, shell.width * 0.75, touchStartY);
192+ }
193+
194+ function swipeLeftFromCenter() {
195+ var touchStartX = shell.width / 2;
196+ var touchStartY = shell.height / 2;
197+ touchFlick(shell, touchStartX, touchStartY, 0, touchStartY);
198+ }
199+
200+ function swipeRightFromCenter() {
201+ var touchStartX = shell.width / 2;
202+ var touchStartY = shell.height / 2;
203+ touchFlick(shell, touchStartX, touchStartY, shell.width, touchStartY);
204+ }
205+
206+ function swipeUpFromCenter() {
207+ var touchStartX = shell.width / 2;
208+ var touchStartY = shell.height / 2;
209+ touchFlick(shell, touchStartX, touchStartY, touchStartX, 0);
210+ }
211+
212+ function waitUntilItemStopsMoving(item) {
213+ var itemRectInShell = item.mapToItem(shell, 0, 0, item.width, item.height);
214+ var previousX = itemRectInShell.x;
215+ var previousY = itemRectInShell.y;
216+ var isStill = false;
217+
218+ do {
219+ wait(100);
220+ itemRectInShell = item.mapToItem(shell, 0, 0, item.width, item.height);
221+ if (itemRectInShell.x == previousX && itemRectInShell.y == previousY) {
222+ isStill = true;
223+ } else {
224+ previousX = itemRectInShell.x;
225+ previousY = itemRectInShell.y;
226+ }
227+ } while (!isStill);
228+ }
229+
230+ function itemIsOnScreen(item) {
231+ var itemRectInShell = item.mapToItem(shell, 0, 0, item.width, item.height);
232+
233+ return itemRectInShell.x >= 0
234+ && itemRectInShell.y >= 0
235+ && itemRectInShell.x + itemRectInShell.width <= shell.width
236+ && itemRectInShell.y + itemRectInShell.height <= shell.height;
237+ }
238+
239+ function itemIsToLeftOfScreen(item) {
240+ var itemRectInShell = item.mapToItem(shell, 0, 0, item.width, item.height);
241+ return itemRectInShell.x < 0;
242+ }
243+
244+ function test_wallpaper() {
245+
246+ }
247+ }
248+}