OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "content/browser/renderer_host/input/synthetic_gesture.h" | 8 #include "content/browser/renderer_host/input/synthetic_gesture.h" |
9 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" | 9 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" |
10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
11 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h" | 11 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h" |
12 #include "content/browser/renderer_host/input/synthetic_smooth_drag_gesture.h" | 12 #include "content/browser/renderer_host/input/synthetic_smooth_drag_gesture.h" |
13 #include "content/browser/renderer_host/input/synthetic_smooth_move_gesture.h" | 13 #include "content/browser/renderer_host/input/synthetic_smooth_move_gesture.h" |
14 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" | 14 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" |
15 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" | 15 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" |
16 #include "content/browser/renderer_host/input/synthetic_touchpad_pinch_gesture.h " | |
17 #include "content/browser/renderer_host/input/synthetic_touchscreen_pinch_gestur e.h" | |
16 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 18 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
17 #include "content/common/input/synthetic_pinch_gesture_params.h" | 19 #include "content/common/input/synthetic_pinch_gesture_params.h" |
18 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" | 20 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" |
19 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 21 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
20 #include "content/common/input/synthetic_tap_gesture_params.h" | 22 #include "content/common/input/synthetic_tap_gesture_params.h" |
21 #include "content/public/test/mock_render_process_host.h" | 23 #include "content/public/test/mock_render_process_host.h" |
22 #include "content/public/test/test_browser_context.h" | 24 #include "content/public/test/test_browser_context.h" |
23 #include "content/test/test_render_view_host.h" | 25 #include "content/test/test_render_view_host.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "third_party/WebKit/public/web/WebInputEvent.h" | 27 #include "third_party/WebKit/public/web/WebInputEvent.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 start_to_end_distance_ = mouse_point - start_; | 213 start_to_end_distance_ = mouse_point - start_; |
212 last_mouse_point_ = mouse_point; | 214 last_mouse_point_ = mouse_point; |
213 } | 215 } |
214 } | 216 } |
215 | 217 |
216 private: | 218 private: |
217 bool started_; | 219 bool started_; |
218 gfx::PointF start_, last_mouse_point_; | 220 gfx::PointF start_, last_mouse_point_; |
219 }; | 221 }; |
220 | 222 |
221 class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget { | 223 class MockSyntheticTouchscreenPinchTouchTarget |
224 : public MockSyntheticGestureTarget { | |
222 public: | 225 public: |
223 enum ZoomDirection { | 226 enum ZoomDirection { |
224 ZOOM_DIRECTION_UNKNOWN, | 227 ZOOM_DIRECTION_UNKNOWN, |
225 ZOOM_IN, | 228 ZOOM_IN, |
226 ZOOM_OUT | 229 ZOOM_OUT |
227 }; | 230 }; |
228 | 231 |
229 MockSyntheticPinchTouchTarget() | 232 MockSyntheticTouchscreenPinchTouchTarget() |
230 : initial_pointer_distance_(0), | 233 : initial_pointer_distance_(0), |
231 last_pointer_distance_(0), | 234 last_pointer_distance_(0), |
232 zoom_direction_(ZOOM_DIRECTION_UNKNOWN), | 235 zoom_direction_(ZOOM_DIRECTION_UNKNOWN), |
233 started_(false) {} | 236 started_(false) {} |
234 ~MockSyntheticPinchTouchTarget() override {} | 237 ~MockSyntheticTouchscreenPinchTouchTarget() override {} |
235 | 238 |
236 void DispatchInputEventToPlatform(const WebInputEvent& event) override { | 239 void DispatchInputEventToPlatform(const WebInputEvent& event) override { |
237 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); | 240 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); |
238 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); | 241 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); |
239 ASSERT_EQ(touch_event.touchesLength, 2U); | 242 ASSERT_EQ(touch_event.touchesLength, 2U); |
240 | 243 |
241 if (!started_) { | 244 if (!started_) { |
242 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart); | 245 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart); |
243 | 246 |
244 start_0_ = gfx::PointF(touch_event.touches[0].position); | 247 start_0_ = gfx::PointF(touch_event.touches[0].position); |
(...skipping 19 matching lines...) Expand all Loading... | |
264 else | 267 else |
265 EXPECT_EQ( | 268 EXPECT_EQ( |
266 zoom_direction_, | 269 zoom_direction_, |
267 ComputeZoomDirection(last_pointer_distance_, pointer_distance)); | 270 ComputeZoomDirection(last_pointer_distance_, pointer_distance)); |
268 } | 271 } |
269 | 272 |
270 last_pointer_distance_ = pointer_distance; | 273 last_pointer_distance_ = pointer_distance; |
271 } | 274 } |
272 } | 275 } |
273 | 276 |
277 SyntheticGestureParams::GestureSourceType | |
278 GetDefaultSyntheticGestureSourceType() const override { | |
279 return SyntheticGestureParams::TOUCH_INPUT; | |
280 } | |
281 | |
274 ZoomDirection zoom_direction() const { return zoom_direction_; } | 282 ZoomDirection zoom_direction() const { return zoom_direction_; } |
275 | 283 |
276 float ComputeScaleFactor() const { | 284 float ComputeScaleFactor() const { |
277 switch (zoom_direction_) { | 285 switch (zoom_direction_) { |
278 case ZOOM_IN: | 286 case ZOOM_IN: |
279 return last_pointer_distance_ / | 287 return last_pointer_distance_ / |
280 (initial_pointer_distance_ + 2 * GetTouchSlopInDips()); | 288 (initial_pointer_distance_ + 2 * GetTouchSlopInDips()); |
281 case ZOOM_OUT: | 289 case ZOOM_OUT: |
282 return last_pointer_distance_ / | 290 return last_pointer_distance_ / |
283 (initial_pointer_distance_ - 2 * GetTouchSlopInDips()); | 291 (initial_pointer_distance_ - 2 * GetTouchSlopInDips()); |
(...skipping 14 matching lines...) Expand all Loading... | |
298 } | 306 } |
299 | 307 |
300 float initial_pointer_distance_; | 308 float initial_pointer_distance_; |
301 float last_pointer_distance_; | 309 float last_pointer_distance_; |
302 ZoomDirection zoom_direction_; | 310 ZoomDirection zoom_direction_; |
303 gfx::PointF start_0_; | 311 gfx::PointF start_0_; |
304 gfx::PointF start_1_; | 312 gfx::PointF start_1_; |
305 bool started_; | 313 bool started_; |
306 }; | 314 }; |
307 | 315 |
316 class MockSyntheticTouchpadPinchTouchTarget | |
317 : public MockSyntheticGestureTarget { | |
318 public: | |
319 enum ZoomDirection { ZOOM_DIRECTION_UNKNOWN, ZOOM_IN, ZOOM_OUT }; | |
320 | |
321 MockSyntheticTouchpadPinchTouchTarget() | |
322 : zoom_direction_(ZOOM_DIRECTION_UNKNOWN), | |
323 started_(false), | |
324 ended_(false), | |
325 scale_factor_(1.0f) {} | |
326 ~MockSyntheticTouchpadPinchTouchTarget() override {} | |
327 | |
328 void DispatchInputEventToPlatform(const WebInputEvent& event) override { | |
329 EXPECT_TRUE(WebInputEvent::isGestureEventType(event.type)); | |
330 const blink::WebGestureEvent& gesture_event = | |
331 static_cast<const blink::WebGestureEvent&>(event); | |
332 | |
333 if (gesture_event.type == WebInputEvent::GesturePinchBegin) { | |
334 EXPECT_FALSE(started_); | |
335 EXPECT_FALSE(ended_); | |
336 started_ = true; | |
337 } else if (gesture_event.type == WebInputEvent::GesturePinchEnd) { | |
338 EXPECT_TRUE(started_); | |
339 EXPECT_FALSE(ended_); | |
340 ended_ = true; | |
341 } else { | |
342 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, gesture_event.type); | |
343 EXPECT_TRUE(started_); | |
344 EXPECT_FALSE(ended_); | |
345 const float scale = gesture_event.data.pinchUpdate.scale; | |
346 if (scale != 1.0f) { | |
347 if (zoom_direction_ == ZOOM_DIRECTION_UNKNOWN) { | |
348 zoom_direction_ = scale > 1.0f ? ZOOM_IN : ZOOM_OUT; | |
349 } else if (zoom_direction_ == ZOOM_IN) { | |
350 EXPECT_GT(scale, 1.0f); | |
351 } else { | |
352 EXPECT_EQ(ZOOM_OUT, zoom_direction_); | |
353 EXPECT_LT(scale, 1.0f); | |
354 } | |
355 | |
356 scale_factor_ *= scale; | |
357 } | |
358 } | |
359 } | |
360 | |
361 SyntheticGestureParams::GestureSourceType | |
362 GetDefaultSyntheticGestureSourceType() const override { | |
363 return SyntheticGestureParams::MOUSE_INPUT; | |
364 } | |
365 | |
366 ZoomDirection zoom_direction() const { return zoom_direction_; } | |
367 | |
368 float scale_factor() const { return scale_factor_; } | |
369 | |
370 private: | |
371 ZoomDirection zoom_direction_; | |
372 bool started_; | |
373 bool ended_; | |
374 float scale_factor_; | |
375 }; | |
376 | |
308 class MockSyntheticTapGestureTarget : public MockSyntheticGestureTarget { | 377 class MockSyntheticTapGestureTarget : public MockSyntheticGestureTarget { |
309 public: | 378 public: |
310 MockSyntheticTapGestureTarget() : state_(NOT_STARTED) {} | 379 MockSyntheticTapGestureTarget() : state_(NOT_STARTED) {} |
311 ~MockSyntheticTapGestureTarget() override {} | 380 ~MockSyntheticTapGestureTarget() override {} |
312 | 381 |
313 bool GestureFinished() const { return state_ == FINISHED; } | 382 bool GestureFinished() const { return state_ == FINISHED; } |
314 gfx::PointF position() const { return position_; } | 383 gfx::PointF position() const { return position_; } |
315 base::TimeDelta GetDuration() const { return stop_time_ - start_time_; } | 384 base::TimeDelta GetDuration() const { return stop_time_ - start_time_; } |
316 | 385 |
317 protected: | 386 protected: |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1093 params.anchor.SetPoint(432, 89); | 1162 params.anchor.SetPoint(432, 89); |
1094 params.distances.push_back(gfx::Vector2d(0, -234)); | 1163 params.distances.push_back(gfx::Vector2d(0, -234)); |
1095 params.speed_in_pixels_s = 800; | 1164 params.speed_in_pixels_s = 800; |
1096 | 1165 |
1097 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 1166 scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
1098 new SyntheticSmoothScrollGesture(params)); | 1167 new SyntheticSmoothScrollGesture(params)); |
1099 const base::TimeTicks timestamp; | 1168 const base::TimeTicks timestamp; |
1100 gesture->ForwardInputEvents(timestamp, target_); | 1169 gesture->ForwardInputEvents(timestamp, target_); |
1101 } | 1170 } |
1102 | 1171 |
1103 TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) { | 1172 TEST_F(SyntheticGestureControllerTest, |
1104 CreateControllerAndTarget<MockSyntheticPinchTouchTarget>(); | 1173 TouchscreenTouchpadPinchGestureTouchZoomIn) { |
1174 CreateControllerAndTarget<MockSyntheticTouchscreenPinchTouchTarget>(); | |
1175 | |
1176 SyntheticPinchGestureParams params; | |
1177 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
1178 params.scale_factor = 2.3f; | |
1179 params.anchor.SetPoint(54, 89); | |
1180 | |
1181 scoped_ptr<SyntheticTouchscreenPinchGesture> gesture( | |
1182 new SyntheticTouchscreenPinchGesture(params)); | |
1183 QueueSyntheticGesture(gesture.Pass()); | |
1184 FlushInputUntilComplete(); | |
1185 | |
1186 MockSyntheticTouchscreenPinchTouchTarget* pinch_target = | |
1187 static_cast<MockSyntheticTouchscreenPinchTouchTarget*>(target_); | |
1188 EXPECT_EQ(1, num_success_); | |
1189 EXPECT_EQ(0, num_failure_); | |
1190 EXPECT_EQ(pinch_target->zoom_direction(), | |
1191 MockSyntheticTouchscreenPinchTouchTarget::ZOOM_IN); | |
1192 EXPECT_FLOAT_EQ(params.scale_factor, pinch_target->ComputeScaleFactor()); | |
1193 } | |
1194 | |
1195 TEST_F(SyntheticGestureControllerTest, | |
1196 TouchscreenTouchpadPinchGestureTouchZoomOut) { | |
1197 CreateControllerAndTarget<MockSyntheticTouchscreenPinchTouchTarget>(); | |
1198 | |
1199 SyntheticPinchGestureParams params; | |
1200 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
1201 params.scale_factor = 0.4f; | |
1202 params.anchor.SetPoint(-12, 93); | |
1203 | |
1204 scoped_ptr<SyntheticTouchscreenPinchGesture> gesture( | |
1205 new SyntheticTouchscreenPinchGesture(params)); | |
1206 QueueSyntheticGesture(gesture.Pass()); | |
1207 FlushInputUntilComplete(); | |
1208 | |
1209 MockSyntheticTouchscreenPinchTouchTarget* pinch_target = | |
1210 static_cast<MockSyntheticTouchscreenPinchTouchTarget*>(target_); | |
1211 EXPECT_EQ(1, num_success_); | |
1212 EXPECT_EQ(0, num_failure_); | |
1213 EXPECT_EQ(pinch_target->zoom_direction(), | |
1214 MockSyntheticTouchscreenPinchTouchTarget::ZOOM_OUT); | |
1215 EXPECT_FLOAT_EQ(params.scale_factor, pinch_target->ComputeScaleFactor()); | |
1216 } | |
1217 | |
1218 TEST_F(SyntheticGestureControllerTest, | |
1219 TouchscreenTouchpadPinchGestureTouchNoScaling) { | |
1220 CreateControllerAndTarget<MockSyntheticTouchscreenPinchTouchTarget>(); | |
1221 | |
1222 SyntheticPinchGestureParams params; | |
1223 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
1224 params.scale_factor = 1.0f; | |
1225 | |
1226 scoped_ptr<SyntheticTouchscreenPinchGesture> gesture( | |
1227 new SyntheticTouchscreenPinchGesture(params)); | |
1228 QueueSyntheticGesture(gesture.Pass()); | |
1229 FlushInputUntilComplete(); | |
1230 | |
1231 MockSyntheticTouchscreenPinchTouchTarget* pinch_target = | |
1232 static_cast<MockSyntheticTouchscreenPinchTouchTarget*>(target_); | |
1233 EXPECT_EQ(1, num_success_); | |
1234 EXPECT_EQ(0, num_failure_); | |
1235 EXPECT_EQ(pinch_target->zoom_direction(), | |
1236 MockSyntheticTouchscreenPinchTouchTarget::ZOOM_DIRECTION_UNKNOWN); | |
1237 EXPECT_EQ(params.scale_factor, pinch_target->ComputeScaleFactor()); | |
1238 } | |
1239 | |
1240 TEST_F(SyntheticGestureControllerTest, TouchpadPinchGestureTouchZoomIn) { | |
1241 CreateControllerAndTarget<MockSyntheticTouchpadPinchTouchTarget>(); | |
1242 | |
1243 SyntheticPinchGestureParams params; | |
1244 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | |
1245 params.scale_factor = 2.3f; | |
1246 params.anchor.SetPoint(54, 89); | |
1247 | |
1248 scoped_ptr<SyntheticTouchpadPinchGesture> gesture( | |
1249 new SyntheticTouchpadPinchGesture(params)); | |
1250 QueueSyntheticGesture(gesture.Pass()); | |
1251 FlushInputUntilComplete(); | |
1252 | |
1253 MockSyntheticTouchpadPinchTouchTarget* pinch_target = | |
1254 static_cast<MockSyntheticTouchpadPinchTouchTarget*>(target_); | |
1255 EXPECT_EQ(1, num_success_); | |
1256 EXPECT_EQ(0, num_failure_); | |
1257 EXPECT_EQ(pinch_target->zoom_direction(), | |
1258 MockSyntheticTouchpadPinchTouchTarget::ZOOM_IN); | |
1259 EXPECT_FLOAT_EQ(params.scale_factor, pinch_target->scale_factor()); | |
1260 } | |
1261 | |
1262 TEST_F(SyntheticGestureControllerTest, TouchpadPinchGestureTouchZoomOut) { | |
1263 CreateControllerAndTarget<MockSyntheticTouchpadPinchTouchTarget>(); | |
1264 | |
1265 SyntheticPinchGestureParams params; | |
1266 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | |
1267 params.scale_factor = 0.4f; | |
1268 params.anchor.SetPoint(-12, 93); | |
1269 | |
1270 scoped_ptr<SyntheticTouchpadPinchGesture> gesture( | |
1271 new SyntheticTouchpadPinchGesture(params)); | |
1272 QueueSyntheticGesture(gesture.Pass()); | |
1273 FlushInputUntilComplete(); | |
1274 | |
1275 MockSyntheticTouchpadPinchTouchTarget* pinch_target = | |
1276 static_cast<MockSyntheticTouchpadPinchTouchTarget*>(target_); | |
1277 EXPECT_EQ(1, num_success_); | |
1278 EXPECT_EQ(0, num_failure_); | |
1279 EXPECT_EQ(pinch_target->zoom_direction(), | |
1280 MockSyntheticTouchpadPinchTouchTarget::ZOOM_OUT); | |
1281 EXPECT_FLOAT_EQ(params.scale_factor, pinch_target->scale_factor()); | |
1282 } | |
1283 | |
1284 TEST_F(SyntheticGestureControllerTest, TouchpadPinchGestureTouchNoScaling) { | |
1285 CreateControllerAndTarget<MockSyntheticTouchpadPinchTouchTarget>(); | |
1286 | |
1287 SyntheticPinchGestureParams params; | |
1288 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | |
1289 params.scale_factor = 1.0f; | |
1290 | |
1291 scoped_ptr<SyntheticTouchpadPinchGesture> gesture( | |
1292 new SyntheticTouchpadPinchGesture(params)); | |
1293 QueueSyntheticGesture(gesture.Pass()); | |
1294 FlushInputUntilComplete(); | |
1295 | |
1296 MockSyntheticTouchpadPinchTouchTarget* pinch_target = | |
1297 static_cast<MockSyntheticTouchpadPinchTouchTarget*>(target_); | |
1298 EXPECT_EQ(1, num_success_); | |
1299 EXPECT_EQ(0, num_failure_); | |
1300 EXPECT_EQ(pinch_target->zoom_direction(), | |
1301 MockSyntheticTouchpadPinchTouchTarget::ZOOM_DIRECTION_UNKNOWN); | |
1302 EXPECT_EQ(params.scale_factor, pinch_target->scale_factor()); | |
1303 } | |
1304 | |
1305 // Ensure that if SyntheticPinchGesture is instantiated with TOUCH_INPUT it | |
1306 // correctly creates a touchscreen gesture. | |
1307 TEST_F(SyntheticGestureControllerTest, PinchGestureExplicitTouch) { | |
1308 CreateControllerAndTarget<MockSyntheticTouchscreenPinchTouchTarget>(); | |
1105 | 1309 |
1106 SyntheticPinchGestureParams params; | 1310 SyntheticPinchGestureParams params; |
1107 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 1311 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
jdduke (slow)
2015/09/22 21:58:49
What are we validating in these 4 tests? I guess w
ericrk
2015/09/22 22:08:49
The targets will fail if they receive the wrong ev
| |
1108 params.scale_factor = 2.3f; | 1312 params.scale_factor = 2.3f; |
1109 params.anchor.SetPoint(54, 89); | 1313 params.anchor.SetPoint(54, 89); |
1110 | 1314 |
1111 scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params)); | 1315 scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params)); |
1112 QueueSyntheticGesture(gesture.Pass()); | 1316 QueueSyntheticGesture(gesture.Pass()); |
1113 FlushInputUntilComplete(); | 1317 FlushInputUntilComplete(); |
1114 | |
1115 MockSyntheticPinchTouchTarget* pinch_target = | |
1116 static_cast<MockSyntheticPinchTouchTarget*>(target_); | |
1117 EXPECT_EQ(1, num_success_); | |
1118 EXPECT_EQ(0, num_failure_); | |
1119 EXPECT_EQ(pinch_target->zoom_direction(), | |
1120 MockSyntheticPinchTouchTarget::ZOOM_IN); | |
1121 EXPECT_FLOAT_EQ(params.scale_factor, pinch_target->ComputeScaleFactor()); | |
1122 } | 1318 } |
1123 | 1319 |
1124 TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomOut) { | 1320 // Ensure that if SyntheticPinchGesture is instantiated with MOUSE_INPUT it |
1125 CreateControllerAndTarget<MockSyntheticPinchTouchTarget>(); | 1321 // correctly creates a touchpad gesture. |
1322 TEST_F(SyntheticGestureControllerTest, PinchGestureExplicitMouse) { | |
1323 CreateControllerAndTarget<MockSyntheticTouchpadPinchTouchTarget>(); | |
1126 | 1324 |
1127 SyntheticPinchGestureParams params; | 1325 SyntheticPinchGestureParams params; |
1128 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 1326 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
1129 params.scale_factor = 0.4f; | 1327 params.scale_factor = 2.3f; |
1130 params.anchor.SetPoint(-12, 93); | 1328 params.anchor.SetPoint(54, 89); |
1131 | 1329 |
1132 scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params)); | 1330 scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params)); |
1133 QueueSyntheticGesture(gesture.Pass()); | 1331 QueueSyntheticGesture(gesture.Pass()); |
1134 FlushInputUntilComplete(); | 1332 FlushInputUntilComplete(); |
1135 | |
1136 MockSyntheticPinchTouchTarget* pinch_target = | |
1137 static_cast<MockSyntheticPinchTouchTarget*>(target_); | |
1138 EXPECT_EQ(1, num_success_); | |
1139 EXPECT_EQ(0, num_failure_); | |
1140 EXPECT_EQ(pinch_target->zoom_direction(), | |
1141 MockSyntheticPinchTouchTarget::ZOOM_OUT); | |
1142 EXPECT_FLOAT_EQ(params.scale_factor, pinch_target->ComputeScaleFactor()); | |
1143 } | 1333 } |
1144 | 1334 |
1145 TEST_F(SyntheticGestureControllerTest, PinchGestureTouchNoScaling) { | 1335 // Ensure that if SyntheticPinchGesture is instantiated with DEFAULT_INPUT it |
1146 CreateControllerAndTarget<MockSyntheticPinchTouchTarget>(); | 1336 // correctly creates a touchscreen gesture for a touchscreen controller. |
1337 TEST_F(SyntheticGestureControllerTest, PinchGestureDefaultTouch) { | |
1338 CreateControllerAndTarget<MockSyntheticTouchscreenPinchTouchTarget>(); | |
1147 | 1339 |
1148 SyntheticPinchGestureParams params; | 1340 SyntheticPinchGestureParams params; |
1149 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 1341 params.gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; |
1150 params.scale_factor = 1.0f; | 1342 params.scale_factor = 2.3f; |
1343 params.anchor.SetPoint(54, 89); | |
1151 | 1344 |
1152 scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params)); | 1345 scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params)); |
1153 QueueSyntheticGesture(gesture.Pass()); | 1346 QueueSyntheticGesture(gesture.Pass()); |
1154 FlushInputUntilComplete(); | 1347 FlushInputUntilComplete(); |
1348 } | |
1155 | 1349 |
1156 MockSyntheticPinchTouchTarget* pinch_target = | 1350 // Ensure that if SyntheticPinchGesture is instantiated with DEFAULT_INPUT it |
1157 static_cast<MockSyntheticPinchTouchTarget*>(target_); | 1351 // correctly creates a touchpad gesture for a touchpad controller. |
1158 EXPECT_EQ(1, num_success_); | 1352 TEST_F(SyntheticGestureControllerTest, PinchGestureDefaultMouse) { |
1159 EXPECT_EQ(0, num_failure_); | 1353 CreateControllerAndTarget<MockSyntheticTouchpadPinchTouchTarget>(); |
1160 EXPECT_EQ(pinch_target->zoom_direction(), | 1354 |
1161 MockSyntheticPinchTouchTarget::ZOOM_DIRECTION_UNKNOWN); | 1355 SyntheticPinchGestureParams params; |
1162 EXPECT_EQ(params.scale_factor, pinch_target->ComputeScaleFactor()); | 1356 params.gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; |
1357 params.scale_factor = 2.3f; | |
1358 params.anchor.SetPoint(54, 89); | |
1359 | |
1360 scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params)); | |
1361 QueueSyntheticGesture(gesture.Pass()); | |
1362 FlushInputUntilComplete(); | |
1163 } | 1363 } |
1164 | 1364 |
1165 TEST_F(SyntheticGestureControllerTest, TapGestureTouch) { | 1365 TEST_F(SyntheticGestureControllerTest, TapGestureTouch) { |
1166 CreateControllerAndTarget<MockSyntheticTapTouchTarget>(); | 1366 CreateControllerAndTarget<MockSyntheticTapTouchTarget>(); |
1167 | 1367 |
1168 SyntheticTapGestureParams params; | 1368 SyntheticTapGestureParams params; |
1169 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 1369 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
1170 params.duration_ms = 123; | 1370 params.duration_ms = 123; |
1171 params.position.SetPoint(87, -124); | 1371 params.position.SetPoint(87, -124); |
1172 | 1372 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1204 EXPECT_TRUE(tap_target->GestureFinished()); | 1404 EXPECT_TRUE(tap_target->GestureFinished()); |
1205 EXPECT_EQ(tap_target->position(), params.position); | 1405 EXPECT_EQ(tap_target->position(), params.position); |
1206 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); | 1406 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); |
1207 EXPECT_GE(GetTotalTime(), | 1407 EXPECT_GE(GetTotalTime(), |
1208 base::TimeDelta::FromMilliseconds(params.duration_ms)); | 1408 base::TimeDelta::FromMilliseconds(params.duration_ms)); |
1209 } | 1409 } |
1210 | 1410 |
1211 } // namespace | 1411 } // namespace |
1212 | 1412 |
1213 } // namespace content | 1413 } // namespace content |
OLD | NEW |