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