1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17 package com.android.inputmethod.latin; 18 19 import com.android.inputmethod.keyboard.Keyboard; 20 21 import android.text.style.SuggestionSpan; 22 import android.text.style.UnderlineSpan; 23 24 public class BlueUnderlineTests extends InputTestsBase { 25 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(mTextView.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 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(mTextView.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 assertEquals("extend blue underline, span color", true, 54 spanBefore.isAutoCorrectionIndicator()); 55 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 56 runMessages(); 57 // Now we have been able to re-evaluate the word, there shouldn't be an auto-correction span 58 final SpanGetter spanAfter = new SpanGetter(mTextView.getText(), SuggestionSpan.class); 59 assertNull("hide blue underline", spanAfter.mSpan); 60 } 61 62 public void testBlueUnderlineOnBackspace() { 63 final String STRING_TO_TYPE = "tgis"; 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(Keyboard.CODE_SPACE); 71 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 72 runMessages(); 73 type(Keyboard.CODE_DELETE); 74 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 75 runMessages(); 76 type(Keyboard.CODE_DELETE); 77 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 78 runMessages(); 79 final SpanGetter suggestionSpan = new SpanGetter(mTextView.getText(), SuggestionSpan.class); 80 assertEquals("show no blue underline after backspace, span start should be -1", 81 EXPECTED_SUGGESTION_SPAN_START, suggestionSpan.mStart); 82 final SpanGetter underlineSpan = new SpanGetter(mTextView.getText(), UnderlineSpan.class); 83 assertEquals("should be composing, so should have an underline span", 84 EXPECTED_UNDERLINE_SPAN_START, underlineSpan.mStart); 85 assertEquals("should be composing, so should have an underline span", 86 EXPECTED_UNDERLINE_SPAN_END, underlineSpan.mEnd); 87 } 88 89 public void testBlueUnderlineDisappearsWhenCursorMoved() { 90 final String STRING_TO_TYPE = "tgis"; 91 final int NEW_CURSOR_POSITION = 0; 92 type(STRING_TO_TYPE); 93 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 94 // Simulate the onUpdateSelection() event 95 mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1); 96 runMessages(); 97 // Here the blue underline has been set. testBlueUnderline() is testing for this already, 98 // so let's not test it here again. 99 // Now simulate the user moving the cursor. 100 mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION); 101 mLatinIME.onUpdateSelection(0, 0, NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1); 102 sleep(DELAY_TO_WAIT_FOR_UNDERLINE); 103 runMessages(); 104 final SpanGetter span = new SpanGetter(mTextView.getText(), SuggestionSpan.class); 105 assertNull("blue underline removed when cursor is moved", span.mSpan); 106 } 107 } 108