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

Unified Diff: ui/touch_selection/touch_selection_controller_unittest.cc

Issue 1102933003: [Contextual Search] Add support for tap on the selection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unit tests. Created 5 years, 7 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: ui/touch_selection/touch_selection_controller_unittest.cc
diff --git a/ui/touch_selection/touch_selection_controller_unittest.cc b/ui/touch_selection/touch_selection_controller_unittest.cc
index 22059588abd45c65a02b3ab6a58d1c6100edd77d..4170dd6aa68a82a557ba3e0cd87b6d7619862816 100644
--- a/ui/touch_selection/touch_selection_controller_unittest.cc
+++ b/ui/touch_selection/touch_selection_controller_unittest.cc
@@ -19,6 +19,7 @@ namespace {
const int kDefaultTapTimeoutMs = 200;
const float kDefaulTapSlop = 10.f;
+const gfx::PointF kIgnoredPoint(0, 0);
class MockTouchHandleDrawable : public TouchHandleDrawable {
public:
@@ -145,6 +146,24 @@ class TouchSelectionControllerTest : public testing::Test,
controller_->OnSelectionBoundsChanged(start_bound, end_bound);
}
+ void ChangeSelectionToFiveFiftyTen() {
+ gfx::RectF start_rect(5, 5, 0, 10);
+ gfx::RectF end_rect(50, 5, 0, 10);
+ bool visible = false;
+
+ // Establish a selection without handles.
+ ChangeSelection(start_rect, visible, end_rect, visible);
+ EXPECT_THAT(GetAndResetEvents(), IsEmpty());
+ }
+
+ void OnLongPressEvent() {
+ ASSERT_FALSE(controller().WillHandleLongPressEvent(kIgnoredPoint));
+ }
+
+ void OnTapEvent() {
+ ASSERT_FALSE(controller().WillHandleTapEvent(kIgnoredPoint));
+ }
+
void Animate() {
base::TimeTicks now = base::TimeTicks::Now();
while (needs_animate_) {
@@ -215,14 +234,14 @@ TEST_F(TouchSelectionControllerTest, InsertionBasic) {
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), IsEmpty());
EXPECT_EQ(gfx::PointF(), GetLastEventStart());
- controller().OnTapEvent();
+ OnTapEvent();
// Insertion events are ignored until the selection region is marked editable.
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), IsEmpty());
EXPECT_EQ(gfx::PointF(), GetLastEventStart());
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
@@ -245,7 +264,7 @@ TEST_F(TouchSelectionControllerTest, InsertionBasic) {
TEST_F(TouchSelectionControllerTest, InsertionClearedWhenNoLongerEditable) {
gfx::RectF insertion_rect(5, 5, 0, 10);
bool visible = true;
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
ChangeInsertion(insertion_rect, visible);
@@ -263,13 +282,13 @@ TEST_F(TouchSelectionControllerTest, InsertionWithNoShowOnTapForEmptyEditable) {
// Taps on an empty editable region should be ignored if the controller is
// created with |show_on_tap_for_empty_editable| set to false.
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEmpty(true);
ChangeInsertion(insertion_rect, visible);
EXPECT_EQ(gfx::PointF(), GetLastEventStart());
// Once the region becomes non-empty, taps should show the insertion handle.
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEmpty(false);
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
@@ -281,14 +300,14 @@ TEST_F(TouchSelectionControllerTest, InsertionWithNoShowOnTapForEmptyEditable) {
// Long-pressing should show the handle even if the editable region is empty.
insertion_rect.Offset(2, -2);
- controller().OnLongPressEvent();
+ OnLongPressEvent();
controller().OnSelectionEmpty(true);
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart());
// Single Tap on an empty edit field should clear insertion handle.
- controller().OnTapEvent();
+ OnTapEvent();
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED));
}
@@ -301,14 +320,14 @@ TEST_F(TouchSelectionControllerTest, InsertionWithShowOnTapForEmptyEditable) {
// Taps on an empty editable region should show the insertion handle if the
// controller is created with |show_on_tap_for_empty_editable| set to true.
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEmpty(true);
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart());
// Additional taps should not hide the insertion handle in this case.
- controller().OnTapEvent();
+ OnTapEvent();
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), IsEmpty());
}
@@ -318,7 +337,7 @@ TEST_F(TouchSelectionControllerTest, InsertionAppearsAfterTapFollowingTyping) {
bool visible = true;
// Simulate the user tapping an empty text field.
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
controller().OnSelectionEmpty(true);
ChangeInsertion(insertion_rect, visible);
@@ -332,14 +351,14 @@ TEST_F(TouchSelectionControllerTest, InsertionAppearsAfterTapFollowingTyping) {
// If the user taps the *same* position as the cursor at the end of the text
// entry, the handle should appear.
- controller().OnTapEvent();
+ OnTapEvent();
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart());
}
TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) {
- controller().OnLongPressEvent();
+ OnLongPressEvent();
controller().OnSelectionEditable(true);
gfx::RectF start_rect(5, 5, 0, 10);
@@ -363,7 +382,7 @@ TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) {
controller().HideAndDisallowShowingAutomatically();
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED));
- controller().OnTapEvent();
+ OnTapEvent();
ChangeInsertion(end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
EXPECT_EQ(end_rect.bottom_left(), GetLastEventStart());
@@ -371,7 +390,7 @@ TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) {
TEST_F(TouchSelectionControllerTest, InsertionDragged) {
base::TimeTicks event_time = base::TimeTicks::Now();
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
// The touch sequence should not be handled if insertion is not active.
@@ -422,7 +441,7 @@ TEST_F(TouchSelectionControllerTest, InsertionDragged) {
TEST_F(TouchSelectionControllerTest, InsertionTapped) {
base::TimeTicks event_time = base::TimeTicks::Now();
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
SetDraggingEnabled(true);
@@ -443,7 +462,7 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) {
// Reset the insertion.
ClearInsertion();
- controller().OnTapEvent();
+ OnTapEvent();
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED,
INSERTION_SHOWN));
@@ -461,7 +480,7 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) {
// Reset the insertion.
ClearInsertion();
- controller().OnTapEvent();
+ OnTapEvent();
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED,
INSERTION_SHOWN));
@@ -478,7 +497,7 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) {
// Reset the insertion.
ClearInsertion();
- controller().OnTapEvent();
+ OnTapEvent();
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED,
INSERTION_SHOWN));
@@ -494,7 +513,7 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) {
TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) {
base::TimeTicks event_time = base::TimeTicks::Now();
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
SetDraggingEnabled(true);
@@ -505,7 +524,7 @@ TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) {
EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart());
// Tapping again shouldn't reset the active insertion point.
- controller().OnTapEvent();
+ OnTapEvent();
MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED));
@@ -523,7 +542,7 @@ TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) {
EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart());
// Pressing shouldn't reset the active insertion point.
- controller().OnLongPressEvent();
+ OnLongPressEvent();
controller().OnSelectionEmpty(true);
event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
@@ -546,7 +565,7 @@ TEST_F(TouchSelectionControllerTest, SelectionBasic) {
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_EQ(gfx::PointF(), GetLastEventStart());
- controller().OnLongPressEvent();
+ OnLongPressEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
@@ -568,7 +587,7 @@ TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) {
gfx::RectF end_rect(50, 5, 0, 10);
bool visible = true;
- controller().OnLongPressEvent();
+ OnLongPressEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
@@ -577,7 +596,7 @@ TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) {
// A long press triggering a new selection should re-send the SELECTION_SHOWN
// event notification.
start_rect.Offset(10, 10);
- controller().OnLongPressEvent();
+ OnLongPressEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
@@ -586,7 +605,7 @@ TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) {
TEST_F(TouchSelectionControllerTest, SelectionDragged) {
base::TimeTicks event_time = base::TimeTicks::Now();
- controller().OnLongPressEvent();
+ OnLongPressEvent();
// The touch sequence should not be handled if selection is not active.
MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
@@ -644,7 +663,7 @@ TEST_F(TouchSelectionControllerTest, SelectionDragged) {
TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) {
base::TimeTicks event_time = base::TimeTicks::Now();
- controller().OnLongPressEvent();
+ OnLongPressEvent();
float line_height = 10.f;
gfx::RectF start_rect(0, 0, 0, line_height);
@@ -682,7 +701,7 @@ TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) {
TEST_F(TouchSelectionControllerTest, SelectionDraggedToSwitchBaseAndExtent) {
base::TimeTicks event_time = base::TimeTicks::Now();
- controller().OnLongPressEvent();
+ OnLongPressEvent();
float line_height = 10.f;
gfx::RectF start_rect(50, line_height, 0, line_height);
@@ -801,7 +820,7 @@ TEST_F(TouchSelectionControllerTest, SelectionDraggedToSwitchBaseAndExtent) {
TEST_F(TouchSelectionControllerTest, SelectionDragExtremeLineSize) {
base::TimeTicks event_time = base::TimeTicks::Now();
- controller().OnLongPressEvent();
+ OnLongPressEvent();
float small_line_height = 1.f;
float large_line_height = 50.f;
@@ -835,7 +854,7 @@ TEST_F(TouchSelectionControllerTest, SelectionDragExtremeLineSize) {
}
TEST_F(TouchSelectionControllerTest, Animation) {
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
gfx::RectF insertion_rect(5, 5, 0, 10);
@@ -858,14 +877,14 @@ TEST_F(TouchSelectionControllerTest, Animation) {
// If the client doesn't support animation, no animation should be triggered.
SetAnimationEnabled(false);
- controller().OnTapEvent();
+ OnTapEvent();
visible = true;
ChangeInsertion(insertion_rect, visible);
EXPECT_FALSE(GetAndResetNeedsAnimate());
}
TEST_F(TouchSelectionControllerTest, TemporarilyHidden) {
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
gfx::RectF insertion_rect(5, 5, 0, 10);
@@ -894,16 +913,16 @@ TEST_F(TouchSelectionControllerTest, SelectionClearOnTap) {
gfx::RectF end_rect(50, 5, 0, 10);
bool visible = true;
- controller().OnLongPressEvent();
+ OnLongPressEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
// Selection should not be cleared if the selection bounds have not changed.
- controller().OnTapEvent();
+ OnTapEvent();
EXPECT_THAT(GetAndResetEvents(), IsEmpty());
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
- controller().OnTapEvent();
+ OnTapEvent();
ClearSelection();
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED));
EXPECT_EQ(gfx::PointF(), GetLastEventStart());
@@ -915,13 +934,13 @@ TEST_F(TouchSelectionControllerTest, NoSelectionAfterLongpressThenTap) {
bool visible = true;
// Tap-triggered selections should not be allowed.
- controller().OnLongPressEvent();
- controller().OnTapEvent();
+ OnLongPressEvent();
+ OnTapEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), IsEmpty());
// Subsequent longpress selections will be allowed.
- controller().OnLongPressEvent();
+ OnLongPressEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
}
@@ -962,4 +981,44 @@ TEST_F(TouchSelectionControllerTest, AllowShowingFromCurrentSelection) {
EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart());
}
+TEST_F(TouchSelectionControllerTest, HandlesDontShowOnTapOutsideRect) {
+ gfx::PointF outer_point(100, 100);
+
+ // Establish a selection without handles from 5 to 50 with height 10.
+ ChangeSelectionToFiveFiftyTen();
+
+ // A point outside the rect should not be handled.
+ EXPECT_FALSE(controller().WillHandleTapEvent(outer_point));
+}
jdduke (slow) 2015/05/08 22:05:52 I would go ahead and merge the 2 tap tests into on
jdduke (slow) 2015/05/08 22:07:04 Oh, and just call the tests HandlesShowOnTapInsid
Donn Denman 2015/05/11 21:23:39 Done.
Donn Denman 2015/05/11 21:23:39 Done.
+
+TEST_F(TouchSelectionControllerTest, HandlesShowOnTapInsideRect) {
+ gfx::PointF inner_point(25, 10);
+
+ // Establish a selection without handles from 5 to 50 with height 10.
+ ChangeSelectionToFiveFiftyTen();
+
+ // A point inside the rect should be handled.
+ EXPECT_TRUE(controller().WillHandleTapEvent(inner_point));
+}
+
+TEST_F(TouchSelectionControllerTest, HandlesDontShowOnLongPressOutsideRect) {
+ gfx::PointF outer_point(100, 100);
+
+ // Establish a selection without handles from 5 to 50 with height 10.
+ ChangeSelectionToFiveFiftyTen();
+
+ // A point outside the rect should not be handled.
+ EXPECT_FALSE(controller().WillHandleLongPressEvent(outer_point));
+}
+
+TEST_F(TouchSelectionControllerTest, HandlesShowOnLongPressInsideRect) {
+ gfx::PointF inner_point(25, 10);
+
+ // Establish a selection without handles from 5 to 50 with height 10.
+ ChangeSelectionToFiveFiftyTen();
+
+ // A point inside the rect should be handled.
+ EXPECT_TRUE(controller().WillHandleLongPressEvent(inner_point));
+}
+
} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698