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