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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); | 403 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); |
404 | 404 |
405 // No tap should be signalled if the touch sequence is cancelled. | 405 // No tap should be signalled if the touch sequence is cancelled. |
406 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 406 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
407 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 407 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
408 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); | 408 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); |
409 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 409 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
410 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 410 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
411 } | 411 } |
412 | 412 |
| 413 |
| 414 TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) { |
| 415 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 416 controller().OnTapEvent(); |
| 417 controller().OnSelectionEditable(true); |
| 418 SetDraggingEnabled(true); |
| 419 |
| 420 gfx::RectF anchor_rect(10, 0, 0, 10); |
| 421 bool visible = true; |
| 422 ChangeInsertion(anchor_rect, visible); |
| 423 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 424 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
| 425 |
| 426 // Tapping again shouldn't reset the active insertion point. |
| 427 controller().OnTapEvent(); |
| 428 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 429 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 430 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 431 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
| 432 |
| 433 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); |
| 434 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 435 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); |
| 436 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
| 437 |
| 438 anchor_rect.Offset(5, 15); |
| 439 ChangeInsertion(anchor_rect, visible); |
| 440 EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); |
| 441 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
| 442 |
| 443 // Pressing shouldn't reset the active insertion point. |
| 444 controller().OnLongPressEvent(); |
| 445 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 446 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 447 EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); |
| 448 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
| 449 |
| 450 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); |
| 451 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 452 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); |
| 453 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
| 454 } |
| 455 |
413 TEST_F(TouchSelectionControllerTest, SelectionBasic) { | 456 TEST_F(TouchSelectionControllerTest, SelectionBasic) { |
414 gfx::RectF anchor_rect(5, 5, 0, 10); | 457 gfx::RectF anchor_rect(5, 5, 0, 10); |
415 gfx::RectF focus_rect(50, 5, 0, 10); | 458 gfx::RectF focus_rect(50, 5, 0, 10); |
416 bool visible = true; | 459 bool visible = true; |
417 | 460 |
418 // Selection events are ignored until automatic showing is enabled. | 461 // Selection events are ignored until automatic showing is enabled. |
419 ChangeSelection(anchor_rect, visible, focus_rect, visible); | 462 ChangeSelection(anchor_rect, visible, focus_rect, visible); |
420 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 463 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
421 | 464 |
422 controller().OnLongPressEvent(); | 465 controller().OnLongPressEvent(); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 | 582 |
540 visible = true; | 583 visible = true; |
541 ChangeInsertion(insertion_rect, visible); | 584 ChangeInsertion(insertion_rect, visible); |
542 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 585 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
543 | 586 |
544 controller().SetTemporarilyHidden(false); | 587 controller().SetTemporarilyHidden(false); |
545 EXPECT_TRUE(GetAndResetNeedsAnimate()); | 588 EXPECT_TRUE(GetAndResetNeedsAnimate()); |
546 } | 589 } |
547 | 590 |
548 } // namespace content | 591 } // namespace content |
OLD | NEW |