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

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

Powered by Google App Engine
This is Rietveld 408576698