Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2792)

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/input/SelectionHandleTest.java

Issue 188023002: Android-side of insertion/selection handles visibility. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed comments + rebased Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/android/javatests/src/org/chromium/content/browser/input/InsertionHandleTest.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/javatests/src/org/chromium/content/browser/input/SelectionHandleTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/input/SelectionHandleTest.java b/content/public/android/javatests/src/org/chromium/content/browser/input/SelectionHandleTest.java
index 08dc1d48a23359bc5a0772bc07862c7dcea2ce14..baaf1aa5e42a662876e3d679cc32f909ecc4c272 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/input/SelectionHandleTest.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/input/SelectionHandleTest.java
@@ -5,6 +5,7 @@
package org.chromium.content.browser.input;
import android.graphics.Point;
+import android.graphics.PointF;
import android.graphics.Rect;
import android.os.SystemClock;
import android.test.FlakyTest;
@@ -29,6 +30,10 @@ import org.chromium.content_shell_apk.ContentShellTestBase;
import java.util.concurrent.Callable;
+/**
+ * Tests for the selection handles that allow to select text in both editable and non-editable
+ * elements.
+ */
public class SelectionHandleTest extends ContentShellTestBase {
private static final String META_DISABLE_ZOOM =
"<meta name=\"viewport\" content=\"" +
@@ -152,6 +157,76 @@ public class SelectionHandleTest extends ContentShellTestBase {
doSelectionHandleTest(TestPageType.EDITABLE);
}
+ /**
+ * Verifies that the visibility of handles is correct when visible clipping
+ * rectangle is set.
+ */
+ @MediumTest
+ @Feature({ "TextSelection" })
+ public void testEditableSelectionHandlesStartNotVisibleEndVisible() throws Throwable {
+ doSelectionHandleTestVisibility(TestPageType.EDITABLE, false, true, new PointF(.5f, .5f),
+ new PointF(0,1));
+ }
+
+ @MediumTest
+ @Feature({ "TextSelection" })
+ public void testEditableSelectionHandlesStartVisibleEndNotVisible() throws Throwable {
+ doSelectionHandleTestVisibility(TestPageType.EDITABLE, true, false, new PointF(1,0),
+ new PointF(.5f, .5f));
+ }
+
+ @MediumTest
+ @Feature({ "TextSelection" })
+ public void testEditableSelectionHandlesStartVisibleEndVisible() throws Throwable {
+ doSelectionHandleTestVisibility(TestPageType.EDITABLE, true, true, new PointF(1, 0),
+ new PointF(0,1));
+ }
+
+ @MediumTest
+ @Feature({ "TextSelection" })
+ public void testEditableSelectionHandlesStartNotVisibleEndNotVisible() throws Throwable {
+ doSelectionHandleTestVisibility(TestPageType.EDITABLE, false, false, new PointF(1,0),
+ new PointF(1, 0));
+ }
+
+ private void doSelectionHandleTestVisibility(TestPageType pageType,
+ boolean startHandleVisible, boolean endHandleVisible,
+ PointF affineTopLeft, PointF affineBottomRight) throws Throwable {
+ launchWithUrl(pageType.dataUrl);
+
+ clickNodeToShowSelectionHandles(pageType.nodeId);
+ assertWaitForSelectionEditableEquals(pageType.selectionShouldBeEditable);
+
+ HandleView startHandle = getStartHandle();
+ HandleView endHandle = getEndHandle();
+
+ Rect nodeWindowBounds = getNodeBoundsPix(pageType.nodeId);
+
+ int visibleBoundsLeftX = Math.round(affineTopLeft.x * nodeWindowBounds.left
+ + affineTopLeft.y * nodeWindowBounds.right);
+ int visibleBoundsTopY = Math.round(affineTopLeft.x * nodeWindowBounds.top
+ + affineTopLeft.y * nodeWindowBounds.bottom);
+
+ int visibleBoundsRightX = Math.round(affineBottomRight.x * nodeWindowBounds.left
+ + affineBottomRight.y * nodeWindowBounds.right);
+ int visibleBoundsBottomY = Math.round(affineBottomRight.x * nodeWindowBounds.top
+ + affineBottomRight.y * nodeWindowBounds.bottom);
+
+ getContentViewCore().getSelectionHandleControllerForTest().setVisibleClippingRectangle(
+ visibleBoundsLeftX, visibleBoundsTopY, visibleBoundsRightX, visibleBoundsBottomY);
+
+ int leftX = (nodeWindowBounds.left + nodeWindowBounds.centerX()) / 2;
+ int rightX = (nodeWindowBounds.right + nodeWindowBounds.centerX()) / 2;
+
+ int topY = (nodeWindowBounds.top + nodeWindowBounds.centerY()) / 2;
+ int bottomY = (nodeWindowBounds.bottom + nodeWindowBounds.centerY()) / 2;
+
+ dragHandleAndCheckSelectionChange(startHandle, leftX, topY, -1, 0, startHandleVisible);
+ dragHandleAndCheckSelectionChange(endHandle, rightX, bottomY, 0, 1, endHandleVisible);
+
+ clickToDismissHandles();
+ }
+
private void doSelectionHandleTest(TestPageType pageType) throws Throwable {
launchWithUrl(pageType.dataUrl);
@@ -172,23 +247,25 @@ public class SelectionHandleTest extends ContentShellTestBase {
int bottomY = (nodeWindowBounds.bottom + nodeWindowBounds.centerY()) / 2;
// Drag start handle up and to the left. The selection start should decrease.
- dragHandleAndCheckSelectionChange(startHandle, leftX, topY, -1, 0);
+ dragHandleAndCheckSelectionChange(startHandle, leftX, topY, -1, 0, true);
// Drag end handle down and to the right. The selection end should increase.
- dragHandleAndCheckSelectionChange(endHandle, rightX, bottomY, 0, 1);
+ dragHandleAndCheckSelectionChange(endHandle, rightX, bottomY, 0, 1, true);
// Drag start handle back to the middle. The selection start should increase.
- dragHandleAndCheckSelectionChange(startHandle, centerX, centerY, 1, 0);
+ dragHandleAndCheckSelectionChange(startHandle, centerX, centerY, 1, 0, true);
// Drag end handle up and to the left past the start handle. Both selection start and end
// should decrease.
- dragHandleAndCheckSelectionChange(endHandle, leftX, topY, -1, -1);
+ dragHandleAndCheckSelectionChange(endHandle, leftX, topY, -1, -1, true);
// Drag start handle down and to the right past the end handle. Both selection start and end
// should increase.
- dragHandleAndCheckSelectionChange(startHandle, rightX, bottomY, 1, 1);
+ dragHandleAndCheckSelectionChange(startHandle, rightX, bottomY, 1, 1, true);
clickToDismissHandles();
}
- private void dragHandleAndCheckSelectionChange(HandleView handle, int dragToX, int dragToY,
- final int expectedStartChange, final int expectedEndChange) throws Throwable {
+ private void dragHandleAndCheckSelectionChange(final HandleView handle,
+ final int dragToX, final int dragToY,
+ final int expectedStartChange, final int expectedEndChange,
+ final boolean expectedHandleVisible) throws Throwable {
String initialText = getContentViewCore().getSelectedText();
final int initialSelectionEnd = getSelectionEnd();
final int initialSelectionStart = getSelectionStart();
@@ -212,6 +289,8 @@ public class SelectionHandleTest extends ContentShellTestBase {
if ((int) Math.signum(endChange) != expectedEndChange) return false;
}
+ if (expectedHandleVisible != handle.isPositionVisible()) return false;
+
return true;
}
}));
« no previous file with comments | « content/public/android/javatests/src/org/chromium/content/browser/input/InsertionHandleTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698