OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/touch_selection/longpress_drag_selector.h" | 5 #include "ui/touch_selection/longpress_drag_selector.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/events/test/motion_event_test_utils.h" | 8 #include "ui/events/test/motion_event_test_utils.h" |
9 | 9 |
10 using ui::test::MockMotionEvent; | 10 using ui::test::MockMotionEvent; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 // Activate a longpress-triggered selection. | 132 // Activate a longpress-triggered selection. |
133 gfx::PointF selection_start(0, 10); | 133 gfx::PointF selection_start(0, 10); |
134 gfx::PointF selection_end(10, 10); | 134 gfx::PointF selection_end(10, 10); |
135 selector.OnLongPressEvent(event.GetEventTime(), gfx::PointF()); | 135 selector.OnLongPressEvent(event.GetEventTime(), gfx::PointF()); |
136 EXPECT_TRUE(GetAndResetActiveStateChanged()); | 136 EXPECT_TRUE(GetAndResetActiveStateChanged()); |
137 SetSelection(selection_start, selection_end); | 137 SetSelection(selection_start, selection_end); |
138 selector.OnSelectionActivated(); | 138 selector.OnSelectionActivated(); |
139 EXPECT_FALSE(IsDragging()); | 139 EXPECT_FALSE(IsDragging()); |
140 | 140 |
141 // Initiate drag motion. | 141 // Initiate drag motion. |
142 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, 0))); | 142 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 5, 0))); |
143 EXPECT_FALSE(IsDragging()); | 143 EXPECT_FALSE(IsDragging()); |
144 | 144 |
145 // As the initial motion is leftward, toward the selection start, the | 145 // As the initial motion is leftward, toward the selection start, the |
146 // selection start should be the drag point. | 146 // selection start should be the drag point. |
147 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, -kSlop, 0))); | 147 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, -kSlop, 0))); |
148 EXPECT_TRUE(IsDragging()); | 148 EXPECT_TRUE(IsDragging()); |
149 EXPECT_EQ(selection_start, DragPosition()); | 149 EXPECT_EQ(selection_start, DragPosition()); |
150 | 150 |
151 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, -kSlop))); | 151 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, -kSlop))); |
152 EXPECT_TRUE(IsDragging()); | 152 EXPECT_TRUE(IsDragging()); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 EXPECT_FALSE(IsDragging()); | 323 EXPECT_FALSE(IsDragging()); |
324 | 324 |
325 // Subsequent motion should not be consumed. | 325 // Subsequent motion should not be consumed. |
326 EXPECT_FALSE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, 0))); | 326 EXPECT_FALSE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, 0))); |
327 EXPECT_FALSE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop))); | 327 EXPECT_FALSE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop))); |
328 EXPECT_FALSE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop * 2))); | 328 EXPECT_FALSE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop * 2))); |
329 EXPECT_FALSE(IsDragging()); | 329 EXPECT_FALSE(IsDragging()); |
330 EXPECT_FALSE(selector.WillHandleTouchEvent(event.ReleasePoint())); | 330 EXPECT_FALSE(selector.WillHandleTouchEvent(event.ReleasePoint())); |
331 } | 331 } |
332 | 332 |
333 TEST_F(LongPressDragSelectorTest, DragFast) { | |
334 LongPressDragSelector selector(this); | |
335 MockMotionEvent event; | |
336 | |
337 // Start a touch sequence. | |
338 EXPECT_FALSE(selector.WillHandleTouchEvent(event.PressPoint(0, 0))); | |
339 EXPECT_FALSE(GetAndResetActiveStateChanged()); | |
340 | |
341 // Activate a longpress-triggered selection. | |
342 gfx::PointF selection_start(0, 10); | |
343 gfx::PointF selection_end(10, 10); | |
344 selector.OnLongPressEvent(event.GetEventTime(), gfx::PointF()); | |
345 EXPECT_TRUE(GetAndResetActiveStateChanged()); | |
346 SetSelection(selection_start, selection_end); | |
347 selector.OnSelectionActivated(); | |
348 EXPECT_FALSE(IsDragging()); | |
349 | |
350 // Initiate drag motion. | |
351 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 15, 5))); | |
352 EXPECT_FALSE(IsDragging()); | |
353 | |
354 // As the initial motion exceeds both endpoints, the closer bound should | |
355 // be used for dragging, in this case the selection end. | |
356 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 30, 15))); | |
mfomitchev
2015/08/04 18:31:36
would be nice to express the coordinates in terms
jdduke (slow)
2015/08/04 19:14:51
Done.
| |
357 EXPECT_TRUE(IsDragging()); | |
358 EXPECT_EQ(selection_end, DragPosition()); | |
359 | |
360 // Release the touch sequence, ending the drag. | |
361 EXPECT_FALSE(selector.WillHandleTouchEvent(event.ReleasePoint())); | |
362 EXPECT_FALSE(IsDragging()); | |
363 EXPECT_TRUE(GetAndResetActiveStateChanged()); | |
364 } | |
365 | |
333 } // namespace ui | 366 } // namespace ui |
OLD | NEW |