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.test.suitebuilder.annotation.LargeTest; 20 import android.view.inputmethod.BaseInputConnection; 21 22 import com.android.inputmethod.latin.suggestions.SuggestionStripView; 23 24 @LargeTest 25 public class InputLogicTestsLanguageWithoutSpaces extends InputTestsBase { 26 public void testAutoCorrectForLanguageWithoutSpaces() { 27 final String STRING_TO_TYPE = "tgis is"; 28 final String EXPECTED_RESULT = "thisis"; 29 changeKeyboardLocaleAndDictLocale("th", "en_US"); 30 type(STRING_TO_TYPE); 31 assertEquals("simple auto-correct for language without spaces", EXPECTED_RESULT, 32 mEditText.getText().toString()); 33 } 34 35 public void testRevertAutoCorrectForLanguageWithoutSpaces() { 36 final String STRING_TO_TYPE = "tgis "; 37 final String EXPECTED_INTERMEDIATE_RESULT = "this"; 38 final String EXPECTED_FINAL_RESULT = "tgis"; 39 changeKeyboardLocaleAndDictLocale("th", "en_US"); 40 type(STRING_TO_TYPE); 41 assertEquals("simple auto-correct for language without spaces", 42 EXPECTED_INTERMEDIATE_RESULT, mEditText.getText().toString()); 43 type(Constants.CODE_DELETE); 44 assertEquals("simple auto-correct for language without spaces", 45 EXPECTED_FINAL_RESULT, mEditText.getText().toString()); 46 // Check we are back to composing the word 47 assertEquals("don't resume suggestion on backspace", 0, 48 BaseInputConnection.getComposingSpanStart(mEditText.getText())); 49 assertEquals("don't resume suggestion on backspace", 4, 50 BaseInputConnection.getComposingSpanEnd(mEditText.getText())); 51 } 52 53 public void testDontResumeSuggestionOnBackspace() { 54 final String WORD_TO_TYPE = "and this "; 55 changeKeyboardLocaleAndDictLocale("th", "en_US"); 56 type(WORD_TO_TYPE); 57 assertEquals("don't resume suggestion on backspace", -1, 58 BaseInputConnection.getComposingSpanStart(mEditText.getText())); 59 assertEquals("don't resume suggestion on backspace", -1, 60 BaseInputConnection.getComposingSpanEnd(mEditText.getText())); 61 type(" "); 62 type(Constants.CODE_DELETE); 63 assertEquals("don't resume suggestion on backspace", -1, 64 BaseInputConnection.getComposingSpanStart(mEditText.getText())); 65 assertEquals("don't resume suggestion on backspace", -1, 66 BaseInputConnection.getComposingSpanEnd(mEditText.getText())); 67 } 68 69 public void testStartComposingInsideText() { 70 final String WORD_TO_TYPE = "abcdefgh "; 71 final int typedLength = WORD_TO_TYPE.length() - 1; // -1 because space gets eaten 72 final int CURSOR_POS = 4; 73 changeKeyboardLocaleAndDictLocale("th", "en_US"); 74 type(WORD_TO_TYPE); 75 mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1); 76 mInputConnection.setSelection(CURSOR_POS, CURSOR_POS); 77 mLatinIME.onUpdateSelection(typedLength, typedLength, 78 CURSOR_POS, CURSOR_POS, -1, -1); 79 sleep(DELAY_TO_WAIT_FOR_PREDICTIONS); 80 runMessages(); 81 assertEquals("start composing inside text", -1, 82 BaseInputConnection.getComposingSpanStart(mEditText.getText())); 83 assertEquals("start composing inside text", -1, 84 BaseInputConnection.getComposingSpanEnd(mEditText.getText())); 85 type("xxxx"); 86 assertEquals("start composing inside text", 4, 87 BaseInputConnection.getComposingSpanStart(mEditText.getText())); 88 assertEquals("start composing inside text", 8, 89 BaseInputConnection.getComposingSpanEnd(mEditText.getText())); 90 } 91 92 public void testPredictions() { 93 final String WORD_TO_TYPE = "Barack "; 94 changeKeyboardLocaleAndDictLocale("th", "en_US"); 95 type(WORD_TO_TYPE); 96 sleep(DELAY_TO_WAIT_FOR_PREDICTIONS); 97 runMessages(); 98 // Make sure there is no space 99 assertEquals("predictions in lang without spaces", "Barack", 100 mEditText.getText().toString()); 101 // Test the first prediction is displayed 102 assertEquals("predictions in lang without spaces", "Obama", 103 mLatinIME.getFirstSuggestedWord()); 104 } 105 } 106