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 "ui/touch_selection/touch_selection_controller.h" | 5 #include "ui/touch_selection/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/motion_event_test_utils.h" | 8 #include "ui/events/test/motion_event_test_utils.h" |
9 | 9 |
10 using ui::test::MockMotionEvent; | 10 using ui::test::MockMotionEvent; |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
723 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); | 723 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); |
724 EXPECT_EQ(base_offset, GetLastSelectionStart()); | 724 EXPECT_EQ(base_offset, GetLastSelectionStart()); |
725 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); | 725 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); |
726 | 726 |
727 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); | 727 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); |
728 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 728 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
729 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); | 729 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); |
730 EXPECT_FALSE(GetAndResetSelectionMoved()); | 730 EXPECT_FALSE(GetAndResetSelectionMoved()); |
731 } | 731 } |
732 | 732 |
733 TEST_F(TouchSelectionControllerTest, SelectionDragExtremeLineSize) { | |
734 base::TimeTicks event_time = base::TimeTicks::Now(); | |
735 controller().OnLongPressEvent(); | |
736 | |
737 float small_line_height = 1.f; | |
738 float large_line_height = 50.f; | |
739 gfx::RectF small_line_rect(0, 0, 0, small_line_height); | |
740 gfx::RectF large_line_rect(50, 50, 0, large_line_height); | |
741 bool visible = true; | |
742 ChangeSelection(small_line_rect, visible, large_line_rect, visible); | |
743 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | |
744 EXPECT_EQ(small_line_rect.bottom_left(), GetLastEventAnchor()); | |
745 | |
746 // Start dragging the handle on the small line. | |
747 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, | |
748 small_line_rect.x(), small_line_rect.y()); | |
749 SetDraggingEnabled(true); | |
750 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | |
751 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); | |
752 // The drag coordinate for large lines should have be capped to a reasonable | |
mohsen
2015/01/23 23:35:07
nit: should have be capped -> should be capped?
jdduke (slow)
2015/01/23 23:55:23
Ah, good catch, fixed.
| |
753 // offset, allowing seamless transition to neighboring lines with different | |
754 // sizes. The drag coordinate for small lines should have an offset | |
755 // commensurate with the small line size. | |
756 EXPECT_EQ(large_line_rect.bottom_left() - gfx::Vector2dF(0, 5.f), | |
757 GetLastSelectionStart()); | |
758 EXPECT_EQ(small_line_rect.CenterPoint(), GetLastSelectionEnd()); | |
759 | |
760 small_line_rect += gfx::Vector2dF(25.f, 0); | |
761 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, | |
762 small_line_rect.x(), small_line_rect.y()); | |
763 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | |
764 EXPECT_TRUE(GetAndResetSelectionMoved()); | |
765 EXPECT_EQ(small_line_rect.CenterPoint(), GetLastSelectionEnd()); | |
766 } | |
767 | |
733 TEST_F(TouchSelectionControllerTest, Animation) { | 768 TEST_F(TouchSelectionControllerTest, Animation) { |
734 controller().OnTapEvent(); | 769 controller().OnTapEvent(); |
735 controller().OnSelectionEditable(true); | 770 controller().OnSelectionEditable(true); |
736 | 771 |
737 gfx::RectF insertion_rect(5, 5, 0, 10); | 772 gfx::RectF insertion_rect(5, 5, 0, 10); |
738 | 773 |
739 bool visible = true; | 774 bool visible = true; |
740 ChangeInsertion(insertion_rect, visible); | 775 ChangeInsertion(insertion_rect, visible); |
741 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 776 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
742 | 777 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
834 controller().OnSelectionEmpty(false); | 869 controller().OnSelectionEmpty(false); |
835 controller().HideAndDisallowShowingAutomatically(); | 870 controller().HideAndDisallowShowingAutomatically(); |
836 gfx::RectF insertion_rect(5, 5, 0, 10); | 871 gfx::RectF insertion_rect(5, 5, 0, 10); |
837 ChangeInsertion(insertion_rect, visible); | 872 ChangeInsertion(insertion_rect, visible); |
838 controller().AllowShowingFromCurrentSelection(); | 873 controller().AllowShowingFromCurrentSelection(); |
839 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 874 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
840 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 875 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
841 } | 876 } |
842 | 877 |
843 } // namespace ui | 878 } // namespace ui |
OLD | NEW |