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