Index: content/public/android/javatests/src/org/chromium/content/browser/InsertionHandleTest.java |
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/InsertionHandleTest.java b/content/public/android/javatests/src/org/chromium/content/browser/InsertionHandleTest.java |
index c1da521f65445d98d5803b6cc653fcb5e23bf852..8d207a371e16bc2a10cbbda937f61b8c8bf21079 100644 |
--- a/content/public/android/javatests/src/org/chromium/content/browser/InsertionHandleTest.java |
+++ b/content/public/android/javatests/src/org/chromium/content/browser/InsertionHandleTest.java |
@@ -14,12 +14,16 @@ import android.text.Selection; |
import org.chromium.base.test.util.Feature; |
import org.chromium.content.browser.test.util.Criteria; |
import org.chromium.content.browser.test.util.CriteriaHelper; |
+import org.chromium.content.browser.test.util.DOMUtils; |
+import org.chromium.content.browser.test.util.TestCallbackHelperContainer; |
import org.chromium.content.browser.test.util.TouchUtils; |
import org.chromium.content_shell.ContentShellTestBase; |
public class InsertionHandleTest extends ContentShellTestBase { |
private static final String FILENAME = "content/insertion_handle/editable_long_text.html"; |
+ private static final String INPUT_TEXT_FILENAME = "content/insertion_handle/input_text.html"; |
+ private static final String INPUT_TEXT_ID = "input_text"; |
// Offset to compensate for the fact that the handle is below the text. |
private static final int VERTICAL_OFFSET = 10; |
// These positions should both be in the text area and not within |
@@ -28,9 +32,43 @@ public class InsertionHandleTest extends ContentShellTestBase { |
private static final int INITIAL_CLICK_Y = 100; |
private static final int DRAG_TO_X = 287; |
private static final int DRAG_TO_Y = 199; |
- private static final int HANDLE_POSITION_TOLERANCE = 60; |
+ private static final int HANDLE_POSITION_TOLERANCE = 40; |
private static final String PASTE_TEXT = "**test text to paste**"; |
+ private void dragHandleTo(int dragToX, int dragToY, int steps) throws Throwable { |
+ InsertionHandleController ihc = getContentViewCore().getInsertionHandleControllerForTest(); |
+ HandleView handle = ihc.getHandleViewForTest(); |
+ int initialX = handle.getPositionX(); |
+ int initialY = handle.getPositionY() + VERTICAL_OFFSET; |
+ ContentView view = getContentView(); |
+ |
+ int fromLocation[] = TouchUtils.getAbsoluteLocationFromRelative(view, initialX, initialY); |
+ int toLocation[] = TouchUtils.getAbsoluteLocationFromRelative(view, dragToX, dragToY); |
+ |
+ long downTime = TouchUtils.dragStart(getInstrumentation(), fromLocation[0], |
+ fromLocation[1]); |
+ assertWaitForHandleDraggingEquals(true); |
+ TouchUtils.dragTo(getInstrumentation(), fromLocation[0], toLocation[0], fromLocation[1], |
+ toLocation[1], steps, downTime); |
+ TouchUtils.dragEnd(getInstrumentation(), toLocation[0], toLocation[1], downTime); |
+ assertWaitForHandleDraggingEquals(false); |
+ } |
+ |
+ private void dragHandleTo(int dragToX, int dragToY) throws Throwable { |
+ dragHandleTo(dragToX, dragToY, 5); |
+ } |
+ |
+ private void assertWaitForHandleDraggingEquals(final boolean expected) throws Throwable { |
+ InsertionHandleController ihc = getContentViewCore().getInsertionHandleControllerForTest(); |
+ final HandleView handle = ihc.getHandleViewForTest(); |
+ assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
+ @Override |
+ public boolean isSatisfied() { |
+ return handle.isDragging() == expected; |
+ } |
+ })); |
+ } |
+ |
@MediumTest |
@Feature({"TextSelection", "TextInput", "Main"}) |
public void testDragInsertionHandle() throws Throwable { |
@@ -38,15 +76,8 @@ public class InsertionHandleTest extends ContentShellTestBase { |
clickToShowInsertionHandle(); |
- InsertionHandleController ihc = getContentViewCore().getInsertionHandleControllerForTest(); |
- HandleView handle = ihc.getHandleViewForTest(); |
- int initialX = handle.getPositionX(); |
- int initialY = handle.getPositionY(); |
- |
- TouchUtils.dragCompleteView(getInstrumentation(), getContentView(), initialX, DRAG_TO_X, |
- initialY + VERTICAL_OFFSET, DRAG_TO_Y, 5); |
- |
- assertTrue(waitForHandleNear(handle, DRAG_TO_X, DRAG_TO_Y)); |
+ dragHandleTo(DRAG_TO_X, DRAG_TO_Y); |
+ assertWaitForHandleNear(DRAG_TO_X, DRAG_TO_Y); |
// Unselecting should cause the handle to disappear. |
getImeAdapter().unselect(); |
@@ -58,14 +89,15 @@ public class InsertionHandleTest extends ContentShellTestBase { |
(Math.abs(handle.getPositionY() - y) < HANDLE_POSITION_TOLERANCE); |
} |
- private static boolean waitForHandleNear(final HandleView handle, final int x, |
- final int y) throws Throwable { |
- return CriteriaHelper.pollForCriteria(new Criteria() { |
+ private void assertWaitForHandleNear(final int x, final int y) throws Throwable { |
+ InsertionHandleController ihc = getContentViewCore().getInsertionHandleControllerForTest(); |
+ final HandleView handle = ihc.getHandleViewForTest(); |
+ assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
@Override |
public boolean isSatisfied() { |
return isHandleNear(handle, x, y); |
} |
- }); |
+ })); |
} |
private boolean waitForHandleShowingEquals(final boolean shouldBeShowing) |
@@ -138,6 +170,88 @@ public class InsertionHandleTest extends ContentShellTestBase { |
}); |
} |
+ @MediumTest |
+ @Feature({"TextSelection", "TextInput", "Main"}) |
+ public void testDragInsertionHandleInputText() throws Throwable { |
+ startActivityWithTestUrl(INPUT_TEXT_FILENAME); |
+ |
+ DOMUtils.clickNode(this, getContentView(), |
+ new TestCallbackHelperContainer(getContentView()), INPUT_TEXT_ID); |
+ TouchUtils.sleepForDoubleTapTimeout(getInstrumentation()); |
+ DOMUtils.clickNode(this, getContentView(), |
+ new TestCallbackHelperContainer(getContentView()), INPUT_TEXT_ID); |
+ |
+ assertTrue(waitForHandleShowingEquals(true)); |
+ assertWaitForZoomFinished(); |
+ assertTrue(waitForHandleViewStopped()); |
+ |
+ InsertionHandleController ihc = getContentViewCore().getInsertionHandleControllerForTest(); |
+ HandleView handle = ihc.getHandleViewForTest(); |
+ |
+ int initialX = handle.getPositionX(); |
+ int initialY = handle.getPositionY() + VERTICAL_OFFSET; |
+ int dragToX = initialX + 120; |
+ int dragToY = initialY; |
+ dragHandleTo(dragToX, dragToY); |
+ |
+ assertTrue(waitForHandleViewStopped()); |
+ assertWaitForHandleNear(dragToX, initialY); |
+ |
+ TouchUtils.sleepForDoubleTapTimeout(getInstrumentation()); |
+ |
+ initialX = handle.getPositionX(); |
+ initialY = handle.getPositionY() + VERTICAL_OFFSET; |
+ dragToX = initialX - 120; |
+ dragToY = initialY; |
+ dragHandleTo(dragToX, dragToY); |
+ |
+ assertTrue(waitForHandleViewStopped()); |
+ // Vertical drag should not change the y-position. |
+ assertWaitForHandleNear(dragToX, initialY); |
+ } |
+ |
+ @MediumTest |
+ @Feature({"TextSelection", "TextInput", "Main"}) |
+ public void testDragInsertionHandleInputTextOutsideBounds() throws Throwable { |
+ startActivityWithTestUrl(INPUT_TEXT_FILENAME); |
+ |
+ DOMUtils.clickNode(this, getContentView(), |
+ new TestCallbackHelperContainer(getContentView()), INPUT_TEXT_ID); |
+ TouchUtils.sleepForDoubleTapTimeout(getInstrumentation()); |
+ DOMUtils.clickNode(this, getContentView(), |
+ new TestCallbackHelperContainer(getContentView()), INPUT_TEXT_ID); |
+ |
+ assertTrue(waitForHandleShowingEquals(true)); |
+ assertWaitForZoomFinished(); |
+ |
+ InsertionHandleController ihc = getContentViewCore().getInsertionHandleControllerForTest(); |
+ HandleView handle = ihc.getHandleViewForTest(); |
+ |
+ getContentView().zoomReset(); |
+ assertWaitForZoomFinished(); |
+ |
+ // Quickly (i.e. few move events) drag the handle down and to the right. When this happens, |
+ // the handle should stay vertically aligned with the drag position. |
+ int initialX = handle.getPositionX(); |
+ int initialY = handle.getPositionY() + VERTICAL_OFFSET; |
+ int dragToX = initialX; |
+ int dragToY = initialY + 150; |
+ |
+ // A vertical drag should not move the insertion handle. |
+ dragHandleTo(dragToX, dragToY); |
+ assertTrue(waitForHandleViewStopped()); |
+ // TODO(cjhopman): This currently does not work, dragging above or below will snap to the |
+ // beginning/end of the editable. See http://crbug.com/169055 |
+ //assertWaitForHandleNear(initialX, initialY); |
+ |
+ // The input box does not go to the edge of the screen, and neither should the insertion |
+ // handle. |
+ dragToX = getContentView().getWidth(); |
+ dragHandleTo(dragToX, dragToY); |
+ assertTrue(waitForHandleViewStopped()); |
+ assertTrue(handle.getPositionX() < dragToX - 100); |
+ } |
+ |
@Override |
protected void tearDown() throws Exception { |
super.tearDown(); |
@@ -152,10 +266,24 @@ public class InsertionHandleTest extends ContentShellTestBase { |
TouchUtils.singleClickView(getInstrumentation(), getContentView(), INITIAL_CLICK_X, |
INITIAL_CLICK_Y); |
assertTrue(waitForHandleShowingEquals(true)); |
- assertTrue(waitForZoomFinished()); |
+ assertWaitForZoomFinished(); |
+ } |
+ |
+ private void assertWaitForZoomFinished() throws Throwable { |
+ // If the polling interval is too short, slowly zooming may be detected as not zooming. |
+ final int POLLING_INTERVAL = 200; |
+ assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
+ float mScale = -1; |
+ @Override |
+ public boolean isSatisfied() { |
+ float lastScale = mScale; |
+ mScale = getContentView().getScale(); |
+ return mScale == lastScale; |
+ } |
+ }, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL, POLLING_INTERVAL)); |
} |
- private boolean waitForZoomFinished() throws Throwable { |
+ private boolean waitForHandleViewStopped() throws Throwable { |
// If the polling interval is too short, slowly zooming may be detected as not zooming. |
final int POLLING_INTERVAL = 200; |
return CriteriaHelper.pollForCriteria(new Criteria() { |
@@ -170,7 +298,8 @@ public class InsertionHandleTest extends ContentShellTestBase { |
HandleView handle = ihc.getHandleViewForTest(); |
mPositionX = handle.getPositionX(); |
mPositionY = handle.getPositionY(); |
- return mPositionX == lastPositionX && mPositionY == lastPositionY; |
+ return !handle.isDragging() && |
+ mPositionX == lastPositionX && mPositionY == lastPositionY; |
} |
}, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL, POLLING_INTERVAL); |
} |