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

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 4 years, 2 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"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 private: 113 private:
114 gfx::PointF position_; 114 gfx::PointF position_;
115 int clickCount_; 115 int clickCount_;
116 WebMouseEvent::Button button_; 116 WebMouseEvent::Button button_;
117 }; 117 };
118 118
119 class SyntheticPointerActionTest : public testing::Test { 119 class SyntheticPointerActionTest : public testing::Test {
120 public: 120 public:
121 SyntheticPointerActionTest() { 121 SyntheticPointerActionTest() {
122 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 122 action_param_list_.clear();
123 std::fill(index_map_.begin(), index_map_.end(), -1); 123 std::fill(index_map_.begin(), index_map_.end(), -1);
124 num_success_ = 0; 124 num_success_ = 0;
125 num_failure_ = 0; 125 num_failure_ = 0;
126 } 126 }
127 ~SyntheticPointerActionTest() override {} 127 ~SyntheticPointerActionTest() override {}
128 128
129 protected: 129 protected:
130 template <typename MockGestureTarget> 130 template <typename MockGestureTarget>
131 void CreateSyntheticPointerActionTarget() { 131 void CreateSyntheticPointerActionTarget() {
132 target_.reset(new MockGestureTarget()); 132 target_.reset(new MockGestureTarget());
133 synthetic_pointer_ = SyntheticPointer::Create( 133 synthetic_pointer_ = SyntheticPointer::Create(
134 target_->GetDefaultSyntheticGestureSourceType()); 134 target_->GetDefaultSyntheticGestureSourceType());
135 } 135 }
136 136
137 void ForwardSyntheticPointerAction() { 137 void ForwardSyntheticPointerAction() {
138 gesture_list_params_.param_list = action_param_list_;
138 pointer_action_.reset(new SyntheticPointerAction( 139 pointer_action_.reset(new SyntheticPointerAction(
139 std::move(action_param_list_), synthetic_pointer_.get(), &index_map_)); 140 gesture_list_params_, synthetic_pointer_.get(), &index_map_));
140 141
141 SyntheticGesture::Result result = pointer_action_->ForwardInputEvents( 142 SyntheticGesture::Result result = pointer_action_->ForwardInputEvents(
142 base::TimeTicks::Now(), target_.get()); 143 base::TimeTicks::Now(), target_.get());
143 144
144 if (result == SyntheticGesture::GESTURE_FINISHED) 145 if (result == SyntheticGesture::GESTURE_FINISHED ||
146 result == SyntheticGesture::GESTURE_RUNNING)
145 num_success_++; 147 num_success_++;
146 else 148 else
147 num_failure_++; 149 num_failure_++;
148 } 150 }
149 151
150 int num_success_; 152 int num_success_;
151 int num_failure_; 153 int num_failure_;
152 std::unique_ptr<MockSyntheticPointerActionTarget> target_; 154 std::unique_ptr<MockSyntheticPointerActionTarget> target_;
153 std::unique_ptr<SyntheticGesture> pointer_action_; 155 std::unique_ptr<SyntheticGesture> pointer_action_;
154 std::unique_ptr<SyntheticPointer> synthetic_pointer_; 156 std::unique_ptr<SyntheticPointer> synthetic_pointer_;
155 std::unique_ptr<std::vector<SyntheticPointerActionParams>> action_param_list_; 157 SyntheticPointerActionListParams gesture_list_params_;
158 std::vector<SyntheticPointerActionParams> action_param_list_;
156 SyntheticPointerAction::IndexMap index_map_; 159 SyntheticPointerAction::IndexMap index_map_;
157 }; 160 };
158 161
159 TEST_F(SyntheticPointerActionTest, PointerTouchAction) { 162 TEST_F(SyntheticPointerActionTest, PointerTouchAction) {
160 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>(); 163 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>();
161 164
162 // Send a touch press for one finger. 165 // Send a touch press for one finger.
163 SyntheticPointerActionParams params0 = SyntheticPointerActionParams( 166 SyntheticPointerActionParams params0 = SyntheticPointerActionParams(
164 SyntheticPointerActionParams::PointerActionType::PRESS); 167 SyntheticPointerActionParams::PointerActionType::PRESS);
165 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 168 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
166 params0.set_index(0); 169 params0.set_index(0);
167 params0.set_position(gfx::PointF(54, 89)); 170 params0.set_position(gfx::PointF(54, 89));
168 action_param_list_->push_back(params0); 171 action_param_list_.push_back(params0);
169 ForwardSyntheticPointerAction(); 172 ForwardSyntheticPointerAction();
170 173
171 MockSyntheticPointerTouchActionTarget* pointer_touch_target = 174 MockSyntheticPointerTouchActionTarget* pointer_touch_target =
172 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get()); 175 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get());
173 EXPECT_EQ(1, num_success_); 176 EXPECT_EQ(1, num_success_);
174 EXPECT_EQ(0, num_failure_); 177 EXPECT_EQ(0, num_failure_);
175 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); 178 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
176 EXPECT_EQ(pointer_touch_target->indexes(0), 0); 179 EXPECT_EQ(pointer_touch_target->indexes(0), 0);
177 EXPECT_EQ(index_map_[0], 0); 180 EXPECT_EQ(index_map_[0], 0);
178 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89)); 181 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89));
179 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); 182 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed);
180 ASSERT_EQ(pointer_touch_target->touch_length(), 1U); 183 ASSERT_EQ(pointer_touch_target->touch_length(), 1U);
181 184
182 // Send a touch move for the first finger and a touch press for the second 185 // Send a touch move for the first finger and a touch press for the second
183 // finger. 186 // finger.
184 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 187 action_param_list_.clear();
185 params0.set_pointer_action_type( 188 params0.set_pointer_action_type(
186 SyntheticPointerActionParams::PointerActionType::MOVE); 189 SyntheticPointerActionParams::PointerActionType::MOVE);
187 params0.set_position(gfx::PointF(133, 156)); 190 params0.set_position(gfx::PointF(133, 156));
188 SyntheticPointerActionParams params1 = SyntheticPointerActionParams( 191 SyntheticPointerActionParams params1 = SyntheticPointerActionParams(
189 SyntheticPointerActionParams::PointerActionType::PRESS); 192 SyntheticPointerActionParams::PointerActionType::PRESS);
190 params1.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 193 params1.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
191 params1.set_index(1); 194 params1.set_index(1);
192 params1.set_position(gfx::PointF(79, 132)); 195 params1.set_position(gfx::PointF(79, 132));
193 action_param_list_->push_back(params0); 196 action_param_list_.push_back(params0);
194 action_param_list_->push_back(params1); 197 action_param_list_.push_back(params1);
195 ForwardSyntheticPointerAction(); 198 ForwardSyntheticPointerAction();
196 199
197 EXPECT_EQ(2, num_success_); 200 EXPECT_EQ(2, num_success_);
198 EXPECT_EQ(0, num_failure_); 201 EXPECT_EQ(0, num_failure_);
199 // The type of the SyntheticWebTouchEvent is the action of the last finger. 202 // The type of the SyntheticWebTouchEvent is the action of the last finger.
200 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); 203 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
201 EXPECT_EQ(pointer_touch_target->indexes(0), 0); 204 EXPECT_EQ(pointer_touch_target->indexes(0), 0);
202 EXPECT_EQ(index_map_[0], 0); 205 EXPECT_EQ(index_map_[0], 0);
203 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(133, 156)); 206 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(133, 156));
204 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateMoved); 207 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateMoved);
205 EXPECT_EQ(pointer_touch_target->indexes(1), 1); 208 EXPECT_EQ(pointer_touch_target->indexes(1), 1);
206 EXPECT_EQ(index_map_[1], 1); 209 EXPECT_EQ(index_map_[1], 1);
207 EXPECT_EQ(pointer_touch_target->positions(1), gfx::PointF(79, 132)); 210 EXPECT_EQ(pointer_touch_target->positions(1), gfx::PointF(79, 132));
208 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StatePressed); 211 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StatePressed);
209 ASSERT_EQ(pointer_touch_target->touch_length(), 2U); 212 ASSERT_EQ(pointer_touch_target->touch_length(), 2U);
210 213
211 // Send a touch move for the second finger. 214 // Send a touch move for the second finger.
212 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 215 action_param_list_.clear();
213 params1.set_pointer_action_type( 216 params1.set_pointer_action_type(
214 SyntheticPointerActionParams::PointerActionType::MOVE); 217 SyntheticPointerActionParams::PointerActionType::MOVE);
215 params1.set_position(gfx::PointF(87, 253)); 218 params1.set_position(gfx::PointF(87, 253));
216 action_param_list_->push_back(params1); 219 action_param_list_.push_back(params1);
217 ForwardSyntheticPointerAction(); 220 ForwardSyntheticPointerAction();
218 221
219 EXPECT_EQ(3, num_success_); 222 EXPECT_EQ(3, num_success_);
220 EXPECT_EQ(0, num_failure_); 223 EXPECT_EQ(0, num_failure_);
221 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchMove); 224 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchMove);
222 EXPECT_EQ(pointer_touch_target->indexes(1), 1); 225 EXPECT_EQ(pointer_touch_target->indexes(1), 1);
223 EXPECT_EQ(index_map_[1], 1); 226 EXPECT_EQ(index_map_[1], 1);
224 EXPECT_EQ(pointer_touch_target->positions(1), gfx::PointF(87, 253)); 227 EXPECT_EQ(pointer_touch_target->positions(1), gfx::PointF(87, 253));
225 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateMoved); 228 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateMoved);
226 ASSERT_EQ(pointer_touch_target->touch_length(), 2U); 229 ASSERT_EQ(pointer_touch_target->touch_length(), 2U);
227 230
228 // Send touch releases for both fingers. 231 // Send touch releases for both fingers.
229 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 232 action_param_list_.clear();
230 params0.set_pointer_action_type( 233 params0.set_pointer_action_type(
231 SyntheticPointerActionParams::PointerActionType::RELEASE); 234 SyntheticPointerActionParams::PointerActionType::RELEASE);
232 params1.set_pointer_action_type( 235 params1.set_pointer_action_type(
233 SyntheticPointerActionParams::PointerActionType::RELEASE); 236 SyntheticPointerActionParams::PointerActionType::RELEASE);
234 action_param_list_->push_back(params0); 237 action_param_list_.push_back(params0);
235 action_param_list_->push_back(params1); 238 action_param_list_.push_back(params1);
236 ForwardSyntheticPointerAction(); 239 ForwardSyntheticPointerAction();
237 240
238 EXPECT_EQ(4, num_success_); 241 EXPECT_EQ(4, num_success_);
239 EXPECT_EQ(0, num_failure_); 242 EXPECT_EQ(0, num_failure_);
240 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchEnd); 243 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchEnd);
241 EXPECT_EQ(pointer_touch_target->indexes(0), 0); 244 EXPECT_EQ(pointer_touch_target->indexes(0), 0);
242 EXPECT_EQ(index_map_[0], -1); 245 EXPECT_EQ(index_map_[0], -1);
243 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateReleased); 246 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateReleased);
244 EXPECT_EQ(pointer_touch_target->indexes(1), 1); 247 EXPECT_EQ(pointer_touch_target->indexes(1), 1);
245 EXPECT_EQ(index_map_[1], -1); 248 EXPECT_EQ(index_map_[1], -1);
246 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased); 249 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased);
247 ASSERT_EQ(pointer_touch_target->touch_length(), 2U); 250 ASSERT_EQ(pointer_touch_target->touch_length(), 2U);
248 } 251 }
249 252
250 TEST_F(SyntheticPointerActionTest, PointerTouchActionIndexInvalid) { 253 TEST_F(SyntheticPointerActionTest, PointerTouchActionIndexInvalid) {
251 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>(); 254 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>();
252 255
253 // Users sent a wrong index for the touch action. 256 // Users sent a wrong index for the touch action.
254 SyntheticPointerActionParams params0 = SyntheticPointerActionParams( 257 SyntheticPointerActionParams params0 = SyntheticPointerActionParams(
255 SyntheticPointerActionParams::PointerActionType::PRESS); 258 SyntheticPointerActionParams::PointerActionType::PRESS);
256 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 259 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
257 params0.set_index(-1); 260 params0.set_index(-1);
258 params0.set_position(gfx::PointF(54, 89)); 261 params0.set_position(gfx::PointF(54, 89));
259 action_param_list_->push_back(params0); 262 action_param_list_.push_back(params0);
260 ForwardSyntheticPointerAction(); 263 ForwardSyntheticPointerAction();
261 264
262 EXPECT_EQ(0, num_success_); 265 EXPECT_EQ(0, num_success_);
263 EXPECT_EQ(1, num_failure_); 266 EXPECT_EQ(1, num_failure_);
264 267
265 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 268 action_param_list_.clear();
266 params0.set_index(0); 269 params0.set_index(0);
267 action_param_list_->push_back(params0); 270 action_param_list_.push_back(params0);
268 ForwardSyntheticPointerAction(); 271 ForwardSyntheticPointerAction();
269 272
270 MockSyntheticPointerTouchActionTarget* pointer_touch_target = 273 MockSyntheticPointerTouchActionTarget* pointer_touch_target =
271 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get()); 274 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get());
272 EXPECT_EQ(1, num_success_); 275 EXPECT_EQ(1, num_success_);
273 EXPECT_EQ(1, num_failure_); 276 EXPECT_EQ(1, num_failure_);
274 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); 277 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
275 EXPECT_EQ(pointer_touch_target->indexes(0), 0); 278 EXPECT_EQ(pointer_touch_target->indexes(0), 0);
276 EXPECT_EQ(index_map_[0], 0); 279 EXPECT_EQ(index_map_[0], 0);
277 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89)); 280 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89));
278 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); 281 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed);
279 ASSERT_EQ(pointer_touch_target->touch_length(), 1U); 282 ASSERT_EQ(pointer_touch_target->touch_length(), 1U);
280 } 283 }
281 284
282 TEST_F(SyntheticPointerActionTest, PointerTouchActionSourceTypeInvalid) { 285 TEST_F(SyntheticPointerActionTest, PointerTouchActionSourceTypeInvalid) {
283 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>(); 286 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>();
284 287
285 // Users' gesture source type does not match with the touch action. 288 // Users' gesture source type does not match with the touch action.
286 SyntheticPointerActionParams params0 = SyntheticPointerActionParams( 289 SyntheticPointerActionParams params0 = SyntheticPointerActionParams(
287 SyntheticPointerActionParams::PointerActionType::PRESS); 290 SyntheticPointerActionParams::PointerActionType::PRESS);
288 params0.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 291 params0.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
289 params0.set_index(0); 292 params0.set_index(0);
290 params0.set_position(gfx::PointF(54, 89)); 293 params0.set_position(gfx::PointF(54, 89));
291 action_param_list_->push_back(params0); 294 action_param_list_.push_back(params0);
292 ForwardSyntheticPointerAction(); 295 ForwardSyntheticPointerAction();
293 296
294 EXPECT_EQ(0, num_success_); 297 EXPECT_EQ(0, num_success_);
295 EXPECT_EQ(1, num_failure_); 298 EXPECT_EQ(1, num_failure_);
296 299
297 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 300 action_param_list_.clear();
298 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 301 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
299 action_param_list_->push_back(params0); 302 action_param_list_.push_back(params0);
300 ForwardSyntheticPointerAction(); 303 ForwardSyntheticPointerAction();
301 304
302 MockSyntheticPointerTouchActionTarget* pointer_touch_target = 305 MockSyntheticPointerTouchActionTarget* pointer_touch_target =
303 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get()); 306 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get());
304 EXPECT_EQ(1, num_success_); 307 EXPECT_EQ(1, num_success_);
305 EXPECT_EQ(1, num_failure_); 308 EXPECT_EQ(1, num_failure_);
306 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); 309 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
307 EXPECT_EQ(pointer_touch_target->indexes(0), 0); 310 EXPECT_EQ(pointer_touch_target->indexes(0), 0);
308 EXPECT_EQ(index_map_[0], 0); 311 EXPECT_EQ(index_map_[0], 0);
309 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89)); 312 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89));
310 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); 313 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed);
311 ASSERT_EQ(pointer_touch_target->touch_length(), 1U); 314 ASSERT_EQ(pointer_touch_target->touch_length(), 1U);
312 } 315 }
313 316
314 TEST_F(SyntheticPointerActionTest, PointerTouchActionTypeInvalid) { 317 TEST_F(SyntheticPointerActionTest, PointerTouchActionTypeInvalid) {
315 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>(); 318 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>();
316 319
317 // Cannot send a touch move or touch release without sending a touch press 320 // Cannot send a touch move or touch release without sending a touch press
318 // first. 321 // first.
319 SyntheticPointerActionParams params0 = SyntheticPointerActionParams( 322 SyntheticPointerActionParams params0 = SyntheticPointerActionParams(
320 SyntheticPointerActionParams::PointerActionType::MOVE); 323 SyntheticPointerActionParams::PointerActionType::MOVE);
321 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 324 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
322 params0.set_index(0); 325 params0.set_index(0);
323 params0.set_position(gfx::PointF(54, 89)); 326 params0.set_position(gfx::PointF(54, 89));
324 action_param_list_->push_back(params0); 327 action_param_list_.push_back(params0);
325 ForwardSyntheticPointerAction(); 328 ForwardSyntheticPointerAction();
326 329
327 EXPECT_EQ(0, num_success_); 330 EXPECT_EQ(0, num_success_);
328 EXPECT_EQ(1, num_failure_); 331 EXPECT_EQ(1, num_failure_);
329 332
330 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 333 action_param_list_.clear();
331 params0.set_pointer_action_type( 334 params0.set_pointer_action_type(
332 SyntheticPointerActionParams::PointerActionType::RELEASE); 335 SyntheticPointerActionParams::PointerActionType::RELEASE);
333 action_param_list_->push_back(params0); 336 action_param_list_.push_back(params0);
334 ForwardSyntheticPointerAction(); 337 ForwardSyntheticPointerAction();
335 338
336 EXPECT_EQ(0, num_success_); 339 EXPECT_EQ(0, num_success_);
337 EXPECT_EQ(2, num_failure_); 340 EXPECT_EQ(2, num_failure_);
338 341
339 // Send a touch press for one finger. 342 // Send a touch press for one finger.
340 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 343 action_param_list_.clear();
341 params0.set_pointer_action_type( 344 params0.set_pointer_action_type(
342 SyntheticPointerActionParams::PointerActionType::PRESS); 345 SyntheticPointerActionParams::PointerActionType::PRESS);
343 action_param_list_->push_back(params0); 346 action_param_list_.push_back(params0);
344 ForwardSyntheticPointerAction(); 347 ForwardSyntheticPointerAction();
345 348
346 MockSyntheticPointerTouchActionTarget* pointer_touch_target = 349 MockSyntheticPointerTouchActionTarget* pointer_touch_target =
347 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get()); 350 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get());
348 EXPECT_EQ(1, num_success_); 351 EXPECT_EQ(1, num_success_);
349 EXPECT_EQ(2, num_failure_); 352 EXPECT_EQ(2, num_failure_);
350 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); 353 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
351 EXPECT_EQ(pointer_touch_target->indexes(0), 0); 354 EXPECT_EQ(pointer_touch_target->indexes(0), 0);
352 EXPECT_EQ(index_map_[0], 0); 355 EXPECT_EQ(index_map_[0], 0);
353 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89)); 356 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89));
354 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); 357 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed);
355 ASSERT_EQ(pointer_touch_target->touch_length(), 1U); 358 ASSERT_EQ(pointer_touch_target->touch_length(), 1U);
356 359
357 // Cannot send a touch press again without releasing the finger. 360 // Cannot send a touch press again without releasing the finger.
358 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 361 action_param_list_.clear();
359 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 362 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
360 params0.set_index(0); 363 params0.set_index(0);
361 params0.set_pointer_action_type( 364 params0.set_pointer_action_type(
362 SyntheticPointerActionParams::PointerActionType::PRESS); 365 SyntheticPointerActionParams::PointerActionType::PRESS);
363 action_param_list_->push_back(params0); 366 action_param_list_.push_back(params0);
364 ForwardSyntheticPointerAction(); 367 ForwardSyntheticPointerAction();
365 368
366 EXPECT_EQ(1, num_success_); 369 EXPECT_EQ(1, num_success_);
367 EXPECT_EQ(3, num_failure_); 370 EXPECT_EQ(3, num_failure_);
368 } 371 }
369 372
370 TEST_F(SyntheticPointerActionTest, PointerMouseAction) { 373 TEST_F(SyntheticPointerActionTest, PointerMouseAction) {
371 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>(); 374 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>();
372 375
373 // Send a mouse move. 376 // Send a mouse move.
374 SyntheticPointerActionParams params = SyntheticPointerActionParams( 377 SyntheticPointerActionParams params = SyntheticPointerActionParams(
375 SyntheticPointerActionParams::PointerActionType::MOVE); 378 SyntheticPointerActionParams::PointerActionType::MOVE);
376 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 379 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
377 params.set_index(0); 380 params.set_index(0);
378 params.set_position(gfx::PointF(189, 62)); 381 params.set_position(gfx::PointF(189, 62));
379 action_param_list_->push_back(params); 382 action_param_list_.push_back(params);
380 ForwardSyntheticPointerAction(); 383 ForwardSyntheticPointerAction();
381 384
382 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = 385 MockSyntheticPointerMouseActionTarget* pointer_mouse_target =
383 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); 386 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get());
384 EXPECT_EQ(1, num_success_); 387 EXPECT_EQ(1, num_success_);
385 EXPECT_EQ(0, num_failure_); 388 EXPECT_EQ(0, num_failure_);
386 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); 389 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove);
387 EXPECT_EQ(pointer_mouse_target->position(), params.position()); 390 EXPECT_EQ(pointer_mouse_target->position(), params.position());
388 EXPECT_EQ(pointer_mouse_target->clickCount(), 0); 391 EXPECT_EQ(pointer_mouse_target->clickCount(), 0);
389 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton); 392 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton);
390 393
391 // Send a mouse down. 394 // Send a mouse down.
392 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 395 action_param_list_.clear();
393 params.set_position(gfx::PointF(189, 62)); 396 params.set_position(gfx::PointF(189, 62));
394 params.set_pointer_action_type( 397 params.set_pointer_action_type(
395 SyntheticPointerActionParams::PointerActionType::PRESS); 398 SyntheticPointerActionParams::PointerActionType::PRESS);
396 action_param_list_->push_back(params); 399 action_param_list_.push_back(params);
397 ForwardSyntheticPointerAction(); 400 ForwardSyntheticPointerAction();
398 401
399 EXPECT_EQ(2, num_success_); 402 EXPECT_EQ(2, num_success_);
400 EXPECT_EQ(0, num_failure_); 403 EXPECT_EQ(0, num_failure_);
401 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); 404 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown);
402 EXPECT_EQ(pointer_mouse_target->position(), params.position()); 405 EXPECT_EQ(pointer_mouse_target->position(), params.position());
403 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); 406 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
404 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); 407 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left);
405 408
406 // Send a mouse drag. 409 // Send a mouse drag.
407 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 410 action_param_list_.clear();
408 params.set_position(gfx::PointF(326, 298)); 411 params.set_position(gfx::PointF(326, 298));
409 params.set_pointer_action_type( 412 params.set_pointer_action_type(
410 SyntheticPointerActionParams::PointerActionType::MOVE); 413 SyntheticPointerActionParams::PointerActionType::MOVE);
411 action_param_list_->push_back(params); 414 action_param_list_.push_back(params);
412 ForwardSyntheticPointerAction(); 415 ForwardSyntheticPointerAction();
413 416
414 EXPECT_EQ(3, num_success_); 417 EXPECT_EQ(3, num_success_);
415 EXPECT_EQ(0, num_failure_); 418 EXPECT_EQ(0, num_failure_);
416 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); 419 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove);
417 EXPECT_EQ(pointer_mouse_target->position(), params.position()); 420 EXPECT_EQ(pointer_mouse_target->position(), params.position());
418 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); 421 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
419 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); 422 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left);
420 423
421 // Send a mouse up. 424 // Send a mouse up.
422 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 425 action_param_list_.clear();
423 params.set_pointer_action_type( 426 params.set_pointer_action_type(
424 SyntheticPointerActionParams::PointerActionType::RELEASE); 427 SyntheticPointerActionParams::PointerActionType::RELEASE);
425 action_param_list_->push_back(params); 428 action_param_list_.push_back(params);
426 ForwardSyntheticPointerAction(); 429 ForwardSyntheticPointerAction();
427 430
428 EXPECT_EQ(4, num_success_); 431 EXPECT_EQ(4, num_success_);
429 EXPECT_EQ(0, num_failure_); 432 EXPECT_EQ(0, num_failure_);
430 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseUp); 433 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseUp);
431 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); 434 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
432 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); 435 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left);
433 } 436 }
434 437
435 TEST_F(SyntheticPointerActionTest, PointerMouseActionSourceTypeInvalid) { 438 TEST_F(SyntheticPointerActionTest, PointerMouseActionSourceTypeInvalid) {
436 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>(); 439 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>();
437 440
438 // Users' gesture source type does not match with the mouse action. 441 // Users' gesture source type does not match with the mouse action.
439 SyntheticPointerActionParams params = SyntheticPointerActionParams( 442 SyntheticPointerActionParams params = SyntheticPointerActionParams(
440 SyntheticPointerActionParams::PointerActionType::PRESS); 443 SyntheticPointerActionParams::PointerActionType::PRESS);
441 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 444 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
442 params.set_index(0); 445 params.set_index(0);
443 params.set_position(gfx::PointF(54, 89)); 446 params.set_position(gfx::PointF(54, 89));
444 action_param_list_->push_back(params); 447 action_param_list_.push_back(params);
445 ForwardSyntheticPointerAction(); 448 ForwardSyntheticPointerAction();
446 449
447 EXPECT_EQ(0, num_success_); 450 EXPECT_EQ(0, num_success_);
448 EXPECT_EQ(1, num_failure_); 451 EXPECT_EQ(1, num_failure_);
449 452
450 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 453 action_param_list_.clear();
451 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 454 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
452 action_param_list_->push_back(params); 455 action_param_list_.push_back(params);
453 ForwardSyntheticPointerAction(); 456 ForwardSyntheticPointerAction();
454 457
455 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = 458 MockSyntheticPointerMouseActionTarget* pointer_mouse_target =
456 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); 459 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get());
457 EXPECT_EQ(1, num_success_); 460 EXPECT_EQ(1, num_success_);
458 EXPECT_EQ(1, num_failure_); 461 EXPECT_EQ(1, num_failure_);
459 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); 462 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown);
460 EXPECT_EQ(pointer_mouse_target->position(), params.position()); 463 EXPECT_EQ(pointer_mouse_target->position(), params.position());
461 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); 464 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
462 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); 465 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left);
463 } 466 }
464 467
465 TEST_F(SyntheticPointerActionTest, PointerMouseActionTypeInvalid) { 468 TEST_F(SyntheticPointerActionTest, PointerMouseActionTypeInvalid) {
466 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>(); 469 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>();
467 470
468 // Send a mouse move. 471 // Send a mouse move.
469 SyntheticPointerActionParams params = SyntheticPointerActionParams( 472 SyntheticPointerActionParams params = SyntheticPointerActionParams(
470 SyntheticPointerActionParams::PointerActionType::MOVE); 473 SyntheticPointerActionParams::PointerActionType::MOVE);
471 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 474 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
472 params.set_index(0); 475 params.set_index(0);
473 params.set_position(gfx::PointF(189, 62)); 476 params.set_position(gfx::PointF(189, 62));
474 action_param_list_->push_back(params); 477 action_param_list_.push_back(params);
475 ForwardSyntheticPointerAction(); 478 ForwardSyntheticPointerAction();
476 479
477 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = 480 MockSyntheticPointerMouseActionTarget* pointer_mouse_target =
478 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); 481 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get());
479 EXPECT_EQ(1, num_success_); 482 EXPECT_EQ(1, num_success_);
480 EXPECT_EQ(0, num_failure_); 483 EXPECT_EQ(0, num_failure_);
481 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); 484 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove);
482 EXPECT_EQ(pointer_mouse_target->position(), params.position()); 485 EXPECT_EQ(pointer_mouse_target->position(), params.position());
483 EXPECT_EQ(pointer_mouse_target->clickCount(), 0); 486 EXPECT_EQ(pointer_mouse_target->clickCount(), 0);
484 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton); 487 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton);
485 488
486 // Cannot send a mouse up without sending a mouse down first. 489 // Cannot send a mouse up without sending a mouse down first.
487 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 490 action_param_list_.clear();
488 params.set_pointer_action_type( 491 params.set_pointer_action_type(
489 SyntheticPointerActionParams::PointerActionType::RELEASE); 492 SyntheticPointerActionParams::PointerActionType::RELEASE);
490 action_param_list_->push_back(params); 493 action_param_list_.push_back(params);
491 ForwardSyntheticPointerAction(); 494 ForwardSyntheticPointerAction();
492 495
493 EXPECT_EQ(1, num_success_); 496 EXPECT_EQ(1, num_success_);
494 EXPECT_EQ(1, num_failure_); 497 EXPECT_EQ(1, num_failure_);
495 498
496 // Send a mouse down for one finger. 499 // Send a mouse down for one finger.
497 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 500 action_param_list_.clear();
498 params.set_pointer_action_type( 501 params.set_pointer_action_type(
499 SyntheticPointerActionParams::PointerActionType::PRESS); 502 SyntheticPointerActionParams::PointerActionType::PRESS);
500 action_param_list_->push_back(params); 503 action_param_list_.push_back(params);
501 ForwardSyntheticPointerAction(); 504 ForwardSyntheticPointerAction();
502 505
503 EXPECT_EQ(2, num_success_); 506 EXPECT_EQ(2, num_success_);
504 EXPECT_EQ(1, num_failure_); 507 EXPECT_EQ(1, num_failure_);
505 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); 508 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown);
506 EXPECT_EQ(pointer_mouse_target->position(), params.position()); 509 EXPECT_EQ(pointer_mouse_target->position(), params.position());
507 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); 510 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
508 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); 511 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left);
509 512
510 // Cannot send a mouse down again without releasing the mouse button. 513 // Cannot send a mouse down again without releasing the mouse button.
511 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); 514 action_param_list_.clear();
512 params.set_pointer_action_type( 515 params.set_pointer_action_type(
513 SyntheticPointerActionParams::PointerActionType::PRESS); 516 SyntheticPointerActionParams::PointerActionType::PRESS);
514 action_param_list_->push_back(params); 517 action_param_list_.push_back(params);
515 ForwardSyntheticPointerAction(); 518 ForwardSyntheticPointerAction();
516 519
517 EXPECT_EQ(2, num_success_); 520 EXPECT_EQ(2, num_success_);
518 EXPECT_EQ(2, num_failure_); 521 EXPECT_EQ(2, num_failure_);
519 } 522 }
520 523
521 } // namespace 524 } // namespace
522 525
523 } // namespace content 526 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698