| 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; |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 const int kDefaultTapTimeoutMs = 200; |
| 16 const float kDefaulTapSlop = 10.f; |
| 17 |
| 15 class MockTouchHandleDrawable : public TouchHandleDrawable { | 18 class MockTouchHandleDrawable : public TouchHandleDrawable { |
| 16 public: | 19 public: |
| 17 explicit MockTouchHandleDrawable(bool* contains_point) | 20 explicit MockTouchHandleDrawable(bool* contains_point) |
| 18 : intersects_rect_(contains_point) {} | 21 : intersects_rect_(contains_point) {} |
| 19 virtual ~MockTouchHandleDrawable() {} | 22 virtual ~MockTouchHandleDrawable() {} |
| 20 virtual void SetEnabled(bool enabled) OVERRIDE {} | 23 virtual void SetEnabled(bool enabled) OVERRIDE {} |
| 21 virtual void SetOrientation(TouchHandleOrientation orientation) OVERRIDE {} | 24 virtual void SetOrientation(TouchHandleOrientation orientation) OVERRIDE {} |
| 22 virtual void SetAlpha(float alpha) OVERRIDE {} | 25 virtual void SetAlpha(float alpha) OVERRIDE {} |
| 23 virtual void SetFocus(const gfx::PointF& position) OVERRIDE {} | 26 virtual void SetFocus(const gfx::PointF& position) OVERRIDE {} |
| 24 virtual void SetVisible(bool visible) OVERRIDE {} | 27 virtual void SetVisible(bool visible) OVERRIDE {} |
| (...skipping 15 matching lines...) Expand all Loading... |
| 40 caret_moved_(false), | 43 caret_moved_(false), |
| 41 selection_moved_(false), | 44 selection_moved_(false), |
| 42 needs_animate_(false), | 45 needs_animate_(false), |
| 43 animation_enabled_(true), | 46 animation_enabled_(true), |
| 44 dragging_enabled_(false) {} | 47 dragging_enabled_(false) {} |
| 45 | 48 |
| 46 virtual ~TouchSelectionControllerTest() {} | 49 virtual ~TouchSelectionControllerTest() {} |
| 47 | 50 |
| 48 // testing::Test implementation. | 51 // testing::Test implementation. |
| 49 virtual void SetUp() OVERRIDE { | 52 virtual void SetUp() OVERRIDE { |
| 50 controller_.reset(new TouchSelectionController(this)); | 53 controller_.reset(new TouchSelectionController( |
| 54 this, |
| 55 base::TimeDelta::FromMilliseconds(kDefaultTapTimeoutMs), |
| 56 kDefaulTapSlop)); |
| 51 } | 57 } |
| 52 | 58 |
| 53 virtual void TearDown() OVERRIDE { controller_.reset(); } | 59 virtual void TearDown() OVERRIDE { controller_.reset(); } |
| 54 | 60 |
| 55 // TouchSelectionControllerClient implementation. | 61 // TouchSelectionControllerClient implementation. |
| 56 | 62 |
| 57 virtual bool SupportsAnimation() const OVERRIDE { return animation_enabled_; } | 63 virtual bool SupportsAnimation() const OVERRIDE { return animation_enabled_; } |
| 58 | 64 |
| 59 virtual void SetNeedsAnimate() OVERRIDE { needs_animate_ = true; } | 65 virtual void SetNeedsAnimate() OVERRIDE { needs_animate_ = true; } |
| 60 | 66 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 0); | 390 0); |
| 385 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 391 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 386 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); | 392 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); |
| 387 | 393 |
| 388 // Reset the insertion. | 394 // Reset the insertion. |
| 389 ClearInsertion(); | 395 ClearInsertion(); |
| 390 controller().OnTapEvent(); | 396 controller().OnTapEvent(); |
| 391 ChangeInsertion(start_rect, visible); | 397 ChangeInsertion(start_rect, visible); |
| 392 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); | 398 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 393 | 399 |
| 400 // No tap should be signalled if the drag was too long. |
| 401 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 402 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 403 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 100, 0); |
| 404 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 405 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 100, 0); |
| 406 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 407 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); |
| 408 |
| 409 // Reset the insertion. |
| 410 ClearInsertion(); |
| 411 controller().OnTapEvent(); |
| 412 ChangeInsertion(start_rect, visible); |
| 413 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); |
| 414 |
| 394 // No tap should be signalled if the touch sequence is cancelled. | 415 // No tap should be signalled if the touch sequence is cancelled. |
| 395 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 416 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 396 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 417 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 397 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); | 418 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); |
| 398 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 419 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 399 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); | 420 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); |
| 400 } | 421 } |
| 401 | 422 |
| 402 TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) { | 423 TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) { |
| 403 base::TimeTicks event_time = base::TimeTicks::Now(); | 424 base::TimeTicks event_time = base::TimeTicks::Now(); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); | 670 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); |
| 650 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 671 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); |
| 651 | 672 |
| 652 controller().OnTapEvent(); | 673 controller().OnTapEvent(); |
| 653 ClearSelection(); | 674 ClearSelection(); |
| 654 EXPECT_EQ(SELECTION_CLEARED, GetLastEventType()); | 675 EXPECT_EQ(SELECTION_CLEARED, GetLastEventType()); |
| 655 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 676 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); |
| 656 } | 677 } |
| 657 | 678 |
| 658 } // namespace content | 679 } // namespace content |
| OLD | NEW |