2012-03-23 05:22:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
2013-02-12 07:15:47 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2012-03-23 05:22:47 +00:00
|
|
|
*
|
2013-02-12 07:15:47 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-03-23 05:22:47 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-02-12 07:15:47 +00:00
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2012-03-23 05:22:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
2013-02-04 23:25:24 +00:00
|
|
|
import android.test.suitebuilder.annotation.LargeTest;
|
2012-05-18 10:10:48 +00:00
|
|
|
import android.text.style.SuggestionSpan;
|
|
|
|
import android.text.style.UnderlineSpan;
|
|
|
|
|
2013-02-04 23:25:24 +00:00
|
|
|
@LargeTest
|
2012-03-23 05:22:47 +00:00
|
|
|
public class BlueUnderlineTests extends InputTestsBase {
|
|
|
|
|
|
|
|
public void testBlueUnderline() {
|
|
|
|
final String STRING_TO_TYPE = "tgis";
|
|
|
|
final int EXPECTED_SPAN_START = 0;
|
|
|
|
final int EXPECTED_SPAN_END = 4;
|
|
|
|
type(STRING_TO_TYPE);
|
|
|
|
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
|
|
|
|
runMessages();
|
2013-05-01 04:33:39 +00:00
|
|
|
final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class);
|
2012-03-23 05:22:47 +00:00
|
|
|
assertEquals("show blue underline, span start", EXPECTED_SPAN_START, span.mStart);
|
|
|
|
assertEquals("show blue underline, span end", EXPECTED_SPAN_END, span.mEnd);
|
|
|
|
assertEquals("show blue underline, span color", true, span.isAutoCorrectionIndicator());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testBlueUnderlineDisappears() {
|
|
|
|
final String STRING_1_TO_TYPE = "tgis";
|
|
|
|
final String STRING_2_TO_TYPE = "q";
|
|
|
|
final int EXPECTED_SPAN_START = 0;
|
|
|
|
final int EXPECTED_SPAN_END = 5;
|
|
|
|
type(STRING_1_TO_TYPE);
|
|
|
|
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
|
|
|
|
runMessages();
|
|
|
|
type(STRING_2_TO_TYPE);
|
|
|
|
// We haven't have time to look into the dictionary yet, so the line should still be
|
|
|
|
// blue to avoid any flicker.
|
2013-05-01 04:33:39 +00:00
|
|
|
final SpanGetter spanBefore = new SpanGetter(mEditText.getText(), SuggestionSpan.class);
|
2012-03-23 05:22:47 +00:00
|
|
|
assertEquals("extend blue underline, span start", EXPECTED_SPAN_START, spanBefore.mStart);
|
|
|
|
assertEquals("extend blue underline, span end", EXPECTED_SPAN_END, spanBefore.mEnd);
|
|
|
|
assertEquals("extend blue underline, span color", true,
|
|
|
|
spanBefore.isAutoCorrectionIndicator());
|
|
|
|
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
|
|
|
|
runMessages();
|
|
|
|
// Now we have been able to re-evaluate the word, there shouldn't be an auto-correction span
|
2013-05-01 04:33:39 +00:00
|
|
|
final SpanGetter spanAfter = new SpanGetter(mEditText.getText(), SuggestionSpan.class);
|
2012-03-23 05:22:47 +00:00
|
|
|
assertNull("hide blue underline", spanAfter.mSpan);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testBlueUnderlineOnBackspace() {
|
|
|
|
final String STRING_TO_TYPE = "tgis";
|
2012-05-18 10:10:48 +00:00
|
|
|
final int EXPECTED_SUGGESTION_SPAN_START = -1;
|
|
|
|
final int EXPECTED_UNDERLINE_SPAN_START = 0;
|
|
|
|
final int EXPECTED_UNDERLINE_SPAN_END = 4;
|
2012-03-23 05:22:47 +00:00
|
|
|
type(STRING_TO_TYPE);
|
|
|
|
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
|
|
|
|
runMessages();
|
2012-10-29 05:46:34 +00:00
|
|
|
type(Constants.CODE_SPACE);
|
2012-03-23 05:22:47 +00:00
|
|
|
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
|
|
|
|
runMessages();
|
2012-10-29 05:46:34 +00:00
|
|
|
type(Constants.CODE_DELETE);
|
2012-03-23 05:22:47 +00:00
|
|
|
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
|
|
|
|
runMessages();
|
2012-10-29 05:46:34 +00:00
|
|
|
type(Constants.CODE_DELETE);
|
2012-03-23 05:22:47 +00:00
|
|
|
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
|
|
|
|
runMessages();
|
2013-05-01 04:33:39 +00:00
|
|
|
final SpanGetter suggestionSpan = new SpanGetter(mEditText.getText(), SuggestionSpan.class);
|
2012-05-18 10:10:48 +00:00
|
|
|
assertEquals("show no blue underline after backspace, span start should be -1",
|
|
|
|
EXPECTED_SUGGESTION_SPAN_START, suggestionSpan.mStart);
|
2013-05-01 04:33:39 +00:00
|
|
|
final SpanGetter underlineSpan = new SpanGetter(mEditText.getText(), UnderlineSpan.class);
|
2012-05-18 10:10:48 +00:00
|
|
|
assertEquals("should be composing, so should have an underline span",
|
|
|
|
EXPECTED_UNDERLINE_SPAN_START, underlineSpan.mStart);
|
|
|
|
assertEquals("should be composing, so should have an underline span",
|
|
|
|
EXPECTED_UNDERLINE_SPAN_END, underlineSpan.mEnd);
|
2012-03-23 05:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testBlueUnderlineDisappearsWhenCursorMoved() {
|
|
|
|
final String STRING_TO_TYPE = "tgis";
|
2012-10-10 09:57:47 +00:00
|
|
|
final int typedLength = STRING_TO_TYPE.length();
|
2012-03-23 05:22:47 +00:00
|
|
|
final int NEW_CURSOR_POSITION = 0;
|
|
|
|
type(STRING_TO_TYPE);
|
|
|
|
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
|
|
|
|
// Simulate the onUpdateSelection() event
|
2012-10-10 09:57:47 +00:00
|
|
|
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
|
2012-03-23 05:22:47 +00:00
|
|
|
runMessages();
|
|
|
|
// Here the blue underline has been set. testBlueUnderline() is testing for this already,
|
|
|
|
// so let's not test it here again.
|
|
|
|
// Now simulate the user moving the cursor.
|
|
|
|
mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION);
|
2012-10-10 09:57:47 +00:00
|
|
|
mLatinIME.onUpdateSelection(typedLength, typedLength,
|
|
|
|
NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
|
2012-03-23 05:22:47 +00:00
|
|
|
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
|
|
|
|
runMessages();
|
2013-05-01 04:33:39 +00:00
|
|
|
final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class);
|
2012-03-23 05:22:47 +00:00
|
|
|
assertNull("blue underline removed when cursor is moved", span.mSpan);
|
|
|
|
}
|
2012-11-19 08:02:47 +00:00
|
|
|
|
|
|
|
public void testComposingStopsOnSpace() {
|
|
|
|
final String STRING_TO_TYPE = "this ";
|
|
|
|
type(STRING_TO_TYPE);
|
|
|
|
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
|
|
|
|
// Simulate the onUpdateSelection() event
|
|
|
|
mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
|
|
|
|
runMessages();
|
|
|
|
// Here the blue underline has been set. testBlueUnderline() is testing for this already,
|
|
|
|
// so let's not test it here again.
|
|
|
|
// Now simulate the user moving the cursor.
|
2013-05-01 04:33:39 +00:00
|
|
|
SpanGetter span = new SpanGetter(mEditText.getText(), UnderlineSpan.class);
|
2012-11-19 08:02:47 +00:00
|
|
|
assertNull("should not be composing, so should not have an underline span", span.mSpan);
|
|
|
|
}
|
2012-03-23 05:22:47 +00:00
|
|
|
}
|