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

Side by Side Diff: ui/touch_selection/touch_selection_controller_unittest.cc

Issue 2733603003: Tapping/longpressing should result in INSERTION_HANDLE_SHOWN (Closed)
Patch Set: removed InsertionNotResetByRepeatedTapOrPress Created 3 years, 9 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
« no previous file with comments | « ui/touch_selection/touch_selection_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 insertion_rect.Offset(1, 0); 248 insertion_rect.Offset(1, 0);
249 ChangeInsertion(insertion_rect, visible); 249 ChangeInsertion(insertion_rect, visible);
250 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_MOVED)); 250 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_MOVED));
251 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart()); 251 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart());
252 252
253 insertion_rect.Offset(0, 1); 253 insertion_rect.Offset(0, 1);
254 ChangeInsertion(insertion_rect, visible); 254 ChangeInsertion(insertion_rect, visible);
255 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_MOVED)); 255 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_MOVED));
256 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart()); 256 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart());
257 257
258 OnTapEvent();
259 insertion_rect.Offset(1, 0);
260 ChangeInsertion(insertion_rect, visible);
261 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_SHOWN));
262 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart());
263
258 ClearInsertion(); 264 ClearInsertion();
259 EXPECT_THAT(GetAndResetEvents(), 265 EXPECT_THAT(GetAndResetEvents(),
260 ElementsAre(INSERTION_HANDLE_CLEARED)); 266 ElementsAre(INSERTION_HANDLE_CLEARED));
261 } 267 }
262 268
263 TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) { 269 TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) {
264 OnLongPressEvent(); 270 OnLongPressEvent();
265 271
266 gfx::RectF start_rect(5, 5, 0, 10); 272 gfx::RectF start_rect(5, 5, 0, 10);
267 gfx::RectF end_rect(50, 5, 0, 10); 273 gfx::RectF end_rect(50, 5, 0, 10);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 468
463 // No tap should be signalled if the touch sequence is cancelled. 469 // No tap should be signalled if the touch sequence is cancelled.
464 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); 470 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
465 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 471 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
466 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); 472 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0);
467 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 473 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
468 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STARTED, 474 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STARTED,
469 INSERTION_HANDLE_DRAG_STOPPED)); 475 INSERTION_HANDLE_DRAG_STOPPED));
470 } 476 }
471 477
472 TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) {
473 base::TimeTicks event_time = base::TimeTicks::Now();
474 OnTapEvent();
475 SetDraggingEnabled(true);
476
477 gfx::RectF anchor_rect(10, 0, 0, 10);
478 bool visible = true;
479 ChangeInsertion(anchor_rect, visible);
480 EXPECT_THAT(GetAndResetEvents(),
481 ElementsAre(INSERTION_HANDLE_SHOWN));
482 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart());
483
484 // Tapping again shouldn't reset the active insertion point.
485 OnTapEvent();
486 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
487 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
488 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STARTED));
489 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart());
490
491 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
492 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
493 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_TAPPED,
494 INSERTION_HANDLE_DRAG_STOPPED));
495 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart());
496
497 anchor_rect.Offset(5, 15);
498 ChangeInsertion(anchor_rect, visible);
499 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_MOVED));
500 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart());
501
502 // Pressing shouldn't reset the active insertion point.
503 OnLongPressEvent();
504 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
505 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
506 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STARTED));
507 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart());
508
509 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
510 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
511 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_TAPPED,
512 INSERTION_HANDLE_DRAG_STOPPED));
513 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart());
514 }
515
516 TEST_F(TouchSelectionControllerTest, SelectionBasic) { 478 TEST_F(TouchSelectionControllerTest, SelectionBasic) {
517 gfx::RectF start_rect(5, 5, 0, 10); 479 gfx::RectF start_rect(5, 5, 0, 10);
518 gfx::RectF end_rect(50, 5, 0, 10); 480 gfx::RectF end_rect(50, 5, 0, 10);
519 bool visible = true; 481 bool visible = true;
520 482
521 OnLongPressEvent(); 483 OnLongPressEvent();
522 ChangeSelection(start_rect, visible, end_rect, visible); 484 ChangeSelection(start_rect, visible, end_rect, visible);
523 EXPECT_THAT(GetAndResetEvents(), 485 EXPECT_THAT(GetAndResetEvents(),
524 ElementsAre(SELECTION_HANDLES_SHOWN)); 486 ElementsAre(SELECTION_HANDLES_SHOWN));
525 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); 487 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 offset_rect.x(), offset_rect.bottom()); 1206 offset_rect.x(), offset_rect.bottom());
1245 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 1207 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1246 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED)); 1208 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
1247 EXPECT_EQ(test_controller.GetStartHandleOrientation(), 1209 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1248 TouchHandleOrientation::LEFT); 1210 TouchHandleOrientation::LEFT);
1249 EXPECT_EQ(test_controller.GetEndHandleOrientation(), 1211 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1250 TouchHandleOrientation::RIGHT); 1212 TouchHandleOrientation::RIGHT);
1251 } 1213 }
1252 1214
1253 } // namespace ui 1215 } // namespace ui
OLDNEW
« no previous file with comments | « ui/touch_selection/touch_selection_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698