on xenial help sign in
Merge pull request #365 from ubports/xenial_-_replace-test-loaders

Fix SurfaceManager assertion errors in qmltests

commitd4566397da26cb85e1925e1d526067c03fdc4f14 authorRodney <6557070+dobey@users.noreply.github.com> dateFri 29 Jan 2021, 10:45 (6 years ago) parent6119aafdbb33c8
4 files changed+132−145
plugins/GlobalShortcut/globalshortcut.cpp+3 tests/mocks/Unity/Application/SurfaceManager.cpp−3 tests/qmltests/Tutorial/tst_Tutorial.qml+53−70 tests/qmltests/tst_Shell.qml+76−72
plugins/GlobalShortcut/globalshortcut.cpp+3
@@ -58,6 +58,9 @@ void GlobalShortcut::setActive(bool active)
5858
5959void GlobalShortcut::componentComplete()
6060{
61+ if (this->window()) {
62+ QMetaObject::invokeMethod(this, "setupFilterOnWindow", Q_ARG(QQuickWindow*, this->window()));
63+ }
6164 connect(this, &QQuickItem::windowChanged, this, &GlobalShortcut::setupFilterOnWindow);
6265}
6366
tests/mocks/Unity/Application/SurfaceManager.cpp−3
@@ -35,9 +35,6 @@ SurfaceManager *SurfaceManager::m_instance = nullptr;
3535
3636SurfaceManager *SurfaceManager::instance()
3737{
38− if (m_instance == nullptr) {
39− auto inst = new SurfaceManager();
40− }
4138 return m_instance;
4239}
4340
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);
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);