Commit b4d47f80 authored by cjhopman@chromium.org's avatar cjhopman@chromium.org

[Android] Add selection handle tests

Add tests for: (all for editable and noneditable text)
Long-press on text shows selection handles.
Dragging selection handle changes selected text.
Single-click dismisses selection handles.
Long-press on text shows ActionMode with correct actions.
Single click dismisses ActionMode.

BUG=155548

Review URL: https://chromiumcodereview.appspot.com/21044008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217056 0039d316-1c4b-4281-b951-d872f2087c98
parent bb43e075
......@@ -285,10 +285,6 @@ public class ContentView extends FrameLayout
mContentViewCore.clearHistory();
}
String getSelectedText() {
return mContentViewCore.getSelectedText();
}
/**
* Start profiling the update speed. You must call {@link #stopFpsProfiling}
* to stop profiling.
......
......@@ -1195,10 +1195,20 @@ import java.util.Map;
if (mNativeContentViewCore != 0) nativeClearHistory(mNativeContentViewCore);
}
String getSelectedText() {
/**
* @return The selected text (empty if no text selected).
*/
public String getSelectedText() {
return mHasSelection ? mLastSelectedText : "";
}
/**
* @return Whether the current selection is editable (false if no text selected).
*/
public boolean isSelectionEditable() {
return mHasSelection ? mSelectionEditable : false;
}
// End FrameLayout overrides.
/**
......@@ -1437,6 +1447,10 @@ import java.util.Map;
}
}
public boolean isSelectActionBarShowing() {
return mActionMode != null;
}
private void resetGestureDetectors() {
mContentViewGestureHandler.resetGestureHandlers();
}
......@@ -2010,10 +2024,16 @@ import java.util.Map;
return mInsertionHandleController;
}
@VisibleForTesting
public InsertionHandleController getInsertionHandleControllerForTest() {
return mInsertionHandleController;
}
@VisibleForTesting
public SelectionHandleController getSelectionHandleControllerForTest() {
return mSelectionHandleController;
}
private void updateHandleScreenPositions() {
if (isSelectionHandleShowing()) {
mSelectionHandleController.setStartHandlePosition(
......
......@@ -16,6 +16,8 @@ import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;
import com.google.common.annotations.VisibleForTesting;
/**
* CursorController for inserting text at the cursor position.
*/
......@@ -108,6 +110,7 @@ public abstract class InsertionHandleController implements CursorController {
return mHandle.getAdjustedPositionY();
}
@VisibleForTesting
public HandleView getHandleViewForTest() {
return mHandle;
}
......
......@@ -6,6 +6,8 @@ package org.chromium.content.browser.input;
import android.view.View;
import com.google.common.annotations.VisibleForTesting;
/**
* CursorController for selecting a range of text.
*/
......@@ -175,6 +177,16 @@ public abstract class SelectionHandleController implements CursorController {
showHandlesIfNeeded();
}
@VisibleForTesting
public HandleView getStartHandleViewForTest() {
return mStartHandle;
}
@VisibleForTesting
public HandleView getEndHandleViewForTest() {
return mEndHandle;
}
private void createHandlesIfNeeded(int startDir, int endDir) {
if (mStartHandle == null) {
mStartHandle = new HandleView(this,
......
......@@ -96,20 +96,4 @@ public class ContentDetectionTestBase extends ContentShellTestBase {
TimeUnit.SECONDS);
getInstrumentation().waitForIdleSync();
}
// TODO(aelias): This method needs to be removed once http://crbug.com/179511 is fixed.
// Meanwhile, we have to wait if the page has the <meta viewport> tag.
/**
* Waits till the ContentViewCore receives the expected page scale factor
* from the compositor and asserts that this happens.
*/
protected void assertWaitForPageScaleFactorMatch(final float expectedScale)
throws InterruptedException {
assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
@Override
public boolean isSatisfied() {
return getContentViewCore().getScale() == expectedScale;
}
}));
}
}
......@@ -63,22 +63,11 @@ public class InsertionHandleTest extends ContentShellTestBase {
private static final int HANDLE_POSITION_TOLERANCE = 20;
private static final String PASTE_TEXT = "**test text to paste**";
// TODO(cjhopman): Due to http://crbug.com/179511, these tests must wait for the ContentViewCore
// to have the correct page scale factor (otherwise clicks will be sent to the wrong
// coordinates). This workaround should be removed when that bug is fixed.
private void assertWaitForPageScaleFactor(final float scale) throws InterruptedException {
assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
@Override
public boolean isSatisfied() {
return getContentViewCore().getScale() == scale;
}
}));
}
public void launchWithUrl(String url) throws Throwable {
super.launchContentShellWithUrl(url);
launchContentShellWithUrl(url);
assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
assertWaitForPageScaleFactor(1);
assertWaitForPageScaleFactorMatch(1.0f);
// The TestInputMethodManagerWrapper intercepts showSoftInput so that a keyboard is never
// brought up.
......
......@@ -185,4 +185,20 @@ public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
callbackHelper.waitForCallback(
currentCallCount, 1, WAIT_PAGE_LOADING_TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
// TODO(aelias): This method needs to be removed once http://crbug.com/179511 is fixed.
// Meanwhile, we have to wait if the page has the <meta viewport> tag.
/**
* Waits till the ContentViewCore receives the expected page scale factor
* from the compositor and asserts that this happens.
*/
protected void assertWaitForPageScaleFactorMatch(final float expectedScale)
throws InterruptedException {
assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
@Override
public boolean isSatisfied() {
return getContentViewCore().getScale() == expectedScale;
}
}));
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment