on xenial help sign in
Update tst_Shell to remove Loaders

For some reason, the Shell component wants to be recreated before it will receive Alt keypresses... so do that in initTestCase!

commitb3fb0fcea748ca23d1ff3f1254770aeab8952915 authorDalton Durst <dalton@ubports.com> dateSun 17 Jan 2021, 21:28 (6 years ago) parentdf1185e
1 file changed+76−72
tests/qmltests/tst_Shell.qml+76−72
tests/qmltests/tst_Shell.qml+76−72
@@ -15,7 +15,8 @@
1515 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1616 */
1717
18−import QtQuick 2.4
18+import QtQuick 2.7
19+import QtQuick.Window 2.4
1920import QtTest 1.0
2021import AccountsService 0.1
2122import GSettings 1.0
@@ -51,14 +52,13 @@ Rectangle {
5152 Component.onCompleted: {
5253 // must set the mock mode before loading the Shell
5354 LightDMController.userMode = "single";
54− shellLoader.active = true;
5555 }
5656
5757 ApplicationMenuDataLoader {
5858 id: appMenuData
5959 }
6060
61− property var shell: shellLoader.item ? shellLoader.item : null
61+ property var shell: null
6262 onShellChanged: {
6363 if (shell) {
6464 topLevelSurfaceList = testCase.findInvisibleChild(shell, "topLevelSurfaceList");
@@ -71,14 +71,33 @@ Rectangle {
7171
7272 property var topLevelSurfaceList: null
7373
74+ Component {
75+ id: shellComponent
76+ Shell {
77+ id: __shell
78+ objectName: "shell"
79+ anchors.fill: parent
80+ usageScenario: usageScenarioSelector.model[usageScenarioSelector.selectedIndex]
81+ nativeWidth: width
82+ nativeHeight: height
83+ orientation: shellRect.shellOrientation
84+ orientations: Orientations {
85+ native_: shellRect.nativeOrientation
86+ primary: shellRect.primaryOrientation
87+ }
88+ mode: shellRect.mode
89+ hasTouchscreen: true
90+ }
91+ }
92+
7493 Item {
7594 id: shellContainer
7695 anchors.left: root.left
7796 anchors.right: controls.left
7897 anchors.top: root.top
7998 anchors.bottom: root.bottom
80− Loader {
81− id: shellLoader
99+ Rectangle {
100+ id: shellRect
82101 focus: true
83102
84103 anchors.centerIn: parent
@@ -93,7 +112,7 @@ Rectangle {
93112 State {
94113 name: "phone"
95114 PropertyChanges {
96− target: shellLoader
115+ target: shellRect
97116 width: units.gu(40)
98117 height: units.gu(71)
99118 }
@@ -101,7 +120,7 @@ Rectangle {
101120 State {
102121 name: "tablet"
103122 PropertyChanges {
104− target: shellLoader
123+ target: shellRect
105124 width: units.gu(100)
106125 height: units.gu(71)
107126 shellOrientation: Qt.LandscapeOrientation
@@ -112,7 +131,7 @@ Rectangle {
112131 State {
113132 name: "desktop"
114133 PropertyChanges {
115− target: shellLoader
134+ target: shellRect
116135 width: shellContainer.width
117136 height: shellContainer.height
118137 }
@@ -122,28 +141,6 @@ Rectangle {
122141 }
123142 }
124143 ]
125−
126− active: false
127− property bool itemDestroyed: false
128− sourceComponent: Component {
129− Shell {
130− id: __shell
131− objectName: "shell"
132− usageScenario: usageScenarioSelector.model[usageScenarioSelector.selectedIndex]
133− nativeWidth: width
134− nativeHeight: height
135− orientation: shellLoader.shellOrientation
136− orientations: Orientations {
137− native_: shellLoader.nativeOrientation
138− primary: shellLoader.primaryOrientation
139− }
140− mode: shellLoader.mode
141− hasTouchscreen: true
142− Component.onDestruction: {
143− shellLoader.itemDestroyed = true;
144− }
145− }
146− }
147144 }
148145 }
149146
@@ -170,14 +167,24 @@ Rectangle {
170167 spacing: units.gu(1)
171168 anchors { left: parent.left; right: parent.right }
172169
170+ Button {
171+ text: "Load shell"
172+ onClicked: {
173+ if (shell === null) {
174+ shell = shellComponent.createObject(shellRect);
175+ shell.focus = true;
176+ }
177+ }
178+ }
179+
173180 Button {
174181 text: "Show Greeter"
175182 activeFocusOnPress: false
176183 onClicked: {
177− if (shellLoader.status !== Loader.Ready)
184+ if (shell === null)
178185 return;
179186
180− var greeter = shellLoader.item.greeter;
187+ var greeter = shell.greeter;
181188 if (!greeter.shown) {
182189 LightDM.Greeter.showGreeter();
183190 }
@@ -187,10 +194,10 @@ Rectangle {
187194 text: "Hide Greeter"
188195 activeFocusOnPress: false
189196 onClicked: {
190− if (shellLoader.status !== Loader.Ready)
197+ if (shell === null)
191198 return;
192199
193− var greeter = shellLoader.item.greeter;
200+ var greeter = shell.greeter;
194201 if (greeter.shown) {
195202 greeter.hide()
196203 }
@@ -200,7 +207,7 @@ Rectangle {
200207 text: callManager.foregroundCall ? "Hide Call" : "Show Call"
201208 activeFocusOnPress: false
202209 onClicked: {
203− if (shellLoader.status !== Loader.Ready)
210+ if (shell === null)
204211 return;
205212
206213 callManager.foregroundCall = callManager.foregroundCall ? null : phoneCall;
@@ -210,10 +217,10 @@ Rectangle {
210217 text: "Show Launcher"
211218 activeFocusOnPress: false
212219 onClicked: {
213− if (shellLoader.status !== Loader.Ready)
220+ if (shell === null)
214221 return;
215222
216− var launcher = testCase.findChild(shellLoader.item, "launcher");
223+ var launcher = testCase.findChild(shell, "launcher");
217224 launcher.state = "visible";
218225 }
219226 }
@@ -222,7 +229,7 @@ Rectangle {
222229 activeFocusOnPress: false
223230 onClicked: {
224231 var childs = new Array(0);
225− childs.push(shellLoader.item)
232+ childs.push(shell)
226233 while (childs.length > 0) {
227234 if (childs[0].activeFocus && childs[0].focus && childs[0].objectName != "shell") {
228235 console.log("Active focus is on item:", childs[0]);
@@ -248,7 +255,7 @@ Rectangle {
248255 onSelectedIndexChanged: {
249256 testCase.tearDown();
250257 LightDMController.userMode = model[selectedIndex];
251− shellLoader.active = true;
258+ testCase.init();
252259 }
253260 }
254261 Label {
@@ -261,7 +268,7 @@ Rectangle {
261268 activeFocusOnPress: false
262269 model: ["phone", "tablet", "desktop"]
263270 onSelectedIndexChanged: {
264− shellLoader.state = model[selectedIndex];
271+ shellRect.state = model[selectedIndex];
265272 }
266273 }
267274 Label {
@@ -419,19 +426,19 @@ Rectangle {
419426 if (guard) return;
420427 guard = true;
421428 testCase.tearDown();
422− shellLoader.mode = model[selectedIndex];
423− shellLoader.active = true;
429+ shellRect.mode = model[selectedIndex];
430+ testCase.init();
424431 guard = false;
425432 }
426433 Connections {
427− target: shellLoader
434+ target: shellRect
428435 onModeChanged: {
429436 if (shellModeSelector.guard) {
430437 return;
431438 }
432439 shellModeSelector.guard = true;
433440 for (var i = 0; i < 3; i++) {
434− if (shellModeSelector.model[i] === shellLoader.mode) {
441+ if (shellModeSelector.model[i] === shellRect.mode) {
435442 shellModeSelector.selectedIndex = i;
436443 return;
437444 }
@@ -556,17 +563,26 @@ Rectangle {
556563 name: "Shell"
557564 when: windowShown
558565
559− property Item shell: shellLoader.status === Loader.Ready ? shellLoader.item : null
560−
561566 function initTestCase() {
567+ // FIXME: The first shell created in the testcase sometimes doesn't
568+ // receive Alt keypresses. Creating and destroying a shell seems
569+ // to fix it.
570+ var localShell = createTemporaryObject(shellComponent, shellRect);
571+ localShell.destroy();
562572 tearDown();
563573 }
564574
565575 function init() {
566576 mouseMove(root, 0, 0);
577+ keyRelease(Qt.Key_Alt);
578+ keyRelease(Qt.Key_Control);
579+ keyRelease(Qt.Key_Super_L);
567580 }
568581
569582 function cleanup() {
583+ var keyMapper = testCase.findChild(shellContainer, "physicalKeysMapper");
584+ keyMapper.controlInsteadOfAlt = false;
585+ keyMapper.controlInsteadOfSuper = false;
570586 waitForRendering(shell);
571587 mouseEmulation.checked = true;
572588 tryCompare(shell, "waitingOnGreeter", false); // make sure greeter didn't leave us in disabled state
@@ -580,10 +596,9 @@ Rectangle {
580596 apps = 0;
581597 }
582598
583− shellLoader.state = formFactor;
584− shellLoader.active = true;
585− tryCompare(shellLoader, "status", Loader.Ready);
586− removeTimeConstraintsFromSwipeAreas(shellLoader.item);
599+ shellRect.state = formFactor;
600+ shell = createTemporaryObject(shellComponent, shellRect);
601+ removeTimeConstraintsFromSwipeAreas(shell);
587602 tryCompare(shell, "waitingOnGreeter", false); // reset by greeter when ready
588603
589604 sessionSpy.target = shell.greeter;
@@ -606,6 +621,8 @@ Rectangle {
606621 stage = findChild(shell, "stage");
607622
608623 addApps(apps);
624+ shell.focus = true;
625+ waitForRendering(shell);
609626 }
610627
611628 function addApps(count) {
@@ -636,20 +653,6 @@ Rectangle {
636653 function tearDown() {
637654 launcherShowDashHomeSpy.target = null;
638655
639− shellLoader.itemDestroyed = false;
640−
641− shellLoader.active = false;
642−
643− tryCompare(shellLoader, "status", Loader.Null);
644− tryCompare(shellLoader, "item", null);
645− // Loader.status might be Loader.Null and Loader.item might be null but the Loader
646− // item might still be alive. So if we set Loader.active back to true
647− // again right now we will get the very same Shell instance back. So no reload
648− // actually took place. Likely because Loader waits until the next event loop
649− // iteration to do its work. So to ensure the reload, we will wait until the
650− // Shell instance gets destroyed.
651− tryCompare(shellLoader, "itemDestroyed", true);
652−
653656 LightDMController.reset();
654657 setLightDMMockMode("single"); // these tests default to "single"
655658
@@ -657,7 +660,7 @@ Rectangle {
657660 AccountsService.demoEdgesCompleted = [];
658661 AccountsService.backgroundFile = "";
659662 Wizard.System.wizardEnabled = false;
660− shellLoader.mode = "full-greeter";
663+ shellRect.mode = "full-greeter";
661664
662665 // kill all (fake) running apps
663666 killApps();
@@ -1647,8 +1650,9 @@ Rectangle {
16471650
16481651 var spreadItem = findChild(shell, "spreadItem");
16491652 verify(spreadItem !== null);
1653+ waitForRendering(shell);
16501654
1651− keyPress(Qt.Key_Alt)
1655+ keyPress(Qt.Key_Alt);
16521656 keyClick(Qt.Key_Tab);
16531657 tryCompare(spreadItem, "highlightedIndex", 1);
16541658
@@ -2406,7 +2410,7 @@ Rectangle {
24062410 }
24072411
24082412 function test_greeterModeBroadcastsApp() {
2409− shellLoader.mode = "greeter";
2413+ shellRect.mode = "greeter";
24102414 setLightDMMockMode("single-pin");
24112415 loadShell("phone");
24122416 waitForRendering(shell);
@@ -2424,7 +2428,7 @@ Rectangle {
24242428 }
24252429
24262430 function test_greeterModeBroadcastsHome() {
2427− shellLoader.mode = "greeter";
2431+ shellRect.mode = "greeter";
24282432 setLightDMMockMode("single-pin");
24292433 loadShell("phone");
24302434 waitForRendering(shell);
@@ -2445,7 +2449,7 @@ Rectangle {
24452449 }
24462450
24472451 function test_greeterModeDispatchesURL() {
2448− shellLoader.mode = "greeter";
2452+ shellRect.mode = "greeter";
24492453 setLightDMMockMode("single-pin");
24502454 loadShell("phone");
24512455 waitForRendering(shell);
@@ -2501,7 +2505,7 @@ Rectangle {
25012505 tryCompare(appSurface, "keymap", "fr");
25022506
25032507 // go to e.g. desktop stage
2504− shellLoader.state = "desktop";
2508+ shellRect.state = "desktop";
25052509 shell.usageScenario = "desktop";
25062510 waitForRendering(shell);
25072511
@@ -2574,7 +2578,7 @@ Rectangle {
25742578 }
25752579
25762580 function test_fullShellModeHasNoInitialGreeter() {
2577− shellLoader.mode = "full-shell";
2581+ shellRect.mode = "full-shell";
25782582 loadShell("phone");
25792583 setLightDMMockMode("single-pin");
25802584 waitForRendering(shell);
@@ -3309,7 +3313,7 @@ Rectangle {
33093313 */
33103314 function test_launcherLockedWhenNoAppsRunning(data) {
33113315 loadShell(data.shell, 0);
3312− shellLoader.state = data.formFactor;
3316+ shellRect.state = data.formFactor;
33133317 var launcher = findChild(shell, "launcher");
33143318 var inputMethod = findChild(shell, "inputMethod");
33153319 GSettingsController.setAutohideLauncher(!data.launcherLocked);