@@ -14,7 +14,8 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−import QtQuick 2.0
17+import QtQuick 2.1
18+import QtQuick.Layouts 1.1
1819import QtTest 1.0
1920import Unity.Test 0.1 as UT
2021import ".."
@@ -32,14 +33,15 @@ Rectangle {
3233 Component.onCompleted: {
3334 root.fakeApplication = ApplicationManager.add("gallery-app");
3435 root.fakeApplication.manualSurfaceCreation = true;
35− root.fakeApplication.setState(ApplicationInfo.Starting);
36+ root.fakeApplication.setState(ApplicationInfoInterface.Starting);
3637 }
3738 property QtObject fakeApplication: null
39+ readonly property var fakeSession: fakeApplication ? fakeApplication.session : null
3840
3941 Connections {
4042 target: fakeApplication
41− onSurfaceChanged: {
42− surfaceCheckbox.checked = fakeApplication.surface !== null;
43+ onSessionChanged: {
44+ sessionCheckbox.checked = fakeApplication.session !== null
4345 }
4446 }
4547
@@ -50,15 +52,20 @@ Rectangle {
5052 application: fakeApplication
5153 }
5254 }
53− Loader {
54− id: applicationWindowLoader
55+ FocusScope {
56+ id: appFocus
5557 anchors {
5658 top: parent.top
5759 bottom: parent.bottom
5860 left: parent.left
5961 }
6062 width: units.gu(40)
61− sourceComponent: applicationWindowComponent
63+
64+ Loader {
65+ id: applicationWindowLoader
66+ anchors.fill: parent
67+ sourceComponent: applicationWindowComponent
68+ }
6269 }
6370
6471 Rectangle {
@@ -66,30 +73,55 @@ Rectangle {
6673 anchors {
6774 top: parent.top
6875 bottom: parent.bottom
69− left: applicationWindowLoader.right
76+ left: appFocus.right
7077 right: parent.right
7178 }
7279
73− Column {
80+ ColumnLayout {
7481 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
7582 spacing: units.gu(1)
76− Row {
77− anchors { left: parent.left; right: parent.right }
83+
84+ RowLayout {
85+ Layout.fillWidth: true
86+
7887 CheckBox {
79− id: surfaceCheckbox; checked: false
88+ id: sessionCheckbox; checked: false
8089 onCheckedChanged: {
8190 if (applicationWindowLoader.status !== Loader.Ready)
8291 return;
8392
84− if (checked && !fakeApplication.surface) {
85− fakeApplication.createSurface();
86− } else if (!checked && fakeApplication.surface) {
87− fakeApplication.surface.release();
93+ if (checked && !fakeApplication.session) {
94+ fakeApplication.createSession();
95+ } else if (!checked && fakeApplication.session) {
96+ fakeApplication.session.release();
8897 }
8998 }
9099 }
91− Label { text: "Surface" }
100+ Label {
101+ text: "Session"
102+ anchors.verticalCenter: parent.verticalCenter
103+ }
92104 }
105+
106+ Rectangle {
107+ border {
108+ color: "black"
109+ width: 1
110+ }
111+ anchors {
112+ left: parent.left
113+ right: parent.right
114+ }
115+ Layout.preferredHeight: sessionControl.height
116+
117+ RecursingChildSessionControl {
118+ id: sessionControl
119+ anchors { left: parent.left; right: parent.right; }
120+
121+ session: fakeSession
122+ }
123+ }
124+
93125 ListItem.ItemSelector {
94126 id: appStateSelector
95127 anchors { left: parent.left; right: parent.right }
@@ -100,13 +132,13 @@ Rectangle {
100132 "Stopped"]
101133 property int selectedApplicationState: {
102134 if (model[selectedIndex] === "Starting") {
103− return ApplicationInfo.Starting;
135+ return ApplicationInfoInterface.Starting;
104136 } else if (model[selectedIndex] === "Running") {
105− return ApplicationInfo.Running;
137+ return ApplicationInfoInterface.Running;
106138 } else if (model[selectedIndex] === "Suspended") {
107− return ApplicationInfo.Suspended;
139+ return ApplicationInfoInterface.Suspended;
108140 } else {
109− return ApplicationInfo.Stopped;
141+ return ApplicationInfoInterface.Stopped;
110142 }
111143 }
112144 onSelectedApplicationStateChanged: {
@@ -114,6 +146,7 @@ Rectangle {
114146 fakeApplication.setState(selectedApplicationState);
115147 }
116148 }
149+
117150 }
118151 }
119152
@@ -123,10 +156,10 @@ Rectangle {
123156 when: windowShown
124157
125158 // just to make them shorter
126− property int appStarting: ApplicationInfo.Starting
127− property int appRunning: ApplicationInfo.Running
128− property int appSuspended: ApplicationInfo.Suspended
129− property int appStopped: ApplicationInfo.Stopped
159+ property int appStarting: ApplicationInfoInterface.Starting
160+ property int appRunning: ApplicationInfoInterface.Running
161+ property int appSuspended: ApplicationInfoInterface.Suspended
162+ property int appStopped: ApplicationInfoInterface.Stopped
130163
131164 function setApplicationState(appState) {
132165 switch (appState) {
@@ -170,6 +203,14 @@ Rectangle {
170203 findInterestingApplicationWindowChildren();
171204 }
172205
206+ function initSession() {
207+ sessionCheckbox.checked = true;
208+ sessionControl.surfaceCheckbox.checked = true;
209+ }
210+ function cleanupSession() {
211+ sessionCheckbox.checked = false;
212+ }
213+
173214 function cleanup() {
174215 forgetApplicationWindowChildren();
175216
@@ -177,10 +218,10 @@ Rectangle {
177218 applicationWindowLoader.active = false;
178219
179220 appStateSelector.selectedIndex = 0;
180− surfaceCheckbox.checked = false;
221+ cleanupSession();
181222
182− if (fakeApplication.surface)
183− fakeApplication.surface.release();
223+ if (fakeApplication.session)
224+ fakeApplication.session.release();
184225
185226 applicationWindowLoader.active = true;
186227 }
@@ -197,7 +238,7 @@ Rectangle {
197238 verify(stateGroup.state === "splashScreen");
198239
199240 if (data.swapInitOrder) {
200− surfaceCheckbox.checked = true;
241+ initSession();
201242 } else {
202243 setApplicationState(appRunning);
203244 }
@@ -207,14 +248,14 @@ Rectangle {
207248 if (data.swapInitOrder) {
208249 setApplicationState(appRunning);
209250 } else {
210− surfaceCheckbox.checked = true;
251+ initSession();
211252 }
212253
213254 tryCompare(stateGroup, "state", "surface");
214255 }
215256
216257 function test_suspendedAppShowsSurface() {
217− surfaceCheckbox.checked = true;
258+ initSession();
218259 setApplicationState(appRunning);
219260
220261 tryCompare(stateGroup, "state", "surface");
@@ -228,7 +269,7 @@ Rectangle {
228269 }
229270
230271 function test_killedAppShowsScreenshot() {
231− surfaceCheckbox.checked = true;
272+ initSession();
232273 setApplicationState(appRunning);
233274 tryCompare(stateGroup, "state", "surface");
234275
@@ -241,13 +282,13 @@ Rectangle {
241282 setApplicationState(appStopped);
242283
243284 tryCompare(stateGroup, "state", "screenshot");
244− tryCompare(fakeApplication, "surface", null);
285+ tryCompare(fakeApplication, "session", null);
245286 }
246287
247288 function test_restartApp() {
248289 var screenshotImage = findChild(applicationWindowLoader.item, "screenshotImage");
249290
250− surfaceCheckbox.checked = true;
291+ initSession();
251292 setApplicationState(appRunning);
252293 tryCompare(stateGroup, "state", "surface");
253294 waitUntilTransitionsEnd();
@@ -259,28 +300,28 @@ Rectangle {
259300
260301 tryCompare(stateGroup, "state", "screenshot");
261302 waitUntilTransitionsEnd();
262− tryCompare(fakeApplication, "surface", null);
303+ tryCompare(fakeApplication, "session", null);
263304
264305 // and restart it
265306 setApplicationState(appStarting);
266307
267308 waitUntilTransitionsEnd();
268309 verify(stateGroup.state === "screenshot");
269− verify(fakeApplication.surface === null);
310+ verify(fakeSession === null);
270311
271312 setApplicationState(appRunning);
272313
273314 waitUntilTransitionsEnd();
274315 verify(stateGroup.state === "screenshot");
275316
276− surfaceCheckbox.checked = true;
317+ initSession();
277318
278319 tryCompare(stateGroup, "state", "surface");
279320 tryCompare(screenshotImage, "status", Image.Null);
280321 }
281322
282323 function test_appCrashed() {
283− surfaceCheckbox.checked = true;
324+ initSession();
284325 setApplicationState(appRunning);
285326 tryCompare(stateGroup, "state", "surface");
286327 waitUntilTransitionsEnd();
@@ -289,39 +330,39 @@ Rectangle {
289330 setApplicationState(appStopped);
290331
291332 tryCompare(stateGroup, "state", "screenshot");
292− tryCompare(fakeApplication, "surface", null);
333+ tryCompare(fakeApplication, "session", null);
293334 }
294335
295336 function test_keepSurfaceWhileInvisible() {
296− surfaceCheckbox.checked = true;
337+ initSession();
297338 setApplicationState(appRunning);
298339 tryCompare(stateGroup, "state", "surface");
299340 waitUntilTransitionsEnd();
300− verify(fakeApplication.surface !== null);
341+ verify(fakeSession.surface !== null);
301342
302343 applicationWindowLoader.item.visible = false;
303344
304345 waitUntilTransitionsEnd();
305346 verify(stateGroup.state === "surface");
306− verify(fakeApplication.surface !== null);
347+ verify(fakeSession.surface !== null);
307348
308349 applicationWindowLoader.item.visible = true;
309350
310351 waitUntilTransitionsEnd();
311352 verify(stateGroup.state === "surface");
312− verify(fakeApplication.surface !== null);
353+ verify(fakeSession.surface !== null);
313354 }
314355
315356 function test_touchesReachSurfaceWhenItsShown() {
316357 setApplicationState(appRunning);
317− surfaceCheckbox.checked = true;
358+ initSession();
318359
319360 tryCompare(stateGroup, "state", "surface");
320361
321362 waitUntilTransitionsEnd();
322363
323364 // Because doing stuff in C++ is a PITA we keep the counter in the interal qml impl.
324− var fakeSurface = findChild(fakeApplication.surface, "fakeSurfaceQML");
365+ var fakeSurface = findChild(fakeSession.surface, "fakeSurfaceQML");
325366 fakeSurface.touchPressCount = 0;
326367 fakeSurface.touchReleaseCount = 0;
327368
@@ -333,14 +374,25 @@ Rectangle {
333374 }
334375
335376 function test_showNothingOnSuddenSurfaceLoss() {
336− surfaceCheckbox.checked = true;
377+ initSession();
337378 setApplicationState(appRunning);
338379 tryCompare(stateGroup, "state", "surface");
339380 waitUntilTransitionsEnd();
340381
341− surfaceCheckbox.checked = false;
382+ cleanupSession();
342383
343384 verify(stateGroup.state === "void");
344385 }
386+
387+ // should be forcing active focus when interactive changes,
388+ // which will cause a FocusScope higher in the object hierarchy tp be given the focus
389+ function test_forceActiveFocusFollowsInterative() {
390+ fakeApplication.createSession();
391+ applicationWindowLoader.item.interactive = false;
392+ applicationWindowLoader.item.interactive = true;
393+ fakeSession.createSurface();
394+
395+ compare(appFocus.focus, true);
396+ }
345397 }
346398}