Skip to content
Snippets Groups Projects
Commit 2752287c authored by Jean Chalard's avatar Jean Chalard
Browse files

Fix failing tests.

Most of the failures can be ascribed to the tests not passing the correct
old position of the cursor on a second call to onUpdateSelection() to
LatinIME.

Bug: 7276565
Bug: 7276805
Bug: 7276195
Change-Id: I3f1b52cdcc783ea18838408bed50699b7254eaf4
parent 3873d361
No related branches found
No related tags found
No related merge requests found
......@@ -88,17 +88,19 @@ public class BlueUnderlineTests extends InputTestsBase {
public void testBlueUnderlineDisappearsWhenCursorMoved() {
final String STRING_TO_TYPE = "tgis";
final int typedLength = STRING_TO_TYPE.length();
final int NEW_CURSOR_POSITION = 0;
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);
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -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.
mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION);
mLatinIME.onUpdateSelection(0, 0, NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
mLatinIME.onUpdateSelection(typedLength, typedLength,
NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
final SpanGetter span = new SpanGetter(mTextView.getText(), SuggestionSpan.class);
......
......@@ -86,6 +86,7 @@ public class InputLogicTests extends InputTestsBase {
public void testDeleteSelection() {
final String STRING_TO_TYPE = "some text delete me some text";
final int typedLength = STRING_TO_TYPE.length();
final int SELECTION_START = 10;
final int SELECTION_END = 19;
final String EXPECTED_RESULT = "some text some text";
......@@ -94,10 +95,11 @@ public class InputLogicTests extends InputTestsBase {
// Send once to simulate the cursor actually responding to the move caused by typing.
// This is necessary because LatinIME is bookkeeping to avoid confusing a real cursor
// move with a move triggered by LatinIME inputting stuff.
mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
mInputConnection.setSelection(SELECTION_START, SELECTION_END);
// And now we simulate the user actually selecting some text.
mLatinIME.onUpdateSelection(0, 0, SELECTION_START, SELECTION_END, -1, -1);
mLatinIME.onUpdateSelection(typedLength, typedLength,
SELECTION_START, SELECTION_END, -1, -1);
type(Keyboard.CODE_DELETE);
assertEquals("delete selection", EXPECTED_RESULT, mTextView.getText().toString());
}
......@@ -163,12 +165,14 @@ public class InputLogicTests extends InputTestsBase {
public void testBackspaceAtStartAfterAutocorrect() {
final String STRING_TO_TYPE = "tgis ";
final int typedLength = STRING_TO_TYPE.length();
final String EXPECTED_RESULT = "this ";
final int NEW_CURSOR_POSITION = 0;
type(STRING_TO_TYPE);
mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION);
mLatinIME.onUpdateSelection(0, 0, NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
mLatinIME.onUpdateSelection(typedLength, typedLength,
NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
type(Keyboard.CODE_DELETE);
assertEquals("auto correct then move cursor to start of line then backspace",
EXPECTED_RESULT, mTextView.getText().toString());
......@@ -176,12 +180,14 @@ public class InputLogicTests extends InputTestsBase {
public void testAutoCorrectThenMoveCursorThenBackspace() {
final String STRING_TO_TYPE = "and tgis ";
final int typedLength = STRING_TO_TYPE.length();
final String EXPECTED_RESULT = "andthis ";
final int NEW_CURSOR_POSITION = STRING_TO_TYPE.indexOf('t');
type(STRING_TO_TYPE);
mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION);
mLatinIME.onUpdateSelection(0, 0, NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
mLatinIME.onUpdateSelection(typedLength, typedLength,
NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
type(Keyboard.CODE_DELETE);
assertEquals("auto correct then move cursor then backspace",
EXPECTED_RESULT, mTextView.getText().toString());
......
......@@ -16,7 +16,10 @@
package com.android.inputmethod.latin;
import com.android.inputmethod.latin.suggestions.SuggestionStripView;
public class InputLogicTestsNonEnglish extends InputTestsBase {
final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction";
public void testAutoCorrectForFrench() {
final String STRING_TO_TYPE = "irq ";
......@@ -43,16 +46,40 @@ public class InputLogicTestsNonEnglish extends InputTestsBase {
final String WORD_TO_TYPE = "test ";
final String PUNCTUATION_FROM_STRIP = "!";
final String EXPECTED_RESULT = "test !!";
final boolean defaultNextWordPredictionOption =
mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction);
final boolean previousNextWordPredictionOption =
setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, false,
defaultNextWordPredictionOption);
try {
changeLanguage("fr");
type(WORD_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
assertTrue("type word then type space should display punctuation strip",
mLatinIME.isShowingPunctuationList());
pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
assertEquals("type word then type space then punctuation from strip twice for French",
EXPECTED_RESULT, mTextView.getText().toString());
} finally {
setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption,
defaultNextWordPredictionOption);
}
}
public void testWordThenSpaceDisplaysPredictions() {
final String WORD_TO_TYPE = "beaujolais ";
final String EXPECTED_RESULT = "nouveau";
changeLanguage("fr");
type(WORD_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
assertTrue("type word then type space should display punctuation strip",
mLatinIME.isShowingPunctuationList());
pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
assertEquals("type word then type space then punctuation from strip twice for French",
EXPECTED_RESULT, mTextView.getText().toString());
final SuggestionStripView suggestionStripView =
(SuggestionStripView)mInputView.findViewById(R.id.suggestion_strip_view);
final SuggestedWords suggestedWords = suggestionStripView.getSuggestions();
assertEquals("type word then type space yields predictions for French",
EXPECTED_RESULT, suggestedWords.getWord(0));
}
public void testAutoCorrectForGerman() {
......
......@@ -53,6 +53,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
protected LatinIME mLatinIME;
protected Keyboard mKeyboard;
protected MyTextView mTextView;
protected View mInputView;
protected InputConnection mInputConnection;
private final HashMap<String, InputMethodSubtype> mSubtypeMap =
new HashMap<String, InputMethodSubtype>();
......@@ -150,9 +151,9 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
final LayoutInflater inflater =
(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final ViewGroup vg = new FrameLayout(getContext());
final View inputView = inflater.inflate(R.layout.input_view, vg);
mInputView = inflater.inflate(R.layout.input_view, vg);
mLatinIME.onCreateInputMethodInterface().startInput(ic, ei);
mLatinIME.setInputView(inputView);
mLatinIME.setInputView(mInputView);
mLatinIME.onBindInput();
mLatinIME.onCreateInputView();
mLatinIME.onStartInputView(ei, false);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment