on xenial help sign in
Some improvements
2c397d3Daniel d'Andrada
qml/Stages/ApplicationWindow.qml+26−37
@@ -67,36 +67,37 @@ Item {
67 onTriggered: { if (d.surface) {d.surfaceInitialized = true;} }
67 onTriggered: { if (d.surface) {d.surfaceInitialized = true;} }
68 }
68 }
69
69
70+ Binding {
71+ target: d.surface
72+ when: d.surface
73+ property: "enabled"
74+ value: root.interactive
75+ }
76+ Binding {
77+ target: d.surface
78+ when: d.surface
79+ property: "focus"
80+ value: root.interactive
81+ }
82+ Connections {
83+ target: d.surface
84+ // FIXME: I would rather not need to do this, but currently it doesn't get
85+ // active focus without it and I don't know why.
86+ onFocusChanged: forceSurfaceActiveFocusIfReady();
87+ onParentChanged: forceSurfaceActiveFocusIfReady();
88+ onEnabledChanged: forceSurfaceActiveFocusIfReady();
89+ function forceSurfaceActiveFocusIfReady() {
90+ if (d.surface.focus && d.surface.parent === surfaceContainer && d.surface.enabled) {
91+ d.surface.forceActiveFocus();
92+ }
93+ }
94+ }
95+
70 SurfaceContainer {
96 SurfaceContainer {
71 id: surfaceContainer
97 id: surfaceContainer
72 objectName: "surfaceContainer"
98 objectName: "surfaceContainer"
73 anchors.fill: parent
99 anchors.fill: parent
74 surface: d.surface
100 surface: d.surface
75−
76− Binding {
77− target: surface
78− property: "enabled"
79− value: root.interactive
80− }
81− Binding {
82− target: surface
83− property: "focus"
84− value: root.interactive
85− }
86−
87− Connections {
88− target: surface
89− // FIXME: I would rather not need to do this, but currently it doesn't get
90− // active focus without it and I don't know why.
91− onFocusChanged: forceSurfaceActiveFocusIfReady();
92− onParentChanged: forceSurfaceActiveFocusIfReady();
93− onEnabledChanged: forceSurfaceActiveFocusIfReady();
94− function forceSurfaceActiveFocusIfReady() {
95− if (surface.focus && surface.parent === surfaceContainer && surface.enabled) {
96− surface.forceActiveFocus();
97− }
98− }
99− }
100 }
101 }
101
102
102 Image {
103 Image {
@@ -173,21 +174,12 @@ Item {
173 }
174 }
174 ]
175 ]
175
176
176− // For testing purposes
177− property bool transitioning: defaultToSplash.running
178− || splashToSurface.running
179− || surfaceToSplash.running
180− || surfaceToScreenshot.running
181− || screenshotToSurface.running
182−
183 transitions: [
177 transitions: [
184 Transition {
178 Transition {
185− id: defaultToSplash
186 from: ""; to: "splashScreen"
179 from: ""; to: "splashScreen"
187 PropertyAction { target: splashLoader; property: "active"; value: true }
180 PropertyAction { target: splashLoader; property: "active"; value: true }
188 },
181 },
189 Transition {
182 Transition {
190− id: splashToSurface
191 from: "splashScreen"; to: "surface"
183 from: "splashScreen"; to: "surface"
192 SequentialAnimation {
184 SequentialAnimation {
193 PropertyAction { target: surfaceContainer
185 PropertyAction { target: surfaceContainer
@@ -199,7 +191,6 @@ Item {
199 }
191 }
200 },
192 },
201 Transition {
193 Transition {
202− id: surfaceToSplash
203 from: "surface"; to: "splashScreen"
194 from: "surface"; to: "splashScreen"
204 SequentialAnimation {
195 SequentialAnimation {
205 PropertyAction { target: splashLoader; property: "active"; value: true }
196 PropertyAction { target: splashLoader; property: "active"; value: true }
@@ -211,7 +202,6 @@ Item {
211 }
202 }
212 },
203 },
213 Transition {
204 Transition {
214− id: surfaceToScreenshot
215 from: "surface"; to: "screenshot"
205 from: "surface"; to: "screenshot"
216 SequentialAnimation {
206 SequentialAnimation {
217 PropertyAction { target: screenshotImage
207 PropertyAction { target: screenshotImage
@@ -225,7 +215,6 @@ Item {
225 }
215 }
226 },
216 },
227 Transition {
217 Transition {
228− id: screenshotToSurface
229 from: "screenshot"; to: "surface"
218 from: "screenshot"; to: "surface"
230 SequentialAnimation {
219 SequentialAnimation {
231 PropertyAction { target: surfaceContainer
220 PropertyAction { target: surfaceContainer
tests/qmltests/Stages/tst_ApplicationWindow.qml+38−26
@@ -145,7 +145,34 @@ Rectangle {
145 }
145 }
146 }
146 }
147
147
148+ // holds some of the internal ApplicationWindow objects we probe during the tests
149+ property var stateGroup: null
150+
151+ function findInterestingApplicationWindowChildren() {
152+ stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
153+ verify(stateGroup);
154+ }
155+
156+ function forgetApplicationWindowChildren() {
157+ stateGroup = null;
158+ }
159+
160+ // wait until any transition animation has finished
161+ function waitUntilTransitionsEnd() {
162+ var transitions = stateGroup.transitions;
163+ for (var i = 0; i < transitions.length; ++i) {
164+ var transition = transitions[i];
165+ tryCompare(transition, "running", false, 2000);
166+ }
167+ }
168+
169+ function init() {
170+ findInterestingApplicationWindowChildren();
171+ }
172+
148 function cleanup() {
173 function cleanup() {
174+ forgetApplicationWindowChildren();
175+
149 // reload our test subject to get it in a fresh state once again
176 // reload our test subject to get it in a fresh state once again
150 applicationWindowLoader.active = false;
177 applicationWindowLoader.active = false;
151
178
@@ -167,8 +194,6 @@ Rectangle {
167 }
194 }
168
195
169 function test_showSplashUntilAppFullyInit() {
196 function test_showSplashUntilAppFullyInit() {
170− var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
171−
172 verify(stateGroup.state === "splashScreen");
197 verify(stateGroup.state === "splashScreen");
173
198
174 if (data.swapInitOrder) {
199 if (data.swapInitOrder) {
@@ -189,25 +214,20 @@ Rectangle {
189 }
214 }
190
215
191 function test_suspendedAppShowsSurface() {
216 function test_suspendedAppShowsSurface() {
192− var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
193−
194 surfaceCheckbox.checked = true;
217 surfaceCheckbox.checked = true;
195 setApplicationState(appRunning);
218 setApplicationState(appRunning);
196
219
197 tryCompare(stateGroup, "state", "surface");
220 tryCompare(stateGroup, "state", "surface");
198
221
199− // wait until any transition animation has finished
222+ waitUntilTransitionsEnd();
200− tryCompare(stateGroup, "transitioning", false, 2000);
201
223
202 setApplicationState(appSuspended);
224 setApplicationState(appSuspended);
203
225
204 verify(stateGroup.state === "surface");
226 verify(stateGroup.state === "surface");
205− verify(stateGroup.transitioning === false);
227+ waitUntilTransitionsEnd();
206 }
228 }
207
229
208 function test_killedAppShowsScreenshot() {
230 function test_killedAppShowsScreenshot() {
209− var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
210−
211 surfaceCheckbox.checked = true;
231 surfaceCheckbox.checked = true;
212 setApplicationState(appRunning);
232 setApplicationState(appRunning);
213 tryCompare(stateGroup, "state", "surface");
233 tryCompare(stateGroup, "state", "surface");
@@ -225,13 +245,12 @@ Rectangle {
225 }
245 }
226
246
227 function test_restartApp() {
247 function test_restartApp() {
228− var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
229 var screenshotImage = findChild(applicationWindowLoader.item, "screenshotImage");
248 var screenshotImage = findChild(applicationWindowLoader.item, "screenshotImage");
230
249
231 surfaceCheckbox.checked = true;
250 surfaceCheckbox.checked = true;
232 setApplicationState(appRunning);
251 setApplicationState(appRunning);
233 tryCompare(stateGroup, "state", "surface");
252 tryCompare(stateGroup, "state", "surface");
234− tryCompare(stateGroup, "transitioning", false, 2000);
253+ waitUntilTransitionsEnd();
235
254
236 setApplicationState(appSuspended);
255 setApplicationState(appSuspended);
237
256
@@ -239,19 +258,19 @@ Rectangle {
239 setApplicationState(appStopped);
258 setApplicationState(appStopped);
240
259
241 tryCompare(stateGroup, "state", "screenshot");
260 tryCompare(stateGroup, "state", "screenshot");
242− tryCompare(stateGroup, "transitioning", false, 2000);
261+ waitUntilTransitionsEnd();
243 tryCompare(fakeApplication, "surface", null);
262 tryCompare(fakeApplication, "surface", null);
244
263
245 // and restart it
264 // and restart it
246 setApplicationState(appStarting);
265 setApplicationState(appStarting);
247
266
248− verify(stateGroup.transitioning === false);
267+ waitUntilTransitionsEnd();
249 verify(stateGroup.state === "screenshot");
268 verify(stateGroup.state === "screenshot");
250 verify(fakeApplication.surface === null);
269 verify(fakeApplication.surface === null);
251
270
252 setApplicationState(appRunning);
271 setApplicationState(appRunning);
253
272
254− verify(stateGroup.transitioning === false);
273+ waitUntilTransitionsEnd();
255 verify(stateGroup.state === "screenshot");
274 verify(stateGroup.state === "screenshot");
256
275
257 surfaceCheckbox.checked = true;
276 surfaceCheckbox.checked = true;
@@ -261,12 +280,10 @@ Rectangle {
261 }
280 }
262
281
263 function test_appCrashed() {
282 function test_appCrashed() {
264− var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
265−
266 surfaceCheckbox.checked = true;
283 surfaceCheckbox.checked = true;
267 setApplicationState(appRunning);
284 setApplicationState(appRunning);
268 tryCompare(stateGroup, "state", "surface");
285 tryCompare(stateGroup, "state", "surface");
269− tryCompare(stateGroup, "transitioning", false, 2000);
286+ waitUntilTransitionsEnd();
270
287
271 // oh, it crashed...
288 // oh, it crashed...
272 setApplicationState(appStopped);
289 setApplicationState(appStopped);
@@ -276,37 +293,32 @@ Rectangle {
276 }
293 }
277
294
278 function test_keepSurfaceWhileInvisible() {
295 function test_keepSurfaceWhileInvisible() {
279− var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
280−
281 surfaceCheckbox.checked = true;
296 surfaceCheckbox.checked = true;
282 setApplicationState(appRunning);
297 setApplicationState(appRunning);
283 tryCompare(stateGroup, "state", "surface");
298 tryCompare(stateGroup, "state", "surface");
284− tryCompare(stateGroup, "transitioning", false, 2000);
299+ waitUntilTransitionsEnd();
285 verify(fakeApplication.surface !== null);
300 verify(fakeApplication.surface !== null);
286
301
287 applicationWindowLoader.item.visible = false;
302 applicationWindowLoader.item.visible = false;
288
303
289− verify(stateGroup.transitioning === false);
304+ waitUntilTransitionsEnd();
290 verify(stateGroup.state === "surface");
305 verify(stateGroup.state === "surface");
291 verify(fakeApplication.surface !== null);
306 verify(fakeApplication.surface !== null);
292
307
293 applicationWindowLoader.item.visible = true;
308 applicationWindowLoader.item.visible = true;
294
309
295− verify(stateGroup.transitioning === false);
310+ waitUntilTransitionsEnd();
296 verify(stateGroup.state === "surface");
311 verify(stateGroup.state === "surface");
297 verify(fakeApplication.surface !== null);
312 verify(fakeApplication.surface !== null);
298 }
313 }
299
314
300 function test_touchesReachSurfaceWhenItsShown() {
315 function test_touchesReachSurfaceWhenItsShown() {
301− var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
302−
303 setApplicationState(appRunning);
316 setApplicationState(appRunning);
304 surfaceCheckbox.checked = true;
317 surfaceCheckbox.checked = true;
305
318
306 tryCompare(stateGroup, "state", "surface");
319 tryCompare(stateGroup, "state", "surface");
307
320
308− // wait until any transition animation has finished
321+ waitUntilTransitionsEnd();
309− tryCompare(stateGroup, "transitioning", false, 2000);
310
322
311 // Because doing stuff in C++ is a PITA we keep the counter in the interal qml impl.
323 // Because doing stuff in C++ is a PITA we keep the counter in the interal qml impl.
312 var fakeSurface = findChild(fakeApplication.surface, "fakeSurfaceQML");
324 var fakeSurface = findChild(fakeApplication.surface, "fakeSurfaceQML");