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

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

Issue 24449007: [Android] Allow text handles to observe position of "parent" view (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 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
Index: content/public/android/javatests/src/org/chromium/content/browser/input/SelectionHandleUnitTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/input/SelectionHandleUnitTest.java b/content/public/android/javatests/src/org/chromium/content/browser/input/SelectionHandleUnitTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..6340d9fcbf11cfb735e4c37d555351bab867283e
--- /dev/null
+++ b/content/public/android/javatests/src/org/chromium/content/browser/input/SelectionHandleUnitTest.java
@@ -0,0 +1,235 @@
+// Copyright 2013 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.input;
+
+import android.content.Context;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.view.View;
+
+import java.util.HashSet;
+
+import org.chromium.base.test.util.Feature;
+import org.chromium.content.browser.PositionObserverInterface;
+
+/**
+ * Test suite for Selection handles.
+ */
+public class SelectionHandleUnitTest extends AndroidTestCase {
+ public class FakeHandleViewDelegate implements HandleView.Delegate {
+ public Context getContext() {
+ return SelectionHandleUnitTest.this.getContext();
+ }
+
+ public boolean isPositionVisible(int x, int y) {
+ return true;
+ }
+
+ public void dismissContainer() {
+ }
+
+ public boolean isContainerShowing() {
+ return true;
+ }
+
+ public void showContainerAtPosition(View view, int x, int y) {
+ mContainerPositionX = x;
+ mContainerPositionY = y;
+ }
+
+ public void updateContainerPosition(int x, int y, int width, int height) {
+ mContainerPositionX = x;
+ mContainerPositionY = y;
+ }
+
+ public int getPositionX() {
+ return mContainerPositionX;
Ted C 2013/10/10 18:16:32 indent is off
+ }
+
+ public int getPositionY() {
+ return mContainerPositionY;
Ted C 2013/10/10 18:16:32 here too
+ }
+
+ private int mContainerPositionX;
Ted C 2013/10/10 18:16:32 member variables at the top
+ private int mContainerPositionY;
+ }
+
+ public class FakePositionObserver implements PositionObserverInterface {
+ FakePositionObserver() {
+ mListeners = new HashSet<Listener>();
+ }
+
+ public int getPositionX() {
+ return mX;
+ }
+
+ public int getPositionY() {
+ return mY;
+ }
+
+ public void addListener(Listener listener) {
+ mListeners.add(listener);
+ }
+
+ public void removeListener(Listener listener) {
+ mListeners.remove(listener);
+ }
+
+ public void moveTo(int x, int y) {
+ mX = x;
+ mY = y;
+ for (Listener l : mListeners) {
+ l.onPositionChanged(x, y);
+ }
+ }
+
+ private int mX;
Ted C 2013/10/10 18:16:32 same
+ private int mY;
+ private HashSet<Listener> mListeners;
+ }
+
+ private interface SelectBetweenCoordinatesCallback {
+ public void Run(int x1, int y1, int x2, int y2);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ mFakePositionObserver = new FakePositionObserver();
+ mStartHandleDelegate = new FakeHandleViewDelegate();
+ mEndHandleDelegate = new FakeHandleViewDelegate();
+ mSelectBetweenCoordinatesCallback = null;
+ mController = new SelectionHandleController(
+ mStartHandleDelegate, mEndHandleDelegate, mFakePositionObserver) {
+ @Override
+ public void selectBetweenCoordinates(int x1, int y1, int x2, int y2) {
+ if (mSelectBetweenCoordinatesCallback != null) {
+ mSelectBetweenCoordinatesCallback.Run(x1, y1, x2, y2);
+ }
+ }
+ };
+ }
+
+ /**
+ * Verifies that selection handles are shown when selection changes if allowAutomaticShowing
+ * has been called and that they are not shown if hideAndDisallowAutomaticShowing was called.
+ *
+ * Also verifies that they are shown at the expected position.
+ */
+ @SmallTest
+ @Feature({ "TextSelection" })
+ public void testShowSelectionHandles() throws Throwable {
+ mController.hideAndDisallowAutomaticShowing();
+ assertFalse(mController.isShowing());
+
+ int startHandleX = 10;
+ int startHandleY = 20;
+ int endHandleX = 30;
+ int endHandleY = 40;
+
+ mController.onSelectionChanged(1, 1);
+ assertFalse(mController.isShowing());
+
+ mController.allowAutomaticShowing();
+ mController.onSelectionChanged(1, 1);
+ assertTrue(mController.isShowing());
+
+ mController.setStartHandlePosition(startHandleX, startHandleY);
+ mController.setEndHandlePosition(endHandleX, endHandleY);
+
+ assertEquals(startHandleX, getStartHandlePositionX());
+ assertEquals(startHandleY, getStartHandlePositionY());
+ assertEquals(endHandleX, getEndHandlePositionX());
+ assertEquals(endHandleY, getEndHandlePositionY());
+ }
+
+ /**
+ * Verifies that the selection handle positions are updated as expected when the observed
+ * position (i.e. of the containing view) is changed.
+ */
+ @SmallTest
+ @Feature({ "TextSelection" })
+ public void testMoveSelectionHandleContainer() throws Throwable {
+ mController.allowAutomaticShowing();
+
+ int startHandleX = 10;
+ int startHandleY = 20;
+ int endHandleX = 30;
+ int endHandleY = 40;
+
+ mController.onSelectionChanged(1, 1);
+ mController.setStartHandlePosition(startHandleX, startHandleY);
+ mController.setEndHandlePosition(endHandleX, endHandleY);
+
+ assertTrue(mController.isShowing());
+
+ int containerPositionX = 0;
+ int containerPositionY = 0;
+
+ int previousStartHandleDelegatePositionX = mStartHandleDelegate.getPositionX();
+ int previousStartHandleDelegatePositionY = mStartHandleDelegate.getPositionY();
+ int previousEndHandleDelegatePositionX = mEndHandleDelegate.getPositionX();
+ int previousEndHandleDelegatePositionY = mEndHandleDelegate.getPositionY();
+
+ assertEquals(startHandleX, getStartHandlePositionX());
+ assertEquals(startHandleY, getStartHandlePositionY());
+ assertEquals(endHandleX, getEndHandlePositionX());
+ assertEquals(endHandleY, getEndHandlePositionY());
+
+ containerPositionX = 20;
+ containerPositionY = 30;
+
+ mFakePositionObserver.moveTo(containerPositionX, containerPositionY);
+
+ assertEquals(startHandleX + containerPositionX, getStartHandlePositionX());
+ assertEquals(startHandleY + containerPositionY, getStartHandlePositionY());
+ assertEquals(endHandleX + containerPositionX, getEndHandlePositionX());
+ assertEquals(endHandleY + containerPositionY, getEndHandlePositionY());
+
+
+ // Check that the handle has updated the position of the container in the delegate by the
+ // movement in the position observer.
+ assertEquals(previousStartHandleDelegatePositionX + containerPositionX,
+ mStartHandleDelegate.getPositionX());
Ted C 2013/10/10 18:16:32 +4 indent on all of these
+ assertEquals(previousStartHandleDelegatePositionY + containerPositionY,
+ mStartHandleDelegate.getPositionY());
+ assertEquals(previousEndHandleDelegatePositionX + containerPositionX,
+ mEndHandleDelegate.getPositionX());
+ assertEquals(previousEndHandleDelegatePositionY + containerPositionY,
+ mEndHandleDelegate.getPositionY());
+ }
+
+ private int getStartHandlePositionX() {
+ return getStartHandle().getRootViewRelativePositionX();
Ted C 2013/10/10 18:16:32 the next 4 methods need an extra +2 indent on thei
+ }
+
+ private int getStartHandlePositionY() {
+ return getStartHandle().getRootViewRelativePositionY();
+ }
+
+ private int getEndHandlePositionX() {
+ return getEndHandle().getRootViewRelativePositionX();
+ }
+
+ private int getEndHandlePositionY() {
+ return getEndHandle().getRootViewRelativePositionY();
+ }
+
+ private HandleView getStartHandle() {
+ return mController.getStartHandleViewForTest();
+ }
+
+ private HandleView getEndHandle() {
+ return mController.getEndHandleViewForTest();
+ }
+
+ private SelectBetweenCoordinatesCallback mSelectBetweenCoordinatesCallback;
+ private FakePositionObserver mFakePositionObserver;
Ted C 2013/10/10 18:16:32 to the top here as well
+ private FakeHandleViewDelegate mStartHandleDelegate;
+ private FakeHandleViewDelegate mEndHandleDelegate;
+ private SelectionHandleController mController;
+
+}
+

Powered by Google App Engine
This is Rietveld 408576698