diff options
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/InputLogicTests.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/InputLogicTests.java | 187 |
1 files changed, 92 insertions, 95 deletions
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java index a6c9bbee0..f2885f5f2 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java @@ -16,17 +16,33 @@ package com.android.inputmethod.latin; -import android.test.MoreAsserts; +import static android.test.MoreAsserts.assertNotEqual; + 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.define.DecoderSpecificConstants; import com.android.inputmethod.latin.settings.Settings; @LargeTest public class InputLogicTests extends InputTestsBase { + private boolean mNextWordPrediction; + + @Override + public void setUp() throws Exception { + super.setUp(); + mNextWordPrediction = getBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, true); + } + + @Override + public void tearDown() throws Exception { + setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, mNextWordPrediction, true); + super.tearDown(); + } + public void testTypeWord() { final String WORD_TO_TYPE = "abcd"; type(WORD_TO_TYPE); @@ -201,22 +217,45 @@ public class InputLogicTests extends InputTestsBase { } public void testDoubleSpace() { - // Set default pref just in case - setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true); // U+1F607 is an emoji final String[] STRINGS_TO_TYPE = new String[] { "this ", "a+ ", "\u1F607 ", ".. ", ") ", "( ", "% " }; final String[] EXPECTED_RESULTS = new String[] { "this. ", "a+. ", "\u1F607. ", ".. ", "). ", "( ", "%. " }; - for (int i = 0; i < STRINGS_TO_TYPE.length; ++i) { + verifyDoubleSpace(STRINGS_TO_TYPE, EXPECTED_RESULTS); + } + + public void testDoubleSpaceHindi() { + changeLanguage("hi"); + // U+1F607 is an emoji + final String[] STRINGS_TO_TYPE = + new String[] { "this ", "a+ ", "\u1F607 ", "|| ", ") ", "( ", "% " }; + final String[] EXPECTED_RESULTS = + new String[] { "this| ", "a+| ", "\u1F607| ", "|| ", ")| ", "( ", "%| " }; + verifyDoubleSpace(STRINGS_TO_TYPE, EXPECTED_RESULTS); + } + + private void verifyDoubleSpace(String[] stringsToType, String[] expectedResults) { + // Set default pref just in case + setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true); + for (int i = 0; i < stringsToType.length; ++i) { mEditText.setText(""); - type(STRINGS_TO_TYPE[i]); - assertEquals("double space processing", EXPECTED_RESULTS[i], + type(stringsToType[i]); + assertEquals("double space processing", expectedResults[i], mEditText.getText().toString()); } } - public void testCancelDoubleSpace() { + public void testCancelDoubleSpaceEnglish() { + final String STRING_TO_TYPE = "this "; + final String EXPECTED_RESULT = "this "; + type(STRING_TO_TYPE); + type(Constants.CODE_DELETE); + assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testCancelDoubleSpaceHindi() { + changeLanguage("hi"); final String STRING_TO_TYPE = "this "; final String EXPECTED_RESULT = "this "; type(STRING_TO_TYPE); @@ -265,9 +304,9 @@ public class InputLogicTests extends InputTestsBase { public void testDoubleSpacePeriod() { // Reset settings to default, else these tests will go flaky. setBooleanPreference(Settings.PREF_SHOW_SUGGESTIONS, true, true); - setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, "1", "1"); + setBooleanPreference(Settings.PREF_AUTO_CORRECTION, true, true); setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true); - testDoubleSpacePeriodWithSettings(true /* expectsPeriod */); + testDoubleSpacePeriodWithSettings(true); // "Suggestion visibility" to off testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS, false); // "Suggestion visibility" to on @@ -277,18 +316,16 @@ public class InputLogicTests extends InputTestsBase { testDoubleSpacePeriodWithSettings(false, Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, false); // "Auto-correction" to "off" - testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0"); - // "Auto-correction" to "modest" - testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "1"); - // "Auto-correction" to "very aggressive" - testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "3"); + testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION, false); + // "Auto-correction" to "on" + testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION, true); // "Suggestion visibility" to "always hide" and "Auto-correction" to "off" testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS, false, - Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0"); + Settings.PREF_AUTO_CORRECTION, false); // "Suggestion visibility" to "always hide" and "Auto-correction" to "off" testDoubleSpacePeriodWithSettings(false, Settings.PREF_SHOW_SUGGESTIONS, false, - Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0", + Settings.PREF_AUTO_CORRECTION, false, Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, false); } @@ -449,38 +486,19 @@ public class InputLogicTests extends InputTestsBase { type(" "); helperTestComposing("a'", true); } + // TODO: Add some tests for non-BMP characters public void testAutoCorrectByUserHistory() { - final String WORD_TO_BE_CORRECTED = "qpmx"; - final String NOT_CORRECTED_RESULT = "qpmx "; - final String DESIRED_WORD = "qpmz"; - final String CORRECTED_RESULT = "qpmz "; - final int typeCountNotToAutocorrect = 1; - final int typeCountToAutoCorrect = 16; - int startIndex = 0; - int endIndex = 0; - - for (int i = 0; i < typeCountNotToAutocorrect; i++) { - type(DESIRED_WORD); - type(Constants.CODE_SPACE); - } - startIndex = mEditText.getText().length(); - type(WORD_TO_BE_CORRECTED); + type("qpmz"); type(Constants.CODE_SPACE); - endIndex = mEditText.getText().length(); - assertEquals("not auto-corrected by user history", NOT_CORRECTED_RESULT, - mEditText.getText().subSequence(startIndex, endIndex).toString()); - for (int i = typeCountNotToAutocorrect; i < typeCountToAutoCorrect; i++) { - type(DESIRED_WORD); - type(Constants.CODE_SPACE); - } - startIndex = mEditText.getText().length(); - type(WORD_TO_BE_CORRECTED); + + int startIndex = mEditText.getText().length(); + type("qpmx"); type(Constants.CODE_SPACE); - endIndex = mEditText.getText().length(); + int endIndex = mEditText.getText().length(); assertEquals("auto-corrected by user history", - CORRECTED_RESULT, mEditText.getText().subSequence(startIndex, endIndex).toString()); + "qpmz ", mEditText.getText().subSequence(startIndex, endIndex).toString()); } public void testPredictionsAfterSpace() { @@ -496,26 +514,19 @@ public class InputLogicTests extends InputTestsBase { public void testPredictionsWithDoubleSpaceToPeriod() { mLatinIME.clearPersonalizedDictionariesForTest(); - final String WORD_TO_TYPE = "Barack "; + final String WORD_TO_TYPE = "Barack "; type(WORD_TO_TYPE); 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_MILLIS); - runMessages(); - // Corrections have been replaced with predictions. - SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest(); - String word = suggestedWords == null ? null : suggestedWords.getWord(0); - assertTrue("predictions after double-space-to-period is I or The", - "I".equals(word) || "The".equals(word)); + type(Constants.CODE_DELETE); sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); runMessages(); - // Test the first prediction is displayed + + SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest(); suggestedWords = mLatinIME.getSuggestedWordsForTest(); assertEquals("predictions after cancel double-space-to-period", "Obama", - suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null); + mLatinIME.getSuggestedWordsForTest().getWord(0)); } public void testPredictionsAfterManualPick() { @@ -531,6 +542,17 @@ public class InputLogicTests extends InputTestsBase { suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null); } + public void testPredictionsAfterPeriod() { + mLatinIME.clearPersonalizedDictionariesForTest(); + final String WORD_TO_TYPE = "Barack. "; + type(WORD_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + + SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest(); + assertFalse(mLatinIME.getSuggestedWordsForTest().isEmpty()); + } + public void testPredictionsAfterRecorrection() { final String PREFIX = "A "; final String WORD_TO_TYPE = "Barack"; @@ -641,13 +663,13 @@ public class InputLogicTests extends InputTestsBase { public void testBasicGesture() { gesture("this"); - assertEquals("gesture \"this\"", "this", mEditText.getText().toString()); + assertEquals("this", mEditText.getText().toString()); } public void testGestureGesture() { - gesture("this"); - gesture("is"); - assertEquals("gesture \"this is\"", "this is", mEditText.getText().toString()); + gesture("got"); + gesture("milk"); + assertEquals("got milk", mEditText.getText().toString()); } public void testGestureBackspaceGestureAgain() { @@ -655,8 +677,11 @@ public class InputLogicTests extends InputTestsBase { type(Constants.CODE_DELETE); assertEquals("gesture then backspace", "", mEditText.getText().toString()); gesture("this"); - MoreAsserts.assertNotEqual("gesture twice the same thing", "this", - mEditText.getText().toString()); + if (DecoderSpecificConstants.SHOULD_REMOVE_PREVIOUSLY_REJECTED_SUGGESTION) { + assertNotEqual("this", mEditText.getText().toString()); + } else { + assertEquals("this", mEditText.getText().toString()); + } } private void typeOrGestureWordAndPutCursorInside(final boolean gesture, final String word, @@ -673,8 +698,6 @@ public class InputLogicTests extends InputTestsBase { 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) { @@ -704,7 +727,7 @@ public class InputLogicTests extends InputTestsBase { 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); + ensureComposingSpanPos("delete while in the middle of a word cancels composition", -1, -1); } public void testTypeWithinGestureComposing() { @@ -720,15 +743,15 @@ public class InputLogicTests extends InputTestsBase { 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); + ensureComposingSpanPos("delete while in the middle of a word cancels composition", -1, -1); } public void testAutoCorrectForFrench() { final String STRING_TO_TYPE = "irq "; - final String EXPECTED_RESULT = "ira "; - changeLanguage("fr"); + final String EXPECTED_RESULT = "ir a "; + changeLanguage("es"); type(STRING_TO_TYPE); - assertEquals("simple auto-correct for French", EXPECTED_RESULT, + assertEquals("simple auto-correct for Spanish", EXPECTED_RESULT, mEditText.getText().toString()); } @@ -758,6 +781,8 @@ public class InputLogicTests extends InputTestsBase { } public void testWordThenSpaceThenPunctuationFromStripTwiceForFrench() { + setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, false, true); + final String WORD_TO_TYPE = "test "; final String PUNCTUATION_FROM_STRIP = "!"; final String EXPECTED_RESULT = "test !!"; @@ -802,32 +827,4 @@ public class InputLogicTests extends InputTestsBase { assertEquals("auto-correct with umlaut for German", EXPECTED_RESULT, mEditText.getText().toString()); } - - // Corresponds to InputLogicTests#testDoubleSpace - public void testDoubleSpaceHindi() { - changeLanguage("hi"); - // Set default pref just in case - setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true); - // U+1F607 is an emoji - final String[] STRINGS_TO_TYPE = - new String[] { "this ", "a+ ", "\u1F607 ", "|| ", ") ", "( ", "% " }; - final String[] EXPECTED_RESULTS = - new String[] { "this| ", "a+| ", "\u1F607| ", "|| ", ")| ", "( ", "%| " }; - for (int i = 0; i < STRINGS_TO_TYPE.length; ++i) { - mEditText.setText(""); - type(STRINGS_TO_TYPE[i]); - assertEquals("double space processing", EXPECTED_RESULTS[i], - mEditText.getText().toString()); - } - } - - // Corresponds to InputLogicTests#testCancelDoubleSpace - public void testCancelDoubleSpaceHindi() { - changeLanguage("hi"); - final String STRING_TO_TYPE = "this "; - final String EXPECTED_RESULT = "this "; - type(STRING_TO_TYPE); - type(Constants.CODE_DELETE); - assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString()); - } } |