diff options
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/InputTestsBase.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/InputTestsBase.java | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index eb47fd517..fe58cb84e 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -39,9 +39,9 @@ import android.widget.TextView; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; -import com.android.inputmethod.keyboard.KeyboardActionListener; import java.util.HashMap; +import java.util.Locale; public class InputTestsBase extends ServiceTestCase<LatinIME> { @@ -52,7 +52,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { protected LatinIME mLatinIME; protected Keyboard mKeyboard; - protected TextView mTextView; + protected MyTextView mTextView; protected InputConnection mInputConnection; private final HashMap<String, InputMethodSubtype> mSubtypeMap = new HashMap<String, InputMethodSubtype>(); @@ -87,6 +87,27 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { return (mSpan instanceof SuggestionSpan) && 0 != (SuggestionSpan.FLAG_AUTO_CORRECTION & ((SuggestionSpan)mSpan).getFlags()); } + public String[] getSuggestions() { + return ((SuggestionSpan)mSpan).getSuggestions(); + } + } + + // A helper class to increase control over the TextView + public static class MyTextView extends TextView { + public Locale mCurrentLocale; + public MyTextView(final Context c) { + super(c); + } + public void onAttachedToWindow() { + super.onAttachedToWindow(); + } + public Locale getTextServicesLocale() { + // This method is necessary because TextView is asking this method for the language + // to check the spell in. If we don't override this, the spell checker will run in + // whatever language the keyboard is currently set on the test device, ignoring any + // settings we do inside the tests. + return mCurrentLocale; + } } public InputTestsBase() { @@ -113,7 +134,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { @Override protected void setUp() throws Exception { super.setUp(); - mTextView = new TextView(getContext()); + mTextView = new MyTextView(getContext()); mTextView.setInputType(InputType.TYPE_CLASS_TEXT); mTextView.setEnabled(true); setupService(); @@ -130,13 +151,12 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); final ViewGroup vg = new FrameLayout(getContext()); final View inputView = inflater.inflate(R.layout.input_view, vg); + mLatinIME.onCreateInputMethodInterface().startInput(ic, ei); mLatinIME.setInputView(inputView); mLatinIME.onBindInput(); mLatinIME.onCreateInputView(); mLatinIME.onStartInputView(ei, false); - mLatinIME.onCreateInputMethodInterface().startInput(ic, ei); mInputConnection = ic; - mKeyboard = mLatinIME.mKeyboardSwitcher.getKeyboard(); changeLanguage("en_US"); } @@ -222,9 +242,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { return; } } - mLatinIME.onCodeInput(codePoint, - KeyboardActionListener.NOT_A_TOUCH_COORDINATE, - KeyboardActionListener.NOT_A_TOUCH_COORDINATE); + mLatinIME.onCodeInput(codePoint, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); //mLatinIME.onReleaseKey(codePoint, false); } @@ -252,17 +270,18 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { protected void changeLanguage(final String locale) { final InputMethodSubtype subtype = mSubtypeMap.get(locale); + mTextView.mCurrentLocale = LocaleUtils.constructLocaleFromString(locale); if (subtype == null) { fail("InputMethodSubtype for locale " + locale + " is not enabled"); } SubtypeSwitcher.getInstance().updateSubtype(subtype); + mLatinIME.loadKeyboard(); + mKeyboard = mLatinIME.mKeyboardSwitcher.getKeyboard(); waitForDictionaryToBeLoaded(); } protected void pickSuggestionManually(final int index, final CharSequence suggestion) { - mLatinIME.pickSuggestionManually(index, suggestion, - KeyboardActionListener.NOT_A_TOUCH_COORDINATE, - KeyboardActionListener.NOT_A_TOUCH_COORDINATE); + mLatinIME.pickSuggestionManually(index, suggestion); } // Helper to avoid writing the try{}catch block each time |