Merge "Cleanup action key label unit tests"

This commit is contained in:
Tadashi G. Takaoka 2014-09-24 06:51:37 +00:00 committed by Android (Google) Code Review
commit 9f38c419bd
7 changed files with 223 additions and 163 deletions

View file

@ -16,12 +16,14 @@
package com.android.inputmethod.keyboard; package com.android.inputmethod.keyboard;
import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.text.InputType; import android.text.InputType;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyVisual;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.utils.RunInLocale; import com.android.inputmethod.latin.utils.RunInLocale;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
@ -29,28 +31,70 @@ import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
import java.util.Locale; import java.util.Locale;
abstract class KeyboardLayoutSetActionLabelBase extends KeyboardLayoutSetTestsBase { abstract class KeyboardLayoutSetActionLabelBase extends KeyboardLayoutSetTestsBase {
static class ExpectedActionKey {
static ExpectedActionKey newIconKey(final String iconName) {
final int iconId = KeyboardIconsSet.getIconId(iconName);
return new ExpectedActionKey(ExpectedKeyVisual.newInstance(iconId));
}
static ExpectedActionKey newLabelKey(final String label) {
return new ExpectedActionKey(ExpectedKeyVisual.newInstance(label));
}
static ExpectedActionKey newLabelKey(final int labelResId,
final Locale labelLocale, final Context context) {
final RunInLocale<String> getString = new RunInLocale<String>() {
@Override
protected String job(final Resources res) {
return res.getString(labelResId);
}
};
return newLabelKey(getString.runInLocale(context.getResources(), labelLocale));
}
private final ExpectedKeyVisual mVisual;
private ExpectedActionKey(final ExpectedKeyVisual visual) {
mVisual = visual;
}
public int getIconId() { return mVisual.getIconId(); }
public String getLabel() { return mVisual.getLabel(); }
}
protected static Locale getLabelLocale(final InputMethodSubtype subtype) {
if (subtype.getLocale().equals(SubtypeLocaleUtils.NO_LANGUAGE)) {
return null;
}
return SubtypeLocaleUtils.getSubtypeLocale(subtype);
}
public void testActionUnspecified() { public void testActionUnspecified() {
final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey(
KeyboardIconsSet.NAME_ENTER_KEY);
for (final InputMethodSubtype subtype : getAllSubtypesList()) { for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "unspecifiled " final String tag = "unspecifiled "
+ SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, expectedKey);
KeyboardIconsSet.NAME_ENTER_KEY);
} }
} }
public void testActionNone() { public void testActionNone() {
final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey(
KeyboardIconsSet.NAME_ENTER_KEY);
for (final InputMethodSubtype subtype : getAllSubtypesList()) { for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_NONE, doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_NONE, expectedKey);
KeyboardIconsSet.NAME_ENTER_KEY);
} }
} }
public void testActionSearch() { public void testActionSearch() {
final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey(
KeyboardIconsSet.NAME_SEARCH_KEY);
for (final InputMethodSubtype subtype : getAllSubtypesList()) { for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_SEARCH, doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_SEARCH, expectedKey);
KeyboardIconsSet.NAME_SEARCH_KEY);
} }
} }
@ -63,94 +107,47 @@ abstract class KeyboardLayoutSetActionLabelBase extends KeyboardLayoutSetTestsBa
public void testActionCustom() { public void testActionCustom() {
for (final InputMethodSubtype subtype : getAllSubtypesList()) { for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
final CharSequence customLabel = "customLabel";
final EditorInfo editorInfo = new EditorInfo(); final EditorInfo editorInfo = new EditorInfo();
editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED; editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED;
editorInfo.actionLabel = customLabel; editorInfo.actionLabel = "customLabel";
doTestActionKeyLabel(tag, subtype, editorInfo, customLabel); final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey("customLabel");
doTestActionKey(tag, subtype, editorInfo, expectedKey);
} }
} }
private static void doTestActionKey(final String tag, final KeyboardLayoutSet layoutSet, private static void assertActionKey(final String tag, final KeyboardLayoutSet layoutSet,
final int elementId, final CharSequence label, final int iconId) { final int elementId, final ExpectedActionKey expectedKey) {
final Keyboard keyboard = layoutSet.getKeyboard(elementId); final Keyboard keyboard = layoutSet.getKeyboard(elementId);
final Key enterKey = keyboard.getKey(Constants.CODE_ENTER); final Key actualKey = keyboard.getKey(Constants.CODE_ENTER);
assertNotNull(tag + " enter key on " + keyboard.mId, enterKey); assertNotNull(tag + " enter key on " + keyboard.mId, actualKey);
assertEquals(tag + " enter label " + enterKey, label, enterKey.getLabel()); assertEquals(tag + " label " + expectedKey, expectedKey.getLabel(), actualKey.getLabel());
assertEquals(tag + " enter icon " + enterKey, iconId, enterKey.getIconId()); assertEquals(tag + " icon " + expectedKey, expectedKey.getIconId(), actualKey.getIconId());
} }
protected void doTestActionKeyLabelResId(final String tag, final InputMethodSubtype subtype, protected void doTestActionKey(final String tag, final InputMethodSubtype subtype,
final int actionId, final int labelResId) { final int actionId, final ExpectedActionKey expectedKey) {
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(); final EditorInfo editorInfo = new EditorInfo();
editorInfo.imeOptions = actionId; editorInfo.imeOptions = actionId;
final RunInLocale<String> job = new RunInLocale<String>() { doTestActionKey(tag, subtype, editorInfo, expectedKey);
@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, protected void doTestActionKey(final String tag, final InputMethodSubtype subtype,
final EditorInfo editorInfo, final CharSequence label) { final EditorInfo editorInfo, final ExpectedActionKey expectedKey) {
// Test text layouts. // Test text layouts.
editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL;
final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo);
doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, expectedKey);
label, KeyboardIconsSet.ICON_UNDEFINED); assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, expectedKey);
doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, expectedKey);
label, KeyboardIconsSet.ICON_UNDEFINED);
doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED,
label, KeyboardIconsSet.ICON_UNDEFINED);
// Test phone number layouts. // Test phone number layouts.
doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, expectedKey);
label, KeyboardIconsSet.ICON_UNDEFINED); assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, expectedKey);
doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS,
label, KeyboardIconsSet.ICON_UNDEFINED);
// Test normal number layout. // Test normal number layout.
doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, expectedKey);
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. // Test number password layout.
editorInfo.inputType = editorInfo.inputType =
InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD;
final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo);
doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId); assertActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, expectedKey);
} }
} }

