| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/time/time.h" | 6 #include "base/time/time.h" |
| 7 #include "content/browser/renderer_host/input/synthetic_gesture.h" | 7 #include "content/browser/renderer_host/input/synthetic_gesture.h" |
| 8 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 8 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
| 9 #include "content/browser/renderer_host/input/synthetic_pointer_action.h" | 9 #include "content/browser/renderer_host/input/synthetic_pointer_action.h" |
| 10 #include "content/browser/renderer_host/input/synthetic_touch_driver.h" | 10 #include "content/browser/renderer_host/input/synthetic_touch_driver.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 private: | 164 private: |
| 165 gfx::PointF positions_[WebTouchEvent::kTouchesLengthCap]; | 165 gfx::PointF positions_[WebTouchEvent::kTouchesLengthCap]; |
| 166 unsigned touch_length_; | 166 unsigned touch_length_; |
| 167 int indexes_[WebTouchEvent::kTouchesLengthCap]; | 167 int indexes_[WebTouchEvent::kTouchesLengthCap]; |
| 168 WebTouchPoint::State states_[WebTouchEvent::kTouchesLengthCap]; | 168 WebTouchPoint::State states_[WebTouchEvent::kTouchesLengthCap]; |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 class MockSyntheticPointerMouseActionTarget | 171 class MockSyntheticPointerMouseActionTarget |
| 172 : public MockSyntheticPointerActionTarget { | 172 : public MockSyntheticPointerActionTarget { |
| 173 public: | 173 public: |
| 174 MockSyntheticPointerMouseActionTarget() {} | 174 MockSyntheticPointerMouseActionTarget() : click_count_(0) {} |
| 175 ~MockSyntheticPointerMouseActionTarget() override {} | 175 ~MockSyntheticPointerMouseActionTarget() override {} |
| 176 | 176 |
| 177 void DispatchInputEventToPlatform(const WebInputEvent& event) override { | 177 void DispatchInputEventToPlatform(const WebInputEvent& event) override { |
| 178 DCHECK(WebInputEvent::isMouseEventType(event.type())); | 178 DCHECK(WebInputEvent::isMouseEventType(event.type())); |
| 179 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); | 179 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); |
| 180 type_ = mouse_event.type(); | 180 type_ = mouse_event.type(); |
| 181 position_ = gfx::PointF(mouse_event.x, mouse_event.y); | 181 position_ = gfx::PointF(mouse_event.x, mouse_event.y); |
| 182 clickCount_ = mouse_event.clickCount; | 182 click_count_ = mouse_event.clickCount; |
| 183 button_ = mouse_event.button; | 183 button_ = mouse_event.button; |
| 184 } | 184 } |
| 185 | 185 |
| 186 testing::AssertionResult SyntheticMouseActionDispatchedCorrectly( | 186 testing::AssertionResult SyntheticMouseActionDispatchedCorrectly( |
| 187 const SyntheticPointerActionParams& param, | 187 const SyntheticPointerActionParams& param, |
| 188 int click_count) { | 188 int click_count, |
| 189 SyntheticGestureParams::GestureSourceType source_type = |
| 190 SyntheticGestureParams::MOUSE_INPUT) { |
| 191 if (GetDefaultSyntheticGestureSourceType() != source_type) { |
| 192 return testing::AssertionFailure() |
| 193 << "Pointer source type was " |
| 194 << int(GetDefaultSyntheticGestureSourceType()) << ", expected " |
| 195 << int(source_type) << "."; |
| 196 } |
| 197 |
| 189 if (type_ != ToWebMouseEventType(param.pointer_action_type())) { | 198 if (type_ != ToWebMouseEventType(param.pointer_action_type())) { |
| 190 return testing::AssertionFailure() | 199 return testing::AssertionFailure() |
| 191 << "Pointer type was " << WebInputEvent::GetName(type_) | 200 << "Pointer type was " << WebInputEvent::GetName(type_) |
| 192 << ", expected " << WebInputEvent::GetName(ToWebMouseEventType( | 201 << ", expected " << WebInputEvent::GetName(ToWebMouseEventType( |
| 193 param.pointer_action_type())) << "."; | 202 param.pointer_action_type())) << "."; |
| 194 } | 203 } |
| 195 | 204 |
| 196 if (clickCount_ != click_count) { | 205 if (click_count_ != click_count) { |
| 197 return testing::AssertionFailure() << "Pointer click count was " | 206 return testing::AssertionFailure() << "Pointer click count was " |
| 198 << clickCount_ << ", expected " | 207 << click_count_ << ", expected " |
| 199 << click_count << "."; | 208 << click_count << "."; |
| 200 } | 209 } |
| 201 | 210 |
| 202 if (clickCount_ == 1 && button_ != WebMouseEvent::Button::Left) { | 211 if (click_count_ == 1 && button_ != WebMouseEvent::Button::Left) { |
| 203 return testing::AssertionFailure() | 212 return testing::AssertionFailure() |
| 204 << "Pointer button was " << (int)button_ << ", expected " | 213 << "Pointer button was " << (int)button_ << ", expected " |
| 205 << (int)WebMouseEvent::Button::Left << "."; | 214 << (int)WebMouseEvent::Button::Left << "."; |
| 206 } | 215 } |
| 207 | 216 |
| 208 if (clickCount_ == 0 && button_ != WebMouseEvent::Button::NoButton) { | 217 if (click_count_ == 0 && button_ != WebMouseEvent::Button::NoButton) { |
| 209 return testing::AssertionFailure() | 218 return testing::AssertionFailure() |
| 210 << "Pointer button was " << (int)button_ << ", expected " | 219 << "Pointer button was " << (int)button_ << ", expected " |
| 211 << (int)WebMouseEvent::Button::NoButton << "."; | 220 << (int)WebMouseEvent::Button::NoButton << "."; |
| 212 } | 221 } |
| 213 | 222 |
| 214 if ((param.pointer_action_type() == | 223 if ((param.pointer_action_type() == |
| 215 SyntheticPointerActionParams::PointerActionType::PRESS || | 224 SyntheticPointerActionParams::PointerActionType::PRESS || |
| 216 param.pointer_action_type() == | 225 param.pointer_action_type() == |
| 217 SyntheticPointerActionParams::PointerActionType::MOVE) && | 226 SyntheticPointerActionParams::PointerActionType::MOVE) && |
| 218 position_ != param.position()) { | 227 position_ != param.position()) { |
| 219 return testing::AssertionFailure() | 228 return testing::AssertionFailure() |
| 220 << "Pointer position was " << position_.ToString() | 229 << "Pointer position was " << position_.ToString() |
| 221 << ", expected " << param.position().ToString() << "."; | 230 << ", expected " << param.position().ToString() << "."; |
| 222 } | 231 } |
| 223 return testing::AssertionSuccess(); | 232 return testing::AssertionSuccess(); |
| 224 } | 233 } |
| 225 | 234 |
| 226 SyntheticGestureParams::GestureSourceType | 235 SyntheticGestureParams::GestureSourceType |
| 227 GetDefaultSyntheticGestureSourceType() const override { | 236 GetDefaultSyntheticGestureSourceType() const override { |
| 228 return SyntheticGestureParams::MOUSE_INPUT; | 237 return SyntheticGestureParams::MOUSE_INPUT; |
| 229 } | 238 } |
| 230 | 239 |
| 231 private: | 240 private: |
| 232 gfx::PointF position_; | 241 gfx::PointF position_; |
| 233 int clickCount_; | 242 int click_count_; |
| 234 WebMouseEvent::Button button_; | 243 WebMouseEvent::Button button_; |
| 235 }; | 244 }; |
| 236 | 245 |
| 246 class MockSyntheticPointerPenActionTarget |
| 247 : public MockSyntheticPointerMouseActionTarget { |
| 248 public: |
| 249 MockSyntheticPointerPenActionTarget() {} |
| 250 ~MockSyntheticPointerPenActionTarget() override {} |
| 251 |
| 252 SyntheticGestureParams::GestureSourceType |
| 253 GetDefaultSyntheticGestureSourceType() const override { |
| 254 return SyntheticGestureParams::PEN_INPUT; |
| 255 } |
| 256 }; |
| 257 |
| 237 class SyntheticPointerActionTest : public testing::Test { | 258 class SyntheticPointerActionTest : public testing::Test { |
| 238 public: | 259 public: |
| 239 SyntheticPointerActionTest() { | 260 SyntheticPointerActionTest() { |
| 240 params_ = SyntheticPointerActionListParams(); | 261 params_ = SyntheticPointerActionListParams(); |
| 241 num_success_ = 0; | 262 num_success_ = 0; |
| 242 num_failure_ = 0; | 263 num_failure_ = 0; |
| 243 } | 264 } |
| 244 ~SyntheticPointerActionTest() override {} | 265 ~SyntheticPointerActionTest() override {} |
| 245 | 266 |
| 246 protected: | 267 protected: |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 EXPECT_EQ(1, num_success_); | 571 EXPECT_EQ(1, num_success_); |
| 551 EXPECT_EQ(1, num_failure_); | 572 EXPECT_EQ(1, num_failure_); |
| 552 EXPECT_TRUE( | 573 EXPECT_TRUE( |
| 553 pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param, 1)); | 574 pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param, 1)); |
| 554 | 575 |
| 555 ForwardSyntheticPointerAction(); | 576 ForwardSyntheticPointerAction(); |
| 556 EXPECT_EQ(1, num_success_); | 577 EXPECT_EQ(1, num_success_); |
| 557 EXPECT_EQ(2, num_failure_); | 578 EXPECT_EQ(2, num_failure_); |
| 558 } | 579 } |
| 559 | 580 |
| 581 TEST_F(SyntheticPointerActionTest, PointerPenAction) { |
| 582 CreateSyntheticPointerActionTarget<MockSyntheticPointerPenActionTarget>(); |
| 583 |
| 584 // Send a pen move. |
| 585 SyntheticPointerActionParams param1 = SyntheticPointerActionParams( |
| 586 SyntheticPointerActionParams::PointerActionType::MOVE); |
| 587 param1.set_position(gfx::PointF(189, 62)); |
| 588 params_.PushPointerActionParams(param1); |
| 589 |
| 590 // Send a pen down. |
| 591 SyntheticPointerActionParams param2 = SyntheticPointerActionParams( |
| 592 SyntheticPointerActionParams::PointerActionType::PRESS); |
| 593 param2.set_position(gfx::PointF(189, 62)); |
| 594 params_.PushPointerActionParams(param2); |
| 595 |
| 596 // Send a pen up. |
| 597 SyntheticPointerActionParams param3 = SyntheticPointerActionParams( |
| 598 SyntheticPointerActionParams::PointerActionType::RELEASE); |
| 599 params_.PushPointerActionParams(param3); |
| 600 pointer_action_.reset(new SyntheticPointerAction(params_)); |
| 601 |
| 602 ForwardSyntheticPointerAction(); |
| 603 MockSyntheticPointerPenActionTarget* pointer_pen_target = |
| 604 static_cast<MockSyntheticPointerPenActionTarget*>(target_.get()); |
| 605 EXPECT_EQ(1, num_success_); |
| 606 EXPECT_EQ(0, num_failure_); |
| 607 EXPECT_TRUE(pointer_pen_target->SyntheticMouseActionDispatchedCorrectly( |
| 608 param1, 0, SyntheticGestureParams::PEN_INPUT)); |
| 609 |
| 610 ForwardSyntheticPointerAction(); |
| 611 EXPECT_EQ(2, num_success_); |
| 612 EXPECT_EQ(0, num_failure_); |
| 613 EXPECT_TRUE(pointer_pen_target->SyntheticMouseActionDispatchedCorrectly( |
| 614 param2, 1, SyntheticGestureParams::PEN_INPUT)); |
| 615 |
| 616 ForwardSyntheticPointerAction(); |
| 617 EXPECT_EQ(3, num_success_); |
| 618 EXPECT_EQ(0, num_failure_); |
| 619 EXPECT_TRUE(pointer_pen_target->SyntheticMouseActionDispatchedCorrectly( |
| 620 param3, 1, SyntheticGestureParams::PEN_INPUT)); |
| 621 } |
| 622 |
| 560 } // namespace | 623 } // namespace |
| 561 | 624 |
| 562 } // namespace content | 625 } // namespace content |
| OLD | NEW |