Home | History | Annotate | Download | only in latin
      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.latin;
     18 
     19 import android.os.Build;
     20 import android.test.suitebuilder.annotation.LargeTest;
     21 import android.text.TextUtils;
     22 import android.view.inputmethod.EditorInfo;
     23 
     24 import com.android.inputmethod.latin.Constants;
     25 import com.android.inputmethod.latin.WordComposer;
     26 
     27 @LargeTest
     28 public class ShiftModeTests extends InputTestsBase {
     29 
     30     @Override
     31     protected EditorInfo enrichEditorInfo(final EditorInfo ei) {
     32         ei.inputType |= TextUtils.CAP_MODE_SENTENCES;
     33         ei.initialCapsMode = TextUtils.CAP_MODE_SENTENCES;
     34         return ei;
     35     }
     36 
     37     private boolean isCapsModeAutoShifted() {
     38         return mLatinIME.mKeyboardSwitcher.getKeyboardShiftMode()
     39                 == WordComposer.CAPS_MODE_AUTO_SHIFTED;
     40     }
     41 
     42     public void testTypicalSentence() {
     43         assertTrue("Initial auto caps state", isCapsModeAutoShifted());
     44         type("Test");
     45         assertFalse("Caps after letter", isCapsModeAutoShifted());
     46         type(" ");
     47         assertFalse("Caps after space", isCapsModeAutoShifted());
     48         type("some,");
     49         assertFalse("Caps after comma", isCapsModeAutoShifted());
     50         type(" ");
     51         assertFalse("Caps after comma space", isCapsModeAutoShifted());
     52         type("words.");
     53         assertFalse("Caps directly after period", isCapsModeAutoShifted());
     54         type(" ");
     55         assertTrue("Caps after period space", isCapsModeAutoShifted());
     56     }
     57 
     58     public void testBackspace() {
     59         assertTrue("Initial auto caps state", isCapsModeAutoShifted());
     60         type("A");
     61         assertFalse("Caps state after one letter", isCapsModeAutoShifted());
     62         type(Constants.CODE_DELETE);
     63         assertTrue("Auto caps state at start after delete", isCapsModeAutoShifted());
     64     }
     65 
     66     public void testRepeatingBackspace() {
     67         final String SENTENCE_TO_TYPE = "Test sentence. Another.";
     68         final int BACKSPACE_COUNT =
     69                 SENTENCE_TO_TYPE.length() - SENTENCE_TO_TYPE.lastIndexOf(' ') - 1;
     70 
     71         type(SENTENCE_TO_TYPE);
     72         assertFalse("Caps after typing \"" + SENTENCE_TO_TYPE + "\"", isCapsModeAutoShifted());
     73         type(Constants.CODE_DELETE);
     74         for (int i = 1; i < BACKSPACE_COUNT; ++i) {
     75             repeatKey(Constants.CODE_DELETE);
     76         }
     77         assertFalse("Caps immediately after repeating Backspace a lot", isCapsModeAutoShifted());
     78         sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
     79         runMessages();
     80         assertTrue("Caps after a while after repeating Backspace a lot", isCapsModeAutoShifted());
     81     }
     82 
     83     public void testAutoCapsAfterDigitsPeriod() {
     84         changeLanguage("en");
     85         type("On 22.11.");
     86         assertFalse("(English) Auto caps after digits-period", isCapsModeAutoShifted());
     87         type(" ");
     88         assertTrue("(English) Auto caps after digits-period-whitespace", isCapsModeAutoShifted());
     89         mEditText.setText("");
     90         changeLanguage("fr");
     91         type("Le 22.");
     92         assertFalse("(French) Auto caps after digits-period", isCapsModeAutoShifted());
     93         type(" ");
     94         assertTrue("(French) Auto caps after digits-period-whitespace", isCapsModeAutoShifted());
     95         mEditText.setText("");
     96         changeLanguage("de");
     97         type("Am 22.");
     98         assertFalse("(German) Auto caps after digits-period", isCapsModeAutoShifted());
     99         type(" ");
    100         // For German, no auto-caps in this case
    101         assertFalse("(German) Auto caps after digits-period-whitespace", isCapsModeAutoShifted());
    102     }
    103 
    104     public void testAutoCapsAfterInvertedMarks() {
    105         changeLanguage("es");
    106         assertTrue("(Spanish) Auto caps at start", isCapsModeAutoShifted());
    107         type("Hey. ");
    108         assertTrue("(Spanish) Auto caps after inverted what", isCapsModeAutoShifted());
    109         mEditText.setText("");
    110         type("");
    111         assertTrue("(Spanish) Auto caps after inverted bang", isCapsModeAutoShifted());
    112     }
    113 
    114     public void testOtherSentenceSeparators() {
    115         changeLanguage("hy_AM");
    116         assertTrue("(Armenian) Auto caps at start", isCapsModeAutoShifted());
    117         type("Hey. ");
    118         assertFalse("(Armenian) No auto-caps after latin period", isCapsModeAutoShifted());
    119         type("Hey\u0589");
    120         assertFalse("(Armenian) No auto-caps directly after armenian period",
    121                 isCapsModeAutoShifted());
    122         type(" ");
    123         assertTrue("(Armenian) Auto-caps after armenian period-whitespace",
    124                 isCapsModeAutoShifted());
    125     }
    126 }
    127