aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/inputmethod/latin/InputTestsBase.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2014-10-24 06:47:14 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-10-24 06:47:14 +0000
commitdfbdf8eb811e22141bd7d3e3397c37544dc382d9 (patch)
tree37d542ba082d6824b7e1a0d8f154216bcedcf134 /tests/src/com/android/inputmethod/latin/InputTestsBase.java
parent64cf43bd11f0c256fe63e05900501cb4401d04df (diff)
parent9afac3319c09f3daa626a403927a89c6ec25d3b8 (diff)
downloadlatinime-dfbdf8eb811e22141bd7d3e3397c37544dc382d9.tar.gz
latinime-dfbdf8eb811e22141bd7d3e3397c37544dc382d9.tar.xz
latinime-dfbdf8eb811e22141bd7d3e3397c37544dc382d9.zip
am 9afac331: Merge "Add tests for type through recorrection"
* commit '9afac3319c09f3daa626a403927a89c6ec25d3b8': 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.java37
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);
+ }
}