| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/test/simple_test_tick_clock.h" |
| 13 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/aura/env.h" | 16 #include "ui/aura/env.h" |
| 16 #include "ui/aura/test/aura_test_base.h" | 17 #include "ui/aura/test/aura_test_base.h" |
| 17 #include "ui/aura/test/test_window_delegate.h" | 18 #include "ui/aura/test/test_window_delegate.h" |
| 18 #include "ui/aura/test/test_windows.h" | 19 #include "ui/aura/test/test_windows.h" |
| 19 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_event_dispatcher.h" | 21 #include "ui/aura/window_event_dispatcher.h" |
| 21 #include "ui/base/hit_test.h" | 22 #include "ui/base/hit_test.h" |
| 22 #include "ui/base/ui_base_switches.h" | 23 #include "ui/base/ui_base_switches.h" |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 | 475 |
| 475 private: | 476 private: |
| 476 ui::GestureRecognizer* original_gr_; | 477 ui::GestureRecognizer* original_gr_; |
| 477 std::unique_ptr<ui::GestureRecognizer> new_gr_; | 478 std::unique_ptr<ui::GestureRecognizer> new_gr_; |
| 478 | 479 |
| 479 DISALLOW_COPY_AND_ASSIGN(ScopedGestureRecognizerSetter); | 480 DISALLOW_COPY_AND_ASSIGN(ScopedGestureRecognizerSetter); |
| 480 }; | 481 }; |
| 481 | 482 |
| 482 class TimedEvents { | 483 class TimedEvents { |
| 483 private: | 484 private: |
| 484 int simulated_now_; | 485 base::SimpleTestTickClock tick_clock_; |
| 485 | 486 |
| 486 public: | 487 public: |
| 487 // Use a non-zero start time to pass DCHECKs which ensure events have had a | 488 // Use a non-zero start time to pass DCHECKs which ensure events have had a |
| 488 // time assigned. | 489 // time assigned. |
| 489 TimedEvents() : simulated_now_(1) { | 490 TimedEvents() { |
| 491 tick_clock_.Advance(base::TimeDelta::FromMilliseconds(1)); |
| 490 } | 492 } |
| 491 | 493 |
| 492 base::TimeDelta Now() { | 494 base::TimeTicks Now() { |
| 493 base::TimeDelta t = base::TimeDelta::FromMilliseconds(simulated_now_); | 495 base::TimeTicks t = tick_clock_.NowTicks(); |
| 494 simulated_now_++; | 496 tick_clock_.Advance(base::TimeDelta::FromMilliseconds(1)); |
| 495 return t; | 497 return t; |
| 496 } | 498 } |
| 497 | 499 |
| 498 base::TimeDelta LeapForward(int time_in_millis) { | 500 base::TimeTicks LeapForward(int time_in_millis) { |
| 499 simulated_now_ += time_in_millis; | 501 tick_clock_.Advance(base::TimeDelta::FromMilliseconds(time_in_millis)); |
| 500 return base::TimeDelta::FromMilliseconds(simulated_now_); | 502 return tick_clock_.NowTicks(); |
| 501 } | 503 } |
| 502 | 504 |
| 503 base::TimeDelta InFuture(int time_in_millis) { | 505 base::TimeTicks InFuture(int time_in_millis) { |
| 504 return base::TimeDelta::FromMilliseconds(simulated_now_ + time_in_millis); | 506 return tick_clock_.NowTicks() + |
| 507 base::TimeDelta::FromMilliseconds(time_in_millis); |
| 505 } | 508 } |
| 506 | 509 |
| 507 void SendScrollEvents(ui::EventProcessor* dispatcher, | 510 void SendScrollEvents(ui::EventProcessor* dispatcher, |
| 508 int x_start, | 511 int x_start, |
| 509 int y_start, | 512 int y_start, |
| 510 int dx, | 513 int dx, |
| 511 int dy, | 514 int dy, |
| 512 int touch_id, | 515 int touch_id, |
| 513 int time_step, | 516 int time_step_ms, |
| 514 int num_steps, | 517 int num_steps, |
| 515 GestureEventConsumeDelegate* delegate) { | 518 GestureEventConsumeDelegate* delegate) { |
| 516 float x = x_start; | 519 float x = x_start; |
| 517 float y = y_start; | 520 float y = y_start; |
| 518 | 521 |
| 519 for (int i = 0; i < num_steps; i++) { | 522 for (int i = 0; i < num_steps; i++) { |
| 520 x += dx; | 523 x += dx; |
| 521 y += dy; | 524 y += dy; |
| 522 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), touch_id, | 525 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), touch_id, |
| 523 base::TimeDelta::FromMilliseconds(simulated_now_)); | 526 tick_clock_.NowTicks()); |
| 524 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move); | 527 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move); |
| 525 ASSERT_FALSE(details.dispatcher_destroyed); | 528 ASSERT_FALSE(details.dispatcher_destroyed); |
| 526 simulated_now_ += time_step; | 529 tick_clock_.Advance(base::TimeDelta::FromMilliseconds(time_step_ms)); |
| 527 } | 530 } |
| 528 } | 531 } |
| 529 | 532 |
| 530 void SendScrollEvent(ui::EventProcessor* dispatcher, | 533 void SendScrollEvent(ui::EventProcessor* dispatcher, |
| 531 float x, | 534 float x, |
| 532 float y, | 535 float y, |
| 533 int touch_id, | 536 int touch_id, |
| 534 GestureEventConsumeDelegate* delegate) { | 537 GestureEventConsumeDelegate* delegate) { |
| 535 delegate->Reset(); | 538 delegate->Reset(); |
| 536 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(), touch_id, | 539 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(), touch_id, |
| 537 base::TimeDelta::FromMilliseconds(simulated_now_)); | 540 Now()); |
| 538 move.set_location_f(gfx::PointF(x, y)); | 541 move.set_location_f(gfx::PointF(x, y)); |
| 539 move.set_root_location_f(gfx::PointF(x, y)); | 542 move.set_root_location_f(gfx::PointF(x, y)); |
| 540 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move); | 543 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move); |
| 541 ASSERT_FALSE(details.dispatcher_destroyed); | 544 ASSERT_FALSE(details.dispatcher_destroyed); |
| 542 simulated_now_++; | |
| 543 } | 545 } |
| 544 }; | 546 }; |
| 545 | 547 |
| 546 // An event handler to keep track of events. | 548 // An event handler to keep track of events. |
| 547 class TestEventHandler : public ui::EventHandler { | 549 class TestEventHandler : public ui::EventHandler { |
| 548 public: | 550 public: |
| 549 TestEventHandler() | 551 TestEventHandler() |
| 550 : touch_released_count_(0), | 552 : touch_released_count_(0), |
| 551 touch_pressed_count_(0), | 553 touch_pressed_count_(0), |
| 552 touch_moved_count_(0) {} | 554 touch_moved_count_(0) {} |
| (...skipping 3886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4439 EXPECT_FALSE(queued_delegate2->long_press()); | 4441 EXPECT_FALSE(queued_delegate2->long_press()); |
| 4440 | 4442 |
| 4441 queued_delegate->Reset(); | 4443 queued_delegate->Reset(); |
| 4442 queued_delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS); | 4444 queued_delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS); |
| 4443 EXPECT_TRUE(queued_delegate->show_press()); | 4445 EXPECT_TRUE(queued_delegate->show_press()); |
| 4444 EXPECT_FALSE(queued_delegate->tap_down()); | 4446 EXPECT_FALSE(queued_delegate->tap_down()); |
| 4445 } | 4447 } |
| 4446 | 4448 |
| 4447 } // namespace test | 4449 } // namespace test |
| 4448 } // namespace aura | 4450 } // namespace aura |
| OLD | NEW |