| 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..6aba6e27ddf6dc18185fdc5c01f90840b5ea8bc7 100644
|
| --- a/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc
|
| +++ b/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc
|
| @@ -482,14 +482,12 @@ class MockSyntheticPointerActionTarget : public MockSyntheticGestureTarget {
|
| 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_;
|
| };
|
|
|
| class MockSyntheticPointerTouchActionTarget
|
| @@ -501,7 +499,6 @@ class MockSyntheticPointerTouchActionTarget
|
| void DispatchInputEventToPlatform(const WebInputEvent& event) override {
|
| ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type));
|
| const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event);
|
| - type_ = touch_event.type;
|
| for (size_t i = 0; i < touch_event.touchesLength; ++i) {
|
| indexes_[i] = touch_event.touches[i].id;
|
| positions_[i] = gfx::PointF(touch_event.touches[i].position);
|
| @@ -532,6 +529,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 +556,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_;
|
| base::TimeTicks start_time_;
|
| base::TimeTicks time_;
|
| int num_success_;
|
| int num_failure_;
|
| + PointerActionState action_state_;
|
| };
|
|
|
| class SyntheticGestureControllerTest
|
| @@ -570,6 +593,7 @@ class SyntheticGestureControllerTest
|
| time_ = start_time_;
|
| num_success_ = 0;
|
| num_failure_ = 0;
|
| + action_state_ = OTHER;
|
| }
|
|
|
| void TearDown() override {
|
| @@ -588,6 +612,7 @@ class SyntheticGestureControllerTestWithParam
|
| time_ = start_time_;
|
| num_success_ = 0;
|
| num_failure_ = 0;
|
| + action_state_ = OTHER;
|
| }
|
|
|
| void TearDown() override {
|
| @@ -1475,63 +1500,89 @@ 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));
|
| + params1.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
|
| + params1.set_index(0);
|
| + params1.set_position(gfx::PointF(54, 89));
|
| SyntheticTouchPointer synthetic_pointer;
|
|
|
| - std::unique_ptr<SyntheticPointerAction> gesture(
|
| - new SyntheticPointerAction(params, &synthetic_pointer));
|
| - QueueSyntheticGesture(std::move(gesture));
|
| + // 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(pointer_touch_target->type(), WebInputEvent::TouchStart);
|
| - EXPECT_EQ(pointer_touch_target->positions(0), params.position());
|
| + EXPECT_EQ(1, num_success_);
|
| + EXPECT_EQ(0, num_failure_);
|
| + 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(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(2, num_success_);
|
| + EXPECT_EQ(0, num_failure_);
|
| + 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->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);
|
| -
|
| - params.set_pointer_action_type(
|
| - SyntheticPointerActionParams::PointerActionType::RELEASE);
|
| - gesture.reset(new SyntheticPointerAction(params, &synthetic_pointer));
|
| - QueueSyntheticGesture(std::move(gesture));
|
| + 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();
|
|
|
| - 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(4, num_success_);
|
| + EXPECT_EQ(0, num_failure_);
|
| + EXPECT_EQ(FINISHED, action_state_);
|
| }
|
|
|
| } // namespace
|
|
|