on xenial help sign in
Update tst_Tutorial to remove Loaders
977d1d7Dalton Durst
tests/qmltests/Tutorial/tst_Tutorial.qml+53−70
@@ -36,6 +36,8 @@ Rectangle {
36 width: units.gu(100) + buttons.width
36 width: units.gu(100) + buttons.width
37 height: units.gu(71)
37 height: units.gu(71)
38
38
39+ property var shell: null
40+
39 QtObject {
41 QtObject {
40 id: applicationArguments
42 id: applicationArguments
41
43
@@ -87,7 +89,23 @@ Rectangle {
87 Component.onCompleted: {
89 Component.onCompleted: {
88 // must set the mock mode before loading the Shell
90 // must set the mock mode before loading the Shell
89 LightDMController.userMode = "single-pin";
91 LightDMController.userMode = "single-pin";
90− shellLoader.active = true;
92+ }
93+
94+ Component {
95+ id: shellComponent
96+ Shell {
97+ anchors.fill: parent
98+ usageScenario: shellRect.state
99+ nativeWidth: width
100+ nativeHeight: height
101+ property string indicatorProfile: "phone"
102+ orientation: shellRect.shellOrientation
103+ orientations: Orientations {
104+ native_: shellRect.nativeOrientation
105+ primary: shellRect.primaryOrientation
106+ }
107+ hasTouchscreen: true
108+ }
91 }
109 }
92
110
93 Item {
111 Item {
@@ -97,10 +115,9 @@ Rectangle {
97 anchors.top: root.top
115 anchors.top: root.top
98 anchors.bottom: root.bottom
116 anchors.bottom: root.bottom
99
117
100− Loader {
118+ Rectangle {
101− id: shellLoader
119+ id: shellRect
102
120
103− active: false
104 anchors.horizontalCenter: parent.horizontalCenter
121 anchors.horizontalCenter: parent.horizontalCenter
105 anchors.top: parent.top
122 anchors.top: parent.top
106 anchors.bottom: parent.bottom
123 anchors.bottom: parent.bottom
@@ -114,14 +131,14 @@ Rectangle {
114 State {
131 State {
115 name: "phone"
132 name: "phone"
116 PropertyChanges {
133 PropertyChanges {
117− target: shellLoader
134+ target: shellRect
118 width: units.gu(40)
135 width: units.gu(40)
119 }
136 }
120 },
137 },
121 State {
138 State {
122 name: "tablet"
139 name: "tablet"
123 PropertyChanges {
140 PropertyChanges {
124− target: shellLoader
141+ target: shellRect
125 width: units.gu(100)
142 width: units.gu(100)
126 shellOrientation: Qt.LandscapeOrientation
143 shellOrientation: Qt.LandscapeOrientation
127 nativeOrientation: Qt.LandscapeOrientation
144 nativeOrientation: Qt.LandscapeOrientation
@@ -131,31 +148,11 @@ Rectangle {
131 State {
148 State {
132 name: "desktop"
149 name: "desktop"
133 PropertyChanges {
150 PropertyChanges {
134− target: shellLoader
151+ target: shellRect
135 width: units.gu(100)
152 width: units.gu(100)
136 }
153 }
137 }
154 }
138 ]
155 ]
139−
140− property bool itemDestroyed: false
141− sourceComponent: Component {
142− Shell {
143− usageScenario: shellLoader.state
144− nativeWidth: width
145− nativeHeight: height
146− property string indicatorProfile: "phone"
147− orientation: shellLoader.shellOrientation
148− orientations: Orientations {
149− native_: shellLoader.nativeOrientation
150− primary: shellLoader.primaryOrientation
151− }
152− hasTouchscreen: true
153−
154− Component.onDestruction: {
155− shellLoader.itemDestroyed = true;
156− }
157− }
158− }
159 }
156 }
160 }
157 }
161
158
@@ -170,15 +167,28 @@ Rectangle {
170 Column {
167 Column {
171 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
168 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
172 spacing: units.gu(1)
169 spacing: units.gu(1)
170+ Row {
171+ anchors { left: parent.left; right: parent.right }
172+ Button {
173+ text: "Load shell"
174+ onClicked: {
175+ if (shell === null) {
176+ shell = shellComponent.createObject(shellRect);
177+ shell.focus = true;
178+ }
179+ }
180+ }
181+ }
182+
173 Row {
183 Row {
174 anchors { left: parent.left; right: parent.right }
184 anchors { left: parent.left; right: parent.right }
175 Button {
185 Button {
176 text: "Hide Greeter"
186 text: "Hide Greeter"
177 onClicked: {
187 onClicked: {
178− if (shellLoader.status !== Loader.Ready)
188+ if (root.shell === null)
179 return;
189 return;
180
190
181− var greeter = testCase.findChild(shellLoader.item, "greeter");
191+ var greeter = testCase.findChild(shell, "greeter");
182 if (greeter.shown) {
192 if (greeter.shown) {
183 greeter.hide();
193 greeter.hide();
184 }
194 }
@@ -191,7 +201,7 @@ Rectangle {
191 Button {
201 Button {
192 text: "Restart Tutorial"
202 text: "Restart Tutorial"
193 onClicked: {
203 onClicked: {
194− if (shellLoader.status !== Loader.Ready)
204+ if (root.shell === null)
195 return;
205 return;
196
206
197 AccountsService.demoEdges = false;
207 AccountsService.demoEdges = false;
@@ -223,6 +233,7 @@ Rectangle {
223 CheckBox {
233 CheckBox {
224 activeFocusOnPress: false
234 activeFocusOnPress: false
225 onCheckedChanged: {
235 onCheckedChanged: {
236+ var topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
226 var surface = topLevelSurfaceList.inputMethodSurface;
237 var surface = topLevelSurfaceList.inputMethodSurface;
227 if (checked) {
238 if (checked) {
228 surface.requestState(Mir.RestoredState);
239 surface.requestState(Mir.RestoredState);
@@ -252,19 +263,11 @@ Rectangle {
252 name: "Tutorial"
263 name: "Tutorial"
253 when: windowShown
264 when: windowShown
254
265
255− property Item shell: shellLoader.status === Loader.Ready ? shellLoader.item : null
256 property real halfWidth: shell ? shell.width / 2 : 0
266 property real halfWidth: shell ? shell.width / 2 : 0
257 property real halfHeight: shell ? shell.height / 2 : 0
267 property real halfHeight: shell ? shell.height / 2 : 0
258
268
259− onShellChanged: {
260− if (shell) {
261− topLevelSurfaceList = testCase.findInvisibleChild(shell, "topLevelSurfaceList");
262− } else {
263− topLevelSurfaceList = null;
264− }
265− }
266−
267 function init() {
269 function init() {
270+ shell = createTemporaryObject(shellComponent, shellRect);
268 prepareShell();
271 prepareShell();
269
272
270 var tutorialTop = findChild(shell, "tutorialTop");
273 var tutorialTop = findChild(shell, "tutorialTop");
@@ -274,38 +277,14 @@ Rectangle {
274 }
277 }
275
278
276 function cleanup() {
279 function cleanup() {
277− resetLoader("phone");
278− }
279−
280− function resetLoader(state) {
281− shellLoader.itemDestroyed = false;
282−
283− shellLoader.active = false;
284− shellLoader.state = state;
285−
286− tryCompare(shellLoader, "status", Loader.Null);
287− tryCompare(shellLoader, "item", null);
288− // Loader.status might be Loader.Null and Loader.item might be null but the Loader
289− // item might still be alive. So if we set Loader.active back to true
290− // again right now we will get the very same Shell instance back. So no reload
291− // actually took place. Likely because Loader waits until the next event loop
292− // iteration to do its work. So to ensure the reload, we will wait until the
293− // Shell instance gets destroyed.
294− tryCompare(shellLoader, "itemDestroyed", true);
295−
296− // kill all (fake) running apps
297− killApps();
298−
299− // reload our test subject to get it in a fresh state once again
300− shellLoader.active = true;
301−
302 mockNotificationsModel.clear();
280 mockNotificationsModel.clear();
303− tryCompare(shellLoader, "status", Loader.Ready);
281+ killApps();
304− removeTimeConstraintsFromSwipeAreas(shellLoader.item);
282+ shellRect.state = "phone";
305 }
283 }
306
284
307 function prepareShell() {
285 function prepareShell() {
308 tryCompare(shell, "waitingOnGreeter", false); // reset by greeter when ready
286 tryCompare(shell, "waitingOnGreeter", false); // reset by greeter when ready
287+ removeTimeConstraintsFromSwipeAreas(shell);
309
288
310 WindowStateStorage.clear();
289 WindowStateStorage.clear();
311 callManager.foregroundCall = null;
290 callManager.foregroundCall = null;
@@ -319,11 +298,11 @@ Rectangle {
319 }
298 }
320
299
321 function loadShell(state) {
300 function loadShell(state) {
322− resetLoader(state);
301+ shellRect.state = state;
323 prepareShell();
302 prepareShell();
324 }
303 }
325
304
326− function ensureInputMethodSurface() {
305+ function ensureInputMethodSurface(topLevelSurfaceList) {
327 var surfaceManager = findInvisibleChild(shell, "surfaceManager");
306 var surfaceManager = findInvisibleChild(shell, "surfaceManager");
328 verify(surfaceManager);
307 verify(surfaceManager);
329 surfaceManager.createInputMethodSurface();
308 surfaceManager.createInputMethodSurface();
@@ -726,10 +705,12 @@ Rectangle {
726 }
705 }
727
706
728 function test_oskDoesNotHideTutorial() {
707 function test_oskDoesNotHideTutorial() {
708+ var topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
709+ verify(topLevelSurfaceList);
729 var tutorialTopLoader = findChild(shell, "tutorialTopLoader");
710 var tutorialTopLoader = findChild(shell, "tutorialTopLoader");
730 verify(tutorialTopLoader.shown);
711 verify(tutorialTopLoader.shown);
731
712
732− ensureInputMethodSurface();
713+ ensureInputMethodSurface(topLevelSurfaceList);
733 var surface = topLevelSurfaceList.inputMethodSurface;
714 var surface = topLevelSurfaceList.inputMethodSurface;
734 surface.requestState(Mir.RestoredState);
715 surface.requestState(Mir.RestoredState);
735
716
@@ -740,10 +721,12 @@ Rectangle {
740 }
721 }
741
722
742 function test_oskDelaysTutorial() {
723 function test_oskDelaysTutorial() {
724+ var topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
725+ verify(topLevelSurfaceList);
743 var tutorial = findChild(shell, "tutorial");
726 var tutorial = findChild(shell, "tutorial");
744 verify(!tutorial.delayed);
727 verify(!tutorial.delayed);
745
728
746− ensureInputMethodSurface();
729+ ensureInputMethodSurface(topLevelSurfaceList);
747 topLevelSurfaceList.inputMethodSurface.requestState(Mir.RestoredState);
730 topLevelSurfaceList.inputMethodSurface.requestState(Mir.RestoredState);
748
731
749 tryCompare(tutorial, "delayed", true);
732 tryCompare(tutorial, "delayed", true);