@@ -21,6 +21,7 @@ import QtQuick 2.0
2121import QtTest 1.0
2222import Ubuntu.Application 0.1
2323import Unity.Test 0.1 as UT
24+import Powerd 0.1
2425
2526import "../.."
2627
@@ -53,26 +54,29 @@ Item {
5354 when: windowShown
5455
5556 function initTestCase() {
56− // swipe away the greeter/lockscreen
57− var touchX = shell.width - (shell.edgeSize / 2);
58− var touchY = shell.height / 2;
59− touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY);
60−
61− var dash = findChild(shell, "dash");
62− // wait until the animation has finished
63− tryCompare(dash, "contentScale", 1.0);
64− tryCompare(dash, "opacity", 1.0);
57+ swipeAwayGreeter();
6558 }
6659
6760 function cleanup() {
61+ // If a test invoked the greeter, make sure we swipe it away again
62+ var greeter = findChild(shell, "greeter");
63+ if (greeter.shown)
64+ swipeAwayGreeter();
65+
6866 // kill all (fake) running apps
69− ApplicationManager.mainStageApplications.clear();
70− ApplicationManager.sideStageApplications.clear();
67+ killApps(ApplicationManager.mainStageApplications);
68+ killApps(ApplicationManager.sideStageApplications);
7169
7270 var dashHome = findChild(shell, "DashHome");
7371 swipeUntilScopeViewIsReached(dashHome);
7472 }
7573
74+ function killApps(apps) {
75+ while (apps.count > 0) {
76+ ApplicationManager.stopProcess(apps.get(0));
77+ }
78+ }
79+
7680 /*
7781 Test the effect of a right-edge drag on the dash in 3 situations:
7882 1 - when no application has been launched yet
@@ -100,15 +104,48 @@ Item {
100104 // Minimize that application once again
101105 swipeFromLeftEdge();
102106
103− // kill it
104− ApplicationManager.mainStageApplications.clear();
105−
107+ // Right edge behavior should now be the same as before that app,
108+ // was launched. Manually cleanup beforehand to get to initial
109+ // state.
110+ cleanup();
106111 waitForUIToSettle();
107−
108− // Right edge behavior should now be the same as before that app was launched
109112 checkRightEdgeDragWithNoRunningApps();
110113 }
111114
115+ function test_suspend() {
116+ var greeter = findChild(shell, "greeter");
117+
118+ // Launch an app from the launcher
119+ dragLauncherIntoView();
120+ tapOnAppIconInLauncher();
121+ waitUntilApplicationWindowIsFullyVisible();
122+
123+ var mainApp = ApplicationManager.mainStageFocusedApplication;
124+ tryCompareFunction(function() { return mainApp != null; }, true);
125+
126+ // Now suspend
127+ Powerd.powerStateChange(0);
128+ tryCompare(greeter, "showProgress", 1);
129+ tryCompare(ApplicationManager, "mainStageFocusedApplication", null);
130+
131+ // And wake up
132+ Powerd.powerStateChange(1);
133+ tryCompare(ApplicationManager, "mainStageFocusedApplication", mainApp);
134+ tryCompare(greeter, "showProgress", 1);
135+ }
136+
137+ function swipeAwayGreeter() {
138+ var greeter = findChild(shell, "greeter");
139+ tryCompare(greeter, "showProgress", 1);
140+
141+ var touchX = shell.width - (shell.edgeSize / 2);
142+ var touchY = shell.height / 2;
143+ touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY);
144+
145+ // wait until the animation has finished
146+ tryCompare(greeter, "showProgress", 0);
147+ }
148+
112149 /*
113150 Perform a right-edge drag when the Dash is being show and there are
114151 no running/minimized apps to be restored.
@@ -123,8 +160,8 @@ Item {
123160
124161 var dash = findChild(shell, "dash");
125162 // check that dash has normal scale and opacity
126− compare(dash.contentScale, 1.0);
127− compare(dash.opacity, 1.0);
163+ tryCompare(dash.contentScale, 1.0);
164+ tryCompare(dash.opacity, 1.0);
128165
129166 touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY,
130167 true /* beginTouch */, false /* endTouch */);