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

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

Issue 2178153002: Prepare SyntheticPointerAction to handle mouse actions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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_pointer.h" 10 #include "content/browser/renderer_host/input/synthetic_touch_pointer.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/WebKit/public/web/WebInputEvent.h" 12 #include "third_party/WebKit/public/web/WebInputEvent.h"
13 #include "ui/gfx/geometry/point.h" 13 #include "ui/gfx/geometry/point.h"
14 #include "ui/gfx/geometry/point_f.h" 14 #include "ui/gfx/geometry/point_f.h"
15 15
16 using blink::WebInputEvent; 16 using blink::WebInputEvent;
17 using blink::WebTouchEvent; 17 using blink::WebTouchEvent;
18 using blink::WebMouseEvent;
18 using blink::WebTouchPoint; 19 using blink::WebTouchPoint;
19 20
20 namespace content { 21 namespace content {
21 22
22 namespace { 23 namespace {
23 24
24 class MockSyntheticPointerActionTarget : public SyntheticGestureTarget { 25 class MockSyntheticPointerActionTarget : public SyntheticGestureTarget {
25 public: 26 public:
26 MockSyntheticPointerActionTarget() {} 27 MockSyntheticPointerActionTarget() {}
27 ~MockSyntheticPointerActionTarget() override {} 28 ~MockSyntheticPointerActionTarget() override {}
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 WebTouchPoint::State states(int index) { return states_[index]; } 79 WebTouchPoint::State states(int index) { return states_[index]; }
79 unsigned touch_length() const { return touch_length_; } 80 unsigned touch_length() const { return touch_length_; }
80 81
81 private: 82 private:
82 gfx::PointF positions_[WebTouchEvent::touchesLengthCap]; 83 gfx::PointF positions_[WebTouchEvent::touchesLengthCap];
83 unsigned touch_length_; 84 unsigned touch_length_;
84 int indexes_[WebTouchEvent::touchesLengthCap]; 85 int indexes_[WebTouchEvent::touchesLengthCap];
85 WebTouchPoint::State states_[WebTouchEvent::touchesLengthCap]; 86 WebTouchPoint::State states_[WebTouchEvent::touchesLengthCap];
86 }; 87 };
87 88
89 class MockSyntheticPointerMouseActionTarget
90 : public MockSyntheticPointerActionTarget {
91 public:
92 MockSyntheticPointerMouseActionTarget() {}
93 ~MockSyntheticPointerMouseActionTarget() override {}
94
95 void DispatchInputEventToPlatform(const WebInputEvent& event) override {
96 ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type));
97 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event);
98 type_ = mouse_event.type;
99 position_ = gfx::PointF(mouse_event.x, mouse_event.y);
100 clickCount_ = mouse_event.clickCount;
101 button_ = mouse_event.button;
102 }
103
104 SyntheticGestureParams::GestureSourceType
105 GetDefaultSyntheticGestureSourceType() const override {
106 return SyntheticGestureParams::MOUSE_INPUT;
107 }
108
109 gfx::PointF position() const { return position_; }
110 int clickCount() const { return clickCount_; }
111 WebMouseEvent::Button button() const { return button_; }
112
113 private:
114 gfx::PointF position_;
115 int clickCount_;
116 WebMouseEvent::Button button_;
117 };
118
88 class SyntheticPointerActionTest : public testing::Test { 119 class SyntheticPointerActionTest : public testing::Test {
89 public: 120 public:
90 SyntheticPointerActionTest() { 121 SyntheticPointerActionTest() {
91 target_.reset(new MockSyntheticPointerTouchActionTarget());
92 synthetic_pointer_ =
93 SyntheticPointer::Create(SyntheticGestureParams::TOUCH_INPUT);
94 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 122 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
95 std::fill(index_map_.begin(), index_map_.end(), -1); 123 std::fill(index_map_.begin(), index_map_.end(), -1);
96 num_success_ = 0; 124 num_success_ = 0;
97 num_failure_ = 0; 125 num_failure_ = 0;
98 } 126 }
99 ~SyntheticPointerActionTest() override {} 127 ~SyntheticPointerActionTest() override {}
100 128
101 protected: 129 protected:
130 template <typename MockGestureTarget>
131 void CreateSyntheticPointerActionTarget() {
132 target_.reset(new MockGestureTarget());
133 synthetic_pointer_ = SyntheticPointer::Create(
134 target_->GetDefaultSyntheticGestureSourceType());
135 }
136
102 void ForwardSyntheticPointerAction() { 137 void ForwardSyntheticPointerAction() {
103 pointer_action_.reset(new SyntheticPointerAction( 138 pointer_action_.reset(new SyntheticPointerAction(
104 std::move(action_param_list_), synthetic_pointer_.get(), &index_map_)); 139 std::move(action_param_list_), synthetic_pointer_.get(), &index_map_));
105 140
106 SyntheticGesture::Result result = pointer_action_->ForwardInputEvents( 141 SyntheticGesture::Result result = pointer_action_->ForwardInputEvents(
107 base::TimeTicks::Now(), target_.get()); 142 base::TimeTicks::Now(), target_.get());
108 143
109 if (result == SyntheticGesture::GESTURE_FINISHED) 144 if (result == SyntheticGesture::GESTURE_FINISHED)
110 num_success_++; 145 num_success_++;
111 else 146 else
112 num_failure_++; 147 num_failure_++;
113 } 148 }
114 149
115 int num_success_; 150 int num_success_;
116 int num_failure_; 151 int num_failure_;
117 std::unique_ptr<MockSyntheticPointerActionTarget> target_; 152 std::unique_ptr<MockSyntheticPointerActionTarget> target_;
118 std::unique_ptr<SyntheticGesture> pointer_action_; 153 std::unique_ptr<SyntheticGesture> pointer_action_;
119 std::unique_ptr<SyntheticPointer> synthetic_pointer_; 154 std::unique_ptr<SyntheticPointer> synthetic_pointer_;
120 std::unique_ptr<std::vector<SyntheticPointerActionParams>> action_param_list_; 155 std::unique_ptr<std::vector<SyntheticPointerActionParams>> action_param_list_;
121 SyntheticPointerAction::IndexMap index_map_; 156 SyntheticPointerAction::IndexMap index_map_;
122 }; 157 };
123 158
124 TEST_F(SyntheticPointerActionTest, PointerTouchAction) { 159 TEST_F(SyntheticPointerActionTest, PointerTouchAction) {
160 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>();
161
125 // Send a touch press for one finger. 162 // Send a touch press for one finger.
126 SyntheticPointerActionParams params0 = SyntheticPointerActionParams( 163 SyntheticPointerActionParams params0 = SyntheticPointerActionParams(
127 SyntheticPointerActionParams::PointerActionType::PRESS); 164 SyntheticPointerActionParams::PointerActionType::PRESS);
128 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 165 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
129 params0.set_index(0); 166 params0.set_index(0);
130 params0.set_position(gfx::PointF(54, 89)); 167 params0.set_position(gfx::PointF(54, 89));
131 action_param_list_->push_back(params0); 168 action_param_list_->push_back(params0);
132 ForwardSyntheticPointerAction(); 169 ForwardSyntheticPointerAction();
133 170
134 MockSyntheticPointerTouchActionTarget* pointer_touch_target = 171 MockSyntheticPointerTouchActionTarget* pointer_touch_target =
(...skipping 15 matching lines...) Expand all
150 params0.set_position(gfx::PointF(133, 156)); 187 params0.set_position(gfx::PointF(133, 156));
151 SyntheticPointerActionParams params1 = SyntheticPointerActionParams( 188 SyntheticPointerActionParams params1 = SyntheticPointerActionParams(
152 SyntheticPointerActionParams::PointerActionType::PRESS); 189 SyntheticPointerActionParams::PointerActionType::PRESS);
153 params1.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 190 params1.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
154 params1.set_index(1); 191 params1.set_index(1);
155 params1.set_position(gfx::PointF(79, 132)); 192 params1.set_position(gfx::PointF(79, 132));
156 action_param_list_->push_back(params0); 193 action_param_list_->push_back(params0);
157 action_param_list_->push_back(params1); 194 action_param_list_->push_back(params1);
158 ForwardSyntheticPointerAction(); 195 ForwardSyntheticPointerAction();
159 196
160 pointer_touch_target =
161 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get());
162 EXPECT_EQ(2, num_success_); 197 EXPECT_EQ(2, num_success_);
163 EXPECT_EQ(0, num_failure_); 198 EXPECT_EQ(0, num_failure_);
164 // The type of the SyntheticWebTouchEvent is the action of the last finger. 199 // The type of the SyntheticWebTouchEvent is the action of the last finger.
165 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); 200 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
166 EXPECT_EQ(pointer_touch_target->indexes(0), 0); 201 EXPECT_EQ(pointer_touch_target->indexes(0), 0);
167 EXPECT_EQ(index_map_[0], 0); 202 EXPECT_EQ(index_map_[0], 0);
168 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(133, 156)); 203 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(133, 156));
169 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateMoved); 204 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateMoved);
170 EXPECT_EQ(pointer_touch_target->indexes(1), 1); 205 EXPECT_EQ(pointer_touch_target->indexes(1), 1);
171 EXPECT_EQ(index_map_[1], 1); 206 EXPECT_EQ(index_map_[1], 1);
172 EXPECT_EQ(pointer_touch_target->positions(1), gfx::PointF(79, 132)); 207 EXPECT_EQ(pointer_touch_target->positions(1), gfx::PointF(79, 132));
173 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StatePressed); 208 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StatePressed);
174 ASSERT_EQ(pointer_touch_target->touch_length(), 2U); 209 ASSERT_EQ(pointer_touch_target->touch_length(), 2U);
175 210
176 // Send a touch move for the second finger. 211 // Send a touch move for the second finger.
177 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 212 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
178 params1.set_pointer_action_type( 213 params1.set_pointer_action_type(
179 SyntheticPointerActionParams::PointerActionType::MOVE); 214 SyntheticPointerActionParams::PointerActionType::MOVE);
180 params1.set_position(gfx::PointF(87, 253)); 215 params1.set_position(gfx::PointF(87, 253));
181 action_param_list_->push_back(params1); 216 action_param_list_->push_back(params1);
182 ForwardSyntheticPointerAction(); 217 ForwardSyntheticPointerAction();
183 218
184 pointer_touch_target =
185 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get());
186 EXPECT_EQ(3, num_success_); 219 EXPECT_EQ(3, num_success_);
187 EXPECT_EQ(0, num_failure_); 220 EXPECT_EQ(0, num_failure_);
188 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchMove); 221 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchMove);
189 EXPECT_EQ(pointer_touch_target->indexes(1), 1); 222 EXPECT_EQ(pointer_touch_target->indexes(1), 1);
190 EXPECT_EQ(index_map_[1], 1); 223 EXPECT_EQ(index_map_[1], 1);
191 EXPECT_EQ(pointer_touch_target->positions(1), gfx::PointF(87, 253)); 224 EXPECT_EQ(pointer_touch_target->positions(1), gfx::PointF(87, 253));
192 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateMoved); 225 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateMoved);
193 ASSERT_EQ(pointer_touch_target->touch_length(), 2U); 226 ASSERT_EQ(pointer_touch_target->touch_length(), 2U);
194 227
195 // Send touch releases for both fingers. 228 // Send touch releases for both fingers.
(...skipping 12 matching lines...) Expand all
208 EXPECT_EQ(pointer_touch_target->indexes(0), 0); 241 EXPECT_EQ(pointer_touch_target->indexes(0), 0);
209 EXPECT_EQ(index_map_[0], -1); 242 EXPECT_EQ(index_map_[0], -1);
210 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateReleased); 243 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateReleased);
211 EXPECT_EQ(pointer_touch_target->indexes(1), 1); 244 EXPECT_EQ(pointer_touch_target->indexes(1), 1);
212 EXPECT_EQ(index_map_[1], -1); 245 EXPECT_EQ(index_map_[1], -1);
213 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased); 246 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased);
214 ASSERT_EQ(pointer_touch_target->touch_length(), 2U); 247 ASSERT_EQ(pointer_touch_target->touch_length(), 2U);
215 } 248 }
216 249
217 TEST_F(SyntheticPointerActionTest, PointerTouchActionIndexInvalid) { 250 TEST_F(SyntheticPointerActionTest, PointerTouchActionIndexInvalid) {
251 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>();
252
218 // Users sent a wrong index for the touch action. 253 // Users sent a wrong index for the touch action.
219 SyntheticPointerActionParams params0 = SyntheticPointerActionParams( 254 SyntheticPointerActionParams params0 = SyntheticPointerActionParams(
220 SyntheticPointerActionParams::PointerActionType::PRESS); 255 SyntheticPointerActionParams::PointerActionType::PRESS);
221 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 256 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
222 params0.set_index(-1); 257 params0.set_index(-1);
223 params0.set_position(gfx::PointF(54, 89)); 258 params0.set_position(gfx::PointF(54, 89));
224 action_param_list_->push_back(params0); 259 action_param_list_->push_back(params0);
225 ForwardSyntheticPointerAction(); 260 ForwardSyntheticPointerAction();
226 261
227 EXPECT_EQ(0, num_success_); 262 EXPECT_EQ(0, num_success_);
(...skipping 10 matching lines...) Expand all
238 EXPECT_EQ(1, num_failure_); 273 EXPECT_EQ(1, num_failure_);
239 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); 274 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
240 EXPECT_EQ(pointer_touch_target->indexes(0), 0); 275 EXPECT_EQ(pointer_touch_target->indexes(0), 0);
241 EXPECT_EQ(index_map_[0], 0); 276 EXPECT_EQ(index_map_[0], 0);
242 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89)); 277 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89));
243 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); 278 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed);
244 ASSERT_EQ(pointer_touch_target->touch_length(), 1U); 279 ASSERT_EQ(pointer_touch_target->touch_length(), 1U);
245 } 280 }
246 281
247 TEST_F(SyntheticPointerActionTest, PointerTouchActionSourceTypeInvalid) { 282 TEST_F(SyntheticPointerActionTest, PointerTouchActionSourceTypeInvalid) {
283 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>();
284
248 // Users' gesture source type does not match with the touch action. 285 // Users' gesture source type does not match with the touch action.
249 SyntheticPointerActionParams params0 = SyntheticPointerActionParams( 286 SyntheticPointerActionParams params0 = SyntheticPointerActionParams(
250 SyntheticPointerActionParams::PointerActionType::PRESS); 287 SyntheticPointerActionParams::PointerActionType::PRESS);
251 params0.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 288 params0.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
252 params0.set_index(0); 289 params0.set_index(0);
253 params0.set_position(gfx::PointF(54, 89)); 290 params0.set_position(gfx::PointF(54, 89));
254 action_param_list_->push_back(params0); 291 action_param_list_->push_back(params0);
255 ForwardSyntheticPointerAction(); 292 ForwardSyntheticPointerAction();
256 293
257 EXPECT_EQ(0, num_success_); 294 EXPECT_EQ(0, num_success_);
(...skipping 10 matching lines...) Expand all
268 EXPECT_EQ(1, num_failure_); 305 EXPECT_EQ(1, num_failure_);
269 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); 306 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
270 EXPECT_EQ(pointer_touch_target->indexes(0), 0); 307 EXPECT_EQ(pointer_touch_target->indexes(0), 0);
271 EXPECT_EQ(index_map_[0], 0); 308 EXPECT_EQ(index_map_[0], 0);
272 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89)); 309 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89));
273 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); 310 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed);
274 ASSERT_EQ(pointer_touch_target->touch_length(), 1U); 311 ASSERT_EQ(pointer_touch_target->touch_length(), 1U);
275 } 312 }
276 313
277 TEST_F(SyntheticPointerActionTest, PointerTouchActionTypeInvalid) { 314 TEST_F(SyntheticPointerActionTest, PointerTouchActionTypeInvalid) {
315 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>();
316
278 // Cannot send a touch move or touch release without sending a touch press 317 // Cannot send a touch move or touch release without sending a touch press
279 // first. 318 // first.
280 SyntheticPointerActionParams params0 = SyntheticPointerActionParams( 319 SyntheticPointerActionParams params0 = SyntheticPointerActionParams(
281 SyntheticPointerActionParams::PointerActionType::MOVE); 320 SyntheticPointerActionParams::PointerActionType::MOVE);
282 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 321 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
283 params0.set_index(0); 322 params0.set_index(0);
284 params0.set_position(gfx::PointF(54, 89)); 323 params0.set_position(gfx::PointF(54, 89));
285 action_param_list_->push_back(params0); 324 action_param_list_->push_back(params0);
286 ForwardSyntheticPointerAction(); 325 ForwardSyntheticPointerAction();
287 326
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 params0.set_index(0); 360 params0.set_index(0);
322 params0.set_pointer_action_type( 361 params0.set_pointer_action_type(
323 SyntheticPointerActionParams::PointerActionType::PRESS); 362 SyntheticPointerActionParams::PointerActionType::PRESS);
324 action_param_list_->push_back(params0); 363 action_param_list_->push_back(params0);
325 ForwardSyntheticPointerAction(); 364 ForwardSyntheticPointerAction();
326 365
327 EXPECT_EQ(1, num_success_); 366 EXPECT_EQ(1, num_success_);
328 EXPECT_EQ(3, num_failure_); 367 EXPECT_EQ(3, num_failure_);
329 } 368 }
330 369
370 TEST_F(SyntheticPointerActionTest, PointerMouseAction) {
tdresser 2016/07/26 12:27:41 How different are the touch and mouse tests? Could
371 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>();
372
373 // Send a mouse move.
374 SyntheticPointerActionParams params = SyntheticPointerActionParams(
375 SyntheticPointerActionParams::PointerActionType::MOVE);
376 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
377 params.set_position(gfx::PointF(189, 62));
378 action_param_list_->push_back(params);
379 ForwardSyntheticPointerAction();
380
381 MockSyntheticPointerMouseActionTarget* pointer_mouse_target =
382 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get());
383 EXPECT_EQ(1, num_success_);
384 EXPECT_EQ(0, num_failure_);
385 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove);
386 EXPECT_EQ(pointer_mouse_target->position(), params.position());
387 EXPECT_EQ(pointer_mouse_target->clickCount(), 0);
388 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonNone);
389
390 // Send a mouse down.
391 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
392 params.set_position(gfx::PointF(189, 62));
393 params.set_pointer_action_type(
394 SyntheticPointerActionParams::PointerActionType::PRESS);
395 action_param_list_->push_back(params);
396 ForwardSyntheticPointerAction();
397
398 EXPECT_EQ(2, num_success_);
399 EXPECT_EQ(0, num_failure_);
400 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown);
401 EXPECT_EQ(pointer_mouse_target->position(), params.position());
402 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
403 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft);
404
405 // Send a mouse drag.
406 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
407 params.set_position(gfx::PointF(326, 298));
408 params.set_pointer_action_type(
409 SyntheticPointerActionParams::PointerActionType::MOVE);
410 action_param_list_->push_back(params);
411 ForwardSyntheticPointerAction();
412
413 EXPECT_EQ(3, num_success_);
414 EXPECT_EQ(0, num_failure_);
415 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove);
416 EXPECT_EQ(pointer_mouse_target->position(), params.position());
417 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
418 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft);
419
420 // Send a mouse up.
421 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
422 params.set_pointer_action_type(
423 SyntheticPointerActionParams::PointerActionType::RELEASE);
424 action_param_list_->push_back(params);
425 ForwardSyntheticPointerAction();
426
427 EXPECT_EQ(4, num_success_);
428 EXPECT_EQ(0, num_failure_);
429 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseUp);
430 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
431 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft);
432 }
433
434 TEST_F(SyntheticPointerActionTest, PointerMouseActionIndexInvalid) {
435 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>();
436
437 // Users sent a wrong index for the mouse action.
438 SyntheticPointerActionParams params = SyntheticPointerActionParams(
439 SyntheticPointerActionParams::PointerActionType::PRESS);
440 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
441 params.set_index(-1);
442 params.set_position(gfx::PointF(54, 89));
443 action_param_list_->push_back(params);
444 ForwardSyntheticPointerAction();
445
446 EXPECT_EQ(0, num_success_);
447 EXPECT_EQ(1, num_failure_);
448
449 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
450 params.set_index(0);
451 action_param_list_->push_back(params);
452 ForwardSyntheticPointerAction();
453
454 MockSyntheticPointerMouseActionTarget* pointer_mouse_target =
455 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get());
456 EXPECT_EQ(1, num_success_);
457 EXPECT_EQ(1, num_failure_);
458 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown);
459 EXPECT_EQ(pointer_mouse_target->position(), params.position());
460 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
461 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft);
462 }
463
464 TEST_F(SyntheticPointerActionTest, PointerMouseActionSourceTypeInvalid) {
465 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>();
466
467 // Users' gesture source type does not match with the mouse action.
468 SyntheticPointerActionParams params = SyntheticPointerActionParams(
469 SyntheticPointerActionParams::PointerActionType::PRESS);
470 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
471 params.set_index(0);
472 params.set_position(gfx::PointF(54, 89));
473 action_param_list_->push_back(params);
474 ForwardSyntheticPointerAction();
475
476 EXPECT_EQ(0, num_success_);
477 EXPECT_EQ(1, num_failure_);
478
479 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
480 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
481 action_param_list_->push_back(params);
482 ForwardSyntheticPointerAction();
483
484 MockSyntheticPointerMouseActionTarget* pointer_mouse_target =
485 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get());
486 EXPECT_EQ(1, num_success_);
487 EXPECT_EQ(1, num_failure_);
488 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown);
489 EXPECT_EQ(pointer_mouse_target->position(), params.position());
490 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
491 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft);
492 }
493
494 TEST_F(SyntheticPointerActionTest, PointerMouseActionTypeInvalid) {
495 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>();
496
497 // Send a mouse move.
498 SyntheticPointerActionParams params = SyntheticPointerActionParams(
499 SyntheticPointerActionParams::PointerActionType::MOVE);
500 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
501 params.set_position(gfx::PointF(189, 62));
502 action_param_list_->push_back(params);
503 ForwardSyntheticPointerAction();
504
505 MockSyntheticPointerMouseActionTarget* pointer_mouse_target =
506 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get());
507 EXPECT_EQ(1, num_success_);
508 EXPECT_EQ(0, num_failure_);
509 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove);
510 EXPECT_EQ(pointer_mouse_target->position(), params.position());
511 EXPECT_EQ(pointer_mouse_target->clickCount(), 0);
512 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonNone);
513
514 // Cannot send a mouse up without sending a mouse down first.
515 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
516 params.set_pointer_action_type(
517 SyntheticPointerActionParams::PointerActionType::RELEASE);
518 action_param_list_->push_back(params);
519 ForwardSyntheticPointerAction();
520
521 EXPECT_EQ(1, num_success_);
522 EXPECT_EQ(1, num_failure_);
523
524 // Send a mouse down for one finger.
525 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
526 params.set_pointer_action_type(
527 SyntheticPointerActionParams::PointerActionType::PRESS);
528 action_param_list_->push_back(params);
529 ForwardSyntheticPointerAction();
530
531 EXPECT_EQ(2, num_success_);
532 EXPECT_EQ(1, num_failure_);
533 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown);
534 EXPECT_EQ(pointer_mouse_target->position(), params.position());
535 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
536 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft);
537
538 // Cannot send a mouse down again without releasing the mouse button.
539 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
540 params.set_pointer_action_type(
541 SyntheticPointerActionParams::PointerActionType::PRESS);
542 action_param_list_->push_back(params);
543 ForwardSyntheticPointerAction();
544
545 EXPECT_EQ(2, num_success_);
546 EXPECT_EQ(2, num_failure_);
547 }
548
331 } // namespace 549 } // namespace
332 550
333 } // namespace content 551 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698