am cab6fa3e: Fix some InputLogicTests.

* commit 'cab6fa3e1b9f22135825cfdee1fb9df992e63234':
  Fix some InputLogicTests.
main
Dan Zivkovic 2015-03-17 19:12:34 +00:00 committed by Android Git Automerger
commit 2ec1e12d1f
2 changed files with 40 additions and 24 deletions

View File

@ -16,17 +16,33 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import android.test.MoreAsserts; import static android.test.MoreAsserts.assertNotEqual;
import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.LargeTest;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.inputmethod.BaseInputConnection; import android.view.inputmethod.BaseInputConnection;
import com.android.inputmethod.latin.common.Constants; import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.define.DecoderSpecificConstants;
import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.settings.Settings;
@LargeTest @LargeTest
public class InputLogicTests extends InputTestsBase { 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() { public void testTypeWord() {
final String WORD_TO_TYPE = "abcd"; final String WORD_TO_TYPE = "abcd";
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
@ -498,20 +514,15 @@ public class InputLogicTests extends InputTestsBase {
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages(); runMessages();
// No need to test here, testPredictionsAfterSpace is testing it already
type(" ");
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); type(Constants.CODE_DELETE);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages(); runMessages();
// Test the first prediction is displayed
SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
suggestedWords = mLatinIME.getSuggestedWordsForTest(); suggestedWords = mLatinIME.getSuggestedWordsForTest();
assertEquals("predictions after cancel double-space-to-period", "Obama", assertEquals("predictions after cancel double-space-to-period", "Obama",
suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null); mLatinIME.getSuggestedWordsForTest().getWord(0));
} }
public void testPredictionsAfterManualPick() { public void testPredictionsAfterManualPick() {
@ -533,15 +544,9 @@ public class InputLogicTests extends InputTestsBase {
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages(); runMessages();
SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
assertEquals("No prediction after period after inputting once.", 0, suggestedWords.size());
type(WORD_TO_TYPE); SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); assertFalse(mLatinIME.getSuggestedWordsForTest().isEmpty());
runMessages();
suggestedWords = mLatinIME.getSuggestedWordsForTest();
assertEquals("Beginning-of-Sentence prediction after inputting 2 times.", "Barack",
suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
} }
public void testPredictionsAfterRecorrection() { public void testPredictionsAfterRecorrection() {
@ -668,8 +673,11 @@ public class InputLogicTests extends InputTestsBase {
type(Constants.CODE_DELETE); type(Constants.CODE_DELETE);
assertEquals("gesture then backspace", "", mEditText.getText().toString()); assertEquals("gesture then backspace", "", mEditText.getText().toString());
gesture("this"); gesture("this");
MoreAsserts.assertNotEqual("gesture twice the same thing", "this", if (DecoderSpecificConstants.SHOULD_REMOVE_PREVIOUSLY_REJECTED_SUGGESTION) {
mEditText.getText().toString()); assertNotEqual("this", mEditText.getText().toString());
} else {
assertEquals("this", mEditText.getText().toString());
}
} }
private void typeOrGestureWordAndPutCursorInside(final boolean gesture, final String word, private void typeOrGestureWordAndPutCursorInside(final boolean gesture, final String word,
@ -736,12 +744,13 @@ public class InputLogicTests extends InputTestsBase {
ensureComposingSpanPos("space while in the middle of a word cancels composition", -1, -1); ensureComposingSpanPos("space while in the middle of a word cancels composition", -1, -1);
} }
// TODO: Verify this works when we return FIGS language models to the APK.
public void testAutoCorrectForFrench() { public void testAutoCorrectForFrench() {
final String STRING_TO_TYPE = "irq "; final String STRING_TO_TYPE = "irq ";
final String EXPECTED_RESULT = "ir a "; final String EXPECTED_RESULT = "ir a ";
changeLanguage("fr"); changeLanguage("es");
type(STRING_TO_TYPE); type(STRING_TO_TYPE);
assertEquals("simple auto-correct for French", EXPECTED_RESULT, assertEquals("simple auto-correct for Spanish", EXPECTED_RESULT,
mEditText.getText().toString()); mEditText.getText().toString());
} }
@ -771,6 +780,8 @@ public class InputLogicTests extends InputTestsBase {
} }
public void testWordThenSpaceThenPunctuationFromStripTwiceForFrench() { public void testWordThenSpaceThenPunctuationFromStripTwiceForFrench() {
setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, false, true);
final String WORD_TO_TYPE = "test "; final String WORD_TO_TYPE = "test ";
final String PUNCTUATION_FROM_STRIP = "!"; final String PUNCTUATION_FROM_STRIP = "!";
final String EXPECTED_RESULT = "test !!"; final String EXPECTED_RESULT = "test !!";

View File

@ -164,6 +164,11 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
return previousSetting; return previousSetting;
} }
protected boolean getBooleanPreference(final String key, final boolean defaultValue) {
return PreferenceManager.getDefaultSharedPreferences(mLatinIME)
.getBoolean(key, defaultValue);
}
protected String setStringPreference(final String key, final String value, protected String setStringPreference(final String key, final String value,
final String defaultValue) { final String defaultValue) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mLatinIME); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mLatinIME);