summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Cosmin Băieș <cosminbaies@google.com> 2025-02-05 18:44:16 +0100
committer Cosmin Băieș <cosminbaies@google.com> 2025-02-05 21:37:30 +0100
commit4619d46b2444a81f3fcf2d329ef2e53125bfd694 (patch)
tree1a11dc275d862d5445fb5b58bad98495f332656d
parent38633894c85feca89437b00cd7ad9c01c75376da (diff)
Use InputInjection util for InputMethodServiceTest
In testShowHideKeyboard_byUserAction we were using UiDevice to search for the EditText, and to click on it, despite having a reference to the View readily available. This makes the test more robust by using the InputInjection utils to directly click on the existing reference. Flag: EXEMPT testfix Bug: 394328311 Test: atest InputMethodServiceTest#testShowHideKeyboard_byUserAction Change-Id: Ib2f51b16126467a4f1a857657c5e6086fb63159c
-rw-r--r--services/tests/InputMethodSystemServerTests/Android.bp1
-rw-r--r--services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java10
-rw-r--r--services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/testing/TestActivity.java2
3 files changed, 4 insertions, 9 deletions
diff --git a/services/tests/InputMethodSystemServerTests/Android.bp b/services/tests/InputMethodSystemServerTests/Android.bp
index de5f6ac0bf1e..ae9a34efc222 100644
--- a/services/tests/InputMethodSystemServerTests/Android.bp
+++ b/services/tests/InputMethodSystemServerTests/Android.bp
@@ -110,6 +110,7 @@ android_test {
"androidx.test.espresso.core",
"androidx.test.ext.truth",
"androidx.test.runner",
+ "cts-input-lib",
"cts-wm-util",
"frameworks-base-testutils",
"mockito-target-extended-minus-junit4",
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java
index 8a52d46f9f0a..a103b0583eac 100644
--- a/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java
@@ -19,6 +19,7 @@ package com.android.inputmethodservice;
import static android.view.WindowInsets.Type.captionBar;
import static com.android.compatibility.common.util.SystemUtil.eventually;
+import static com.android.cts.input.injectinputinprocess.InjectInputInProcessKt.clickOnViewCenter;
import static com.android.internal.inputmethod.InputMethodNavButtonFlags.IME_DRAWS_IME_NAV_BAR;
import static com.android.internal.inputmethod.InputMethodNavButtonFlags.SHOW_IME_SWITCHER_WHEN_IME_IS_SHOWN;
@@ -77,7 +78,6 @@ public class InputMethodServiceTest {
private static final String TAG = "SimpleIMSTest";
private static final String INPUT_METHOD_SERVICE_NAME = ".SimpleInputMethodService";
- private static final String EDIT_TEXT_DESC = "Input box";
private static final String INPUT_METHOD_NAV_BACK_ID =
"android:id/input_method_nav_back";
private static final String INPUT_METHOD_NAV_IME_SWITCHER_ID =
@@ -168,7 +168,7 @@ public class InputMethodServiceTest {
// Performs click on EditText to bring up the IME.
Log.i(TAG, "Click on EditText");
verifyInputViewStatus(
- this::clickOnEditText,
+ () -> clickOnViewCenter(mActivity.getEditText()),
true /* expected */,
true /* inputViewStarted */);
assertWithMessage("IME is shown").that(mInputMethodService.isInputViewShown()).isTrue();
@@ -1260,10 +1260,4 @@ public class InputMethodServiceTest {
controller.hide(captionBar());
}
}
-
- private void clickOnEditText() {
- // Find the editText and click it.
- getUiObject(By.desc(EDIT_TEXT_DESC)).click();
- mInstrumentation.waitForIdleSync();
- }
}
diff --git a/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/testing/TestActivity.java b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/testing/TestActivity.java
index 5a73ed5b25e1..eadbac3ca74b 100644
--- a/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/testing/TestActivity.java
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/testing/TestActivity.java
@@ -75,7 +75,7 @@ public final class TestActivity extends Activity {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
final var rootView = new LinearLayout(this);
mEditText = new EditText(this);
- mEditText.setContentDescription("Input box");
+ mEditText.setHint("editText");
rootView.addView(mEditText, new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
rootView.setFitsSystemWindows(true);
setContentView(rootView);