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 748f0ae33443b8b29fcd94d096b980fdd357ef07..5e2efafe438c461c5cd2f2d05ffc6c9231550714 100644 |
--- a/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc |
+++ b/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc |
@@ -46,6 +46,20 @@ using blink::WebTouchPoint; |
namespace content { |
+class TestSyntheticGestureController : public SyntheticGestureController { |
+ public: |
+ TestSyntheticGestureController( |
+ std::unique_ptr<SyntheticGestureTarget> gesture_target) |
+ : SyntheticGestureController(std::move(gesture_target)) {} |
+ ~TestSyntheticGestureController() override {} |
+ |
+ int PointerIndex(int index) const { |
+ CHECK_GE(index, 0); |
+ CHECK_LT(index, WebTouchEvent::touchesLengthCap); |
+ return pointer_action_controller_.index_map_[index]; |
+ } |
+}; |
+ |
namespace { |
const int kFlushInputRateInMs = 16; |
@@ -478,17 +492,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 +515,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 { |
@@ -520,7 +562,7 @@ class SyntheticGestureControllerTestBase { |
template<typename MockGestureTarget> |
void CreateControllerAndTarget() { |
target_ = new MockGestureTarget(); |
- controller_.reset(new SyntheticGestureController( |
+ controller_.reset(new TestSyntheticGestureController( |
std::unique_ptr<SyntheticGestureTarget>(target_))); |
} |
@@ -532,6 +574,14 @@ class SyntheticGestureControllerTestBase { |
base::Unretained(this))); |
} |
+ void QueueSyntheticPointerAction( |
+ const SyntheticPointerActionParams& gesture_params) { |
+ controller_->QueueSyntheticPointerAction( |
+ gesture_params, base::Bind(&SyntheticGestureControllerTestBase:: |
+ OnSyntheticPointerActionCompleted, |
+ base::Unretained(this))); |
+ } |
+ |
void FlushInputUntilComplete() { |
while (target_->flush_requested()) { |
while (target_->flush_requested()) { |
@@ -551,14 +601,32 @@ class SyntheticGestureControllerTestBase { |
num_failure_++; |
} |
+ void OnSyntheticPointerActionCompleted(SyntheticGesture::Result result) { |
+ if (result == SyntheticGesture::POINTER_ACTION_PROCESSED) { |
+ num_success_++; |
+ action_state_ = PROCESSED; |
+ } else if (result == SyntheticGesture::POINTER_ACTION_FINISHED) { |
+ num_success_++; |
+ action_state_ = FINISHED; |
+ } else { |
+ num_failure_++; |
+ action_state_ = OTHER; |
+ } |
+ } |
+ |
base::TimeDelta GetTotalTime() const { return time_ - start_time_; } |
+ int PointerIndex(int index) const { return controller_->PointerIndex(index); } |
+ |
+ enum PointerActionState { PROCESSED, FINISHED, OTHER }; |
+ |
MockSyntheticGestureTarget* target_; |
- std::unique_ptr<SyntheticGestureController> controller_; |
+ std::unique_ptr<TestSyntheticGestureController> controller_; |
base::TimeTicks start_time_; |
base::TimeTicks time_; |
int num_success_; |
int num_failure_; |
+ PointerActionState action_state_; |
}; |
class SyntheticGestureControllerTest |
@@ -570,6 +638,7 @@ class SyntheticGestureControllerTest |
time_ = start_time_; |
num_success_ = 0; |
num_failure_ = 0; |
+ action_state_ = OTHER; |
} |
void TearDown() override { |
@@ -588,6 +657,7 @@ class SyntheticGestureControllerTestWithParam |
time_ = start_time_; |
num_success_ = 0; |
num_failure_ = 0; |
+ action_state_ = OTHER; |
} |
void TearDown() override { |
@@ -1475,63 +1545,162 @@ TEST_F(SyntheticGestureControllerTest, TapGestureMouse) { |
TEST_F(SyntheticGestureControllerTest, PointerTouchAction) { |
CreateControllerAndTarget<MockSyntheticPointerTouchActionTarget>(); |
- SyntheticPointerActionParams params = SyntheticPointerActionParams( |
+ SyntheticPointerActionParams params1 = SyntheticPointerActionParams( |
SyntheticPointerActionParams::PointerActionType::PRESS); |
- params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
- params.set_index(0); |
- params.set_position(gfx::PointF(54, 89)); |
- SyntheticTouchPointer synthetic_pointer; |
- |
- std::unique_ptr<SyntheticPointerAction> gesture( |
- new SyntheticPointerAction(params, &synthetic_pointer)); |
- QueueSyntheticGesture(std::move(gesture)); |
+ params1.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
+ params1.set_index(0); |
+ params1.set_position(gfx::PointF(54, 89)); |
+ |
+ // Send a touch press for one finger. |
+ SyntheticPointerActionParams process_params = SyntheticPointerActionParams( |
+ SyntheticPointerActionParams::PointerActionType::PROCESS); |
+ process_params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
+ QueueSyntheticPointerAction(params1); |
+ QueueSyntheticPointerAction(process_params); |
FlushInputUntilComplete(); |
MockSyntheticPointerTouchActionTarget* pointer_touch_target = |
static_cast<MockSyntheticPointerTouchActionTarget*>(target_); |
+ EXPECT_EQ(1, num_success_); |
+ EXPECT_EQ(0, num_failure_); |
EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); |
- EXPECT_EQ(pointer_touch_target->positions(0), params.position()); |
+ EXPECT_EQ(pointer_touch_target->indexes(0), PointerIndex(0)); |
+ EXPECT_EQ(pointer_touch_target->positions(0), params1.position()); |
EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); |
ASSERT_EQ(pointer_touch_target->touch_length(), 1U); |
+ EXPECT_EQ(PROCESSED, action_state_); |
- params.set_index(1); |
- params.set_position(gfx::PointF(79, 132)); |
- gesture.reset(new SyntheticPointerAction(params, &synthetic_pointer)); |
- QueueSyntheticGesture(std::move(gesture)); |
+ // Send a touch move for the first finger and a touch press for the second |
+ // finger. |
+ params1.set_pointer_action_type( |
+ SyntheticPointerActionParams::PointerActionType::MOVE); |
+ params1.set_position(gfx::PointF(133, 156)); |
+ QueueSyntheticPointerAction(params1); |
+ SyntheticPointerActionParams params2 = SyntheticPointerActionParams( |
+ SyntheticPointerActionParams::PointerActionType::PRESS); |
+ params2.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
+ params2.set_index(1); |
+ params2.set_position(gfx::PointF(79, 132)); |
+ QueueSyntheticPointerAction(params2); |
+ QueueSyntheticPointerAction(process_params); |
FlushInputUntilComplete(); |
pointer_touch_target = |
static_cast<MockSyntheticPointerTouchActionTarget*>(target_); |
+ EXPECT_EQ(2, num_success_); |
+ EXPECT_EQ(0, num_failure_); |
+ // The type of the SyntheticWebTouchEvent is the action of the last finger. |
EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); |
- EXPECT_EQ(pointer_touch_target->indexes(1), params.index()); |
- EXPECT_EQ(pointer_touch_target->positions(1), params.position()); |
+ EXPECT_EQ(pointer_touch_target->indexes(0), PointerIndex(0)); |
+ EXPECT_EQ(pointer_touch_target->positions(0), params1.position()); |
+ EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateMoved); |
+ EXPECT_EQ(pointer_touch_target->indexes(1), PointerIndex(1)); |
+ EXPECT_EQ(pointer_touch_target->positions(1), params2.position()); |
EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StatePressed); |
ASSERT_EQ(pointer_touch_target->touch_length(), 2U); |
+ EXPECT_EQ(PROCESSED, action_state_); |
- params.set_pointer_action_type( |
- SyntheticPointerActionParams::PointerActionType::MOVE); |
- params.set_position(gfx::PointF(133, 156)); |
- gesture.reset(new SyntheticPointerAction(params, &synthetic_pointer)); |
- QueueSyntheticGesture(std::move(gesture)); |
+ // Send touch releases for both fingers. |
+ params1.set_pointer_action_type( |
+ SyntheticPointerActionParams::PointerActionType::RELEASE); |
+ QueueSyntheticPointerAction(params1); |
+ params2.set_pointer_action_type( |
+ SyntheticPointerActionParams::PointerActionType::RELEASE); |
+ QueueSyntheticPointerAction(params2); |
+ QueueSyntheticPointerAction(process_params); |
FlushInputUntilComplete(); |
- pointer_touch_target = |
- static_cast<MockSyntheticPointerTouchActionTarget*>(target_); |
- EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchMove); |
- EXPECT_EQ(pointer_touch_target->positions(1), params.position()); |
- EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateMoved); |
+ EXPECT_EQ(3, num_success_); |
+ EXPECT_EQ(0, num_failure_); |
+ EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchEnd); |
+ EXPECT_EQ(pointer_touch_target->indexes(0), PointerIndex(0)); |
+ EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateReleased); |
+ EXPECT_EQ(pointer_touch_target->indexes(1), PointerIndex(1)); |
+ EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased); |
ASSERT_EQ(pointer_touch_target->touch_length(), 2U); |
+ EXPECT_EQ(PROCESSED, action_state_); |
+ |
+ // Send a finish action to notify synthetic gesture controller the whole |
+ // pointer action sequence has been handled. |
+ SyntheticPointerActionParams finish_params = SyntheticPointerActionParams( |
+ SyntheticPointerActionParams::PointerActionType::FINISH); |
+ finish_params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
+ QueueSyntheticPointerAction(finish_params); |
+ FlushInputUntilComplete(); |
+ |
+ EXPECT_EQ(4, num_success_); |
+ EXPECT_EQ(0, num_failure_); |
+ EXPECT_EQ(FINISHED, action_state_); |
+} |
+ |
+TEST_F(SyntheticGestureControllerTest, PointerMouseAction) { |
+ CreateControllerAndTarget<MockSyntheticPointerMouseActionTarget>(); |
+ SyntheticPointerActionParams params = SyntheticPointerActionParams( |
+ SyntheticPointerActionParams::PointerActionType::MOVE); |
+ params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
+ params.set_index(0); |
+ params.set_position(gfx::PointF(189, 62)); |
+ |
+ // Send a mouse move. |
+ SyntheticPointerActionParams process_params = SyntheticPointerActionParams( |
+ SyntheticPointerActionParams::PointerActionType::PROCESS); |
+ process_params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
+ QueueSyntheticPointerAction(params); |
+ QueueSyntheticPointerAction(process_params); |
+ FlushInputUntilComplete(); |
+ |
+ MockSyntheticPointerMouseActionTarget* pointer_mouse_target = |
+ static_cast<MockSyntheticPointerMouseActionTarget*>(target_); |
+ EXPECT_EQ(1, num_success_); |
+ EXPECT_EQ(0, num_failure_); |
tdresser
2016/05/31 13:44:26
Should we test a case that does cause a failure?
|
+ EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); |
+ EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
+ EXPECT_EQ(pointer_mouse_target->clickCount(), 0); |
+ EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft); |
+ EXPECT_EQ(PROCESSED, action_state_); |
+ |
+ // Send a mouse press. |
+ params.set_position(gfx::PointF(326, 298)); |
+ params.set_pointer_action_type( |
+ SyntheticPointerActionParams::PointerActionType::PRESS); |
+ QueueSyntheticPointerAction(params); |
+ QueueSyntheticPointerAction(process_params); |
+ FlushInputUntilComplete(); |
+ |
+ EXPECT_EQ(2, num_success_); |
+ EXPECT_EQ(0, num_failure_); |
+ EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); |
+ EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
+ EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
+ EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft); |
+ EXPECT_EQ(PROCESSED, action_state_); |
+ |
+ // Send a mouse release. |
params.set_pointer_action_type( |
SyntheticPointerActionParams::PointerActionType::RELEASE); |
- gesture.reset(new SyntheticPointerAction(params, &synthetic_pointer)); |
- QueueSyntheticGesture(std::move(gesture)); |
+ QueueSyntheticPointerAction(params); |
+ QueueSyntheticPointerAction(process_params); |
FlushInputUntilComplete(); |
- pointer_touch_target = |
- static_cast<MockSyntheticPointerTouchActionTarget*>(target_); |
- EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchEnd); |
- EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased); |
+ EXPECT_EQ(3, num_success_); |
+ EXPECT_EQ(0, num_failure_); |
+ EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseUp); |
+ EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
+ EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft); |
+ EXPECT_EQ(PROCESSED, action_state_); |
+ |
+ // Send a finish action to notify synthetic gesture controller the whole |
+ // pointer action sequence has been handled. |
+ SyntheticPointerActionParams finish_params = SyntheticPointerActionParams( |
+ SyntheticPointerActionParams::PointerActionType::FINISH); |
+ finish_params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
+ QueueSyntheticPointerAction(finish_params); |
+ FlushInputUntilComplete(); |
+ |
+ EXPECT_EQ(4, num_success_); |
+ EXPECT_EQ(0, num_failure_); |
+ EXPECT_EQ(FINISHED, action_state_); |
} |
} // namespace |