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 <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 25 matching lines...) Expand all Loading... |
36 } | 36 } |
37 | 37 |
38 private: | 38 private: |
39 bool* intersects_rect_; | 39 bool* intersects_rect_; |
40 | 40 |
41 DISALLOW_COPY_AND_ASSIGN(MockTouchHandleDrawable); | 41 DISALLOW_COPY_AND_ASSIGN(MockTouchHandleDrawable); |
42 }; | 42 }; |
43 | 43 |
44 } // namespace | 44 } // namespace |
45 | 45 |
| 46 class TouchSelectionControllerTestApi { |
| 47 public: |
| 48 explicit TouchSelectionControllerTestApi(TouchSelectionController* controller) |
| 49 : controller_(controller) {} |
| 50 ~TouchSelectionControllerTestApi() {} |
| 51 |
| 52 bool GetStartVisible() const { return controller_->GetStartVisible(); } |
| 53 bool GetEndVisible() const { return controller_->GetEndVisible(); } |
| 54 |
| 55 private: |
| 56 TouchSelectionController* controller_; |
| 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerTestApi); |
| 59 }; |
| 60 |
46 class TouchSelectionControllerTest : public testing::Test, | 61 class TouchSelectionControllerTest : public testing::Test, |
47 public TouchSelectionControllerClient { | 62 public TouchSelectionControllerClient { |
48 public: | 63 public: |
49 TouchSelectionControllerTest() | 64 TouchSelectionControllerTest() |
50 : caret_moved_(false), | 65 : caret_moved_(false), |
51 selection_moved_(false), | 66 selection_moved_(false), |
52 selection_points_swapped_(false), | 67 selection_points_swapped_(false), |
53 needs_animate_(false), | 68 needs_animate_(false), |
54 animation_enabled_(true), | 69 animation_enabled_(true), |
55 dragging_enabled_(false) {} | 70 dragging_enabled_(false) {} |
56 | 71 |
57 ~TouchSelectionControllerTest() override {} | 72 ~TouchSelectionControllerTest() override {} |
58 | 73 |
59 // testing::Test implementation. | 74 // testing::Test implementation. |
60 | 75 |
61 void SetUp() override { | 76 void SetUp() override { |
62 // Default touch selection controller is created with | 77 controller_.reset(new TouchSelectionController(this, DefaultConfig())); |
63 // |show_on_tap_for_empty_editable| flag set to false. Use | |
64 // |AllowShowingOnTapForEmptyEditable()| function to override it. | |
65 bool show_on_tap_for_empty_editable = false; | |
66 controller_.reset(new TouchSelectionController( | |
67 this, | |
68 base::TimeDelta::FromMilliseconds(kDefaultTapTimeoutMs), | |
69 kDefaulTapSlop, | |
70 show_on_tap_for_empty_editable)); | |
71 } | 78 } |
72 | 79 |
73 void TearDown() override { controller_.reset(); } | 80 void TearDown() override { controller_.reset(); } |
74 | 81 |
75 // TouchSelectionControllerClient implementation. | 82 // TouchSelectionControllerClient implementation. |
76 | 83 |
77 bool SupportsAnimation() const override { return animation_enabled_; } | 84 bool SupportsAnimation() const override { return animation_enabled_; } |
78 | 85 |
79 void SetNeedsAnimate() override { needs_animate_ = true; } | 86 void SetNeedsAnimate() override { needs_animate_ = true; } |
80 | 87 |
(...skipping 21 matching lines...) Expand all Loading... |
102 last_event_start_ = controller_->GetStartPosition(); | 109 last_event_start_ = controller_->GetStartPosition(); |
103 last_event_end_ = controller_->GetEndPosition(); | 110 last_event_end_ = controller_->GetEndPosition(); |
104 last_event_bounds_rect_ = controller_->GetRectBetweenBounds(); | 111 last_event_bounds_rect_ = controller_->GetRectBetweenBounds(); |
105 } | 112 } |
106 | 113 |
107 scoped_ptr<TouchHandleDrawable> CreateDrawable() override { | 114 scoped_ptr<TouchHandleDrawable> CreateDrawable() override { |
108 return make_scoped_ptr(new MockTouchHandleDrawable(&dragging_enabled_)); | 115 return make_scoped_ptr(new MockTouchHandleDrawable(&dragging_enabled_)); |
109 } | 116 } |
110 | 117 |
111 void AllowShowingOnTapForEmptyEditable() { | 118 void AllowShowingOnTapForEmptyEditable() { |
112 bool show_on_tap_for_empty_editable = true; | 119 TouchSelectionController::Config config = DefaultConfig(); |
113 controller_.reset(new TouchSelectionController( | 120 config.show_on_tap_for_empty_editable = true; |
114 this, | 121 controller_.reset(new TouchSelectionController(this, config)); |
115 base::TimeDelta::FromMilliseconds(kDefaultTapTimeoutMs), | 122 } |
116 kDefaulTapSlop, | 123 |
117 show_on_tap_for_empty_editable)); | 124 void EnableLongPressDragSelection() { |
| 125 TouchSelectionController::Config config = DefaultConfig(); |
| 126 config.enable_longpress_drag_selection = true; |
| 127 controller_.reset(new TouchSelectionController(this, config)); |
118 } | 128 } |
119 | 129 |
120 void SetAnimationEnabled(bool enabled) { animation_enabled_ = enabled; } | 130 void SetAnimationEnabled(bool enabled) { animation_enabled_ = enabled; } |
121 void SetDraggingEnabled(bool enabled) { dragging_enabled_ = enabled; } | 131 void SetDraggingEnabled(bool enabled) { dragging_enabled_ = enabled; } |
122 | 132 |
123 void ClearSelection() { | 133 void ClearSelection() { |
124 controller_->OnSelectionBoundsChanged(SelectionBound(), | 134 controller_->OnSelectionBoundsChanged(SelectionBound(), |
125 SelectionBound()); | 135 SelectionBound()); |
126 } | 136 } |
127 | 137 |
(...skipping 15 matching lines...) Expand all Loading... |
143 start_bound.set_type(SelectionBound::LEFT); | 153 start_bound.set_type(SelectionBound::LEFT); |
144 end_bound.set_type(SelectionBound::RIGHT); | 154 end_bound.set_type(SelectionBound::RIGHT); |
145 start_bound.SetEdge(start_rect.origin(), start_rect.bottom_left()); | 155 start_bound.SetEdge(start_rect.origin(), start_rect.bottom_left()); |
146 end_bound.SetEdge(end_rect.origin(), end_rect.bottom_left()); | 156 end_bound.SetEdge(end_rect.origin(), end_rect.bottom_left()); |
147 start_bound.set_visible(start_visible); | 157 start_bound.set_visible(start_visible); |
148 end_bound.set_visible(end_visible); | 158 end_bound.set_visible(end_visible); |
149 controller_->OnSelectionBoundsChanged(start_bound, end_bound); | 159 controller_->OnSelectionBoundsChanged(start_bound, end_bound); |
150 } | 160 } |
151 | 161 |
152 void OnLongPressEvent() { | 162 void OnLongPressEvent() { |
153 ASSERT_FALSE(controller().WillHandleLongPressEvent(kIgnoredPoint)); | 163 ASSERT_FALSE(controller().WillHandleLongPressEvent(base::TimeTicks(), |
| 164 kIgnoredPoint)); |
154 } | 165 } |
155 | 166 |
156 void OnTapEvent() { | 167 void OnTapEvent() { |
157 ASSERT_FALSE(controller().WillHandleTapEvent(kIgnoredPoint)); | 168 ASSERT_FALSE(controller().WillHandleTapEvent(kIgnoredPoint)); |
158 } | 169 } |
159 | 170 |
160 void Animate() { | 171 void Animate() { |
161 base::TimeTicks now = base::TimeTicks::Now(); | 172 base::TimeTicks now = base::TimeTicks::Now(); |
162 while (needs_animate_) { | 173 while (needs_animate_) { |
163 needs_animate_ = controller_->Animate(now); | 174 needs_animate_ = controller_->Animate(now); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 211 |
201 std::vector<SelectionEventType> GetAndResetEvents() { | 212 std::vector<SelectionEventType> GetAndResetEvents() { |
202 std::vector<SelectionEventType> events; | 213 std::vector<SelectionEventType> events; |
203 events.swap(events_); | 214 events.swap(events_); |
204 return events; | 215 return events; |
205 } | 216 } |
206 | 217 |
207 TouchSelectionController& controller() { return *controller_; } | 218 TouchSelectionController& controller() { return *controller_; } |
208 | 219 |
209 private: | 220 private: |
| 221 TouchSelectionController::Config DefaultConfig() { |
| 222 // Both |show_on_tap_for_empty_editable| and |
| 223 // |enable_longpress_drag_selection| are set to false by default, and should |
| 224 // be overriden for explicit testing. |
| 225 TouchSelectionController::Config config; |
| 226 config.tap_timeout = |
| 227 base::TimeDelta::FromMilliseconds(kDefaultTapTimeoutMs); |
| 228 config.tap_slop = kDefaulTapSlop; |
| 229 config.show_on_tap_for_empty_editable = false; |
| 230 config.enable_longpress_drag_selection = false; |
| 231 return config; |
| 232 } |
| 233 |
210 gfx::PointF last_event_start_; | 234 gfx::PointF last_event_start_; |
211 gfx::PointF last_event_end_; | 235 gfx::PointF last_event_end_; |
212 gfx::PointF caret_position_; | 236 gfx::PointF caret_position_; |
213 gfx::PointF selection_start_; | 237 gfx::PointF selection_start_; |
214 gfx::PointF selection_end_; | 238 gfx::PointF selection_end_; |
215 gfx::RectF last_event_bounds_rect_; | 239 gfx::RectF last_event_bounds_rect_; |
216 std::vector<SelectionEventType> events_; | 240 std::vector<SelectionEventType> events_; |
217 bool caret_moved_; | 241 bool caret_moved_; |
218 bool selection_moved_; | 242 bool selection_moved_; |
219 bool selection_points_swapped_; | 243 bool selection_points_swapped_; |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 | 920 |
897 // If the client doesn't support animation, no animation should be triggered. | 921 // If the client doesn't support animation, no animation should be triggered. |
898 SetAnimationEnabled(false); | 922 SetAnimationEnabled(false); |
899 OnTapEvent(); | 923 OnTapEvent(); |
900 visible = true; | 924 visible = true; |
901 ChangeInsertion(insertion_rect, visible); | 925 ChangeInsertion(insertion_rect, visible); |
902 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 926 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
903 } | 927 } |
904 | 928 |
905 TEST_F(TouchSelectionControllerTest, TemporarilyHidden) { | 929 TEST_F(TouchSelectionControllerTest, TemporarilyHidden) { |
| 930 TouchSelectionControllerTestApi test_controller(&controller()); |
| 931 |
906 OnTapEvent(); | 932 OnTapEvent(); |
907 controller().OnSelectionEditable(true); | 933 controller().OnSelectionEditable(true); |
908 | 934 |
909 gfx::RectF insertion_rect(5, 5, 0, 10); | 935 gfx::RectF insertion_rect(5, 5, 0, 10); |
910 | 936 |
911 bool visible = true; | 937 bool visible = true; |
912 ChangeInsertion(insertion_rect, visible); | 938 ChangeInsertion(insertion_rect, visible); |
913 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 939 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
| 940 EXPECT_TRUE(test_controller.GetStartVisible()); |
| 941 EXPECT_TRUE(test_controller.GetEndVisible()); |
914 | 942 |
915 controller().SetTemporarilyHidden(true); | 943 controller().SetTemporarilyHidden(true); |
916 EXPECT_TRUE(GetAndResetNeedsAnimate()); | 944 EXPECT_TRUE(GetAndResetNeedsAnimate()); |
| 945 EXPECT_FALSE(test_controller.GetStartVisible()); |
| 946 EXPECT_FALSE(test_controller.GetEndVisible()); |
917 | 947 |
918 visible = false; | 948 visible = false; |
919 ChangeInsertion(insertion_rect, visible); | 949 ChangeInsertion(insertion_rect, visible); |
920 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 950 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
| 951 EXPECT_FALSE(test_controller.GetStartVisible()); |
921 | 952 |
922 visible = true; | 953 visible = true; |
923 ChangeInsertion(insertion_rect, visible); | 954 ChangeInsertion(insertion_rect, visible); |
924 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 955 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
| 956 EXPECT_FALSE(test_controller.GetStartVisible()); |
925 | 957 |
926 controller().SetTemporarilyHidden(false); | 958 controller().SetTemporarilyHidden(false); |
927 EXPECT_TRUE(GetAndResetNeedsAnimate()); | 959 EXPECT_TRUE(GetAndResetNeedsAnimate()); |
| 960 EXPECT_TRUE(test_controller.GetStartVisible()); |
928 } | 961 } |
929 | 962 |
930 TEST_F(TouchSelectionControllerTest, SelectionClearOnTap) { | 963 TEST_F(TouchSelectionControllerTest, SelectionClearOnTap) { |
931 gfx::RectF start_rect(5, 5, 0, 10); | 964 gfx::RectF start_rect(5, 5, 0, 10); |
932 gfx::RectF end_rect(50, 5, 0, 10); | 965 gfx::RectF end_rect(50, 5, 0, 10); |
933 bool visible = true; | 966 bool visible = true; |
934 | 967 |
935 OnLongPressEvent(); | 968 OnLongPressEvent(); |
936 ChangeSelection(start_rect, visible, end_rect, visible); | 969 ChangeSelection(start_rect, visible, end_rect, visible); |
937 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); | 970 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 gfx::RectF start_rect(5, 5, 0, 10); | 1069 gfx::RectF start_rect(5, 5, 0, 10); |
1037 gfx::RectF end_rect(50, 5, 0, 10); | 1070 gfx::RectF end_rect(50, 5, 0, 10); |
1038 gfx::PointF inner_point(25, 10); | 1071 gfx::PointF inner_point(25, 10); |
1039 gfx::PointF outer_point(100, 100); | 1072 gfx::PointF outer_point(100, 100); |
1040 | 1073 |
1041 // Establish a selection without handles from 5 to 50 with height 10. | 1074 // Establish a selection without handles from 5 to 50 with height 10. |
1042 ChangeSelection(start_rect, visible, end_rect, visible); | 1075 ChangeSelection(start_rect, visible, end_rect, visible); |
1043 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); | 1076 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
1044 | 1077 |
1045 // A point outside the rect should not be handled. | 1078 // A point outside the rect should not be handled. |
1046 EXPECT_FALSE(controller().WillHandleLongPressEvent(outer_point)); | 1079 EXPECT_FALSE( |
| 1080 controller().WillHandleLongPressEvent(base::TimeTicks(), outer_point)); |
1047 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); | 1081 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
1048 | 1082 |
1049 // A point inside the rect should be handled. | 1083 // A point inside the rect should be handled. |
1050 EXPECT_TRUE(controller().WillHandleLongPressEvent(inner_point)); | 1084 EXPECT_TRUE( |
| 1085 controller().WillHandleLongPressEvent(base::TimeTicks(), inner_point)); |
1051 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); | 1086 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
1052 } | 1087 } |
1053 | 1088 |
| 1089 TEST_F(TouchSelectionControllerTest, LongPressDrag) { |
| 1090 EnableLongPressDragSelection(); |
| 1091 TouchSelectionControllerTestApi test_controller(&controller()); |
| 1092 |
| 1093 gfx::RectF start_rect(-50, 0, 0, 10); |
| 1094 gfx::RectF end_rect(50, 0, 0, 10); |
| 1095 bool visible = true; |
| 1096 |
| 1097 // Start a touch sequence. |
| 1098 MockMotionEvent event; |
| 1099 EXPECT_FALSE(controller().WillHandleTouchEvent(event.PressPoint(0, 0))); |
| 1100 |
| 1101 // Activate a longpress-triggered selection. |
| 1102 OnLongPressEvent(); |
| 1103 ChangeSelection(start_rect, visible, end_rect, visible); |
| 1104 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| 1105 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 1106 |
| 1107 // The handles should remain invisible while the touch release and longpress |
| 1108 // drag gesture are pending. |
| 1109 EXPECT_FALSE(test_controller.GetStartVisible()); |
| 1110 EXPECT_FALSE(test_controller.GetEndVisible()); |
| 1111 |
| 1112 // The selection coordinates should reflect the drag movement. |
| 1113 gfx::PointF fixed_offset = start_rect.CenterPoint(); |
| 1114 gfx::PointF end_offset = end_rect.CenterPoint(); |
| 1115 EXPECT_TRUE(controller().WillHandleTouchEvent(event.MovePoint(0, 0, 0))); |
| 1116 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| 1117 |
| 1118 EXPECT_TRUE( |
| 1119 controller().WillHandleTouchEvent(event.MovePoint(0, 0, kDefaulTapSlop))); |
| 1120 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED)); |
| 1121 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); |
| 1122 EXPECT_EQ(end_offset, GetLastSelectionEnd()); |
| 1123 |
| 1124 // Movement after the start of drag will be relative to the moved endpoint. |
| 1125 EXPECT_TRUE(controller().WillHandleTouchEvent( |
| 1126 event.MovePoint(0, 0, 2 * kDefaulTapSlop))); |
| 1127 EXPECT_TRUE(GetAndResetSelectionMoved()); |
| 1128 EXPECT_EQ(end_offset + gfx::Vector2dF(0, kDefaulTapSlop), |
| 1129 GetLastSelectionEnd()); |
| 1130 |
| 1131 EXPECT_TRUE(controller().WillHandleTouchEvent( |
| 1132 event.MovePoint(0, kDefaulTapSlop, 2 * kDefaulTapSlop))); |
| 1133 EXPECT_TRUE(GetAndResetSelectionMoved()); |
| 1134 EXPECT_EQ(end_offset + gfx::Vector2dF(kDefaulTapSlop, kDefaulTapSlop), |
| 1135 GetLastSelectionEnd()); |
| 1136 |
| 1137 EXPECT_TRUE(controller().WillHandleTouchEvent( |
| 1138 event.MovePoint(0, 2 * kDefaulTapSlop, 2 * kDefaulTapSlop))); |
| 1139 EXPECT_TRUE(GetAndResetSelectionMoved()); |
| 1140 EXPECT_EQ(end_offset + gfx::Vector2dF(2 * kDefaulTapSlop, kDefaulTapSlop), |
| 1141 GetLastSelectionEnd()); |
| 1142 |
| 1143 // The handles should still be hidden. |
| 1144 EXPECT_FALSE(test_controller.GetStartVisible()); |
| 1145 EXPECT_FALSE(test_controller.GetEndVisible()); |
| 1146 |
| 1147 // Releasing the touch sequence should end the drag and show the handles. |
| 1148 EXPECT_FALSE(controller().WillHandleTouchEvent(event.ReleasePoint())); |
| 1149 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STOPPED)); |
| 1150 EXPECT_TRUE(test_controller.GetStartVisible()); |
| 1151 EXPECT_TRUE(test_controller.GetEndVisible()); |
| 1152 } |
| 1153 |
| 1154 TEST_F(TouchSelectionControllerTest, LongPressNoDrag) { |
| 1155 EnableLongPressDragSelection(); |
| 1156 TouchSelectionControllerTestApi test_controller(&controller()); |
| 1157 |
| 1158 gfx::RectF start_rect(-50, 0, 0, 10); |
| 1159 gfx::RectF end_rect(50, 0, 0, 10); |
| 1160 bool visible = true; |
| 1161 |
| 1162 // Start a touch sequence. |
| 1163 MockMotionEvent event; |
| 1164 EXPECT_FALSE(controller().WillHandleTouchEvent(event.PressPoint(0, 0))); |
| 1165 |
| 1166 // Activate a longpress-triggered selection. |
| 1167 OnLongPressEvent(); |
| 1168 ChangeSelection(start_rect, visible, end_rect, visible); |
| 1169 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| 1170 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 1171 |
| 1172 // The handles should remain invisible while the touch release and longpress |
| 1173 // drag gesture are pending. |
| 1174 EXPECT_FALSE(test_controller.GetStartVisible()); |
| 1175 EXPECT_FALSE(test_controller.GetEndVisible()); |
| 1176 |
| 1177 // If no drag movement occurs, the handles should reappear after the touch |
| 1178 // is released. |
| 1179 EXPECT_FALSE(controller().WillHandleTouchEvent(event.ReleasePoint())); |
| 1180 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| 1181 EXPECT_TRUE(test_controller.GetStartVisible()); |
| 1182 EXPECT_TRUE(test_controller.GetEndVisible()); |
| 1183 } |
| 1184 |
| 1185 TEST_F(TouchSelectionControllerTest, NoLongPressDragIfDisabled) { |
| 1186 // The TouchSelectionController disables longpress drag selection by default. |
| 1187 TouchSelectionControllerTestApi test_controller(&controller()); |
| 1188 |
| 1189 gfx::RectF start_rect(-50, 0, 0, 10); |
| 1190 gfx::RectF end_rect(50, 0, 0, 10); |
| 1191 bool visible = true; |
| 1192 |
| 1193 // Start a touch sequence. |
| 1194 MockMotionEvent event; |
| 1195 EXPECT_FALSE(controller().WillHandleTouchEvent(event.PressPoint(0, 0))); |
| 1196 |
| 1197 // Activate a longpress-triggered selection. |
| 1198 OnLongPressEvent(); |
| 1199 ChangeSelection(start_rect, visible, end_rect, visible); |
| 1200 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| 1201 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 1202 EXPECT_TRUE(test_controller.GetStartVisible()); |
| 1203 EXPECT_TRUE(test_controller.GetEndVisible()); |
| 1204 |
| 1205 // Subsequent motion of the same touch sequence after longpress shouldn't |
| 1206 // trigger drag selection. |
| 1207 EXPECT_FALSE(controller().WillHandleTouchEvent(event.MovePoint(0, 0, 0))); |
| 1208 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| 1209 |
| 1210 EXPECT_FALSE(controller().WillHandleTouchEvent( |
| 1211 event.MovePoint(0, 0, kDefaulTapSlop * 10))); |
| 1212 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| 1213 |
| 1214 // Releasing the touch sequence should have no effect. |
| 1215 EXPECT_FALSE(controller().WillHandleTouchEvent(event.ReleasePoint())); |
| 1216 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| 1217 EXPECT_TRUE(test_controller.GetStartVisible()); |
| 1218 EXPECT_TRUE(test_controller.GetEndVisible()); |
| 1219 } |
| 1220 |
1054 TEST_F(TouchSelectionControllerTest, RectBetweenBounds) { | 1221 TEST_F(TouchSelectionControllerTest, RectBetweenBounds) { |
1055 gfx::RectF start_rect(5, 5, 0, 10); | 1222 gfx::RectF start_rect(5, 5, 0, 10); |
1056 gfx::RectF end_rect(50, 5, 0, 10); | 1223 gfx::RectF end_rect(50, 5, 0, 10); |
1057 bool visible = true; | 1224 bool visible = true; |
1058 | 1225 |
1059 EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds()); | 1226 EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds()); |
1060 | 1227 |
1061 OnLongPressEvent(); | 1228 OnLongPressEvent(); |
1062 ChangeSelection(start_rect, visible, end_rect, visible); | 1229 ChangeSelection(start_rect, visible, end_rect, visible); |
1063 ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); | 1230 ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
(...skipping 26 matching lines...) Expand all Loading... |
1090 ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_MOVED)); | 1257 ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_MOVED)); |
1091 EXPECT_EQ(gfx::RectF(6, 5, 44, 10), controller().GetRectBetweenBounds()); | 1258 EXPECT_EQ(gfx::RectF(6, 5, 44, 10), controller().GetRectBetweenBounds()); |
1092 EXPECT_EQ(GetLastEventBoundsRect(), controller().GetRectBetweenBounds()); | 1259 EXPECT_EQ(GetLastEventBoundsRect(), controller().GetRectBetweenBounds()); |
1093 | 1260 |
1094 ClearSelection(); | 1261 ClearSelection(); |
1095 ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED)); | 1262 ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED)); |
1096 EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds()); | 1263 EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds()); |
1097 } | 1264 } |
1098 | 1265 |
1099 } // namespace ui | 1266 } // namespace ui |
OLD | NEW |