on xenial help sign in
Update tst_Tutorial to remove Loaders
commit977d1d77ccb4f0b8afeacc62e15cc1ddc9899454 authorDalton Durst <dalton@ubports.com> dateThu 28 Jan 2021, 19:50 (6 years ago) parentb3fb0fc
1 file changed+53−70
tests/qmltests/Tutorial/tst_Tutorial.qml+53−70
tests/qmltests/Tutorial/tst_Tutorial.qml+53−70
@@ -36,6 +36,8 @@ Rectangle {
3636 width: units.gu(100) + buttons.width
3737 height: units.gu(71)
3838
39+ property var shell: null
40+
3941 QtObject {
4042 id: applicationArguments
4143
@@ -87,7 +89,23 @@ Rectangle {
8789 Component.onCompleted: {
8890 // must set the mock mode before loading the Shell
8991 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+ }
91109 }
92110
93111 Item {
@@ -97,10 +115,9 @@ Rectangle {
97115 anchors.top: root.top
98116 anchors.bottom: root.bottom
99117
100− Loader {
101− id: shellLoader
118+ Rectangle {
119+ id: shellRect
102120
103− active: false
104121 anchors.horizontalCenter: parent.horizontalCenter
105122 anchors.top: parent.top
106123 anchors.bottom: parent.bottom
@@ -114,14 +131,14 @@ Rectangle {
114131 State {
115132 name: "phone"
116133 PropertyChanges {
117− target: shellLoader
134+ target: shellRect
118135 width: units.gu(40)
119136 }
120137 },
121138 State {
122139 name: "tablet"
123140 PropertyChanges {
124− target: shellLoader
141+ target: shellRect
125142 width: units.gu(100)
126143 shellOrientation: Qt.LandscapeOrientation
127144 nativeOrientation: Qt.LandscapeOrientation
@@ -131,31 +148,11 @@ Rectangle {
131148 State {
132149 name: "desktop"
133150 PropertyChanges {
134− target: shellLoader
151+ target: shellRect
135152 width: units.gu(100)
136153 }
137154 }
138155 ]
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− }
159156 }
160157 }
161158
@@ -170,15 +167,28 @@ Rectangle {
170167 Column {
171168 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
172169 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+
173183 Row {
174184 anchors { left: parent.left; right: parent.right }
175185 Button {
176186 text: "Hide Greeter"
177187 onClicked: {
178− if (shellLoader.status !== Loader.Ready)
188+ if (root.shell === null)
179189 return;
180190
181− var greeter = testCase.findChild(shellLoader.item, "greeter");
191+ var greeter = testCase.findChild(shell, "greeter");
182192 if (greeter.shown) {
183193 greeter.hide();
184194 }
@@ -191,7 +201,7 @@ Rectangle {
191201 Button {
192202 text: "Restart Tutorial"
193203 onClicked: {
194− if (shellLoader.status !== Loader.Ready)
204+ if (root.shell === null)
195205 return;
196206
197207 AccountsService.demoEdges = false;
@@ -223,6 +233,7 @@ Rectangle {
223233 CheckBox {
224234 activeFocusOnPress: false
225235 onCheckedChanged: {
236+ var topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
226237 var surface = topLevelSurfaceList.inputMethodSurface;
227238 if (checked) {
228239 surface.requestState(Mir.RestoredState);
@@ -252,19 +263,11 @@ Rectangle {
252263 name: "Tutorial"
253264 when: windowShown
254265
255− property Item shell: shellLoader.status === Loader.Ready ? shellLoader.item : null
256266 property real halfWidth: shell ? shell.width / 2 : 0
257267 property real halfHeight: shell ? shell.height / 2 : 0
258268
259− onShellChanged: {
260− if (shell) {
261− topLevelSurfaceList = testCase.findInvisibleChild(shell, "topLevelSurfaceList");
262− } else {
263− topLevelSurfaceList = null;
264− }
265− }
266−
267269 function init() {
270+ shell = createTemporaryObject(shellComponent, shellRect);
268271 prepareShell();
269272
270273 var tutorialTop = findChild(shell, "tutorialTop");
@@ -274,38 +277,14 @@ Rectangle {
274277 }
275278
276279 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−
302280 mockNotificationsModel.clear();
303− tryCompare(shellLoader, "status", Loader.Ready);
304− removeTimeConstraintsFromSwipeAreas(shellLoader.item);
281+ killApps();
282+ shellRect.state = "phone";
305283 }
306284
307285 function prepareShell() {
308286 tryCompare(shell, "waitingOnGreeter", false); // reset by greeter when ready
287+ removeTimeConstraintsFromSwipeAreas(shell);
309288
310289 WindowStateStorage.clear();
311290 callManager.foregroundCall = null;
@@ -319,11 +298,11 @@ Rectangle {
319298 }
320299
321300 function loadShell(state) {
322− resetLoader(state);
301+ shellRect.state = state;
323302 prepareShell();
324303 }
325304
326− function ensureInputMethodSurface() {
305+ function ensureInputMethodSurface(topLevelSurfaceList) {
327306 var surfaceManager = findInvisibleChild(shell, "surfaceManager");
328307 verify(surfaceManager);
329308 surfaceManager.createInputMethodSurface();
@@ -726,10 +705,12 @@ Rectangle {
726705 }
727706
728707 function test_oskDoesNotHideTutorial() {
708+ var topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
709+ verify(topLevelSurfaceList);
729710 var tutorialTopLoader = findChild(shell, "tutorialTopLoader");
730711 verify(tutorialTopLoader.shown);
731712
732− ensureInputMethodSurface();
713+ ensureInputMethodSurface(topLevelSurfaceList);
733714 var surface = topLevelSurfaceList.inputMethodSurface;
734715 surface.requestState(Mir.RestoredState);
735716
@@ -740,10 +721,12 @@ Rectangle {
740721 }
741722
742723 function test_oskDelaysTutorial() {
724+ var topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
725+ verify(topLevelSurfaceList);
743726 var tutorial = findChild(shell, "tutorial");
744727 verify(!tutorial.delayed);
745728
746− ensureInputMethodSurface();
729+ ensureInputMethodSurface(topLevelSurfaceList);
747730 topLevelSurfaceList.inputMethodSurface.requestState(Mir.RestoredState);
748731
749732 tryCompare(tutorial, "delayed", true);