summaryrefslogtreecommitdiffstats
path: root/core/tests
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2014-05-01 17:20:05 +0900
committerYohei Yukawa <yukawa@google.com>2014-05-01 19:13:25 +0900
commitd1da11529813f6d3f51518b5fe028e0b8084f5cc (patch)
tree3160da22cf12e5a66e37eec2915d48c7ececf853 /core/tests
parent64ab917e5eb3269c72c795781a512d4ee7d9d7a4 (diff)
downloadframeworks_base-d1da11529813f6d3f51518b5fe028e0b8084f5cc.zip
frameworks_base-d1da11529813f6d3f51518b5fe028e0b8084f5cc.tar.gz
frameworks_base-d1da11529813f6d3f51518b5fe028e0b8084f5cc.tar.bz2
Add unit tests for InputMethodSubtypeSwitchingController
This CL adds unit tests for InputMethodSubtypeSwitchingController as a ground work to make it aware of supportsSwitchingToNextInputMethod in a subsequent CL. This CL never changes existing behavior. BUG: 12981505 Change-Id: I3b2c46c47c7686b811fa248ad549f20875367425
Diffstat (limited to 'core/tests')
-rwxr-xr-xcore/tests/inputmethodtests/run_core_inputmethod_test.sh2
-rw-r--r--core/tests/inputmethodtests/src/android/os/InputMethodSubtypeSwitchingControllerTest.java205
2 files changed, 206 insertions, 1 deletions
diff --git a/core/tests/inputmethodtests/run_core_inputmethod_test.sh b/core/tests/inputmethodtests/run_core_inputmethod_test.sh
index b0b119b..9029ba5 100755
--- a/core/tests/inputmethodtests/run_core_inputmethod_test.sh
+++ b/core/tests/inputmethodtests/run_core_inputmethod_test.sh
@@ -21,4 +21,4 @@ if [[ $rebuild == true ]]; then
$COMMAND
fi
-adb shell am instrument -w -e class android.os.InputMethodTest,android.os.InputMethodSubtypeArrayTest com.android.frameworks.coretests.inputmethod/android.test.InstrumentationTestRunner
+adb shell am instrument -w -e class android.os.InputMethodTest,android.os.InputMethodSubtypeArrayTest,android.os.InputMethodSubtypeSwitchingControllerTest com.android.frameworks.coretests.inputmethod/android.test.InstrumentationTestRunner
diff --git a/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeSwitchingControllerTest.java b/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeSwitchingControllerTest.java
new file mode 100644
index 0000000..6d33529
--- /dev/null
+++ b/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeSwitchingControllerTest.java
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.os;
+
+import android.content.pm.ApplicationInfo;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+import android.test.InstrumentationTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.view.inputmethod.InputMethodInfo;
+import android.view.inputmethod.InputMethodSubtype;
+import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
+
+import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController;
+import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTestCase {
+ final private static String DUMMY_PACKAGE_NAME = "dymmy package name";
+ final private static String DUMMY_SETTING_ACTIVITY_NAME = "";
+ final private static boolean DUMMY_IS_AUX_IME = false;
+ final private static boolean DUMMY_FORCE_DEFAULT = false;
+ final private static int DUMMY_IS_DEFAULT_RES_ID = 0;
+ final private static String SYSTEM_LOCALE = "en_US";
+
+ private static InputMethodSubtype createDummySubtype(final String locale) {
+ final InputMethodSubtypeBuilder builder = new InputMethodSubtypeBuilder();
+ return builder.setSubtypeNameResId(0)
+ .setSubtypeIconResId(0)
+ .setSubtypeLocale(locale)
+ .setIsAsciiCapable(true)
+ .build();
+ }
+
+ private static void addDummyImeSubtypeListItems(List<ImeSubtypeListItem> items,
+ String imeName, String imeLabel, List<String> subtypeLocales,
+ boolean supportsSwitchingToNextInputMethod) {
+ final ResolveInfo ri = new ResolveInfo();
+ final ServiceInfo si = new ServiceInfo();
+ final ApplicationInfo ai = new ApplicationInfo();
+ ai.packageName = DUMMY_PACKAGE_NAME;
+ ai.enabled = true;
+ si.applicationInfo = ai;
+ si.enabled = true;
+ si.packageName = DUMMY_PACKAGE_NAME;
+ si.name = imeName;
+ si.exported = true;
+ si.nonLocalizedLabel = imeLabel;
+ ri.serviceInfo = si;
+ final List<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
+ for (String subtypeLocale : subtypeLocales) {
+ subtypes.add(createDummySubtype(subtypeLocale));
+ }
+ final InputMethodInfo imi = new InputMethodInfo(ri, DUMMY_IS_AUX_IME,
+ DUMMY_SETTING_ACTIVITY_NAME, subtypes, DUMMY_IS_DEFAULT_RES_ID,
+ DUMMY_FORCE_DEFAULT, supportsSwitchingToNextInputMethod);
+ for (int i = 0; i < subtypes.size(); ++i) {
+ final String subtypeLocale = subtypeLocales.get(i);
+ final InputMethodSubtype subtype = subtypes.get(i);
+ items.add(new ImeSubtypeListItem(imeName, subtypeLocale, imi, i, subtypeLocale,
+ SYSTEM_LOCALE));
+ }
+ }
+
+ private static List<ImeSubtypeListItem> createTestData() {
+ final List<ImeSubtypeListItem> items = new ArrayList<ImeSubtypeListItem>();
+ addDummyImeSubtypeListItems(items, "switchAwareLatinIme", "switchAwareLatinIme",
+ Arrays.asList("en_US", "es_US", "fr"),
+ true /* supportsSwitchingToNextInputMethod*/);
+ addDummyImeSubtypeListItems(items, "nonSwitchAwareLatinIme", "nonSwitchAwareLatinIme",
+ Arrays.asList("en_UK", "hi"),
+ false /* supportsSwitchingToNextInputMethod*/);
+ addDummyImeSubtypeListItems(items, "switchAwareJapaneseIme", "switchAwareJapaneseIme",
+ Arrays.asList("ja_JP"),
+ true /* supportsSwitchingToNextInputMethod*/);
+ addDummyImeSubtypeListItems(items, "nonSwitchAwareJapaneseIme", "nonSwitchAwareJapaneseIme",
+ Arrays.asList("ja_JP"),
+ false /* supportsSwitchingToNextInputMethod*/);
+ return items;
+ }
+
+ @SmallTest
+ public void testGetNextInputMethodImplWithNotOnlyCurrentIme() throws Exception {
+ final List<ImeSubtypeListItem> imList = createTestData();
+
+ final boolean ONLY_CURRENT_IME = false;
+ ImeSubtypeListItem currentIme;
+ ImeSubtypeListItem nextIme;
+
+ // "switchAwareLatinIme/en_US" -> "switchAwareLatinIme/es_US"
+ currentIme = imList.get(0);
+ nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl(
+ imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype(
+ currentIme.mSubtypeName.toString()));
+ assertEquals(imList.get(1), nextIme);
+ // "switchAwareLatinIme/es_US" -> "switchAwareLatinIme/fr"
+ currentIme = imList.get(1);
+ nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl(
+ imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype(
+ currentIme.mSubtypeName.toString()));
+ assertEquals(imList.get(2), nextIme);
+ // "switchAwareLatinIme/fr" -> "nonSwitchAwareLatinIme/en_UK
+ currentIme = imList.get(2);
+ nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl(
+ imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype(
+ currentIme.mSubtypeName.toString()));
+ assertEquals(imList.get(3), nextIme);
+ // "nonSwitchAwareLatinIme/en_UK" -> "nonSwitchAwareLatinIme/hi"
+ currentIme = imList.get(3);
+ nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl(
+ imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype(
+ currentIme.mSubtypeName.toString()));
+ assertEquals(imList.get(4), nextIme);
+ // "nonSwitchAwareLatinIme/hi" -> "switchAwareJapaneseIme/ja_JP"
+ currentIme = imList.get(4);
+ nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl(
+ imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype(
+ currentIme.mSubtypeName.toString()));
+ assertEquals(imList.get(5), nextIme);
+ // "switchAwareJapaneseIme/ja_JP" -> "nonSwitchAwareJapaneseIme/ja_JP"
+ currentIme = imList.get(5);
+ nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl(
+ imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype(
+ currentIme.mSubtypeName.toString()));
+ assertEquals(imList.get(6), nextIme);
+ // "nonSwitchAwareJapaneseIme/ja_JP" -> "switchAwareLatinIme/en_US"
+ currentIme = imList.get(6);
+ nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl(
+ imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype(
+ currentIme.mSubtypeName.toString()));
+ assertEquals(imList.get(0), nextIme);
+ }
+
+ @SmallTest
+ public void testGetNextInputMethodImplWithOnlyCurrentIme() throws Exception {
+ final List<ImeSubtypeListItem> imList = createTestData();
+
+ final boolean ONLY_CURRENT_IME = true;
+ ImeSubtypeListItem currentIme;
+ ImeSubtypeListItem nextIme;
+
+ // "switchAwareLatinIme/en_US" -> "switchAwareLatinIme/es_US"
+ currentIme = imList.get(0);
+ nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl(
+ imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype(
+ currentIme.mSubtypeName.toString()));
+ assertEquals(imList.get(1), nextIme);
+ // "switchAwareLatinIme/es_US" -> "switchAwareLatinIme/fr"
+ currentIme = imList.get(1);
+ nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl(
+ imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype(
+ currentIme.mSubtypeName.toString()));
+ assertEquals(imList.get(2), nextIme);
+ // "switchAwareLatinIme/fr" -> "switchAwareLatinIme/en_US"
+ currentIme = imList.get(2);
+ nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl(
+ imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype(
+ currentIme.mSubtypeName.toString()));
+ assertEquals(imList.get(0), nextIme);
+
+ // "nonSwitchAwareLatinIme/en_UK" -> "nonSwitchAwareLatinIme/hi"
+ currentIme = imList.get(3);
+ nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl(
+ imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype(
+ currentIme.mSubtypeName.toString()));
+ assertEquals(imList.get(4), nextIme);
+ // "nonSwitchAwareLatinIme/hi" -> "switchAwareLatinIme/en_UK"
+ currentIme = imList.get(4);
+ nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl(
+ imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype(
+ currentIme.mSubtypeName.toString()));
+ assertEquals(imList.get(3), nextIme);
+
+ // "switchAwareJapaneseIme/ja_JP" -> null
+ currentIme = imList.get(5);
+ nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl(
+ imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype(
+ currentIme.mSubtypeName.toString()));
+ assertNull(nextIme);
+
+ // "nonSwitchAwareJapaneseIme/ja_JP" -> null
+ currentIme = imList.get(6);
+ nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl(
+ imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype(
+ currentIme.mSubtypeName.toString()));
+ assertNull(nextIme);
+ }
+ }