diff options
| -rw-r--r-- | services/tests/InputMethodSystemServerTests/Android.bp | 21 | ||||
| -rw-r--r-- | services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java | 26 |
2 files changed, 37 insertions, 10 deletions
diff --git a/services/tests/InputMethodSystemServerTests/Android.bp b/services/tests/InputMethodSystemServerTests/Android.bp index da58aa1f6c66..de5f6ac0bf1e 100644 --- a/services/tests/InputMethodSystemServerTests/Android.bp +++ b/services/tests/InputMethodSystemServerTests/Android.bp @@ -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", ], diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java index 0f4e39511796..8a52d46f9f0a 100644 --- a/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java +++ b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java @@ -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; |