OLD | NEW |
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 Loading... |
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( |
| 167 SyntheticGestureParams::TOUCH_INPUT, |
164 SyntheticPointerActionParams::PointerActionType::PRESS); | 168 SyntheticPointerActionParams::PointerActionType::PRESS); |
165 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( |
| 192 SyntheticGestureParams::TOUCH_INPUT, |
189 SyntheticPointerActionParams::PointerActionType::PRESS); | 193 SyntheticPointerActionParams::PointerActionType::PRESS); |
190 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( |
| 258 SyntheticGestureParams::TOUCH_INPUT, |
255 SyntheticPointerActionParams::PointerActionType::PRESS); | 259 SyntheticPointerActionParams::PointerActionType::PRESS); |
256 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()); | |
272 EXPECT_EQ(1, num_success_); | |
273 EXPECT_EQ(1, num_failure_); | |
274 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); | |
275 EXPECT_EQ(pointer_touch_target->indexes(0), 0); | |
276 EXPECT_EQ(index_map_[0], 0); | |
277 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89)); | |
278 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); | |
279 ASSERT_EQ(pointer_touch_target->touch_length(), 1U); | |
280 } | |
281 | |
282 TEST_F(SyntheticPointerActionTest, PointerTouchActionSourceTypeInvalid) { | |
283 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>(); | |
284 | |
285 // Users' gesture source type does not match with the touch action. | |
286 SyntheticPointerActionParams params0 = SyntheticPointerActionParams( | |
287 SyntheticPointerActionParams::PointerActionType::PRESS); | |
288 params0.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | |
289 params0.set_index(0); | |
290 params0.set_position(gfx::PointF(54, 89)); | |
291 action_param_list_->push_back(params0); | |
292 ForwardSyntheticPointerAction(); | |
293 | |
294 EXPECT_EQ(0, num_success_); | |
295 EXPECT_EQ(1, num_failure_); | |
296 | |
297 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | |
298 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
299 action_param_list_->push_back(params0); | |
300 ForwardSyntheticPointerAction(); | |
301 | |
302 MockSyntheticPointerTouchActionTarget* pointer_touch_target = | |
303 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get()); | 274 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get()); |
304 EXPECT_EQ(1, num_success_); | 275 EXPECT_EQ(1, num_success_); |
305 EXPECT_EQ(1, num_failure_); | 276 EXPECT_EQ(1, num_failure_); |
306 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); | 277 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); |
307 EXPECT_EQ(pointer_touch_target->indexes(0), 0); | 278 EXPECT_EQ(pointer_touch_target->indexes(0), 0); |
308 EXPECT_EQ(index_map_[0], 0); | 279 EXPECT_EQ(index_map_[0], 0); |
309 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89)); | 280 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89)); |
310 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); | 281 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); |
311 ASSERT_EQ(pointer_touch_target->touch_length(), 1U); | 282 ASSERT_EQ(pointer_touch_target->touch_length(), 1U); |
312 } | 283 } |
313 | 284 |
314 TEST_F(SyntheticPointerActionTest, PointerTouchActionTypeInvalid) { | 285 TEST_F(SyntheticPointerActionTest, PointerTouchActionTypeInvalid) { |
315 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>(); | 286 CreateSyntheticPointerActionTarget<MockSyntheticPointerTouchActionTarget>(); |
316 | 287 |
317 // Cannot send a touch move or touch release without sending a touch press | 288 // Cannot send a touch move or touch release without sending a touch press |
318 // first. | 289 // first. |
319 SyntheticPointerActionParams params0 = SyntheticPointerActionParams( | 290 SyntheticPointerActionParams params0 = SyntheticPointerActionParams( |
| 291 SyntheticGestureParams::TOUCH_INPUT, |
320 SyntheticPointerActionParams::PointerActionType::MOVE); | 292 SyntheticPointerActionParams::PointerActionType::MOVE); |
321 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
322 params0.set_index(0); | 293 params0.set_index(0); |
323 params0.set_position(gfx::PointF(54, 89)); | 294 params0.set_position(gfx::PointF(54, 89)); |
324 action_param_list_->push_back(params0); | 295 action_param_list_.push_back(params0); |
325 ForwardSyntheticPointerAction(); | 296 ForwardSyntheticPointerAction(); |
326 | 297 |
327 EXPECT_EQ(0, num_success_); | 298 EXPECT_EQ(0, num_success_); |
328 EXPECT_EQ(1, num_failure_); | 299 EXPECT_EQ(1, num_failure_); |
329 | 300 |
330 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 301 action_param_list_.clear(); |
331 params0.set_pointer_action_type( | 302 params0.set_pointer_action_type( |
332 SyntheticPointerActionParams::PointerActionType::RELEASE); | 303 SyntheticPointerActionParams::PointerActionType::RELEASE); |
333 action_param_list_->push_back(params0); | 304 action_param_list_.push_back(params0); |
334 ForwardSyntheticPointerAction(); | 305 ForwardSyntheticPointerAction(); |
335 | 306 |
336 EXPECT_EQ(0, num_success_); | 307 EXPECT_EQ(0, num_success_); |
337 EXPECT_EQ(2, num_failure_); | 308 EXPECT_EQ(2, num_failure_); |
338 | 309 |
339 // Send a touch press for one finger. | 310 // Send a touch press for one finger. |
340 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 311 action_param_list_.clear(); |
341 params0.set_pointer_action_type( | 312 params0.set_pointer_action_type( |
342 SyntheticPointerActionParams::PointerActionType::PRESS); | 313 SyntheticPointerActionParams::PointerActionType::PRESS); |
343 action_param_list_->push_back(params0); | 314 action_param_list_.push_back(params0); |
344 ForwardSyntheticPointerAction(); | 315 ForwardSyntheticPointerAction(); |
345 | 316 |
346 MockSyntheticPointerTouchActionTarget* pointer_touch_target = | 317 MockSyntheticPointerTouchActionTarget* pointer_touch_target = |
347 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get()); | 318 static_cast<MockSyntheticPointerTouchActionTarget*>(target_.get()); |
348 EXPECT_EQ(1, num_success_); | 319 EXPECT_EQ(1, num_success_); |
349 EXPECT_EQ(2, num_failure_); | 320 EXPECT_EQ(2, num_failure_); |
350 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); | 321 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); |
351 EXPECT_EQ(pointer_touch_target->indexes(0), 0); | 322 EXPECT_EQ(pointer_touch_target->indexes(0), 0); |
352 EXPECT_EQ(index_map_[0], 0); | 323 EXPECT_EQ(index_map_[0], 0); |
353 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89)); | 324 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89)); |
354 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); | 325 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); |
355 ASSERT_EQ(pointer_touch_target->touch_length(), 1U); | 326 ASSERT_EQ(pointer_touch_target->touch_length(), 1U); |
356 | 327 |
357 // Cannot send a touch press again without releasing the finger. | 328 // Cannot send a touch press again without releasing the finger. |
358 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 329 action_param_list_.clear(); |
359 params0.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
360 params0.set_index(0); | 330 params0.set_index(0); |
361 params0.set_pointer_action_type( | 331 params0.set_pointer_action_type( |
362 SyntheticPointerActionParams::PointerActionType::PRESS); | 332 SyntheticPointerActionParams::PointerActionType::PRESS); |
363 action_param_list_->push_back(params0); | 333 action_param_list_.push_back(params0); |
364 ForwardSyntheticPointerAction(); | 334 ForwardSyntheticPointerAction(); |
365 | 335 |
366 EXPECT_EQ(1, num_success_); | 336 EXPECT_EQ(1, num_success_); |
367 EXPECT_EQ(3, num_failure_); | 337 EXPECT_EQ(3, num_failure_); |
368 } | 338 } |
369 | 339 |
370 TEST_F(SyntheticPointerActionTest, PointerMouseAction) { | 340 TEST_F(SyntheticPointerActionTest, PointerMouseAction) { |
371 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>(); | 341 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>(); |
372 | 342 |
373 // Send a mouse move. | 343 // Send a mouse move. |
374 SyntheticPointerActionParams params = SyntheticPointerActionParams( | 344 SyntheticPointerActionParams params = SyntheticPointerActionParams( |
| 345 SyntheticGestureParams::MOUSE_INPUT, |
375 SyntheticPointerActionParams::PointerActionType::MOVE); | 346 SyntheticPointerActionParams::PointerActionType::MOVE); |
376 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | |
377 params.set_index(0); | 347 params.set_index(0); |
378 params.set_position(gfx::PointF(189, 62)); | 348 params.set_position(gfx::PointF(189, 62)); |
379 action_param_list_->push_back(params); | 349 action_param_list_.push_back(params); |
380 ForwardSyntheticPointerAction(); | 350 ForwardSyntheticPointerAction(); |
381 | 351 |
382 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = | 352 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = |
383 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); | 353 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); |
384 EXPECT_EQ(1, num_success_); | 354 EXPECT_EQ(1, num_success_); |
385 EXPECT_EQ(0, num_failure_); | 355 EXPECT_EQ(0, num_failure_); |
386 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); | 356 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); |
387 EXPECT_EQ(pointer_mouse_target->position(), params.position()); | 357 EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
388 EXPECT_EQ(pointer_mouse_target->clickCount(), 0); | 358 EXPECT_EQ(pointer_mouse_target->clickCount(), 0); |
389 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton); | 359 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton); |
390 | 360 |
391 // Send a mouse down. | 361 // Send a mouse down. |
392 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 362 action_param_list_.clear(); |
393 params.set_position(gfx::PointF(189, 62)); | 363 params.set_position(gfx::PointF(189, 62)); |
394 params.set_pointer_action_type( | 364 params.set_pointer_action_type( |
395 SyntheticPointerActionParams::PointerActionType::PRESS); | 365 SyntheticPointerActionParams::PointerActionType::PRESS); |
396 action_param_list_->push_back(params); | 366 action_param_list_.push_back(params); |
397 ForwardSyntheticPointerAction(); | 367 ForwardSyntheticPointerAction(); |
398 | 368 |
399 EXPECT_EQ(2, num_success_); | 369 EXPECT_EQ(2, num_success_); |
400 EXPECT_EQ(0, num_failure_); | 370 EXPECT_EQ(0, num_failure_); |
401 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); | 371 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); |
402 EXPECT_EQ(pointer_mouse_target->position(), params.position()); | 372 EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
403 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); | 373 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
404 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); | 374 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
405 | 375 |
406 // Send a mouse drag. | 376 // Send a mouse drag. |
407 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 377 action_param_list_.clear(); |
408 params.set_position(gfx::PointF(326, 298)); | 378 params.set_position(gfx::PointF(326, 298)); |
409 params.set_pointer_action_type( | 379 params.set_pointer_action_type( |
410 SyntheticPointerActionParams::PointerActionType::MOVE); | 380 SyntheticPointerActionParams::PointerActionType::MOVE); |
411 action_param_list_->push_back(params); | 381 action_param_list_.push_back(params); |
412 ForwardSyntheticPointerAction(); | 382 ForwardSyntheticPointerAction(); |
413 | 383 |
414 EXPECT_EQ(3, num_success_); | 384 EXPECT_EQ(3, num_success_); |
415 EXPECT_EQ(0, num_failure_); | 385 EXPECT_EQ(0, num_failure_); |
416 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); | 386 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); |
417 EXPECT_EQ(pointer_mouse_target->position(), params.position()); | 387 EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
418 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); | 388 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
419 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); | 389 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
420 | 390 |
421 // Send a mouse up. | 391 // Send a mouse up. |
422 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 392 action_param_list_.clear(); |
423 params.set_pointer_action_type( | 393 params.set_pointer_action_type( |
424 SyntheticPointerActionParams::PointerActionType::RELEASE); | 394 SyntheticPointerActionParams::PointerActionType::RELEASE); |
425 action_param_list_->push_back(params); | 395 action_param_list_.push_back(params); |
426 ForwardSyntheticPointerAction(); | 396 ForwardSyntheticPointerAction(); |
427 | 397 |
428 EXPECT_EQ(4, num_success_); | 398 EXPECT_EQ(4, num_success_); |
429 EXPECT_EQ(0, num_failure_); | 399 EXPECT_EQ(0, num_failure_); |
430 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseUp); | 400 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseUp); |
431 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); | 401 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
432 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); | 402 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
433 } | 403 } |
434 | 404 |
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::Button::Left); | |
463 } | |
464 | |
465 TEST_F(SyntheticPointerActionTest, PointerMouseActionTypeInvalid) { | 405 TEST_F(SyntheticPointerActionTest, PointerMouseActionTypeInvalid) { |
466 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>(); | 406 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>(); |
467 | 407 |
468 // Send a mouse move. | 408 // Send a mouse move. |
469 SyntheticPointerActionParams params = SyntheticPointerActionParams( | 409 SyntheticPointerActionParams params = SyntheticPointerActionParams( |
| 410 SyntheticGestureParams::MOUSE_INPUT, |
470 SyntheticPointerActionParams::PointerActionType::MOVE); | 411 SyntheticPointerActionParams::PointerActionType::MOVE); |
471 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | |
472 params.set_index(0); | 412 params.set_index(0); |
473 params.set_position(gfx::PointF(189, 62)); | 413 params.set_position(gfx::PointF(189, 62)); |
474 action_param_list_->push_back(params); | 414 action_param_list_.push_back(params); |
475 ForwardSyntheticPointerAction(); | 415 ForwardSyntheticPointerAction(); |
476 | 416 |
477 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = | 417 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = |
478 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); | 418 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); |
479 EXPECT_EQ(1, num_success_); | 419 EXPECT_EQ(1, num_success_); |
480 EXPECT_EQ(0, num_failure_); | 420 EXPECT_EQ(0, num_failure_); |
481 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); | 421 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); |
482 EXPECT_EQ(pointer_mouse_target->position(), params.position()); | 422 EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
483 EXPECT_EQ(pointer_mouse_target->clickCount(), 0); | 423 EXPECT_EQ(pointer_mouse_target->clickCount(), 0); |
484 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton); | 424 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton); |
485 | 425 |
486 // Cannot send a mouse up without sending a mouse down first. | 426 // Cannot send a mouse up without sending a mouse down first. |
487 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 427 action_param_list_.clear(); |
488 params.set_pointer_action_type( | 428 params.set_pointer_action_type( |
489 SyntheticPointerActionParams::PointerActionType::RELEASE); | 429 SyntheticPointerActionParams::PointerActionType::RELEASE); |
490 action_param_list_->push_back(params); | 430 action_param_list_.push_back(params); |
491 ForwardSyntheticPointerAction(); | 431 ForwardSyntheticPointerAction(); |
492 | 432 |
493 EXPECT_EQ(1, num_success_); | 433 EXPECT_EQ(1, num_success_); |
494 EXPECT_EQ(1, num_failure_); | 434 EXPECT_EQ(1, num_failure_); |
495 | 435 |
496 // Send a mouse down for one finger. | 436 // Send a mouse down for one finger. |
497 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 437 action_param_list_.clear(); |
498 params.set_pointer_action_type( | 438 params.set_pointer_action_type( |
499 SyntheticPointerActionParams::PointerActionType::PRESS); | 439 SyntheticPointerActionParams::PointerActionType::PRESS); |
500 action_param_list_->push_back(params); | 440 action_param_list_.push_back(params); |
501 ForwardSyntheticPointerAction(); | 441 ForwardSyntheticPointerAction(); |
502 | 442 |
503 EXPECT_EQ(2, num_success_); | 443 EXPECT_EQ(2, num_success_); |
504 EXPECT_EQ(1, num_failure_); | 444 EXPECT_EQ(1, num_failure_); |
505 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); | 445 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); |
506 EXPECT_EQ(pointer_mouse_target->position(), params.position()); | 446 EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
507 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); | 447 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
508 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); | 448 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
509 | 449 |
510 // Cannot send a mouse down again without releasing the mouse button. | 450 // Cannot send a mouse down again without releasing the mouse button. |
511 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 451 action_param_list_.clear(); |
512 params.set_pointer_action_type( | 452 params.set_pointer_action_type( |
513 SyntheticPointerActionParams::PointerActionType::PRESS); | 453 SyntheticPointerActionParams::PointerActionType::PRESS); |
514 action_param_list_->push_back(params); | 454 action_param_list_.push_back(params); |
515 ForwardSyntheticPointerAction(); | 455 ForwardSyntheticPointerAction(); |
516 | 456 |
517 EXPECT_EQ(2, num_success_); | 457 EXPECT_EQ(2, num_success_); |
518 EXPECT_EQ(2, num_failure_); | 458 EXPECT_EQ(2, num_failure_); |
519 } | 459 } |
520 | 460 |
521 } // namespace | 461 } // namespace |
522 | 462 |
523 } // namespace content | 463 } // namespace content |
OLD | NEW |