diff options
| author | 2024-07-10 10:23:30 +0000 | |
|---|---|---|
| committer | 2024-07-10 10:23:30 +0000 | |
| commit | 98e390c75da77ea8c88e7d38056bfe0ab201e82e (patch) | |
| tree | 0a26fc92e107a0ce233cf164c28207cb90ddff35 | |
| parent | 4ad3c8ad8e838961e8397ebf182ce85f562188fc (diff) | |
Deflake InputMethodServiceTest
- Waits for the TestActiivty to obtain window focus and start input
- Improves EditorInfo logging in onStartInput
Flag: TEST_ONLY
Test: atest FrameworksImeTests
Fixes: 351269753
Change-Id: I7d501f9385f3ad5c70dea0022f18cb686da0b0bd
2 files changed, 19 insertions, 2 deletions
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java index 2029b71034eb..8f630af476c7 100644 --- a/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java +++ b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java @@ -99,6 +99,12 @@ public class InputMethodServiceTest { InputMethodServiceWrapper.getInputMethodServiceWrapperForTesting(); assertThat(mInputMethodService).isNotNull(); + // The activity gets focus. + assertThat(mActivity.hasWindowFocus()).isTrue(); + assertThat(mInputMethodService.getCurrentInputEditorInfo()).isNotNull(); + assertThat(mInputMethodService.getCurrentInputEditorInfo().packageName) + .isEqualTo(mTargetPackageName); + // The editor won't bring up keyboard by default. assertThat(mInputMethodService.getCurrentInputStarted()).isTrue(); assertThat(mInputMethodService.getCurrentInputViewStarted()).isFalse(); diff --git a/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/ims/InputMethodServiceWrapper.java b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/ims/InputMethodServiceWrapper.java index b706a654e3a8..67212b60f1b8 100644 --- a/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/ims/InputMethodServiceWrapper.java +++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/ims/InputMethodServiceWrapper.java @@ -53,13 +53,14 @@ public class InputMethodServiceWrapper extends InputMethodService { @Override public void onStartInput(EditorInfo info, boolean restarting) { - Log.i(TAG, "onStartInput() editor=" + info + ", restarting=" + restarting); + Log.i(TAG, "onStartInput() editor=" + dumpEditorInfo(info) + ", restarting=" + restarting); super.onStartInput(info, restarting); } @Override public void onStartInputView(EditorInfo info, boolean restarting) { - Log.i(TAG, "onStartInputView() editor=" + info + ", restarting=" + restarting); + Log.i(TAG, "onStartInputView() editor=" + dumpEditorInfo(info) + + ", restarting=" + restarting); super.onStartInputView(info, restarting); mInputViewStarted = true; if (mCountDownLatchForTesting != null) { @@ -99,4 +100,14 @@ public class InputMethodServiceWrapper extends InputMethodService { mCountDownLatchForTesting.countDown(); } } + + private String dumpEditorInfo(EditorInfo info) { + var sb = new StringBuilder(); + sb.append("EditorInfo{packageName=").append(info.packageName); + sb.append(" fieldId=").append(info.fieldId); + sb.append(" hintText=").append(info.hintText); + sb.append(" privateImeOptions=").append(info.privateImeOptions); + sb.append("}"); + return sb.toString(); + } } |