summaryrefslogtreecommitdiffstats
path: root/android_webview/javatests
diff options
context:
space:
mode:
authorhush <hush@chromium.org>2015-06-17 12:52:00 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-17 19:52:25 +0000
commitd6b6b6df86d87905a51b5a97522a8c49887b1bcd (patch)
tree067817b059dd71e7719c561b798167ca483bed54 /android_webview/javatests
parent18bcaf062c839d3f707228c94c393e1bc38d4691 (diff)
downloadchromium_src-d6b6b6df86d87905a51b5a97522a8c49887b1bcd.zip
chromium_src-d6b6b6df86d87905a51b5a97522a8c49887b1bcd.tar.gz
chromium_src-d6b6b6df86d87905a51b5a97522a8c49887b1bcd.tar.bz2
Test text handles appear in Android WebView popups
Also fix some possible flakiness for similar tests in content shell. BUG=437069 Review URL: https://codereview.chromium.org/759363003 Cr-Commit-Position: refs/heads/master@{#334894}
Diffstat (limited to 'android_webview/javatests')
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/PopupWindowTest.java69
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java15
2 files changed, 84 insertions, 0 deletions
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/PopupWindowTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/PopupWindowTest.java
index 16d6b55..3c07e5f 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/PopupWindowTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/PopupWindowTest.java
@@ -11,9 +11,15 @@ import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.test.util.CommonResources;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.MinAndroidSdkLevel;
+import org.chromium.content.browser.ContentViewCore;
+import org.chromium.content.browser.test.util.Criteria;
+import org.chromium.content.browser.test.util.CriteriaHelper;
+import org.chromium.content.browser.test.util.DOMUtils;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
import org.chromium.net.test.util.TestWebServer;
+import java.util.concurrent.Callable;
+
/**
* Tests for pop up window flow.
*/
@@ -84,4 +90,67 @@ public class PopupWindowTest extends AwTestBase {
onPageFinishedHelper.waitForCallback(onPageFinishedCallCount);
assertEquals("about:blank", onPageFinishedHelper.getUrl());
}
+
+ @SmallTest
+ @Feature({"AndroidWebView"})
+ public void testPopupWindowTextHandle() throws Throwable {
+ final String popupPath = "/popup.html";
+ final String parentPageHtml = CommonResources.makeHtmlPageFrom("", "<script>"
+ + "function tryOpenWindow() {"
+ + " var newWindow = window.open('" + popupPath + "');"
+ + "}</script>");
+
+ final String popupPageHtml = CommonResources.makeHtmlPageFrom(
+ "<title>" + POPUP_TITLE + "</title>",
+ "<span id=\"plain_text\" class=\"full_view\">This is a popup window.</span>");
+
+ triggerPopup(mParentContents, mParentContentsClient, mWebServer, parentPageHtml,
+ popupPageHtml, popupPath, "tryOpenWindow()");
+ PopupInfo popupInfo = connectPendingPopup(mParentContents);
+ final AwContents popupContents = popupInfo.popupContents;
+ TestAwContentsClient popupContentsClient = popupInfo.popupContentsClient;
+ assertEquals(POPUP_TITLE, getTitleOnUiThread(popupContents));
+
+ enableJavaScriptOnUiThread(popupContents);
+
+ // Now long press on some texts and see if the text handles show up.
+ DOMUtils.longPressNode(this, popupContents.getContentViewCore(), "plain_text");
+ assertWaitForSelectActionBarStatus(true, popupContents.getContentViewCore());
+ assertTrue(runTestOnUiThreadAndGetResult(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ return popupContents.getContentViewCore().hasSelection();
+ }
+ }));
+
+ // Now hide the select action bar. This should hide the text handles and
+ // clear the selection.
+ hideSelectActionMode(popupContents.getContentViewCore());
+
+ assertWaitForSelectActionBarStatus(false, popupContents.getContentViewCore());
+ String jsGetSelection = "window.getSelection().toString()";
+ // Test window.getSelection() returns empty string "" literally.
+ assertEquals("\"\"", executeJavaScriptAndWaitForResult(
+ popupContents, popupContentsClient, jsGetSelection));
+ }
+
+ // Copied from imeTest.java.
+ private void assertWaitForSelectActionBarStatus(final boolean show, final ContentViewCore cvc)
+ throws InterruptedException {
+ assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return show == cvc.isSelectActionBarShowing();
+ }
+ }));
+ }
+
+ private void hideSelectActionMode(final ContentViewCore cvc) {
+ getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ cvc.hideSelectActionMode();
+ }
+ });
+ }
}
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java b/android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java
index 42e9225..6a6182f 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java
@@ -6,12 +6,17 @@ package org.chromium.android_webview.test;
import android.graphics.Picture;
import android.net.http.SslError;
+import android.view.ActionMode;
+import android.view.View;
import android.webkit.ConsoleMessage;
import android.webkit.ValueCallback;
import org.chromium.android_webview.AwContentsClient.AwWebResourceRequest;
import org.chromium.android_webview.AwWebResourceResponse;
import org.chromium.base.ThreadUtils;
+import org.chromium.content.browser.SelectActionMode;
+import org.chromium.content.browser.SelectActionModeCallback;
+import org.chromium.content.browser.SelectActionModeCallback.ActionHandler;
import org.chromium.content.browser.test.util.CallbackHelper;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageCommitVisibleHelper;
@@ -216,6 +221,16 @@ public class TestAwContentsClient extends NullContentsClient {
mOnReceivedSslErrorHelper.notifyCalled();
}
+ @Override
+ public SelectActionMode startActionMode(
+ View view, ActionHandler actionHandler, boolean floating) {
+ if (floating) return null;
+ ActionMode.Callback callback =
+ new SelectActionModeCallback(view.getContext(), actionHandler);
+ ActionMode actionMode = view.startActionMode(callback);
+ return actionMode != null ? new SelectActionMode(actionMode) : null;
+ }
+
public void setAllowSslError(boolean allow) {
mAllowSslError = allow;
}