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

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: Rearranged the HTML to escape from flaky failure. 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..2d26287b6079c618fa9423cd9190b811a11820f5 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,13 +31,12 @@ 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=\"input_password\" type=\"password\" value=\"SamplePassword\" />"
+ "<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\" />"
+ "</form></body></html>");
private ContentViewCore mContentViewCore;
@@ -130,7 +129,7 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
@SmallTest
@Feature({"TextInput"})
public void testPastePopupNotShownOnLongPressingNonEmptyInput() throws Throwable {
- copyStringToClipboard();
+ copyStringToClipboard("SampleTextToCopy");
DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text");
assertWaitForPastePopupStatus(true);
DOMUtils.longPressNode(this, mContentViewCore, "input_text");
@@ -141,7 +140,7 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
@SmallTest
@Feature({"TextInput"})
public void testPastePopupClearedOnTappingEmptyInput() throws Throwable {
- copyStringToClipboard();
+ copyStringToClipboard("SampleTextToCopy");
DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text");
assertWaitForPastePopupStatus(true);
DOMUtils.clickNode(this, mContentViewCore, "empty_input_text");
@@ -151,7 +150,7 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
@SmallTest
@Feature({"TextInput"})
public void testPastePopupClearedOnTappingNonEmptyInput() throws Throwable {
- copyStringToClipboard();
+ copyStringToClipboard("SampleTextToCopy");
DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text");
assertWaitForPastePopupStatus(true);
DOMUtils.clickNode(this, mContentViewCore, "input_text");
@@ -161,7 +160,7 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
@SmallTest
@Feature({"TextInput"})
public void testPastePopupClearedOnTappingOutsideInput() throws Throwable {
- copyStringToClipboard();
+ copyStringToClipboard("SampleTextToCopy");
DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text");
assertWaitForPastePopupStatus(true);
DOMUtils.clickNode(this, mContentViewCore, "plain_text_2");
@@ -171,7 +170,7 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
@SmallTest
@Feature({"TextInput"})
public void testPastePopupClearedOnLongPressingOutsideInput() throws Throwable {
- copyStringToClipboard();
+ copyStringToClipboard("SampleTextToCopy");
DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text");
assertWaitForPastePopupStatus(true);
DOMUtils.longPressNode(this, mContentViewCore, "plain_text_2");
@@ -181,7 +180,7 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
@SmallTest
@Feature({"TextInput"})
public void testPastePopupNotShownOnLongPressingReadOnlyInput() throws Throwable {
- copyStringToClipboard();
+ copyStringToClipboard("SampleTextToCopy");
DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text");
assertWaitForPastePopupStatus(true);
assertTrue(mContentViewCore.hasInsertion());
@@ -193,7 +192,7 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
@SmallTest
@Feature({"TextInput"})
public void testPastePopupNotShownOnLongPressingDisabledInput() throws Throwable {
- copyStringToClipboard();
+ copyStringToClipboard("SampleTextToCopy");
DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text");
assertWaitForPastePopupStatus(true);
assertTrue(mContentViewCore.hasInsertion());
@@ -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("SampleTextToCopy");
+ 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("SampleTextToCopy");
+ 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);
+ }
+
+ @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("SampleTextToCopy");
+ 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("SampleTextToCopy");
+ 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("SampleTextToCopy");
+ 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
jdduke1 2014/11/03 17:39:33 Why can't you paste into a password field? That se
AKVT 2014/11/03 19:24:53 Right. The comment line was misleading. We will ha
+ 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("SampleTextToCopy");
+ 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();
+ }
+ });
+ }
+
private void selectActionBarCopy() {
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
@@ -353,11 +580,11 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
});
}
- private void copyStringToClipboard() {
+ private void copyStringToClipboard(String string) {
ClipboardManager clipboardManager =
(ClipboardManager) getActivity().getSystemService(
Context.CLIPBOARD_SERVICE);
- ClipData clip = ClipData.newPlainText("test", "Text to copy");
+ ClipData clip = ClipData.newPlainText("test", string);
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