summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Cosmin Băieș <cosminbaies@google.com> 2025-02-11 14:21:22 +0100
committer Cosmin Băieș <cosminbaies@google.com> 2025-02-11 16:57:49 +0100
commitdb4d909371d09dee8b0ceeeac21d9636c7b94617 (patch)
tree5c12820340d10c4de37f0baa899e21e0b90786db
parented465be2fafd9aee27477d50495c1e9fc365a01d (diff)
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
-rw-r--r--services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/AndroidManifest.xml4
-rw-r--r--services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java27
-rw-r--r--services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/xml/method.xml11
3 files changed, 28 insertions, 14 deletions
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/AndroidManifest.xml b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/AndroidManifest.xml
index b7de74987eb8..45523268c966 100644
--- a/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/AndroidManifest.xml
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/AndroidManifest.xml
@@ -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"
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java
index b501dd246363..5d64cb638702 100644
--- a/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java
@@ -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(
() -> {
diff --git a/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/xml/method.xml b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/xml/method.xml
index 872b0688814a..3dd4a97f464f 100644
--- a/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/xml/method.xml
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/xml/method.xml
@@ -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