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

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

Issue 2355403002: Consume entire touch sequence in touch selection controller (Closed)
Patch Set: Created 4 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 "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); 427 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
428 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 428 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
429 EXPECT_FALSE(GetAndResetCaretMoved()); 429 EXPECT_FALSE(GetAndResetCaretMoved());
430 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STOPPED)); 430 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STOPPED));
431 431
432 // Once the drag is complete, no more touch events should be consumed until 432 // Once the drag is complete, no more touch events should be consumed until
433 // the next ACTION_DOWN. 433 // the next ACTION_DOWN.
434 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); 434 EXPECT_FALSE(controller().WillHandleTouchEvent(event));
435 } 435 }
436 436
437 TEST_F(TouchSelectionControllerTest, InsertionDeactivatedWhileDragging) {
438 base::TimeTicks event_time = base::TimeTicks::Now();
439 OnTapEvent();
440 controller().OnSelectionEditable(true);
441
442 float line_height = 10.f;
443 gfx::RectF start_rect(10, 0, 0, line_height);
444 bool visible = true;
445 ChangeInsertion(start_rect, visible);
446 EXPECT_THAT(GetAndResetEvents(),
447 ElementsAre(SELECTION_ESTABLISHED, INSERTION_HANDLE_SHOWN));
448 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
449
450 // Enable dragging so that the following ACTION_DOWN starts handle dragging.
451 SetDraggingEnabled(true);
452
453 // Touch down to start dragging.
454 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
455 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
456 EXPECT_FALSE(GetAndResetCaretMoved());
457 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STARTED));
458
459 // Move the handle.
460 gfx::PointF start_offset = start_rect.CenterPoint();
461 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 5);
462 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
463 EXPECT_TRUE(GetAndResetCaretMoved());
464 EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastCaretPosition());
465
466 // Deactivate touch selection to end dragging.
467 controller().HideAndDisallowShowingAutomatically();
468 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STOPPED,
469 INSERTION_HANDLE_CLEARED));
470
471 // Move the finger. There is no handle to move, so the cursor is not moved;
472 // but, the event is still consumed because the touch down that started the
473 // touch sequence was consumed.
474 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 5, 5);
475 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
476 EXPECT_FALSE(GetAndResetCaretMoved());
477 EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastCaretPosition());
478
479 // Lift the finger to end the touch sequence.
480 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 5, 5);
481 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
482 EXPECT_FALSE(GetAndResetCaretMoved());
483 EXPECT_THAT(GetAndResetEvents(), IsEmpty());
484
485 // No more event is consumed since the touch sequence is finished.
486 EXPECT_FALSE(controller().WillHandleTouchEvent(event));
487 }
488
437 TEST_F(TouchSelectionControllerTest, InsertionTapped) { 489 TEST_F(TouchSelectionControllerTest, InsertionTapped) {
438 base::TimeTicks event_time = base::TimeTicks::Now(); 490 base::TimeTicks event_time = base::TimeTicks::Now();
439 OnTapEvent(); 491 OnTapEvent();
440 controller().OnSelectionEditable(true); 492 controller().OnSelectionEditable(true);
441 SetDraggingEnabled(true); 493 SetDraggingEnabled(true);
442 494
443 gfx::RectF start_rect(10, 0, 0, 10); 495 gfx::RectF start_rect(10, 0, 0, 10);
444 bool visible = true; 496 bool visible = true;
445 ChangeInsertion(start_rect, visible); 497 ChangeInsertion(start_rect, visible);
446 EXPECT_THAT(GetAndResetEvents(), 498 EXPECT_THAT(GetAndResetEvents(),
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 offset_rect.x(), offset_rect.bottom()); 1496 offset_rect.x(), offset_rect.bottom());
1445 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 1497 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
1446 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED)); 1498 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
1447 EXPECT_EQ(test_controller.GetStartHandleOrientation(), 1499 EXPECT_EQ(test_controller.GetStartHandleOrientation(),
1448 TouchHandleOrientation::LEFT); 1500 TouchHandleOrientation::LEFT);
1449 EXPECT_EQ(test_controller.GetEndHandleOrientation(), 1501 EXPECT_EQ(test_controller.GetEndHandleOrientation(),
1450 TouchHandleOrientation::RIGHT); 1502 TouchHandleOrientation::RIGHT);
1451 } 1503 }
1452 1504
1453 } // namespace ui 1505 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698