OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/synthetic_gesture_controller.h" | 5 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/test/scoped_task_environment.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "content/browser/renderer_host/input/synthetic_gesture.h" | 16 #include "content/browser/renderer_host/input/synthetic_gesture.h" |
16 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 17 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
17 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h" | 18 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h" |
18 #include "content/browser/renderer_host/input/synthetic_pointer_action.h" | 19 #include "content/browser/renderer_host/input/synthetic_pointer_action.h" |
19 #include "content/browser/renderer_host/input/synthetic_smooth_drag_gesture.h" | 20 #include "content/browser/renderer_host/input/synthetic_smooth_drag_gesture.h" |
20 #include "content/browser/renderer_host/input/synthetic_smooth_move_gesture.h" | 21 #include "content/browser/renderer_host/input/synthetic_smooth_move_gesture.h" |
21 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" | 22 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" |
22 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" | 23 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" |
23 #include "content/browser/renderer_host/input/synthetic_touchpad_pinch_gesture.h
" | 24 #include "content/browser/renderer_host/input/synthetic_touchpad_pinch_gesture.h
" |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 | 669 |
669 private: | 670 private: |
670 // SyntheticGestureController::Delegate: | 671 // SyntheticGestureController::Delegate: |
671 void RequestBeginFrameForSynthesizedInput( | 672 void RequestBeginFrameForSynthesizedInput( |
672 base::OnceClosure callback) override {} | 673 base::OnceClosure callback) override {} |
673 bool HasGestureStopped() override { return true; } | 674 bool HasGestureStopped() override { return true; } |
674 | 675 |
675 DISALLOW_COPY_AND_ASSIGN(DummySyntheticGestureControllerDelegate); | 676 DISALLOW_COPY_AND_ASSIGN(DummySyntheticGestureControllerDelegate); |
676 }; | 677 }; |
677 | 678 |
| 679 } // namespace |
| 680 |
678 class SyntheticGestureControllerTestBase { | 681 class SyntheticGestureControllerTestBase { |
679 public: | 682 public: |
680 SyntheticGestureControllerTestBase() {} | 683 SyntheticGestureControllerTestBase() {} |
681 ~SyntheticGestureControllerTestBase() {} | 684 ~SyntheticGestureControllerTestBase() {} |
682 | 685 |
683 protected: | 686 protected: |
684 template<typename MockGestureTarget> | 687 template<typename MockGestureTarget> |
685 void CreateControllerAndTarget() { | 688 void CreateControllerAndTarget() { |
686 target_ = new MockGestureTarget(); | 689 target_ = new MockGestureTarget(); |
687 controller_ = base::MakeUnique<SyntheticGestureController>( | 690 controller_ = base::MakeUnique<SyntheticGestureController>( |
688 &delegate_, std::unique_ptr<SyntheticGestureTarget>(target_)); | 691 &delegate_, std::unique_ptr<SyntheticGestureTarget>(target_)); |
689 } | 692 } |
690 | 693 |
691 void QueueSyntheticGesture(std::unique_ptr<SyntheticGesture> gesture) { | 694 void QueueSyntheticGesture(std::unique_ptr<SyntheticGesture> gesture) { |
692 controller_->QueueSyntheticGesture( | 695 controller_->QueueSyntheticGesture( |
693 std::move(gesture), | 696 std::move(gesture), |
694 base::Bind( | 697 base::Bind( |
695 &SyntheticGestureControllerTestBase::OnSyntheticGestureCompleted, | 698 &SyntheticGestureControllerTestBase::OnSyntheticGestureCompleted, |
696 base::Unretained(this))); | 699 base::Unretained(this))); |
697 } | 700 } |
698 | 701 |
699 void FlushInputUntilComplete() { | 702 void FlushInputUntilComplete() { |
| 703 // Start and stop the timer explicitly here, since the test does not need to |
| 704 // wait for begin-frame to start the timer. |
| 705 controller_->dispatch_timer_.Start(FROM_HERE, |
| 706 base::TimeDelta::FromSeconds(1), |
| 707 base::Bind(&base::DoNothing)); |
700 do | 708 do |
701 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); | 709 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); |
702 while (controller_->DispatchNextEvent(time_)); | 710 while (controller_->DispatchNextEvent(time_)); |
| 711 controller_->dispatch_timer_.Stop(); |
703 } | 712 } |
704 | 713 |
705 void OnSyntheticGestureCompleted(SyntheticGesture::Result result) { | 714 void OnSyntheticGestureCompleted(SyntheticGesture::Result result) { |
706 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); | 715 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); |
707 if (result == SyntheticGesture::GESTURE_FINISHED) | 716 if (result == SyntheticGesture::GESTURE_FINISHED) |
708 num_success_++; | 717 num_success_++; |
709 else | 718 else |
710 num_failure_++; | 719 num_failure_++; |
711 } | 720 } |
712 | 721 |
713 base::TimeDelta GetTotalTime() const { return time_ - start_time_; } | 722 base::TimeDelta GetTotalTime() const { return time_ - start_time_; } |
714 | 723 |
| 724 base::test::ScopedTaskEnvironment env_; |
715 MockSyntheticGestureTarget* target_; | 725 MockSyntheticGestureTarget* target_; |
716 DummySyntheticGestureControllerDelegate delegate_; | 726 DummySyntheticGestureControllerDelegate delegate_; |
717 std::unique_ptr<SyntheticGestureController> controller_; | 727 std::unique_ptr<SyntheticGestureController> controller_; |
718 base::TimeTicks start_time_; | 728 base::TimeTicks start_time_; |
719 base::TimeTicks time_; | 729 base::TimeTicks time_; |
720 int num_success_; | 730 int num_success_; |
721 int num_failure_; | 731 int num_failure_; |
722 }; | 732 }; |
723 | 733 |
724 class SyntheticGestureControllerTest | 734 class SyntheticGestureControllerTest |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 | 848 |
839 bool finished_1, finished_2; | 849 bool finished_1, finished_2; |
840 std::unique_ptr<MockSyntheticGesture> gesture_1( | 850 std::unique_ptr<MockSyntheticGesture> gesture_1( |
841 new MockSyntheticGesture(&finished_1, 2)); | 851 new MockSyntheticGesture(&finished_1, 2)); |
842 std::unique_ptr<MockSyntheticGesture> gesture_2( | 852 std::unique_ptr<MockSyntheticGesture> gesture_2( |
843 new MockSyntheticGesture(&finished_2, 4)); | 853 new MockSyntheticGesture(&finished_2, 4)); |
844 | 854 |
845 QueueSyntheticGesture(std::move(gesture_1)); | 855 QueueSyntheticGesture(std::move(gesture_1)); |
846 QueueSyntheticGesture(std::move(gesture_2)); | 856 QueueSyntheticGesture(std::move(gesture_2)); |
847 | 857 |
848 do { | 858 FlushInputUntilComplete(); |
849 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); | |
850 } while (controller_->DispatchNextEvent(time_)); | |
851 EXPECT_EQ(2, num_success_); | 859 EXPECT_EQ(2, num_success_); |
852 } | 860 } |
853 | 861 |
854 gfx::Vector2d AddTouchSlopToVector(const gfx::Vector2dF& vector, | 862 gfx::Vector2d AddTouchSlopToVector(const gfx::Vector2dF& vector, |
855 SyntheticGestureTarget* target) { | 863 SyntheticGestureTarget* target) { |
856 const int kTouchSlop = target->GetTouchSlopInDips(); | 864 const int kTouchSlop = target->GetTouchSlopInDips(); |
857 | 865 |
858 int x = vector.x(); | 866 int x = vector.x(); |
859 if (x > 0) | 867 if (x > 0) |
860 x += kTouchSlop; | 868 x += kTouchSlop; |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1754 pointer_mouse_target->reset_num_actions_dispatched(); | 1762 pointer_mouse_target->reset_num_actions_dispatched(); |
1755 FlushInputUntilComplete(); | 1763 FlushInputUntilComplete(); |
1756 | 1764 |
1757 EXPECT_EQ(4, num_success_); | 1765 EXPECT_EQ(4, num_success_); |
1758 EXPECT_EQ(0, num_failure_); | 1766 EXPECT_EQ(0, num_failure_); |
1759 EXPECT_EQ(pointer_mouse_target->num_actions_dispatched(), 4); | 1767 EXPECT_EQ(pointer_mouse_target->num_actions_dispatched(), 4); |
1760 EXPECT_TRUE( | 1768 EXPECT_TRUE( |
1761 pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param, 1)); | 1769 pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param, 1)); |
1762 } | 1770 } |
1763 | 1771 |
1764 } // namespace | |
1765 | |
1766 } // namespace content | 1772 } // namespace content |
OLD | NEW |