Chromium Code Reviews| 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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 } | 378 } |
| 379 | 379 |
| 380 void QueueSyntheticGesture(scoped_ptr<SyntheticGesture> gesture) { | 380 void QueueSyntheticGesture(scoped_ptr<SyntheticGesture> gesture) { |
| 381 controller_->QueueSyntheticGesture(gesture.Pass(), | 381 controller_->QueueSyntheticGesture(gesture.Pass(), |
| 382 base::Bind(&SyntheticGestureControllerTest::OnSyntheticGestureCompleted, | 382 base::Bind(&SyntheticGestureControllerTest::OnSyntheticGestureCompleted, |
| 383 base::Unretained(this))); | 383 base::Unretained(this))); |
| 384 } | 384 } |
| 385 | 385 |
| 386 void FlushInputUntilComplete() { | 386 void FlushInputUntilComplete() { |
| 387 while (target_->flush_requested()) { | 387 while (target_->flush_requested()) { |
| 388 target_->ClearFlushRequest(); | 388 while (target_->flush_requested()) { |
| 389 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); | 389 target_->ClearFlushRequest(); |
| 390 controller_->Flush(time_); | 390 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); |
| 391 controller_->Flush(time_); | |
| 392 } | |
| 393 controller_->OnDidFlushInput(); | |
| 391 } | 394 } |
| 392 } | 395 } |
| 393 | 396 |
| 394 void OnSyntheticGestureCompleted(SyntheticGesture::Result result) { | 397 void OnSyntheticGestureCompleted(SyntheticGesture::Result result) { |
| 395 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); | 398 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); |
| 396 if (result == SyntheticGesture::GESTURE_FINISHED) | 399 if (result == SyntheticGesture::GESTURE_FINISHED) |
| 397 num_success_++; | 400 num_success_++; |
| 398 else | 401 else |
| 399 num_failure_++; | 402 num_failure_++; |
| 400 } | 403 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 QueueSyntheticGesture(gesture_2.PassAs<SyntheticGesture>()); | 479 QueueSyntheticGesture(gesture_2.PassAs<SyntheticGesture>()); |
| 477 FlushInputUntilComplete(); | 480 FlushInputUntilComplete(); |
| 478 | 481 |
| 479 EXPECT_TRUE(finished_1); | 482 EXPECT_TRUE(finished_1); |
| 480 EXPECT_TRUE(finished_2); | 483 EXPECT_TRUE(finished_2); |
| 481 | 484 |
| 482 EXPECT_EQ(2, num_success_); | 485 EXPECT_EQ(2, num_success_); |
| 483 EXPECT_EQ(0, num_failure_); | 486 EXPECT_EQ(0, num_failure_); |
| 484 } | 487 } |
| 485 | 488 |
| 489 TEST_F(SyntheticGestureControllerTest, GestureCompledOnDidFlushInput) { | |
|
Dominik Grewe
2014/04/02 09:10:31
typo: GestureCompledOnDidFlushInput -> GestureComp
| |
| 490 CreateControllerAndTarget<MockSyntheticGestureTarget>(); | |
| 491 | |
| 492 bool finished_1, finished_2; | |
| 493 scoped_ptr<MockSyntheticGesture> gesture_1( | |
| 494 new MockSyntheticGesture(&finished_1, 2)); | |
| 495 scoped_ptr<MockSyntheticGesture> gesture_2( | |
| 496 new MockSyntheticGesture(&finished_2, 4)); | |
| 497 | |
| 498 QueueSyntheticGesture(gesture_1.PassAs<SyntheticGesture>()); | |
| 499 QueueSyntheticGesture(gesture_2.PassAs<SyntheticGesture>()); | |
| 500 | |
| 501 while (target_->flush_requested()) { | |
| 502 target_->ClearFlushRequest(); | |
| 503 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); | |
| 504 controller_->Flush(time_); | |
| 505 } | |
| 506 EXPECT_EQ(0, num_success_); | |
| 507 controller_->OnDidFlushInput(); | |
| 508 EXPECT_EQ(1, num_success_); | |
| 509 | |
| 510 while (target_->flush_requested()) { | |
| 511 target_->ClearFlushRequest(); | |
| 512 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); | |
| 513 controller_->Flush(time_); | |
| 514 } | |
| 515 EXPECT_EQ(1, num_success_); | |
| 516 controller_->OnDidFlushInput(); | |
| 517 EXPECT_EQ(2, num_success_); | |
| 518 } | |
| 519 | |
| 486 gfx::Vector2d AddTouchSlopToVector(const gfx::Vector2d& vector, | 520 gfx::Vector2d AddTouchSlopToVector(const gfx::Vector2d& vector, |
| 487 SyntheticGestureTarget* target) { | 521 SyntheticGestureTarget* target) { |
| 488 const int kTouchSlop = target->GetTouchSlopInDips(); | 522 const int kTouchSlop = target->GetTouchSlopInDips(); |
| 489 | 523 |
| 490 int x = vector.x(); | 524 int x = vector.x(); |
| 491 if (x > 0) | 525 if (x > 0) |
| 492 x += kTouchSlop; | 526 x += kTouchSlop; |
| 493 else if (x < 0) | 527 else if (x < 0) |
| 494 x -= kTouchSlop; | 528 x -= kTouchSlop; |
| 495 | 529 |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 958 EXPECT_TRUE(tap_target->GestureFinished()); | 992 EXPECT_TRUE(tap_target->GestureFinished()); |
| 959 EXPECT_EQ(tap_target->position(), params.position); | 993 EXPECT_EQ(tap_target->position(), params.position); |
| 960 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); | 994 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); |
| 961 EXPECT_GE(GetTotalTime(), | 995 EXPECT_GE(GetTotalTime(), |
| 962 base::TimeDelta::FromMilliseconds(params.duration_ms)); | 996 base::TimeDelta::FromMilliseconds(params.duration_ms)); |
| 963 } | 997 } |
| 964 | 998 |
| 965 } // namespace | 999 } // namespace |
| 966 | 1000 |
| 967 } // namespace content | 1001 } // namespace content |
| OLD | NEW |