Home | History | Annotate | Download | only in keyboard
      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 
     17 package com.android.inputmethod.keyboard;
     18 
     19 import android.content.res.Resources;
     20 import android.test.suitebuilder.annotation.MediumTest;
     21 import android.view.inputmethod.EditorInfo;
     22 import android.view.inputmethod.InputMethodSubtype;
     23 
     24 import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
     25 import com.android.inputmethod.latin.R;
     26 import com.android.inputmethod.latin.RichInputMethodManager;
     27 import com.android.inputmethod.latin.utils.RunInLocale;
     28 import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
     29 
     30 import java.util.Locale;
     31 
     32 @MediumTest
     33 public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActionLabelBase {
     34     @Override
     35     protected int getKeyboardThemeForTests() {
     36         return KeyboardTheme.THEME_ID_KLP;
     37     }
     38 
     39     @Override
     40     public void testActionGo() {
     41         for (final InputMethodSubtype subtype : getAllSubtypesList()) {
     42             final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
     43             doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_GO,
     44                     R.string.label_go_key);
     45         }
     46     }
     47 
     48     @Override
     49     public void testActionSend() {
     50         for (final InputMethodSubtype subtype : getAllSubtypesList()) {
     51             final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
     52             doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_SEND,
     53                     R.string.label_send_key);
     54         }
     55     }
     56 
     57     @Override
     58     public void testActionNext() {
     59         for (final InputMethodSubtype subtype : getAllSubtypesList()) {
     60             final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
     61             doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_NEXT,
     62                     R.string.label_next_key);
     63         }
     64     }
     65 
     66     @Override
     67     public void testActionDone() {
     68         for (final InputMethodSubtype subtype : getAllSubtypesList()) {
     69             final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
     70             doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_DONE,
     71                     R.string.label_done_key);
     72         }
     73     }
     74 
     75     @Override
     76     public void testActionPrevious() {
     77         for (final InputMethodSubtype subtype : getAllSubtypesList()) {
     78             final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
     79             doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS,
     80                     R.string.label_previous_key);
     81         }
     82     }
     83 
     84     // Working variable to simulate system locale changing.
     85     private Locale mSystemLocale = Locale.getDefault();
     86 
     87     private void doTestActionLabelInLocale(final InputMethodSubtype subtype,
     88             final Locale labelLocale, final Locale systemLocale) {
     89         // Simulate system locale changing, see {@link SystemBroadcastReceiver}.
     90         if (!systemLocale.equals(mSystemLocale)) {
     91             KeyboardLayoutSet.onSystemLocaleChanged();
     92             mSystemLocale = systemLocale;
     93         }
     94         final String tag = "label=" + labelLocale + " system=" + systemLocale
     95                 + " " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
     96         final RunInLocale<Void> job = new RunInLocale<Void>() {
     97             @Override
     98             public Void job(final Resources res) {
     99                 doTestActionKeyIcon(tag + " unspecified", subtype,
    100                         EditorInfo.IME_ACTION_UNSPECIFIED, KeyboardIconsSet.NAME_ENTER_KEY);
    101                 doTestActionKeyIcon(tag + " none", subtype,
    102                         EditorInfo.IME_ACTION_NONE, KeyboardIconsSet.NAME_ENTER_KEY);
    103                 doTestActionKeyLabelResIdInLocale(tag + " go", subtype,
    104                         EditorInfo.IME_ACTION_GO, labelLocale, R.string.label_go_key);
    105                 doTestActionKeyIcon(tag + " search", subtype,
    106                         EditorInfo.IME_ACTION_SEARCH, KeyboardIconsSet.NAME_SEARCH_KEY);
    107                 doTestActionKeyLabelResIdInLocale(tag + " send", subtype,
    108                         EditorInfo.IME_ACTION_SEND, labelLocale, R.string.label_send_key);
    109                 doTestActionKeyLabelResIdInLocale(tag + " next", subtype,
    110                         EditorInfo.IME_ACTION_NEXT, labelLocale, R.string.label_next_key);
    111                 doTestActionKeyLabelResIdInLocale(tag + " done", subtype,
    112                         EditorInfo.IME_ACTION_DONE, labelLocale, R.string.label_done_key);
    113                 doTestActionKeyLabelResIdInLocale(tag + " previous", subtype,
    114                         EditorInfo.IME_ACTION_PREVIOUS, labelLocale, R.string.label_previous_key);
    115                 return null;
    116             }
    117         };
    118         job.runInLocale(getContext().getResources(), systemLocale);
    119     }
    120 
    121     public void testActionLabelInOtherLocale() {
    122         final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
    123         final InputMethodSubtype italian = richImm.findSubtypeByLocaleAndKeyboardLayoutSet(
    124                 Locale.ITALIAN.toString(), SubtypeLocaleUtils.QWERTY);
    125         // An action label should be displayed in subtype's locale regardless of the system locale.
    126         doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.US);
    127         doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.FRENCH);
    128         doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.ITALIAN);
    129         doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.JAPANESE);
    130     }
    131 
    132     public void testNoLanguageSubtypeActionLabel() {
    133         final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
    134         final InputMethodSubtype noLanguage = richImm.findSubtypeByLocaleAndKeyboardLayoutSet(
    135                 SubtypeLocaleUtils.NO_LANGUAGE, SubtypeLocaleUtils.QWERTY);
    136         // An action label of no language keyboard should be displayed in the system locale.
    137         doTestActionLabelInLocale(noLanguage, Locale.US, Locale.US);
    138         doTestActionLabelInLocale(noLanguage, Locale.FRENCH, Locale.FRENCH);
    139         doTestActionLabelInLocale(noLanguage, Locale.ITALIAN, Locale.ITALIAN);
    140         doTestActionLabelInLocale(noLanguage, Locale.JAPANESE, Locale.JAPANESE);
    141     }
    142 }
    143