diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-02-02 12:21:57 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-02-12 08:13:00 +0000 |
commit | 606d85f2a5386472314d39923da28c70c60dc8e7 (patch) | |
tree | a8f4d7bf997f349f45605e6058259fba0630e4d7 /chromium/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc | |
parent | 5786336dda477d04fb98483dca1a5426eebde2d7 (diff) | |
download | qtwebengine-chromium-606d85f2a5386472314d39923da28c70c60dc8e7.tar.gz |
BASELINE: Update Chromium to 96.0.4664.181
Change-Id: I762cd1da89d73aa6313b4a753fe126c34833f046
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc')
-rw-r--r-- | chromium/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc | 233 |
1 files changed, 222 insertions, 11 deletions
diff --git a/chromium/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc b/chromium/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc index f532add7956..e884b699c0c 100644 --- a/chromium/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc +++ b/chromium/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc @@ -159,7 +159,11 @@ class MockSyntheticGestureTarget : public SyntheticGestureTarget { ~MockSyntheticGestureTarget() override {} // SyntheticGestureTarget: - void DispatchInputEventToPlatform(const WebInputEvent& event) override {} + void DispatchInputEventToPlatform(const WebInputEvent& event) override { + if (!(event.GetModifiers() & blink::WebInputEvent::kFromDebugger)) { + all_from_debugger_ = false; + } + } content::mojom::GestureSourceType GetDefaultSyntheticGestureSourceType() const override { @@ -167,7 +171,7 @@ class MockSyntheticGestureTarget : public SyntheticGestureTarget { } base::TimeDelta PointerAssumedStoppedTime() const override { - return base::TimeDelta::FromMilliseconds(pointer_assumed_stopped_time_ms_); + return base::Milliseconds(pointer_assumed_stopped_time_ms_); } void set_pointer_assumed_stopped_time_ms(int time_ms) { @@ -196,10 +200,13 @@ class MockSyntheticGestureTarget : public SyntheticGestureTarget { std::move(callback).Run(); } + bool all_from_debugger() { return all_from_debugger_; } + private: bool flush_requested_; int pointer_assumed_stopped_time_ms_; + bool all_from_debugger_ = true; }; class MockMoveGestureTarget : public MockSyntheticGestureTarget { @@ -230,6 +237,7 @@ class MockScrollMouseTarget : public MockMoveGestureTarget { ~MockScrollMouseTarget() override {} void DispatchInputEventToPlatform(const WebInputEvent& event) override { + MockSyntheticGestureTarget::DispatchInputEventToPlatform(event); ASSERT_EQ(event.GetType(), WebInputEvent::Type::kMouseWheel); const WebMouseWheelEvent& mouse_wheel_event = static_cast<const WebMouseWheelEvent&>(event); @@ -246,6 +254,7 @@ class MockMoveTouchTarget : public MockMoveGestureTarget { ~MockMoveTouchTarget() override {} void DispatchInputEventToPlatform(const WebInputEvent& event) override { + MockSyntheticGestureTarget::DispatchInputEventToPlatform(event); ASSERT_TRUE(WebInputEvent::IsTouchEventType(event.GetType())); const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); ASSERT_EQ(touch_event.touches_length, 1U); @@ -282,6 +291,7 @@ class MockFlingGestureTarget : public MockMoveGestureTarget { ~MockFlingGestureTarget() override {} void DispatchInputEventToPlatform(const WebInputEvent& event) override { + MockSyntheticGestureTarget::DispatchInputEventToPlatform(event); if (event.GetType() == WebInputEvent::Type::kGestureFlingStart) { const blink::WebGestureEvent& gesture_event = static_cast<const blink::WebGestureEvent&>(event); @@ -304,6 +314,7 @@ class MockDragMouseTarget : public MockMoveGestureTarget { ~MockDragMouseTarget() override {} void DispatchInputEventToPlatform(const WebInputEvent& event) override { + MockSyntheticGestureTarget::DispatchInputEventToPlatform(event); ASSERT_TRUE(WebInputEvent::IsMouseEventType(event.GetType())); const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); if (!started_) { @@ -348,6 +359,7 @@ class MockSyntheticTouchscreenPinchTouchTarget ~MockSyntheticTouchscreenPinchTouchTarget() override {} void DispatchInputEventToPlatform(const WebInputEvent& event) override { + MockSyntheticGestureTarget::DispatchInputEventToPlatform(event); ASSERT_TRUE(WebInputEvent::IsTouchEventType(event.GetType())); const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); ASSERT_EQ(touch_event.touches_length, 2U); @@ -439,6 +451,7 @@ class MockSyntheticTouchpadPinchTouchTarget ~MockSyntheticTouchpadPinchTouchTarget() override {} void DispatchInputEventToPlatform(const WebInputEvent& event) override { + MockSyntheticGestureTarget::DispatchInputEventToPlatform(event); EXPECT_TRUE(WebInputEvent::IsGestureEventType(event.GetType())); const blink::WebGestureEvent& gesture_event = static_cast<const blink::WebGestureEvent&>(event); @@ -517,6 +530,7 @@ class MockSyntheticTapTouchTarget : public MockSyntheticTapGestureTarget { ~MockSyntheticTapTouchTarget() override {} void DispatchInputEventToPlatform(const WebInputEvent& event) override { + MockSyntheticGestureTarget::DispatchInputEventToPlatform(event); ASSERT_TRUE(WebInputEvent::IsTouchEventType(event.GetType())); const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); ASSERT_EQ(touch_event.touches_length, 1U); @@ -548,6 +562,7 @@ class MockSyntheticTapMouseTarget : public MockSyntheticTapGestureTarget { ~MockSyntheticTapMouseTarget() override {} void DispatchInputEventToPlatform(const WebInputEvent& event) override { + MockSyntheticGestureTarget::DispatchInputEventToPlatform(event); ASSERT_TRUE(WebInputEvent::IsMouseEventType(event.GetType())); const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); @@ -600,6 +615,7 @@ class MockSyntheticPointerTouchActionTarget ~MockSyntheticPointerTouchActionTarget() override {} void DispatchInputEventToPlatform(const WebInputEvent& event) override { + MockSyntheticGestureTarget::DispatchInputEventToPlatform(event); DCHECK(WebInputEvent::IsTouchEventType(event.GetType())); const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); type_ = touch_event.GetType(); @@ -674,6 +690,7 @@ class MockSyntheticPointerMouseActionTarget ~MockSyntheticPointerMouseActionTarget() override {} void DispatchInputEventToPlatform(const WebInputEvent& event) override { + MockSyntheticGestureTarget::DispatchInputEventToPlatform(event); ASSERT_TRUE(WebInputEvent::IsMouseEventType(event.GetType())); const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); type_ = mouse_event.GetType(); @@ -750,13 +767,17 @@ class DummySyntheticGestureControllerDelegate : public SyntheticGestureController::Delegate { public: DummySyntheticGestureControllerDelegate() {} + + DummySyntheticGestureControllerDelegate( + const DummySyntheticGestureControllerDelegate&) = delete; + DummySyntheticGestureControllerDelegate& operator=( + const DummySyntheticGestureControllerDelegate&) = delete; + ~DummySyntheticGestureControllerDelegate() override {} private: // SyntheticGestureController::Delegate: bool HasGestureStopped() override { return true; } - - DISALLOW_COPY_AND_ASSIGN(DummySyntheticGestureControllerDelegate); }; } // namespace @@ -785,10 +806,10 @@ class SyntheticGestureControllerTestBase { void FlushInputUntilComplete() { // Start and stop the timer explicitly here, since the test does not need to // wait for begin-frame to start the timer. - controller_->dispatch_timer_.Start( - FROM_HERE, base::TimeDelta::FromSeconds(1), base::DoNothing()); + controller_->dispatch_timer_.Start(FROM_HERE, base::Seconds(1), + base::DoNothing()); do - time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); + time_ += base::Milliseconds(kFlushInputRateInMs); while (controller_->DispatchNextEvent(time_)); controller_->dispatch_timer_.Stop(); } @@ -1142,6 +1163,29 @@ TEST_P(SyntheticGestureControllerTestWithParam, EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_target->start_to_end_distance()); } +TEST_P(SyntheticGestureControllerTestWithParam, + SingleScrollGestureTouchFromDebugger) { + CreateControllerAndTarget<MockMoveTouchTarget>(); + + SyntheticSmoothMoveGestureParams params; + params.from_devtools_debugger = true; + params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; + if (GetParam() == TOUCH_DRAG) { + params.add_slop = false; + } + params.start_point.SetPoint(89, 32); + params.distances.push_back(gfx::Vector2d(0, 123)); + + std::unique_ptr<SyntheticSmoothMoveGesture> gesture( + new SyntheticSmoothMoveGesture(params)); + QueueSyntheticGesture(std::move(gesture)); + FlushInputUntilComplete(); + + EXPECT_EQ(1, num_success_); + EXPECT_EQ(0, num_failure_); + EXPECT_TRUE(target_->all_from_debugger()); +} + TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseVertical) { CreateControllerAndTarget<MockScrollMouseTarget>(); @@ -1316,6 +1360,25 @@ TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseScrollByPage) { EXPECT_EQ(params.granularity, scroll_target->granularity()); } +TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseFromDebugger) { + CreateControllerAndTarget<MockScrollMouseTarget>(); + + SyntheticSmoothMoveGestureParams params; + params.from_devtools_debugger = true; + params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT; + params.start_point.SetPoint(432, 89); + params.distances.push_back(gfx::Vector2d(0, -234)); + + std::unique_ptr<SyntheticSmoothMoveGesture> gesture( + new SyntheticSmoothMoveGesture(params)); + QueueSyntheticGesture(std::move(gesture)); + FlushInputUntilComplete(); + + EXPECT_EQ(1, num_success_); + EXPECT_EQ(0, num_failure_); + EXPECT_TRUE(target_->all_from_debugger()); +} + void CheckIsWithinRangeMulti(float scroll_distance, int target_distance, SyntheticGestureTarget* target) { @@ -1480,6 +1543,23 @@ TEST_F(SyntheticGestureControllerTest, } TEST_F(SyntheticGestureControllerTest, + SyntheticSmoothDragTestUsingSingleMouseDragFromDebugger) { + CreateControllerAndTarget<MockDragMouseTarget>(); + + SyntheticSmoothDragGestureParams params; + params.from_devtools_debugger = true; + params.gesture_source_type = content::mojom::GestureSourceType::kMouseInput; + params.distances.push_back(gfx::Vector2d(234, 133)); + params.speed_in_pixels_s = 800; + + std::unique_ptr<SyntheticSmoothDragGesture> gesture( + new SyntheticSmoothDragGesture(params)); + const base::TimeTicks timestamp; + gesture->ForwardInputEvents(timestamp, target_); + EXPECT_TRUE(target_->all_from_debugger()); +} + +TEST_F(SyntheticGestureControllerTest, SyntheticSmoothDragTestUsingSingleTouchDrag) { CreateControllerAndTarget<MockMoveTouchTarget>(); @@ -1496,6 +1576,24 @@ TEST_F(SyntheticGestureControllerTest, } TEST_F(SyntheticGestureControllerTest, + SyntheticSmoothDragTestUsingSingleTouchDragFromDebugger) { + CreateControllerAndTarget<MockMoveTouchTarget>(); + + SyntheticSmoothDragGestureParams params; + params.from_devtools_debugger = true; + params.gesture_source_type = content::mojom::GestureSourceType::kTouchInput; + params.start_point.SetPoint(89, 32); + params.distances.push_back(gfx::Vector2d(0, 123)); + params.speed_in_pixels_s = 800; + + std::unique_ptr<SyntheticSmoothDragGesture> gesture( + new SyntheticSmoothDragGesture(params)); + const base::TimeTicks timestamp; + gesture->ForwardInputEvents(timestamp, target_); + EXPECT_TRUE(target_->all_from_debugger()); +} + +TEST_F(SyntheticGestureControllerTest, SyntheticSmoothScrollTestUsingSingleTouchScroll) { CreateControllerAndTarget<MockMoveTouchTarget>(); @@ -1509,6 +1607,26 @@ TEST_F(SyntheticGestureControllerTest, } TEST_F(SyntheticGestureControllerTest, + SyntheticSmoothScrollTestUsingSingleTouchScrollFromDebugger) { + CreateControllerAndTarget<MockMoveTouchTarget>(); + + SyntheticSmoothScrollGestureParams params; + params.from_devtools_debugger = true; + params.gesture_source_type = content::mojom::GestureSourceType::kTouchInput; + params.anchor.SetPoint(432, 89); + params.distances.push_back(gfx::Vector2d(0, -234)); + params.speed_in_pixels_s = 800; + + std::unique_ptr<SyntheticSmoothScrollGesture> gesture( + new SyntheticSmoothScrollGesture(params)); + QueueSyntheticGesture(std::move(gesture)); + FlushInputUntilComplete(); + EXPECT_EQ(1, num_success_); + EXPECT_EQ(0, num_failure_); + EXPECT_TRUE(target_->all_from_debugger()); +} + +TEST_F(SyntheticGestureControllerTest, SyntheticSmoothScrollTestUsingSingleMouseScroll) { CreateControllerAndTarget<MockScrollMouseTarget>(); @@ -1525,6 +1643,26 @@ TEST_F(SyntheticGestureControllerTest, } TEST_F(SyntheticGestureControllerTest, + SyntheticSmoothScrollTestUsingSingleMouseScrollFromDebugger) { + CreateControllerAndTarget<MockScrollMouseTarget>(); + + SyntheticSmoothScrollGestureParams params; + params.from_devtools_debugger = true; + params.gesture_source_type = content::mojom::GestureSourceType::kMouseInput; + params.anchor.SetPoint(432, 89); + params.distances.push_back(gfx::Vector2d(0, -234)); + params.speed_in_pixels_s = 800; + + std::unique_ptr<SyntheticSmoothScrollGesture> gesture( + new SyntheticSmoothScrollGesture(params)); + QueueSyntheticGesture(std::move(gesture)); + FlushInputUntilComplete(); + EXPECT_EQ(1, num_success_); + EXPECT_EQ(0, num_failure_); + EXPECT_TRUE(target_->all_from_debugger()); +} + +TEST_F(SyntheticGestureControllerTest, TouchscreenTouchpadPinchGestureTouchZoomIn) { CreateControllerAndTarget<MockSyntheticTouchscreenPinchTouchTarget>(); @@ -1592,6 +1730,26 @@ TEST_F(SyntheticGestureControllerTest, EXPECT_EQ(params.scale_factor, pinch_target->ComputeScaleFactor()); } +TEST_F(SyntheticGestureControllerTest, + TouchscreenTouchpadPinchGestureTouchFromDebugger) { + CreateControllerAndTarget<MockSyntheticTouchscreenPinchTouchTarget>(); + + SyntheticPinchGestureParams params; + params.from_devtools_debugger = true; + params.gesture_source_type = content::mojom::GestureSourceType::kTouchInput; + params.scale_factor = 2.3f; + params.anchor.SetPoint(54, 89); + + std::unique_ptr<SyntheticTouchscreenPinchGesture> gesture( + new SyntheticTouchscreenPinchGesture(params)); + QueueSyntheticGesture(std::move(gesture)); + FlushInputUntilComplete(); + + EXPECT_EQ(1, num_success_); + EXPECT_EQ(0, num_failure_); + EXPECT_TRUE(target_->all_from_debugger()); +} + TEST_F(SyntheticGestureControllerTest, TouchpadPinchGestureTouchZoomIn) { CreateControllerAndTarget<MockSyntheticTouchpadPinchTouchTarget>(); @@ -1657,6 +1815,25 @@ TEST_F(SyntheticGestureControllerTest, TouchpadPinchGestureTouchNoScaling) { EXPECT_EQ(params.scale_factor, pinch_target->scale_factor()); } +TEST_F(SyntheticGestureControllerTest, TouchpadPinchGestureTouchFromDebugger) { + CreateControllerAndTarget<MockSyntheticTouchpadPinchTouchTarget>(); + + SyntheticPinchGestureParams params; + params.from_devtools_debugger = true; + params.gesture_source_type = content::mojom::GestureSourceType::kMouseInput; + params.scale_factor = 2.3f; + params.anchor.SetPoint(54, 89); + + std::unique_ptr<SyntheticTouchpadPinchGesture> gesture( + new SyntheticTouchpadPinchGesture(params)); + QueueSyntheticGesture(std::move(gesture)); + FlushInputUntilComplete(); + + EXPECT_EQ(1, num_success_); + EXPECT_EQ(0, num_failure_); + EXPECT_TRUE(target_->all_from_debugger()); +} + // Ensure that if SyntheticPinchGesture is instantiated with TOUCH_INPUT it // correctly creates a touchscreen gesture. TEST_F(SyntheticGestureControllerTest, PinchGestureExplicitTouch) { @@ -1752,8 +1929,25 @@ TEST_F(SyntheticGestureControllerTest, TapGestureTouch) { EXPECT_TRUE(tap_target->GestureFinished()); EXPECT_EQ(tap_target->position(), params.position); EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); - EXPECT_GE(GetTotalTime(), - base::TimeDelta::FromMilliseconds(params.duration_ms)); + EXPECT_GE(GetTotalTime(), base::Milliseconds(params.duration_ms)); +} + +TEST_F(SyntheticGestureControllerTest, TapGestureTouchFromDebugger) { + CreateControllerAndTarget<MockSyntheticTapTouchTarget>(); + + SyntheticTapGestureParams params; + params.from_devtools_debugger = true; + params.gesture_source_type = content::mojom::GestureSourceType::kTouchInput; + params.duration_ms = 123; + params.position.SetPoint(87, -124); + + std::unique_ptr<SyntheticTapGesture> gesture(new SyntheticTapGesture(params)); + QueueSyntheticGesture(std::move(gesture)); + FlushInputUntilComplete(); + + EXPECT_EQ(1, num_success_); + EXPECT_EQ(0, num_failure_); + EXPECT_TRUE(target_->all_from_debugger()); } TEST_F(SyntheticGestureControllerTest, TapGestureMouse) { @@ -1775,8 +1969,25 @@ TEST_F(SyntheticGestureControllerTest, TapGestureMouse) { EXPECT_TRUE(tap_target->GestureFinished()); EXPECT_EQ(tap_target->position(), params.position); EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); - EXPECT_GE(GetTotalTime(), - base::TimeDelta::FromMilliseconds(params.duration_ms)); + EXPECT_GE(GetTotalTime(), base::Milliseconds(params.duration_ms)); +} + +TEST_F(SyntheticGestureControllerTest, TapGestureMouseFromDebugger) { + CreateControllerAndTarget<MockSyntheticTapMouseTarget>(); + + SyntheticTapGestureParams params; + params.from_devtools_debugger = true; + params.gesture_source_type = content::mojom::GestureSourceType::kMouseInput; + params.duration_ms = 79; + params.position.SetPoint(98, 123); + + std::unique_ptr<SyntheticTapGesture> gesture(new SyntheticTapGesture(params)); + QueueSyntheticGesture(std::move(gesture)); + FlushInputUntilComplete(); + + EXPECT_EQ(1, num_success_); + EXPECT_EQ(0, num_failure_); + EXPECT_TRUE(target_->all_from_debugger()); } TEST_F(SyntheticGestureControllerTest, PointerTouchAction) { |