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

Side by Side Diff: content/browser/renderer_host/input/synthetic_pointer_action_unittest.cc

Issue 2336803003: Make SyntheticPointerAction to flush the pointer action sequence (Closed)
Patch Set: controller Created 3 years, 12 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 unified diff | Download patch
OLDNEW
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 15 matching lines...) Expand all
26 SyntheticPointerActionParams::PointerActionType action_type) { 26 SyntheticPointerActionParams::PointerActionType action_type) {
27 switch (action_type) { 27 switch (action_type) {
28 case SyntheticPointerActionParams::PointerActionType::PRESS: 28 case SyntheticPointerActionParams::PointerActionType::PRESS:
29 return WebTouchPoint::StatePressed; 29 return WebTouchPoint::StatePressed;
30 case SyntheticPointerActionParams::PointerActionType::MOVE: 30 case SyntheticPointerActionParams::PointerActionType::MOVE:
31 return WebTouchPoint::StateMoved; 31 return WebTouchPoint::StateMoved;
32 case SyntheticPointerActionParams::PointerActionType::RELEASE: 32 case SyntheticPointerActionParams::PointerActionType::RELEASE:
33 return WebTouchPoint::StateReleased; 33 return WebTouchPoint::StateReleased;
34 case SyntheticPointerActionParams::PointerActionType::IDLE: 34 case SyntheticPointerActionParams::PointerActionType::IDLE:
35 return WebTouchPoint::StateStationary; 35 return WebTouchPoint::StateStationary;
36 case SyntheticPointerActionParams::PointerActionType::FINISH:
37 case SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED: 36 case SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED:
38 NOTREACHED() 37 NOTREACHED()
39 << "Invalid SyntheticPointerActionParams::PointerActionType."; 38 << "Invalid SyntheticPointerActionParams::PointerActionType.";
40 return WebTouchPoint::StateUndefined; 39 return WebTouchPoint::StateUndefined;
41 } 40 }
42 NOTREACHED() << "Invalid SyntheticPointerActionParams::PointerActionType."; 41 NOTREACHED() << "Invalid SyntheticPointerActionParams::PointerActionType.";
43 return WebTouchPoint::StateUndefined; 42 return WebTouchPoint::StateUndefined;
44 } 43 }
45 44
46 WebInputEvent::Type ToWebMouseEventType( 45 WebInputEvent::Type ToWebMouseEventType(
47 SyntheticPointerActionParams::PointerActionType action_type) { 46 SyntheticPointerActionParams::PointerActionType action_type) {
48 switch (action_type) { 47 switch (action_type) {
49 case SyntheticPointerActionParams::PointerActionType::PRESS: 48 case SyntheticPointerActionParams::PointerActionType::PRESS:
50 return WebInputEvent::MouseDown; 49 return WebInputEvent::MouseDown;
51 case SyntheticPointerActionParams::PointerActionType::MOVE: 50 case SyntheticPointerActionParams::PointerActionType::MOVE:
52 return WebInputEvent::MouseMove; 51 return WebInputEvent::MouseMove;
53 case SyntheticPointerActionParams::PointerActionType::RELEASE: 52 case SyntheticPointerActionParams::PointerActionType::RELEASE:
54 return WebInputEvent::MouseUp; 53 return WebInputEvent::MouseUp;
55 case SyntheticPointerActionParams::PointerActionType::IDLE: 54 case SyntheticPointerActionParams::PointerActionType::IDLE:
56 case SyntheticPointerActionParams::PointerActionType::FINISH:
57 case SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED: 55 case SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED:
58 NOTREACHED() 56 NOTREACHED()
59 << "Invalid SyntheticPointerActionParams::PointerActionType."; 57 << "Invalid SyntheticPointerActionParams::PointerActionType.";
60 return WebInputEvent::Undefined; 58 return WebInputEvent::Undefined;
61 } 59 }
62 NOTREACHED() << "Invalid SyntheticPointerActionParams::PointerActionType."; 60 NOTREACHED() << "Invalid SyntheticPointerActionParams::PointerActionType.";
63 return WebInputEvent::Undefined; 61 return WebInputEvent::Undefined;
64 } 62 }
65 63
66 class MockSyntheticPointerActionTarget : public SyntheticGestureTarget { 64 class MockSyntheticPointerActionTarget : public SyntheticGestureTarget {
(...skipping 28 matching lines...) Expand all
95 class MockSyntheticPointerTouchActionTarget 93 class MockSyntheticPointerTouchActionTarget
96 : public MockSyntheticPointerActionTarget { 94 : public MockSyntheticPointerActionTarget {
97 public: 95 public:
98 MockSyntheticPointerTouchActionTarget() {} 96 MockSyntheticPointerTouchActionTarget() {}
99 ~MockSyntheticPointerTouchActionTarget() override {} 97 ~MockSyntheticPointerTouchActionTarget() override {}
100 98
101 void DispatchInputEventToPlatform(const WebInputEvent& event) override { 99 void DispatchInputEventToPlatform(const WebInputEvent& event) override {
102 DCHECK(WebInputEvent::isTouchEventType(event.type)); 100 DCHECK(WebInputEvent::isTouchEventType(event.type));
103 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); 101 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event);
104 type_ = touch_event.type; 102 type_ = touch_event.type;
105 for (size_t i = 0; i < touch_event.touchesLength; ++i) { 103 for (size_t i = 0; i < WebTouchEvent::kTouchesLengthCap; ++i) {
106 indexes_[i] = touch_event.touches[i].id; 104 indexes_[i] = touch_event.touches[i].id;
107 positions_[i] = gfx::PointF(touch_event.touches[i].position); 105 positions_[i] = gfx::PointF(touch_event.touches[i].position);
108 states_[i] = touch_event.touches[i].state; 106 states_[i] = touch_event.touches[i].state;
109 } 107 }
110 touch_length_ = touch_event.touchesLength; 108 touch_length_ = touch_event.touchesLength;
111 } 109 }
112 110
113 testing::AssertionResult SyntheticTouchActionDispatchedCorrectly( 111 testing::AssertionResult SyntheticTouchActionDispatchedCorrectly(
114 const SyntheticPointerActionParams& param, 112 const SyntheticPointerActionParams& param,
115 int index) { 113 int index) {
(...skipping 27 matching lines...) Expand all
143 testing::AssertionResult SyntheticTouchActionListDispatchedCorrectly( 141 testing::AssertionResult SyntheticTouchActionListDispatchedCorrectly(
144 const std::vector<SyntheticPointerActionParams>& params_list) { 142 const std::vector<SyntheticPointerActionParams>& params_list) {
145 if (touch_length_ != params_list.size()) { 143 if (touch_length_ != params_list.size()) {
146 return testing::AssertionFailure() << "Touch point length was " 144 return testing::AssertionFailure() << "Touch point length was "
147 << touch_length_ << ", expected " 145 << touch_length_ << ", expected "
148 << params_list.size() << "."; 146 << params_list.size() << ".";
149 } 147 }
150 148
151 testing::AssertionResult result = testing::AssertionSuccess(); 149 testing::AssertionResult result = testing::AssertionSuccess();
152 for (size_t i = 0; i < params_list.size(); ++i) { 150 for (size_t i = 0; i < params_list.size(); ++i) {
153 result = SyntheticTouchActionDispatchedCorrectly(params_list[i], i); 151 result = SyntheticTouchActionDispatchedCorrectly(params_list[i],
152 params_list[i].index());
154 if (result == testing::AssertionFailure()) 153 if (result == testing::AssertionFailure())
155 return result; 154 return result;
156 } 155 }
157 return testing::AssertionSuccess(); 156 return testing::AssertionSuccess();
158 } 157 }
159 158
160 SyntheticGestureParams::GestureSourceType 159 SyntheticGestureParams::GestureSourceType
161 GetDefaultSyntheticGestureSourceType() const override { 160 GetDefaultSyntheticGestureSourceType() const override {
162 return SyntheticGestureParams::TOUCH_INPUT; 161 return SyntheticGestureParams::TOUCH_INPUT;
163 } 162 }
(...skipping 16 matching lines...) Expand all
180 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); 179 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event);
181 type_ = mouse_event.type; 180 type_ = mouse_event.type;
182 position_ = gfx::PointF(mouse_event.x, mouse_event.y); 181 position_ = gfx::PointF(mouse_event.x, mouse_event.y);
183 clickCount_ = mouse_event.clickCount; 182 clickCount_ = mouse_event.clickCount;
184 button_ = mouse_event.button; 183 button_ = mouse_event.button;
185 } 184 }
186 185
187 testing::AssertionResult SyntheticMouseActionDispatchedCorrectly( 186 testing::AssertionResult SyntheticMouseActionDispatchedCorrectly(
188 const SyntheticPointerActionParams& param, 187 const SyntheticPointerActionParams& param,
189 int click_count) { 188 int click_count) {
190 if (type() != ToWebMouseEventType(param.pointer_action_type())) { 189 if (type_ != ToWebMouseEventType(param.pointer_action_type())) {
191 return testing::AssertionFailure() 190 return testing::AssertionFailure()
192 << "Pointer type was " << WebInputEvent::GetName(type()) 191 << "Pointer type was " << WebInputEvent::GetName(type_)
193 << ", expected " << WebInputEvent::GetName(ToWebMouseEventType( 192 << ", expected " << WebInputEvent::GetName(ToWebMouseEventType(
194 param.pointer_action_type())) 193 param.pointer_action_type())) << ".";
195 << ".";
196 } 194 }
197 195
198 if (clickCount() != click_count) { 196 if (clickCount_ != click_count) {
199 return testing::AssertionFailure() << "Pointer click count was " 197 return testing::AssertionFailure() << "Pointer click count was "
200 << clickCount() << ", expected " 198 << clickCount_ << ", expected "
201 << click_count << "."; 199 << click_count << ".";
202 } 200 }
203 201
204 if (clickCount() == 1 && button() != WebMouseEvent::Button::Left) { 202 if (clickCount_ == 1 && button_ != WebMouseEvent::Button::Left) {
205 return testing::AssertionFailure() 203 return testing::AssertionFailure()
206 << "Pointer button was " << (int)button() << ", expected " 204 << "Pointer button was " << (int)button_ << ", expected "
207 << (int)WebMouseEvent::Button::Left << "."; 205 << (int)WebMouseEvent::Button::Left << ".";
208 } 206 }
209 207
210 if (clickCount() == 0 && button() != WebMouseEvent::Button::NoButton) { 208 if (clickCount_ == 0 && button_ != WebMouseEvent::Button::NoButton) {
211 return testing::AssertionFailure() 209 return testing::AssertionFailure()
212 << "Pointer button was " << (int)button() << ", expected " 210 << "Pointer button was " << (int)button_ << ", expected "
213 << (int)WebMouseEvent::Button::NoButton << "."; 211 << (int)WebMouseEvent::Button::NoButton << ".";
214 } 212 }
215 213
216 if ((param.pointer_action_type() == 214 if ((param.pointer_action_type() ==
217 SyntheticPointerActionParams::PointerActionType::PRESS || 215 SyntheticPointerActionParams::PointerActionType::PRESS ||
218 param.pointer_action_type() == 216 param.pointer_action_type() ==
219 SyntheticPointerActionParams::PointerActionType::MOVE) && 217 SyntheticPointerActionParams::PointerActionType::MOVE) &&
220 position() != param.position()) { 218 position_ != param.position()) {
221 return testing::AssertionFailure() 219 return testing::AssertionFailure()
222 << "Pointer position was " << position().ToString() 220 << "Pointer position was " << position_.ToString()
223 << ", expected " << param.position().ToString() << "."; 221 << ", expected " << param.position().ToString() << ".";
224 } 222 }
225 return testing::AssertionSuccess(); 223 return testing::AssertionSuccess();
226 } 224 }
227 225
228 SyntheticGestureParams::GestureSourceType 226 SyntheticGestureParams::GestureSourceType
229 GetDefaultSyntheticGestureSourceType() const override { 227 GetDefaultSyntheticGestureSourceType() const override {
230 return SyntheticGestureParams::MOUSE_INPUT; 228 return SyntheticGestureParams::MOUSE_INPUT;
231 } 229 }
232 230
233 gfx::PointF position() const { return position_; }
234 int clickCount() const { return clickCount_; }
235 WebMouseEvent::Button button() const { return button_; }
236
237 private: 231 private:
238 gfx::PointF position_; 232 gfx::PointF position_;
239 int clickCount_; 233 int clickCount_;
240 WebMouseEvent::Button button_; 234 WebMouseEvent::Button button_;
241 }; 235 };
242 236
243 class SyntheticPointerActionTest : public testing::Test { 237 class SyntheticPointerActionTest : public testing::Test {
244 public: 238 public:
245 SyntheticPointerActionTest() { 239 SyntheticPointerActionTest() {
246 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 240 params_ = SyntheticPointerActionListParams();
247 num_success_ = 0; 241 num_success_ = 0;
248 num_failure_ = 0; 242 num_failure_ = 0;
249 } 243 }
250 ~SyntheticPointerActionTest() override {} 244 ~SyntheticPointerActionTest() override {}
251 245
252 protected: 246 protected:
253 template <typename MockGestureTarget> 247 template <typename MockGestureTarget>
254 void CreateSyntheticPointerActionTarget() { 248 void CreateSyntheticPointerActionTarget() {
255 target_.reset(new MockGestureTarget()); 249 target_.reset(new MockGestureTarget());
256 synthetic_pointer_driver_ = SyntheticPointerDriver::Create( 250 synthetic_pointer_driver_ = SyntheticPointerDriver::Create(
257 target_->GetDefaultSyntheticGestureSourceType()); 251 target_->GetDefaultSyntheticGestureSourceType());
258 } 252 }
259 253
260 void ForwardSyntheticPointerAction() { 254 void ForwardSyntheticPointerAction() {
261 pointer_action_.reset(new SyntheticPointerAction(
262 action_param_list_.get(), synthetic_pointer_driver_.get()));
263
264 SyntheticGesture::Result result = pointer_action_->ForwardInputEvents( 255 SyntheticGesture::Result result = pointer_action_->ForwardInputEvents(
265 base::TimeTicks::Now(), target_.get()); 256 base::TimeTicks::Now(), target_.get());
266 257
267 if (result == SyntheticGesture::GESTURE_FINISHED) 258 if (result == SyntheticGesture::GESTURE_FINISHED ||
259 result == SyntheticGesture::GESTURE_RUNNING)
268 num_success_++; 260 num_success_++;
269 else 261 else
270 num_failure_++; 262 num_failure_++;
271 } 263 }
272 264
273 int num_success_; 265 int num_success_;
274 int num_failure_; 266 int num_failure_;
275 std::unique_ptr<MockSyntheticPointerActionTarget> target_; 267 std::unique_ptr<MockSyntheticPointerActionTarget> target_;
276 std::unique_ptr<SyntheticGesture> pointer_action_; 268 std::unique_ptr<SyntheticGesture> pointer_action_;
277 std::unique_ptr<SyntheticPointerDriver> synthetic_pointer_driver_; 269 std::unique_ptr<SyntheticPointerDriver> synthetic_pointer_driver_;
278 std::unique_ptr<std::vector<SyntheticPointerActionParams>> action_param_list_; 270 SyntheticPointerActionListParams params_;
279 }; 271 };
280 272
281 TEST_F(SyntheticPointerActionTest, PointerTouchAction) { 273 TEST_F(SyntheticPointerActionTest, PointerTouchAction) {
282 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>(); 274 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>();
283 275
284 // Send a touch press for one finger. 276 // Send a touch press for one finger.
285 SyntheticPointerActionParams params0 = SyntheticPointerActionParams( 277 SyntheticPointerActionParams param1 = SyntheticPointerActionParams(
286 SyntheticPointerActionParams::PointerActionType::PRESS, 278 SyntheticPointerActionParams::PointerActionType::PRESS);
287 SyntheticGestureParams::TOUCH_INPUT); 279 param1.set_index(0);
288 params0.set_position(gfx::PointF(54, 89)); 280 param1.set_position(gfx::PointF(54, 89));
289 action_param_list_->push_back(params0); 281 SyntheticPointerActionListParams::ParamList param_list1;
290 ForwardSyntheticPointerAction(); 282 param_list1.push_back(param1);
291 283 params_.PushPointerActionParamsList(param_list1);
284
285 // Send a touch move for the first finger and a touch press for the second
286 // finger.
287 param1.set_pointer_action_type(
288 SyntheticPointerActionParams::PointerActionType::MOVE);
289 param1.set_position(gfx::PointF(133, 156));
290 SyntheticPointerActionParams param2 = SyntheticPointerActionParams(
291 SyntheticPointerActionParams::PointerActionType::PRESS);
292 param2.set_index(1);
293 param2.set_position(gfx::PointF(79, 132));
294 SyntheticPointerActionListParams::ParamList param_list2;
295 param_list2.push_back(param1);
296 param_list2.push_back(param2);
297 params_.PushPointerActionParamsList(param_list2);
298
299 // Send a touch move for the second finger.
300 param1.set_pointer_action_type(
301 SyntheticPointerActionParams::PointerActionType::IDLE);
302 param2.set_pointer_action_type(
303 SyntheticPointerActionParams::PointerActionType::MOVE);
304 param2.set_position(gfx::PointF(87, 253));
305 SyntheticPointerActionListParams::ParamList param_list3;
306 param_list3.push_back(param1);
307 param_list3.push_back(param2);
308 params_.PushPointerActionParamsList(param_list3);
309
310 // Send touch releases for both fingers.
311 SyntheticPointerActionListParams::ParamList param_list4;
312 param1.set_pointer_action_type(
313 SyntheticPointerActionParams::PointerActionType::RELEASE);
314 param2.set_pointer_action_type(
315 SyntheticPointerActionParams::PointerActionType::RELEASE);
316 param_list4.push_back(param1);
317 param_list4.push_back(param2);
318 params_.PushPointerActionParamsList(param_list4);
319 pointer_action_.reset(new SyntheticPointerAction(params_));
320
321 ForwardSyntheticPointerAction();
292 MockSyntheticPointerTouchActionTarget* pointer_touch_target = 322 MockSyntheticPointerTouchActionTarget* pointer_touch_target =
293 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get()); 323 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get());
294 EXPECT_EQ(1, num_success_); 324 EXPECT_EQ(1, num_success_);
295 EXPECT_EQ(0, num_failure_); 325 EXPECT_EQ(0, num_failure_);
296 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); 326 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
297 EXPECT_TRUE(pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly( 327 EXPECT_TRUE(pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly(
298 *action_param_list_.get())); 328 param_list1));
299 329
300 // Send a touch move for the first finger and a touch press for the second 330 ForwardSyntheticPointerAction();
301 // finger.
302 action_param_list_->at(0).set_pointer_action_type(
303 SyntheticPointerActionParams::PointerActionType::MOVE);
304 action_param_list_->at(0).set_position(gfx::PointF(133, 156));
305 SyntheticPointerActionParams params1 = SyntheticPointerActionParams(
306 SyntheticPointerActionParams::PointerActionType::PRESS,
307 SyntheticGestureParams::TOUCH_INPUT);
308 params1.set_position(gfx::PointF(79, 132));
309 action_param_list_->push_back(params1);
310 ForwardSyntheticPointerAction();
311
312 EXPECT_EQ(2, num_success_); 331 EXPECT_EQ(2, num_success_);
313 EXPECT_EQ(0, num_failure_); 332 EXPECT_EQ(0, num_failure_);
314 // The type of the SyntheticWebTouchEvent is the action of the last finger. 333 // The type of the SyntheticWebTouchEvent is the action of the last finger.
315 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); 334 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
316 EXPECT_TRUE(pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly( 335 EXPECT_TRUE(pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly(
317 *action_param_list_.get())); 336 param_list2));
318 337
319 // Send a touch move for the second finger. 338 ForwardSyntheticPointerAction();
320 action_param_list_->at(1).set_pointer_action_type(
321 SyntheticPointerActionParams::PointerActionType::MOVE);
322 action_param_list_->at(1).set_position(gfx::PointF(87, 253));
323 ForwardSyntheticPointerAction();
324
325 EXPECT_EQ(3, num_success_); 339 EXPECT_EQ(3, num_success_);
326 EXPECT_EQ(0, num_failure_); 340 EXPECT_EQ(0, num_failure_);
327 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchMove); 341 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchMove);
328 EXPECT_TRUE(pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly( 342 EXPECT_TRUE(pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly(
329 *action_param_list_.get())); 343 param_list3));
330 344
331 // Send touch releases for both fingers. 345 ForwardSyntheticPointerAction();
332 action_param_list_->at(0).set_pointer_action_type(
333 SyntheticPointerActionParams::PointerActionType::RELEASE);
334 action_param_list_->at(1).set_pointer_action_type(
335 SyntheticPointerActionParams::PointerActionType::RELEASE);
336 ForwardSyntheticPointerAction();
337
338 EXPECT_EQ(4, num_success_); 346 EXPECT_EQ(4, num_success_);
339 EXPECT_EQ(0, num_failure_); 347 EXPECT_EQ(0, num_failure_);
340 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchEnd); 348 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchEnd);
341 EXPECT_TRUE(pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly( 349 EXPECT_TRUE(pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly(
342 *action_param_list_.get())); 350 param_list4));
343 } 351 }
344 352
345 TEST_F(SyntheticPointerActionTest, PointerTouchActionWithIdle) { 353 TEST_F(SyntheticPointerActionTest, PointerTouchActionsMultiPressRelease) {
346 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>(); 354 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>();
347 int count_success = 1; 355 int count_success = 1;
356
348 // Send a touch press for one finger. 357 // Send a touch press for one finger.
349 SyntheticPointerActionParams params0 = SyntheticPointerActionParams( 358 SyntheticPointerActionParams param1 = SyntheticPointerActionParams(
350 SyntheticPointerActionParams::PointerActionType::PRESS, 359 SyntheticPointerActionParams::PointerActionType::PRESS);
351 SyntheticGestureParams::TOUCH_INPUT); 360 param1.set_index(0);
352 params0.set_position(gfx::PointF(54, 89)); 361 param1.set_position(gfx::PointF(54, 89));
353 action_param_list_->push_back(params0); 362 SyntheticPointerActionListParams::ParamList param_list1;
354 ForwardSyntheticPointerAction(); 363 param_list1.push_back(param1);
355 364 params_.PushPointerActionParamsList(param_list1);
365
366 SyntheticPointerActionParams param2 = SyntheticPointerActionParams(
367 SyntheticPointerActionParams::PointerActionType::PRESS);
368 param2.set_index(1);
369 param2.set_position(gfx::PointF(123, 69));
370 param1.set_pointer_action_type(
371 SyntheticPointerActionParams::PointerActionType::IDLE);
372 SyntheticPointerActionListParams::ParamList param_list2;
373 param_list2.push_back(param1);
374 param_list2.push_back(param2);
375
376 param2.set_pointer_action_type(
377 SyntheticPointerActionParams::PointerActionType::RELEASE);
378 SyntheticPointerActionListParams::ParamList param_list3;
379 param_list3.push_back(param1);
380 param_list3.push_back(param2);
381 for (int i = 0; i < 3; ++i) {
382 // Send a touch press for the second finger and not move the first finger.
383 params_.PushPointerActionParamsList(param_list2);
384
385 // Send a touch release for the second finger and not move the first finger.
386 params_.PushPointerActionParamsList(param_list3);
387 }
388 pointer_action_.reset(new SyntheticPointerAction(params_));
389
390 ForwardSyntheticPointerAction();
356 MockSyntheticPointerTouchActionTarget* pointer_touch_target = 391 MockSyntheticPointerTouchActionTarget* pointer_touch_target =
357 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get()); 392 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get());
358 EXPECT_EQ(count_success++, num_success_); 393 EXPECT_EQ(count_success++, num_success_);
359 EXPECT_EQ(0, num_failure_); 394 EXPECT_EQ(0, num_failure_);
360 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); 395 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
361 EXPECT_TRUE(pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly( 396 EXPECT_TRUE(pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly(
362 *action_param_list_.get())); 397 param_list1));
363 398
364 SyntheticPointerActionParams params1; 399 for (int index = 1; index < 4; ++index) {
365 params1.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
366 action_param_list_->push_back(params1);
367 for (int i = 0; i < 3; ++i) {
368 // Send a touch press for the second finger and not move the first finger.
369 action_param_list_->at(0).set_pointer_action_type(
370 SyntheticPointerActionParams::PointerActionType::IDLE);
371 action_param_list_->at(1).set_pointer_action_type(
372 SyntheticPointerActionParams::PointerActionType::PRESS);
373 action_param_list_->at(1).set_position(gfx::PointF(123, 69));
374 ForwardSyntheticPointerAction(); 400 ForwardSyntheticPointerAction();
375
376 EXPECT_EQ(count_success++, num_success_); 401 EXPECT_EQ(count_success++, num_success_);
377 EXPECT_EQ(0, num_failure_); 402 EXPECT_EQ(0, num_failure_);
378 // The type of the SyntheticWebTouchEvent is the action of the last finger. 403 // The type of the SyntheticWebTouchEvent is the action of the last finger.
379 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); 404 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
380 EXPECT_TRUE( 405 EXPECT_TRUE(
381 pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly( 406 pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly(
382 *action_param_list_.get())); 407 param_list2));
383
384 // Send a touch release for the second finger and not move the first finger.
385 action_param_list_->at(0).set_pointer_action_type(
386 SyntheticPointerActionParams::PointerActionType::IDLE);
387 action_param_list_->at(1).set_pointer_action_type(
388 SyntheticPointerActionParams::PointerActionType::RELEASE);
389 408
390 ForwardSyntheticPointerAction(); 409 ForwardSyntheticPointerAction();
391
392 EXPECT_EQ(count_success++, num_success_); 410 EXPECT_EQ(count_success++, num_success_);
393 EXPECT_EQ(0, num_failure_); 411 EXPECT_EQ(0, num_failure_);
394 // The type of the SyntheticWebTouchEvent is the action of the last finger. 412 // The type of the SyntheticWebTouchEvent is the action of the last finger.
395 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchEnd); 413 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchEnd);
396 EXPECT_TRUE( 414 EXPECT_TRUE(
397 pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly( 415 pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly(
398 *action_param_list_.get())); 416 param_list3));
399 } 417 }
400 } 418 }
401 419
402 TEST_F(SyntheticPointerActionTest, PointerTouchActionSourceTypeInvalid) { 420 TEST_F(SyntheticPointerActionTest, PointerTouchActionTypeInvalid) {
403 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>(); 421 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>();
404 422
405 // Users' gesture source type does not match with the touch action. 423 // Cannot send a touch move or touch release without sending a touch press
406 SyntheticPointerActionParams params = SyntheticPointerActionParams( 424 // first.
407 SyntheticPointerActionParams::PointerActionType::PRESS, 425 SyntheticPointerActionParams param = SyntheticPointerActionParams(
408 SyntheticGestureParams::MOUSE_INPUT); 426 SyntheticPointerActionParams::PointerActionType::MOVE);
409 params.set_position(gfx::PointF(54, 89)); 427 param.set_index(0);
410 action_param_list_->push_back(params); 428 param.set_position(gfx::PointF(54, 89));
411 ForwardSyntheticPointerAction(); 429 params_.PushPointerActionParams(param);
412 430 pointer_action_.reset(new SyntheticPointerAction(params_));
431
432 ForwardSyntheticPointerAction();
413 EXPECT_EQ(0, num_success_); 433 EXPECT_EQ(0, num_success_);
414 EXPECT_EQ(1, num_failure_); 434 EXPECT_EQ(1, num_failure_);
415 435
416 params = SyntheticPointerActionParams( 436 param.set_pointer_action_type(
417 SyntheticPointerActionParams::PointerActionType::PRESS, 437 SyntheticPointerActionParams::PointerActionType::RELEASE);
418 SyntheticGestureParams::TOUCH_INPUT); 438 params_ = SyntheticPointerActionListParams();
419 params.set_position(gfx::PointF(54, 89)); 439 params_.PushPointerActionParams(param);
420 action_param_list_->at(0) = params; 440 pointer_action_.reset(new SyntheticPointerAction(params_));
421 ForwardSyntheticPointerAction(); 441
422 442 ForwardSyntheticPointerAction();
423 MockSyntheticPointerTouchActionTarget* pointer_touch_target =
424 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get());
425 EXPECT_EQ(1, num_success_);
426 EXPECT_EQ(1, num_failure_);
427 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
428 EXPECT_TRUE(pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly(
429 *action_param_list_.get()));
430 }
431
432 TEST_F(SyntheticPointerActionTest, PointerTouchActionTypeInvalid) {
433 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>();
434
435 // Cannot send a touch move or touch release without sending a touch press
436 // first.
437 SyntheticPointerActionParams params = SyntheticPointerActionParams(
438 SyntheticPointerActionParams::PointerActionType::MOVE,
439 SyntheticGestureParams::TOUCH_INPUT);
440 params.set_position(gfx::PointF(54, 89));
441 action_param_list_->push_back(params);
442 ForwardSyntheticPointerAction();
443
444 EXPECT_EQ(0, num_success_);
445 EXPECT_EQ(1, num_failure_);
446
447 action_param_list_->at(0).set_pointer_action_type(
448 SyntheticPointerActionParams::PointerActionType::RELEASE);
449 ForwardSyntheticPointerAction();
450
451 EXPECT_EQ(0, num_success_); 443 EXPECT_EQ(0, num_success_);
452 EXPECT_EQ(2, num_failure_); 444 EXPECT_EQ(2, num_failure_);
453 445
454 // Send a touch press for one finger. 446 // Send a touch press for one finger.
455 action_param_list_->at(0).set_pointer_action_type( 447 param.set_pointer_action_type(
456 SyntheticPointerActionParams::PointerActionType::PRESS); 448 SyntheticPointerActionParams::PointerActionType::PRESS);
457 ForwardSyntheticPointerAction(); 449 params_ = SyntheticPointerActionListParams();
458 450 params_.PushPointerActionParams(param);
451 params_.PushPointerActionParams(param);
452 pointer_action_.reset(new SyntheticPointerAction(params_));
453
454 ForwardSyntheticPointerAction();
459 MockSyntheticPointerTouchActionTarget* pointer_touch_target = 455 MockSyntheticPointerTouchActionTarget* pointer_touch_target =
460 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get()); 456 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get());
461 EXPECT_EQ(1, num_success_); 457 EXPECT_EQ(1, num_success_);
462 EXPECT_EQ(2, num_failure_); 458 EXPECT_EQ(2, num_failure_);
463 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); 459 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
464 EXPECT_TRUE(pointer_touch_target->SyntheticTouchActionListDispatchedCorrectly( 460 EXPECT_TRUE(
465 *action_param_list_.get())); 461 pointer_touch_target->SyntheticTouchActionDispatchedCorrectly(param, 0));
466 462
467 // Cannot send a touch press again without releasing the finger. 463 // Cannot send a touch press again without releasing the finger.
468 action_param_list_->at(0).gesture_source_type = 464 ForwardSyntheticPointerAction();
469 SyntheticGestureParams::TOUCH_INPUT;
470 action_param_list_->at(0).set_pointer_action_type(
471 SyntheticPointerActionParams::PointerActionType::PRESS);
472 ForwardSyntheticPointerAction();
473
474 EXPECT_EQ(1, num_success_); 465 EXPECT_EQ(1, num_success_);
475 EXPECT_EQ(3, num_failure_); 466 EXPECT_EQ(3, num_failure_);
476 } 467 }
477 468
478 TEST_F(SyntheticPointerActionTest, PointerMouseAction) { 469 TEST_F(SyntheticPointerActionTest, PointerMouseAction) {
479 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>(); 470 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>();
480 471
481 // Send a mouse move. 472 // Send a mouse move.
482 SyntheticPointerActionParams params = SyntheticPointerActionParams( 473 SyntheticPointerActionParams param1 = SyntheticPointerActionParams(
483 SyntheticPointerActionParams::PointerActionType::MOVE, 474 SyntheticPointerActionParams::PointerActionType::MOVE);
484 SyntheticGestureParams::MOUSE_INPUT); 475 param1.set_position(gfx::PointF(189, 62));
485 params.set_position(gfx::PointF(189, 62)); 476 params_.PushPointerActionParams(param1);
486 action_param_list_->push_back(params); 477
478 // Send a mouse down.
479 SyntheticPointerActionParams param2 = SyntheticPointerActionParams(
480 SyntheticPointerActionParams::PointerActionType::PRESS);
481 param2.set_position(gfx::PointF(189, 62));
482 params_.PushPointerActionParams(param2);
483
484 // Send a mouse drag.
485 SyntheticPointerActionParams param3 = SyntheticPointerActionParams(
486 SyntheticPointerActionParams::PointerActionType::MOVE);
487 param3.set_position(gfx::PointF(326, 298));
488 params_.PushPointerActionParams(param3);
489
490 // Send a mouse up.
491 SyntheticPointerActionParams param4 = SyntheticPointerActionParams(
492 SyntheticPointerActionParams::PointerActionType::RELEASE);
493 params_.PushPointerActionParams(param4);
494 pointer_action_.reset(new SyntheticPointerAction(params_));
495
487 ForwardSyntheticPointerAction(); 496 ForwardSyntheticPointerAction();
488
489 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = 497 MockSyntheticPointerMouseActionTarget* pointer_mouse_target =
490 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); 498 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get());
491 EXPECT_EQ(1, num_success_); 499 EXPECT_EQ(1, num_success_);
492 EXPECT_EQ(0, num_failure_); 500 EXPECT_EQ(0, num_failure_);
493 EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly( 501 EXPECT_TRUE(
494 action_param_list_->at(0), 0)); 502 pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param1, 0));
495 503
496 // Send a mouse down.
497 action_param_list_->at(0).set_position(gfx::PointF(189, 62));
498 action_param_list_->at(0).set_pointer_action_type(
499 SyntheticPointerActionParams::PointerActionType::PRESS);
500 ForwardSyntheticPointerAction(); 504 ForwardSyntheticPointerAction();
501
502 EXPECT_EQ(2, num_success_); 505 EXPECT_EQ(2, num_success_);
503 EXPECT_EQ(0, num_failure_); 506 EXPECT_EQ(0, num_failure_);
504 EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly( 507 EXPECT_TRUE(
505 action_param_list_->at(0), 1)); 508 pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param2, 1));
506 509
507 // Send a mouse drag.
508 action_param_list_->at(0).set_position(gfx::PointF(326, 298));
509 action_param_list_->at(0).set_pointer_action_type(
510 SyntheticPointerActionParams::PointerActionType::MOVE);
511 ForwardSyntheticPointerAction(); 510 ForwardSyntheticPointerAction();
512
513 EXPECT_EQ(3, num_success_); 511 EXPECT_EQ(3, num_success_);
514 EXPECT_EQ(0, num_failure_); 512 EXPECT_EQ(0, num_failure_);
515 EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly( 513 EXPECT_TRUE(
516 action_param_list_->at(0), 1)); 514 pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param3, 1));
517 515
518 // Send a mouse up.
519 action_param_list_->at(0).set_pointer_action_type(
520 SyntheticPointerActionParams::PointerActionType::RELEASE);
521 ForwardSyntheticPointerAction(); 516 ForwardSyntheticPointerAction();
522
523 EXPECT_EQ(4, num_success_); 517 EXPECT_EQ(4, num_success_);
524 EXPECT_EQ(0, num_failure_); 518 EXPECT_EQ(0, num_failure_);
525 EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly( 519 EXPECT_TRUE(
526 action_param_list_->at(0), 1)); 520 pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param4, 1));
527 }
528
529 TEST_F(SyntheticPointerActionTest, PointerMouseActionSourceTypeInvalid) {
530 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>();
531
532 // Users' gesture source type does not match with the mouse action.
533 SyntheticPointerActionParams params = SyntheticPointerActionParams(
534 SyntheticPointerActionParams::PointerActionType::PRESS,
535 SyntheticGestureParams::TOUCH_INPUT);
536 params.set_position(gfx::PointF(54, 89));
537 action_param_list_->push_back(params);
538 ForwardSyntheticPointerAction();
539
540 EXPECT_EQ(0, num_success_);
541 EXPECT_EQ(1, num_failure_);
542
543 params = SyntheticPointerActionParams(
544 SyntheticPointerActionParams::PointerActionType::PRESS,
545 SyntheticGestureParams::MOUSE_INPUT);
546 params.set_position(gfx::PointF(54, 89));
547 action_param_list_->at(0) = params;
548 ForwardSyntheticPointerAction();
549
550 MockSyntheticPointerMouseActionTarget* pointer_mouse_target =
551 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get());
552 EXPECT_EQ(1, num_success_);
553 EXPECT_EQ(1, num_failure_);
554 EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(
555 action_param_list_->at(0), 1));
556 } 521 }
557 522
558 TEST_F(SyntheticPointerActionTest, PointerMouseActionTypeInvalid) { 523 TEST_F(SyntheticPointerActionTest, PointerMouseActionTypeInvalid) {
559 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>(); 524 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>();
560 525
561 // Send a mouse move. 526 // Cannot send a mouse up without sending a mouse down first.
562 SyntheticPointerActionParams params = SyntheticPointerActionParams( 527 SyntheticPointerActionParams param = SyntheticPointerActionParams(
563 SyntheticPointerActionParams::PointerActionType::MOVE, 528 SyntheticPointerActionParams::PointerActionType::RELEASE);
564 SyntheticGestureParams::MOUSE_INPUT); 529 params_.PushPointerActionParams(param);
565 params.set_position(gfx::PointF(189, 62)); 530 pointer_action_.reset(new SyntheticPointerAction(params_));
566 action_param_list_->push_back(params); 531
567 ForwardSyntheticPointerAction(); 532 ForwardSyntheticPointerAction();
533 EXPECT_EQ(0, num_success_);
534 EXPECT_EQ(1, num_failure_);
568 535
536 // Send a mouse down for one finger.
537 param.set_pointer_action_type(
538 SyntheticPointerActionParams::PointerActionType::PRESS);
539 param.set_position(gfx::PointF(54, 89));
540 params_ = SyntheticPointerActionListParams();
541 params_.PushPointerActionParams(param);
542
543 // Cannot send a mouse down again without releasing the mouse button.
544 params_.PushPointerActionParams(param);
545 pointer_action_.reset(new SyntheticPointerAction(params_));
546
547 ForwardSyntheticPointerAction();
569 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = 548 MockSyntheticPointerMouseActionTarget* pointer_mouse_target =
570 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); 549 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get());
571 EXPECT_EQ(1, num_success_); 550 EXPECT_EQ(1, num_success_);
572 EXPECT_EQ(0, num_failure_); 551 EXPECT_EQ(1, num_failure_);
573 EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly( 552 EXPECT_TRUE(
574 action_param_list_->at(0), 0)); 553 pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param, 1));
575 554
576 // Cannot send a mouse up without sending a mouse down first.
577 action_param_list_->at(0).set_pointer_action_type(
578 SyntheticPointerActionParams::PointerActionType::RELEASE);
579 ForwardSyntheticPointerAction(); 555 ForwardSyntheticPointerAction();
580
581 EXPECT_EQ(1, num_success_); 556 EXPECT_EQ(1, num_success_);
582 EXPECT_EQ(1, num_failure_);
583
584 // Send a mouse down for one finger.
585 action_param_list_->at(0).set_pointer_action_type(
586 SyntheticPointerActionParams::PointerActionType::PRESS);
587 ForwardSyntheticPointerAction();
588
589 EXPECT_EQ(2, num_success_);
590 EXPECT_EQ(1, num_failure_);
591 EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(
592 action_param_list_->at(0), 1));
593
594 // Cannot send a mouse down again without releasing the mouse button.
595 action_param_list_->at(0).set_pointer_action_type(
596 SyntheticPointerActionParams::PointerActionType::PRESS);
597 ForwardSyntheticPointerAction();
598
599 EXPECT_EQ(2, num_success_);
600 EXPECT_EQ(2, num_failure_); 557 EXPECT_EQ(2, num_failure_);
601 } 558 }
602 559
603 } // namespace 560 } // namespace
604 561
605 } // namespace content 562 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698