Chromium Code Reviews| Index: content/browser/renderer_host/input/synthetic_pointer_action_unittest.cc |
| diff --git a/content/browser/renderer_host/input/synthetic_pointer_action_unittest.cc b/content/browser/renderer_host/input/synthetic_pointer_action_unittest.cc |
| index 46df157fc18487cf56c076f2bd7ca209aa1902d8..5a1f3a686e7e49415cb0514362fca0f261d1b1a0 100644 |
| --- a/content/browser/renderer_host/input/synthetic_pointer_action_unittest.cc |
| +++ b/content/browser/renderer_host/input/synthetic_pointer_action_unittest.cc |
| @@ -61,6 +61,32 @@ WebInputEvent::Type ToWebMouseEventType( |
| return WebInputEvent::Undefined; |
| } |
| +blink::WebMouseEvent::Button GetWebMouseEventButton(int button) { |
|
tdresser
2017/01/17 13:23:18
We shouldn't duplicate these.
Let's put them some
lanwei
2017/01/17 19:50:34
Done.
|
| + switch (button) { |
| + case 0: |
| + return blink::WebMouseEvent::Button::Left; |
| + case 1: |
| + return blink::WebMouseEvent::Button::Middle; |
| + case 2: |
| + return blink::WebMouseEvent::Button::Right; |
| + } |
| + NOTREACHED(); |
| + return blink::WebMouseEvent::Button::NoButton; |
| +} |
| + |
| +unsigned GetWebMouseEventModifier(int button) { |
| + switch (button) { |
| + case 0: |
| + return blink::WebMouseEvent::LeftButtonDown; |
| + case 1: |
| + return blink::WebMouseEvent::MiddleButtonDown; |
| + case 2: |
| + return blink::WebMouseEvent::RightButtonDown; |
| + } |
| + NOTREACHED(); |
| + return blink::WebMouseEvent::NoModifiers; |
| +} |
| + |
| class MockSyntheticPointerActionTarget : public SyntheticGestureTarget { |
| public: |
| MockSyntheticPointerActionTarget() {} |
| @@ -171,7 +197,7 @@ class MockSyntheticPointerTouchActionTarget |
| class MockSyntheticPointerMouseActionTarget |
| : public MockSyntheticPointerActionTarget { |
| public: |
| - MockSyntheticPointerMouseActionTarget() {} |
| + MockSyntheticPointerMouseActionTarget() : click_count_(0), modifiers_(0) {} |
| ~MockSyntheticPointerMouseActionTarget() override {} |
| void DispatchInputEventToPlatform(const WebInputEvent& event) override { |
| @@ -179,13 +205,15 @@ class MockSyntheticPointerMouseActionTarget |
| 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; |
| + click_count_ = mouse_event.clickCount; |
| + modifiers_ = mouse_event.modifiers(); |
| button_ = mouse_event.button; |
| } |
| testing::AssertionResult SyntheticMouseActionDispatchedCorrectly( |
| const SyntheticPointerActionParams& param, |
| - int click_count) { |
| + int click_count, |
| + std::vector<int> buttons) { |
| if (type_ != ToWebMouseEventType(param.pointer_action_type())) { |
| return testing::AssertionFailure() |
| << "Pointer type was " << WebInputEvent::GetName(type_) |
| @@ -193,24 +221,38 @@ class MockSyntheticPointerMouseActionTarget |
| param.pointer_action_type())) << "."; |
| } |
| - if (clickCount_ != click_count) { |
| + if (click_count_ != click_count) { |
| return testing::AssertionFailure() << "Pointer click count was " |
| - << clickCount_ << ", expected " |
| + << click_count_ << ", expected " |
| << click_count << "."; |
| } |
| - if (clickCount_ == 1 && button_ != WebMouseEvent::Button::Left) { |
| - return testing::AssertionFailure() |
| - << "Pointer button was " << (int)button_ << ", expected " |
| - << (int)WebMouseEvent::Button::Left << "."; |
| + if (click_count_ == 1) { |
| + DCHECK_GT(buttons.size(), 0U); |
| + int button = buttons[buttons.size() - 1]; |
| + if (button_ != GetWebMouseEventButton(button)) { |
| + return testing::AssertionFailure() << "Pointer button was " |
| + << (int)button_ << ", expected " |
|
tdresser
2017/01/17 13:23:18
static_cast
lanwei
2017/01/17 19:50:34
Done.
|
| + << button << "."; |
| + } |
| } |
| - if (clickCount_ == 0 && button_ != WebMouseEvent::Button::NoButton) { |
| + if (click_count_ == 0 && button_ != WebMouseEvent::Button::NoButton) { |
| + DCHECK_EQ(buttons.size(), 0U); |
| return testing::AssertionFailure() |
| << "Pointer button was " << (int)button_ << ", expected " |
| << (int)WebMouseEvent::Button::NoButton << "."; |
| } |
| + int modifiers = 0; |
| + for (size_t index = 0; index < buttons.size(); ++index) |
| + modifiers |= GetWebMouseEventModifier(buttons[index]); |
| + if (modifiers_ != modifiers) { |
| + return testing::AssertionFailure() << "Pointer modifiers was " |
| + << modifiers_ << ", expected " |
| + << modifiers << "."; |
| + } |
| + |
| if ((param.pointer_action_type() == |
| SyntheticPointerActionParams::PointerActionType::PRESS || |
| param.pointer_action_type() == |
| @@ -230,7 +272,8 @@ class MockSyntheticPointerMouseActionTarget |
| private: |
| gfx::PointF position_; |
| - int clickCount_; |
| + int click_count_; |
| + int modifiers_; |
| WebMouseEvent::Button button_; |
| }; |
| @@ -498,26 +541,89 @@ TEST_F(SyntheticPointerActionTest, PointerMouseAction) { |
| static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); |
| EXPECT_EQ(1, num_success_); |
| EXPECT_EQ(0, num_failure_); |
| - EXPECT_TRUE( |
| - pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param1, 0)); |
| + std::vector<int> buttons; |
| + EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly( |
| + param1, 0, buttons)); |
| ForwardSyntheticPointerAction(); |
| EXPECT_EQ(2, num_success_); |
| EXPECT_EQ(0, num_failure_); |
| - EXPECT_TRUE( |
| - pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param2, 1)); |
| + buttons.push_back(0); |
| + EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly( |
| + param2, 1, buttons)); |
| ForwardSyntheticPointerAction(); |
| EXPECT_EQ(3, num_success_); |
| EXPECT_EQ(0, num_failure_); |
| - EXPECT_TRUE( |
| - pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param3, 1)); |
| + EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly( |
| + param3, 1, buttons)); |
| ForwardSyntheticPointerAction(); |
| EXPECT_EQ(4, num_success_); |
| EXPECT_EQ(0, num_failure_); |
| - EXPECT_TRUE( |
| - pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param4, 1)); |
| + EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly( |
| + param4, 1, buttons)); |
| +} |
| + |
| +TEST_F(SyntheticPointerActionTest, PointerMouseActionMultiPress) { |
| + CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>(); |
| + |
| + // Press a mouse's left button. |
| + SyntheticPointerActionParams param1 = SyntheticPointerActionParams( |
| + SyntheticPointerActionParams::PointerActionType::PRESS); |
| + param1.set_position(gfx::PointF(189, 62)); |
| + param1.set_button(0); |
| + params_.PushPointerActionParams(param1); |
| + |
| + // Press a mouse's middle button. |
| + SyntheticPointerActionParams param2 = SyntheticPointerActionParams( |
| + SyntheticPointerActionParams::PointerActionType::PRESS); |
| + param2.set_position(gfx::PointF(189, 62)); |
| + param2.set_button(1); |
| + params_.PushPointerActionParams(param2); |
| + |
| + // Release a mouse's middle button. |
| + SyntheticPointerActionParams param3 = SyntheticPointerActionParams( |
| + SyntheticPointerActionParams::PointerActionType::RELEASE); |
| + param3.set_button(1); |
| + params_.PushPointerActionParams(param3); |
| + pointer_action_.reset(new SyntheticPointerAction(params_)); |
| + |
| + // Release a mouse's middle button. |
| + SyntheticPointerActionParams param4 = SyntheticPointerActionParams( |
| + SyntheticPointerActionParams::PointerActionType::RELEASE); |
| + param4.set_button(0); |
| + params_.PushPointerActionParams(param4); |
| + pointer_action_.reset(new SyntheticPointerAction(params_)); |
| + |
| + ForwardSyntheticPointerAction(); |
| + MockSyntheticPointerMouseActionTarget* pointer_mouse_target = |
| + static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); |
| + EXPECT_EQ(1, num_success_); |
| + EXPECT_EQ(0, num_failure_); |
| + std::vector<int> buttons(1, 0); |
| + EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly( |
| + param1, 1, buttons)); |
| + |
| + ForwardSyntheticPointerAction(); |
| + EXPECT_EQ(2, num_success_); |
| + EXPECT_EQ(0, num_failure_); |
| + buttons.push_back(1); |
| + EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly( |
| + param2, 1, buttons)); |
| + |
| + ForwardSyntheticPointerAction(); |
| + EXPECT_EQ(3, num_success_); |
| + EXPECT_EQ(0, num_failure_); |
| + EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly( |
| + param3, 1, buttons)); |
| + |
| + ForwardSyntheticPointerAction(); |
| + EXPECT_EQ(4, num_success_); |
| + EXPECT_EQ(0, num_failure_); |
| + buttons.pop_back(); |
| + EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly( |
| + param4, 1, buttons)); |
| } |
| TEST_F(SyntheticPointerActionTest, PointerMouseActionTypeInvalid) { |
| @@ -549,8 +655,9 @@ TEST_F(SyntheticPointerActionTest, PointerMouseActionTypeInvalid) { |
| static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); |
| EXPECT_EQ(1, num_success_); |
| EXPECT_EQ(1, num_failure_); |
| - EXPECT_TRUE( |
| - pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param, 1)); |
| + std::vector<int> buttons(1, 0); |
| + EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly( |
| + param, 1, buttons)); |
| ForwardSyntheticPointerAction(); |
| EXPECT_EQ(1, num_success_); |