Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1048)

Unified Diff: content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc

Issue 2336803003: Make SyntheticPointerAction to flush the pointer action sequence (Closed)
Patch Set: return invaid when index is out bound Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 7a538420fcd0e718a47d4b8f38526b02bb717b06..39739704c98c2231ff5ada2ea5719d50082b3bf3 100644
--- a/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc
+++ b/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc
@@ -474,21 +474,16 @@ class MockSyntheticTapMouseTarget : public MockSyntheticTapGestureTarget {
class MockSyntheticPointerActionTarget : public MockSyntheticGestureTarget {
public:
- MockSyntheticPointerActionTarget() {}
+ MockSyntheticPointerActionTarget() : count_(0) {}
~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_; }
+ int count() const { return count_; }
+ void reset_count() { count_ = 0; }
protected:
- gfx::PointF positions_[kTouchPointersLength];
- unsigned touch_length_;
- int indexes_[kTouchPointersLength];
- WebTouchPoint::State states_[kTouchPointersLength];
WebInputEvent::Type type_;
+ int count_;
tdresser 2016/12/13 14:37:43 Be more specific in the variable name here.
};
class MockSyntheticPointerTouchActionTarget
@@ -507,7 +502,45 @@ class MockSyntheticPointerTouchActionTarget
states_[i] = touch_event.touches[i].state;
}
touch_length_ = touch_event.touchesLength;
+ count_++;
}
+
+ 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;
+ count_++;
+ }
+
+ 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 {
@@ -1471,6 +1504,170 @@ TEST_F(SyntheticGestureControllerTest, TapGestureMouse) {
base::TimeDelta::FromMilliseconds(params.duration_ms));
}
+TEST_F(SyntheticGestureControllerTest, PointerTouchAction) {
+ CreateControllerAndTarget<MockSyntheticPointerTouchActionTarget>();
+
+ // First, send two touch presses for finger 0 and finger 1.
+ SyntheticPointerActionListParams::ParamList param_list;
+ SyntheticPointerActionParams param0 = SyntheticPointerActionParams(
+ SyntheticPointerActionParams::PointerActionType::PRESS,
+ SyntheticGestureParams::TOUCH_INPUT);
+ SyntheticPointerActionParams param1 = SyntheticPointerActionParams(
+ SyntheticPointerActionParams::PointerActionType::PRESS,
+ SyntheticGestureParams::TOUCH_INPUT);
+ param0.set_position(gfx::PointF(54, 89));
+ param0.set_index(0);
+ param1.set_position(gfx::PointF(79, 132));
+ param1.set_index(1);
+ param_list.push_back(param0);
+ param_list.push_back(param1);
+ SyntheticPointerActionListParams params(param_list);
+ params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
+ std::unique_ptr<SyntheticPointerAction> gesture(
+ new SyntheticPointerAction(params));
+ QueueSyntheticGesture(std::move(gesture));
+ FlushInputUntilComplete();
+
+ MockSyntheticPointerTouchActionTarget* pointer_touch_target =
+ static_cast<MockSyntheticPointerTouchActionTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ EXPECT_EQ(pointer_touch_target->count(), 1);
+ EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
+ EXPECT_EQ(pointer_touch_target->touch_length(), 2u);
+ EXPECT_EQ(pointer_touch_target->indexes(0), 0);
+ EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89));
+ EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed);
tdresser 2016/12/13 14:37:43 Can we add a helper to shorten this up? Maybe som
+ EXPECT_EQ(pointer_touch_target->indexes(1), 1);
+ EXPECT_EQ(pointer_touch_target->positions(1), gfx::PointF(79, 132));
+ EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StatePressed);
+
+ // Second, send a touch release for finger 0, a touch move for finger 1.
+ param0.set_pointer_action_type(
+ SyntheticPointerActionParams::PointerActionType::RELEASE);
+ param1.set_pointer_action_type(
+ SyntheticPointerActionParams::PointerActionType::MOVE);
+ param1.set_position(gfx::PointF(183, 239));
+ param_list.clear();
+ param_list.push_back(param0);
+ param_list.push_back(param1);
+ params.PushPointerActionParamsList(param_list);
+ gesture.reset(new SyntheticPointerAction(params));
+ QueueSyntheticGesture(std::move(gesture));
+ pointer_touch_target->reset_count();
+ FlushInputUntilComplete();
+
+ EXPECT_EQ(2, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ EXPECT_EQ(pointer_touch_target->count(), 2);
+ EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchMove);
+ EXPECT_EQ(pointer_touch_target->touch_length(), 2u);
+ EXPECT_EQ(pointer_touch_target->indexes(0), 0);
+ EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateReleased);
+ EXPECT_EQ(pointer_touch_target->indexes(1), 1);
+ EXPECT_EQ(pointer_touch_target->positions(1), gfx::PointF(183, 239));
+ EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateMoved);
+
+ // Third, send a touch release for finger 1.
+ param1.set_pointer_action_type(
+ SyntheticPointerActionParams::PointerActionType::RELEASE);
+ params.PushPointerActionParams(param1);
+ gesture.reset(new SyntheticPointerAction(params));
+ QueueSyntheticGesture(std::move(gesture));
+ pointer_touch_target->reset_count();
+ FlushInputUntilComplete();
+
+ EXPECT_EQ(3, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ EXPECT_EQ(pointer_touch_target->count(), 3);
+ EXPECT_EQ(pointer_touch_target->type(),
+ WebInputEvent::WebInputEvent::TouchEnd);
+ EXPECT_EQ(pointer_touch_target->touch_length(), 2u);
+ EXPECT_EQ(pointer_touch_target->indexes(1), 1);
+ EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased);
+}
+
+TEST_F(SyntheticGestureControllerTest, PointerMouseAction) {
+ CreateControllerAndTarget<MockSyntheticPointerMouseActionTarget>();
+
+ // First, send a mouse move.
+ SyntheticPointerActionListParams::ParamList param_list;
+ SyntheticPointerActionParams param = SyntheticPointerActionParams(
+ SyntheticPointerActionParams::PointerActionType::MOVE,
+ SyntheticGestureParams::MOUSE_INPUT);
+
+ param.set_position(gfx::PointF(54, 89));
+ SyntheticPointerActionListParams params;
+ params.PushPointerActionParams(param);
+ params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
+ std::unique_ptr<SyntheticPointerAction> gesture(
+ new SyntheticPointerAction(params));
+ QueueSyntheticGesture(std::move(gesture));
+ FlushInputUntilComplete();
+
+ MockSyntheticPointerMouseActionTarget* pointer_mouse_target =
+ static_cast<MockSyntheticPointerMouseActionTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ EXPECT_EQ(pointer_mouse_target->count(), 1);
+ EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove);
+ EXPECT_EQ(pointer_mouse_target->position(), gfx::PointF(54, 89));
+ EXPECT_EQ(pointer_mouse_target->clickCount(), 0);
+ EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton);
+
+ // Second, send a mouse press.
+ param.set_pointer_action_type(
+ SyntheticPointerActionParams::PointerActionType::PRESS);
+ param.set_position(gfx::PointF(183, 239));
+ params.PushPointerActionParams(param);
+ gesture.reset(new SyntheticPointerAction(params));
+ QueueSyntheticGesture(std::move(gesture));
+ pointer_mouse_target->reset_count();
+ FlushInputUntilComplete();
+
+ EXPECT_EQ(2, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ EXPECT_EQ(pointer_mouse_target->count(), 2);
+ 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);
+
+ // Third, send a mouse move.
+ param.set_pointer_action_type(
+ SyntheticPointerActionParams::PointerActionType::MOVE);
+ param.set_position(gfx::PointF(254, 279));
+ params.PushPointerActionParams(param);
+ gesture.reset(new SyntheticPointerAction(params));
+ QueueSyntheticGesture(std::move(gesture));
+ pointer_mouse_target->reset_count();
+ FlushInputUntilComplete();
+
+ EXPECT_EQ(3, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ EXPECT_EQ(pointer_mouse_target->count(), 3);
+ 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);
+
+ // Fourth, send a mouse release.
+ param.set_pointer_action_type(
+ SyntheticPointerActionParams::PointerActionType::RELEASE);
+ params.PushPointerActionParams(param);
+ gesture.reset(new SyntheticPointerAction(params));
+ QueueSyntheticGesture(std::move(gesture));
+ pointer_mouse_target->reset_count();
+ FlushInputUntilComplete();
+
+ EXPECT_EQ(4, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ EXPECT_EQ(pointer_mouse_target->count(), 4);
+ 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
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698