Chromium Code Reviews| 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 247ed97a45ae753b8f191345dd52393f34f52dcf..2a5b8bb4c49ebdb4154508113889b6d2515ab8d0 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,14 @@ class TouchSelectionControllerTest : public testing::Test, |
| controller_->OnSelectionBoundsChanged(start_bound, end_bound); |
| } |
| + 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 +224,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 +254,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 +272,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 +290,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 +310,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 +327,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 +341,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 +372,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 +380,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 +431,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 +452,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 +470,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 +487,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 +503,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 +514,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 +532,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 +555,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 +577,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 +586,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 +595,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 +653,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 +691,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 +810,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 +844,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 +867,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 +903,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,18 +924,18 @@ 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)); |
| // Tapping again shouldn't have any effect on subsequent selection events. |
| - controller().OnTapEvent(); |
| + OnTapEvent(); |
| end_rect.Offset(10, 10); |
| ChangeSelection(start_rect, visible, end_rect, visible); |
| EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_MOVED)); |
| @@ -970,4 +979,54 @@ TEST_F(TouchSelectionControllerTest, AllowShowingFromCurrentSelection) { |
| EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart()); |
| } |
| +TEST_F(TouchSelectionControllerTest, HandlesShowOnTapInsideRect) { |
| + bool visible = false; |
| + gfx::RectF start_rect(5, 5, 0, 10); |
| + gfx::RectF end_rect(50, 5, 0, 10); |
| + gfx::PointF inner_point(25, 10); |
| + gfx::PointF outer_point(100, 100); |
| + |
| + // Establish a selection without handles from 5 to 50 with height 10. |
| + ChangeSelection(start_rect, visible, end_rect, visible); |
| + EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| + |
| + // A point outside the rect should not be handled. |
| + EXPECT_FALSE(controller().WillHandleTapEvent(outer_point)); |
| + EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| + |
| + // Establish a selection without handles from 5 to 50 with height 10. |
| + ChangeSelection(start_rect, visible, end_rect, visible); |
|
jdduke (slow)
2015/05/11 21:32:17
I think you can remove this |ChangeSelection| line
|
| + EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| + |
| + // A point inside the rect should be handled. |
| + EXPECT_TRUE(controller().WillHandleTapEvent(inner_point)); |
| + EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| +} |
| + |
| +TEST_F(TouchSelectionControllerTest, HandlesShowOnLongPressInsideRect) { |
| + bool visible = false; |
| + gfx::RectF start_rect(5, 5, 0, 10); |
| + gfx::RectF end_rect(50, 5, 0, 10); |
| + gfx::PointF inner_point(25, 10); |
| + gfx::PointF outer_point(100, 100); |
| + |
| + // Establish a selection without handles from 5 to 50 with height 10. |
| + ChangeSelection(start_rect, visible, end_rect, visible); |
| + EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| + |
| + // A point outside the rect should not be handled. |
| + EXPECT_FALSE(controller().WillHandleLongPressEvent(outer_point)); |
| + |
| + // Reset the selection. |
|
jdduke (slow)
2015/05/11 21:32:17
Hmm, why reset? It should be a simple matter of te
|
| + controller().HideAndDisallowShowingAutomatically(); |
| + |
| + // Establish a selection without handles from 5 to 50 with height 10. |
| + ChangeSelection(start_rect, visible, end_rect, visible); |
| + EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| + |
| + // A point inside the rect should be handled. |
| + EXPECT_TRUE(controller().WillHandleLongPressEvent(inner_point)); |
| + EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| +} |
| + |
| } // namespace ui |