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

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

Issue 1884883005: Prepare SyntheticPointerAction to handle touch actions for multiple fingers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Modify comments Created 4 years, 7 months 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 748f0ae33443b8b29fcd94d096b980fdd357ef07..8a91d8d20152d70224f5535d3984d5a8cb72bc0a 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,21 @@ 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];
+ ;
tdresser 2016/05/20 14:24:30 Remove extra ;
lanwei 2016/05/23 16:40:50 Done.
+ }
+};
+
namespace {
const int kFlushInputRateInMs = 16;
@@ -482,14 +497,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 +514,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);
@@ -520,7 +532,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 +544,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 +571,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 +608,7 @@ class SyntheticGestureControllerTest
time_ = start_time_;
num_success_ = 0;
num_failure_ = 0;
+ action_state_ = OTHER;
}
void TearDown() override {
@@ -588,6 +627,7 @@ class SyntheticGestureControllerTestWithParam
time_ = start_time_;
num_success_ = 0;
num_failure_ = 0;
+ action_state_ = OTHER;
}
void TearDown() override {
@@ -1475,63 +1515,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);
tdresser 2016/05/20 14:24:30 Why remove the type comparison?
lanwei 2016/05/23 16:40:50 Because when we have one finger move and one finge
tdresser 2016/05/24 20:35:38 I wouldn't say it's not meaningful - it depends on
- 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

Powered by Google App Engine
This is Rietveld 408576698