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

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: cleanup Created 5 years, 2 months 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) {
AKV 2015/10/21 06:19:29 Can we name it as OrientationUnchangedDuringHandle
AviD 2015/10/21 06:40:02 Most of the test cases here start with Selection/I
1325 TouchSelectionControllerTestApi test_controller(&controller());
1326 base::TimeTicks event_time = base::TimeTicks::Now();
1327 OnLongPressEvent();
1328
1329 float line_height = 10.f;
AKV 2015/10/21 06:19:29 nit: 10.0f
AviD 2015/10/21 06:40:02 This is short for 10.0f. Used in other test cases
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(300);
1360 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
1361 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1362 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
1363 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1364 TouchHandleOrientation::LEFT);
1365 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1366 TouchHandleOrientation::RIGHT);
1367
1368 // Simulate moving the base, triggering a swap of points.
1369 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time,
1370 offset_rect.x(), offset_rect.bottom());
1371 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1372 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
1373
1374 offset_rect.Offset(gfx::Vector2dF(20, 0));
1375 ChangeSelection(end_rect, visible, offset_rect, visible);
1376 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
1377 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1378 TouchHandleOrientation::LEFT);
1379 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1380 TouchHandleOrientation::LEFT);
1381
1382 event_time += base::TimeDelta::FromMilliseconds(300);
1383 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
1384 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1385 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
1386 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1387 TouchHandleOrientation::LEFT);
1388 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1389 TouchHandleOrientation::RIGHT);
1390
1391 // Simulate moving the anchor, not triggering a swap of points.
1392 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time,
1393 offset_rect.x(), offset_rect.bottom());
1394 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1395 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
1396
1397 offset_rect.Offset(gfx::Vector2dF(-5, 0));
1398 ChangeSelection(end_rect, visible, offset_rect, visible);
1399 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
1400 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1401 TouchHandleOrientation::LEFT);
1402 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1403 TouchHandleOrientation::RIGHT);
1404
1405 event_time += base::TimeDelta::FromMilliseconds(300);
1406 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
1407 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1408 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
1409 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1410 TouchHandleOrientation::LEFT);
1411 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1412 TouchHandleOrientation::RIGHT);
1413
1414 // Simulate moving the anchor, triggering a swap of points.
1415 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time,
1416 offset_rect.x(), offset_rect.bottom());
1417 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1418 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
1419
1420 offset_rect.Offset(gfx::Vector2dF(-15, 0));
1421 ChangeSelection(offset_rect, visible, end_rect, visible);
1422 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
1423 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1424 TouchHandleOrientation::RIGHT);
1425 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1426 TouchHandleOrientation::RIGHT);
1427
1428 event_time += base::TimeDelta::FromMilliseconds(300);
1429 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
1430 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1431 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
1432 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1433 TouchHandleOrientation::LEFT);
1434 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1435 TouchHandleOrientation::RIGHT);
1436 }
1437
1324 } // namespace ui 1438 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698