Chromium Code Reviews| 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 <map> | |
| 8 | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/events/test/motion_event_test_utils.h" | 10 #include "ui/events/test/motion_event_test_utils.h" |
| 9 | 11 |
| 10 using ui::test::MockMotionEvent; | 12 using ui::test::MockMotionEvent; |
| 11 | 13 |
| 12 namespace ui { | 14 namespace ui { |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 const int kDefaultTapTimeoutMs = 200; | 17 const int kDefaultTapTimeoutMs = 200; |
| 16 const float kDefaulTapSlop = 10.f; | 18 const float kDefaulTapSlop = 10.f; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 32 private: | 34 private: |
| 33 bool* intersects_rect_; | 35 bool* intersects_rect_; |
| 34 }; | 36 }; |
| 35 | 37 |
| 36 } // namespace | 38 } // namespace |
| 37 | 39 |
| 38 class TouchSelectionControllerTest : public testing::Test, | 40 class TouchSelectionControllerTest : public testing::Test, |
| 39 public TouchSelectionControllerClient { | 41 public TouchSelectionControllerClient { |
| 40 public: | 42 public: |
| 41 TouchSelectionControllerTest() | 43 TouchSelectionControllerTest() |
| 42 : last_event_(SELECTION_CLEARED), | 44 : total_event_count_(0), |
| 43 caret_moved_(false), | 45 caret_moved_(false), |
| 44 selection_moved_(false), | 46 selection_moved_(false), |
| 45 selection_points_swapped_(false), | 47 selection_points_swapped_(false), |
| 46 needs_animate_(false), | 48 needs_animate_(false), |
| 47 animation_enabled_(true), | 49 animation_enabled_(true), |
| 48 dragging_enabled_(false) {} | 50 dragging_enabled_(false) {} |
| 49 | 51 |
| 50 ~TouchSelectionControllerTest() override {} | 52 ~TouchSelectionControllerTest() override {} |
| 51 | 53 |
| 52 // testing::Test implementation. | 54 // testing::Test implementation. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 selection_end_ = extent; | 87 selection_end_ = extent; |
| 86 } | 88 } |
| 87 | 89 |
| 88 void MoveRangeSelectionExtent(const gfx::PointF& extent) override { | 90 void MoveRangeSelectionExtent(const gfx::PointF& extent) override { |
| 89 selection_moved_ = true; | 91 selection_moved_ = true; |
| 90 selection_end_ = extent; | 92 selection_end_ = extent; |
| 91 } | 93 } |
| 92 | 94 |
| 93 void OnSelectionEvent(SelectionEventType event, | 95 void OnSelectionEvent(SelectionEventType event, |
| 94 const gfx::PointF& end_position) override { | 96 const gfx::PointF& end_position) override { |
| 95 last_event_ = event; | 97 event_count_[event]++; |
| 98 total_event_count_++; | |
| 96 last_event_start_ = end_position; | 99 last_event_start_ = end_position; |
| 97 } | 100 } |
| 98 | 101 |
| 99 scoped_ptr<TouchHandleDrawable> CreateDrawable() override { | 102 scoped_ptr<TouchHandleDrawable> CreateDrawable() override { |
| 100 return scoped_ptr<TouchHandleDrawable>( | 103 return scoped_ptr<TouchHandleDrawable>( |
| 101 new MockTouchHandleDrawable(&dragging_enabled_)); | 104 new MockTouchHandleDrawable(&dragging_enabled_)); |
| 102 } | 105 } |
| 103 | 106 |
| 104 void AllowShowingOnTapForEmptyEditable() { | 107 void AllowShowingOnTapForEmptyEditable() { |
| 105 bool show_on_tap_for_empty_editable = true; | 108 bool show_on_tap_for_empty_editable = true; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 | 173 |
| 171 bool GetAndResetSelectionPointsSwapped() { | 174 bool GetAndResetSelectionPointsSwapped() { |
| 172 bool swapped = selection_points_swapped_; | 175 bool swapped = selection_points_swapped_; |
| 173 selection_points_swapped_ = false; | 176 selection_points_swapped_ = false; |
| 174 return swapped; | 177 return swapped; |
| 175 } | 178 } |
| 176 | 179 |
| 177 const gfx::PointF& GetLastCaretPosition() const { return caret_position_; } | 180 const gfx::PointF& GetLastCaretPosition() const { return caret_position_; } |
| 178 const gfx::PointF& GetLastSelectionStart() const { return selection_start_; } | 181 const gfx::PointF& GetLastSelectionStart() const { return selection_start_; } |
| 179 const gfx::PointF& GetLastSelectionEnd() const { return selection_end_; } | 182 const gfx::PointF& GetLastSelectionEnd() const { return selection_end_; } |
| 180 SelectionEventType GetLastEventType() const { return last_event_; } | |
| 181 const gfx::PointF& GetLastEventAnchor() const { return last_event_start_; } | 183 const gfx::PointF& GetLastEventAnchor() const { return last_event_start_; } |
| 182 | 184 |
| 185 int total_event_count() const { return total_event_count_; } | |
| 186 | |
| 187 int GetAndResetEventCount(SelectionEventType event) { | |
| 188 int count = event_count_[event]; | |
| 189 event_count_.erase(event); | |
| 190 total_event_count_ -= count; | |
| 191 return count; | |
| 192 } | |
| 193 | |
| 183 TouchSelectionController& controller() { return *controller_; } | 194 TouchSelectionController& controller() { return *controller_; } |
| 184 | 195 |
| 185 private: | 196 private: |
| 186 gfx::PointF last_event_start_; | 197 gfx::PointF last_event_start_; |
| 187 gfx::PointF caret_position_; | 198 gfx::PointF caret_position_; |
| 188 gfx::PointF selection_start_; | 199 gfx::PointF selection_start_; |
| 189 gfx::PointF selection_end_; | 200 gfx::PointF selection_end_; |
| 190 SelectionEventType last_event_; | 201 int total_event_count_; |
| 202 std::map<SelectionEventType, int> event_count_; | |
| 191 bool caret_moved_; | 203 bool caret_moved_; |
| 192 bool selection_moved_; | 204 bool selection_moved_; |
| 193 bool selection_points_swapped_; | 205 bool selection_points_swapped_; |
| 194 bool needs_animate_; | 206 bool needs_animate_; |
| 195 bool animation_enabled_; | 207 bool animation_enabled_; |
| 196 bool dragging_enabled_; | 208 bool dragging_enabled_; |
| 197 scoped_ptr<TouchSelectionController> controller_; | 209 scoped_ptr<TouchSelectionController> controller_; |
| 198 }; | 210 }; |
| 199 | 211 |
| 200 TEST_F(TouchSelectionControllerTest, InsertionBasic) { | 212 TEST_F(TouchSelectionControllerTest, InsertionBasic) { |
| 201 gfx::RectF insertion_rect(5, 5, 0, 10); | 213 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 202 bool visible = true; | 214 bool visible = true; |
| 203 | 215 |
| 204 // Insertion events are ignored until automatic showing is enabled. | 216 // Insertion events are ignored until automatic showing is enabled. |
| 205 ChangeInsertion(insertion_rect, visible); | 217 ChangeInsertion(insertion_rect, visible); |
| 218 EXPECT_EQ(0, total_event_count()); | |
| 206 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 219 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 207 controller().OnTapEvent(); | 220 controller().OnTapEvent(); |
| 208 | 221 |
| 209 // Insertion events are ignored until the selection region is marked editable. | 222 // Insertion events are ignored until the selection region is marked editable. |
| 210 ChangeInsertion(insertion_rect, visible); | 223 ChangeInsertion(insertion_rect, visible); |
| 224 EXPECT_EQ(0, total_event_count()); | |
| 211 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 225 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 212 | 226 |
| 213 controller().OnTapEvent(); | 227 controller().OnTapEvent(); |
| 214 controller().OnSelectionEditable(true); | 228 controller().OnSelectionEditable(true); |
| 215 ChangeInsertion(insertion_rect, visible); | 229 ChangeInsertion(insertion_rect, visible); |
| 216 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 230 EXPECT_EQ(1, total_event_count()); |
| 231 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 217 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 232 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 218 | 233 |
| 219 insertion_rect.Offset(1, 0); | 234 insertion_rect.Offset(1, 0); |
| 220 ChangeInsertion(insertion_rect, visible); | 235 ChangeInsertion(insertion_rect, visible); |
| 221 EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); | 236 EXPECT_EQ(1, total_event_count()); |
| 237 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_MOVED)); | |
| 222 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 238 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 223 | 239 |
| 224 insertion_rect.Offset(0, 1); | 240 insertion_rect.Offset(0, 1); |
| 225 ChangeInsertion(insertion_rect, visible); | 241 ChangeInsertion(insertion_rect, visible); |
| 226 EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); | 242 EXPECT_EQ(1, total_event_count()); |
| 243 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_MOVED)); | |
| 227 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 244 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 228 | 245 |
| 229 ClearInsertion(); | 246 ClearInsertion(); |
| 230 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); | 247 EXPECT_EQ(1, total_event_count()); |
| 248 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_CLEARED)); | |
| 231 } | 249 } |
| 232 | 250 |
| 233 TEST_F(TouchSelectionControllerTest, InsertionClearedWhenNoLongerEditable) { | 251 TEST_F(TouchSelectionControllerTest, InsertionClearedWhenNoLongerEditable) { |
| 234 gfx::RectF insertion_rect(5, 5, 0, 10); | 252 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 235 bool visible = true; | 253 bool visible = true; |
| 236 controller().OnTapEvent(); | 254 controller().OnTapEvent(); |
| 237 controller().OnSelectionEditable(true); | 255 controller().OnSelectionEditable(true); |
| 238 | 256 |
| 239 ChangeInsertion(insertion_rect, visible); | 257 ChangeInsertion(insertion_rect, visible); |
| 240 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 258 EXPECT_EQ(1, total_event_count()); |
| 259 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 241 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 260 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 242 | 261 |
| 243 controller().OnSelectionEditable(false); | 262 controller().OnSelectionEditable(false); |
| 244 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); | 263 EXPECT_EQ(1, total_event_count()); |
| 264 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_CLEARED)); | |
| 245 } | 265 } |
| 246 | 266 |
| 247 TEST_F(TouchSelectionControllerTest, InsertionWithNoShowOnTapForEmptyEditable) { | 267 TEST_F(TouchSelectionControllerTest, InsertionWithNoShowOnTapForEmptyEditable) { |
| 248 gfx::RectF insertion_rect(5, 5, 0, 10); | 268 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 249 bool visible = true; | 269 bool visible = true; |
| 250 controller().OnSelectionEditable(true); | 270 controller().OnSelectionEditable(true); |
| 251 | 271 |
| 252 // Taps on an empty editable region should be ignored if the controller is | 272 // Taps on an empty editable region should be ignored if the controller is |
| 253 // created with |show_on_tap_for_empty_editable| set to false. | 273 // created with |show_on_tap_for_empty_editable| set to false. |
| 254 controller().OnTapEvent(); | 274 controller().OnTapEvent(); |
| 255 controller().OnSelectionEmpty(true); | 275 controller().OnSelectionEmpty(true); |
| 256 ChangeInsertion(insertion_rect, visible); | 276 ChangeInsertion(insertion_rect, visible); |
| 257 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 277 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 258 | 278 |
| 259 // Once the region becomes non-empty, taps should show the insertion handle. | 279 // Once the region becomes non-empty, taps should show the insertion handle. |
| 260 controller().OnTapEvent(); | 280 controller().OnTapEvent(); |
| 261 controller().OnSelectionEmpty(false); | 281 controller().OnSelectionEmpty(false); |
| 262 ChangeInsertion(insertion_rect, visible); | 282 ChangeInsertion(insertion_rect, visible); |
| 263 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 283 EXPECT_EQ(1, total_event_count()); |
| 284 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 264 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 285 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 265 | 286 |
| 266 // Reset the selection. | 287 // Reset the selection. |
| 267 controller().HideAndDisallowShowingAutomatically(); | 288 controller().HideAndDisallowShowingAutomatically(); |
| 268 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); | 289 EXPECT_EQ(1, total_event_count()); |
| 290 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_CLEARED)); | |
| 269 | 291 |
| 270 // Long-pressing should show the handle even if the editable region is empty. | 292 // Long-pressing should show the handle even if the editable region is empty. |
| 271 insertion_rect.Offset(2, -2); | 293 insertion_rect.Offset(2, -2); |
| 272 controller().OnLongPressEvent(); | 294 controller().OnLongPressEvent(); |
| 273 controller().OnSelectionEmpty(true); | 295 controller().OnSelectionEmpty(true); |
| 274 ChangeInsertion(insertion_rect, visible); | 296 ChangeInsertion(insertion_rect, visible); |
| 275 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 297 EXPECT_EQ(1, total_event_count()); |
| 298 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 276 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 299 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 277 | 300 |
| 278 // Single Tap on an empty edit field should clear insertion handle. | 301 // Single Tap on an empty edit field should clear insertion handle. |
| 279 controller().OnTapEvent(); | 302 controller().OnTapEvent(); |
| 280 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); | 303 EXPECT_EQ(1, total_event_count()); |
| 304 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_CLEARED)); | |
| 281 } | 305 } |
| 282 | 306 |
| 283 TEST_F(TouchSelectionControllerTest, InsertionWithShowOnTapForEmptyEditable) { | 307 TEST_F(TouchSelectionControllerTest, InsertionWithShowOnTapForEmptyEditable) { |
| 284 AllowShowingOnTapForEmptyEditable(); | 308 AllowShowingOnTapForEmptyEditable(); |
| 285 | 309 |
| 286 gfx::RectF insertion_rect(5, 5, 0, 10); | 310 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 287 bool visible = true; | 311 bool visible = true; |
| 288 controller().OnSelectionEditable(true); | 312 controller().OnSelectionEditable(true); |
| 289 | 313 |
| 290 // Taps on an empty editable region should show the insertion handle if the | 314 // Taps on an empty editable region should show the insertion handle if the |
| 291 // controller is created with |show_on_tap_for_empty_editable| set to true. | 315 // controller is created with |show_on_tap_for_empty_editable| set to true. |
| 292 controller().OnTapEvent(); | 316 controller().OnTapEvent(); |
| 293 controller().OnSelectionEmpty(true); | 317 controller().OnSelectionEmpty(true); |
| 294 ChangeInsertion(insertion_rect, visible); | 318 ChangeInsertion(insertion_rect, visible); |
| 295 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 319 EXPECT_EQ(1, total_event_count()); |
| 320 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 296 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 321 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 297 } | 322 } |
| 298 | 323 |
| 299 TEST_F(TouchSelectionControllerTest, InsertionAppearsAfterTapFollowingTyping) { | 324 TEST_F(TouchSelectionControllerTest, InsertionAppearsAfterTapFollowingTyping) { |
| 300 gfx::RectF insertion_rect(5, 5, 0, 10); | 325 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 301 bool visible = true; | 326 bool visible = true; |
| 302 | 327 |
| 303 // Simulate the user tapping an empty text field. | 328 // Simulate the user tapping an empty text field. |
| 304 controller().OnTapEvent(); | 329 controller().OnTapEvent(); |
| 305 controller().OnSelectionEditable(true); | 330 controller().OnSelectionEditable(true); |
| 306 controller().OnSelectionEmpty(true); | 331 controller().OnSelectionEmpty(true); |
| 307 ChangeInsertion(insertion_rect, visible); | 332 ChangeInsertion(insertion_rect, visible); |
| 308 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 333 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 309 | 334 |
| 310 // Simulate the cursor moving while a user is typing. | 335 // Simulate the cursor moving while a user is typing. |
| 311 insertion_rect.Offset(10, 0); | 336 insertion_rect.Offset(10, 0); |
| 312 controller().OnSelectionEmpty(false); | 337 controller().OnSelectionEmpty(false); |
| 313 ChangeInsertion(insertion_rect, visible); | 338 ChangeInsertion(insertion_rect, visible); |
| 314 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 339 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 315 | 340 |
| 316 // If the user taps the *same* position as the cursor at the end of the text | 341 // If the user taps the *same* position as the cursor at the end of the text |
| 317 // entry, the handle should appear. | 342 // entry, the handle should appear. |
| 318 controller().OnTapEvent(); | 343 controller().OnTapEvent(); |
| 319 ChangeInsertion(insertion_rect, visible); | 344 ChangeInsertion(insertion_rect, visible); |
| 320 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 345 EXPECT_EQ(1, total_event_count()); |
| 346 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 321 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 347 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 322 } | 348 } |
| 323 | 349 |
| 324 TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) { | 350 TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) { |
| 325 controller().OnLongPressEvent(); | 351 controller().OnLongPressEvent(); |
| 326 controller().OnSelectionEditable(true); | 352 controller().OnSelectionEditable(true); |
| 327 | 353 |
| 328 gfx::RectF start_rect(5, 5, 0, 10); | 354 gfx::RectF start_rect(5, 5, 0, 10); |
| 329 gfx::RectF end_rect(50, 5, 0, 10); | 355 gfx::RectF end_rect(50, 5, 0, 10); |
| 330 bool visible = true; | 356 bool visible = true; |
| 331 | 357 |
| 332 ChangeInsertion(start_rect, visible); | 358 ChangeInsertion(start_rect, visible); |
| 333 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 359 EXPECT_EQ(1, total_event_count()); |
| 360 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 334 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 361 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); |
| 335 | 362 |
| 336 ChangeSelection(start_rect, visible, end_rect, visible); | 363 ChangeSelection(start_rect, visible, end_rect, visible); |
| 337 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 364 EXPECT_EQ(2, total_event_count()); |
| 365 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_CLEARED)); | |
| 366 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN)); | |
| 338 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 367 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); |
| 339 | 368 |
| 340 ChangeInsertion(end_rect, visible); | 369 ChangeInsertion(end_rect, visible); |
| 341 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 370 EXPECT_EQ(2, total_event_count()); |
| 371 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_CLEARED)); | |
| 372 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 342 EXPECT_EQ(end_rect.bottom_left(), GetLastEventAnchor()); | 373 EXPECT_EQ(end_rect.bottom_left(), GetLastEventAnchor()); |
| 343 | 374 |
| 344 controller().HideAndDisallowShowingAutomatically(); | 375 controller().HideAndDisallowShowingAutomatically(); |
| 345 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); | 376 EXPECT_EQ(1, total_event_count()); |
| 377 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_CLEARED)); | |
| 346 | 378 |
| 347 controller().OnTapEvent(); | 379 controller().OnTapEvent(); |
| 348 ChangeInsertion(end_rect, visible); | 380 ChangeInsertion(end_rect, visible); |
| 349 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 381 EXPECT_EQ(1, total_event_count()); |
| 382 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 350 EXPECT_EQ(end_rect.bottom_left(), GetLastEventAnchor()); | 383 EXPECT_EQ(end_rect.bottom_left(), GetLastEventAnchor()); |
| 351 } | 384 } |
| 352 | 385 |
| 353 TEST_F(TouchSelectionControllerTest, InsertionDragged) { | 386 TEST_F(TouchSelectionControllerTest, InsertionDragged) { |
| 354 base::TimeTicks event_time = base::TimeTicks::Now(); | 387 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 355 controller().OnTapEvent(); | 388 controller().OnTapEvent(); |
| 356 controller().OnSelectionEditable(true); | 389 controller().OnSelectionEditable(true); |
| 357 | 390 |
| 358 // The touch sequence should not be handled if insertion is not active. | 391 // The touch sequence should not be handled if insertion is not active. |
| 359 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 392 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 360 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 393 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
| 361 | 394 |
| 362 float line_height = 10.f; | 395 float line_height = 10.f; |
| 363 gfx::RectF start_rect(10, 0, 0, line_height); | 396 gfx::RectF start_rect(10, 0, 0, line_height); |
| 364 bool visible = true; | 397 bool visible = true; |
| 365 ChangeInsertion(start_rect, visible); | 398 ChangeInsertion(start_rect, visible); |
| 366 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 399 EXPECT_EQ(1, total_event_count()); |
| 400 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 367 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 401 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); |
| 368 | 402 |
| 369 // The touch sequence should be handled only if the drawable reports a hit. | 403 // The touch sequence should be handled only if the drawable reports a hit. |
| 370 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 404 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
| 371 SetDraggingEnabled(true); | 405 SetDraggingEnabled(true); |
| 372 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 406 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 373 EXPECT_FALSE(GetAndResetCaretMoved()); | 407 EXPECT_FALSE(GetAndResetCaretMoved()); |
| 408 EXPECT_EQ(1, total_event_count()); | |
| 409 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STARTED)); | |
| 374 | 410 |
| 375 // The MoveCaret() result should reflect the movement. | 411 // The MoveCaret() result should reflect the movement. |
| 376 // The reported position is offset from the center of |start_rect|. | 412 // The reported position is offset from the center of |start_rect|. |
| 377 gfx::PointF start_offset = start_rect.CenterPoint(); | 413 gfx::PointF start_offset = start_rect.CenterPoint(); |
| 378 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 5); | 414 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 5); |
| 379 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 415 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 380 EXPECT_TRUE(GetAndResetCaretMoved()); | 416 EXPECT_TRUE(GetAndResetCaretMoved()); |
| 381 EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastCaretPosition()); | 417 EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastCaretPosition()); |
| 382 | 418 |
| 383 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 5, 5); | 419 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 5, 5); |
| 384 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 420 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 385 EXPECT_TRUE(GetAndResetCaretMoved()); | 421 EXPECT_TRUE(GetAndResetCaretMoved()); |
| 386 EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5), GetLastCaretPosition()); | 422 EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5), GetLastCaretPosition()); |
| 387 | 423 |
| 388 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 10, 10); | 424 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 10, 10); |
| 389 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 425 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 390 EXPECT_TRUE(GetAndResetCaretMoved()); | 426 EXPECT_TRUE(GetAndResetCaretMoved()); |
| 391 EXPECT_EQ(start_offset + gfx::Vector2dF(10, 10), GetLastCaretPosition()); | 427 EXPECT_EQ(start_offset + gfx::Vector2dF(10, 10), GetLastCaretPosition()); |
| 392 | 428 |
| 393 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); | 429 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); |
| 394 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 430 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 395 EXPECT_FALSE(GetAndResetCaretMoved()); | 431 EXPECT_FALSE(GetAndResetCaretMoved()); |
| 432 EXPECT_EQ(1, total_event_count()); | |
| 433 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STOPPED)); | |
| 396 | 434 |
| 397 // Once the drag is complete, no more touch events should be consumed until | 435 // Once the drag is complete, no more touch events should be consumed until |
| 398 // the next ACTION_DOWN. | 436 // the next ACTION_DOWN. |
| 399 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 437 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
| 400 } | 438 } |
| 401 | 439 |
| 402 TEST_F(TouchSelectionControllerTest, InsertionTapped) { | 440 TEST_F(TouchSelectionControllerTest, InsertionTapped) { |
| 403 base::TimeTicks event_time = base::TimeTicks::Now(); | 441 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 404 controller().OnTapEvent(); | 442 controller().OnTapEvent(); |
| 405 controller().OnSelectionEditable(true); | 443 controller().OnSelectionEditable(true); |
| 406 SetDraggingEnabled(true); | 444 SetDraggingEnabled(true); |
| 407 | 445 |
| 408 gfx::RectF start_rect(10, 0, 0, 10); | 446 gfx::RectF start_rect(10, 0, 0, 10); |
| 409 bool visible = true; | 447 bool visible = true; |
| 410 ChangeInsertion(start_rect, visible); | 448 ChangeInsertion(start_rect, visible); |
| 411 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 449 EXPECT_EQ(1, total_event_count()); |
| 450 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 412 | 451 |
| 413 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 452 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 414 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 453 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 415 //TODO(AKV): this test case has to be modified once crbug.com/394093 is fixed. | 454 //TODO(AKV): this test case has to be modified once crbug.com/394093 is fixed. |
| 416 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); | 455 EXPECT_EQ(1, total_event_count()); |
| 456 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STARTED)); | |
| 417 | 457 |
| 418 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); | 458 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); |
| 419 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 459 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 420 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); | 460 EXPECT_EQ(2, total_event_count()); |
| 461 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STOPPED)); | |
| 462 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_TAPPED)); | |
| 421 | 463 |
| 422 // Reset the insertion. | 464 // Reset the insertion. |
| 423 ClearInsertion(); | 465 ClearInsertion(); |
| 424 controller().OnTapEvent(); | 466 controller().OnTapEvent(); |
| 425 ChangeInsertion(start_rect, visible); | 467 ChangeInsertion(start_rect, visible); |
| 426 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); | 468 EXPECT_EQ(2, total_event_count()); |
| 469 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_CLEARED)); | |
| 470 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 427 | 471 |
| 428 // No tap should be signalled if the time between DOWN and UP was too long. | 472 // No tap should be signalled if the time between DOWN and UP was too long. |
| 429 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 473 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 430 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 474 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 431 event = MockMotionEvent(MockMotionEvent::ACTION_UP, | 475 event = MockMotionEvent(MockMotionEvent::ACTION_UP, |
| 432 event_time + base::TimeDelta::FromSeconds(1), | 476 event_time + base::TimeDelta::FromSeconds(1), |
| 433 0, | 477 0, |
| 434 0); | 478 0); |
| 435 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 479 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 436 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); | 480 EXPECT_EQ(2, total_event_count()); |
| 481 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STARTED)); | |
| 482 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STOPPED)); | |
| 437 | 483 |
| 438 // Reset the insertion. | 484 // Reset the insertion. |
| 439 ClearInsertion(); | 485 ClearInsertion(); |
| 440 controller().OnTapEvent(); | 486 controller().OnTapEvent(); |
| 441 ChangeInsertion(start_rect, visible); | 487 ChangeInsertion(start_rect, visible); |
| 442 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); | 488 EXPECT_EQ(2, total_event_count()); |
| 489 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_CLEARED)); | |
| 490 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 443 | 491 |
| 444 // No tap should be signalled if the drag was too long. | 492 // No tap should be signalled if the drag was too long. |
| 445 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 493 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 446 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 494 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 447 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 100, 0); | 495 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 100, 0); |
| 448 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 496 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 449 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 100, 0); | 497 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 100, 0); |
| 450 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 498 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 451 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); | 499 EXPECT_EQ(2, total_event_count()); |
| 500 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STARTED)); | |
| 501 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STOPPED)); | |
| 452 | 502 |
| 453 // Reset the insertion. | 503 // Reset the insertion. |
| 454 ClearInsertion(); | 504 ClearInsertion(); |
| 455 controller().OnTapEvent(); | 505 controller().OnTapEvent(); |
| 456 ChangeInsertion(start_rect, visible); | 506 ChangeInsertion(start_rect, visible); |
| 457 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); | 507 EXPECT_EQ(2, total_event_count()); |
| 508 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_CLEARED)); | |
| 509 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 458 | 510 |
| 459 // No tap should be signalled if the touch sequence is cancelled. | 511 // No tap should be signalled if the touch sequence is cancelled. |
| 460 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 512 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 461 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 513 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 462 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); | 514 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); |
| 463 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 515 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 464 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); | 516 EXPECT_EQ(2, total_event_count()); |
| 517 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STARTED)); | |
| 518 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STOPPED)); | |
| 465 } | 519 } |
| 466 | 520 |
| 467 TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) { | 521 TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) { |
| 468 base::TimeTicks event_time = base::TimeTicks::Now(); | 522 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 469 controller().OnTapEvent(); | 523 controller().OnTapEvent(); |
| 470 controller().OnSelectionEditable(true); | 524 controller().OnSelectionEditable(true); |
| 471 SetDraggingEnabled(true); | 525 SetDraggingEnabled(true); |
| 472 | 526 |
| 473 gfx::RectF anchor_rect(10, 0, 0, 10); | 527 gfx::RectF anchor_rect(10, 0, 0, 10); |
| 474 bool visible = true; | 528 bool visible = true; |
| 475 ChangeInsertion(anchor_rect, visible); | 529 ChangeInsertion(anchor_rect, visible); |
| 476 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 530 EXPECT_EQ(1, total_event_count()); |
| 531 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 477 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 532 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
| 478 | 533 |
| 479 // Tapping again shouldn't reset the active insertion point. | 534 // Tapping again shouldn't reset the active insertion point. |
| 480 controller().OnTapEvent(); | 535 controller().OnTapEvent(); |
| 481 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 536 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 482 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 537 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 483 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); | 538 EXPECT_EQ(1, total_event_count()); |
| 539 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STARTED)); | |
| 484 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 540 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
| 485 | 541 |
| 486 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); | 542 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); |
| 487 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 543 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 488 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); | 544 EXPECT_EQ(2, total_event_count()); |
| 545 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_TAPPED)); | |
| 546 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STOPPED)); | |
| 489 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 547 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
| 490 | 548 |
| 491 anchor_rect.Offset(5, 15); | 549 anchor_rect.Offset(5, 15); |
| 492 ChangeInsertion(anchor_rect, visible); | 550 ChangeInsertion(anchor_rect, visible); |
| 493 EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); | 551 EXPECT_EQ(1, total_event_count()); |
| 552 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_MOVED)); | |
| 494 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 553 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
| 495 | 554 |
| 496 // Pressing shouldn't reset the active insertion point. | 555 // Pressing shouldn't reset the active insertion point. |
| 497 controller().OnLongPressEvent(); | 556 controller().OnLongPressEvent(); |
| 498 controller().OnSelectionEmpty(true); | 557 controller().OnSelectionEmpty(true); |
| 499 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 558 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 500 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 559 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 501 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); | 560 EXPECT_EQ(1, total_event_count()); |
| 561 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STARTED)); | |
| 502 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 562 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
| 503 | 563 |
| 504 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); | 564 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); |
| 505 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 565 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 506 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); | 566 EXPECT_EQ(2, total_event_count()); |
|
jdduke (slow)
2015/02/19 22:53:48
This is still too much boiler plate. If we use Gmo
mohsen
2015/02/20 18:16:00
Nice, I was looking for something like that. Pleas
| |
| 567 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_TAPPED)); | |
| 568 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STOPPED)); | |
| 507 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 569 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
| 508 } | 570 } |
| 509 | 571 |
| 510 TEST_F(TouchSelectionControllerTest, SelectionBasic) { | 572 TEST_F(TouchSelectionControllerTest, SelectionBasic) { |
| 511 gfx::RectF start_rect(5, 5, 0, 10); | 573 gfx::RectF start_rect(5, 5, 0, 10); |
| 512 gfx::RectF end_rect(50, 5, 0, 10); | 574 gfx::RectF end_rect(50, 5, 0, 10); |
| 513 bool visible = true; | 575 bool visible = true; |
| 514 | 576 |
| 515 // Selection events are ignored until automatic showing is enabled. | 577 // Selection events are ignored until automatic showing is enabled. |
| 516 ChangeSelection(start_rect, visible, end_rect, visible); | 578 ChangeSelection(start_rect, visible, end_rect, visible); |
| 517 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 579 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 518 | 580 |
| 519 controller().OnLongPressEvent(); | 581 controller().OnLongPressEvent(); |
| 520 ChangeSelection(start_rect, visible, end_rect, visible); | 582 ChangeSelection(start_rect, visible, end_rect, visible); |
| 521 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 583 EXPECT_EQ(1, total_event_count()); |
| 584 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN)); | |
| 522 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 585 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); |
| 523 | 586 |
| 524 start_rect.Offset(1, 0); | 587 start_rect.Offset(1, 0); |
| 525 ChangeSelection(start_rect, visible, end_rect, visible); | 588 ChangeSelection(start_rect, visible, end_rect, visible); |
| 526 // Selection movement does not currently trigger a separate event. | 589 // Selection movement does not currently trigger a separate event. |
| 527 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 590 EXPECT_EQ(0, total_event_count()); |
| 528 | 591 |
| 529 ClearSelection(); | 592 ClearSelection(); |
| 530 EXPECT_EQ(SELECTION_CLEARED, GetLastEventType()); | 593 EXPECT_EQ(1, total_event_count()); |
| 594 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_CLEARED)); | |
| 531 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 595 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 532 } | 596 } |
| 533 | 597 |
| 534 TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) { | 598 TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) { |
| 535 gfx::RectF start_rect(5, 5, 0, 10); | 599 gfx::RectF start_rect(5, 5, 0, 10); |
| 536 gfx::RectF end_rect(50, 5, 0, 10); | 600 gfx::RectF end_rect(50, 5, 0, 10); |
| 537 bool visible = true; | 601 bool visible = true; |
| 538 | 602 |
| 539 controller().OnLongPressEvent(); | 603 controller().OnLongPressEvent(); |
| 540 ChangeSelection(start_rect, visible, end_rect, visible); | 604 ChangeSelection(start_rect, visible, end_rect, visible); |
| 541 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 605 EXPECT_EQ(1, total_event_count()); |
| 606 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN)); | |
| 542 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 607 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); |
| 543 | 608 |
| 544 // A long press triggering a new selection should re-send the SELECTION_SHOWN | 609 // A long press triggering a new selection should re-send the SELECTION_SHOWN |
| 545 // event notification. | 610 // event notification. |
| 546 start_rect.Offset(10, 10); | 611 start_rect.Offset(10, 10); |
| 547 controller().OnLongPressEvent(); | 612 controller().OnLongPressEvent(); |
| 548 ChangeSelection(start_rect, visible, end_rect, visible); | 613 ChangeSelection(start_rect, visible, end_rect, visible); |
| 549 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 614 EXPECT_EQ(1, total_event_count()); |
| 615 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN)); | |
| 550 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 616 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); |
| 551 } | 617 } |
| 552 | 618 |
| 553 TEST_F(TouchSelectionControllerTest, SelectionDragged) { | 619 TEST_F(TouchSelectionControllerTest, SelectionDragged) { |
| 554 base::TimeTicks event_time = base::TimeTicks::Now(); | 620 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 555 controller().OnLongPressEvent(); | 621 controller().OnLongPressEvent(); |
| 556 | 622 |
| 557 // The touch sequence should not be handled if selection is not active. | 623 // The touch sequence should not be handled if selection is not active. |
| 558 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 624 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 559 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 625 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
| 560 | 626 |
| 561 float line_height = 10.f; | 627 float line_height = 10.f; |
| 562 gfx::RectF start_rect(0, 0, 0, line_height); | 628 gfx::RectF start_rect(0, 0, 0, line_height); |
| 563 gfx::RectF end_rect(50, 0, 0, line_height); | 629 gfx::RectF end_rect(50, 0, 0, line_height); |
| 564 bool visible = true; | 630 bool visible = true; |
| 565 ChangeSelection(start_rect, visible, end_rect, visible); | 631 ChangeSelection(start_rect, visible, end_rect, visible); |
| 566 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 632 EXPECT_EQ(1, total_event_count()); |
| 633 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN)); | |
| 567 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 634 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); |
| 568 | 635 |
| 569 // The touch sequence should be handled only if the drawable reports a hit. | 636 // The touch sequence should be handled only if the drawable reports a hit. |
| 570 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 637 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
| 571 SetDraggingEnabled(true); | 638 SetDraggingEnabled(true); |
| 572 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 639 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 573 EXPECT_FALSE(GetAndResetSelectionMoved()); | 640 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 574 | 641 |
| 575 // The SelectBetweenCoordinates() result should reflect the movement. Note | 642 // The SelectBetweenCoordinates() result should reflect the movement. Note |
| 576 // that the start coordinate will always reflect the "fixed" handle's | 643 // that the start coordinate will always reflect the "fixed" handle's |
| 577 // position, in this case the position from |end_rect|. | 644 // position, in this case the position from |end_rect|. |
| 578 // Note that the reported position is offset from the center of the | 645 // Note that the reported position is offset from the center of the |
| 579 // input rects (i.e., the middle of the corresponding text line). | 646 // input rects (i.e., the middle of the corresponding text line). |
| 580 gfx::PointF fixed_offset = end_rect.CenterPoint(); | 647 gfx::PointF fixed_offset = end_rect.CenterPoint(); |
| 581 gfx::PointF start_offset = start_rect.CenterPoint(); | 648 gfx::PointF start_offset = start_rect.CenterPoint(); |
| 582 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 5); | 649 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 5); |
| 583 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 650 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 584 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); | 651 EXPECT_EQ(1, total_event_count()); |
| 652 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STARTED)); | |
| 585 EXPECT_TRUE(GetAndResetSelectionMoved()); | 653 EXPECT_TRUE(GetAndResetSelectionMoved()); |
| 586 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); | 654 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); |
| 587 EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); | 655 EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); |
| 588 | 656 |
| 589 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 5, 5); | 657 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 5, 5); |
| 590 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 658 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 591 EXPECT_TRUE(GetAndResetSelectionMoved()); | 659 EXPECT_TRUE(GetAndResetSelectionMoved()); |
| 592 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); | 660 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); |
| 593 EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5), GetLastSelectionEnd()); | 661 EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5), GetLastSelectionEnd()); |
| 594 | 662 |
| 595 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 10, 5); | 663 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 10, 5); |
| 596 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 664 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 597 EXPECT_TRUE(GetAndResetSelectionMoved()); | 665 EXPECT_TRUE(GetAndResetSelectionMoved()); |
| 598 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); | 666 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); |
| 599 EXPECT_EQ(start_offset + gfx::Vector2dF(10, 5), GetLastSelectionEnd()); | 667 EXPECT_EQ(start_offset + gfx::Vector2dF(10, 5), GetLastSelectionEnd()); |
| 600 | 668 |
| 601 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); | 669 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); |
| 602 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 670 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 603 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); | 671 EXPECT_EQ(1, total_event_count()); |
| 672 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STOPPED)); | |
| 604 EXPECT_FALSE(GetAndResetSelectionMoved()); | 673 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 605 | 674 |
| 606 // Once the drag is complete, no more touch events should be consumed until | 675 // Once the drag is complete, no more touch events should be consumed until |
| 607 // the next ACTION_DOWN. | 676 // the next ACTION_DOWN. |
| 608 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 677 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
| 609 } | 678 } |
| 610 | 679 |
| 611 TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) { | 680 TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) { |
| 612 base::TimeTicks event_time = base::TimeTicks::Now(); | 681 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 613 controller().OnLongPressEvent(); | 682 controller().OnLongPressEvent(); |
| 614 | 683 |
| 615 float line_height = 10.f; | 684 float line_height = 10.f; |
| 616 gfx::RectF start_rect(0, 0, 0, line_height); | 685 gfx::RectF start_rect(0, 0, 0, line_height); |
| 617 gfx::RectF end_rect(50, 0, 0, line_height); | 686 gfx::RectF end_rect(50, 0, 0, line_height); |
| 618 bool visible = true; | 687 bool visible = true; |
| 619 ChangeSelection(start_rect, visible, end_rect, visible); | 688 ChangeSelection(start_rect, visible, end_rect, visible); |
| 620 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 689 EXPECT_EQ(1, total_event_count()); |
| 690 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN)); | |
| 621 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 691 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); |
| 622 | 692 |
| 623 // The ACTION_DOWN should lock to the closest handle. | 693 // The ACTION_DOWN should lock to the closest handle. |
| 624 gfx::PointF end_offset = end_rect.CenterPoint(); | 694 gfx::PointF end_offset = end_rect.CenterPoint(); |
| 625 gfx::PointF fixed_offset = start_rect.CenterPoint(); | 695 gfx::PointF fixed_offset = start_rect.CenterPoint(); |
| 626 float touch_down_x = (end_offset.x() + fixed_offset.x()) / 2 + 1.f; | 696 float touch_down_x = (end_offset.x() + fixed_offset.x()) / 2 + 1.f; |
| 627 MockMotionEvent event( | 697 MockMotionEvent event( |
| 628 MockMotionEvent::ACTION_DOWN, event_time, touch_down_x, 0); | 698 MockMotionEvent::ACTION_DOWN, event_time, touch_down_x, 0); |
| 629 SetDraggingEnabled(true); | 699 SetDraggingEnabled(true); |
| 630 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 700 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 631 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); | 701 EXPECT_EQ(1, total_event_count()); |
| 702 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STARTED)); | |
| 632 EXPECT_FALSE(GetAndResetSelectionMoved()); | 703 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 633 | 704 |
| 634 // Even though the ACTION_MOVE is over the start handle, it should continue | 705 // Even though the ACTION_MOVE is over the start handle, it should continue |
| 635 // targetting the end handle that consumed the ACTION_DOWN. | 706 // targetting the end handle that consumed the ACTION_DOWN. |
| 636 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 0); | 707 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 0); |
| 637 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 708 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 638 EXPECT_TRUE(GetAndResetSelectionMoved()); | 709 EXPECT_TRUE(GetAndResetSelectionMoved()); |
| 639 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); | 710 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); |
| 640 EXPECT_EQ(end_offset - gfx::Vector2dF(touch_down_x, 0), | 711 EXPECT_EQ(end_offset - gfx::Vector2dF(touch_down_x, 0), |
| 641 GetLastSelectionEnd()); | 712 GetLastSelectionEnd()); |
| 642 | 713 |
| 643 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); | 714 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); |
| 644 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 715 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 645 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); | 716 EXPECT_EQ(1, total_event_count()); |
| 717 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STOPPED)); | |
| 646 EXPECT_FALSE(GetAndResetSelectionMoved()); | 718 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 647 } | 719 } |
| 648 | 720 |
| 649 TEST_F(TouchSelectionControllerTest, SelectionDraggedToSwitchBaseAndExtent) { | 721 TEST_F(TouchSelectionControllerTest, SelectionDraggedToSwitchBaseAndExtent) { |
| 650 base::TimeTicks event_time = base::TimeTicks::Now(); | 722 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 651 controller().OnLongPressEvent(); | 723 controller().OnLongPressEvent(); |
| 652 | 724 |
| 653 float line_height = 10.f; | 725 float line_height = 10.f; |
| 654 gfx::RectF start_rect(50, line_height, 0, line_height); | 726 gfx::RectF start_rect(50, line_height, 0, line_height); |
| 655 gfx::RectF end_rect(100, line_height, 0, line_height); | 727 gfx::RectF end_rect(100, line_height, 0, line_height); |
| 656 bool visible = true; | 728 bool visible = true; |
| 657 ChangeSelection(start_rect, visible, end_rect, visible); | 729 ChangeSelection(start_rect, visible, end_rect, visible); |
| 658 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 730 EXPECT_EQ(1, total_event_count()); |
| 731 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN)); | |
| 659 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 732 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); |
| 660 | 733 |
| 661 SetDraggingEnabled(true); | 734 SetDraggingEnabled(true); |
| 662 | 735 |
| 663 // Move the extent, not triggering a swap of points. | 736 // Move the extent, not triggering a swap of points. |
| 664 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, | 737 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, |
| 665 end_rect.x(), end_rect.bottom()); | 738 end_rect.x(), end_rect.bottom()); |
| 666 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 739 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 667 EXPECT_FALSE(GetAndResetSelectionMoved()); | 740 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 668 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); | 741 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); |
| 669 | 742 |
| 670 gfx::PointF base_offset = start_rect.CenterPoint(); | 743 gfx::PointF base_offset = start_rect.CenterPoint(); |
| 671 gfx::PointF extent_offset = end_rect.CenterPoint(); | 744 gfx::PointF extent_offset = end_rect.CenterPoint(); |
| 672 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, | 745 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, |
| 673 end_rect.x(), end_rect.bottom() + 5); | 746 end_rect.x(), end_rect.bottom() + 5); |
| 674 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 747 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 675 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); | 748 EXPECT_EQ(1, total_event_count()); |
| 749 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STARTED)); | |
| 676 EXPECT_TRUE(GetAndResetSelectionMoved()); | 750 EXPECT_TRUE(GetAndResetSelectionMoved()); |
| 677 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); | 751 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); |
| 678 EXPECT_EQ(base_offset, GetLastSelectionStart()); | 752 EXPECT_EQ(base_offset, GetLastSelectionStart()); |
| 679 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); | 753 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); |
| 680 | 754 |
| 681 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); | 755 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); |
| 682 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 756 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 683 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); | 757 EXPECT_EQ(1, total_event_count()); |
| 758 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STOPPED)); | |
| 684 EXPECT_FALSE(GetAndResetSelectionMoved()); | 759 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 685 | 760 |
| 686 end_rect += gfx::Vector2dF(0, 5); | 761 end_rect += gfx::Vector2dF(0, 5); |
| 687 ChangeSelection(start_rect, visible, end_rect, visible); | 762 ChangeSelection(start_rect, visible, end_rect, visible); |
| 688 | 763 |
| 689 // Move the base, triggering a swap of points. | 764 // Move the base, triggering a swap of points. |
| 690 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, | 765 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, |
| 691 start_rect.x(), start_rect.bottom()); | 766 start_rect.x(), start_rect.bottom()); |
| 692 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 767 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 693 EXPECT_FALSE(GetAndResetSelectionMoved()); | 768 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 694 EXPECT_TRUE(GetAndResetSelectionPointsSwapped()); | 769 EXPECT_TRUE(GetAndResetSelectionPointsSwapped()); |
| 695 | 770 |
| 696 base_offset = end_rect.CenterPoint(); | 771 base_offset = end_rect.CenterPoint(); |
| 697 extent_offset = start_rect.CenterPoint(); | 772 extent_offset = start_rect.CenterPoint(); |
| 698 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, | 773 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, |
| 699 start_rect.x(), start_rect.bottom() + 5); | 774 start_rect.x(), start_rect.bottom() + 5); |
| 700 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 775 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 701 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); | 776 EXPECT_EQ(1, total_event_count()); |
| 777 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STARTED)); | |
| 702 EXPECT_TRUE(GetAndResetSelectionMoved()); | 778 EXPECT_TRUE(GetAndResetSelectionMoved()); |
| 703 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); | 779 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); |
| 704 EXPECT_EQ(base_offset, GetLastSelectionStart()); | 780 EXPECT_EQ(base_offset, GetLastSelectionStart()); |
| 705 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); | 781 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); |
| 706 | 782 |
| 707 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); | 783 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); |
| 708 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 784 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 709 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); | 785 EXPECT_EQ(1, total_event_count()); |
| 786 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STOPPED)); | |
| 710 EXPECT_FALSE(GetAndResetSelectionMoved()); | 787 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 711 | 788 |
| 712 start_rect += gfx::Vector2dF(0, 5); | 789 start_rect += gfx::Vector2dF(0, 5); |
| 713 ChangeSelection(start_rect, visible, end_rect, visible); | 790 ChangeSelection(start_rect, visible, end_rect, visible); |
| 714 | 791 |
| 715 // Move the same point again, not triggering a swap of points. | 792 // Move the same point again, not triggering a swap of points. |
| 716 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, | 793 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, |
| 717 start_rect.x(), start_rect.bottom()); | 794 start_rect.x(), start_rect.bottom()); |
| 718 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 795 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 719 EXPECT_FALSE(GetAndResetSelectionMoved()); | 796 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 720 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); | 797 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); |
| 721 | 798 |
| 722 base_offset = end_rect.CenterPoint(); | 799 base_offset = end_rect.CenterPoint(); |
| 723 extent_offset = start_rect.CenterPoint(); | 800 extent_offset = start_rect.CenterPoint(); |
| 724 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, | 801 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, |
| 725 start_rect.x(), start_rect.bottom() + 5); | 802 start_rect.x(), start_rect.bottom() + 5); |
| 726 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 803 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 727 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); | 804 EXPECT_EQ(1, total_event_count()); |
| 805 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STARTED)); | |
| 728 EXPECT_TRUE(GetAndResetSelectionMoved()); | 806 EXPECT_TRUE(GetAndResetSelectionMoved()); |
| 729 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); | 807 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); |
| 730 EXPECT_EQ(base_offset, GetLastSelectionStart()); | 808 EXPECT_EQ(base_offset, GetLastSelectionStart()); |
| 731 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); | 809 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); |
| 732 | 810 |
| 733 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); | 811 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); |
| 734 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 812 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 735 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); | 813 EXPECT_EQ(1, total_event_count()); |
| 814 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STOPPED)); | |
| 736 EXPECT_FALSE(GetAndResetSelectionMoved()); | 815 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 737 | 816 |
| 738 start_rect += gfx::Vector2dF(0, 5); | 817 start_rect += gfx::Vector2dF(0, 5); |
| 739 ChangeSelection(start_rect, visible, end_rect, visible); | 818 ChangeSelection(start_rect, visible, end_rect, visible); |
| 740 | 819 |
| 741 // Move the base, triggering a swap of points. | 820 // Move the base, triggering a swap of points. |
| 742 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, | 821 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, |
| 743 end_rect.x(), end_rect.bottom()); | 822 end_rect.x(), end_rect.bottom()); |
| 744 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 823 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 745 EXPECT_FALSE(GetAndResetSelectionMoved()); | 824 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 746 EXPECT_TRUE(GetAndResetSelectionPointsSwapped()); | 825 EXPECT_TRUE(GetAndResetSelectionPointsSwapped()); |
| 747 | 826 |
| 748 base_offset = start_rect.CenterPoint(); | 827 base_offset = start_rect.CenterPoint(); |
| 749 extent_offset = end_rect.CenterPoint(); | 828 extent_offset = end_rect.CenterPoint(); |
| 750 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, | 829 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, |
| 751 end_rect.x(), end_rect.bottom() + 5); | 830 end_rect.x(), end_rect.bottom() + 5); |
| 752 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 831 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 753 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); | 832 EXPECT_EQ(1, total_event_count()); |
| 833 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STARTED)); | |
| 754 EXPECT_TRUE(GetAndResetSelectionMoved()); | 834 EXPECT_TRUE(GetAndResetSelectionMoved()); |
| 755 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); | 835 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); |
| 756 EXPECT_EQ(base_offset, GetLastSelectionStart()); | 836 EXPECT_EQ(base_offset, GetLastSelectionStart()); |
| 757 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); | 837 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); |
| 758 | 838 |
| 759 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); | 839 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); |
| 760 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 840 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 761 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); | 841 EXPECT_EQ(1, total_event_count()); |
| 842 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STOPPED)); | |
| 762 EXPECT_FALSE(GetAndResetSelectionMoved()); | 843 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 763 } | 844 } |
| 764 | 845 |
| 765 TEST_F(TouchSelectionControllerTest, SelectionDragExtremeLineSize) { | 846 TEST_F(TouchSelectionControllerTest, SelectionDragExtremeLineSize) { |
| 766 base::TimeTicks event_time = base::TimeTicks::Now(); | 847 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 767 controller().OnLongPressEvent(); | 848 controller().OnLongPressEvent(); |
| 768 | 849 |
| 769 float small_line_height = 1.f; | 850 float small_line_height = 1.f; |
| 770 float large_line_height = 50.f; | 851 float large_line_height = 50.f; |
| 771 gfx::RectF small_line_rect(0, 0, 0, small_line_height); | 852 gfx::RectF small_line_rect(0, 0, 0, small_line_height); |
| 772 gfx::RectF large_line_rect(50, 50, 0, large_line_height); | 853 gfx::RectF large_line_rect(50, 50, 0, large_line_height); |
| 773 bool visible = true; | 854 bool visible = true; |
| 774 ChangeSelection(small_line_rect, visible, large_line_rect, visible); | 855 ChangeSelection(small_line_rect, visible, large_line_rect, visible); |
| 775 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 856 EXPECT_EQ(1, total_event_count()); |
| 857 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN)); | |
| 776 EXPECT_EQ(small_line_rect.bottom_left(), GetLastEventAnchor()); | 858 EXPECT_EQ(small_line_rect.bottom_left(), GetLastEventAnchor()); |
| 777 | 859 |
| 778 // Start dragging the handle on the small line. | 860 // Start dragging the handle on the small line. |
| 779 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, | 861 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, |
| 780 small_line_rect.x(), small_line_rect.y()); | 862 small_line_rect.x(), small_line_rect.y()); |
| 781 SetDraggingEnabled(true); | 863 SetDraggingEnabled(true); |
| 782 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 864 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 783 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); | 865 EXPECT_EQ(1, total_event_count()); |
| 866 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STARTED)); | |
| 784 // The drag coordinate for large lines should be capped to a reasonable | 867 // The drag coordinate for large lines should be capped to a reasonable |
| 785 // offset, allowing seamless transition to neighboring lines with different | 868 // offset, allowing seamless transition to neighboring lines with different |
| 786 // sizes. The drag coordinate for small lines should have an offset | 869 // sizes. The drag coordinate for small lines should have an offset |
| 787 // commensurate with the small line size. | 870 // commensurate with the small line size. |
| 788 EXPECT_EQ(large_line_rect.bottom_left() - gfx::Vector2dF(0, 5.f), | 871 EXPECT_EQ(large_line_rect.bottom_left() - gfx::Vector2dF(0, 5.f), |
| 789 GetLastSelectionStart()); | 872 GetLastSelectionStart()); |
| 790 EXPECT_EQ(small_line_rect.CenterPoint(), GetLastSelectionEnd()); | 873 EXPECT_EQ(small_line_rect.CenterPoint(), GetLastSelectionEnd()); |
| 791 | 874 |
| 792 small_line_rect += gfx::Vector2dF(25.f, 0); | 875 small_line_rect += gfx::Vector2dF(25.f, 0); |
| 793 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, | 876 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 852 EXPECT_TRUE(GetAndResetNeedsAnimate()); | 935 EXPECT_TRUE(GetAndResetNeedsAnimate()); |
| 853 } | 936 } |
| 854 | 937 |
| 855 TEST_F(TouchSelectionControllerTest, SelectionClearOnTap) { | 938 TEST_F(TouchSelectionControllerTest, SelectionClearOnTap) { |
| 856 gfx::RectF start_rect(5, 5, 0, 10); | 939 gfx::RectF start_rect(5, 5, 0, 10); |
| 857 gfx::RectF end_rect(50, 5, 0, 10); | 940 gfx::RectF end_rect(50, 5, 0, 10); |
| 858 bool visible = true; | 941 bool visible = true; |
| 859 | 942 |
| 860 controller().OnLongPressEvent(); | 943 controller().OnLongPressEvent(); |
| 861 ChangeSelection(start_rect, visible, end_rect, visible); | 944 ChangeSelection(start_rect, visible, end_rect, visible); |
| 945 EXPECT_EQ(1, total_event_count()); | |
| 946 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN)); | |
| 862 | 947 |
| 863 // Selection should not be cleared if the selection bounds have not changed. | 948 // Selection should not be cleared if the selection bounds have not changed. |
| 864 controller().OnTapEvent(); | 949 controller().OnTapEvent(); |
| 865 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 950 EXPECT_EQ(0, total_event_count()); |
| 866 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 951 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); |
| 867 | 952 |
| 868 controller().OnTapEvent(); | 953 controller().OnTapEvent(); |
| 869 ClearSelection(); | 954 ClearSelection(); |
| 870 EXPECT_EQ(SELECTION_CLEARED, GetLastEventType()); | 955 EXPECT_EQ(1, total_event_count()); |
| 956 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_CLEARED)); | |
| 871 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 957 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 872 } | 958 } |
| 873 | 959 |
| 874 TEST_F(TouchSelectionControllerTest, AllowShowingFromCurrentSelection) { | 960 TEST_F(TouchSelectionControllerTest, AllowShowingFromCurrentSelection) { |
| 875 gfx::RectF start_rect(5, 5, 0, 10); | 961 gfx::RectF start_rect(5, 5, 0, 10); |
| 876 gfx::RectF end_rect(50, 5, 0, 10); | 962 gfx::RectF end_rect(50, 5, 0, 10); |
| 877 bool visible = true; | 963 bool visible = true; |
| 878 | 964 |
| 879 // The selection should not have be activated, as it wasn't yet allowed. | 965 // The selection should not be activated, as it wasn't yet allowed. |
| 880 ChangeSelection(start_rect, visible, end_rect, visible); | 966 ChangeSelection(start_rect, visible, end_rect, visible); |
| 881 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 967 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 882 | 968 |
| 883 // Now explicitly allow showing from the previously supplied bounds. | 969 // Now explicitly allow showing from the previously supplied bounds. |
| 884 controller().AllowShowingFromCurrentSelection(); | 970 controller().AllowShowingFromCurrentSelection(); |
| 885 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 971 EXPECT_EQ(1, total_event_count()); |
| 972 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN)); | |
| 886 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 973 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); |
| 887 | 974 |
| 888 // Repeated calls to show from the current selection should be ignored. | 975 // Repeated calls to show from the current selection should be ignored. |
| 889 controller().AllowShowingFromCurrentSelection(); | 976 controller().AllowShowingFromCurrentSelection(); |
| 890 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 977 EXPECT_EQ(0, total_event_count()); |
| 891 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 978 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); |
| 892 | 979 |
| 893 // Trying to show from an empty selection will have no result. | 980 // Trying to show from an empty selection will have no result. |
| 894 ClearSelection(); | 981 ClearSelection(); |
| 895 EXPECT_EQ(SELECTION_CLEARED, GetLastEventType()); | 982 EXPECT_EQ(1, total_event_count()); |
| 983 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_CLEARED)); | |
| 896 controller().AllowShowingFromCurrentSelection(); | 984 controller().AllowShowingFromCurrentSelection(); |
| 897 EXPECT_EQ(SELECTION_CLEARED, GetLastEventType()); | 985 EXPECT_EQ(0, total_event_count()); |
| 898 | 986 |
| 899 // Showing the insertion handle should also be supported. | 987 // Showing the insertion handle should also be supported. |
| 900 controller().OnSelectionEditable(true); | 988 controller().OnSelectionEditable(true); |
| 901 controller().OnSelectionEmpty(false); | 989 controller().OnSelectionEmpty(false); |
| 902 controller().HideAndDisallowShowingAutomatically(); | 990 controller().HideAndDisallowShowingAutomatically(); |
| 903 gfx::RectF insertion_rect(5, 5, 0, 10); | 991 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 904 ChangeInsertion(insertion_rect, visible); | 992 ChangeInsertion(insertion_rect, visible); |
| 905 controller().AllowShowingFromCurrentSelection(); | 993 controller().AllowShowingFromCurrentSelection(); |
| 906 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 994 EXPECT_EQ(1, total_event_count()); |
| 995 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN)); | |
| 907 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 996 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
| 908 } | 997 } |
| 909 | 998 |
| 910 } // namespace ui | 999 } // namespace ui |
| OLD | NEW |