1 /* 2 * Copyright (C) 2012 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.style.SuggestionSpan; 21 import android.text.style.UnderlineSpan; 22 23 @LargeTest 24 public class BlueUnderlineTests extends InputTestsBase { 25 testBlueUnderline()26 public void testBlueUnderline() { 27 final String STRING_TO_TYPE = "tgis"; 28 final int EXPECTED_SPAN_START = 0; 29 final int EXPECTED_SPAN_END = 4; 30 type(STRING_TO_TYPE); 31 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 32 runMessages(); 33 final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class); 34 assertEquals("show blue underline, span start", EXPECTED_SPAN_START, span.mStart); 35 assertEquals("show blue underline, span end", EXPECTED_SPAN_END, span.mEnd); 36 assertEquals("show blue underline, span color", true, span.isAutoCorrectionIndicator()); 37 } 38 testBlueUnderlineDisappears()39 public void testBlueUnderlineDisappears() { 40 final String STRING_1_TO_TYPE = "tgis"; 41 final String STRING_2_TO_TYPE = "q"; 42 final int EXPECTED_SPAN_START = 0; 43 final int EXPECTED_SPAN_END = 5; 44 type(STRING_1_TO_TYPE); 45 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 46 runMessages(); 47 type(STRING_2_TO_TYPE); 48 // We haven't have time to look into the dictionary yet, so the line should still be 49 // blue to avoid any flicker. 50 final SpanGetter spanBefore = new SpanGetter(mEditText.getText(), SuggestionSpan.class); 51 assertEquals("extend blue underline, span start", EXPECTED_SPAN_START, spanBefore.mStart); 52 assertEquals("extend blue underline, span end", EXPECTED_SPAN_END, spanBefore.mEnd); 53 assertTrue("extend blue underline, span color", spanBefore.isAutoCorrectionIndicator()); 54 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 55 runMessages(); 56 // Now we have been able to re-evaluate the word, there shouldn't be an auto-correction span 57 final SpanGetter spanAfter = new SpanGetter(mEditText.getText(), SuggestionSpan.class); 58 assertNull("hide blue underline", spanAfter.mSpan); 59 } 60 testBlueUnderlineOnBackspace()61 public void testBlueUnderlineOnBackspace() { 62 final String STRING_TO_TYPE = "tgis"; 63 final int typedLength = STRING_TO_TYPE.length(); 64 final int EXPECTED_SUGGESTION_SPAN_START = -1; 65 final int EXPECTED_UNDERLINE_SPAN_START = 0; 66 final int EXPECTED_UNDERLINE_SPAN_END = 4; 67 type(STRING_TO_TYPE); 68 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 69 runMessages(); 70 type(Constants.CODE_SPACE); 71 // typedLength + 1 because we also typed a space 72 mLatinIME.onUpdateSelection(0, 0, typedLength + 1, typedLength + 1, -1, -1); 73 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 74 runMessages(); 75 type(Constants.CODE_DELETE); 76 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 77 runMessages(); 78 type(Constants.CODE_DELETE); 79 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 80 runMessages(); 81 final SpanGetter suggestionSpan = new SpanGetter(mEditText.getText(), SuggestionSpan.class); 82 assertFalse("show no blue underline after backspace, span should not be the auto-" 83 + "correction indicator", suggestionSpan.isAutoCorrectionIndicator()); 84 final SpanGetter underlineSpan = new SpanGetter(mEditText.getText(), UnderlineSpan.class); 85 assertEquals("should be composing, so should have an underline span", 86 EXPECTED_UNDERLINE_SPAN_START, underlineSpan.mStart); 87 assertEquals("should be composing, so should have an underline span", 88 EXPECTED_UNDERLINE_SPAN_END, underlineSpan.mEnd); 89 } 90 testBlueUnderlineDisappearsWhenCursorMoved()91 public void testBlueUnderlineDisappearsWhenCursorMoved() { 92 final String STRING_TO_TYPE = "tgis"; 93 final int typedLength = STRING_TO_TYPE.length(); 94 final int NEW_CURSOR_POSITION = 0; 95 type(STRING_TO_TYPE); 96 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 97 // Simulate the onUpdateSelection() event 98 mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1); 99 runMessages(); 100 // Here the blue underline has been set. testBlueUnderline() is testing for this already, 101 // so let's not test it here again. 102 // Now simulate the user moving the cursor. 103 mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION); 104 mLatinIME.onUpdateSelection(typedLength, typedLength, 105 NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1); 106 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 107 runMessages(); 108 final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class); 109 assertFalse("blue underline removed when cursor is moved", 110 span.isAutoCorrectionIndicator()); 111 } 112 testComposingStopsOnSpace()113 public void testComposingStopsOnSpace() { 114 final String STRING_TO_TYPE = "this "; 115 type(STRING_TO_TYPE); 116 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 117 // Simulate the onUpdateSelection() event 118 mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1); 119 runMessages(); 120 // Here the blue underline has been set. testBlueUnderline() is testing for this already, 121 // so let's not test it here again. 122 // Now simulate the user moving the cursor. 123 SpanGetter span = new SpanGetter(mEditText.getText(), UnderlineSpan.class); 124 assertNull("should not be composing, so should not have an underline span", span.mSpan); 125 } 126 } 127