aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/inputmethod/latin/InputLogicTests.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/InputLogicTests.java')
-rw-r--r--tests/src/com/android/inputmethod/latin/InputLogicTests.java178
1 files changed, 139 insertions, 39 deletions
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
index 59b858dbd..c76f6f446 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
@@ -16,10 +16,12 @@
package com.android.inputmethod.latin;
+import android.test.MoreAsserts;
import android.test.suitebuilder.annotation.LargeTest;
import android.text.TextUtils;
import android.view.inputmethod.BaseInputConnection;
+import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.settings.Settings;
@LargeTest
@@ -36,7 +38,7 @@ public class InputLogicTests extends InputTestsBase {
final String EXPECTED_RESULT = "thi";
type(WORD_TO_TYPE);
pickSuggestionManually(WORD_TO_TYPE);
- mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
+ sendUpdateForCursorMoveTo(WORD_TO_TYPE.length());
type(Constants.CODE_DELETE);
assertEquals("press suggestion then backspace", EXPECTED_RESULT,
mEditText.getText().toString());
@@ -49,7 +51,7 @@ public class InputLogicTests extends InputTestsBase {
type(WORD_TO_TYPE);
// Choose the auto-correction. For "tgis", the auto-correction should be "this".
pickSuggestionManually(WORD_TO_PICK);
- mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
+ sendUpdateForCursorMoveTo(WORD_TO_TYPE.length());
assertEquals("pick typed word over auto-correction then backspace", WORD_TO_PICK,
mEditText.getText().toString());
type(Constants.CODE_DELETE);
@@ -63,7 +65,7 @@ public class InputLogicTests extends InputTestsBase {
type(WORD_TO_TYPE);
// Choose the typed word.
pickSuggestionManually(WORD_TO_TYPE);
- mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
+ sendUpdateForCursorMoveTo(WORD_TO_TYPE.length());
assertEquals("pick typed word over auto-correction then backspace", WORD_TO_TYPE,
mEditText.getText().toString());
type(Constants.CODE_DELETE);
@@ -78,7 +80,7 @@ public class InputLogicTests extends InputTestsBase {
type(WORD_TO_TYPE);
// Choose the second suggestion, which should be "thus" when "tgis" is typed.
pickSuggestionManually(WORD_TO_PICK);
- mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
+ sendUpdateForCursorMoveTo(WORD_TO_TYPE.length());
assertEquals("pick different suggestion then backspace", WORD_TO_PICK,
mEditText.getText().toString());
type(Constants.CODE_DELETE);
@@ -93,7 +95,8 @@ public class InputLogicTests extends InputTestsBase {
final int SELECTION_END = 19;
final String EXPECTED_RESULT = "some text some text";
type(STRING_TO_TYPE);
- // There is no IMF to call onUpdateSelection for us so we must do it by hand.
+ // Don't use the sendUpdateForCursorMove* family of methods here because they
+ // don't handle selections.
// 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.
@@ -113,7 +116,8 @@ public class InputLogicTests extends InputTestsBase {
final int SELECTION_END = 19;
final String EXPECTED_RESULT = "some text some text";
type(STRING_TO_TYPE);
- // There is no IMF to call onUpdateSelection for us so we must do it by hand.
+ // Don't use the sendUpdateForCursorMove* family of methods here because they
+ // don't handle selections.
// 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.
@@ -152,27 +156,45 @@ public class InputLogicTests extends InputTestsBase {
final String STRING_TO_TYPE = "tgis.";
final String EXPECTED_RESULT = "tgis.";
type(STRING_TO_TYPE);
- mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
+ sendUpdateForCursorMoveTo(STRING_TO_TYPE.length());
type(Constants.CODE_DELETE);
assertEquals("auto-correct with period then revert", EXPECTED_RESULT,
mEditText.getText().toString());
}
public void testAutoCorrectWithSpaceThenRevert() {
+ // Backspacing to cancel the "tgis"->"this" autocorrection should result in
+ // a "phantom space": if the user presses space immediately after,
+ // only one space will be inserted in total.
final String STRING_TO_TYPE = "tgis ";
- final String EXPECTED_RESULT = "tgis ";
+ final String EXPECTED_RESULT = "tgis";
type(STRING_TO_TYPE);
- mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
+ sendUpdateForCursorMoveTo(STRING_TO_TYPE.length());
type(Constants.CODE_DELETE);
assertEquals("auto-correct with space then revert", EXPECTED_RESULT,
mEditText.getText().toString());
}
+ public void testAutoCorrectWithSpaceThenRevertThenTypeMore() {
+ final String STRING_TO_TYPE_FIRST = "tgis ";
+ final String STRING_TO_TYPE_SECOND = "a";
+ final String EXPECTED_RESULT = "tgis a";
+ type(STRING_TO_TYPE_FIRST);
+ sendUpdateForCursorMoveTo(STRING_TO_TYPE_FIRST.length());
+ type(Constants.CODE_DELETE);
+
+ type(STRING_TO_TYPE_SECOND);
+ sendUpdateForCursorMoveTo(STRING_TO_TYPE_FIRST.length() - 1
+ + STRING_TO_TYPE_SECOND.length());
+ assertEquals("auto-correct with space then revert then type more", EXPECTED_RESULT,
+ mEditText.getText().toString());
+ }
+
public void testAutoCorrectToSelfDoesNotRevert() {
final String STRING_TO_TYPE = "this ";
final String EXPECTED_RESULT = "this";
type(STRING_TO_TYPE);
- mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
+ sendUpdateForCursorMoveTo(STRING_TO_TYPE.length());
type(Constants.CODE_DELETE);
assertEquals("auto-correct with space does not revert", EXPECTED_RESULT,
mEditText.getText().toString());
@@ -276,10 +298,9 @@ public class InputLogicTests extends InputTestsBase {
final String EXPECTED_RESULT = "this ";
final int NEW_CURSOR_POSITION = 0;
type(STRING_TO_TYPE);
- mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
+ sendUpdateForCursorMoveTo(typedLength);
mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION);
- mLatinIME.onUpdateSelection(typedLength, typedLength,
- NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
+ sendUpdateForCursorMoveTo(NEW_CURSOR_POSITION);
type(Constants.CODE_DELETE);
assertEquals("auto correct then move cursor to start of line then backspace",
EXPECTED_RESULT, mEditText.getText().toString());
@@ -291,10 +312,9 @@ public class InputLogicTests extends InputTestsBase {
final String EXPECTED_RESULT = "andthis ";
final int NEW_CURSOR_POSITION = STRING_TO_TYPE.indexOf('t');
type(STRING_TO_TYPE);
- mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
+ sendUpdateForCursorMoveTo(typedLength);
mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION);
- mLatinIME.onUpdateSelection(typedLength, typedLength,
- NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
+ sendUpdateForCursorMoveTo(NEW_CURSOR_POSITION);
type(Constants.CODE_DELETE);
assertEquals("auto correct then move cursor then backspace",
EXPECTED_RESULT, mEditText.getText().toString());
@@ -394,7 +414,7 @@ public class InputLogicTests extends InputTestsBase {
BaseInputConnection.getComposingSpanStart(mEditText.getText()));
assertEquals("resume suggestion on backspace", -1,
BaseInputConnection.getComposingSpanEnd(mEditText.getText()));
- mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
+ sendUpdateForCursorMoveTo(typedLength);
type(Constants.CODE_DELETE);
assertEquals("resume suggestion on backspace", 4,
BaseInputConnection.getComposingSpanStart(mEditText.getText()));
@@ -466,7 +486,7 @@ public class InputLogicTests extends InputTestsBase {
public void testPredictionsAfterSpace() {
final String WORD_TO_TYPE = "Barack ";
type(WORD_TO_TYPE);
- sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
// Test the first prediction is displayed
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
@@ -478,17 +498,17 @@ public class InputLogicTests extends InputTestsBase {
mLatinIME.clearPersonalizedDictionariesForTest();
final String WORD_TO_TYPE = "Barack ";
type(WORD_TO_TYPE);
- sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
// No need to test here, testPredictionsAfterSpace is testing it already
type(" ");
- sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
// Test the predictions have been cleared
SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
assertEquals("predictions cleared after double-space-to-period", suggestedWords.size(), 0);
type(Constants.CODE_DELETE);
- sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
// Test the first prediction is displayed
suggestedWords = mLatinIME.getSuggestedWordsForTest();
@@ -501,7 +521,7 @@ public class InputLogicTests extends InputTestsBase {
type(WORD_TO_TYPE);
// Choose the auto-correction. For "Barack", the auto-correction should be "Barack".
pickSuggestionManually(WORD_TO_TYPE);
- sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
// Test the first prediction is displayed
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
@@ -513,13 +533,13 @@ public class InputLogicTests extends InputTestsBase {
mLatinIME.clearPersonalizedDictionariesForTest();
final String WORD_TO_TYPE = "Barack. ";
type(WORD_TO_TYPE);
- sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
assertEquals("No prediction after period after inputting once.", 0, suggestedWords.size());
type(WORD_TO_TYPE);
- sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
suggestedWords = mLatinIME.getSuggestedWordsForTest();
assertEquals("Beginning-of-Sentence prediction after inputting 2 times.", "Barack",
@@ -535,27 +555,23 @@ public class InputLogicTests extends InputTestsBase {
final int endOfSuggestion = endOfPrefix + FIRST_NON_TYPED_SUGGESTION.length();
final int indexForManualCursor = endOfPrefix + 3; // +3 because it's after "Bar" in "Barack"
type(PREFIX);
- mLatinIME.onUpdateSelection(0, 0, endOfPrefix, endOfPrefix, -1, -1);
+ sendUpdateForCursorMoveTo(endOfPrefix);
type(WORD_TO_TYPE);
pickSuggestionManually(FIRST_NON_TYPED_SUGGESTION);
- mLatinIME.onUpdateSelection(endOfPrefix, endOfPrefix, endOfSuggestion, endOfSuggestion,
- -1, -1);
+ sendUpdateForCursorMoveTo(endOfSuggestion);
runMessages();
type(" ");
- mLatinIME.onUpdateSelection(endOfSuggestion, endOfSuggestion,
- endOfSuggestion + 1, endOfSuggestion + 1, -1, -1);
- sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ sendUpdateForCursorMoveBy(1);
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
// Simulate a manual cursor move
mInputConnection.setSelection(indexForManualCursor, indexForManualCursor);
- mLatinIME.onUpdateSelection(endOfSuggestion + 1, endOfSuggestion + 1,
- indexForManualCursor, indexForManualCursor, -1, -1);
- sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ sendUpdateForCursorMoveTo(indexForManualCursor);
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
pickSuggestionManually(WORD_TO_TYPE);
- mLatinIME.onUpdateSelection(indexForManualCursor, indexForManualCursor,
- endOfWord, endOfWord, -1, -1);
- sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ sendUpdateForCursorMoveTo(endOfWord);
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
// Test the first prediction is displayed
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
@@ -603,7 +619,7 @@ public class InputLogicTests extends InputTestsBase {
for (int i = 0; i < WORD_TO_TYPE.length(); ++i) {
type(WORD_TO_TYPE.substring(i, i+1));
- sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
}
assertEquals("type many trailing single quotes one by one", EXPECTED_RESULT,
@@ -615,7 +631,7 @@ public class InputLogicTests extends InputTestsBase {
final String EXPECTED_RESULT = WORD_TO_TYPE;
for (int i = 0; i < WORD_TO_TYPE.length(); ++i) {
type(WORD_TO_TYPE.substring(i, i+1));
- sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
}
assertEquals("type words letter by letter", EXPECTED_RESULT,
@@ -631,10 +647,94 @@ public class InputLogicTests extends InputTestsBase {
changeLanguage("fr");
runMessages();
type(WORD_TO_TYPE_SECOND_PART);
- sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
+ sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS);
runMessages();
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
assertEquals("Suggestions updated after switching languages",
EXPECTED_RESULT, suggestedWords.size() > 0 ? suggestedWords.getWord(1) : null);
}
+
+ public void testBasicGesture() {
+ gesture("this");
+ assertEquals("gesture \"this\"", "this", mEditText.getText().toString());
+ }
+
+ public void testGestureGesture() {
+ gesture("this");
+ gesture("is");
+ assertEquals("gesture \"this is\"", "this is", mEditText.getText().toString());
+ }
+
+ public void testGestureBackspaceGestureAgain() {
+ gesture("this");
+ type(Constants.CODE_DELETE);
+ assertEquals("gesture then backspace", "", mEditText.getText().toString());
+ gesture("this");
+ MoreAsserts.assertNotEqual("gesture twice the same thing", "this",
+ mEditText.getText().toString());
+ }
+
+ private void typeOrGestureWordAndPutCursorInside(final boolean gesture, final String word,
+ final int startPos) {
+ final int END_OF_WORD = startPos + word.length();
+ final int NEW_CURSOR_POSITION = startPos + word.length() / 2;
+ if (gesture) {
+ gesture(word);
+ } else {
+ type(word);
+ }
+ sendUpdateForCursorMoveTo(END_OF_WORD);
+ runMessages();
+ sendUpdateForCursorMoveTo(NEW_CURSOR_POSITION);
+ sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS);
+ runMessages();
+ ensureComposingSpanPos("move cursor inside word leaves composing span in the right place",
+ startPos, END_OF_WORD);
+ }
+
+ private void typeWordAndPutCursorInside(final String word, final int startPos) {
+ typeOrGestureWordAndPutCursorInside(false /* gesture */, word, startPos);
+ }
+
+ private void gestureWordAndPutCursorInside(final String word, final int startPos) {
+ typeOrGestureWordAndPutCursorInside(true /* gesture */, word, startPos);
+ }
+
+ private void ensureComposingSpanPos(final String message, final int from, final int to) {
+ assertEquals(message, from, BaseInputConnection.getComposingSpanStart(mEditText.getText()));
+ assertEquals(message, to, BaseInputConnection.getComposingSpanEnd(mEditText.getText()));
+ }
+
+ public void testTypeWithinComposing() {
+ final String WORD_TO_TYPE = "something";
+ final String EXPECTED_RESULT = "some thing";
+ typeWordAndPutCursorInside(WORD_TO_TYPE, 0 /* startPos */);
+ type(" ");
+ ensureComposingSpanPos("space while in the middle of a word cancels composition", -1, -1);
+ assertEquals("space in the middle of a composing word", EXPECTED_RESULT,
+ mEditText.getText().toString());
+ int cursorPos = sendUpdateForCursorMoveToEndOfLine();
+ runMessages();
+ type(" ");
+ assertEquals("mbo", "some thing ", mEditText.getText().toString());
+ typeWordAndPutCursorInside(WORD_TO_TYPE, cursorPos + 1 /* startPos */);
+ type(Constants.CODE_DELETE);
+ ensureComposingSpanPos("space while in the middle of a word cancels composition", -1, -1);
+ }
+
+ public void testTypeWithinGestureComposing() {
+ final String WORD_TO_TYPE = "something";
+ final String EXPECTED_RESULT = "some thing";
+ gestureWordAndPutCursorInside(WORD_TO_TYPE, 0 /* startPos */);
+ type(" ");
+ ensureComposingSpanPos("space while in the middle of a word cancels composition", -1, -1);
+ assertEquals("space in the middle of a composing word", EXPECTED_RESULT,
+ mEditText.getText().toString());
+ int cursorPos = sendUpdateForCursorMoveToEndOfLine();
+ runMessages();
+ type(" ");
+ typeWordAndPutCursorInside(WORD_TO_TYPE, cursorPos + 1 /* startPos */);
+ type(Constants.CODE_DELETE);
+ ensureComposingSpanPos("space while in the middle of a word cancels composition", -1, -1);
+ }
}