Adjust a test for a new default setting

Bug: 6338940
Change-Id: I8f14ce0de768ddb0394eb2b584d8753e0df82a28
main
Jean Chalard 2012-04-16 13:03:23 +09:00
parent a7352c8df4
commit 9f7392ea9d
2 changed files with 36 additions and 14 deletions

View File

@ -90,14 +90,21 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
super(LatinIME.class); super(LatinIME.class);
} }
// returns the previous setting value // TODO: Isn't there a way to make this generic somehow? We can take a <T> and return a <T>
protected boolean setDebugMode(final boolean mode) { // but we'd have to dispatch types on editor.put...() functions
protected boolean setBooleanPreference(final String key, final boolean value,
final boolean defaultValue) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mLatinIME); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mLatinIME);
final boolean previousDebugSetting = prefs.getBoolean(PREF_DEBUG_MODE, false); final boolean previousSetting = prefs.getBoolean(key, defaultValue);
final SharedPreferences.Editor editor = prefs.edit(); final SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(PREF_DEBUG_MODE, mode); editor.putBoolean(key, value);
editor.commit(); editor.commit();
return previousDebugSetting; return previousSetting;
}
// returns the previous setting value
protected boolean setDebugMode(final boolean value) {
return setBooleanPreference(PREF_DEBUG_MODE, value, false);
} }
// overload this to configure preferences in a way specific to a subclass's tests // overload this to configure preferences in a way specific to a subclass's tests

View File

@ -16,21 +16,36 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import com.android.inputmethod.latin.R;
public class PunctuationTests extends InputTestsBase { public class PunctuationTests extends InputTestsBase {
final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction";
public void testWordThenSpaceThenPunctuationFromStripTwice() { public void testWordThenSpaceThenPunctuationFromStripTwice() {
final String WORD_TO_TYPE = "this "; final String WORD_TO_TYPE = "this ";
final String PUNCTUATION_FROM_STRIP = "!"; final String PUNCTUATION_FROM_STRIP = "!";
final String EXPECTED_RESULT = "this!! "; final String EXPECTED_RESULT = "this!! ";
type(WORD_TO_TYPE); final boolean defaultNextWordPredictionOption =
sleep(DELAY_TO_WAIT_FOR_UNDERLINE); mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_suggestions);
runMessages(); final boolean previousNextWordPredictionOption =
assertTrue("type word then type space should display punctuation strip", setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, false,
mLatinIME.isShowingPunctuationList()); defaultNextWordPredictionOption);
mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); try {
mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); mLatinIME.loadSettings();
assertEquals("type word then type space then punctuation from strip twice", EXPECTED_RESULT, type(WORD_TO_TYPE);
mTextView.getText().toString()); sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
assertTrue("type word then type space should display punctuation strip",
mLatinIME.isShowingPunctuationList());
mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
assertEquals("type word then type space then punctuation from strip twice",
EXPECTED_RESULT, mTextView.getText().toString());
} finally {
setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption,
defaultNextWordPredictionOption);
}
} }
public void testWordThenSpaceThenPunctuationFromKeyboardTwice() { public void testWordThenSpaceThenPunctuationFromKeyboardTwice() {