View file

@ -40,8 +40,9 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio
public void testActionGo() { public void testActionGo() {
for (final InputMethodSubtype subtype : getAllSubtypesList()) { for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_GO, final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey(
R.string.label_go_key); R.string.label_go_key, getLabelLocale(subtype), getContext());
doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_GO, expectedKey);
} }
} }
@ -49,8 +50,9 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio
public void testActionSend() { public void testActionSend() {
for (final InputMethodSubtype subtype : getAllSubtypesList()) { for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_SEND, final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey(
R.string.label_send_key); R.string.label_send_key, getLabelLocale(subtype), getContext());
doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_SEND, expectedKey);
} }
} }
@ -58,8 +60,9 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio
public void testActionNext() { public void testActionNext() {
for (final InputMethodSubtype subtype : getAllSubtypesList()) { for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_NEXT, final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey(
R.string.label_next_key); R.string.label_next_key, getLabelLocale(subtype), getContext());
doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_NEXT, expectedKey);
} }
} }
@ -67,8 +70,9 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio
public void testActionDone() { public void testActionDone() {
for (final InputMethodSubtype subtype : getAllSubtypesList()) { for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_DONE, final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey(
R.string.label_done_key); R.string.label_done_key, getLabelLocale(subtype), getContext());
doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_DONE, expectedKey);
} }
} }
@ -76,42 +80,59 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio
public void testActionPrevious() { public void testActionPrevious() {
for (final InputMethodSubtype subtype : getAllSubtypesList()) { for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey(
R.string.label_previous_key); R.string.label_previous_key, getLabelLocale(subtype), getContext());
doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, expectedKey);
} }
} }
private void doTestActionKeys(final InputMethodSubtype subtype, final String tag,
final ExpectedActionKey unspecifiedKey, final ExpectedActionKey noneKey,
final ExpectedActionKey goKey, final ExpectedActionKey searchKey,
final ExpectedActionKey sendKey, final ExpectedActionKey nextKey,
final ExpectedActionKey doneKey, final ExpectedActionKey previousKey) {
doTestActionKey(
tag + " unspecified", subtype, EditorInfo.IME_ACTION_UNSPECIFIED, unspecifiedKey);
doTestActionKey(tag + " none", subtype, EditorInfo.IME_ACTION_NONE, noneKey);
doTestActionKey(tag + " go", subtype, EditorInfo.IME_ACTION_GO, goKey);
doTestActionKey(tag + " search", subtype, EditorInfo.IME_ACTION_SEARCH, searchKey);
doTestActionKey(tag + " send", subtype, EditorInfo.IME_ACTION_SEND, sendKey);
doTestActionKey(tag + " next", subtype, EditorInfo.IME_ACTION_NEXT, nextKey);
doTestActionKey(tag + " done", subtype, EditorInfo.IME_ACTION_DONE, doneKey);
doTestActionKey(tag + " previous", subtype, EditorInfo.IME_ACTION_PREVIOUS, previousKey);
}
// Working variable to simulate system locale changing. // Working variable to simulate system locale changing.
private Locale mSystemLocale = Locale.getDefault(); private Locale mSystemLocale = Locale.getDefault();
private void doTestActionLabelInLocale(final InputMethodSubtype subtype, private void doTestActionKeysInLocale(final InputMethodSubtype subtype,
final Locale labelLocale, final Locale systemLocale) { final Locale labelLocale, final Locale systemLocale) {
// Simulate system locale changing, see {@link SystemBroadcastReceiver}. // Simulate system locale changing, see {@link SystemBroadcastReceiver}.
if (!systemLocale.equals(mSystemLocale)) { if (!systemLocale.equals(mSystemLocale)) {
KeyboardLayoutSet.onSystemLocaleChanged(); KeyboardLayoutSet.onSystemLocaleChanged();
mSystemLocale = systemLocale; mSystemLocale = systemLocale;
} }
final ExpectedActionKey enterKey = ExpectedActionKey.newIconKey(
KeyboardIconsSet.NAME_ENTER_KEY);
final ExpectedActionKey goKey = ExpectedActionKey.newLabelKey(
R.string.label_go_key, labelLocale, getContext());
final ExpectedActionKey searchKey = ExpectedActionKey.newIconKey(
KeyboardIconsSet.NAME_SEARCH_KEY);
final ExpectedActionKey sendKey = ExpectedActionKey.newLabelKey(
R.string.label_send_key, labelLocale, getContext());
final ExpectedActionKey nextKey = ExpectedActionKey.newLabelKey(
R.string.label_next_key, labelLocale, getContext());
final ExpectedActionKey doneKey = ExpectedActionKey.newLabelKey(
R.string.label_done_key, labelLocale, getContext());
final ExpectedActionKey previousKey = ExpectedActionKey.newLabelKey(
R.string.label_previous_key, labelLocale, getContext());
final String tag = "label=" + labelLocale + " system=" + systemLocale final String tag = "label=" + labelLocale + " system=" + systemLocale
+ " " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + " " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
final RunInLocale<Void> job = new RunInLocale<Void>() { final RunInLocale<Void> job = new RunInLocale<Void>() {
@Override @Override
public Void job(final Resources res) { public Void job(final Resources res) {
doTestActionKeyIcon(tag + " unspecified", subtype, doTestActionKeys(subtype, tag, enterKey, enterKey, goKey, searchKey, sendKey,
EditorInfo.IME_ACTION_UNSPECIFIED, KeyboardIconsSet.NAME_ENTER_KEY); nextKey, doneKey, previousKey);
doTestActionKeyIcon(tag + " none", subtype,
EditorInfo.IME_ACTION_NONE, KeyboardIconsSet.NAME_ENTER_KEY);
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);
doTestActionKeyLabelResIdInLocale(tag + " send", subtype,
EditorInfo.IME_ACTION_SEND, labelLocale, R.string.label_send_key);
doTestActionKeyLabelResIdInLocale(tag + " next", subtype,
EditorInfo.IME_ACTION_NEXT, labelLocale, R.string.label_next_key);
doTestActionKeyLabelResIdInLocale(tag + " done", subtype,
EditorInfo.IME_ACTION_DONE, labelLocale, R.string.label_done_key);
doTestActionKeyLabelResIdInLocale(tag + " previous", subtype,
EditorInfo.IME_ACTION_PREVIOUS, labelLocale, R.string.label_previous_key);
return null; return null;
} }
}; };
@ -123,10 +144,10 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio
final InputMethodSubtype italian = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( final InputMethodSubtype italian = richImm.findSubtypeByLocaleAndKeyboardLayoutSet(
Locale.ITALIAN.toString(), SubtypeLocaleUtils.QWERTY); Locale.ITALIAN.toString(), SubtypeLocaleUtils.QWERTY);
// An action label should be displayed in subtype's locale regardless of the system locale. // An action label should be displayed in subtype's locale regardless of the system locale.
doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.US); doTestActionKeysInLocale(italian, Locale.ITALIAN, Locale.US);
doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.FRENCH); doTestActionKeysInLocale(italian, Locale.ITALIAN, Locale.FRENCH);
doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.ITALIAN); doTestActionKeysInLocale(italian, Locale.ITALIAN, Locale.ITALIAN);
doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.JAPANESE); doTestActionKeysInLocale(italian, Locale.ITALIAN, Locale.JAPANESE);
} }
public void testNoLanguageSubtypeActionLabel() { public void testNoLanguageSubtypeActionLabel() {
@ -134,9 +155,9 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio
final InputMethodSubtype noLanguage = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( final InputMethodSubtype noLanguage = richImm.findSubtypeByLocaleAndKeyboardLayoutSet(
SubtypeLocaleUtils.NO_LANGUAGE, SubtypeLocaleUtils.QWERTY); SubtypeLocaleUtils.NO_LANGUAGE, SubtypeLocaleUtils.QWERTY);
// An action label of no language keyboard should be displayed in the system locale. // An action label of no language keyboard should be displayed in the system locale.
doTestActionLabelInLocale(noLanguage, Locale.US, Locale.US); doTestActionKeysInLocale(noLanguage, Locale.US, Locale.US);
doTestActionLabelInLocale(noLanguage, Locale.FRENCH, Locale.FRENCH); doTestActionKeysInLocale(noLanguage, Locale.FRENCH, Locale.FRENCH);
doTestActionLabelInLocale(noLanguage, Locale.ITALIAN, Locale.ITALIAN); doTestActionKeysInLocale(noLanguage, Locale.ITALIAN, Locale.ITALIAN);
doTestActionLabelInLocale(noLanguage, Locale.JAPANESE, Locale.JAPANESE); doTestActionKeysInLocale(noLanguage, Locale.JAPANESE, Locale.JAPANESE);
} }
} }

