aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/inputmethod/latin/InputTestsBase.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2014-10-15 17:20:16 +0900
committerJean Chalard <jchalard@google.com>2014-10-22 17:05:10 +0900
commit7e930bfb3a6b4a36e6e6cde5cecc76640c148fb0 (patch)
tree3ac6434ef5a652434e720ac61401f58d215c7fdc /tests/src/com/android/inputmethod/latin/InputTestsBase.java
parent1249395563d43c818e12038231ec89dcbcdc5cd0 (diff)
downloadlatinime-7e930bfb3a6b4a36e6e6cde5cecc76640c148fb0.tar.gz
latinime-7e930bfb3a6b4a36e6e6cde5cecc76640c148fb0.tar.xz
latinime-7e930bfb3a6b4a36e6e6cde5cecc76640c148fb0.zip
Add tests for type through recorrection
Also introduce some helper methods Change-Id: I0f99733a4b7f0318b2b07217b614c19ea98859fc
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 f58dad9e6..269e53291 100644
--- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java
+++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
@@ -192,6 +192,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();
}
@@ -413,4 +414,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);
+ }
}