summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Keisuke Kuroyanagi <ksk@google.com> 2015-11-25 07:37:29 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2015-11-25 07:37:29 +0000
commit877a4e09ea4a8a0dea8aa51dac210e7e3172e166 (patch)
tree4145323e75e774e7e8b9655bff5c90dbb182da34
parent68e1945c3935a92b6043e2dd8f98eaf9af620279 (diff)
parentec913c0eb6c3cb70f69653ee988d440f47e5cc55 (diff)
Merge "Selection Test: selection handle snaps to word boundaries."
-rw-r--r--core/tests/coretests/src/android/widget/TextViewActivityTest.java89
-rw-r--r--core/tests/coretests/src/android/widget/espresso/DragAction.java7
2 files changed, 96 insertions, 0 deletions
diff --git a/core/tests/coretests/src/android/widget/TextViewActivityTest.java b/core/tests/coretests/src/android/widget/TextViewActivityTest.java
index 8e8a460d32be..78a0a59c862a 100644
--- a/core/tests/coretests/src/android/widget/TextViewActivityTest.java
+++ b/core/tests/coretests/src/android/widget/TextViewActivityTest.java
@@ -247,4 +247,93 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV
.perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('a')));
onView(withId(R.id.textview)).check(hasSelection("h"));
}
+
+ @SmallTest
+ public void testSelectionHandles_snapToWordBoundary() throws Exception {
+ final String text = "abcd efg hijk lmn opqr";
+ onView(withId(R.id.textview)).perform(click());
+ onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text));
+ onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i')));
+
+ final TextView textView = (TextView)getActivity().findViewById(R.id.textview);
+
+ onHandleView(com.android.internal.R.id.selection_start_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('f')));
+ onView(withId(R.id.textview)).check(hasSelection("efg hijk"));
+
+ onHandleView(com.android.internal.R.id.selection_start_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('d') + 1));
+ onView(withId(R.id.textview)).check(hasSelection("efg hijk"));
+
+
+ onHandleView(com.android.internal.R.id.selection_start_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('c')));
+ onView(withId(R.id.textview)).check(hasSelection("abcd efg hijk"));
+
+ onHandleView(com.android.internal.R.id.selection_start_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('d')));
+ onView(withId(R.id.textview)).check(hasSelection("d efg hijk"));
+
+ onHandleView(com.android.internal.R.id.selection_start_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('b')));
+ onView(withId(R.id.textview)).check(hasSelection("bcd efg hijk"));
+
+ onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i')));
+
+ onHandleView(com.android.internal.R.id.selection_end_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('n')));
+ onView(withId(R.id.textview)).check(hasSelection("hijk lmn"));
+
+ onHandleView(com.android.internal.R.id.selection_end_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('o')));
+ onView(withId(R.id.textview)).check(hasSelection("hijk lmn"));
+
+ onHandleView(com.android.internal.R.id.selection_end_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('q')));
+ onView(withId(R.id.textview)).check(hasSelection("hijk lmn opqr"));
+
+ onHandleView(com.android.internal.R.id.selection_end_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('p')));
+ onView(withId(R.id.textview)).check(hasSelection("hijk lmn o"));
+
+ onHandleView(com.android.internal.R.id.selection_end_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('r')));
+ onView(withId(R.id.textview)).check(hasSelection("hijk lmn opq"));
+ }
+
+ @SmallTest
+ public void testSelectionHandles_snapToWordBoundary_multiLine() throws Exception {
+ final String text = "abcd efg\n" + "hijk lmn\n" + "opqr stu";
+ onView(withId(R.id.textview)).perform(click());
+ onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text));
+ onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('m')));
+
+ final TextView textView = (TextView)getActivity().findViewById(R.id.textview);
+
+ onHandleView(com.android.internal.R.id.selection_start_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('c')));
+ onView(withId(R.id.textview)).check(hasSelection("abcd efg\nhijk lmn"));
+
+ onHandleView(com.android.internal.R.id.selection_start_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('g')));
+ onView(withId(R.id.textview)).check(hasSelection("g\nhijk lmn"));
+
+ onHandleView(com.android.internal.R.id.selection_start_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('m')));
+ onView(withId(R.id.textview)).check(hasSelection("lmn"));
+
+ onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i')));
+
+ onHandleView(com.android.internal.R.id.selection_end_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('u')));
+ onView(withId(R.id.textview)).check(hasSelection("hijk lmn\nopqr stu"));
+
+ onHandleView(com.android.internal.R.id.selection_end_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('p')));
+ onView(withId(R.id.textview)).check(hasSelection("hijk lmn\no"));
+
+ onHandleView(com.android.internal.R.id.selection_end_handle)
+ .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('i')));
+ onView(withId(R.id.textview)).check(hasSelection("hijk"));
+ }
}
diff --git a/core/tests/coretests/src/android/widget/espresso/DragAction.java b/core/tests/coretests/src/android/widget/espresso/DragAction.java
index c939217f89e9..1132ce0c52ac 100644
--- a/core/tests/coretests/src/android/widget/espresso/DragAction.java
+++ b/core/tests/coretests/src/android/widget/espresso/DragAction.java
@@ -206,6 +206,9 @@ public final class DragAction implements ViewAction {
/** Length of time a drag should last for, in milliseconds. */
private static final int DRAG_DURATION = 1500;
+ /** Duration between the last move event and the up event, in milliseconds. */
+ private static final int WAIT_BEFORE_SENDING_UP = 400;
+
private static Status sendLinearDrag(
UiController uiController, DownMotionPerformer downMotion,
float[] startCoordinates, float[] endCoordinates, float[] precision) {
@@ -236,6 +239,10 @@ public final class DragAction implements ViewAction {
}
}
+ // Wait before sending up because some drag handling logic may discard move events
+ // that has been sent immediately before the up event. e.g. HandleView.
+ uiController.loopMainThreadForAtLeast(WAIT_BEFORE_SENDING_UP);
+
if (!MotionEvents.sendUp(uiController, downEvent, endCoordinates)) {
String logMessage = "Injection of up event as part of the drag failed. " +
"Sending cancel event.";