From e2cf2faa7d64b1d2ea195c606fc77e976dccf6b3 Mon Sep 17 00:00:00 2001 From: Ming-Shin Lu Date: Fri, 12 Nov 2021 20:40:10 +0800 Subject: [PATCH] Add a regression test to verify no IME flickering when navigating back As CL[1] changes the semantic of WindowState#isVisibleOrAdding that affects computeImeTarget result when finishing the activity with IME has shown by back navigation, that caused IME flicking after backing to the previous app. Add a flicker test to verify the above test scenerio won't happen. [1]: Ic537d77c8b0e10e80444dd46d7b49e5a9bd63d6c Bug: 205075200 Bug: 205761007 Bug: 204948120 Bug: 204731658 Test: atest OpenImeWindowAndCloseTest Change-Id: Ibe582ccd73aa3b2326040f5d2e6e5edd9de95605 --- .../server/wm/flicker/helpers/ImeAppHelper.kt | 16 +++ .../flicker/ime/OpenImeWindowAndCloseTest.kt | 131 ++++++++++++++++++ .../flickerapp/res/layout/activity_ime.xml | 6 + .../wm/flicker/testapp/ImeActivity.java | 5 + 4 files changed, 158 insertions(+) create mode 100644 tests/FlickerTests/src/com/android/server/wm/flicker/ime/OpenImeWindowAndCloseTest.kt diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/ImeAppHelper.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/ImeAppHelper.kt index 1c2164a70a551..7ee6451b2797c 100644 --- a/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/ImeAppHelper.kt +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/ImeAppHelper.kt @@ -84,4 +84,20 @@ open class ImeAppHelper @JvmOverloads constructor( wmHelper.waitImeGone() } } + + @JvmOverloads + open fun finishActivity(device: UiDevice, wmHelper: WindowManagerStateHelper? = null) { + val finishButton = device.wait( + Until.findObject(By.res(getPackage(), "finish_activity_btn")), + FIND_TIMEOUT) + require(finishButton != null) { + "Finish activity button not found, probably IME activity is not on the screen ?" + } + finishButton.click() + if (wmHelper == null) { + device.waitForIdle() + } else { + wmHelper.waitForActivityRemoved(component) + } + } } \ No newline at end of file diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/OpenImeWindowAndCloseTest.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/OpenImeWindowAndCloseTest.kt new file mode 100644 index 0000000000000..972918e28fa72 --- /dev/null +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/OpenImeWindowAndCloseTest.kt @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wm.flicker.ime + +import android.app.Instrumentation +import android.platform.test.annotations.Presubmit +import android.view.Surface +import android.view.WindowManagerPolicyConstants +import androidx.test.filters.RequiresDevice +import androidx.test.platform.app.InstrumentationRegistry +import com.android.server.wm.flicker.* +import com.android.server.wm.flicker.annotation.Group2 +import com.android.server.wm.flicker.dsl.FlickerBuilder +import com.android.server.wm.flicker.helpers.ImeAppHelper +import com.android.server.wm.flicker.helpers.SimpleAppHelper +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.MethodSorters +import org.junit.runners.Parameterized + +/** + * Unlike {@link OpenImeWindowTest} testing IME window opening transitions, this test also verify + * there is no flickering when back to the simple activity without requesting IME to show. + * + * To run this test: `atest FlickerTests:OpenImeWindowAndCloseTest` + */ +@RequiresDevice +@RunWith(Parameterized::class) +@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Group2 +class OpenImeWindowAndCloseTest(private val testSpec: FlickerTestParameter) { + private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() + private val simpleApp = SimpleAppHelper(instrumentation) + private val testApp = ImeAppHelper(instrumentation) + + @FlickerBuilderProvider + fun buildFlicker(): FlickerBuilder { + return FlickerBuilder(instrumentation).apply { + setup { + eachRun { + simpleApp.launchViaIntent(wmHelper) + testApp.launchViaIntent(wmHelper) + testApp.openIME(device, wmHelper) + } + } + transitions { + testApp.finishActivity(device, wmHelper) + } + teardown { + test { + simpleApp.exit() + } + } + } + } + + @Presubmit + @Test + fun navBarWindowIsVisible() = testSpec.navBarWindowIsVisible() + + @Presubmit + @Test + fun statusBarWindowIsVisible() = testSpec.statusBarWindowIsVisible() + + @Presubmit + @Test + fun imeWindowBecomesInvisible() = testSpec.imeWindowBecomesInvisible() + + @Presubmit + @Test + fun navBarLayerIsVisible() = testSpec.navBarLayerIsVisible() + + @Presubmit + @Test + fun statusBarLayerIsVisible() = testSpec.statusBarLayerIsVisible() + + @Presubmit + @Test + fun entireScreenCovered() = testSpec.entireScreenCovered() + + @Presubmit + @Test + fun imeLayerBecomesInvisible() = testSpec.imeLayerBecomesInvisible() + + @Presubmit + @Test + fun visibleLayersShownMoreThanOneConsecutiveEntry() { + testSpec.assertLayers { + this.visibleLayersShownMoreThanOneConsecutiveEntry() + } + } + + @Test + fun visibleWindowsShownMoreThanOneConsecutiveEntry() { + testSpec.assertWm { + this.visibleWindowsShownMoreThanOneConsecutiveEntry() + } + } + + companion object { + @Parameterized.Parameters(name = "{0}") + @JvmStatic + fun getParams(): Collection { + return FlickerTestParameterFactory.getInstance() + .getConfigNonRotationTests( + repetitions = 3, + supportedRotations = listOf(Surface.ROTATION_0), + supportedNavigationModes = listOf( + WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY, + WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY + ) + ) + } + } +} \ No newline at end of file diff --git a/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_ime.xml b/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_ime.xml index c55e7c2720db2..2620ff407efc9 100644 --- a/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_ime.xml +++ b/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_ime.xml @@ -18,6 +18,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" + android:orientation="vertical" android:focusableInTouchMode="true" android:background="@android:color/holo_green_light"> +