View file

@ -32,46 +32,51 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetActio
@Override @Override
public void testActionGo() { public void testActionGo() {
final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey(
KeyboardIconsSet.NAME_GO_KEY);
for (final InputMethodSubtype subtype : getAllSubtypesList()) { for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_GO, doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_GO, expectedKey);
KeyboardIconsSet.NAME_GO_KEY);
} }
} }
@Override @Override
public void testActionSend() { public void testActionSend() {
final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey(
KeyboardIconsSet.NAME_SEND_KEY);
for (final InputMethodSubtype subtype : getAllSubtypesList()) { for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_SEND, doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_SEND, expectedKey);
KeyboardIconsSet.NAME_SEND_KEY);
} }
} }
@Override @Override
public void testActionNext() { public void testActionNext() {
final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey(
KeyboardIconsSet.NAME_NEXT_KEY);
for (final InputMethodSubtype subtype : getAllSubtypesList()) { for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_NEXT, doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_NEXT, expectedKey);
KeyboardIconsSet.NAME_NEXT_KEY);
} }
} }
@Override @Override
public void testActionDone() { public void testActionDone() {
final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey(
KeyboardIconsSet.NAME_DONE_KEY);
for (final InputMethodSubtype subtype : getAllSubtypesList()) { for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_DONE, doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_DONE, expectedKey);
KeyboardIconsSet.NAME_DONE_KEY);
} }
} }
@Override @Override
public void testActionPrevious() { public void testActionPrevious() {
final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey(
KeyboardIconsSet.NAME_PREVIOUS_KEY);
for (final InputMethodSubtype subtype : getAllSubtypesList()) { for (final InputMethodSubtype subtype : getAllSubtypesList()) {
final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, expectedKey);
KeyboardIconsSet.NAME_PREVIOUS_KEY);
} }
} }
} }

