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

Adding Paste Popup behavior Unit Test cases.

Currently there is not enough unit test cases available to cover
the functionality of Paste Popup menu behavior. This patch covers
essential unit test cases for the same.

These tests originally landed in r293222, but were incidentally reverted
due to some pre-existing test failures in the same file.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#294353}
parent ede7c38b
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
package org.chromium.content.browser; package org.chromium.content.browser;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
...@@ -43,6 +46,7 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase { ...@@ -43,6 +46,7 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
mContentViewCore = getContentViewCore(); mContentViewCore = getContentViewCore();
assertWaitForPageScaleFactorMatch(1.1f); assertWaitForPageScaleFactorMatch(1.1f);
assertWaitForSelectActionBarVisible(false); assertWaitForSelectActionBarVisible(false);
assertWaitForPastePopupStatus(false);
} }
@SmallTest @SmallTest
...@@ -118,6 +122,57 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase { ...@@ -118,6 +122,57 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
assertTrue(mContentViewCore.hasSelection()); assertTrue(mContentViewCore.hasSelection());
} }
@SmallTest
@Feature({"TextInput"})
public void testPastePopupNotShownOnLongPressingNonEmptyInput() throws Throwable {
copyStringToClipboard();
DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text");
assertWaitForPastePopupStatus(true);
DOMUtils.longPressNode(this, mContentViewCore, "input_text");
assertWaitForSelectActionBarVisible(true);
assertWaitForPastePopupStatus(false);
}
@SmallTest
@Feature({"TextInput"})
public void testPastePopupClearedOnTappingEmptyInput() throws Throwable {
copyStringToClipboard();
DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text");
assertWaitForPastePopupStatus(true);
DOMUtils.clickNode(this, mContentViewCore, "empty_input_text");
assertWaitForPastePopupStatus(false);
}
@SmallTest
@Feature({"TextInput"})
public void testPastePopupClearedOnTappingNonEmptyInput() throws Throwable {
copyStringToClipboard();
DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text");
assertWaitForPastePopupStatus(true);
DOMUtils.clickNode(this, mContentViewCore, "input_text");
assertWaitForPastePopupStatus(false);
}
@SmallTest
@Feature({"TextInput"})
public void testPastePopupClearedOnTappingOutsideInput() throws Throwable {
copyStringToClipboard();
DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text");
assertWaitForPastePopupStatus(true);
DOMUtils.clickNode(this, mContentViewCore, "plain_text_2");
assertWaitForPastePopupStatus(false);
}
@SmallTest
@Feature({"TextInput"})
public void testPastePopupClearedOnLongPressingOutsideInput() throws Throwable {
copyStringToClipboard();
DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text");
assertWaitForPastePopupStatus(true);
DOMUtils.longPressNode(this, mContentViewCore, "plain_text_2");
assertWaitForPastePopupStatus(false);
}
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() {
...@@ -165,4 +220,21 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase { ...@@ -165,4 +220,21 @@ public class ContentViewCoreSelectionTest extends ContentShellTestBase {
} }
}); });
} }
private void copyStringToClipboard() {
ClipboardManager clipboardManager =
(ClipboardManager) getActivity().getSystemService(
Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("test", "Text to copy");
clipboardManager.setPrimaryClip(clip);
}
private void assertWaitForPastePopupStatus(final boolean show) throws InterruptedException {
assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
@Override
public boolean isSatisfied() {
return show == mContentViewCore.getPastePopupForTest().isShowing();
}
}));
}
} }
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