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

Side by Side 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 unified diff | Download patch
OLDNEW
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 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED)); 1314 ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
1315 EXPECT_EQ(gfx::RectF(6, 5, 44, 10), controller().GetRectBetweenBounds()); 1315 EXPECT_EQ(gfx::RectF(6, 5, 44, 10), controller().GetRectBetweenBounds());
1316 EXPECT_EQ(GetLastEventBoundsRect(), controller().GetRectBetweenBounds()); 1316 EXPECT_EQ(GetLastEventBoundsRect(), controller().GetRectBetweenBounds());
1317 1317
1318 ClearSelection(); 1318 ClearSelection();
1319 ASSERT_THAT(GetAndResetEvents(), 1319 ASSERT_THAT(GetAndResetEvents(),
1320 ElementsAre(SELECTION_DISSOLVED, SELECTION_HANDLES_CLEARED)); 1320 ElementsAre(SELECTION_DISSOLVED, SELECTION_HANDLES_CLEARED));
1321 EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds()); 1321 EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds());
1322 } 1322 }
1323 1323
1324 TEST_F(TouchSelectionControllerTest, SelectionNoOrientationChangeWhenSwapped) {
1325 TouchSelectionControllerTestApi test_controller(&controller());
1326 base::TimeTicks event_time = base::TimeTicks::Now();
1327 OnLongPressEvent();
1328
1329 float line_height = 10.f;
1330 gfx::RectF start_rect(50, line_height, 0, line_height);
1331 gfx::RectF end_rect(100, line_height, 0, line_height);
1332 bool visible = true;
1333 ChangeSelection(start_rect, visible, end_rect, visible);
1334 EXPECT_THAT(GetAndResetEvents(),
1335 ElementsAre(SELECTION_ESTABLISHED, SELECTION_HANDLES_SHOWN));
1336 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
1337 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1338 TouchHandleOrientation::LEFT);
1339 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1340 TouchHandleOrientation::RIGHT);
1341
1342 SetDraggingEnabled(true);
1343
1344 // Simulate moving the base, not triggering a swap of points.
1345 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time,
1346 start_rect.x(), start_rect.bottom());
1347 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1348 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
1349
1350 gfx::RectF offset_rect = end_rect;
1351 offset_rect.Offset(gfx::Vector2dF(-10, 0));
1352 ChangeSelection(offset_rect, visible, end_rect, visible);
1353 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
1354 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1355 TouchHandleOrientation::LEFT);
1356 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1357 TouchHandleOrientation::RIGHT);
1358
1359 event_time += base::TimeDelta::FromMilliseconds(2 * kDefaultTapTimeoutMs);
1360 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time,
1361 offset_rect.x(), offset_rect.bottom());
1362 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1363 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
1364 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1365 TouchHandleOrientation::LEFT);
1366 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1367 TouchHandleOrientation::RIGHT);
1368
1369 // Simulate moving the base, triggering a swap of points.
1370 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time,
1371 offset_rect.x(), offset_rect.bottom());
1372 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1373 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
1374
1375 offset_rect.Offset(gfx::Vector2dF(20, 0));
1376 ChangeSelection(end_rect, visible, offset_rect, visible);
1377 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
1378 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1379 TouchHandleOrientation::LEFT);
1380 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1381 TouchHandleOrientation::LEFT);
1382
1383 event_time += base::TimeDelta::FromMilliseconds(2 * kDefaultTapTimeoutMs);
1384 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time,
1385 offset_rect.x(), offset_rect.bottom());
1386 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1387 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
1388 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1389 TouchHandleOrientation::LEFT);
1390 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1391 TouchHandleOrientation::RIGHT);
1392
1393 // Simulate moving the anchor, not triggering a swap of points.
1394 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time,
1395 offset_rect.x(), offset_rect.bottom());
1396 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1397 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
1398
1399 offset_rect.Offset(gfx::Vector2dF(-5, 0));
1400 ChangeSelection(end_rect, visible, offset_rect, visible);
1401 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
1402 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1403 TouchHandleOrientation::LEFT);
1404 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1405 TouchHandleOrientation::RIGHT);
1406
1407 event_time += base::TimeDelta::FromMilliseconds(2 * kDefaultTapTimeoutMs);
1408 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time,
1409 offset_rect.x(), offset_rect.bottom());
1410 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1411 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
1412 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1413 TouchHandleOrientation::LEFT);
1414 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1415 TouchHandleOrientation::RIGHT);
1416
1417 // Simulate moving the anchor, triggering a swap of points.
1418 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time,
1419 offset_rect.x(), offset_rect.bottom());
1420 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1421 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
1422
1423 offset_rect.Offset(gfx::Vector2dF(-15, 0));
1424 ChangeSelection(offset_rect, visible, end_rect, visible);
1425 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
1426 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1427 TouchHandleOrientation::RIGHT);
1428 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1429 TouchHandleOrientation::RIGHT);
1430
1431 event_time += base::TimeDelta::FromMilliseconds(2 * kDefaultTapTimeoutMs);
1432 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time,
1433 offset_rect.x(), offset_rect.bottom());
1434 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1435 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
1436 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1437 TouchHandleOrientation::LEFT);
1438 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1439 TouchHandleOrientation::RIGHT);
1440 }
1441
1324 } // namespace ui 1442 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698