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