diff options
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/InputTestsBase.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/InputTestsBase.java | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index b267bc5da..4b157e700 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -35,9 +35,12 @@ import android.view.inputmethod.InputMethodSubtype; import android.widget.EditText; import android.widget.FrameLayout; +import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; +import com.android.inputmethod.latin.settings.DebugSettings; +import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.utils.LocaleUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; @@ -47,8 +50,6 @@ import java.util.concurrent.TimeUnit; public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { private static final String TAG = InputTestsBase.class.getSimpleName(); - private static final String PREF_DEBUG_MODE = "debug_mode"; - private static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold"; // Default value for auto-correction threshold. This is the string representation of the // index in the resources array of auto-correction threshold settings. private static final String DEFAULT_AUTO_CORRECTION_THRESHOLD = "1"; @@ -65,6 +66,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { protected View mInputView; protected InputConnection mInputConnection; private boolean mPreviousDebugSetting; + private boolean mPreviousBigramPredictionSettings; private String mPreviousAutoCorrectSetting; // A helper class to ease span tests @@ -163,7 +165,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { // returns the previous setting value protected boolean setDebugMode(final boolean value) { - return setBooleanPreference(PREF_DEBUG_MODE, value, false); + return setBooleanPreference(DebugSettings.PREF_DEBUG_MODE, value, false); } protected EditorInfo enrichEditorInfo(final EditorInfo ei) { @@ -184,7 +186,9 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { setupService(); mLatinIME = getService(); mPreviousDebugSetting = setDebugMode(true); - mPreviousAutoCorrectSetting = setStringPreference(PREF_AUTO_CORRECTION_THRESHOLD, + mPreviousBigramPredictionSettings = setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, + true, true /* defaultValue */); + mPreviousAutoCorrectSetting = setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, DEFAULT_AUTO_CORRECTION_THRESHOLD, DEFAULT_AUTO_CORRECTION_THRESHOLD); mLatinIME.onCreate(); EditorInfo ei = new EditorInfo(); @@ -202,16 +206,21 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { mInputConnection = ic; changeLanguage("en_US"); // Run messages to avoid the messages enqueued by startInputView() and its friends - // to run on a later call and ruin things. + // to run on a later call and ruin things. We need to wait first because some of them + // can be posted with a delay (notably, MSG_RESUME_SUGGESTIONS) + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS); runMessages(); } @Override - protected void tearDown() { + protected void tearDown() throws Exception { mLatinIME.mHandler.removeAllMessages(); - setStringPreference(PREF_AUTO_CORRECTION_THRESHOLD, mPreviousAutoCorrectSetting, + setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, mPreviousBigramPredictionSettings, + true /* defaultValue */); + setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, mPreviousAutoCorrectSetting, DEFAULT_AUTO_CORRECTION_THRESHOLD); setDebugMode(mPreviousDebugSetting); + super.tearDown(); } // We need to run the messages added to the handler from LatinIME. The only way to do @@ -282,17 +291,25 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { protected void changeLanguageWithoutWait(final String locale) { mEditText.mCurrentLocale = LocaleUtils.constructLocaleFromString(locale); - final InputMethodSubtype subtype = new InputMethodSubtype( - R.string.subtype_no_language_qwerty, R.drawable.ic_ime_switcher_dark, - locale, "keyboard", "KeyboardLayoutSet=" - // TODO: this is forcing a QWERTY keyboard for all locales, which is wrong. - // It's still better than using whatever keyboard is the current one, but we - // should actually use the default keyboard for this locale. - + SubtypeLocaleUtils.QWERTY - + "," + Constants.Subtype.ExtraValue.ASCII_CAPABLE - + "," + Constants.Subtype.ExtraValue.ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE - + "," + Constants.Subtype.ExtraValue.EMOJI_CAPABLE, - false /* isAuxiliary */, false /* overridesImplicitlyEnabledSubtype */); + // TODO: this is forcing a QWERTY keyboard for all locales, which is wrong. + // It's still better than using whatever keyboard is the current one, but we + // should actually use the default keyboard for this locale. + // TODO: Use {@link InputMethodSubtype.InputMethodSubtypeBuilder} directly or indirectly so + // that {@link InputMethodSubtype#isAsciiCapable} can return the correct value. + final String EXTRA_VALUE_FOR_TEST = + "KeyboardLayoutSet=" + SubtypeLocaleUtils.QWERTY + + "," + Constants.Subtype.ExtraValue.ASCII_CAPABLE + + "," + Constants.Subtype.ExtraValue.ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE + + "," + Constants.Subtype.ExtraValue.EMOJI_CAPABLE; + final InputMethodSubtype subtype = InputMethodSubtypeCompatUtils.newInputMethodSubtype( + R.string.subtype_no_language_qwerty, + R.drawable.ic_ime_switcher_dark, + locale, + Constants.Subtype.KEYBOARD_MODE, + EXTRA_VALUE_FOR_TEST, + false /* isAuxiliary */, + false /* overridesImplicitlyEnabledSubtype */, + 0 /* id */); SubtypeSwitcher.getInstance().forceSubtype(subtype); mLatinIME.loadKeyboard(); runMessages(); |