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

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

Issue 690613003: Adding Unit Test Coverage for Select Action Bar Cut, Paste, Select All options (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added Paste Test cases. Created 6 years, 2 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 | « no previous file | 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/ContentViewCoreSelectionTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ContentViewCoreSelectionTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewCoreSelectionTest.java
index f0044ff970828056ace1bfe3f34a66a2dfeaf0ca..7db83689fd61612027626464997fc0f0507e746b 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/ContentViewCoreSelectionTest.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewCoreSelectionTest.java
@@ -31,10 +31,9 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
+ "<input id=\"empty_input_text\" type=\"text\" />"
+ "<br/><p><span id=\"plain_text_1\">SamplePlainTextOne</span></p>"
+ "<br/><p><span id=\"plain_text_2\">SamplePlainTextTwo</span></p>"
- + "<br/><input id=\"empty_input_text\" type=\"text\" />"
+ "<br/><input id=\"input_text\" type=\"text\" value=\"SampleInputText\" />"
+ "<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\">SampleTextArea</textarea>"
+ "<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=\"input_password\" type=\"password\" value=\"SamplePassword\" />"
@@ -237,6 +236,17 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
@SmallTest
@Feature({"TextInput"})
+ public void testActionBarConfiguredCorrectlyForTextArea() throws Throwable {
+ DOMUtils.longPressNode(this, mContentViewCore, "textarea");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertNotNull(mContentViewCore.getSelectActionHandler());
+ assertTrue(mContentViewCore.getSelectActionHandler().isSelectionEditable());
+ assertFalse(mContentViewCore.getSelectActionHandler().isSelectionPassword());
+ }
+
+ @SmallTest
+ @Feature({"TextInput"})
public void testSelectActionBarPlainTextCopy() throws Exception {
DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1");
assertWaitForSelectActionBarVisible(true);
@@ -276,6 +286,223 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
assertClipboardContents(mContentViewCore.getContext(), "SamplePlainTextOne");
}
+ @SmallTest
+ @Feature({"TextInput"})
+ public void testSelectActionBarTextAreaCopy() throws Exception {
+ DOMUtils.longPressNode(this, mContentViewCore, "textarea");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertNotNull(mContentViewCore.getSelectActionHandler());
+ selectActionBarCopy();
+ assertClipboardContents(mContentViewCore.getContext(), "SampleTextArea");
+ }
+
+ @SmallTest
+ @Feature({"TextSelection"})
+ public void testSelectActionBarPlainTextCut() throws Exception {
+ copyStringToClipboard();
+ DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertEquals(mContentViewCore.getSelectedText(), "SamplePlainTextOne");
+ assertNotNull(mContentViewCore.getSelectActionHandler());
+ selectActionBarCut();
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ // Cut option won't be available for plain text.
+ // Hence validating previous Clipboard content.
+ assertClipboardContents(mContentViewCore.getContext(), "SampleTextToCopy");
+ }
+
+ @SmallTest
+ @Feature({"TextInput"})
+ public void testSelectActionBarInputCut() throws Exception {
+ DOMUtils.longPressNode(this, mContentViewCore, "input_text");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertEquals(mContentViewCore.getSelectedText(), "SampleInputText");
+ assertNotNull(mContentViewCore.getSelectActionHandler());
+ selectActionBarCut();
+ assertWaitForSelectActionBarVisible(false);
+ assertFalse(mContentViewCore.hasSelection());
+ assertClipboardContents(mContentViewCore.getContext(), "SampleInputText");
+ assertEquals(mContentViewCore.getSelectedText(), "");
+ }
+
+ @SmallTest
+ @Feature({"TextInput"})
+ public void testSelectActionBarPasswordCut() throws Exception {
+ copyStringToClipboard();
+ DOMUtils.longPressNode(this, mContentViewCore, "input_password");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertNotNull(mContentViewCore.getSelectActionHandler());
+ selectActionBarCut();
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ // Cut option won't be there for Password, hence no change in Clipboard
+ // Validating with previous Clipboard content
+ assertClipboardContents(mContentViewCore.getContext(), "SampleTextToCopy");
+ }
+
+ @SmallTest
+ @Feature({"TextInput"})
+ public void testSelectActionBarTextAreaCut() throws Exception {
+ DOMUtils.longPressNode(this, mContentViewCore, "textarea");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertEquals(mContentViewCore.getSelectedText(), "SampleTextArea");
+ assertNotNull(mContentViewCore.getSelectActionHandler());
+ selectActionBarCut();
+ assertWaitForSelectActionBarVisible(false);
+ assertFalse(mContentViewCore.hasSelection());
+ assertClipboardContents(mContentViewCore.getContext(), "SampleTextArea");
+ assertEquals(mContentViewCore.getSelectedText(), "");
+ }
+
+ @SmallTest
+ @Feature({"TextSelection"})
+ public void testSelectActionBarPlainTextSelectAll() throws Exception {
+ DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertNotNull(mContentViewCore.getSelectActionHandler());
+ selectActionBarSelectAll();
+ assertTrue(mContentViewCore.hasSelection());
+ assertWaitForSelectActionBarVisible(true);
+ }
+
+ @SmallTest
+ @Feature({"TextInput"})
+ public void testSelectActionBarInputSelectAll() throws Exception {
+ DOMUtils.longPressNode(this, mContentViewCore, "input_text");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertNotNull(mContentViewCore.getSelectActionHandler());
+ selectActionBarSelectAll();
+ assertTrue(mContentViewCore.hasSelection());
+ assertWaitForSelectActionBarVisible(true);
+ assertEquals(mContentViewCore.getSelectedText(), "SampleInputText");
+ }
+
+ @SmallTest
+ @Feature({"TextInput"})
+ public void testSelectActionBarPasswordSelectAll() throws Exception {
+ DOMUtils.longPressNode(this, mContentViewCore, "input_password");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertNotNull(mContentViewCore.getSelectActionHandler());
+ selectActionBarSelectAll();
+ assertTrue(mContentViewCore.hasSelection());
+ assertWaitForSelectActionBarVisible(true);
jdduke (slow) 2014/10/31 17:39:41 Don't you also want to assert that getSelectedText
AKVT 2014/10/31 17:52:09 Actually selected text we can't validate positivel
jdduke (slow) 2014/10/31 17:57:06 Hmm, nah this is OK.
+ }
+
+ @SmallTest
+ @Feature({"TextInput"})
+ public void testSelectActionBarTextAreaSelectAll() throws Exception {
+ DOMUtils.longPressNode(this, mContentViewCore, "textarea");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertNotNull(mContentViewCore.getSelectActionHandler());
+ selectActionBarSelectAll();
+ assertTrue(mContentViewCore.hasSelection());
+ assertWaitForSelectActionBarVisible(true);
+ assertEquals(mContentViewCore.getSelectedText(), "SampleTextArea");
+ }
+
+ @SmallTest
+ @Feature({"TextSelection"})
+ public void testSelectActionBarPlainTextPaste() throws Exception {
+ copyStringToClipboard();
+ DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertNotNull(mContentViewCore.getSelectActionHandler());
+ selectActionBarPaste();
+ DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ // Paste option won't be available for plain text.
+ // Hence content won't be changed.
+ assertNotSame(mContentViewCore.getSelectedText(), "SampleTextToCopy");
+ }
+
+ @SmallTest
+ @Feature({"TextInput"})
+ public void testSelectActionBarInputPaste() throws Exception {
+ copyStringToClipboard();
+ DOMUtils.longPressNode(this, mContentViewCore, "input_text");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertNotNull(mContentViewCore.getSelectActionHandler());
+ selectActionBarPaste();
+ DOMUtils.clickNode(this, mContentViewCore, "plain_text_1");
+ DOMUtils.longPressNode(this, mContentViewCore, "input_text");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertEquals(mContentViewCore.getSelectedText(), "SampleTextToCopy");
+ }
+
+ @SmallTest
+ @Feature({"TextInput"})
+ public void testSelectActionBarPasswordPaste() throws Exception {
+ copyStringToClipboard();
+ DOMUtils.longPressNode(this, mContentViewCore, "input_password");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertNotNull(mContentViewCore.getSelectActionHandler());
+ selectActionBarPaste();
+ // Paste option won't be there for Password, hence no action happens
jdduke (slow) 2014/10/31 17:39:41 This comment is misleading (as are several others)
AKVT 2014/10/31 17:52:09 My intention is even if we call paste, expected ac
+ DOMUtils.clickNode(this, mContentViewCore, "plain_text_1");
+ DOMUtils.longPressNode(this, mContentViewCore, "input_password");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertNotSame(mContentViewCore.getSelectedText(), "SampleTextToCopy");
+ }
+
+ @SmallTest
+ @Feature({"TextInput"})
+ public void testSelectActionBarTextAreaPaste() throws Exception {
+ copyStringToClipboard();
+ DOMUtils.longPressNode(this, mContentViewCore, "textarea");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertNotNull(mContentViewCore.getSelectActionHandler());
+ selectActionBarPaste();
+ DOMUtils.clickNode(this, mContentViewCore, "plain_text_1");
+ DOMUtils.longPressNode(this, mContentViewCore, "textarea");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ assertEquals(mContentViewCore.getSelectedText(), "SampleTextToCopy");
+ }
+
+ private void selectActionBarPaste() {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ mContentViewCore.getSelectActionHandler().paste();
+ }
+ });
+ }
+
+ private void selectActionBarSelectAll() {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ mContentViewCore.getSelectActionHandler().selectAll();
+ }
+ });
+ }
+
+ private void selectActionBarCut() {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ mContentViewCore.getSelectActionHandler().cut();
jdduke (slow) 2014/10/31 17:39:41 The biggest problem I have with these tests is tha
AKVT 2014/10/31 17:52:09 IMO, even though we have a SelectActionModeCallbac
+ }
+ });
+ }
+
private void selectActionBarCopy() {
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
@@ -357,7 +584,7 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
ClipboardManager clipboardManager =
(ClipboardManager) getActivity().getSystemService(
Context.CLIPBOARD_SERVICE);
- ClipData clip = ClipData.newPlainText("test", "Text to copy");
+ ClipData clip = ClipData.newPlainText("test", "SampleTextToCopy");
clipboardManager.setPrimaryClip(clip);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698