@@ -14,7 +14,8 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17−import QtQuick 2.0
17+import QtQuick 2.1
18+import QtQuick.Layouts 1.1
18import QtTest 1.0
19import QtTest 1.0
19import Unity.Test 0.1 as UT
20import Unity.Test 0.1 as UT
20import ".."
21import ".."
@@ -32,14 +33,15 @@ Rectangle {
32 Component.onCompleted: {
33 Component.onCompleted: {
33 root.fakeApplication = ApplicationManager.add("gallery-app");
34 root.fakeApplication = ApplicationManager.add("gallery-app");
34 root.fakeApplication.manualSurfaceCreation = true;
35 root.fakeApplication.manualSurfaceCreation = true;
35− root.fakeApplication.setState(ApplicationInfo.Starting);
36+ root.fakeApplication.setState(ApplicationInfoInterface.Starting);
37 property QtObject fakeApplication: null
38 property QtObject fakeApplication: null
39+ readonly property var fakeSession: fakeApplication ? fakeApplication.session : null
39 Connections {
41 Connections {
40 target: fakeApplication
42 target: fakeApplication
41− onSurfaceChanged: {
43+ onSessionChanged: {
42− surfaceCheckbox.checked = fakeApplication.surface !== null;
44+ sessionCheckbox.checked = fakeApplication.session !== null
@@ -50,15 +52,20 @@ Rectangle {
50 application: fakeApplication
52 application: fakeApplication
53− Loader {
55+ FocusScope {
54− id: applicationWindowLoader
56+ id: appFocus
56 top: parent.top
58 top: parent.top
57 bottom: parent.bottom
59 bottom: parent.bottom
58 left: parent.left
60 left: parent.left
60 width: units.gu(40)
62 width: units.gu(40)
65+ id: applicationWindowLoader
61− sourceComponent: applicationWindowComponent
67+ sourceComponent: applicationWindowComponent
64 Rectangle {
71 Rectangle {
@@ -66,30 +73,55 @@ Rectangle {
67 top: parent.top
74 top: parent.top
68 bottom: parent.bottom
75 bottom: parent.bottom
69− left: applicationWindowLoader.right
76+ left: appFocus.right
70 right: parent.right
77 right: parent.right
73− Column {
80+ ColumnLayout {
74 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
81 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
75 spacing: units.gu(1)
82 spacing: units.gu(1)
77− anchors { left: parent.left; right: parent.right }
84+ RowLayout {
85+ Layout.fillWidth: true
78 CheckBox {
87 CheckBox {
79− id: surfaceCheckbox; checked: false
88+ id: sessionCheckbox; checked: false
80 onCheckedChanged: {
89 onCheckedChanged: {
81 if (applicationWindowLoader.status !== Loader.Ready)
90 if (applicationWindowLoader.status !== Loader.Ready)
84− if (checked && !fakeApplication.surface) {
93+ if (checked && !fakeApplication.session) {
85− fakeApplication.createSurface();
94+ fakeApplication.createSession();
86− } else if (!checked && fakeApplication.surface) {
95+ } else if (!checked && fakeApplication.session) {
87− fakeApplication.surface.release();
96+ fakeApplication.session.release();
91− Label { text: "Surface" }
100+ Label {
102+ anchors.verticalCenter: parent.verticalCenter
115+ Layout.preferredHeight: sessionControl.height
117+ RecursingChildSessionControl {
119+ anchors { left: parent.left; right: parent.right; }
121+ session: fakeSession
93 ListItem.ItemSelector {
125 ListItem.ItemSelector {
94 id: appStateSelector
126 id: appStateSelector
95 anchors { left: parent.left; right: parent.right }
127 anchors { left: parent.left; right: parent.right }
@@ -100,13 +132,13 @@ Rectangle {
100 "Stopped"]
132 "Stopped"]
101 property int selectedApplicationState: {
133 property int selectedApplicationState: {
102 if (model[selectedIndex] === "Starting") {
134 if (model[selectedIndex] === "Starting") {
103− return ApplicationInfo.Starting;
135+ return ApplicationInfoInterface.Starting;
104 } else if (model[selectedIndex] === "Running") {
136 } else if (model[selectedIndex] === "Running") {
105− return ApplicationInfo.Running;
137+ return ApplicationInfoInterface.Running;
106 } else if (model[selectedIndex] === "Suspended") {
138 } else if (model[selectedIndex] === "Suspended") {
107− return ApplicationInfo.Suspended;
139+ return ApplicationInfoInterface.Suspended;
109− return ApplicationInfo.Stopped;
141+ return ApplicationInfoInterface.Stopped;
112 onSelectedApplicationStateChanged: {
144 onSelectedApplicationStateChanged: {
@@ -114,6 +146,7 @@ Rectangle {
114 fakeApplication.setState(selectedApplicationState);
146 fakeApplication.setState(selectedApplicationState);
@@ -123,10 +156,10 @@ Rectangle {
123 when: windowShown
156 when: windowShown
125 // just to make them shorter
158 // just to make them shorter
126− property int appStarting: ApplicationInfo.Starting
159+ property int appStarting: ApplicationInfoInterface.Starting
127− property int appRunning: ApplicationInfo.Running
160+ property int appRunning: ApplicationInfoInterface.Running
128− property int appSuspended: ApplicationInfo.Suspended
161+ property int appSuspended: ApplicationInfoInterface.Suspended
129− property int appStopped: ApplicationInfo.Stopped
162+ property int appStopped: ApplicationInfoInterface.Stopped
131 function setApplicationState(appState) {
164 function setApplicationState(appState) {
132 switch (appState) {
165 switch (appState) {
@@ -170,6 +203,14 @@ Rectangle {
170 findInterestingApplicationWindowChildren();
203 findInterestingApplicationWindowChildren();
206+ function initSession() {
207+ sessionCheckbox.checked = true;
208+ sessionControl.surfaceCheckbox.checked = true;
210+ function cleanupSession() {
211+ sessionCheckbox.checked = false;
173 function cleanup() {
214 function cleanup() {
174 forgetApplicationWindowChildren();
215 forgetApplicationWindowChildren();
@@ -177,10 +218,10 @@ Rectangle {
177 applicationWindowLoader.active = false;
218 applicationWindowLoader.active = false;
179 appStateSelector.selectedIndex = 0;
220 appStateSelector.selectedIndex = 0;
180− surfaceCheckbox.checked = false;
221+ cleanupSession();
182− if (fakeApplication.surface)
223+ if (fakeApplication.session)
183− fakeApplication.surface.release();
224+ fakeApplication.session.release();
185 applicationWindowLoader.active = true;
226 applicationWindowLoader.active = true;
@@ -197,7 +238,7 @@ Rectangle {
197 verify(stateGroup.state === "splashScreen");
238 verify(stateGroup.state === "splashScreen");
199 if (data.swapInitOrder) {
240 if (data.swapInitOrder) {
200− surfaceCheckbox.checked = true;
241+ initSession();
202 setApplicationState(appRunning);
243 setApplicationState(appRunning);
@@ -207,14 +248,14 @@ Rectangle {
207 if (data.swapInitOrder) {
248 if (data.swapInitOrder) {
208 setApplicationState(appRunning);
249 setApplicationState(appRunning);
210− surfaceCheckbox.checked = true;
251+ initSession();
213 tryCompare(stateGroup, "state", "surface");
254 tryCompare(stateGroup, "state", "surface");
216 function test_suspendedAppShowsSurface() {
257 function test_suspendedAppShowsSurface() {
217− surfaceCheckbox.checked = true;
258+ initSession();
218 setApplicationState(appRunning);
259 setApplicationState(appRunning);
220 tryCompare(stateGroup, "state", "surface");
261 tryCompare(stateGroup, "state", "surface");
@@ -228,7 +269,7 @@ Rectangle {
230 function test_killedAppShowsScreenshot() {
271 function test_killedAppShowsScreenshot() {
231− surfaceCheckbox.checked = true;
272+ initSession();
232 setApplicationState(appRunning);
273 setApplicationState(appRunning);
233 tryCompare(stateGroup, "state", "surface");
274 tryCompare(stateGroup, "state", "surface");
@@ -241,13 +282,13 @@ Rectangle {
241 setApplicationState(appStopped);
282 setApplicationState(appStopped);
243 tryCompare(stateGroup, "state", "screenshot");
284 tryCompare(stateGroup, "state", "screenshot");
244− tryCompare(fakeApplication, "surface", null);
285+ tryCompare(fakeApplication, "session", null);
247 function test_restartApp() {
288 function test_restartApp() {
248 var screenshotImage = findChild(applicationWindowLoader.item, "screenshotImage");
289 var screenshotImage = findChild(applicationWindowLoader.item, "screenshotImage");
250− surfaceCheckbox.checked = true;
291+ initSession();
251 setApplicationState(appRunning);
292 setApplicationState(appRunning);
252 tryCompare(stateGroup, "state", "surface");
293 tryCompare(stateGroup, "state", "surface");
253 waitUntilTransitionsEnd();
294 waitUntilTransitionsEnd();
@@ -259,28 +300,28 @@ Rectangle {
260 tryCompare(stateGroup, "state", "screenshot");
301 tryCompare(stateGroup, "state", "screenshot");
261 waitUntilTransitionsEnd();
302 waitUntilTransitionsEnd();
262− tryCompare(fakeApplication, "surface", null);
303+ tryCompare(fakeApplication, "session", null);
264 // and restart it
305 // and restart it
265 setApplicationState(appStarting);
306 setApplicationState(appStarting);
267 waitUntilTransitionsEnd();
308 waitUntilTransitionsEnd();
268 verify(stateGroup.state === "screenshot");
309 verify(stateGroup.state === "screenshot");
269− verify(fakeApplication.surface === null);
310+ verify(fakeSession === null);
271 setApplicationState(appRunning);
312 setApplicationState(appRunning);
273 waitUntilTransitionsEnd();
314 waitUntilTransitionsEnd();
274 verify(stateGroup.state === "screenshot");
315 verify(stateGroup.state === "screenshot");
276− surfaceCheckbox.checked = true;
317+ initSession();
278 tryCompare(stateGroup, "state", "surface");
319 tryCompare(stateGroup, "state", "surface");
279 tryCompare(screenshotImage, "status", Image.Null);
320 tryCompare(screenshotImage, "status", Image.Null);
282 function test_appCrashed() {
323 function test_appCrashed() {
283− surfaceCheckbox.checked = true;
324+ initSession();
284 setApplicationState(appRunning);
325 setApplicationState(appRunning);
285 tryCompare(stateGroup, "state", "surface");
326 tryCompare(stateGroup, "state", "surface");
286 waitUntilTransitionsEnd();
327 waitUntilTransitionsEnd();
@@ -289,39 +330,39 @@ Rectangle {
289 setApplicationState(appStopped);
330 setApplicationState(appStopped);
291 tryCompare(stateGroup, "state", "screenshot");
332 tryCompare(stateGroup, "state", "screenshot");
292− tryCompare(fakeApplication, "surface", null);
333+ tryCompare(fakeApplication, "session", null);
295 function test_keepSurfaceWhileInvisible() {
336 function test_keepSurfaceWhileInvisible() {
296− surfaceCheckbox.checked = true;
337+ initSession();
297 setApplicationState(appRunning);
338 setApplicationState(appRunning);
298 tryCompare(stateGroup, "state", "surface");
339 tryCompare(stateGroup, "state", "surface");
299 waitUntilTransitionsEnd();
340 waitUntilTransitionsEnd();
300− verify(fakeApplication.surface !== null);
341+ verify(fakeSession.surface !== null);
302 applicationWindowLoader.item.visible = false;
343 applicationWindowLoader.item.visible = false;
304 waitUntilTransitionsEnd();
345 waitUntilTransitionsEnd();
305 verify(stateGroup.state === "surface");
346 verify(stateGroup.state === "surface");
306− verify(fakeApplication.surface !== null);
347+ verify(fakeSession.surface !== null);
308 applicationWindowLoader.item.visible = true;
349 applicationWindowLoader.item.visible = true;
310 waitUntilTransitionsEnd();
351 waitUntilTransitionsEnd();
311 verify(stateGroup.state === "surface");
352 verify(stateGroup.state === "surface");
312− verify(fakeApplication.surface !== null);
353+ verify(fakeSession.surface !== null);
315 function test_touchesReachSurfaceWhenItsShown() {
356 function test_touchesReachSurfaceWhenItsShown() {
316 setApplicationState(appRunning);
357 setApplicationState(appRunning);
317− surfaceCheckbox.checked = true;
358+ initSession();
319 tryCompare(stateGroup, "state", "surface");
360 tryCompare(stateGroup, "state", "surface");
321 waitUntilTransitionsEnd();
362 waitUntilTransitionsEnd();
323 // Because doing stuff in C++ is a PITA we keep the counter in the interal qml impl.
364 // 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");
325 fakeSurface.touchPressCount = 0;
366 fakeSurface.touchPressCount = 0;
326 fakeSurface.touchReleaseCount = 0;
367 fakeSurface.touchReleaseCount = 0;
@@ -333,14 +374,25 @@ Rectangle {
335 function test_showNothingOnSuddenSurfaceLoss() {
376 function test_showNothingOnSuddenSurfaceLoss() {
336− surfaceCheckbox.checked = true;
377+ initSession();
337 setApplicationState(appRunning);
378 setApplicationState(appRunning);
338 tryCompare(stateGroup, "state", "surface");
379 tryCompare(stateGroup, "state", "surface");
339 waitUntilTransitionsEnd();
380 waitUntilTransitionsEnd();
341− surfaceCheckbox.checked = false;
382+ cleanupSession();
343 verify(stateGroup.state === "void");
384 verify(stateGroup.state === "void");
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();
395+ compare(appFocus.focus, true);