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