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

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: Add comment 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::kTouchesLengthCap]; 83 gfx::PointF positions_[WebTouchEvent::kTouchesLengthCap];
83 unsigned touch_length_; 84 unsigned touch_length_;
84 int indexes_[WebTouchEvent::kTouchesLengthCap]; 85 int indexes_[WebTouchEvent::kTouchesLengthCap];
85 WebTouchPoint::State states_[WebTouchEvent::kTouchesLengthCap]; 86 WebTouchPoint::State states_[WebTouchEvent::kTouchesLengthCap];
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) {
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_index(0);
378 params.set_position(gfx::PointF(189, 62));
379 action_param_list_->push_back(params);
380 ForwardSyntheticPointerAction();
381
382 MockSyntheticPointerMouseActionTarget* pointer_mouse_target =
383 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get());
384 EXPECT_EQ(1, num_success_);
385 EXPECT_EQ(0, num_failure_);
386 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove);
387 EXPECT_EQ(pointer_mouse_target->position(), params.position());
388 EXPECT_EQ(pointer_mouse_target->clickCount(), 0);
389 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonNone);
390
391 // Send a mouse down.
392 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
393 params.set_position(gfx::PointF(189, 62));
394 params.set_pointer_action_type(
395 SyntheticPointerActionParams::PointerActionType::PRESS);
396 action_param_list_->push_back(params);
397 ForwardSyntheticPointerAction();
398
399 EXPECT_EQ(2, num_success_);
400 EXPECT_EQ(0, num_failure_);
401 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown);
402 EXPECT_EQ(pointer_mouse_target->position(), params.position());
403 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
404 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft);
405
406 // Send a mouse drag.
407 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
408 params.set_position(gfx::PointF(326, 298));
409 params.set_pointer_action_type(
410 SyntheticPointerActionParams::PointerActionType::MOVE);
411 action_param_list_->push_back(params);
412 ForwardSyntheticPointerAction();
413
414 EXPECT_EQ(3, num_success_);
415 EXPECT_EQ(0, num_failure_);
416 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove);
417 EXPECT_EQ(pointer_mouse_target->position(), params.position());
418 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
419 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft);
420
421 // Send a mouse up.
422 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
423 params.set_pointer_action_type(
424 SyntheticPointerActionParams::PointerActionType::RELEASE);
425 action_param_list_->push_back(params);
426 ForwardSyntheticPointerAction();
427
428 EXPECT_EQ(4, num_success_);
429 EXPECT_EQ(0, num_failure_);
430 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseUp);
431 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
432 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft);
433 }
434
435 TEST_F(SyntheticPointerActionTest, PointerMouseActionSourceTypeInvalid) {
436 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>();
437
438 // Users' gesture source type does not match with the mouse action.
439 SyntheticPointerActionParams params = SyntheticPointerActionParams(
440 SyntheticPointerActionParams::PointerActionType::PRESS);
441 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
442 params.set_index(0);
443 params.set_position(gfx::PointF(54, 89));
444 action_param_list_->push_back(params);
445 ForwardSyntheticPointerAction();
446
447 EXPECT_EQ(0, num_success_);
448 EXPECT_EQ(1, num_failure_);
449
450 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
451 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
452 action_param_list_->push_back(params);
453 ForwardSyntheticPointerAction();
454
455 MockSyntheticPointerMouseActionTarget* pointer_mouse_target =
456 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get());
457 EXPECT_EQ(1, num_success_);
458 EXPECT_EQ(1, num_failure_);
459 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown);
460 EXPECT_EQ(pointer_mouse_target->position(), params.position());
461 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
462 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft);
463 }
464
465 TEST_F(SyntheticPointerActionTest, PointerMouseActionTypeInvalid) {
466 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>();
467
468 // Send a mouse move.
469 SyntheticPointerActionParams params = SyntheticPointerActionParams(
470 SyntheticPointerActionParams::PointerActionType::MOVE);
471 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
472 params.set_index(0);
473 params.set_position(gfx::PointF(189, 62));
474 action_param_list_->push_back(params);
475 ForwardSyntheticPointerAction();
476
477 MockSyntheticPointerMouseActionTarget* pointer_mouse_target =
478 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get());
479 EXPECT_EQ(1, num_success_);
480 EXPECT_EQ(0, num_failure_);
481 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove);
482 EXPECT_EQ(pointer_mouse_target->position(), params.position());
483 EXPECT_EQ(pointer_mouse_target->clickCount(), 0);
484 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonNone);
485
486 // Cannot send a mouse up without sending a mouse down first.
487 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
488 params.set_pointer_action_type(
489 SyntheticPointerActionParams::PointerActionType::RELEASE);
490 action_param_list_->push_back(params);
491 ForwardSyntheticPointerAction();
492
493 EXPECT_EQ(1, num_success_);
494 EXPECT_EQ(1, num_failure_);
495
496 // Send a mouse down for one finger.
497 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
498 params.set_pointer_action_type(
499 SyntheticPointerActionParams::PointerActionType::PRESS);
500 action_param_list_->push_back(params);
501 ForwardSyntheticPointerAction();
502
503 EXPECT_EQ(2, num_success_);
504 EXPECT_EQ(1, num_failure_);
505 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown);
506 EXPECT_EQ(pointer_mouse_target->position(), params.position());
507 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
508 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft);
509
510 // Cannot send a mouse down again without releasing the mouse button.
511 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>());
512 params.set_pointer_action_type(
513 SyntheticPointerActionParams::PointerActionType::PRESS);
514 action_param_list_->push_back(params);
515 ForwardSyntheticPointerAction();
516
517 EXPECT_EQ(2, num_success_);
518 EXPECT_EQ(2, num_failure_);
519 }
520
331 } // namespace 521 } // namespace
332 522
333 } // namespace content 523 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698