| 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> |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 class MockSyntheticGestureTarget : public SyntheticGestureTarget { | 128 class MockSyntheticGestureTarget : public SyntheticGestureTarget { |
| 129 public: | 129 public: |
| 130 MockSyntheticGestureTarget() | 130 MockSyntheticGestureTarget() |
| 131 : flush_requested_(false), | 131 : flush_requested_(false), |
| 132 pointer_assumed_stopped_time_ms_(kPointerAssumedStoppedTimeMs) {} | 132 pointer_assumed_stopped_time_ms_(kPointerAssumedStoppedTimeMs) {} |
| 133 ~MockSyntheticGestureTarget() override {} | 133 ~MockSyntheticGestureTarget() override {} |
| 134 | 134 |
| 135 // SyntheticGestureTarget: | 135 // SyntheticGestureTarget: |
| 136 void DispatchInputEventToPlatform(const WebInputEvent& event) override {} | 136 void DispatchInputEventToPlatform(const WebInputEvent& event) override {} |
| 137 | 137 |
| 138 void SetNeedsFlush() override { flush_requested_ = true; } | |
| 139 | |
| 140 SyntheticGestureParams::GestureSourceType | 138 SyntheticGestureParams::GestureSourceType |
| 141 GetDefaultSyntheticGestureSourceType() const override { | 139 GetDefaultSyntheticGestureSourceType() const override { |
| 142 return SyntheticGestureParams::TOUCH_INPUT; | 140 return SyntheticGestureParams::TOUCH_INPUT; |
| 143 } | 141 } |
| 144 | 142 |
| 145 base::TimeDelta PointerAssumedStoppedTime() const override { | 143 base::TimeDelta PointerAssumedStoppedTime() const override { |
| 146 return base::TimeDelta::FromMilliseconds(pointer_assumed_stopped_time_ms_); | 144 return base::TimeDelta::FromMilliseconds(pointer_assumed_stopped_time_ms_); |
| 147 } | 145 } |
| 148 | 146 |
| 149 void set_pointer_assumed_stopped_time_ms(int time_ms) { | 147 void set_pointer_assumed_stopped_time_ms(int time_ms) { |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 | 662 |
| 665 class SyntheticGestureControllerTestBase { | 663 class SyntheticGestureControllerTestBase { |
| 666 public: | 664 public: |
| 667 SyntheticGestureControllerTestBase() {} | 665 SyntheticGestureControllerTestBase() {} |
| 668 ~SyntheticGestureControllerTestBase() {} | 666 ~SyntheticGestureControllerTestBase() {} |
| 669 | 667 |
| 670 protected: | 668 protected: |
| 671 template<typename MockGestureTarget> | 669 template<typename MockGestureTarget> |
| 672 void CreateControllerAndTarget() { | 670 void CreateControllerAndTarget() { |
| 673 target_ = new MockGestureTarget(); | 671 target_ = new MockGestureTarget(); |
| 674 controller_.reset(new SyntheticGestureController( | 672 controller_ = base::MakeUnique<SyntheticGestureController>( |
| 675 std::unique_ptr<SyntheticGestureTarget>(target_))); | 673 std::unique_ptr<SyntheticGestureTarget>(target_), |
| 674 base::Bind([](base::OnceClosure callback) {})); |
| 676 } | 675 } |
| 677 | 676 |
| 678 void QueueSyntheticGesture(std::unique_ptr<SyntheticGesture> gesture) { | 677 void QueueSyntheticGesture(std::unique_ptr<SyntheticGesture> gesture) { |
| 679 controller_->QueueSyntheticGesture( | 678 controller_->QueueSyntheticGesture( |
| 680 std::move(gesture), | 679 std::move(gesture), |
| 681 base::Bind( | 680 base::Bind( |
| 682 &SyntheticGestureControllerTestBase::OnSyntheticGestureCompleted, | 681 &SyntheticGestureControllerTestBase::OnSyntheticGestureCompleted, |
| 683 base::Unretained(this))); | 682 base::Unretained(this))); |
| 684 } | 683 } |
| 685 | 684 |
| 686 void FlushInputUntilComplete() { | 685 void FlushInputUntilComplete() { |
| 687 while (target_->flush_requested()) { | 686 do |
| 688 while (target_->flush_requested()) { | 687 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); |
| 689 target_->ClearFlushRequest(); | 688 while (controller_->DispatchNextEvent(time_)); |
| 690 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); | |
| 691 controller_->Flush(time_); | |
| 692 } | |
| 693 controller_->OnDidFlushInput(); | |
| 694 } | |
| 695 } | 689 } |
| 696 | 690 |
| 697 void OnSyntheticGestureCompleted(SyntheticGesture::Result result) { | 691 void OnSyntheticGestureCompleted(SyntheticGesture::Result result) { |
| 698 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); | 692 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); |
| 699 if (result == SyntheticGesture::GESTURE_FINISHED) | 693 if (result == SyntheticGesture::GESTURE_FINISHED) |
| 700 num_success_++; | 694 num_success_++; |
| 701 else | 695 else |
| 702 num_failure_++; | 696 num_failure_++; |
| 703 } | 697 } |
| 704 | 698 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 | 823 |
| 830 bool finished_1, finished_2; | 824 bool finished_1, finished_2; |
| 831 std::unique_ptr<MockSyntheticGesture> gesture_1( | 825 std::unique_ptr<MockSyntheticGesture> gesture_1( |
| 832 new MockSyntheticGesture(&finished_1, 2)); | 826 new MockSyntheticGesture(&finished_1, 2)); |
| 833 std::unique_ptr<MockSyntheticGesture> gesture_2( | 827 std::unique_ptr<MockSyntheticGesture> gesture_2( |
| 834 new MockSyntheticGesture(&finished_2, 4)); | 828 new MockSyntheticGesture(&finished_2, 4)); |
| 835 | 829 |
| 836 QueueSyntheticGesture(std::move(gesture_1)); | 830 QueueSyntheticGesture(std::move(gesture_1)); |
| 837 QueueSyntheticGesture(std::move(gesture_2)); | 831 QueueSyntheticGesture(std::move(gesture_2)); |
| 838 | 832 |
| 839 while (target_->flush_requested()) { | 833 do { |
| 840 target_->ClearFlushRequest(); | |
| 841 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); | 834 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); |
| 842 controller_->Flush(time_); | 835 } while (controller_->DispatchNextEvent(time_)); |
| 843 } | |
| 844 EXPECT_EQ(0, num_success_); | |
| 845 controller_->OnDidFlushInput(); | |
| 846 EXPECT_EQ(1, num_success_); | |
| 847 | |
| 848 while (target_->flush_requested()) { | |
| 849 target_->ClearFlushRequest(); | |
| 850 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); | |
| 851 controller_->Flush(time_); | |
| 852 } | |
| 853 EXPECT_EQ(1, num_success_); | |
| 854 controller_->OnDidFlushInput(); | |
| 855 EXPECT_EQ(2, num_success_); | 836 EXPECT_EQ(2, num_success_); |
| 856 } | 837 } |
| 857 | 838 |
| 858 gfx::Vector2d AddTouchSlopToVector(const gfx::Vector2dF& vector, | 839 gfx::Vector2d AddTouchSlopToVector(const gfx::Vector2dF& vector, |
| 859 SyntheticGestureTarget* target) { | 840 SyntheticGestureTarget* target) { |
| 860 const int kTouchSlop = target->GetTouchSlopInDips(); | 841 const int kTouchSlop = target->GetTouchSlopInDips(); |
| 861 | 842 |
| 862 int x = vector.x(); | 843 int x = vector.x(); |
| 863 if (x > 0) | 844 if (x > 0) |
| 864 x += kTouchSlop; | 845 x += kTouchSlop; |
| (...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1761 EXPECT_EQ(4, num_success_); | 1742 EXPECT_EQ(4, num_success_); |
| 1762 EXPECT_EQ(0, num_failure_); | 1743 EXPECT_EQ(0, num_failure_); |
| 1763 EXPECT_EQ(pointer_mouse_target->num_actions_dispatched(), 4); | 1744 EXPECT_EQ(pointer_mouse_target->num_actions_dispatched(), 4); |
| 1764 EXPECT_TRUE( | 1745 EXPECT_TRUE( |
| 1765 pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param, 1)); | 1746 pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param, 1)); |
| 1766 } | 1747 } |
| 1767 | 1748 |
| 1768 } // namespace | 1749 } // namespace |
| 1769 | 1750 |
| 1770 } // namespace content | 1751 } // namespace content |
| OLD | NEW |