Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 38633894 authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Wait for activity to be ready for input injection

In InputMethodServiceTest we verify the behaviour of short clicking and
long clicking on the IME back button and the IME Switcher button, and we
verify that the TestActivity is focused before starting the test.

However, in some cases the test still fails with the input_interaction
going to the NotificationShade window. This adds an extra assertion that
the Activity is ready for input injection, which should detect this case
early and provide a more explicit signal.

Flag: EXEMPT testfix
Bug: 394240124
Test: atest InputMethodServiceTest#testShowHideKeyboard_byUserAction
Change-Id: I90704eccde26115c9da746742f3d74ec3a00021e
parent 5aefade7
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -34,24 +34,24 @@ android_test {

    static_libs: [
        "androidx.test.core",
        "androidx.test.runner",
        "androidx.test.espresso.core",
        "androidx.test.espresso.contrib",
        "androidx.test.espresso.core",
        "androidx.test.ext.truth",
        "androidx.test.runner",
        "frameworks-base-testutils",
        "mockito-target-extended-minus-junit4",
        "platform-test-annotations",
        "ravenwood-junit",
        "services.core",
        "service-permission.stubs.system_server",
        "services.core",
        "servicestests-core-utils",
        "servicestests-utils-mockito-extended",
        "truth",
    ],

    libs: [
        "android.test.mock.stubs.system",
        "android.test.base.stubs.system",
        "android.test.mock.stubs.system",
        "android.test.runner.stubs.system",
    ],

@@ -103,27 +103,28 @@ android_test {
    test_config: "src/com/android/inputmethodservice/AndroidTest.xml",

    static_libs: [
        "SimpleImeImsLib",
        "SimpleImeTestingLib",
        "androidx.test.core",
        "androidx.test.runner",
        "androidx.test.espresso.core",
        "androidx.test.espresso.contrib",
        "androidx.test.espresso.core",
        "androidx.test.ext.truth",
        "androidx.test.runner",
        "cts-wm-util",
        "frameworks-base-testutils",
        "mockito-target-extended-minus-junit4",
        "platform-test-annotations",
        "ravenwood-junit",
        "services.core",
        "service-permission.stubs.system_server",
        "services.core",
        "servicestests-core-utils",
        "servicestests-utils-mockito-extended",
        "truth",
        "SimpleImeTestingLib",
        "SimpleImeImsLib",
    ],

    libs: [
        "android.test.mock.stubs.system",
        "android.test.base.stubs.system",
        "android.test.mock.stubs.system",
        "android.test.runner.stubs.system",
    ],

+26 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.provider.Settings;
import android.server.wm.WindowManagerStateHelper;
import android.util.Log;
import android.view.WindowManagerGlobal;
import android.view.WindowManagerPolicyConstants;
@@ -63,6 +64,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;

import java.util.Objects;
@@ -86,11 +88,16 @@ public class InputMethodServiceTest {
    private static final String DISABLE_SHOW_IME_WITH_HARD_KEYBOARD_CMD =
            "settings put secure " + Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD + " 0";

    private final WindowManagerStateHelper mWmState =  new WindowManagerStateHelper();

    private final DeviceFlagsValueProvider mFlagsValueProvider = new DeviceFlagsValueProvider();

    @Rule
    public final CheckFlagsRule mCheckFlagsRule = new CheckFlagsRule(mFlagsValueProvider);

    @Rule
    public final TestName mName = new TestName();

    private Instrumentation mInstrumentation;
    private UiDevice mUiDevice;
    private Context mContext;
@@ -154,6 +161,8 @@ public class InputMethodServiceTest {
     */
    @Test
    public void testShowHideKeyboard_byUserAction() {
        waitUntilActivityReadyForInputInjection(mActivity);

        setShowImeWithHardKeyboard(true /* enabled */);

        // Performs click on EditText to bring up the IME.
@@ -867,6 +876,8 @@ public class InputMethodServiceTest {
        assumeTrue("Must have a navigation bar", hasNavigationBar());
        assumeTrue("Must be in gesture navigation mode", isGestureNavEnabled());

        waitUntilActivityReadyForInputInjection(mActivity);

        setShowImeWithHardKeyboard(true /* enabled */);

        verifyInputViewStatusOnMainSync(
@@ -901,6 +912,8 @@ public class InputMethodServiceTest {
        assumeTrue("Must have a navigation bar", hasNavigationBar());
        assumeTrue("Must be in gesture navigation mode", isGestureNavEnabled());

        waitUntilActivityReadyForInputInjection(mActivity);

        setShowImeWithHardKeyboard(true /* enabled */);

        verifyInputViewStatusOnMainSync(
@@ -936,6 +949,8 @@ public class InputMethodServiceTest {
        assumeTrue("Must have a navigation bar", hasNavigationBar());
        assumeTrue("Must be in gesture navigation mode", isGestureNavEnabled());

        waitUntilActivityReadyForInputInjection(mActivity);

        setShowImeWithHardKeyboard(true /* enabled */);

        verifyInputViewStatusOnMainSync(
@@ -974,6 +989,8 @@ public class InputMethodServiceTest {
        assumeTrue("Must have a navigation bar", hasNavigationBar());
        assumeTrue("Must be in gesture navigation mode", isGestureNavEnabled());

        waitUntilActivityReadyForInputInjection(mActivity);

        setShowImeWithHardKeyboard(true /* enabled */);

        verifyInputViewStatusOnMainSync(
@@ -1143,6 +1160,15 @@ public class InputMethodServiceTest {
        Log.i(TAG, "Finish preparing activity with editor.");
    }

    private void waitUntilActivityReadyForInputInjection(@NonNull TestActivity activity) {
        try {
            mWmState.waitUntilActivityReadyForInputInjection(activity, mInstrumentation, TAG,
                    "test: " + mName.getMethodName());
        } catch (InterruptedException e) {
            fail("Interrupted while waiting for activity to be ready: " + e.getMessage());
        }
    }

    @NonNull
    private String getInputMethodId() {
        return mTargetPackageName + "/" + INPUT_METHOD_SERVICE_NAME;