Merge "Selection Test: selection handle snaps to word boundaries."
This commit is contained in:
committed by
Android (Google) Code Review
commit
877a4e09ea
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.";
|
||||
|
||||
Reference in New Issue
Block a user