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

Unified Diff: ui/touch_selection/touch_selection_controller_unittest.cc

Issue 1404163004: Swap touch selection handles when they are interchanged (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: linux build error Created 5 years 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 73e11323534ffe527ac3ae5cce9af3ba8ea182c6..cabfd04c2bb1cad8a816df6069624cbfc568e72e 100644
--- a/ui/touch_selection/touch_selection_controller_unittest.cc
+++ b/ui/touch_selection/touch_selection_controller_unittest.cc
@@ -1321,4 +1321,122 @@ TEST_F(TouchSelectionControllerTest, RectBetweenBounds) {
EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds());
}
+TEST_F(TouchSelectionControllerTest, SelectionNoOrientationChangeWhenSwapped) {
+ TouchSelectionControllerTestApi test_controller(&controller());
+ base::TimeTicks event_time = base::TimeTicks::Now();
+ OnLongPressEvent();
+
+ float line_height = 10.f;
+ gfx::RectF start_rect(50, line_height, 0, line_height);
+ gfx::RectF end_rect(100, line_height, 0, line_height);
+ bool visible = true;
+ ChangeSelection(start_rect, visible, end_rect, visible);
+ EXPECT_THAT(GetAndResetEvents(),
+ ElementsAre(SELECTION_ESTABLISHED, SELECTION_HANDLES_SHOWN));
+ EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
+ EXPECT_EQ(test_controller.GetStartHandleOrientation(),
+ TouchHandleOrientation::LEFT);
+ EXPECT_EQ(test_controller.GetEndHandleOrientation(),
+ TouchHandleOrientation::RIGHT);
+
+ SetDraggingEnabled(true);
+
+ // Simulate moving the base, not triggering a swap of points.
+ MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time,
+ start_rect.x(), start_rect.bottom());
+ EXPECT_TRUE(controller().WillHandleTouchEvent(event));
+ EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
+
+ gfx::RectF offset_rect = end_rect;
+ offset_rect.Offset(gfx::Vector2dF(-10, 0));
+ ChangeSelection(offset_rect, visible, end_rect, visible);
+ EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
+ EXPECT_EQ(test_controller.GetStartHandleOrientation(),
+ TouchHandleOrientation::LEFT);
+ EXPECT_EQ(test_controller.GetEndHandleOrientation(),
+ TouchHandleOrientation::RIGHT);
+
+ event_time += base::TimeDelta::FromMilliseconds(2 * kDefaultTapTimeoutMs);
+ event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time,
+ offset_rect.x(), offset_rect.bottom());
+ EXPECT_TRUE(controller().WillHandleTouchEvent(event));
+ EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
+ EXPECT_EQ(test_controller.GetStartHandleOrientation(),
+ TouchHandleOrientation::LEFT);
+ EXPECT_EQ(test_controller.GetEndHandleOrientation(),
+ TouchHandleOrientation::RIGHT);
+
+ // Simulate moving the base, triggering a swap of points.
+ event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time,
+ offset_rect.x(), offset_rect.bottom());
+ EXPECT_TRUE(controller().WillHandleTouchEvent(event));
+ EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
+
+ offset_rect.Offset(gfx::Vector2dF(20, 0));
+ ChangeSelection(end_rect, visible, offset_rect, visible);
+ EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
+ EXPECT_EQ(test_controller.GetStartHandleOrientation(),
+ TouchHandleOrientation::LEFT);
+ EXPECT_EQ(test_controller.GetEndHandleOrientation(),
+ TouchHandleOrientation::LEFT);
+
+ event_time += base::TimeDelta::FromMilliseconds(2 * kDefaultTapTimeoutMs);
+ event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time,
+ offset_rect.x(), offset_rect.bottom());
+ EXPECT_TRUE(controller().WillHandleTouchEvent(event));
+ EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
+ EXPECT_EQ(test_controller.GetStartHandleOrientation(),
+ TouchHandleOrientation::LEFT);
+ EXPECT_EQ(test_controller.GetEndHandleOrientation(),
+ TouchHandleOrientation::RIGHT);
+
+ // Simulate moving the anchor, not triggering a swap of points.
+ event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time,
+ offset_rect.x(), offset_rect.bottom());
+ EXPECT_TRUE(controller().WillHandleTouchEvent(event));
+ EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
+
+ offset_rect.Offset(gfx::Vector2dF(-5, 0));
+ ChangeSelection(end_rect, visible, offset_rect, visible);
+ EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
+ EXPECT_EQ(test_controller.GetStartHandleOrientation(),
+ TouchHandleOrientation::LEFT);
+ EXPECT_EQ(test_controller.GetEndHandleOrientation(),
+ TouchHandleOrientation::RIGHT);
+
+ event_time += base::TimeDelta::FromMilliseconds(2 * kDefaultTapTimeoutMs);
+ event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time,
+ offset_rect.x(), offset_rect.bottom());
+ EXPECT_TRUE(controller().WillHandleTouchEvent(event));
+ EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
+ EXPECT_EQ(test_controller.GetStartHandleOrientation(),
+ TouchHandleOrientation::LEFT);
+ EXPECT_EQ(test_controller.GetEndHandleOrientation(),
+ TouchHandleOrientation::RIGHT);
+
+ // Simulate moving the anchor, triggering a swap of points.
+ event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time,
+ offset_rect.x(), offset_rect.bottom());
+ EXPECT_TRUE(controller().WillHandleTouchEvent(event));
+ EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
+
+ offset_rect.Offset(gfx::Vector2dF(-15, 0));
+ ChangeSelection(offset_rect, visible, end_rect, visible);
+ EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
+ EXPECT_EQ(test_controller.GetStartHandleOrientation(),
+ TouchHandleOrientation::RIGHT);
+ EXPECT_EQ(test_controller.GetEndHandleOrientation(),
+ TouchHandleOrientation::RIGHT);
+
+ event_time += base::TimeDelta::FromMilliseconds(2 * kDefaultTapTimeoutMs);
+ event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time,
+ offset_rect.x(), offset_rect.bottom());
+ EXPECT_TRUE(controller().WillHandleTouchEvent(event));
+ EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
+ EXPECT_EQ(test_controller.GetStartHandleOrientation(),
+ TouchHandleOrientation::LEFT);
+ EXPECT_EQ(test_controller.GetEndHandleOrientation(),
+ TouchHandleOrientation::RIGHT);
+}
+
} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698