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

Side by Side Diff: content/browser/renderer_host/input/synthetic_pointer_action_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698