on xenial help sign in
Some improvements

- remove warnings from qml code when surface is null, which is always thecase on start up (we show the splash screen at that time) - remove unnecessary nesting of bindings and connections inside the SurfaceContainer - improve test code so that we no longer need a property in ApplicationWindow.qml just to support the tests - refactor test code a bit

commit2c397d302c56b2227307d17145d26ebdcf8f2361 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateMon 18 Aug 2014, 11:10 (12 years ago) parent4eedf03
2 files changed+64−63
qml/Stages/ApplicationWindow.qml+26−37 tests/qmltests/Stages/tst_ApplicationWindow.qml+38−26
qml/Stages/ApplicationWindow.qml+26−37
@@ -67,36 +67,37 @@ Item {
6767 onTriggered: { if (d.surface) {d.surfaceInitialized = true;} }
6868 }
6969
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+
7096 SurfaceContainer {
7197 id: surfaceContainer
7298 objectName: "surfaceContainer"
7399 anchors.fill: parent
74100 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− }
100101 }
101102
102103 Image {
@@ -173,21 +174,12 @@ Item {
173174 }
174175 ]
175176
176− // For testing purposes
177− property bool transitioning: defaultToSplash.running
178− || splashToSurface.running
179− || surfaceToSplash.running
180− || surfaceToScreenshot.running
181− || screenshotToSurface.running
182−
183177 transitions: [
184178 Transition {
185− id: defaultToSplash
186179 from: ""; to: "splashScreen"
187180 PropertyAction { target: splashLoader; property: "active"; value: true }
188181 },
189182 Transition {
190− id: splashToSurface
191183 from: "splashScreen"; to: "surface"
192184 SequentialAnimation {
193185 PropertyAction { target: surfaceContainer
@@ -199,7 +191,6 @@ Item {
199191 }
200192 },
201193 Transition {
202− id: surfaceToSplash
203194 from: "surface"; to: "splashScreen"
204195 SequentialAnimation {
205196 PropertyAction { target: splashLoader; property: "active"; value: true }
@@ -211,7 +202,6 @@ Item {
211202 }
212203 },
213204 Transition {
214− id: surfaceToScreenshot
215205 from: "surface"; to: "screenshot"
216206 SequentialAnimation {
217207 PropertyAction { target: screenshotImage
@@ -225,7 +215,6 @@ Item {
225215 }
226216 },
227217 Transition {
228− id: screenshotToSurface
229218 from: "screenshot"; to: "surface"
230219 SequentialAnimation {
231220 PropertyAction { target: surfaceContainer
tests/qmltests/Stages/tst_ApplicationWindow.qml+38−26
@@ -145,7 +145,34 @@ Rectangle {
145145 }
146146 }
147147
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+
148173 function cleanup() {
174+ forgetApplicationWindowChildren();
175+
149176 // reload our test subject to get it in a fresh state once again
150177 applicationWindowLoader.active = false;
151178
@@ -167,8 +194,6 @@ Rectangle {
167194 }
168195
169196 function test_showSplashUntilAppFullyInit() {
170− var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
171−
172197 verify(stateGroup.state === "splashScreen");
173198
174199 if (data.swapInitOrder) {
@@ -189,25 +214,20 @@ Rectangle {
189214 }
190215
191216 function test_suspendedAppShowsSurface() {
192− var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
193−
194217 surfaceCheckbox.checked = true;
195218 setApplicationState(appRunning);
196219
197220 tryCompare(stateGroup, "state", "surface");
198221
199− // wait until any transition animation has finished
200− tryCompare(stateGroup, "transitioning", false, 2000);
222+ waitUntilTransitionsEnd();
201223
202224 setApplicationState(appSuspended);
203225
204226 verify(stateGroup.state === "surface");
205− verify(stateGroup.transitioning === false);
227+ waitUntilTransitionsEnd();
206228 }
207229
208230 function test_killedAppShowsScreenshot() {
209− var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
210−
211231 surfaceCheckbox.checked = true;
212232 setApplicationState(appRunning);
213233 tryCompare(stateGroup, "state", "surface");
@@ -225,13 +245,12 @@ Rectangle {
225245 }
226246
227247 function test_restartApp() {
228− var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
229248 var screenshotImage = findChild(applicationWindowLoader.item, "screenshotImage");
230249
231250 surfaceCheckbox.checked = true;
232251 setApplicationState(appRunning);
233252 tryCompare(stateGroup, "state", "surface");
234− tryCompare(stateGroup, "transitioning", false, 2000);
253+ waitUntilTransitionsEnd();
235254
236255 setApplicationState(appSuspended);
237256
@@ -239,19 +258,19 @@ Rectangle {
239258 setApplicationState(appStopped);
240259
241260 tryCompare(stateGroup, "state", "screenshot");
242− tryCompare(stateGroup, "transitioning", false, 2000);
261+ waitUntilTransitionsEnd();
243262 tryCompare(fakeApplication, "surface", null);
244263
245264 // and restart it
246265 setApplicationState(appStarting);
247266
248− verify(stateGroup.transitioning === false);
267+ waitUntilTransitionsEnd();
249268 verify(stateGroup.state === "screenshot");
250269 verify(fakeApplication.surface === null);
251270
252271 setApplicationState(appRunning);
253272
254− verify(stateGroup.transitioning === false);
273+ waitUntilTransitionsEnd();
255274 verify(stateGroup.state === "screenshot");
256275
257276 surfaceCheckbox.checked = true;
@@ -261,12 +280,10 @@ Rectangle {
261280 }
262281
263282 function test_appCrashed() {
264− var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
265−
266283 surfaceCheckbox.checked = true;
267284 setApplicationState(appRunning);
268285 tryCompare(stateGroup, "state", "surface");
269− tryCompare(stateGroup, "transitioning", false, 2000);
286+ waitUntilTransitionsEnd();
270287
271288 // oh, it crashed...
272289 setApplicationState(appStopped);
@@ -276,37 +293,32 @@ Rectangle {
276293 }
277294
278295 function test_keepSurfaceWhileInvisible() {
279− var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
280−
281296 surfaceCheckbox.checked = true;
282297 setApplicationState(appRunning);
283298 tryCompare(stateGroup, "state", "surface");
284− tryCompare(stateGroup, "transitioning", false, 2000);
299+ waitUntilTransitionsEnd();
285300 verify(fakeApplication.surface !== null);
286301
287302 applicationWindowLoader.item.visible = false;
288303
289− verify(stateGroup.transitioning === false);
304+ waitUntilTransitionsEnd();
290305 verify(stateGroup.state === "surface");
291306 verify(fakeApplication.surface !== null);
292307
293308 applicationWindowLoader.item.visible = true;
294309
295− verify(stateGroup.transitioning === false);
310+ waitUntilTransitionsEnd();
296311 verify(stateGroup.state === "surface");
297312 verify(fakeApplication.surface !== null);
298313 }
299314
300315 function test_touchesReachSurfaceWhenItsShown() {
301− var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
302−
303316 setApplicationState(appRunning);
304317 surfaceCheckbox.checked = true;
305318
306319 tryCompare(stateGroup, "state", "surface");
307320
308− // wait until any transition animation has finished
309− tryCompare(stateGroup, "transitioning", false, 2000);
321+ waitUntilTransitionsEnd();
310322
311323 // Because doing stuff in C++ is a PITA we keep the counter in the interal qml impl.
312324 var fakeSurface = findChild(fakeApplication.surface, "fakeSurfaceQML");