KeyboardLayoutSetActionLabelLxxTests.java revision 5f19606d54266e55bb065880c77a74b1d47a52c8
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.inputmethod.keyboard;
18
19import android.test.suitebuilder.annotation.MediumTest;
20import android.text.InputType;
21import android.view.inputmethod.EditorInfo;
22import android.view.inputmethod.InputMethodSubtype;
23
24import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
25import com.android.inputmethod.latin.Constants;
26import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
27
28@MediumTest
29public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTestsBase {
30    @Override
31    protected int getKeyboardThemeForTests() {
32        return KeyboardTheme.THEME_ID_LXX_DARK;
33    }
34
35    private static void doTestActionKey(final String tag, final KeyboardLayoutSet layoutSet,
36            final int elementId, final CharSequence label, final int iconId) {
37        final Keyboard keyboard = layoutSet.getKeyboard(elementId);
38        final Key enterKey = keyboard.getKey(Constants.CODE_ENTER);
39        assertNotNull(tag + " enter key on " + keyboard.mId, enterKey);
40        assertEquals(tag + " enter label " + enterKey, label, enterKey.getLabel());
41        assertEquals(tag + " enter icon " + enterKey, iconId, enterKey.getIconId());
42    }
43
44    protected void doTestActionKeyLabel(final String tag, final InputMethodSubtype subtype,
45            final EditorInfo editorInfo, final CharSequence label) {
46        // Test text layouts.
47        editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL;
48        final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo);
49        doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET,
50                label, KeyboardIconsSet.ICON_UNDEFINED);
51        doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS,
52                label, KeyboardIconsSet.ICON_UNDEFINED);
53        doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED,
54                label, KeyboardIconsSet.ICON_UNDEFINED);
55        // Test phone number layouts.
56        doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE,
57                label, KeyboardIconsSet.ICON_UNDEFINED);
58        doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS,
59                label, KeyboardIconsSet.ICON_UNDEFINED);
60        // Test normal number layout.
61        doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER,
62                label, KeyboardIconsSet.ICON_UNDEFINED);
63        // Test number password layouts.
64        editorInfo.inputType =
65                InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD;
66        final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo);
67        doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER,
68                label, KeyboardIconsSet.ICON_UNDEFINED);
69    }
70
71    protected void doTestActionKeyIcon(final String tag, final InputMethodSubtype subtype,
72            final int actionId, final String iconName) {
73        final int iconId = KeyboardIconsSet.getIconId(iconName);
74        final EditorInfo editorInfo = new EditorInfo();
75        editorInfo.imeOptions = actionId;
76        // Test text layouts.
77        editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL;
78        final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo);
79        doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, null /* label */, iconId);
80        doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, null /* label */, iconId);
81        doTestActionKey(
82                tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, null /* label */, iconId);
83        // Test phone number layouts.
84        doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, null /* label */, iconId);
85        doTestActionKey(
86                tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, null /* label */, iconId);
87        // Test normal number layout.
88        doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId);
89        // Test number password layout.
90        editorInfo.inputType =
91                InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD;
92        final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo);
93        doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId);
94    }
95
96    public void testActionUnspecified() {
97        for (final InputMethodSubtype subtype : getAllSubtypesList()) {
98            final String tag = "unspecifiled "
99                    + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
100            doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED,
101                    KeyboardIconsSet.NAME_ENTER_KEY);
102        }
103    }
104
105    public void testActionNone() {
106        for (final InputMethodSubtype subtype : getAllSubtypesList()) {
107            final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
108            doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_NONE,
109                    KeyboardIconsSet.NAME_ENTER_KEY);
110        }
111    }
112
113    public void testActionGo() {
114        for (final InputMethodSubtype subtype : getAllSubtypesList()) {
115            final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
116            doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_GO,
117                    KeyboardIconsSet.NAME_GO_KEY);
118        }
119    }
120
121    public void testActionSearch() {
122        for (final InputMethodSubtype subtype : getAllSubtypesList()) {
123            final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
124            doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_SEARCH,
125                    KeyboardIconsSet.NAME_SEARCH_KEY);
126        }
127    }
128
129    public void testActionSend() {
130        for (final InputMethodSubtype subtype : getAllSubtypesList()) {
131            final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
132            doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_SEND,
133                    KeyboardIconsSet.NAME_SEND_KEY);
134        }
135    }
136
137    public void testActionNext() {
138        for (final InputMethodSubtype subtype : getAllSubtypesList()) {
139            final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
140            doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_NEXT,
141                    KeyboardIconsSet.NAME_NEXT_KEY);
142        }
143    }
144
145    public void testActionDone() {
146        for (final InputMethodSubtype subtype : getAllSubtypesList()) {
147            final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
148            doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_DONE,
149                    KeyboardIconsSet.NAME_DONE_KEY);
150        }
151    }
152
153    public void testActionPrevious() {
154        for (final InputMethodSubtype subtype : getAllSubtypesList()) {
155            final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
156            doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS,
157                    KeyboardIconsSet.NAME_PREVIOUS_KEY);
158        }
159    }
160
161    public void testActionCustom() {
162        for (final InputMethodSubtype subtype : getAllSubtypesList()) {
163            final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
164            final CharSequence customLabel = "customLabel";
165            final EditorInfo editorInfo = new EditorInfo();
166            editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED;
167            editorInfo.actionLabel = customLabel;
168            doTestActionKeyLabel(tag, subtype, editorInfo, customLabel);
169        }
170    }
171}
172