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

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

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
parent 38633894
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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",
+2 −8
Original line number Diff line number Diff line
@@ -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();
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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);