View file

@ -105,11 +105,11 @@ public class ExpectedKey {
// The expected output of this key. // The expected output of this key.
private final ExpectedKeyOutput mOutput; private final ExpectedKeyOutput mOutput;
public final ExpectedKeyVisual getVisual() { protected final ExpectedKeyVisual getVisual() {
return mVisual; return mVisual;
} }
public final ExpectedKeyOutput getOutput() { protected final ExpectedKeyOutput getOutput() {
return mOutput; return mOutput;
} }
@ -162,18 +162,19 @@ public class ExpectedKey {
public boolean equalsTo(final Key key) { public boolean equalsTo(final Key key) {
// This key has no "more keys". // This key has no "more keys".
return mVisual.equalsTo(key) && mOutput.equalsTo(key) && key.getMoreKeys() == null; return mVisual.hasSameKeyVisual(key) && mOutput.hasSameKeyOutput(key)
&& key.getMoreKeys() == null;
} }
public boolean equalsTo(final MoreKeySpec moreKeySpec) { public boolean equalsTo(final MoreKeySpec moreKeySpec) {
return mVisual.equalsTo(moreKeySpec) && mOutput.equalsTo(moreKeySpec); return mVisual.hasSameKeyVisual(moreKeySpec) && mOutput.hasSameKeyOutput(moreKeySpec);
} }
@Override @Override
public boolean equals(final Object object) { public boolean equals(final Object object) {
if (object instanceof ExpectedKey) { if (object instanceof ExpectedKey) {
final ExpectedKey key = (ExpectedKey) object; final ExpectedKey key = (ExpectedKey) object;
return mVisual.equalsTo(key.mVisual) && mOutput.equalsTo(key.mOutput) return mVisual.hasSameKeyVisual(key.mVisual) && mOutput.hasSameKeyOutput(key.mOutput)
&& Arrays.equals(getMoreKeys(), key.getMoreKeys()); && Arrays.equals(getMoreKeys(), key.getMoreKeys());
} }
return false; return false;
@ -190,7 +191,7 @@ public class ExpectedKey {
@Override @Override
public String toString() { public String toString() {
if (mVisual.equalsTo(mOutput)) { if (mVisual.hasSameKeyVisual(mOutput)) {
return mVisual.toString(); return mVisual.toString();
} }
return mVisual + "|" + mOutput; return mVisual + "|" + mOutput;
@ -274,7 +275,7 @@ public class ExpectedKey {
@Override @Override
public boolean equalsTo(final Key key) { public boolean equalsTo(final Key key) {
if (getVisual().equalsTo(key) && getOutput().equalsTo(key)) { if (getVisual().hasSameKeyVisual(key) && getOutput().hasSameKeyOutput(key)) {
final MoreKeySpec[] moreKeySpecs = key.getMoreKeys(); final MoreKeySpec[] moreKeySpecs = key.getMoreKeys();
final ExpectedKey[] moreKeys = getMoreKeys(); final ExpectedKey[] moreKeys = getMoreKeys();
// This key should have at least one "more key". // This key should have at least one "more key".

View file

@ -43,10 +43,10 @@ abstract class ExpectedKeyOutput {
abstract ExpectedKeyOutput toUpperCase(final Locale locale); abstract ExpectedKeyOutput toUpperCase(final Locale locale);
abstract ExpectedKeyOutput preserveCase(); abstract ExpectedKeyOutput preserveCase();
abstract boolean equalsTo(final String text); abstract boolean hasSameKeyOutput(final String text);
abstract boolean equalsTo(final Key key); abstract boolean hasSameKeyOutput(final Key key);
abstract boolean equalsTo(final MoreKeySpec moreKeySpec); abstract boolean hasSameKeyOutput(final MoreKeySpec moreKeySpec);
abstract boolean equalsTo(final ExpectedKeyOutput output); abstract boolean hasSameKeyOutput(final ExpectedKeyOutput output);
/** /**
* This class represents an integer code point. * This class represents an integer code point.
@ -75,22 +75,22 @@ abstract class ExpectedKeyOutput {
} }
@Override @Override
boolean equalsTo(final String text) { boolean hasSameKeyOutput(final String text) {
return StringUtils.codePointCount(text) == 1 && text.codePointAt(0) == mCode; return StringUtils.codePointCount(text) == 1 && text.codePointAt(0) == mCode;
} }
@Override @Override
boolean equalsTo(final Key key) { boolean hasSameKeyOutput(final Key key) {
return mCode == key.getCode(); return mCode == key.getCode();
} }
@Override @Override
boolean equalsTo(final MoreKeySpec moreKeySpec) { boolean hasSameKeyOutput(final MoreKeySpec moreKeySpec) {
return mCode == moreKeySpec.mCode; return mCode == moreKeySpec.mCode;
} }
@Override @Override
boolean equalsTo(final ExpectedKeyOutput output) { boolean hasSameKeyOutput(final ExpectedKeyOutput output) {
return (output instanceof Code) && mCode == ((Code)output).mCode; return (output instanceof Code) && mCode == ((Code)output).mCode;
} }
@ -130,24 +130,24 @@ abstract class ExpectedKeyOutput {
} }
@Override @Override
boolean equalsTo(final String text) { boolean hasSameKeyOutput(final String text) {
return text.equals(text); return text.equals(text);
} }
@Override @Override
boolean equalsTo(final Key key) { boolean hasSameKeyOutput(final Key key) {
return key.getCode() == Constants.CODE_OUTPUT_TEXT return key.getCode() == Constants.CODE_OUTPUT_TEXT
&& mText.equals(key.getOutputText()); && mText.equals(key.getOutputText());
} }
@Override @Override
boolean equalsTo(final MoreKeySpec moreKeySpec) { boolean hasSameKeyOutput(final MoreKeySpec moreKeySpec) {
return moreKeySpec.mCode == Constants.CODE_OUTPUT_TEXT return moreKeySpec.mCode == Constants.CODE_OUTPUT_TEXT
&& mText.equals(moreKeySpec.mOutputText); && mText.equals(moreKeySpec.mOutputText);
} }
@Override @Override
boolean equalsTo(final ExpectedKeyOutput output) { boolean hasSameKeyOutput(final ExpectedKeyOutput output) {
return (output instanceof Text) && mText == ((Text)output).mText; return (output instanceof Text) && mText == ((Text)output).mText;
} }

View file

@ -27,22 +27,24 @@ import java.util.Locale;
* *
* There are two types of expected visual, an integer icon id and a string label. * There are two types of expected visual, an integer icon id and a string label.
*/ */
abstract class ExpectedKeyVisual { public abstract class ExpectedKeyVisual {
static ExpectedKeyVisual newInstance(final String label) { public static ExpectedKeyVisual newInstance(final String label) {
return new Label(label); return new Label(label);
} }
static ExpectedKeyVisual newInstance(final int iconId) { public static ExpectedKeyVisual newInstance(final int iconId) {
return new Icon(iconId); return new Icon(iconId);
} }
public abstract int getIconId();
public abstract String getLabel();
abstract ExpectedKeyVisual toUpperCase(final Locale locale); abstract ExpectedKeyVisual toUpperCase(final Locale locale);
abstract ExpectedKeyVisual preserveCase(); abstract ExpectedKeyVisual preserveCase();
abstract boolean equalsTo(final String text); abstract boolean hasSameKeyVisual(final String text);
abstract boolean equalsTo(final Key key); abstract boolean hasSameKeyVisual(final Key key);
abstract boolean equalsTo(final MoreKeySpec moreKeySpec); abstract boolean hasSameKeyVisual(final MoreKeySpec moreKeySpec);
abstract boolean equalsTo(final ExpectedKeyOutput output); abstract boolean hasSameKeyVisual(final ExpectedKeyOutput output);
abstract boolean equalsTo(final ExpectedKeyVisual visual); abstract boolean hasSameKeyVisual(final ExpectedKeyVisual visual);
/** /**
* This class represents an integer icon id. * This class represents an integer icon id.
@ -54,6 +56,16 @@ abstract class ExpectedKeyVisual {
mIconId = iconId; mIconId = iconId;
} }
@Override
public int getIconId() {
return mIconId;
}
@Override
public String getLabel() {
return null;
}
@Override @Override
ExpectedKeyVisual toUpperCase(final Locale locale) { ExpectedKeyVisual toUpperCase(final Locale locale) {
return this; return this;
@ -65,27 +77,32 @@ abstract class ExpectedKeyVisual {
} }
@Override @Override
boolean equalsTo(final String text) { boolean hasSameKeyVisual(final String text) {
return false; return false;
} }
@Override @Override
boolean equalsTo(final Key key) { boolean hasSameKeyVisual(final Key key) {
return mIconId == key.getIconId(); // If the actual key has an icon as its visual, a label has to be null.
// See {@link KeyboardView#onDrawKeyTopVisuals(Key,Canvas,Paint,KeyDrawParams).
return mIconId == key.getIconId() && key.getLabel() == null;
} }
@Override @Override
boolean equalsTo(final MoreKeySpec moreKeySpec) { boolean hasSameKeyVisual(final MoreKeySpec moreKeySpec) {
return mIconId == moreKeySpec.mIconId; // If the actual more key has an icon as its visual, a label has to be null.
// See {@link KeySpecParser#getIconId(String)} and
// {@link KeySpecParser#getLabel(String)}.
return mIconId == moreKeySpec.mIconId && moreKeySpec.mLabel == null;
} }
@Override @Override
boolean equalsTo(final ExpectedKeyOutput output) { boolean hasSameKeyVisual(final ExpectedKeyOutput output) {
return false; return false;
} }
@Override @Override
boolean equalsTo(final ExpectedKeyVisual visual) { boolean hasSameKeyVisual(final ExpectedKeyVisual visual) {
return (visual instanceof Icon) && mIconId == ((Icon)visual).mIconId; return (visual instanceof Icon) && mIconId == ((Icon)visual).mIconId;
} }
@ -101,7 +118,19 @@ abstract class ExpectedKeyVisual {
private static class Label extends ExpectedKeyVisual { private static class Label extends ExpectedKeyVisual {
private final String mLabel; private final String mLabel;
Label(final String label) { mLabel = label; } Label(final String label) {
mLabel = label;
}
@Override
public int getIconId() {
return KeyboardIconsSet.ICON_UNDEFINED;
}
@Override
public String getLabel() {
return mLabel;
}
@Override @Override
ExpectedKeyVisual toUpperCase(final Locale locale) { ExpectedKeyVisual toUpperCase(final Locale locale) {
@ -114,27 +143,34 @@ abstract class ExpectedKeyVisual {
} }
@Override @Override
boolean equalsTo(final String text) { boolean hasSameKeyVisual(final String text) {
return mLabel.equals(text); return mLabel.equals(text);
} }
@Override @Override
boolean equalsTo(final Key key) { boolean hasSameKeyVisual(final Key key) {
return mLabel.equals(key.getLabel()); // If the actual key has a label as its visual, an icon has to be undefined.
// See {@link KeyboardView#onDrawKeyTopVisuals(Key,Canvas,Paint,KeyDrawParams).
return mLabel.equals(key.getLabel())
&& key.getIconId() == KeyboardIconsSet.ICON_UNDEFINED;
} }
@Override @Override
boolean equalsTo(final MoreKeySpec moreKeySpec) { boolean hasSameKeyVisual(final MoreKeySpec moreKeySpec) {
return mLabel.equals(moreKeySpec.mLabel); // If the actual more key has a label as its visual, an icon has to be undefined.
// See {@link KeySpecParser#getIconId(String)} and
// {@link KeySpecParser#getLabel(String)}.
return mLabel.equals(moreKeySpec.mLabel)
&& moreKeySpec.mIconId == KeyboardIconsSet.ICON_UNDEFINED;
} }
@Override @Override
boolean equalsTo(final ExpectedKeyOutput output) { boolean hasSameKeyVisual(final ExpectedKeyOutput output) {
return output.equalsTo(mLabel); return output.hasSameKeyOutput(mLabel);
} }
@Override @Override
boolean equalsTo(final ExpectedKeyVisual visual) { boolean hasSameKeyVisual(final ExpectedKeyVisual visual) {
return (visual instanceof Label) && mLabel.equals(((Label)visual).mLabel); return (visual instanceof Label) && mLabel.equals(((Label)visual).mLabel);
} }

View file

@ -91,7 +91,7 @@ public final class ExpectedKeyboardBuilder extends AbstractKeyboardBuilder<Expec
ExpectedKey[] keys = getRowAt(row); ExpectedKey[] keys = getRowAt(row);
for (int columnIndex = 0; columnIndex < keys.length; /* nothing */) { for (int columnIndex = 0; columnIndex < keys.length; /* nothing */) {
final ExpectedKey currentKey = keys[columnIndex]; final ExpectedKey currentKey = keys[columnIndex];
if (!currentKey.getVisual().equalsTo(visual)) { if (!currentKey.getVisual().hasSameKeyVisual(visual)) {
columnIndex++; columnIndex++;
continue; continue;
} }