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

Commit 98e390c7 authored by Adrian Roos's avatar Adrian Roos
Browse files

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
parent 4ad3c8ad
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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();
+13 −2
Original line number Diff line number Diff line
@@ -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();
    }
}