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 "content/browser/renderer_host/input/touch_selection_controller.h" | 5 #include "content/browser/renderer_host/input/touch_selection_controller.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/events/test/mock_motion_event.h" | 8 #include "ui/events/test/mock_motion_event.h" |
9 | 9 |
10 using ui::test::MockMotionEvent; | 10 using ui::test::MockMotionEvent; |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 | 502 |
503 // The SelectBetweenCoordinates() result should reflect the movement. Note | 503 // The SelectBetweenCoordinates() result should reflect the movement. Note |
504 // that the start coordinate will always reflect the "fixed" handle's | 504 // that the start coordinate will always reflect the "fixed" handle's |
505 // position, in this case the position from |end_rect|. | 505 // position, in this case the position from |end_rect|. |
506 // Note that the reported position is offset from the center of the | 506 // Note that the reported position is offset from the center of the |
507 // input rects (i.e., the middle of the corresponding text line). | 507 // input rects (i.e., the middle of the corresponding text line). |
508 gfx::PointF fixed_offset = end_rect.CenterPoint(); | 508 gfx::PointF fixed_offset = end_rect.CenterPoint(); |
509 gfx::PointF start_offset = start_rect.CenterPoint(); | 509 gfx::PointF start_offset = start_rect.CenterPoint(); |
510 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 5); | 510 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 5); |
511 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 511 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 512 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); |
512 EXPECT_TRUE(GetAndResetSelectionMoved()); | 513 EXPECT_TRUE(GetAndResetSelectionMoved()); |
513 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); | 514 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); |
514 EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); | 515 EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); |
515 | 516 |
516 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 5, 5); | 517 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 5, 5); |
517 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 518 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
518 EXPECT_TRUE(GetAndResetSelectionMoved()); | 519 EXPECT_TRUE(GetAndResetSelectionMoved()); |
519 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); | 520 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); |
520 EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5), GetLastSelectionEnd()); | 521 EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5), GetLastSelectionEnd()); |
521 | 522 |
522 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 10, 5); | 523 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 10, 5); |
523 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 524 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
524 EXPECT_TRUE(GetAndResetSelectionMoved()); | 525 EXPECT_TRUE(GetAndResetSelectionMoved()); |
525 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); | 526 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); |
526 EXPECT_EQ(start_offset + gfx::Vector2dF(10, 5), GetLastSelectionEnd()); | 527 EXPECT_EQ(start_offset + gfx::Vector2dF(10, 5), GetLastSelectionEnd()); |
527 | 528 |
528 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); | 529 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); |
529 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 530 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 531 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); |
530 EXPECT_FALSE(GetAndResetSelectionMoved()); | 532 EXPECT_FALSE(GetAndResetSelectionMoved()); |
531 | 533 |
532 // Once the drag is complete, no more touch events should be consumed until | 534 // Once the drag is complete, no more touch events should be consumed until |
533 // the next ACTION_DOWN. | 535 // the next ACTION_DOWN. |
534 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 536 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
535 } | 537 } |
536 | 538 |
537 TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) { | 539 TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) { |
538 base::TimeTicks event_time = base::TimeTicks::Now(); | 540 base::TimeTicks event_time = base::TimeTicks::Now(); |
539 controller().OnLongPressEvent(); | 541 controller().OnLongPressEvent(); |
540 | 542 |
541 float line_height = 10.f; | 543 float line_height = 10.f; |
542 gfx::RectF start_rect(0, 0, 0, line_height); | 544 gfx::RectF start_rect(0, 0, 0, line_height); |
543 gfx::RectF end_rect(50, 0, 0, line_height); | 545 gfx::RectF end_rect(50, 0, 0, line_height); |
544 bool visible = true; | 546 bool visible = true; |
545 ChangeSelection(start_rect, visible, end_rect, visible); | 547 ChangeSelection(start_rect, visible, end_rect, visible); |
546 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 548 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); |
547 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 549 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); |
548 | 550 |
549 // The ACTION_DOWN should lock to the closest handle. | 551 // The ACTION_DOWN should lock to the closest handle. |
550 gfx::PointF end_offset = end_rect.CenterPoint(); | 552 gfx::PointF end_offset = end_rect.CenterPoint(); |
551 gfx::PointF fixed_offset = start_rect.CenterPoint(); | 553 gfx::PointF fixed_offset = start_rect.CenterPoint(); |
552 float touch_down_x = (end_offset.x() + fixed_offset.x()) / 2 + 1.f; | 554 float touch_down_x = (end_offset.x() + fixed_offset.x()) / 2 + 1.f; |
553 MockMotionEvent event( | 555 MockMotionEvent event( |
554 MockMotionEvent::ACTION_DOWN, event_time, touch_down_x, 0); | 556 MockMotionEvent::ACTION_DOWN, event_time, touch_down_x, 0); |
555 SetDraggingEnabled(true); | 557 SetDraggingEnabled(true); |
556 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 558 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 559 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); |
557 EXPECT_FALSE(GetAndResetSelectionMoved()); | 560 EXPECT_FALSE(GetAndResetSelectionMoved()); |
558 | 561 |
559 // Even though the ACTION_MOVE is over the start handle, it should continue | 562 // Even though the ACTION_MOVE is over the start handle, it should continue |
560 // targetting the end handle that consumed the ACTION_DOWN. | 563 // targetting the end handle that consumed the ACTION_DOWN. |
561 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 0); | 564 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 0); |
562 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 565 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
563 EXPECT_TRUE(GetAndResetSelectionMoved()); | 566 EXPECT_TRUE(GetAndResetSelectionMoved()); |
564 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); | 567 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); |
565 EXPECT_EQ(end_offset - gfx::Vector2dF(touch_down_x, 0), | 568 EXPECT_EQ(end_offset - gfx::Vector2dF(touch_down_x, 0), |
566 GetLastSelectionEnd()); | 569 GetLastSelectionEnd()); |
567 | 570 |
568 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); | 571 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); |
569 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 572 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 573 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); |
570 EXPECT_FALSE(GetAndResetSelectionMoved()); | 574 EXPECT_FALSE(GetAndResetSelectionMoved()); |
571 } | 575 } |
572 | 576 |
573 TEST_F(TouchSelectionControllerTest, Animation) { | 577 TEST_F(TouchSelectionControllerTest, Animation) { |
574 controller().OnTapEvent(); | 578 controller().OnTapEvent(); |
575 controller().OnSelectionEditable(true); | 579 controller().OnSelectionEditable(true); |
576 | 580 |
577 gfx::RectF insertion_rect(5, 5, 0, 10); | 581 gfx::RectF insertion_rect(5, 5, 0, 10); |
578 | 582 |
579 bool visible = true; | 583 bool visible = true; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 | 623 |
620 visible = true; | 624 visible = true; |
621 ChangeInsertion(insertion_rect, visible); | 625 ChangeInsertion(insertion_rect, visible); |
622 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 626 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
623 | 627 |
624 controller().SetTemporarilyHidden(false); | 628 controller().SetTemporarilyHidden(false); |
625 EXPECT_TRUE(GetAndResetNeedsAnimate()); | 629 EXPECT_TRUE(GetAndResetNeedsAnimate()); |
626 } | 630 } |
627 | 631 |
628 } // namespace content | 632 } // namespace content |
OLD | NEW |