KeyboardLayoutSetActionLabelKlpTests.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.content.res.Resources; 20import android.test.suitebuilder.annotation.MediumTest; 21import android.view.inputmethod.EditorInfo; 22import android.view.inputmethod.InputMethodSubtype; 23 24import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; 25import com.android.inputmethod.latin.R; 26import com.android.inputmethod.latin.RichInputMethodManager; 27import com.android.inputmethod.latin.utils.RunInLocale; 28import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; 29 30import java.util.Locale; 31 32@MediumTest 33public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActionLabelLxxTests { 34 @Override 35 protected int getKeyboardThemeForTests() { 36 return KeyboardTheme.THEME_ID_KLP; 37 } 38 39 protected void doTestActionKeyLabel(final String tag, final InputMethodSubtype subtype, 40 final int actionId, final int labelResId) { 41 final Locale labelLocale = subtype.getLocale().equals(SubtypeLocaleUtils.NO_LANGUAGE) 42 ? null : SubtypeLocaleUtils.getSubtypeLocale(subtype); 43 doTestActionKeyLabel(tag, subtype, actionId, labelLocale, labelResId); 44 } 45 46 protected void doTestActionKeyLabel(final String tag, final InputMethodSubtype subtype, 47 final int actionId, final Locale labelLocale, final int labelResId) { 48 final EditorInfo editorInfo = new EditorInfo(); 49 editorInfo.imeOptions = actionId; 50 final RunInLocale<String> job = new RunInLocale<String>() { 51 @Override 52 protected String job(final Resources res) { 53 return res.getString(labelResId); 54 } 55 }; 56 final String label = job.runInLocale(getContext().getResources(), labelLocale); 57 doTestActionKeyLabel(tag, subtype, editorInfo, label); 58 } 59 60 @Override 61 public void testActionUnspecified() { 62 super.testActionUnspecified(); 63 } 64 65 @Override 66 public void testActionNone() { 67 super.testActionNone(); 68 } 69 70 @Override 71 public void testActionGo() { 72 for (final InputMethodSubtype subtype : getAllSubtypesList()) { 73 final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); 74 doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_GO, R.string.label_go_key); 75 } 76 } 77 78 @Override 79 public void testActionSearch() { 80 super.testActionSearch(); 81 } 82 83 @Override 84 public void testActionSend() { 85 for (final InputMethodSubtype subtype : getAllSubtypesList()) { 86 final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); 87 doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_SEND, R.string.label_send_key); 88 } 89 } 90 91 @Override 92 public void testActionNext() { 93 for (final InputMethodSubtype subtype : getAllSubtypesList()) { 94 final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); 95 doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_NEXT, R.string.label_next_key); 96 } 97 } 98 99 @Override 100 public void testActionDone() { 101 for (final InputMethodSubtype subtype : getAllSubtypesList()) { 102 final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); 103 doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_DONE, R.string.label_done_key); 104 } 105 } 106 107 @Override 108 public void testActionPrevious() { 109 for (final InputMethodSubtype subtype : getAllSubtypesList()) { 110 final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); 111 doTestActionKeyLabel( 112 tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, R.string.label_previous_key); 113 } 114 } 115 116 @Override 117 public void testActionCustom() { 118 super.testActionCustom(); 119 } 120 121 private void doTestActionLabelInLocale(final InputMethodSubtype subtype, 122 final Locale labelLocale, final Locale systemLocale) { 123 final String tag = "label=" + labelLocale + " system=" + systemLocale 124 + " " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); 125 final RunInLocale<Void> job = new RunInLocale<Void>() { 126 @Override 127 public Void job(final Resources res) { 128 doTestActionKeyIcon(tag + " unspecified", subtype, 129 EditorInfo.IME_ACTION_UNSPECIFIED, KeyboardIconsSet.NAME_ENTER_KEY); 130 doTestActionKeyIcon(tag + " none", subtype, 131 EditorInfo.IME_ACTION_NONE, KeyboardIconsSet.NAME_ENTER_KEY); 132 doTestActionKeyLabel(tag + " go", subtype, 133 EditorInfo.IME_ACTION_GO, labelLocale, R.string.label_go_key); 134 doTestActionKeyIcon(tag + " search", subtype, 135 EditorInfo.IME_ACTION_SEARCH, KeyboardIconsSet.NAME_SEARCH_KEY); 136 doTestActionKeyLabel(tag + " send", subtype, 137 EditorInfo.IME_ACTION_SEND, labelLocale, R.string.label_send_key); 138 doTestActionKeyLabel(tag + " next", subtype, 139 EditorInfo.IME_ACTION_NEXT, labelLocale, R.string.label_next_key); 140 doTestActionKeyLabel(tag + " done", subtype, 141 EditorInfo.IME_ACTION_DONE, labelLocale, R.string.label_done_key); 142 doTestActionKeyLabel(tag + " previous", subtype, 143 EditorInfo.IME_ACTION_PREVIOUS, labelLocale, R.string.label_previous_key); 144 return null; 145 } 146 }; 147 job.runInLocale(getContext().getResources(), systemLocale); 148 } 149 150 public void testActionLabelInOtherLocale() { 151 final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); 152 final InputMethodSubtype italian = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( 153 Locale.ITALIAN.toString(), SubtypeLocaleUtils.QWERTY); 154 // An action label should be displayed in subtype's locale regardless of the system locale. 155 doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.US); 156 doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.FRENCH); 157 doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.ITALIAN); 158 doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.JAPANESE); 159 } 160 161 public void testNoLanguageSubtypeActionLabel() { 162 final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); 163 final InputMethodSubtype noLanguage = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( 164 SubtypeLocaleUtils.NO_LANGUAGE, SubtypeLocaleUtils.QWERTY); 165 // An action label of no language keyboard should be displayed in the system locale. 166 doTestActionLabelInLocale(noLanguage, Locale.US, Locale.US); 167 // TODO: Uncomment the following test once a bug is fixed. 168 // doTestActionLabelInLocale(noLanguage, Locale.FRENCH, Locale.FRENCH); 169 // doTestActionLabelInLocale(noLanguage, Locale.ITALIAN, Locale.ITALIAN); 170 // doTestActionLabelInLocale(noLanguage, Locale.JAPANESE, Locale.JAPANESE); 171 } 172} 173