diff options
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/InputTestsBase.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/InputTestsBase.java | 62 |
1 files changed, 16 insertions, 46 deletions
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index fe58cb84e..4ccbf4857 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -1,17 +1,17 @@ /* * Copyright (C) 2012 The Android Open Source Project * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.android.inputmethod.latin; @@ -31,16 +31,12 @@ import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; -import android.view.inputmethod.InputMethodInfo; -import android.view.inputmethod.InputMethodManager; -import android.view.inputmethod.InputMethodSubtype; import android.widget.FrameLayout; import android.widget.TextView; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; -import java.util.HashMap; import java.util.Locale; public class InputTestsBase extends ServiceTestCase<LatinIME> { @@ -53,9 +49,8 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { protected LatinIME mLatinIME; protected Keyboard mKeyboard; protected MyTextView mTextView; + protected View mInputView; protected InputConnection mInputConnection; - private final HashMap<String, InputMethodSubtype> mSubtypeMap = - new HashMap<String, InputMethodSubtype>(); // A helper class to ease span tests public static class SpanGetter { @@ -142,7 +137,6 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { final boolean previousDebugSetting = setDebugMode(true); mLatinIME.onCreate(); setDebugMode(previousDebugSetting); - initSubtypeMap(); final EditorInfo ei = new EditorInfo(); ei.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT; final InputConnection ic = mTextView.onCreateInputConnection(ei); @@ -150,9 +144,9 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { final LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); final ViewGroup vg = new FrameLayout(getContext()); - final View inputView = inflater.inflate(R.layout.input_view, vg); + mInputView = inflater.inflate(R.layout.input_view, vg); mLatinIME.onCreateInputMethodInterface().startInput(ic, ei); - mLatinIME.setInputView(inputView); + mLatinIME.setInputView(mInputView); mLatinIME.onBindInput(); mLatinIME.onCreateInputView(); mLatinIME.onStartInputView(ei, false); @@ -160,26 +154,6 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { changeLanguage("en_US"); } - private void initSubtypeMap() { - final InputMethodManager imm = (InputMethodManager)mLatinIME.getSystemService( - Context.INPUT_METHOD_SERVICE); - final String packageName = mLatinIME.getPackageName(); - // The IMEs and subtypes don't need to be enabled to run this test because IMF isn't - // involved here. - for (final InputMethodInfo imi : imm.getInputMethodList()) { - if (imi.getPackageName().equals(packageName)) { - final int subtypeCount = imi.getSubtypeCount(); - for (int i = 0; i < subtypeCount; i++) { - final InputMethodSubtype ims = imi.getSubtypeAt(i); - final String locale = ims.getLocale(); - mSubtypeMap.put(locale, ims); - } - return; - } - } - fail("LatinIME is not found"); - } - // We need to run the messages added to the handler from LatinIME. The only way to do // that is to call Looper#loop() on the right looper, so we're going to get the looper // object and call #loop() here. The messages in the handler actually run on the UI @@ -211,7 +185,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { // any subsequent post in this queue. However the queue itself is still fully functional! // If we have a way of resetting "queue.mQuiting" then we can continue using it as normal, // coming back to this method to run the messages. - MessageQueue queue = looper.getQueue(); + MessageQueue queue = Looper.myQueue(); try { // However there is no way of doing it externally, and mQuiting is private. // So... get out the big guns. @@ -253,8 +227,8 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { } protected void waitForDictionaryToBeLoaded() { - int remainingAttempts = 10; - while (remainingAttempts > 0 && !mLatinIME.mSuggest.hasMainDictionary()) { + int remainingAttempts = 300; + while (remainingAttempts > 0 && mLatinIME.mSuggest.isCurrentlyWaitingForMainDictionary()) { try { Thread.sleep(200); } catch (InterruptedException e) { @@ -269,18 +243,14 @@ 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); + SubtypeSwitcher.getInstance().forceLocale(mTextView.mCurrentLocale); mLatinIME.loadKeyboard(); mKeyboard = mLatinIME.mKeyboardSwitcher.getKeyboard(); waitForDictionaryToBeLoaded(); } - protected void pickSuggestionManually(final int index, final CharSequence suggestion) { + protected void pickSuggestionManually(final int index, final String suggestion) { mLatinIME.pickSuggestionManually(index, suggestion); } |