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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.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_controller.h" | 8 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" |
9 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 9 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
10 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h" | 10 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h" |
11 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" | 11 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" |
12 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 12 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
13 #include "content/browser/renderer_host/test_render_view_host.h" | 13 #include "content/browser/renderer_host/test_render_view_host.h" |
14 #include "content/common/input/input_event.h" | 14 #include "content/common/input/input_event.h" |
15 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 15 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
16 #include "content/public/test/mock_render_process_host.h" | 16 #include "content/public/test/mock_render_process_host.h" |
17 #include "content/public/test/test_browser_context.h" | 17 #include "content/public/test/test_browser_context.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/WebKit/public/web/WebInputEvent.h" | 19 #include "third_party/WebKit/public/web/WebInputEvent.h" |
20 #include "ui/gfx/point_f.h" | 20 #include "ui/gfx/point_f.h" |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const int kFlushInputRateInMs = 16; | 26 const int kFlushInputRateInMs = 16; |
27 const int kPointerAssumedStoppedTimeMs = 43; | 27 const int kPointerAssumedStoppedTimeMs = 43; |
| 28 const int kTouchSlopInDips = 7; |
28 | 29 |
29 class MockSyntheticGesture : public SyntheticGesture { | 30 class MockSyntheticGesture : public SyntheticGesture { |
30 public: | 31 public: |
31 MockSyntheticGesture(bool* finished, int num_steps) | 32 MockSyntheticGesture(bool* finished, int num_steps) |
32 : finished_(finished), | 33 : finished_(finished), |
33 num_steps_(num_steps), | 34 num_steps_(num_steps), |
34 step_count_(0) { | 35 step_count_(0) { |
35 *finished_ = false; | 36 *finished_ = false; |
36 } | 37 } |
37 virtual ~MockSyntheticGesture() {} | 38 virtual ~MockSyntheticGesture() {} |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 94 } |
94 | 95 |
95 virtual base::TimeDelta PointerAssumedStoppedTime() const OVERRIDE { | 96 virtual base::TimeDelta PointerAssumedStoppedTime() const OVERRIDE { |
96 return base::TimeDelta::FromMilliseconds(pointer_assumed_stopped_time_ms_); | 97 return base::TimeDelta::FromMilliseconds(pointer_assumed_stopped_time_ms_); |
97 } | 98 } |
98 | 99 |
99 void set_pointer_assumed_stopped_time_ms(int time_ms) { | 100 void set_pointer_assumed_stopped_time_ms(int time_ms) { |
100 pointer_assumed_stopped_time_ms_ = time_ms; | 101 pointer_assumed_stopped_time_ms_ = time_ms; |
101 } | 102 } |
102 | 103 |
| 104 virtual int GetTouchSlopInDips() const OVERRIDE { |
| 105 return kTouchSlopInDips; |
| 106 } |
| 107 |
103 int num_success() const { return num_success_; } | 108 int num_success() const { return num_success_; } |
104 int num_failure() const { return num_failure_; } | 109 int num_failure() const { return num_failure_; } |
105 | 110 |
106 bool flush_requested() const { return flush_requested_; } | 111 bool flush_requested() const { return flush_requested_; } |
107 void ClearFlushRequest() { flush_requested_ = false; } | 112 void ClearFlushRequest() { flush_requested_ = false; } |
108 | 113 |
109 private: | 114 private: |
110 int num_success_; | 115 int num_success_; |
111 int num_failure_; | 116 int num_failure_; |
112 | 117 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 371 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
367 params.distance = 123; | 372 params.distance = 123; |
368 | 373 |
369 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 374 scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
370 new SyntheticSmoothScrollGesture(params)); | 375 new SyntheticSmoothScrollGesture(params)); |
371 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); | 376 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); |
372 FlushInputUntilComplete(); | 377 FlushInputUntilComplete(); |
373 | 378 |
374 EXPECT_EQ(1, target_->num_success()); | 379 EXPECT_EQ(1, target_->num_success()); |
375 EXPECT_EQ(0, target_->num_failure()); | 380 EXPECT_EQ(0, target_->num_failure()); |
376 EXPECT_FLOAT_EQ(params.distance, | 381 EXPECT_FLOAT_EQ(params.distance + target_->GetTouchSlopInDips(), |
377 static_cast<MockSyntheticSmoothScrollTouchTarget*>(target_) | 382 static_cast<MockSyntheticSmoothScrollTouchTarget*>(target_) |
378 ->scroll_distance()); | 383 ->scroll_distance()); |
379 } | 384 } |
380 | 385 |
381 TEST_F(SyntheticGestureControllerTest, SmoothScrollGestureTouchLongStop) { | 386 TEST_F(SyntheticGestureControllerTest, SmoothScrollGestureTouchLongStop) { |
382 CreateControllerAndTarget<MockSyntheticSmoothScrollTouchTarget>(); | 387 CreateControllerAndTarget<MockSyntheticSmoothScrollTouchTarget>(); |
383 | 388 |
384 // Create a smooth scroll with a short distance and set the pointer assumed | 389 // Create a smooth scroll with a short distance and set the pointer assumed |
385 // stopped time high, so that the stopping should dominate the time the | 390 // stopped time high, so that the stopping should dominate the time the |
386 // gesture is active. | 391 // gesture is active. |
387 SyntheticSmoothScrollGestureParams params; | 392 SyntheticSmoothScrollGestureParams params; |
388 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 393 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
389 params.distance = 21; | 394 params.distance = 21; |
390 | 395 |
391 target_->set_pointer_assumed_stopped_time_ms(543); | 396 target_->set_pointer_assumed_stopped_time_ms(543); |
392 | 397 |
393 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 398 scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
394 new SyntheticSmoothScrollGesture(params)); | 399 new SyntheticSmoothScrollGesture(params)); |
395 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); | 400 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); |
396 FlushInputUntilComplete(); | 401 FlushInputUntilComplete(); |
397 | 402 |
398 EXPECT_EQ(1, target_->num_success()); | 403 EXPECT_EQ(1, target_->num_success()); |
399 EXPECT_EQ(0, target_->num_failure()); | 404 EXPECT_EQ(0, target_->num_failure()); |
400 EXPECT_FLOAT_EQ(params.distance, | 405 EXPECT_FLOAT_EQ(params.distance + target_->GetTouchSlopInDips(), |
401 static_cast<MockSyntheticSmoothScrollTouchTarget*>(target_) | 406 static_cast<MockSyntheticSmoothScrollTouchTarget*>(target_) |
402 ->scroll_distance()); | 407 ->scroll_distance()); |
403 EXPECT_GE(GetTotalTime(), target_->PointerAssumedStoppedTime()); | 408 EXPECT_GE(GetTotalTime(), target_->PointerAssumedStoppedTime()); |
404 } | 409 } |
405 | 410 |
| 411 TEST_F(SyntheticGestureControllerTest, SmoothScrollGestureTouchZeroDistance) { |
| 412 CreateControllerAndTarget<MockSyntheticSmoothScrollTouchTarget>(); |
| 413 |
| 414 SyntheticSmoothScrollGestureParams params; |
| 415 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| 416 params.distance = 0; |
| 417 |
| 418 scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
| 419 new SyntheticSmoothScrollGesture(params)); |
| 420 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); |
| 421 FlushInputUntilComplete(); |
| 422 |
| 423 EXPECT_EQ(1, target_->num_success()); |
| 424 EXPECT_EQ(0, target_->num_failure()); |
| 425 EXPECT_FLOAT_EQ(0, static_cast<MockSyntheticSmoothScrollTouchTarget*>(target_) |
| 426 ->scroll_distance()); |
| 427 } |
| 428 |
406 TEST_F(SyntheticGestureControllerTest, SmoothScrollGestureMouse) { | 429 TEST_F(SyntheticGestureControllerTest, SmoothScrollGestureMouse) { |
407 CreateControllerAndTarget<MockSyntheticSmoothScrollMouseTarget>(); | 430 CreateControllerAndTarget<MockSyntheticSmoothScrollMouseTarget>(); |
408 | 431 |
409 SyntheticSmoothScrollGestureParams params; | 432 SyntheticSmoothScrollGestureParams params; |
410 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | 433 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
411 params.distance = -234; | 434 params.distance = -234; |
412 | 435 |
413 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 436 scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
414 new SyntheticSmoothScrollGesture(params)); | 437 new SyntheticSmoothScrollGesture(params)); |
415 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); | 438 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); |
(...skipping 16 matching lines...) Expand all Loading... |
432 | 455 |
433 scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params)); | 456 scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params)); |
434 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); | 457 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); |
435 FlushInputUntilComplete(); | 458 FlushInputUntilComplete(); |
436 | 459 |
437 EXPECT_EQ(1, target_->num_success()); | 460 EXPECT_EQ(1, target_->num_success()); |
438 EXPECT_EQ(0, target_->num_failure()); | 461 EXPECT_EQ(0, target_->num_failure()); |
439 EXPECT_EQ( | 462 EXPECT_EQ( |
440 static_cast<MockSyntheticPinchTouchTarget*>(target_)->zoom_direction(), | 463 static_cast<MockSyntheticPinchTouchTarget*>(target_)->zoom_direction(), |
441 MockSyntheticPinchTouchTarget::ZOOM_IN); | 464 MockSyntheticPinchTouchTarget::ZOOM_IN); |
442 EXPECT_FLOAT_EQ(params.total_num_pixels_covered, | 465 EXPECT_FLOAT_EQ( |
443 static_cast<MockSyntheticPinchTouchTarget*>(target_) | 466 params.total_num_pixels_covered + 2 * target_->GetTouchSlopInDips(), |
444 ->total_num_pixels_covered()); | 467 static_cast<MockSyntheticPinchTouchTarget*>(target_) |
| 468 ->total_num_pixels_covered()); |
445 } | 469 } |
446 | 470 |
447 TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomOut) { | 471 TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomOut) { |
448 CreateControllerAndTarget<MockSyntheticPinchTouchTarget>(); | 472 CreateControllerAndTarget<MockSyntheticPinchTouchTarget>(); |
449 | 473 |
450 SyntheticPinchGestureParams params; | 474 SyntheticPinchGestureParams params; |
451 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 475 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
452 params.zoom_in = false; | 476 params.zoom_in = false; |
453 params.total_num_pixels_covered = 456; | 477 params.total_num_pixels_covered = 456; |
454 | 478 |
455 scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params)); | 479 scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params)); |
456 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); | 480 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); |
457 FlushInputUntilComplete(); | 481 FlushInputUntilComplete(); |
458 | 482 |
459 EXPECT_EQ(1, target_->num_success()); | 483 EXPECT_EQ(1, target_->num_success()); |
460 EXPECT_EQ(0, target_->num_failure()); | 484 EXPECT_EQ(0, target_->num_failure()); |
461 EXPECT_EQ( | 485 EXPECT_EQ( |
462 static_cast<MockSyntheticPinchTouchTarget*>(target_)->zoom_direction(), | 486 static_cast<MockSyntheticPinchTouchTarget*>(target_)->zoom_direction(), |
463 MockSyntheticPinchTouchTarget::ZOOM_OUT); | 487 MockSyntheticPinchTouchTarget::ZOOM_OUT); |
464 EXPECT_FLOAT_EQ(params.total_num_pixels_covered, | 488 EXPECT_FLOAT_EQ( |
465 static_cast<MockSyntheticPinchTouchTarget*>(target_) | 489 params.total_num_pixels_covered + 2 * target_->GetTouchSlopInDips(), |
466 ->total_num_pixels_covered()); | 490 static_cast<MockSyntheticPinchTouchTarget*>(target_) |
| 491 ->total_num_pixels_covered()); |
| 492 } |
| 493 |
| 494 TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZeroPixelsCovered) { |
| 495 CreateControllerAndTarget<MockSyntheticPinchTouchTarget>(); |
| 496 |
| 497 SyntheticPinchGestureParams params; |
| 498 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| 499 params.zoom_in = true; |
| 500 params.total_num_pixels_covered = 0; |
| 501 |
| 502 scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params)); |
| 503 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); |
| 504 FlushInputUntilComplete(); |
| 505 |
| 506 EXPECT_EQ(1, target_->num_success()); |
| 507 EXPECT_EQ(0, target_->num_failure()); |
| 508 EXPECT_EQ( |
| 509 static_cast<MockSyntheticPinchTouchTarget*>(target_)->zoom_direction(), |
| 510 MockSyntheticPinchTouchTarget::ZOOM_DIRECTION_UNKNOWN); |
| 511 EXPECT_FLOAT_EQ(0, static_cast<MockSyntheticPinchTouchTarget*>(target_) |
| 512 ->total_num_pixels_covered()); |
467 } | 513 } |
468 | 514 |
469 } // namespace | 515 } // namespace |
470 | 516 |
471 } // namespace content | 517 } // namespace content |
OLD | NEW |