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/touch_selection_controller.h" | 5 #include "ui/touch_selection/touch_selection_controller.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 event.MovePoint(0, 0, kDefaulTapSlop * 10))); | 1267 event.MovePoint(0, 0, kDefaulTapSlop * 10))); |
1268 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); | 1268 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
1269 | 1269 |
1270 // Releasing the touch sequence should have no effect. | 1270 // Releasing the touch sequence should have no effect. |
1271 EXPECT_FALSE(controller().WillHandleTouchEvent(event.ReleasePoint())); | 1271 EXPECT_FALSE(controller().WillHandleTouchEvent(event.ReleasePoint())); |
1272 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); | 1272 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
1273 EXPECT_TRUE(test_controller.GetStartVisible()); | 1273 EXPECT_TRUE(test_controller.GetStartVisible()); |
1274 EXPECT_TRUE(test_controller.GetEndVisible()); | 1274 EXPECT_TRUE(test_controller.GetEndVisible()); |
1275 } | 1275 } |
1276 | 1276 |
| 1277 // When there is a selection on the page and long-press drag is performed |
| 1278 // somewhere that has nothing to select, long-press drag selector should not get |
| 1279 // activated so the page can scroll. |
| 1280 TEST_F(TouchSelectionControllerTest, LongPressDragScroll) { |
| 1281 EnableLongPressDragSelection(); |
| 1282 TouchSelectionControllerTestApi test_controller(&controller()); |
| 1283 |
| 1284 gfx::RectF start_rect(10, 0, 0, 10); |
| 1285 gfx::RectF end_rect(20, 0, 0, 10); |
| 1286 gfx::PointF touch_point(0, 0); |
| 1287 bool visible = true; |
| 1288 MockMotionEvent event; |
| 1289 |
| 1290 // Pre-select something. |
| 1291 ChangeSelection(start_rect, visible, end_rect, visible); |
| 1292 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_ESTABLISHED)); |
| 1293 |
| 1294 // Start the touch sequence and perform the long-press out of the existing |
| 1295 // selection. |
| 1296 EXPECT_FALSE(controller().WillHandleTouchEvent( |
| 1297 event.PressPoint(touch_point.x(), touch_point.y()))); |
| 1298 OnLongPressEvent(); |
| 1299 |
| 1300 // Drag down. Selection controller should not consume the touch-move event. |
| 1301 touch_point.Offset(0, 2 * kDefaulTapSlop); |
| 1302 EXPECT_FALSE(controller().WillHandleTouchEvent( |
| 1303 event.MovePoint(0, touch_point.x(), touch_point.y()))); |
| 1304 |
| 1305 // Begin page scroll and update the selection. Selection handles should not be |
| 1306 // shown which means long-press drag selector is not activated. |
| 1307 controller().OnScrollBeginEvent(); |
| 1308 start_rect.Offset(0, 2 * kDefaulTapSlop); |
| 1309 end_rect.Offset(0, 2 * kDefaulTapSlop); |
| 1310 ChangeSelection(start_rect, visible, end_rect, visible); |
| 1311 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| 1312 |
| 1313 // Release the touch sequence. |
| 1314 EXPECT_FALSE(controller().WillHandleTouchEvent(event.ReleasePoint())); |
| 1315 } |
| 1316 |
1277 TEST_F(TouchSelectionControllerTest, RectBetweenBounds) { | 1317 TEST_F(TouchSelectionControllerTest, RectBetweenBounds) { |
1278 gfx::RectF start_rect(5, 5, 0, 10); | 1318 gfx::RectF start_rect(5, 5, 0, 10); |
1279 gfx::RectF end_rect(50, 5, 0, 10); | 1319 gfx::RectF end_rect(50, 5, 0, 10); |
1280 bool visible = true; | 1320 bool visible = true; |
1281 | 1321 |
1282 EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds()); | 1322 EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds()); |
1283 | 1323 |
1284 OnLongPressEvent(); | 1324 OnLongPressEvent(); |
1285 ChangeSelection(start_rect, visible, end_rect, visible); | 1325 ChangeSelection(start_rect, visible, end_rect, visible); |
1286 ASSERT_THAT(GetAndResetEvents(), | 1326 ASSERT_THAT(GetAndResetEvents(), |
(...skipping 28 matching lines...) Expand all Loading... |
1315 EXPECT_EQ(gfx::RectF(6, 5, 44, 10), controller().GetRectBetweenBounds()); | 1355 EXPECT_EQ(gfx::RectF(6, 5, 44, 10), controller().GetRectBetweenBounds()); |
1316 EXPECT_EQ(GetLastEventBoundsRect(), controller().GetRectBetweenBounds()); | 1356 EXPECT_EQ(GetLastEventBoundsRect(), controller().GetRectBetweenBounds()); |
1317 | 1357 |
1318 ClearSelection(); | 1358 ClearSelection(); |
1319 ASSERT_THAT(GetAndResetEvents(), | 1359 ASSERT_THAT(GetAndResetEvents(), |
1320 ElementsAre(SELECTION_DISSOLVED, SELECTION_HANDLES_CLEARED)); | 1360 ElementsAre(SELECTION_DISSOLVED, SELECTION_HANDLES_CLEARED)); |
1321 EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds()); | 1361 EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds()); |
1322 } | 1362 } |
1323 | 1363 |
1324 } // namespace ui | 1364 } // namespace ui |
OLD | NEW |