OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/input/touch_selection_controller.h" | 5 #include "content/browser/renderer_host/input/touch_selection_controller.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/events/test/mock_motion_event.h" | 8 #include "ui/events/test/mock_motion_event.h" |
9 | 9 |
10 using ui::test::MockMotionEvent; | 10 using ui::test::MockMotionEvent; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 void SetAnimationEnabled(bool enabled) { animation_enabled_ = enabled; } | 84 void SetAnimationEnabled(bool enabled) { animation_enabled_ = enabled; } |
85 void SetDraggingEnabled(bool enabled) { dragging_enabled_ = enabled; } | 85 void SetDraggingEnabled(bool enabled) { dragging_enabled_ = enabled; } |
86 | 86 |
87 void ClearSelection() { | 87 void ClearSelection() { |
88 controller_->OnSelectionBoundsChanged(gfx::RectF(), | 88 controller_->OnSelectionBoundsChanged(gfx::RectF(), |
89 TOUCH_HANDLE_ORIENTATION_UNDEFINED, | 89 TOUCH_HANDLE_ORIENTATION_UNDEFINED, |
90 false, | 90 false, |
91 gfx::RectF(), | 91 gfx::RectF(), |
92 TOUCH_HANDLE_ORIENTATION_UNDEFINED, | 92 TOUCH_HANDLE_ORIENTATION_UNDEFINED, |
93 false); | 93 false); |
94 controller().HideAndDisallowShowingAutomatically(); | |
jdduke (slow)
2014/08/02 13:11:12
This is not OK, you just completely changed the se
AKVT
2014/08/02 13:16:53
Without this even after calling clearSelection() E
jdduke (slow)
2014/08/02 14:23:00
Which test? If a drag is in-progress the "clearing
AKVT
2014/08/04 13:45:32
Corrected the source code to counter measure the c
| |
94 } | 95 } |
95 | 96 |
96 void ClearInsertion() { ClearSelection(); } | 97 void ClearInsertion() { ClearSelection(); } |
97 | 98 |
98 void ChangeInsertion(const gfx::RectF& rect, | 99 void ChangeInsertion(const gfx::RectF& rect, |
99 TouchHandleOrientation orientation, | 100 TouchHandleOrientation orientation, |
100 bool visible) { | 101 bool visible) { |
101 controller_->OnSelectionBoundsChanged( | 102 controller_->OnSelectionBoundsChanged( |
102 rect, orientation, visible, rect, orientation, visible); | 103 rect, orientation, visible, rect, orientation, visible); |
103 } | 104 } |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 } | 314 } |
314 | 315 |
315 TEST_F(TouchSelectionControllerTest, InsertionDragged) { | 316 TEST_F(TouchSelectionControllerTest, InsertionDragged) { |
316 base::TimeTicks event_time = base::TimeTicks::Now(); | 317 base::TimeTicks event_time = base::TimeTicks::Now(); |
317 controller().OnTapEvent(); | 318 controller().OnTapEvent(); |
318 controller().OnSelectionEditable(true); | 319 controller().OnSelectionEditable(true); |
319 | 320 |
320 // The touch sequence should not be handled if insertion is not active. | 321 // The touch sequence should not be handled if insertion is not active. |
321 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 322 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
322 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 323 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
324 EXPECT_EQ(SELECTION_CLEARED, GetLastEventType()); | |
jdduke (slow)
2014/08/02 13:11:12
No need to check this it's just confusing.
AKVT
2014/08/04 13:45:32
Done.
| |
323 | 325 |
324 float line_height = 10.f; | 326 float line_height = 10.f; |
325 gfx::RectF start_rect(10, 0, 0, line_height); | 327 gfx::RectF start_rect(10, 0, 0, line_height); |
326 bool visible = true; | 328 bool visible = true; |
327 ChangeInsertion(start_rect, visible); | 329 ChangeInsertion(start_rect, visible); |
328 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 330 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
329 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 331 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); |
330 | 332 |
331 // The touch sequence should be handled only if the drawable reports a hit. | 333 // The touch sequence should be handled only if the drawable reports a hit. |
332 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 334 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 controller().OnSelectionEditable(true); | 369 controller().OnSelectionEditable(true); |
368 SetDraggingEnabled(true); | 370 SetDraggingEnabled(true); |
369 | 371 |
370 gfx::RectF start_rect(10, 0, 0, 10); | 372 gfx::RectF start_rect(10, 0, 0, 10); |
371 bool visible = true; | 373 bool visible = true; |
372 ChangeInsertion(start_rect, visible); | 374 ChangeInsertion(start_rect, visible); |
373 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 375 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
374 | 376 |
375 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 377 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
376 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 378 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
377 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 379 //TODO(AKV): this test case has to be modified once crbug.com/394093 is fixed. |
380 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); | |
378 | 381 |
379 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); | 382 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); |
380 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 383 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
381 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); | 384 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); |
382 | 385 |
383 // Reset the insertion. | 386 // Reset the insertion. |
384 ClearInsertion(); | 387 ClearInsertion(); |
385 controller().OnTapEvent(); | 388 controller().OnTapEvent(); |
386 ChangeInsertion(start_rect, visible); | 389 ChangeInsertion(start_rect, visible); |
387 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); | 390 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); |
388 | 391 |
389 // No tap should be signalled if the time between DOWN and UP was too long. | 392 // No tap should be signalled if the time between DOWN and UP was too long. |
390 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 393 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
391 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 394 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
392 event = MockMotionEvent(MockMotionEvent::ACTION_UP, | 395 event = MockMotionEvent(MockMotionEvent::ACTION_UP, |
393 event_time + base::TimeDelta::FromSeconds(1), | 396 event_time + base::TimeDelta::FromSeconds(1), |
394 0, | 397 0, |
395 0); | 398 0); |
396 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 399 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
397 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 400 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); |
398 | 401 |
399 // Reset the insertion. | 402 // Reset the insertion. |
400 ClearInsertion(); | 403 ClearInsertion(); |
401 controller().OnTapEvent(); | 404 controller().OnTapEvent(); |
402 ChangeInsertion(start_rect, visible); | 405 ChangeInsertion(start_rect, visible); |
403 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); | 406 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); |
404 | 407 |
405 // No tap should be signalled if the touch sequence is cancelled. | 408 // No tap should be signalled if the touch sequence is cancelled. |
406 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 409 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
407 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 410 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
408 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); | 411 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); |
409 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 412 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
410 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 413 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); |
411 } | 414 } |
412 | 415 |
413 TEST_F(TouchSelectionControllerTest, SelectionBasic) { | 416 TEST_F(TouchSelectionControllerTest, SelectionBasic) { |
414 gfx::RectF start_rect(5, 5, 0, 10); | 417 gfx::RectF start_rect(5, 5, 0, 10); |
415 gfx::RectF end_rect(50, 5, 0, 10); | 418 gfx::RectF end_rect(50, 5, 0, 10); |
416 bool visible = true; | 419 bool visible = true; |
417 | 420 |
418 // Selection events are ignored until automatic showing is enabled. | 421 // Selection events are ignored until automatic showing is enabled. |
419 ChangeSelection(start_rect, visible, end_rect, visible); | 422 ChangeSelection(start_rect, visible, end_rect, visible); |
420 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 423 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 | 578 |
576 visible = true; | 579 visible = true; |
577 ChangeInsertion(insertion_rect, visible); | 580 ChangeInsertion(insertion_rect, visible); |
578 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 581 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
579 | 582 |
580 controller().SetTemporarilyHidden(false); | 583 controller().SetTemporarilyHidden(false); |
581 EXPECT_TRUE(GetAndResetNeedsAnimate()); | 584 EXPECT_TRUE(GetAndResetNeedsAnimate()); |
582 } | 585 } |
583 | 586 |
584 } // namespace content | 587 } // namespace content |
OLD | NEW |