diff options
author | 2014-10-24 06:43:20 +0000 | |
---|---|---|
committer | 2014-10-24 06:43:20 +0000 | |
commit | 9afac3319c09f3daa626a403927a89c6ec25d3b8 (patch) | |
tree | 2478b884551cdacd248f044f0049bc54c059545a /tests/src/com/android/inputmethod/latin/InputTestsBase.java | |
parent | a2b4bfb0f5b5fd67df9c1e4c0cfc3a461b4fee2e (diff) | |
parent | 7e930bfb3a6b4a36e6e6cde5cecc76640c148fb0 (diff) | |
download | latinime-9afac3319c09f3daa626a403927a89c6ec25d3b8.tar.gz latinime-9afac3319c09f3daa626a403927a89c6ec25d3b8.tar.xz latinime-9afac3319c09f3daa626a403927a89c6ec25d3b8.zip |
Merge "Add tests for type through recorrection"
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/InputTestsBase.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/InputTestsBase.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index 0e9961ae8..78b4b18ec 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -193,6 +193,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { | InputType.TYPE_TEXT_FLAG_MULTI_LINE; mEditText.setInputType(inputType); mEditText.setEnabled(true); + mLastCursorPos = 0; if (null == Looper.myLooper()) { Looper.prepare(); } @@ -414,4 +415,40 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { Thread.sleep(milliseconds); } catch (InterruptedException e) {} } + + // Some helper methods to manage the mock cursor position + // DO NOT CALL LatinIME#onUpdateSelection IF YOU WANT TO USE THOSE + int mLastCursorPos = 0; + /** + * Move the cached cursor position to the passed position and send onUpdateSelection to LatinIME + */ + protected int sendUpdateForCursorMoveTo(final int position) { + mInputConnection.setSelection(position, position); + mLatinIME.onUpdateSelection(mLastCursorPos, mLastCursorPos, position, position, -1, -1); + mLastCursorPos = position; + return position; + } + + /** + * Move the cached cursor position by the passed amount and send onUpdateSelection to LatinIME + */ + protected int sendUpdateForCursorMoveBy(final int offset) { + final int lastPos = mEditText.getText().length(); + final int requestedPosition = mLastCursorPos + offset; + if (requestedPosition < 0) { + return sendUpdateForCursorMoveTo(0); + } else if (requestedPosition > lastPos) { + return sendUpdateForCursorMoveTo(lastPos); + } else { + return sendUpdateForCursorMoveTo(requestedPosition); + } + } + + /** + * Move the cached cursor position to the end of the line and send onUpdateSelection to LatinIME + */ + protected int sendUpdateForCursorMoveToEndOfLine() { + final int lastPos = mEditText.getText().length(); + return sendUpdateForCursorMoveTo(lastPos); + } } |