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

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

Enable multiple subtypes in InputMethodServiceTest

Previously in testImeSwitchButtonClick we were checking if either the
menu was shown, or the IME is different (switched away). Currently this
would always be the second case as the actual system IME was still
enabled. However, we should not rely on this fact, but rather enable
addtional subtypes in our SimpleIME and check that we always end up
swiching the subtype.

This also ensures that the SimpleIME is always the currently running IME
at the end of each test.

Flag: EXEMPT testfix
Bug: 394328311
Test: atest InputMethodServiceTest#testImeSwitchButtonClick
  InputMethodServiceTest#testImeSwitchButtonLongClick
Change-Id: I16986c288565b060140a85090b5ba2fb4506bad4
parent ed465be2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -32,8 +32,8 @@
        <uses-library android:name="android.test.runner" />
    </application>

    <!-- The "targetPackage" reference the instruments APK package, which is the FakeImeApk, while
    the test package is "com.android.inputmethod.imetests" (FrameworksImeTests.apk).-->
    <!-- The "targetPackage" reference the instruments APK package, which is the SimpleTestIme.apk,
    while the test package is "com.android.inputmethod.imetests" (FrameworksImeTests.apk).-->
    <instrumentation
        android:name="androidx.test.runner.AndroidJUnitRunner"
        android:targetPackage="com.android.apps.inputmethod.simpleime"
+17 −10
Original line number Diff line number Diff line
@@ -92,6 +92,9 @@ 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";

    /** The ids of the subtypes of SimpleIme. */
    private static final int[] SUBTYPE_IDS = new int[]{1, 2};

    private final WindowManagerStateHelper mWmState =  new WindowManagerStateHelper();

    private final GestureNavSwitchHelper mGestureNavSwitchHelper = new GestureNavSwitchHelper();
@@ -833,8 +836,7 @@ public class InputMethodServiceTest {
    }

    /**
     * Verifies that clicking on the IME switch button either shows the Input Method Switcher Menu,
     * or switches the input method.
     * Verifies that clicking on the IME switch button switches the input method subtype.
     */
    @Test
    public void testImeSwitchButtonClick() throws Exception {
@@ -844,6 +846,12 @@ public class InputMethodServiceTest {

        setShowImeWithHardKeyboard(true /* enabled */);

        final var info = mImm.getCurrentInputMethodInfo();
        assertWithMessage("InputMethodInfo is not null").that(info).isNotNull();
        mImm.setExplicitlyEnabledInputMethodSubtypes(info.getId(), SUBTYPE_IDS);

        final var initialSubtype = mImm.getCurrentInputMethodSubtype();

        try (var ignored = mGestureNavSwitchHelper.withGestureNavigationMode()) {
            verifyInputViewStatusOnMainSync(
                    () -> {
@@ -852,23 +860,18 @@ public class InputMethodServiceTest {
                    },
                    EVENT_SHOW, true /* eventExpected */, true /* shown */, "IME is shown");

            final var initialInfo = mImm.getCurrentInputMethodInfo();

            final var imeSwitcherButton = getUiObject(By.res(INPUT_METHOD_NAV_IME_SWITCHER_ID));
            imeSwitcherButton.click();
            mInstrumentation.waitForIdleSync();

            final var newInfo = mImm.getCurrentInputMethodInfo();
            final var newSubtype = mImm.getCurrentInputMethodSubtype();

            assertWithMessage("Input Method Switcher Menu is shown or input method was switched")
                    .that(isInputMethodPickerShown(mImm) || !Objects.equals(initialInfo, newInfo))
            assertWithMessage("Input method subtype was switched")
                    .that(!Objects.equals(initialSubtype, newSubtype))
                    .isTrue();

            assertWithMessage("IME is still shown after IME Switcher button was clicked")
                    .that(mInputMethodService.isInputViewShown()).isTrue();

            // Hide the IME Switcher Menu before finishing.
            mUiDevice.pressBack();
        }
    }

@@ -883,6 +886,10 @@ public class InputMethodServiceTest {

        setShowImeWithHardKeyboard(true /* enabled */);

        final var info = mImm.getCurrentInputMethodInfo();
        assertWithMessage("InputMethodInfo is not null").that(info).isNotNull();
        mImm.setExplicitlyEnabledInputMethodSubtypes(info.getId(), SUBTYPE_IDS);

        try (var ignored = mGestureNavSwitchHelper.withGestureNavigationMode()) {
            verifyInputViewStatusOnMainSync(
                    () -> {
+9 −2
Original line number Diff line number Diff line
@@ -17,7 +17,14 @@

<input-method xmlns:android="http://schemas.android.com/apk/res/android">
    <subtype
        android:label="FakeIme"
        android:label="SimpleIme"
        android:imeSubtypeLocale="en_US"
        android:imeSubtypeMode="keyboard"/>
        android:imeSubtypeMode="keyboard"
        android:subtypeId="1" />

    <subtype
        android:label="SimpleIme French"
        android:imeSubtypeLocale="fr_FR"
        android:imeSubtypeMode="keyboard"
        android:subtypeId="2" />
</input-method>
 No newline at end of file