@@ -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,30 @@ 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+ }
66+
6867 // kill all (fake) running apps
69− ApplicationManager.mainStageApplications.clear();
70− ApplicationManager.sideStageApplications.clear();
68+ killApps(ApplicationManager.mainStageApplications);
69+ killApps(ApplicationManager.sideStageApplications);
7170
7271 var dashHome = findChild(shell, "DashHome");
7372 swipeUntilScopeViewIsReached(dashHome);
7473 }
7574
75+ function killApps(apps) {
76+ while (apps.count > 0) {
77+ ApplicationManager.stopProcess(apps.get(0));
78+ }
79+ }
80+
7681 /*
7782 Test the effect of a right-edge drag on the dash in 3 situations:
7883 1 - when no application has been launched yet
@@ -100,15 +105,48 @@ Item {
100105 // Minimize that application once again
101106 swipeFromLeftEdge();
102107
103− // kill it
104− ApplicationManager.mainStageApplications.clear();
105−
108+ // Right edge behavior should now be the same as before that app,
109+ // was launched. Manually cleanup beforehand to get to initial
110+ // state.
111+ cleanup();
106112 waitForUIToSettle();
107−
108− // Right edge behavior should now be the same as before that app was launched
109113 checkRightEdgeDragWithNoRunningApps();
110114 }
111115
116+ function test_suspend() {
117+ var greeter = findChild(shell, "greeter");
118+
119+ // Launch an app from the launcher
120+ dragLauncherIntoView();
121+ tapOnAppIconInLauncher();
122+ waitUntilApplicationWindowIsFullyVisible();
123+
124+ var mainApp = ApplicationManager.mainStageFocusedApplication;
125+ tryCompareFunction(function() { return mainApp != null; }, true);
126+
127+ // Now suspend
128+ Powerd.powerStateChange(0);
129+ tryCompare(greeter, "showProgress", 1);
130+ tryCompare(ApplicationManager, "mainStageFocusedApplication", null);
131+
132+ // And wake up
133+ Powerd.powerStateChange(1);
134+ tryCompare(ApplicationManager, "mainStageFocusedApplication", mainApp);
135+ tryCompare(greeter, "showProgress", 1);
136+ }
137+
138+ function swipeAwayGreeter() {
139+ var greeter = findChild(shell, "greeter");
140+ tryCompare(greeter, "showProgress", 1);
141+
142+ var touchX = shell.width - (shell.edgeSize / 2);
143+ var touchY = shell.height / 2;
144+ touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY);
145+
146+ // wait until the animation has finished
147+ tryCompare(greeter, "showProgress", 0);
148+ }
149+
112150 /*
113151 Perform a right-edge drag when the Dash is being show and there are
114152 no running/minimized apps to be restored.
@@ -123,8 +161,8 @@ Item {
123161
124162 var dash = findChild(shell, "dash");
125163 // check that dash has normal scale and opacity
126− compare(dash.contentScale, 1.0);
127− compare(dash.opacity, 1.0);
164+ tryCompare(dash.contentScale, 1.0);
165+ tryCompare(dash.opacity, 1.0);
128166
129167 touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY,
130168 true /* beginTouch */, false /* endTouch */);