Commit 04912389 authored by ajith.v's avatar ajith.v Committed by Commit bot

Add text selection ActionBar tests

Currently there is insufficient coverage for text selection ActionBar
menu interaction. Add several basic tests covering such functionality.

Review URL: https://codereview.chromium.org/538103003

Cr-Commit-Position: refs/heads/master@{#301408}
parent ccf0a3a1
...@@ -283,6 +283,7 @@ public class ContentViewCore ...@@ -283,6 +283,7 @@ public class ContentViewCore
private ActionMode mActionMode; private ActionMode mActionMode;
private boolean mUnselectAllOnActionModeDismiss; private boolean mUnselectAllOnActionModeDismiss;
private boolean mPreserveSelectionOnNextLossOfFocus; private boolean mPreserveSelectionOnNextLossOfFocus;
private SelectActionModeCallback.ActionHandler mActionHandler;
// Delegate that will handle GET downloads, and be notified of completion of POST downloads. // Delegate that will handle GET downloads, and be notified of completion of POST downloads.
private ContentViewDownloadDelegate mDownloadDelegate; private ContentViewDownloadDelegate mDownloadDelegate;
...@@ -562,8 +563,8 @@ public class ContentViewCore ...@@ -562,8 +563,8 @@ public class ContentViewCore
@Override @Override
public void onReceiveResult(int resultCode, Bundle resultData) { public void onReceiveResult(int resultCode, Bundle resultData) {
getContentViewClient().onImeStateChangeRequested( getContentViewClient().onImeStateChangeRequested(
resultCode == InputMethodManager.RESULT_SHOWN || resultCode == InputMethodManager.RESULT_SHOWN
resultCode == InputMethodManager.RESULT_UNCHANGED_SHOWN); || resultCode == InputMethodManager.RESULT_UNCHANGED_SHOWN);
if (resultCode == InputMethodManager.RESULT_SHOWN) { if (resultCode == InputMethodManager.RESULT_SHOWN) {
// If OSK is newly shown, delay the form focus until // If OSK is newly shown, delay the form focus until
// the onSizeChanged (in order to adjust relative to the // the onSizeChanged (in order to adjust relative to the
...@@ -572,8 +573,8 @@ public class ContentViewCore ...@@ -572,8 +573,8 @@ public class ContentViewCore
// always be called, crbug.com/294908. // always be called, crbug.com/294908.
getContainerView().getWindowVisibleDisplayFrame( getContainerView().getWindowVisibleDisplayFrame(
mFocusPreOSKViewportRect); mFocusPreOSKViewportRect);
} else if (hasFocus() && resultCode == } else if (hasFocus() && resultCode
InputMethodManager.RESULT_UNCHANGED_SHOWN) { == InputMethodManager.RESULT_UNCHANGED_SHOWN) {
// If the OSK was already there, focus the form immediately. // If the OSK was already there, focus the form immediately.
assert mWebContents != null; assert mWebContents != null;
mWebContents.scrollFocusedEditableNodeIntoView(); mWebContents.scrollFocusedEditableNodeIntoView();
...@@ -1731,6 +1732,11 @@ public class ContentViewCore ...@@ -1731,6 +1732,11 @@ public class ContentViewCore
return mDownloadDelegate; return mDownloadDelegate;
} }
@VisibleForTesting
public SelectActionModeCallback.ActionHandler getSelectActionHandler() {
return mActionHandler;
}
private void showSelectActionBar() { private void showSelectActionBar() {
if (mActionMode != null) { if (mActionMode != null) {
mActionMode.invalidate(); mActionMode.invalidate();
...@@ -1738,8 +1744,8 @@ public class ContentViewCore ...@@ -1738,8 +1744,8 @@ public class ContentViewCore
} }
// Start a new action mode with a SelectActionModeCallback. // Start a new action mode with a SelectActionModeCallback.
SelectActionModeCallback.ActionHandler actionHandler = if (mActionHandler == null) {
new SelectActionModeCallback.ActionHandler() { mActionHandler = new SelectActionModeCallback.ActionHandler() {
@Override @Override
public void selectAll() { public void selectAll() {
mImeAdapter.selectAll(); mImeAdapter.selectAll();
...@@ -1845,12 +1851,13 @@ public class ContentViewCore ...@@ -1845,12 +1851,13 @@ public class ContentViewCore
PackageManager.MATCH_DEFAULT_ONLY).size() > 0; PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
} }
}; };
}
mActionMode = null; mActionMode = null;
// On ICS, startActionMode throws an NPE when getParent() is null. // On ICS, startActionMode throws an NPE when getParent() is null.
if (mContainerView.getParent() != null) { if (mContainerView.getParent() != null) {
assert mWebContents != null; assert mWebContents != null;
mActionMode = mContainerView.startActionMode( mActionMode = mContainerView.startActionMode(
getContentViewClient().getSelectActionModeCallback(getContext(), actionHandler, getContentViewClient().getSelectActionModeCallback(getContext(), mActionHandler,
mWebContents.isIncognito())); mWebContents.isIncognito()));
} }
mUnselectAllOnActionModeDismiss = true; mUnselectAllOnActionModeDismiss = true;
...@@ -2528,10 +2535,9 @@ public class ContentViewCore ...@@ -2528,10 +2535,9 @@ public class ContentViewCore
return mBrowserAccessibilityManager.getAccessibilityNodeProvider(); return mBrowserAccessibilityManager.getAccessibilityNodeProvider();
} }
if (mNativeAccessibilityAllowed && if (mNativeAccessibilityAllowed && !mNativeAccessibilityEnabled
!mNativeAccessibilityEnabled && && mNativeContentViewCore != 0
mNativeContentViewCore != 0 && && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mNativeAccessibilityEnabled = true; mNativeAccessibilityEnabled = true;
nativeSetAccessibilityEnabled(mNativeContentViewCore, true); nativeSetAccessibilityEnabled(mNativeContentViewCore, true);
} }
...@@ -2579,8 +2585,8 @@ public class ContentViewCore ...@@ -2579,8 +2585,8 @@ public class ContentViewCore
try { try {
// On JellyBean and higher, native accessibility is the default so script // On JellyBean and higher, native accessibility is the default so script
// injection is only allowed if enabled via a flag. // injection is only allowed if enabled via a flag.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
!CommandLine.getInstance().hasSwitch( && !CommandLine.getInstance().hasSwitch(
ContentSwitches.ENABLE_ACCESSIBILITY_SCRIPT_INJECTION)) { ContentSwitches.ENABLE_ACCESSIBILITY_SCRIPT_INJECTION)) {
return false; return false;
} }
......
...@@ -22,19 +22,20 @@ import org.chromium.content_shell_apk.ContentShellTestBase; ...@@ -22,19 +22,20 @@ import org.chromium.content_shell_apk.ContentShellTestBase;
*/ */
public class ContentViewCoreSelectionTest extends ContentShellTestBase { public class ContentViewCoreSelectionTest extends ContentShellTestBase {
private static final String DATA_URL = UrlUtils.encodeHtmlDataUri( private static final String DATA_URL = UrlUtils.encodeHtmlDataUri(
"<html><head><meta name=\"viewport\"" + "<html><head><meta name=\"viewport\""
"content=\"width=device-width, initial-scale=1.1, maximum-scale=1.5\" /></head>" + + "content=\"width=device-width, initial-scale=1.1, maximum-scale=1.5\" /></head>"
"<body><form action=\"about:blank\">" + + "<body><form action=\"about:blank\">"
"<input id=\"empty_input_text\" type=\"text\" />" + + "<input id=\"empty_input_text\" type=\"text\" />"
"<br/><p><span id=\"plain_text_1\">This is Plain Text One</span></p>" + + "<br/><p><span id=\"plain_text_1\">This is Plain Text One</span></p>"
"<br/><p><span id=\"plain_text_2\">This is Plain Text Two</span></p>" + + "<br/><p><span id=\"plain_text_2\">This is Plain Text Two</span></p>"
"<br/><input id=\"empty_input_text\" type=\"text\" />" + + "<br/><input id=\"empty_input_text\" type=\"text\" />"
"<br/><input id=\"input_text\" type=\"text\" value=\"Sample Text\" />" + + "<br/><input id=\"input_text\" type=\"text\" value=\"Sample Text\" />"
"<br/><textarea id=\"empty_textarea\" rows=\"2\" cols=\"20\"></textarea>" + + "<br/><textarea id=\"empty_textarea\" rows=\"2\" cols=\"20\"></textarea>"
"<br/><textarea id=\"textarea\" rows=\"2\" cols=\"20\">Sample Text</textarea>" + + "<br/><textarea id=\"textarea\" rows=\"2\" cols=\"20\">Sample Text</textarea>"
"<br/><input id=\"readonly_text\" type=\"text\" readonly value=\"Sample Text\"/>" + + "<br/><input id=\"readonly_text\" type=\"text\" readonly value=\"Sample Text\"/>"
"<br/><input id=\"disabled_text\" type=\"text\" disabled value=\"Sample Text\" />" + + "<br/><input id=\"disabled_text\" type=\"text\" disabled value=\"Sample Text\" />"
"</form></body></html>"); + "<br/><input id=\"input_password\" type=\"password\" value=\"Sample Password\" />"
+ "</form></body></html>");
private ContentViewCore mContentViewCore; private ContentViewCore mContentViewCore;
...@@ -199,6 +200,28 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase { ...@@ -199,6 +200,28 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
assertFalse(mContentViewCore.hasInsertion()); assertFalse(mContentViewCore.hasInsertion());
} }
@SmallTest
@Feature({"TextInput"})
public void testActionBarConfiguredCorrectlyForInput() throws Throwable {
DOMUtils.longPressNode(this, mContentViewCore, "input_text");
assertWaitForSelectActionBarVisible(true);
assertTrue(mContentViewCore.hasSelection());
assertNotNull(mContentViewCore.getSelectActionHandler());
assertTrue(mContentViewCore.getSelectActionHandler().isSelectionEditable());
assertFalse(mContentViewCore.getSelectActionHandler().isSelectionPassword());
}
@SmallTest
@Feature({"TextInput"})
public void testActionBarConfiguredCorrectlyForPassword() throws Throwable {
DOMUtils.longPressNode(this, mContentViewCore, "input_password");
assertWaitForSelectActionBarVisible(true);
assertTrue(mContentViewCore.hasSelection());
assertNotNull(mContentViewCore.getSelectActionHandler());
assertTrue(mContentViewCore.getSelectActionHandler().isSelectionEditable());
assertTrue(mContentViewCore.getSelectActionHandler().isSelectionPassword());
}
private void assertWaitForSelectActionBarVisible( private void assertWaitForSelectActionBarVisible(
final boolean visible) throws InterruptedException { final boolean visible) throws InterruptedException {
assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
......
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