Loading tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelBase.java 0 → 100644 +156 −0 Original line number Diff line number Diff line /* * 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 com.android.inputmethod.keyboard; import android.content.res.Resources; import android.text.InputType; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.utils.RunInLocale; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import java.util.Locale; abstract class KeyboardLayoutSetActionLabelBase extends KeyboardLayoutSetTestsBase { public void testActionUnspecified() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "unspecifiled " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, KeyboardIconsSet.NAME_ENTER_KEY); } } public void testActionNone() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_NONE, KeyboardIconsSet.NAME_ENTER_KEY); } } public void testActionSearch() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_SEARCH, KeyboardIconsSet.NAME_SEARCH_KEY); } } public abstract void testActionGo(); public abstract void testActionSend(); public abstract void testActionNext(); public abstract void testActionDone(); public abstract void testActionPrevious(); public void testActionCustom() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final CharSequence customLabel = "customLabel"; final EditorInfo editorInfo = new EditorInfo(); editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED; editorInfo.actionLabel = customLabel; doTestActionKeyLabel(tag, subtype, editorInfo, customLabel); } } private static void doTestActionKey(final String tag, final KeyboardLayoutSet layoutSet, final int elementId, final CharSequence label, final int iconId) { final Keyboard keyboard = layoutSet.getKeyboard(elementId); final Key enterKey = keyboard.getKey(Constants.CODE_ENTER); assertNotNull(tag + " enter key on " + keyboard.mId, enterKey); assertEquals(tag + " enter label " + enterKey, label, enterKey.getLabel()); assertEquals(tag + " enter icon " + enterKey, iconId, enterKey.getIconId()); } protected void doTestActionKeyLabelResId(final String tag, final InputMethodSubtype subtype, final int actionId, final int labelResId) { final Locale labelLocale = subtype.getLocale().equals(SubtypeLocaleUtils.NO_LANGUAGE) ? null : SubtypeLocaleUtils.getSubtypeLocale(subtype); doTestActionKeyLabelResIdInLocale(tag, subtype, actionId, labelLocale, labelResId); } protected void doTestActionKeyLabelResIdInLocale(final String tag, final InputMethodSubtype subtype, final int actionId, final Locale labelLocale, final int labelResId) { final EditorInfo editorInfo = new EditorInfo(); editorInfo.imeOptions = actionId; final RunInLocale<String> job = new RunInLocale<String>() { @Override protected String job(final Resources res) { return res.getString(labelResId); } }; final String label = job.runInLocale(getContext().getResources(), labelLocale); doTestActionKeyLabel(tag, subtype, editorInfo, label); } protected void doTestActionKeyLabel(final String tag, final InputMethodSubtype subtype, final EditorInfo editorInfo, final CharSequence label) { // Test text layouts. editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, label, KeyboardIconsSet.ICON_UNDEFINED); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, label, KeyboardIconsSet.ICON_UNDEFINED); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, label, KeyboardIconsSet.ICON_UNDEFINED); // Test phone number layouts. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, label, KeyboardIconsSet.ICON_UNDEFINED); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, label, KeyboardIconsSet.ICON_UNDEFINED); // Test normal number layout. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, label, KeyboardIconsSet.ICON_UNDEFINED); // Test number password layouts. editorInfo.inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, label, KeyboardIconsSet.ICON_UNDEFINED); } protected void doTestActionKeyIcon(final String tag, final InputMethodSubtype subtype, final int actionId, final String iconName) { final int iconId = KeyboardIconsSet.getIconId(iconName); final EditorInfo editorInfo = new EditorInfo(); editorInfo.imeOptions = actionId; // Test text layouts. editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, null /* label */, iconId); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, null /* label */, iconId); doTestActionKey( tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, null /* label */, iconId); // Test phone number layouts. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, null /* label */, iconId); doTestActionKey( tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, null /* label */, iconId); // Test normal number layout. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId); // Test number password layout. editorInfo.inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId); } } tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelKlpTests.java +16 −53 Original line number Diff line number Diff line Loading @@ -30,61 +30,27 @@ import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import java.util.Locale; @MediumTest public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActionLabelLxxTests { public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActionLabelBase { @Override protected int getKeyboardThemeForTests() { return KeyboardTheme.THEME_ID_KLP; } protected void doTestActionKeyLabel(final String tag, final InputMethodSubtype subtype, final int actionId, final int labelResId) { final Locale labelLocale = subtype.getLocale().equals(SubtypeLocaleUtils.NO_LANGUAGE) ? null : SubtypeLocaleUtils.getSubtypeLocale(subtype); doTestActionKeyLabel(tag, subtype, actionId, labelLocale, labelResId); } protected void doTestActionKeyLabel(final String tag, final InputMethodSubtype subtype, final int actionId, final Locale labelLocale, final int labelResId) { final EditorInfo editorInfo = new EditorInfo(); editorInfo.imeOptions = actionId; final RunInLocale<String> job = new RunInLocale<String>() { @Override protected String job(final Resources res) { return res.getString(labelResId); } }; final String label = job.runInLocale(getContext().getResources(), labelLocale); doTestActionKeyLabel(tag, subtype, editorInfo, label); } @Override public void testActionUnspecified() { super.testActionUnspecified(); } @Override public void testActionNone() { super.testActionNone(); } @Override public void testActionGo() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_GO, R.string.label_go_key); doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_GO, R.string.label_go_key); } } @Override public void testActionSearch() { super.testActionSearch(); } @Override public void testActionSend() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_SEND, R.string.label_send_key); doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_SEND, R.string.label_send_key); } } Loading @@ -92,7 +58,8 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio public void testActionNext() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_NEXT, R.string.label_next_key); doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_NEXT, R.string.label_next_key); } } Loading @@ -100,7 +67,8 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio public void testActionDone() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_DONE, R.string.label_done_key); doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_DONE, R.string.label_done_key); } } Loading @@ -108,14 +76,9 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio public void testActionPrevious() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyLabel( tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, R.string.label_previous_key); } doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, R.string.label_previous_key); } @Override public void testActionCustom() { super.testActionCustom(); } // Working variable to simulate system locale changing. Loading @@ -137,17 +100,17 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio EditorInfo.IME_ACTION_UNSPECIFIED, KeyboardIconsSet.NAME_ENTER_KEY); doTestActionKeyIcon(tag + " none", subtype, EditorInfo.IME_ACTION_NONE, KeyboardIconsSet.NAME_ENTER_KEY); doTestActionKeyLabel(tag + " go", subtype, doTestActionKeyLabelResIdInLocale(tag + " go", subtype, EditorInfo.IME_ACTION_GO, labelLocale, R.string.label_go_key); doTestActionKeyIcon(tag + " search", subtype, EditorInfo.IME_ACTION_SEARCH, KeyboardIconsSet.NAME_SEARCH_KEY); doTestActionKeyLabel(tag + " send", subtype, doTestActionKeyLabelResIdInLocale(tag + " send", subtype, EditorInfo.IME_ACTION_SEND, labelLocale, R.string.label_send_key); doTestActionKeyLabel(tag + " next", subtype, doTestActionKeyLabelResIdInLocale(tag + " next", subtype, EditorInfo.IME_ACTION_NEXT, labelLocale, R.string.label_next_key); doTestActionKeyLabel(tag + " done", subtype, doTestActionKeyLabelResIdInLocale(tag + " done", subtype, EditorInfo.IME_ACTION_DONE, labelLocale, R.string.label_done_key); doTestActionKeyLabel(tag + " previous", subtype, doTestActionKeyLabelResIdInLocale(tag + " previous", subtype, EditorInfo.IME_ACTION_PREVIOUS, labelLocale, R.string.label_previous_key); return null; } Loading tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelLxxTests.java +7 −101 Original line number Diff line number Diff line Loading @@ -17,99 +17,20 @@ package com.android.inputmethod.keyboard; import android.test.suitebuilder.annotation.MediumTest; import android.text.InputType; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; @MediumTest public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTestsBase { public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetActionLabelBase { @Override protected int getKeyboardThemeForTests() { return KeyboardTheme.THEME_ID_LXX_DARK; } private static void doTestActionKey(final String tag, final KeyboardLayoutSet layoutSet, final int elementId, final CharSequence label, final int iconId) { final Keyboard keyboard = layoutSet.getKeyboard(elementId); final Key enterKey = keyboard.getKey(Constants.CODE_ENTER); assertNotNull(tag + " enter key on " + keyboard.mId, enterKey); assertEquals(tag + " enter label " + enterKey, label, enterKey.getLabel()); assertEquals(tag + " enter icon " + enterKey, iconId, enterKey.getIconId()); } protected void doTestActionKeyLabel(final String tag, final InputMethodSubtype subtype, final EditorInfo editorInfo, final CharSequence label) { // Test text layouts. editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, label, KeyboardIconsSet.ICON_UNDEFINED); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, label, KeyboardIconsSet.ICON_UNDEFINED); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, label, KeyboardIconsSet.ICON_UNDEFINED); // Test phone number layouts. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, label, KeyboardIconsSet.ICON_UNDEFINED); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, label, KeyboardIconsSet.ICON_UNDEFINED); // Test normal number layout. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, label, KeyboardIconsSet.ICON_UNDEFINED); // Test number password layouts. editorInfo.inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, label, KeyboardIconsSet.ICON_UNDEFINED); } protected void doTestActionKeyIcon(final String tag, final InputMethodSubtype subtype, final int actionId, final String iconName) { final int iconId = KeyboardIconsSet.getIconId(iconName); final EditorInfo editorInfo = new EditorInfo(); editorInfo.imeOptions = actionId; // Test text layouts. editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, null /* label */, iconId); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, null /* label */, iconId); doTestActionKey( tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, null /* label */, iconId); // Test phone number layouts. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, null /* label */, iconId); doTestActionKey( tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, null /* label */, iconId); // Test normal number layout. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId); // Test number password layout. editorInfo.inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId); } public void testActionUnspecified() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "unspecifiled " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, KeyboardIconsSet.NAME_ENTER_KEY); } } public void testActionNone() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_NONE, KeyboardIconsSet.NAME_ENTER_KEY); } return KeyboardTheme.THEME_ID_LXX_LIGHT; } @Override public void testActionGo() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); Loading @@ -118,14 +39,7 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTests } } public void testActionSearch() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_SEARCH, KeyboardIconsSet.NAME_SEARCH_KEY); } } @Override public void testActionSend() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); Loading @@ -134,6 +48,7 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTests } } @Override public void testActionNext() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); Loading @@ -142,6 +57,7 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTests } } @Override public void testActionDone() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); Loading @@ -150,6 +66,7 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTests } } @Override public void testActionPrevious() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); Loading @@ -157,15 +74,4 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTests KeyboardIconsSet.NAME_PREVIOUS_KEY); } } public void testActionCustom() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final CharSequence customLabel = "customLabel"; final EditorInfo editorInfo = new EditorInfo(); editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED; editorInfo.actionLabel = customLabel; doTestActionKeyLabel(tag, subtype, editorInfo, customLabel); } } } Loading
tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelBase.java 0 → 100644 +156 −0 Original line number Diff line number Diff line /* * 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 com.android.inputmethod.keyboard; import android.content.res.Resources; import android.text.InputType; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.utils.RunInLocale; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import java.util.Locale; abstract class KeyboardLayoutSetActionLabelBase extends KeyboardLayoutSetTestsBase { public void testActionUnspecified() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "unspecifiled " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, KeyboardIconsSet.NAME_ENTER_KEY); } } public void testActionNone() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_NONE, KeyboardIconsSet.NAME_ENTER_KEY); } } public void testActionSearch() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_SEARCH, KeyboardIconsSet.NAME_SEARCH_KEY); } } public abstract void testActionGo(); public abstract void testActionSend(); public abstract void testActionNext(); public abstract void testActionDone(); public abstract void testActionPrevious(); public void testActionCustom() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final CharSequence customLabel = "customLabel"; final EditorInfo editorInfo = new EditorInfo(); editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED; editorInfo.actionLabel = customLabel; doTestActionKeyLabel(tag, subtype, editorInfo, customLabel); } } private static void doTestActionKey(final String tag, final KeyboardLayoutSet layoutSet, final int elementId, final CharSequence label, final int iconId) { final Keyboard keyboard = layoutSet.getKeyboard(elementId); final Key enterKey = keyboard.getKey(Constants.CODE_ENTER); assertNotNull(tag + " enter key on " + keyboard.mId, enterKey); assertEquals(tag + " enter label " + enterKey, label, enterKey.getLabel()); assertEquals(tag + " enter icon " + enterKey, iconId, enterKey.getIconId()); } protected void doTestActionKeyLabelResId(final String tag, final InputMethodSubtype subtype, final int actionId, final int labelResId) { final Locale labelLocale = subtype.getLocale().equals(SubtypeLocaleUtils.NO_LANGUAGE) ? null : SubtypeLocaleUtils.getSubtypeLocale(subtype); doTestActionKeyLabelResIdInLocale(tag, subtype, actionId, labelLocale, labelResId); } protected void doTestActionKeyLabelResIdInLocale(final String tag, final InputMethodSubtype subtype, final int actionId, final Locale labelLocale, final int labelResId) { final EditorInfo editorInfo = new EditorInfo(); editorInfo.imeOptions = actionId; final RunInLocale<String> job = new RunInLocale<String>() { @Override protected String job(final Resources res) { return res.getString(labelResId); } }; final String label = job.runInLocale(getContext().getResources(), labelLocale); doTestActionKeyLabel(tag, subtype, editorInfo, label); } protected void doTestActionKeyLabel(final String tag, final InputMethodSubtype subtype, final EditorInfo editorInfo, final CharSequence label) { // Test text layouts. editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, label, KeyboardIconsSet.ICON_UNDEFINED); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, label, KeyboardIconsSet.ICON_UNDEFINED); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, label, KeyboardIconsSet.ICON_UNDEFINED); // Test phone number layouts. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, label, KeyboardIconsSet.ICON_UNDEFINED); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, label, KeyboardIconsSet.ICON_UNDEFINED); // Test normal number layout. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, label, KeyboardIconsSet.ICON_UNDEFINED); // Test number password layouts. editorInfo.inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, label, KeyboardIconsSet.ICON_UNDEFINED); } protected void doTestActionKeyIcon(final String tag, final InputMethodSubtype subtype, final int actionId, final String iconName) { final int iconId = KeyboardIconsSet.getIconId(iconName); final EditorInfo editorInfo = new EditorInfo(); editorInfo.imeOptions = actionId; // Test text layouts. editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, null /* label */, iconId); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, null /* label */, iconId); doTestActionKey( tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, null /* label */, iconId); // Test phone number layouts. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, null /* label */, iconId); doTestActionKey( tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, null /* label */, iconId); // Test normal number layout. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId); // Test number password layout. editorInfo.inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId); } }
tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelKlpTests.java +16 −53 Original line number Diff line number Diff line Loading @@ -30,61 +30,27 @@ import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import java.util.Locale; @MediumTest public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActionLabelLxxTests { public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActionLabelBase { @Override protected int getKeyboardThemeForTests() { return KeyboardTheme.THEME_ID_KLP; } protected void doTestActionKeyLabel(final String tag, final InputMethodSubtype subtype, final int actionId, final int labelResId) { final Locale labelLocale = subtype.getLocale().equals(SubtypeLocaleUtils.NO_LANGUAGE) ? null : SubtypeLocaleUtils.getSubtypeLocale(subtype); doTestActionKeyLabel(tag, subtype, actionId, labelLocale, labelResId); } protected void doTestActionKeyLabel(final String tag, final InputMethodSubtype subtype, final int actionId, final Locale labelLocale, final int labelResId) { final EditorInfo editorInfo = new EditorInfo(); editorInfo.imeOptions = actionId; final RunInLocale<String> job = new RunInLocale<String>() { @Override protected String job(final Resources res) { return res.getString(labelResId); } }; final String label = job.runInLocale(getContext().getResources(), labelLocale); doTestActionKeyLabel(tag, subtype, editorInfo, label); } @Override public void testActionUnspecified() { super.testActionUnspecified(); } @Override public void testActionNone() { super.testActionNone(); } @Override public void testActionGo() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_GO, R.string.label_go_key); doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_GO, R.string.label_go_key); } } @Override public void testActionSearch() { super.testActionSearch(); } @Override public void testActionSend() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_SEND, R.string.label_send_key); doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_SEND, R.string.label_send_key); } } Loading @@ -92,7 +58,8 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio public void testActionNext() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_NEXT, R.string.label_next_key); doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_NEXT, R.string.label_next_key); } } Loading @@ -100,7 +67,8 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio public void testActionDone() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_DONE, R.string.label_done_key); doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_DONE, R.string.label_done_key); } } Loading @@ -108,14 +76,9 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio public void testActionPrevious() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyLabel( tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, R.string.label_previous_key); } doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, R.string.label_previous_key); } @Override public void testActionCustom() { super.testActionCustom(); } // Working variable to simulate system locale changing. Loading @@ -137,17 +100,17 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio EditorInfo.IME_ACTION_UNSPECIFIED, KeyboardIconsSet.NAME_ENTER_KEY); doTestActionKeyIcon(tag + " none", subtype, EditorInfo.IME_ACTION_NONE, KeyboardIconsSet.NAME_ENTER_KEY); doTestActionKeyLabel(tag + " go", subtype, doTestActionKeyLabelResIdInLocale(tag + " go", subtype, EditorInfo.IME_ACTION_GO, labelLocale, R.string.label_go_key); doTestActionKeyIcon(tag + " search", subtype, EditorInfo.IME_ACTION_SEARCH, KeyboardIconsSet.NAME_SEARCH_KEY); doTestActionKeyLabel(tag + " send", subtype, doTestActionKeyLabelResIdInLocale(tag + " send", subtype, EditorInfo.IME_ACTION_SEND, labelLocale, R.string.label_send_key); doTestActionKeyLabel(tag + " next", subtype, doTestActionKeyLabelResIdInLocale(tag + " next", subtype, EditorInfo.IME_ACTION_NEXT, labelLocale, R.string.label_next_key); doTestActionKeyLabel(tag + " done", subtype, doTestActionKeyLabelResIdInLocale(tag + " done", subtype, EditorInfo.IME_ACTION_DONE, labelLocale, R.string.label_done_key); doTestActionKeyLabel(tag + " previous", subtype, doTestActionKeyLabelResIdInLocale(tag + " previous", subtype, EditorInfo.IME_ACTION_PREVIOUS, labelLocale, R.string.label_previous_key); return null; } Loading
tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelLxxTests.java +7 −101 Original line number Diff line number Diff line Loading @@ -17,99 +17,20 @@ package com.android.inputmethod.keyboard; import android.test.suitebuilder.annotation.MediumTest; import android.text.InputType; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; @MediumTest public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTestsBase { public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetActionLabelBase { @Override protected int getKeyboardThemeForTests() { return KeyboardTheme.THEME_ID_LXX_DARK; } private static void doTestActionKey(final String tag, final KeyboardLayoutSet layoutSet, final int elementId, final CharSequence label, final int iconId) { final Keyboard keyboard = layoutSet.getKeyboard(elementId); final Key enterKey = keyboard.getKey(Constants.CODE_ENTER); assertNotNull(tag + " enter key on " + keyboard.mId, enterKey); assertEquals(tag + " enter label " + enterKey, label, enterKey.getLabel()); assertEquals(tag + " enter icon " + enterKey, iconId, enterKey.getIconId()); } protected void doTestActionKeyLabel(final String tag, final InputMethodSubtype subtype, final EditorInfo editorInfo, final CharSequence label) { // Test text layouts. editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, label, KeyboardIconsSet.ICON_UNDEFINED); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, label, KeyboardIconsSet.ICON_UNDEFINED); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, label, KeyboardIconsSet.ICON_UNDEFINED); // Test phone number layouts. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, label, KeyboardIconsSet.ICON_UNDEFINED); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, label, KeyboardIconsSet.ICON_UNDEFINED); // Test normal number layout. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, label, KeyboardIconsSet.ICON_UNDEFINED); // Test number password layouts. editorInfo.inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, label, KeyboardIconsSet.ICON_UNDEFINED); } protected void doTestActionKeyIcon(final String tag, final InputMethodSubtype subtype, final int actionId, final String iconName) { final int iconId = KeyboardIconsSet.getIconId(iconName); final EditorInfo editorInfo = new EditorInfo(); editorInfo.imeOptions = actionId; // Test text layouts. editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, null /* label */, iconId); doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, null /* label */, iconId); doTestActionKey( tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, null /* label */, iconId); // Test phone number layouts. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, null /* label */, iconId); doTestActionKey( tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, null /* label */, iconId); // Test normal number layout. doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId); // Test number password layout. editorInfo.inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId); } public void testActionUnspecified() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "unspecifiled " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, KeyboardIconsSet.NAME_ENTER_KEY); } } public void testActionNone() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_NONE, KeyboardIconsSet.NAME_ENTER_KEY); } return KeyboardTheme.THEME_ID_LXX_LIGHT; } @Override public void testActionGo() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); Loading @@ -118,14 +39,7 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTests } } public void testActionSearch() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_SEARCH, KeyboardIconsSet.NAME_SEARCH_KEY); } } @Override public void testActionSend() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); Loading @@ -134,6 +48,7 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTests } } @Override public void testActionNext() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); Loading @@ -142,6 +57,7 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTests } } @Override public void testActionDone() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); Loading @@ -150,6 +66,7 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTests } } @Override public void testActionPrevious() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); Loading @@ -157,15 +74,4 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTests KeyboardIconsSet.NAME_PREVIOUS_KEY); } } public void testActionCustom() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final CharSequence customLabel = "customLabel"; final EditorInfo editorInfo = new EditorInfo(); editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED; editorInfo.actionLabel = customLabel; doTestActionKeyLabel(tag, subtype, editorInfo, customLabel); } } }