• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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.view.inputmethod.BaseInputConnection;
20 
21 import androidx.test.filters.LargeTest;
22 
23 import com.android.inputmethod.latin.common.Constants;
24 
25 @LargeTest
26 public class InputLogicTestsLanguageWithoutSpaces extends InputTestsBase {
testAutoCorrectForLanguageWithoutSpaces()27     public void testAutoCorrectForLanguageWithoutSpaces() {
28         final String STRING_TO_TYPE = "tgis is";
29         final String EXPECTED_RESULT = "thisis";
30         changeKeyboardLocaleAndDictLocale("th", "en_US");
31         type(STRING_TO_TYPE);
32         assertEquals("simple auto-correct for language without spaces", EXPECTED_RESULT,
33                 mEditText.getText().toString());
34     }
35 
testRevertAutoCorrectForLanguageWithoutSpaces()36     public void testRevertAutoCorrectForLanguageWithoutSpaces() {
37         final String STRING_TO_TYPE = "tgis ";
38         final String EXPECTED_INTERMEDIATE_RESULT = "this";
39         final String EXPECTED_FINAL_RESULT = "tgis";
40         changeKeyboardLocaleAndDictLocale("th", "en_US");
41         type(STRING_TO_TYPE);
42         assertEquals("simple auto-correct for language without spaces",
43                 EXPECTED_INTERMEDIATE_RESULT, mEditText.getText().toString());
44         type(Constants.CODE_DELETE);
45         assertEquals("simple auto-correct for language without spaces",
46                 EXPECTED_FINAL_RESULT, mEditText.getText().toString());
47         // Check we are back to composing the word
48         assertEquals("don't resume suggestion on backspace", 0,
49                 BaseInputConnection.getComposingSpanStart(mEditText.getText()));
50         assertEquals("don't resume suggestion on backspace", 4,
51                 BaseInputConnection.getComposingSpanEnd(mEditText.getText()));
52     }
53 
testDontResumeSuggestionOnBackspace()54     public void testDontResumeSuggestionOnBackspace() {
55         final String WORD_TO_TYPE = "and this ";
56         changeKeyboardLocaleAndDictLocale("th", "en_US");
57         type(WORD_TO_TYPE);
58         assertEquals("don't resume suggestion on backspace", -1,
59                 BaseInputConnection.getComposingSpanStart(mEditText.getText()));
60         assertEquals("don't resume suggestion on backspace", -1,
61                 BaseInputConnection.getComposingSpanEnd(mEditText.getText()));
62         type(" ");
63         type(Constants.CODE_DELETE);
64         assertEquals("don't resume suggestion on backspace", -1,
65                 BaseInputConnection.getComposingSpanStart(mEditText.getText()));
66         assertEquals("don't resume suggestion on backspace", -1,
67                 BaseInputConnection.getComposingSpanEnd(mEditText.getText()));
68     }
69 
testStartComposingInsideText()70     public void testStartComposingInsideText() {
71         final String WORD_TO_TYPE = "abcdefgh ";
72         final int typedLength = WORD_TO_TYPE.length() - 1; // -1 because space gets eaten
73         final int CURSOR_POS = 4;
74         changeKeyboardLocaleAndDictLocale("th", "en_US");
75         type(WORD_TO_TYPE);
76         mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
77         mInputConnection.setSelection(CURSOR_POS, CURSOR_POS);
78         mLatinIME.onUpdateSelection(typedLength, typedLength,
79                 CURSOR_POS, CURSOR_POS, -1, -1);
80         sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
81         runMessages();
82         assertEquals("start composing inside text", -1,
83                 BaseInputConnection.getComposingSpanStart(mEditText.getText()));
84         assertEquals("start composing inside text", -1,
85                 BaseInputConnection.getComposingSpanEnd(mEditText.getText()));
86         type("xxxx");
87         assertEquals("start composing inside text", 4,
88                 BaseInputConnection.getComposingSpanStart(mEditText.getText()));
89         assertEquals("start composing inside text", 8,
90                 BaseInputConnection.getComposingSpanEnd(mEditText.getText()));
91     }
92 
testMovingCursorInsideWordAndType()93     public void testMovingCursorInsideWordAndType() {
94         final String WORD_TO_TYPE = "abcdefgh";
95         final int typedLength = WORD_TO_TYPE.length();
96         final int CURSOR_POS = 4;
97         changeKeyboardLocaleAndDictLocale("th", "en_US");
98         type(WORD_TO_TYPE);
99         mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, 0, typedLength);
100         sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
101         runMessages();
102         mInputConnection.setSelection(CURSOR_POS, CURSOR_POS);
103         mLatinIME.onUpdateSelection(typedLength, typedLength,
104                 CURSOR_POS, CURSOR_POS, 0, typedLength);
105         sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
106         runMessages();
107         assertEquals("move cursor inside text", 0,
108                 BaseInputConnection.getComposingSpanStart(mEditText.getText()));
109         assertEquals("move cursor inside text", typedLength,
110                 BaseInputConnection.getComposingSpanEnd(mEditText.getText()));
111         type("x");
112         sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
113         sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
114         runMessages();
115         assertEquals("start typing while cursor inside composition", CURSOR_POS,
116                 BaseInputConnection.getComposingSpanStart(mEditText.getText()));
117         assertEquals("start typing while cursor inside composition", CURSOR_POS + 1,
118                 BaseInputConnection.getComposingSpanEnd(mEditText.getText()));
119     }
120 
testPredictions()121     public void testPredictions() {
122         final String WORD_TO_TYPE = "Barack ";
123         changeKeyboardLocaleAndDictLocale("th", "en_US");
124         type(WORD_TO_TYPE);
125         sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
126         runMessages();
127         // Make sure there is no space
128         assertEquals("predictions in lang without spaces", "Barack",
129                 mEditText.getText().toString());
130         // Test the first prediction is displayed
131         final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
132         assertEquals("predictions in lang without spaces", "Obama",
133                 suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
134     }
135 }
136