on xenial help sign in
[tests/mocks] don't focus newly created surface

ubports/qtmir@b8f8b9e (Dont automaticly switch to newly placed window, let unity8 handle this) make qtmir stops automatically activating the new window. To make our mock mimicks qtmir better, we have to do that too. This is required to test the regression on the previous commit. This fails a few tests: - Shell::test_switchKeymap() fails because the prompt surface management is broken at the moment (TLWM doesn't manage them). As this test doesn't intended to test that, I added an activate() call on the prompt surface to make it work. - ActiveCallHint::test_activeHint() fails because it doesn't use TLWM thus nothing activates the newly-opened app. I adjusted the test to activate() the appropriate surface based on the case they're testing. - PhoneStage::test_launchAppWithSpreadOpen() fails. That's because the original test was essentially a "surprise launch" i.e. the launch that doesn't come from Unity8 itself but the outer source (e.g. launching from a terminal), thus it can't run TLWM::pendingActivation(). That doesn't work based on testing on a real phone. I separated the test into 2 cases: one of them test expected launch with pending Activation(), another test unexpected launch and has expectFail().

commitba2d37f84386e3504f3ac31b14d99eebf8398a13 authorRatchanan Srirattanamet <ratchanan@ubports.com> dateSat 25 Jan 2020, 00:41 (7 years ago) parentd58308c
4 files changed+23−7
tests/mocks/Unity/Application/ApplicationInfo.cpp−3 tests/qmltests/Panel/tst_ActiveCallHint.qml+6−3 tests/qmltests/Stage/tst_PhoneStage.qml+15−1 tests/qmltests/tst_Shell.qml+2
tests/mocks/Unity/Application/ApplicationInfo.cpp−3
@@ -99,8 +99,6 @@ void ApplicationInfo::createPromptSurface()
9999 surfaceManager->notifySurfaceCreated(surface);
100100
101101 m_promptSurfaceList->addSurface(surface);
102−
103− surfaceManager->activate(surface);
104102}
105103
106104void ApplicationInfo::createSurface()
@@ -179,7 +177,6 @@ void ApplicationInfo::createSurface()
179177 }
180178
181179 surfaceManager->notifySurfaceCreated(surface);
182− surfaceManager->activate(surface);
183180}
184181
185182void ApplicationInfo::setIconId(const QString &iconId)
tests/qmltests/Panel/tst_ActiveCallHint.qml+6−3
@@ -102,10 +102,13 @@ Item {
102102
103103 var application = ApplicationManager.startApplication("dialer-app");
104104 tryCompare(application.surfaceList, "count", 1);
105− tryCompare(ApplicationManager, "focusedApplicationId", "dialer-app");
106− tryCompare(application, "state", ApplicationInfoInterface.Running);
107105
108− if (!data.focused) {
106+ if (data.focused) {
107+ // Dialer has to be explicitly activated because we don't have TLWM.
108+ application.surfaceList.get(0).activate();
109+ tryCompare(ApplicationManager, "focusedApplicationId", "dialer-app");
110+ tryCompare(application, "state", ApplicationInfoInterface.Running);
111+ } else {
109112 dashApp.surfaceList.get(0).activate();
110113 tryCompare(ApplicationManager, "focusedApplicationId", "unity8-dash");
111114 }
tests/qmltests/Stage/tst_PhoneStage.qml+15−1
@@ -573,19 +573,33 @@ Item {
573573 compare(topLevelSurfaceList.count, 1);
574574 }
575575
576+ function test_launchAppWithSpreadOpen_data() {
577+ return [
578+ { tag: "expected", expected: true },
579+ { tag: "unexpected", expected: false },
580+ ];
581+ }
576582
577583 /*
578584 Check that when an application starts while the spread is open, the
579585 spread closes and that new app is brought to front (gets focused).
586+
587+ "Expected" means the app is started from the launcher or the spread,
588+ where TLWM's pendingActivation() will be called. "Unexpected" means
589+ the app is launched from outside, such as from the command line.
580590 */
581− function test_launchAppWithSpreadOpen()
591+ function test_launchAppWithSpreadOpen(data)
582592 {
583593 performEdgeSwipeToShowAppSpread();
584594
595+ if (data.expected)
596+ topLevelSurfaceList.pendingActivation();
597+
585598 var webbrowserSurfaceId = topLevelSurfaceList.nextId;
586599 var webbrowserApp = ApplicationManager.startApplication("morph-browser");
587600 waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
588601
602+ expectFail(/* tag */ "unexpected", "Surprise launch doesn't work properly yet");
589603 compare(topLevelSurfaceList.idAt(0), webbrowserSurfaceId);
590604 compare(webbrowserApp.focused, true);
591605 }
tests/qmltests/tst_Shell.qml+2
@@ -2494,6 +2494,8 @@ Rectangle {
24942494 app.createPromptSurface();
24952495 var promptSurface = app.promptSurfaceList.get(0);
24962496 verify(promptSurface);
2497+ // FIXME: remove when prompt surface focus management is working.
2498+ promptSurface.activate();
24972499 tryCompare(appSurface, "keymap", promptSurface.keymap);
24982500 // ... and that the controller's surface keymap is also the same
24992501 tryCompare(topLevelSurfaceList.focusedWindow.surface, "keymap", "sk");