Chromium Code Reviews| Index: content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc |
| diff --git a/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc b/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc |
| index c2e16707f9d306ef4a0bc8f65fe4e4fdb2882557..2b13e6b534bd193de9974f16f6f38525a1f1c61c 100644 |
| --- a/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc |
| +++ b/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc |
| @@ -478,17 +478,9 @@ class MockSyntheticPointerActionTarget : public MockSyntheticGestureTarget { |
| MockSyntheticPointerActionTarget() {} |
| ~MockSyntheticPointerActionTarget() override {} |
| - gfx::PointF positions(int index) const { return positions_[index]; } |
| - int indexes(int index) const { return indexes_[index]; } |
| - WebTouchPoint::State states(int index) { return states_[index]; } |
| - unsigned touch_length() const { return touch_length_; } |
| WebInputEvent::Type type() const { return type_; } |
| protected: |
| - gfx::PointF positions_[kTouchPointersLength]; |
| - unsigned touch_length_; |
| - int indexes_[kTouchPointersLength]; |
| - WebTouchPoint::State states_[kTouchPointersLength]; |
| WebInputEvent::Type type_; |
| }; |
| @@ -509,6 +501,42 @@ class MockSyntheticPointerTouchActionTarget |
| } |
| touch_length_ = touch_event.touchesLength; |
| } |
| + |
| + gfx::PointF positions(int index) const { return positions_[index]; } |
| + int indexes(int index) const { return indexes_[index]; } |
| + WebTouchPoint::State states(int index) { return states_[index]; } |
| + unsigned touch_length() const { return touch_length_; } |
| + |
| + private: |
| + gfx::PointF positions_[kTouchPointersLength]; |
| + unsigned touch_length_; |
| + int indexes_[kTouchPointersLength]; |
| + WebTouchPoint::State states_[kTouchPointersLength]; |
| +}; |
| + |
| +class MockSyntheticPointerMouseActionTarget |
| + : public MockSyntheticPointerActionTarget { |
| + public: |
| + MockSyntheticPointerMouseActionTarget() {} |
| + ~MockSyntheticPointerMouseActionTarget() override {} |
| + |
| + void DispatchInputEventToPlatform(const WebInputEvent& event) override { |
| + ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type)); |
| + const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); |
| + type_ = mouse_event.type; |
| + position_ = gfx::PointF(mouse_event.x, mouse_event.y); |
| + clickCount_ = mouse_event.clickCount; |
| + button_ = mouse_event.button; |
| + } |
| + |
| + gfx::PointF position() const { return position_; } |
| + int clickCount() const { return clickCount_; } |
| + WebMouseEvent::Button button() const { return button_; } |
| + |
| + private: |
| + gfx::PointF position_; |
| + int clickCount_; |
| + WebMouseEvent::Button button_; |
| }; |
| class SyntheticGestureControllerTestBase { |
| @@ -1472,6 +1500,141 @@ TEST_F(SyntheticGestureControllerTest, TapGestureMouse) { |
| base::TimeDelta::FromMilliseconds(params.duration_ms)); |
| } |
| +TEST_F(SyntheticGestureControllerTest, PointerTouchAction) { |
| + CreateControllerAndTarget<MockSyntheticPointerTouchActionTarget>(); |
| + std::unique_ptr<SyntheticPointer> synthetic_pointer = |
| + SyntheticPointer::Create(SyntheticGestureParams::TOUCH_INPUT); |
| + SyntheticPointerAction::IndexMap index_map; |
| + std::fill(index_map.begin(), index_map.end(), -1); |
| + SyntheticPointerActionListParams action_list_params; |
| + action_list_params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| + |
| + SyntheticPointerActionParams params0 = SyntheticPointerActionParams( |
| + SyntheticGestureParams::TOUCH_INPUT, |
| + SyntheticPointerActionParams::PointerActionType::PRESS); |
| + SyntheticPointerActionParams params1 = SyntheticPointerActionParams( |
| + SyntheticGestureParams::TOUCH_INPUT, |
| + SyntheticPointerActionParams::PointerActionType::PRESS); |
| + params0.set_index(0); |
| + params0.set_position(gfx::PointF(54, 89)); |
| + params1.set_index(1); |
| + params1.set_position(gfx::PointF(79, 132)); |
| + action_list_params.param_list.push_back(params0); |
| + action_list_params.param_list.push_back(params1); |
| + std::unique_ptr<SyntheticPointerAction> gesture(new SyntheticPointerAction( |
| + action_list_params, synthetic_pointer.get(), &index_map)); |
|
tdresser
2016/10/31 14:22:57
We use a single SyntheticPointer for two separate
lanwei
2016/12/04 18:08:01
We are planing to support multiple pointer types i
lanwei
2016/12/04 18:08:02
Done.
|
| + QueueSyntheticGesture(std::move(gesture)); |
| + FlushInputUntilComplete(); |
| + |
| + MockSyntheticPointerTouchActionTarget* pointer_touch_target = |
| + static_cast<MockSyntheticPointerTouchActionTarget*>(target_); |
| + ASSERT_EQ(pointer_touch_target->touch_length(), 2u); |
| + EXPECT_EQ(pointer_touch_target->indexes(0), params0.index()); |
| + EXPECT_EQ(pointer_touch_target->positions(0), params0.position()); |
| + EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); |
| + EXPECT_EQ(pointer_touch_target->indexes(1), params1.index()); |
| + EXPECT_EQ(pointer_touch_target->positions(1), params1.position()); |
| + EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StatePressed); |
| + |
| + action_list_params.param_list.clear(); |
| + params0.set_pointer_action_type( |
| + SyntheticPointerActionParams::PointerActionType::RELEASE); |
| + params1.set_pointer_action_type( |
| + SyntheticPointerActionParams::PointerActionType::MOVE); |
| + params1.set_position(gfx::PointF(183, 239)); |
| + action_list_params.param_list.push_back(params0); |
| + action_list_params.param_list.push_back(params1); |
| + gesture.reset(new SyntheticPointerAction( |
| + action_list_params, synthetic_pointer.get(), &index_map)); |
| + QueueSyntheticGesture(std::move(gesture)); |
| + FlushInputUntilComplete(); |
| + |
| + ASSERT_EQ(pointer_touch_target->touch_length(), 2u); |
| + EXPECT_EQ(pointer_touch_target->indexes(0), params0.index()); |
| + EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateReleased); |
| + EXPECT_EQ(pointer_touch_target->indexes(1), params1.index()); |
| + EXPECT_EQ(pointer_touch_target->positions(1), params1.position()); |
| + EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateMoved); |
| + |
| + action_list_params.param_list.clear(); |
| + params1.set_pointer_action_type( |
| + SyntheticPointerActionParams::PointerActionType::RELEASE); |
| + action_list_params.param_list.push_back(params1); |
| + gesture.reset(new SyntheticPointerAction( |
| + action_list_params, synthetic_pointer.get(), &index_map)); |
| + QueueSyntheticGesture(std::move(gesture)); |
| + FlushInputUntilComplete(); |
| + |
| + ASSERT_EQ(pointer_touch_target->touch_length(), 2u); |
| + EXPECT_EQ(pointer_touch_target->indexes(1), params1.index()); |
| + EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased); |
| +} |
| + |
| +TEST_F(SyntheticGestureControllerTest, PointerMouseAction) { |
| + CreateControllerAndTarget<MockSyntheticPointerMouseActionTarget>(); |
| + std::unique_ptr<SyntheticPointer> synthetic_pointer = |
| + SyntheticPointer::Create(SyntheticGestureParams::MOUSE_INPUT); |
| + SyntheticPointerAction::IndexMap index_map; |
| + std::fill(index_map.begin(), index_map.end(), -1); |
| + SyntheticPointerActionListParams action_list_params; |
| + action_list_params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
| + |
| + SyntheticPointerActionParams action_params = SyntheticPointerActionParams( |
| + SyntheticGestureParams::MOUSE_INPUT, |
| + SyntheticPointerActionParams::PointerActionType::MOVE); |
| + action_params.set_index(0); |
| + action_params.set_position(gfx::PointF(54, 89)); |
| + action_list_params.param_list.push_back(action_params); |
| + std::unique_ptr<SyntheticPointerAction> gesture(new SyntheticPointerAction( |
| + action_list_params, synthetic_pointer.get(), &index_map)); |
| + QueueSyntheticGesture(std::move(gesture)); |
| + FlushInputUntilComplete(); |
| + |
| + MockSyntheticPointerMouseActionTarget* pointer_mouse_target = |
| + static_cast<MockSyntheticPointerMouseActionTarget*>(target_); |
| + EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); |
| + EXPECT_EQ(pointer_mouse_target->position(), action_params.position()); |
| + EXPECT_EQ(pointer_mouse_target->clickCount(), 0); |
| + EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton); |
| + |
| + action_list_params.param_list[0].set_pointer_action_type( |
| + SyntheticPointerActionParams::PointerActionType::PRESS); |
| + action_list_params.param_list[0].set_position(gfx::PointF(183, 239)); |
| + gesture.reset(new SyntheticPointerAction( |
| + action_list_params, synthetic_pointer.get(), &index_map)); |
| + QueueSyntheticGesture(std::move(gesture)); |
| + FlushInputUntilComplete(); |
| + |
| + EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); |
| + EXPECT_EQ(pointer_mouse_target->position(), gfx::PointF(183, 239)); |
| + EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
| + EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
| + |
| + action_list_params.param_list[0].set_pointer_action_type( |
| + SyntheticPointerActionParams::PointerActionType::MOVE); |
| + action_list_params.param_list[0].set_position(gfx::PointF(254, 279)); |
| + gesture.reset(new SyntheticPointerAction( |
| + action_list_params, synthetic_pointer.get(), &index_map)); |
| + QueueSyntheticGesture(std::move(gesture)); |
| + FlushInputUntilComplete(); |
| + |
| + EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); |
| + EXPECT_EQ(pointer_mouse_target->position(), gfx::PointF(254, 279)); |
| + EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
| + EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
| + |
| + action_list_params.param_list[0].set_pointer_action_type( |
| + SyntheticPointerActionParams::PointerActionType::RELEASE); |
| + gesture.reset(new SyntheticPointerAction( |
| + action_list_params, synthetic_pointer.get(), &index_map)); |
| + QueueSyntheticGesture(std::move(gesture)); |
| + FlushInputUntilComplete(); |
| + |
| + EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseUp); |
| + EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
| + EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
| +} |
| + |
| } // namespace |
| } // namespace content |