diff options
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/InputTestsBase.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/InputTestsBase.java | 47 |
1 files changed, 15 insertions, 32 deletions
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index 4ccbf4857..9e107a49c 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -36,6 +36,7 @@ import android.widget.TextView; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import java.util.Locale; @@ -130,7 +131,9 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { protected void setUp() throws Exception { super.setUp(); mTextView = new MyTextView(getContext()); - mTextView.setInputType(InputType.TYPE_CLASS_TEXT); + final int inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT + | InputType.TYPE_TEXT_FLAG_MULTI_LINE; + mTextView.setInputType(inputType); mTextView.setEnabled(true); setupService(); mLatinIME = getService(); @@ -138,9 +141,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { mLatinIME.onCreate(); setDebugMode(previousDebugSetting); final EditorInfo ei = new EditorInfo(); - ei.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT; final InputConnection ic = mTextView.onCreateInputConnection(ei); - ei.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT; final LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); final ViewGroup vg = new FrameLayout(getContext()); @@ -161,41 +162,22 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { // on the same thread that the tests are running on to mimic the actual environment as // closely as possible. // Now, Looper#loop() never exits in normal operation unless the Looper#quit() method - // is called, so we need to do that at the right time so that #loop() returns at some - // point and we don't end up in an infinite loop. - // After we quit, the looper is still technically ready to process more messages but - // the handler will refuse to enqueue any because #quit() has been called and it - // explicitly tests for it on message enqueuing, so we'll have to reset it so that - // it lets us continue normal operation. + // is called, which has a lot of bad side effects. We can however just throw an exception + // in the runnable which will unwind the stack and allow us to exit. + private final class InterruptRunMessagesException extends RuntimeException { + // Empty class + } protected void runMessages() { - // Here begins deep magic. - final Looper looper = mLatinIME.mHandler.getLooper(); mLatinIME.mHandler.post(new Runnable() { @Override public void run() { - looper.quit(); + throw new InterruptRunMessagesException(); } }); - // The only way to get out of Looper#loop() is to call #quit() on it (or on its queue). - // Once #quit() is called remaining messages are not processed, which is why we post - // a message that calls it instead of calling it directly. - Looper.loop(); - - // Once #quit() has been called, the message queue has an "mQuiting" field that prevents - // 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.myQueue(); try { - // However there is no way of doing it externally, and mQuiting is private. - // So... get out the big guns. - java.lang.reflect.Field f = MessageQueue.class.getDeclaredField("mQuiting"); - f.setAccessible(true); // What do you mean "private"? - f.setBoolean(queue, false); - } catch (NoSuchFieldException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); + Looper.loop(); + } catch (InterruptRunMessagesException e) { + // Resume normal operation } } @@ -251,7 +233,8 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { } protected void pickSuggestionManually(final int index, final String suggestion) { - mLatinIME.pickSuggestionManually(index, suggestion); + mLatinIME.pickSuggestionManually(index, new SuggestedWordInfo(suggestion, 1, + SuggestedWordInfo.KIND_CORRECTION, "main")); } // Helper to avoid writing the try{}catch block each time |