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

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

Issue 516523003: [Android] Preserve selection on hide/detach (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review Created 6 years, 3 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 | « content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java ('k') | 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
new file mode 100644
index 0000000000000000000000000000000000000000..ede2cddb1e932e0930a8e41d917b37084ef50473
--- /dev/null
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewCoreSelectionTest.java
@@ -0,0 +1,168 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.content.browser;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.test.util.Feature;
+import org.chromium.base.test.util.UrlUtils;
+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_shell_apk.ContentShellTestBase;
+
+/**
+ * Integration tests for text selection-related behavior.
+ */
+public class ContentViewCoreSelectionTest extends ContentShellTestBase {
+ private static final String DATA_URL = UrlUtils.encodeHtmlDataUri(
+ "<html><head><meta name=\"viewport\"" +
+ "content=\"width=device-width, initial-scale=1.1, maximum-scale=1.5\" /></head>" +
+ "<body><form action=\"about:blank\">" +
+ "<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_2\">This is Plain Text Two</span></p>" +
+ "<br/><input id=\"empty_input_text\" type=\"text\" />" +
+ "<br/><input id=\"input_text\" type=\"text\" value=\"Sample Text\" />" +
+ "<br/><textarea id=\"empty_textarea\" rows=\"2\" cols=\"20\"></textarea>" +
+ "<br/><textarea id=\"textarea\" rows=\"2\" cols=\"20\">Sample Text</textarea>" +
+ "</form></body></html>");
+
+ private ContentViewCore mContentViewCore;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ launchContentShellWithUrl(DATA_URL);
+ assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
+
+ mContentViewCore = getContentViewCore();
+ assertWaitForPageScaleFactorMatch(1.1f);
+ assertWaitForSelectActionBarVisible(false);
+ }
+
+ @SmallTest
+ @Feature({"TextSelection"})
+ public void testSelectionClearedAfterLossOfFocus() throws Throwable {
+ requestFocusOnUiThread(true);
+
+ DOMUtils.longPressNode(this, mContentViewCore, "textarea");
+ assertWaitForSelectActionBarVisible(true);
+
+ requestFocusOnUiThread(false);
+ assertWaitForSelectActionBarVisible(false);
+ assertFalse(mContentViewCore.hasSelection());
+
+ requestFocusOnUiThread(true);
+ assertWaitForSelectActionBarVisible(false);
+ assertFalse(mContentViewCore.hasSelection());
+ }
+
+ @SmallTest
+ @Feature({"TextSelection"})
+ public void testSelectionPreservedAfterLossOfFocusIfRequested() throws Throwable {
+ requestFocusOnUiThread(true);
+
+ DOMUtils.longPressNode(this, mContentViewCore, "textarea");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+
+ mContentViewCore.preserveSelectionOnNextLossOfFocus();
+ requestFocusOnUiThread(false);
+ assertWaitForSelectActionBarVisible(false);
+ assertTrue(mContentViewCore.hasSelection());
+
+ requestFocusOnUiThread(true);
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+
+ // Losing focus yet again should properly clear the selection.
+ requestFocusOnUiThread(false);
+ assertWaitForSelectActionBarVisible(false);
+ assertFalse(mContentViewCore.hasSelection());
+ }
+
+ @SmallTest
+ @Feature({"TextSelection"})
+ public void testSelectionPreservedAfterReshown() throws Throwable {
+ DOMUtils.longPressNode(this, mContentViewCore, "textarea");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+
+ setVisibileOnUiThread(false);
+ assertWaitForSelectActionBarVisible(false);
+ assertTrue(mContentViewCore.hasSelection());
+
+ setVisibileOnUiThread(true);
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ }
+
+ @SmallTest
+ @Feature({"TextSelection"})
+ public void testSelectionPreservedAfterReattached() throws Throwable {
+ DOMUtils.longPressNode(this, mContentViewCore, "textarea");
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+
+ setAttachedOnUiThread(false);
+ assertWaitForSelectActionBarVisible(false);
+ assertTrue(mContentViewCore.hasSelection());
+
+ setAttachedOnUiThread(true);
+ assertWaitForSelectActionBarVisible(true);
+ assertTrue(mContentViewCore.hasSelection());
+ }
+
+ private void assertWaitForSelectActionBarVisible(
+ final boolean visible) throws InterruptedException {
+ assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return visible == mContentViewCore.isSelectActionBarShowing();
+ }
+ }));
+ }
+
+ private void setVisibileOnUiThread(final boolean show) {
+ final ContentViewCore contentViewCore = mContentViewCore;
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ if (show) {
+ contentViewCore.onShow();
+ } else {
+ contentViewCore.onHide();
+ }
+ }
+ });
+ }
+
+ private void setAttachedOnUiThread(final boolean attached) {
+ final ContentViewCore contentViewCore = mContentViewCore;
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ if (attached) {
+ contentViewCore.onAttachedToWindow();
+ } else {
+ contentViewCore.onDetachedFromWindow();
+ }
+ }
+ });
+ }
+
+ private void requestFocusOnUiThread(final boolean gainFocus) {
+ final ContentViewCore contentViewCore = mContentViewCore;
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ contentViewCore.onFocusChanged(gainFocus);
+ }
+ });
+ }
+}
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698