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 46c2f4f9cd1481aec32ecef38cea46a99522b079..045d3493fd0f2934856593d1ae732b16c7416036 100644 |
| --- a/ui/touch_selection/touch_selection_controller_unittest.cc |
| +++ b/ui/touch_selection/touch_selection_controller_unittest.cc |
| @@ -10,6 +10,7 @@ |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "ui/events/test/motion_event_test_utils.h" |
| +using base::TimeTicks; |
| using testing::ElementsAre; |
| using testing::IsEmpty; |
| using ui::test::MockMotionEvent; |
| @@ -148,7 +149,7 @@ class TouchSelectionControllerTest : public testing::Test, |
| } |
| void Animate() { |
| - base::TimeTicks now = base::TimeTicks::Now(); |
| + TimeTicks now = TimeTicks::Now(); |
| while (needs_animate_) { |
| needs_animate_ = controller_->Animate(now); |
| now += base::TimeDelta::FromMilliseconds(16); |
| @@ -285,7 +286,7 @@ TEST_F(TouchSelectionControllerTest, InsertionWithNoShowOnTapForEmptyEditable) { |
| // Long-pressing should show the handle even if the editable region is empty. |
| insertion_rect.Offset(2, -2); |
| - controller().OnLongPressEvent(); |
| + controller().OnLongPressEvent(TimeTicks::Now(), insertion_rect.bottom_left()); |
| controller().OnSelectionEmpty(true); |
| ChangeInsertion(insertion_rect, visible); |
| EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); |
| @@ -343,7 +344,7 @@ TEST_F(TouchSelectionControllerTest, InsertionAppearsAfterTapFollowingTyping) { |
| } |
| TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) { |
| - controller().OnLongPressEvent(); |
| + controller().OnLongPressEvent(TimeTicks::Now(), gfx::PointF()); |
| controller().OnSelectionEditable(true); |
| gfx::RectF start_rect(5, 5, 0, 10); |
| @@ -526,7 +527,7 @@ TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) { |
| EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart()); |
| // Pressing shouldn't reset the active insertion point. |
| - controller().OnLongPressEvent(); |
| + controller().OnLongPressEvent(TimeTicks::Now(), gfx::PointF()); |
| controller().OnSelectionEmpty(true); |
| event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| @@ -549,7 +550,7 @@ TEST_F(TouchSelectionControllerTest, SelectionBasic) { |
| ChangeSelection(start_rect, visible, end_rect, visible); |
| EXPECT_EQ(gfx::PointF(), GetLastEventStart()); |
| - controller().OnLongPressEvent(); |
| + controller().OnLongPressEvent(TimeTicks::Now(), start_rect.bottom_left()); |
| ChangeSelection(start_rect, visible, end_rect, visible); |
| EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| @@ -571,7 +572,7 @@ TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) { |
| gfx::RectF end_rect(50, 5, 0, 10); |
| bool visible = true; |
| - controller().OnLongPressEvent(); |
| + controller().OnLongPressEvent(TimeTicks::Now(), start_rect.bottom_left()); |
| ChangeSelection(start_rect, visible, end_rect, visible); |
| EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| @@ -580,7 +581,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(); |
| + controller().OnLongPressEvent(TimeTicks::Now(), start_rect.bottom_left()); |
| ChangeSelection(start_rect, visible, end_rect, visible); |
| EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| @@ -589,7 +590,7 @@ TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) { |
| TEST_F(TouchSelectionControllerTest, SelectionDragged) { |
| base::TimeTicks event_time = base::TimeTicks::Now(); |
| - controller().OnLongPressEvent(); |
| + controller().OnLongPressEvent(event_time, gfx::PointF()); |
| // The touch sequence should not be handled if selection is not active. |
| MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| @@ -647,7 +648,7 @@ TEST_F(TouchSelectionControllerTest, SelectionDragged) { |
| TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) { |
| base::TimeTicks event_time = base::TimeTicks::Now(); |
| - controller().OnLongPressEvent(); |
| + controller().OnLongPressEvent(event_time, gfx::PointF()); |
| float line_height = 10.f; |
| gfx::RectF start_rect(0, 0, 0, line_height); |
| @@ -685,7 +686,7 @@ TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) { |
| TEST_F(TouchSelectionControllerTest, SelectionDraggedToSwitchBaseAndExtent) { |
| base::TimeTicks event_time = base::TimeTicks::Now(); |
| - controller().OnLongPressEvent(); |
| + controller().OnLongPressEvent(event_time, gfx::PointF()); |
| float line_height = 10.f; |
| gfx::RectF start_rect(50, line_height, 0, line_height); |
| @@ -804,7 +805,7 @@ TEST_F(TouchSelectionControllerTest, SelectionDraggedToSwitchBaseAndExtent) { |
| TEST_F(TouchSelectionControllerTest, SelectionDragExtremeLineSize) { |
| base::TimeTicks event_time = base::TimeTicks::Now(); |
| - controller().OnLongPressEvent(); |
| + controller().OnLongPressEvent(event_time, gfx::PointF()); |
| float small_line_height = 1.f; |
| float large_line_height = 50.f; |
| @@ -876,20 +877,27 @@ TEST_F(TouchSelectionControllerTest, TemporarilyHidden) { |
| bool visible = true; |
| ChangeInsertion(insertion_rect, visible); |
| EXPECT_FALSE(GetAndResetNeedsAnimate()); |
| + EXPECT_TRUE(controller().GetStartVisibleForTesting()); |
| + EXPECT_TRUE(controller().GetEndVisibleForTesting()); |
| controller().SetTemporarilyHidden(true); |
| EXPECT_TRUE(GetAndResetNeedsAnimate()); |
| + EXPECT_FALSE(controller().GetStartVisibleForTesting()); |
| + EXPECT_FALSE(controller().GetEndVisibleForTesting()); |
| visible = false; |
| ChangeInsertion(insertion_rect, visible); |
| EXPECT_FALSE(GetAndResetNeedsAnimate()); |
| + EXPECT_FALSE(controller().GetStartVisibleForTesting()); |
| visible = true; |
| ChangeInsertion(insertion_rect, visible); |
| EXPECT_FALSE(GetAndResetNeedsAnimate()); |
| + EXPECT_FALSE(controller().GetStartVisibleForTesting()); |
| controller().SetTemporarilyHidden(false); |
| EXPECT_TRUE(GetAndResetNeedsAnimate()); |
| + EXPECT_TRUE(controller().GetStartVisibleForTesting()); |
| } |
| TEST_F(TouchSelectionControllerTest, SelectionClearOnTap) { |
| @@ -897,7 +905,7 @@ TEST_F(TouchSelectionControllerTest, SelectionClearOnTap) { |
| gfx::RectF end_rect(50, 5, 0, 10); |
| bool visible = true; |
| - controller().OnLongPressEvent(); |
| + controller().OnLongPressEvent(TimeTicks::Now(), start_rect.bottom_left()); |
| ChangeSelection(start_rect, visible, end_rect, visible); |
| EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| @@ -918,13 +926,13 @@ TEST_F(TouchSelectionControllerTest, NoSelectionAfterLongpressThenTap) { |
| bool visible = true; |
| // Tap-triggered selections should not be allowed. |
| - controller().OnLongPressEvent(); |
| + controller().OnLongPressEvent(TimeTicks::Now(), start_rect.bottom_left()); |
| controller().OnTapEvent(); |
| ChangeSelection(start_rect, visible, end_rect, visible); |
| EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| // Subsequent longpress selections will be allowed. |
| - controller().OnLongPressEvent(); |
| + controller().OnLongPressEvent(TimeTicks::Now(), start_rect.bottom_left()); |
| ChangeSelection(start_rect, visible, end_rect, visible); |
| EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| @@ -947,7 +955,7 @@ TEST_F(TouchSelectionControllerTest, AllowShowingFromCurrentSelection) { |
| EXPECT_EQ(gfx::PointF(), GetLastEventStart()); |
| // A longpress should have no immediate effect. |
| - controller().OnLongPressEvent(); |
| + controller().OnLongPressEvent(TimeTicks::Now(), start_rect.bottom_left()); |
| // Now explicitly allow showing from the previously supplied bounds. |
| controller().AllowShowingFromCurrentSelection(); |
| @@ -976,4 +984,59 @@ TEST_F(TouchSelectionControllerTest, AllowShowingFromCurrentSelection) { |
| EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart()); |
| } |
| +TEST_F(TouchSelectionControllerTest, LongPressDrag) { |
|
mfomitchev
2015/05/13 20:52:25
Can we also add a test that the handles reappear i
jdduke (slow)
2015/05/14 18:29:27
Done.
|
| + gfx::RectF start_rect(-50, 0, 0, 10); |
| + gfx::RectF end_rect(50, 0, 0, 10); |
| + bool visible = true; |
| + |
| + // Start a touch sequence. |
| + MockMotionEvent event; |
| + EXPECT_FALSE(controller().WillHandleTouchEvent(event.PressPoint(0, 0))); |
| + |
| + // Activate a longpress-triggered selection. |
| + controller().OnLongPressEvent(event.GetEventTime(), gfx::PointF()); |
| + ChangeSelection(start_rect, visible, end_rect, visible); |
| + EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| + EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| + |
| + // The handles should remain invisible while the touch release and longpress |
| + // drag gesture are pending. |
| + EXPECT_FALSE(controller().GetStartVisibleForTesting()); |
| + EXPECT_FALSE(controller().GetEndVisibleForTesting()); |
| + |
| + // The selection coordinates should reflect the drag movement. |
| + gfx::PointF fixed_offset = start_rect.CenterPoint(); |
| + gfx::PointF end_offset = end_rect.CenterPoint(); |
| + EXPECT_TRUE(controller().WillHandleTouchEvent(event.MovePoint(0, 0, 0))); |
| + EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| + |
| + EXPECT_TRUE(controller().WillHandleTouchEvent(event.MovePoint(0, 0, 10))); |
|
mfomitchev
2015/05/13 20:52:25
Can we use kDefaulTapSlop instead of ints here?
jdduke (slow)
2015/05/14 18:29:27
Done.
|
| + EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED)); |
| + EXPECT_EQ(fixed_offset, GetLastSelectionStart()); |
| + EXPECT_EQ(end_offset, GetLastSelectionEnd()); |
| + |
| + // Movement after the start of drag will be relative to the moved endpoint. |
| + EXPECT_TRUE(controller().WillHandleTouchEvent(event.MovePoint(0, 0, 20))); |
| + EXPECT_TRUE(GetAndResetSelectionMoved()); |
| + EXPECT_EQ(end_offset + gfx::Vector2dF(0, 10), GetLastSelectionEnd()); |
| + |
| + EXPECT_TRUE(controller().WillHandleTouchEvent(event.MovePoint(0, 10, 20))); |
| + EXPECT_TRUE(GetAndResetSelectionMoved()); |
| + EXPECT_EQ(end_offset + gfx::Vector2dF(10, 10), GetLastSelectionEnd()); |
| + |
| + EXPECT_TRUE(controller().WillHandleTouchEvent(event.MovePoint(0, 20, 20))); |
| + EXPECT_TRUE(GetAndResetSelectionMoved()); |
| + EXPECT_EQ(end_offset + gfx::Vector2dF(20, 10), GetLastSelectionEnd()); |
| + |
| + // The handles should still be hidden. |
| + EXPECT_FALSE(controller().GetStartVisibleForTesting()); |
| + EXPECT_FALSE(controller().GetEndVisibleForTesting()); |
| + |
| + // Releasing the touch sequence should end the drag and show the handles. |
| + EXPECT_FALSE(controller().WillHandleTouchEvent(event.ReleasePoint())); |
| + EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STOPPED)); |
| + EXPECT_TRUE(controller().GetStartVisibleForTesting()); |
| + EXPECT_TRUE(controller().GetEndVisibleForTesting()); |
| +} |
| + |
| } // namespace ui |