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" |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 scoped_ptr<SyntheticGestureController> controller_; | 423 scoped_ptr<SyntheticGestureController> controller_; |
424 base::TimeTicks start_time_; | 424 base::TimeTicks start_time_; |
425 base::TimeTicks time_; | 425 base::TimeTicks time_; |
426 int num_success_; | 426 int num_success_; |
427 int num_failure_; | 427 int num_failure_; |
428 }; | 428 }; |
429 | 429 |
430 TEST_F(SyntheticGestureControllerTest, SingleGesture) { | 430 TEST_F(SyntheticGestureControllerTest, SingleGesture) { |
431 CreateControllerAndTarget<MockSyntheticGestureTarget>(); | 431 CreateControllerAndTarget<MockSyntheticGestureTarget>(); |
432 | 432 |
433 bool finished; | 433 bool finished = false; |
434 scoped_ptr<MockSyntheticGesture> gesture( | 434 scoped_ptr<MockSyntheticGesture> gesture( |
435 new MockSyntheticGesture(&finished, 3)); | 435 new MockSyntheticGesture(&finished, 3)); |
436 QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); | 436 QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); |
437 FlushInputUntilComplete(); | 437 FlushInputUntilComplete(); |
438 | 438 |
439 EXPECT_TRUE(finished); | 439 EXPECT_TRUE(finished); |
440 EXPECT_EQ(1, num_success_); | 440 EXPECT_EQ(1, num_success_); |
441 EXPECT_EQ(0, num_failure_); | 441 EXPECT_EQ(0, num_failure_); |
442 } | 442 } |
443 | 443 |
444 TEST_F(SyntheticGestureControllerTest, GestureFailed) { | 444 TEST_F(SyntheticGestureControllerTest, GestureFailed) { |
445 CreateControllerAndTarget<MockSyntheticGestureTarget>(); | 445 CreateControllerAndTarget<MockSyntheticGestureTarget>(); |
446 | 446 |
447 bool finished; | 447 bool finished = false; |
448 scoped_ptr<MockSyntheticGesture> gesture( | 448 scoped_ptr<MockSyntheticGesture> gesture( |
449 new MockSyntheticGesture(&finished, 0)); | 449 new MockSyntheticGesture(&finished, 0)); |
450 QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); | 450 QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); |
451 FlushInputUntilComplete(); | 451 FlushInputUntilComplete(); |
452 | 452 |
453 EXPECT_TRUE(finished); | 453 EXPECT_TRUE(finished); |
454 EXPECT_EQ(1, num_failure_); | 454 EXPECT_EQ(1, num_failure_); |
455 EXPECT_EQ(0, num_success_); | 455 EXPECT_EQ(0, num_success_); |
456 } | 456 } |
457 | 457 |
458 TEST_F(SyntheticGestureControllerTest, SuccessiveGestures) { | 458 TEST_F(SyntheticGestureControllerTest, SuccessiveGestures) { |
459 CreateControllerAndTarget<MockSyntheticGestureTarget>(); | 459 CreateControllerAndTarget<MockSyntheticGestureTarget>(); |
460 | 460 |
461 bool finished_1, finished_2; | 461 bool finished_1 = false; |
462 scoped_ptr<MockSyntheticGesture> gesture_1( | 462 scoped_ptr<MockSyntheticGesture> gesture_1( |
463 new MockSyntheticGesture(&finished_1, 2)); | 463 new MockSyntheticGesture(&finished_1, 2)); |
| 464 bool finished_2 = false; |
464 scoped_ptr<MockSyntheticGesture> gesture_2( | 465 scoped_ptr<MockSyntheticGesture> gesture_2( |
465 new MockSyntheticGesture(&finished_2, 4)); | 466 new MockSyntheticGesture(&finished_2, 4)); |
466 | 467 |
467 // Queue first gesture and wait for it to finish | 468 // Queue first gesture and wait for it to finish |
468 QueueSyntheticGesture(gesture_1.PassAs<SyntheticGesture>()); | 469 QueueSyntheticGesture(gesture_1.PassAs<SyntheticGesture>()); |
469 FlushInputUntilComplete(); | 470 FlushInputUntilComplete(); |
470 | 471 |
471 EXPECT_TRUE(finished_1); | 472 EXPECT_TRUE(finished_1); |
472 EXPECT_EQ(1, num_success_); | 473 EXPECT_EQ(1, num_success_); |
473 EXPECT_EQ(0, num_failure_); | 474 EXPECT_EQ(0, num_failure_); |
474 | 475 |
475 // Queue second gesture. | 476 // Queue second gesture. |
476 QueueSyntheticGesture(gesture_2.PassAs<SyntheticGesture>()); | 477 QueueSyntheticGesture(gesture_2.PassAs<SyntheticGesture>()); |
477 FlushInputUntilComplete(); | 478 FlushInputUntilComplete(); |
478 | 479 |
479 EXPECT_TRUE(finished_2); | 480 EXPECT_TRUE(finished_2); |
480 EXPECT_EQ(2, num_success_); | 481 EXPECT_EQ(2, num_success_); |
481 EXPECT_EQ(0, num_failure_); | 482 EXPECT_EQ(0, num_failure_); |
482 } | 483 } |
483 | 484 |
484 TEST_F(SyntheticGestureControllerTest, TwoGesturesInFlight) { | 485 TEST_F(SyntheticGestureControllerTest, TwoGesturesInFlight) { |
485 CreateControllerAndTarget<MockSyntheticGestureTarget>(); | 486 CreateControllerAndTarget<MockSyntheticGestureTarget>(); |
486 | 487 |
487 bool finished_1, finished_2; | 488 bool finished_1 = false; |
488 scoped_ptr<MockSyntheticGesture> gesture_1( | 489 scoped_ptr<MockSyntheticGesture> gesture_1( |
489 new MockSyntheticGesture(&finished_1, 2)); | 490 new MockSyntheticGesture(&finished_1, 2)); |
| 491 bool finished_2 = false; |
490 scoped_ptr<MockSyntheticGesture> gesture_2( | 492 scoped_ptr<MockSyntheticGesture> gesture_2( |
491 new MockSyntheticGesture(&finished_2, 4)); | 493 new MockSyntheticGesture(&finished_2, 4)); |
492 | 494 |
493 QueueSyntheticGesture(gesture_1.PassAs<SyntheticGesture>()); | 495 QueueSyntheticGesture(gesture_1.PassAs<SyntheticGesture>()); |
494 QueueSyntheticGesture(gesture_2.PassAs<SyntheticGesture>()); | 496 QueueSyntheticGesture(gesture_2.PassAs<SyntheticGesture>()); |
495 FlushInputUntilComplete(); | 497 FlushInputUntilComplete(); |
496 | 498 |
497 EXPECT_TRUE(finished_1); | 499 EXPECT_TRUE(finished_1); |
498 EXPECT_TRUE(finished_2); | 500 EXPECT_TRUE(finished_2); |
499 | 501 |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 EXPECT_TRUE(tap_target->GestureFinished()); | 1004 EXPECT_TRUE(tap_target->GestureFinished()); |
1003 EXPECT_EQ(tap_target->position(), params.position); | 1005 EXPECT_EQ(tap_target->position(), params.position); |
1004 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); | 1006 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); |
1005 EXPECT_GE(GetTotalTime(), | 1007 EXPECT_GE(GetTotalTime(), |
1006 base::TimeDelta::FromMilliseconds(params.duration_ms)); | 1008 base::TimeDelta::FromMilliseconds(params.duration_ms)); |
1007 } | 1009 } |
1008 | 1010 |
1009 } // namespace | 1011 } // namespace |
1010 | 1012 |
1011 } // namespace content | 1013 } // namespace content |
OLD | NEW |