OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/chromeos/touch_exploration_controller.h" | 5 #include "ui/chromeos/touch_exploration_controller.h" |
6 | 6 |
7 #include "base/test/simple_test_tick_clock.h" | 7 #include "base/test/simple_test_tick_clock.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "ui/aura/client/cursor_client.h" | 9 #include "ui/aura/client/cursor_client.h" |
10 #include "ui/aura/test/aura_test_base.h" | 10 #include "ui/aura/test/aura_test_base.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 touch_exploration_controller_->OnTapTimerFired(); | 105 touch_exploration_controller_->OnTapTimerFired(); |
106 } | 106 } |
107 | 107 |
108 void CallTapTimerNowIfRunningForTesting() { | 108 void CallTapTimerNowIfRunningForTesting() { |
109 if (touch_exploration_controller_->tap_timer_.IsRunning()) { | 109 if (touch_exploration_controller_->tap_timer_.IsRunning()) { |
110 touch_exploration_controller_->tap_timer_.Stop(); | 110 touch_exploration_controller_->tap_timer_.Stop(); |
111 touch_exploration_controller_->OnTapTimerFired(); | 111 touch_exploration_controller_->OnTapTimerFired(); |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 void SetEventHandlerForTesting( | |
116 ui::EventHandler* event_handler_for_testing) { | |
117 touch_exploration_controller_->event_handler_for_testing_ = | |
118 event_handler_for_testing; | |
119 } | |
120 | |
121 bool IsInNoFingersDownStateForTesting() const { | 115 bool IsInNoFingersDownStateForTesting() const { |
122 return touch_exploration_controller_->state_ == | 116 return touch_exploration_controller_->state_ == |
123 touch_exploration_controller_->NO_FINGERS_DOWN; | 117 touch_exploration_controller_->NO_FINGERS_DOWN; |
124 } | 118 } |
125 | 119 |
126 bool IsInGestureInProgressStateForTesting() const { | 120 bool IsInGestureInProgressStateForTesting() const { |
127 return touch_exploration_controller_->state_ == | 121 return touch_exploration_controller_->state_ == |
128 touch_exploration_controller_->GESTURE_IN_PROGRESS; | 122 touch_exploration_controller_->GESTURE_IN_PROGRESS; |
129 } | 123 } |
130 | 124 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); | 237 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); |
244 } | 238 } |
245 | 239 |
246 void SwitchTouchExplorationMode(bool on) { | 240 void SwitchTouchExplorationMode(bool on) { |
247 if (!on && touch_exploration_controller_.get()) { | 241 if (!on && touch_exploration_controller_.get()) { |
248 touch_exploration_controller_.reset(); | 242 touch_exploration_controller_.reset(); |
249 } else if (on && !touch_exploration_controller_.get()) { | 243 } else if (on && !touch_exploration_controller_.get()) { |
250 touch_exploration_controller_.reset( | 244 touch_exploration_controller_.reset( |
251 new ui::TouchExplorationControllerTestApi( | 245 new ui::TouchExplorationControllerTestApi( |
252 new TouchExplorationController(root_window(), &delegate_))); | 246 new TouchExplorationController(root_window(), &delegate_))); |
253 touch_exploration_controller_->SetEventHandlerForTesting( | |
254 &event_capturer_); | |
255 cursor_client()->ShowCursor(); | 247 cursor_client()->ShowCursor(); |
256 cursor_client()->DisableMouseEvents(); | 248 cursor_client()->DisableMouseEvents(); |
257 } | 249 } |
258 } | 250 } |
259 | 251 |
260 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) { | 252 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) { |
261 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now()); | 253 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now()); |
262 generator_->Dispatch(&touch_press); | 254 generator_->Dispatch(&touch_press); |
263 AdvanceSimulatedTimePastTapDelay(); | 255 AdvanceSimulatedTimePastTapDelay(); |
264 EXPECT_TRUE(IsInTouchToMouseMode()); | 256 EXPECT_TRUE(IsInTouchToMouseMode()); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 EXPECT_FALSE(IsInTouchToMouseMode()); | 420 EXPECT_FALSE(IsInTouchToMouseMode()); |
429 generator_->MoveTouch(gfx::Point(11, 12 + half_slop)); | 421 generator_->MoveTouch(gfx::Point(11, 12 + half_slop)); |
430 EXPECT_FALSE(IsInTouchToMouseMode()); | 422 EXPECT_FALSE(IsInTouchToMouseMode()); |
431 AdvanceSimulatedTimePastTapDelay(); | 423 AdvanceSimulatedTimePastTapDelay(); |
432 generator_->MoveTouch(gfx::Point(11 + slop + 1, 12)); | 424 generator_->MoveTouch(gfx::Point(11 + slop + 1, 12)); |
433 EXPECT_TRUE(IsInTouchToMouseMode()); | 425 EXPECT_TRUE(IsInTouchToMouseMode()); |
434 } | 426 } |
435 | 427 |
436 TEST_F(TouchExplorationTest, OneFingerTap) { | 428 TEST_F(TouchExplorationTest, OneFingerTap) { |
437 SwitchTouchExplorationMode(true); | 429 SwitchTouchExplorationMode(true); |
430 cursor_client()->EnableMouseEvents(); | |
tdresser
2014/07/28 18:31:43
I'm not super clear what's going on here. Is it OK
lisayin
2014/07/28 19:14:54
By default, passing true to SwitchTouchExploration
dmazzoni
2014/07/28 19:28:37
Yes, could we rename that?
| |
438 gfx::Point location(11, 12); | 431 gfx::Point location(11, 12); |
439 generator_->set_current_location(location); | 432 generator_->set_current_location(location); |
440 generator_->PressTouch(); | 433 generator_->PressTouch(); |
441 generator_->ReleaseTouch(); | 434 generator_->ReleaseTouch(); |
442 AdvanceSimulatedTimePastTapDelay(); | 435 AdvanceSimulatedTimePastTapDelay(); |
443 | 436 |
444 std::vector<ui::LocatedEvent*> events = | 437 std::vector<ui::LocatedEvent*> events = |
445 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 438 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
446 ASSERT_EQ(1U, events.size()); | 439 ASSERT_EQ(1U, events.size()); |
447 | 440 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 generator_->ReleaseTouchId(1); | 572 generator_->ReleaseTouchId(1); |
580 AdvanceSimulatedTimePastTapDelay(); | 573 AdvanceSimulatedTimePastTapDelay(); |
581 EXPECT_TRUE(IsInNoFingersDownState()); | 574 EXPECT_TRUE(IsInNoFingersDownState()); |
582 } | 575 } |
583 | 576 |
584 // If a new tap is received after the double-tap timeout has elapsed from | 577 // If a new tap is received after the double-tap timeout has elapsed from |
585 // a previous tap, but before the timer has fired, a mouse move should | 578 // a previous tap, but before the timer has fired, a mouse move should |
586 // still be generated from the old tap. | 579 // still be generated from the old tap. |
587 TEST_F(TouchExplorationTest, TimerFiresLateAfterTap) { | 580 TEST_F(TouchExplorationTest, TimerFiresLateAfterTap) { |
588 SwitchTouchExplorationMode(true); | 581 SwitchTouchExplorationMode(true); |
582 cursor_client()->EnableMouseEvents(); | |
589 | 583 |
590 // Send a tap at location1. | 584 // Send a tap at location1. |
591 gfx::Point location0(11, 12); | 585 gfx::Point location0(11, 12); |
592 generator_->set_current_location(location0); | 586 generator_->set_current_location(location0); |
593 generator_->PressTouch(); | 587 generator_->PressTouch(); |
594 generator_->ReleaseTouch(); | 588 generator_->ReleaseTouch(); |
595 | 589 |
596 // Send a tap at location2, after the double-tap timeout, but before the | 590 // Send a tap at location2, after the double-tap timeout, but before the |
597 // timer fires. | 591 // timer fires. |
598 gfx::Point location1(33, 34); | 592 gfx::Point location1(33, 34); |
(...skipping 12 matching lines...) Expand all Loading... | |
611 EXPECT_EQ(location1, events[1]->location()); | 605 EXPECT_EQ(location1, events[1]->location()); |
612 EXPECT_TRUE(events[1]->flags() & ui::EF_IS_SYNTHESIZED); | 606 EXPECT_TRUE(events[1]->flags() & ui::EF_IS_SYNTHESIZED); |
613 EXPECT_TRUE(events[1]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | 607 EXPECT_TRUE(events[1]->flags() & ui::EF_TOUCH_ACCESSIBILITY); |
614 EXPECT_TRUE(IsInNoFingersDownState()); | 608 EXPECT_TRUE(IsInNoFingersDownState()); |
615 } | 609 } |
616 | 610 |
617 // Double-tapping should send a touch press and release through to the location | 611 // Double-tapping should send a touch press and release through to the location |
618 // of the last successful touch exploration. | 612 // of the last successful touch exploration. |
619 TEST_F(TouchExplorationTest, DoubleTap) { | 613 TEST_F(TouchExplorationTest, DoubleTap) { |
620 SwitchTouchExplorationMode(true); | 614 SwitchTouchExplorationMode(true); |
615 cursor_client()->EnableMouseEvents(); | |
621 | 616 |
622 // Tap at one location, and get a mouse move event. | 617 // Tap at one location, and get a mouse move event. |
623 gfx::Point tap_location(11, 12); | 618 gfx::Point tap_location(11, 12); |
624 generator_->set_current_location(tap_location); | 619 generator_->set_current_location(tap_location); |
625 generator_->PressTouch(); | 620 generator_->PressTouch(); |
626 generator_->ReleaseTouch(); | 621 generator_->ReleaseTouch(); |
627 AdvanceSimulatedTimePastTapDelay(); | 622 AdvanceSimulatedTimePastTapDelay(); |
628 | 623 |
629 std::vector<ui::LocatedEvent*> events = | 624 std::vector<ui::LocatedEvent*> events = |
630 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 625 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
(...skipping 21 matching lines...) Expand all Loading... | |
652 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); | 647 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); |
653 EXPECT_EQ(tap_location, captured_events[1]->location()); | 648 EXPECT_EQ(tap_location, captured_events[1]->location()); |
654 EXPECT_TRUE(IsInNoFingersDownState()); | 649 EXPECT_TRUE(IsInNoFingersDownState()); |
655 } | 650 } |
656 | 651 |
657 // Double-tapping where the user holds their finger down for the second time | 652 // Double-tapping where the user holds their finger down for the second time |
658 // for a longer press should send a touch press and released (right click) | 653 // for a longer press should send a touch press and released (right click) |
659 // to the location of the last successful touch exploration. | 654 // to the location of the last successful touch exploration. |
660 TEST_F(TouchExplorationTest, DoubleTapLongPress) { | 655 TEST_F(TouchExplorationTest, DoubleTapLongPress) { |
661 SwitchTouchExplorationMode(true); | 656 SwitchTouchExplorationMode(true); |
657 cursor_client()->EnableMouseEvents(); | |
662 | 658 |
663 // Tap at one location, and get a mouse move event. | 659 // Tap at one location, and get a mouse move event. |
664 gfx::Point tap_location(11, 12); | 660 gfx::Point tap_location(11, 12); |
665 generator_->set_current_location(tap_location); | 661 generator_->set_current_location(tap_location); |
666 generator_->PressTouch(); | 662 generator_->PressTouch(); |
667 generator_->ReleaseTouch(); | 663 generator_->ReleaseTouch(); |
668 AdvanceSimulatedTimePastTapDelay(); | 664 AdvanceSimulatedTimePastTapDelay(); |
669 | 665 |
670 std::vector<ui::LocatedEvent*> events = | 666 std::vector<ui::LocatedEvent*> events = |
671 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 667 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1100 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); | 1096 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); |
1101 generator_->Dispatch(&second_touch_release); | 1097 generator_->Dispatch(&second_touch_release); |
1102 captured_events = GetCapturedLocatedEvents(); | 1098 captured_events = GetCapturedLocatedEvents(); |
1103 ASSERT_EQ(captured_events.size(), 0u); | 1099 ASSERT_EQ(captured_events.size(), 0u); |
1104 EXPECT_TRUE(IsInNoFingersDownState()); | 1100 EXPECT_TRUE(IsInNoFingersDownState()); |
1105 } | 1101 } |
1106 | 1102 |
1107 // Placing three fingers should start passthrough, and all fingers should | 1103 // Placing three fingers should start passthrough, and all fingers should |
1108 // continue to be passed through until the last one is released. | 1104 // continue to be passed through until the last one is released. |
1109 TEST_F(TouchExplorationTest, Passthrough) { | 1105 TEST_F(TouchExplorationTest, Passthrough) { |
1110 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 1106 SwitchTouchExplorationMode(true); |
1107 std::vector<ui::LocatedEvent*> captured_events; | |
1111 | 1108 |
1112 gfx::Point first_touch_location = gfx::Point(11,12); | 1109 gfx::Point first_touch_location = gfx::Point(11,12); |
1110 ui::TouchEvent first_touch_press( | |
1111 ui::ET_TOUCH_PRESSED, first_touch_location, 0, Now()); | |
1112 generator_->Dispatch(&first_touch_press); | |
1113 | |
1113 gfx::Point second_touch_location = gfx::Point(21, 22); | 1114 gfx::Point second_touch_location = gfx::Point(21, 22); |
1114 EnterTwoToOne(first_touch_location, second_touch_location); | 1115 ui::TouchEvent second_touch_press( |
1116 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); | |
1117 generator_->Dispatch(&second_touch_press); | |
1118 | |
1115 captured_events = GetCapturedLocatedEvents(); | 1119 captured_events = GetCapturedLocatedEvents(); |
1116 ASSERT_EQ(captured_events.size(), 1u); | 1120 ASSERT_EQ(captured_events.size(), 1u); |
1117 | 1121 |
1118 gfx::Point third_touch_location = gfx::Point(31, 32); | 1122 gfx::Point third_touch_location = gfx::Point(31, 32); |
1119 ui::TouchEvent third_touch_press( | 1123 ui::TouchEvent third_touch_press( |
1120 ui::ET_TOUCH_PRESSED, third_touch_location, 2, Now()); | 1124 ui::ET_TOUCH_PRESSED, third_touch_location, 2, Now()); |
1121 generator_->Dispatch(&third_touch_press); | 1125 generator_->Dispatch(&third_touch_press); |
1122 captured_events = GetCapturedLocatedEvents(); | 1126 captured_events = GetCapturedLocatedEvents(); |
1123 // Now all fingers are registered as pressed. | 1127 // Now all fingers are registered as pressed. |
1124 ASSERT_EQ(captured_events.size(), 3u); | 1128 ASSERT_EQ(3u, captured_events.size()); |
1125 ClearCapturedEvents(); | 1129 ClearCapturedEvents(); |
1126 | 1130 |
1127 // All fingers should be passed through. | 1131 // All fingers should be passed through. |
1128 first_touch_location = gfx::Point(13, 14); | 1132 first_touch_location = gfx::Point(13, 14); |
1129 second_touch_location = gfx::Point(23, 24); | 1133 second_touch_location = gfx::Point(23, 24); |
1130 third_touch_location = gfx::Point(33, 34); | 1134 third_touch_location = gfx::Point(33, 34); |
1131 ui::TouchEvent first_touch_first_move( | 1135 ui::TouchEvent first_touch_first_move( |
1132 ui::ET_TOUCH_MOVED, first_touch_location, 0, Now()); | 1136 ui::ET_TOUCH_MOVED, first_touch_location, 0, Now()); |
1133 ui::TouchEvent second_touch_first_move( | 1137 ui::TouchEvent second_touch_first_move( |
1134 ui::ET_TOUCH_MOVED, second_touch_location, 1, Now()); | 1138 ui::ET_TOUCH_MOVED, second_touch_location, 1, Now()); |
1135 ui::TouchEvent third_touch_first_move( | 1139 ui::TouchEvent third_touch_first_move( |
1136 ui::ET_TOUCH_MOVED, third_touch_location, 2, Now()); | 1140 ui::ET_TOUCH_MOVED, third_touch_location, 2, Now()); |
1137 generator_->Dispatch(&first_touch_first_move); | 1141 generator_->Dispatch(&first_touch_first_move); |
1138 generator_->Dispatch(&second_touch_first_move); | 1142 generator_->Dispatch(&second_touch_first_move); |
1139 generator_->Dispatch(&third_touch_first_move); | 1143 generator_->Dispatch(&third_touch_first_move); |
1140 captured_events = GetCapturedLocatedEvents(); | 1144 captured_events = GetCapturedLocatedEvents(); |
1141 ASSERT_EQ(captured_events.size(), 3u); | 1145 ASSERT_EQ(3u, captured_events.size()); |
1142 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[0]->type()); | 1146 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[0]->type()); |
1143 EXPECT_EQ(first_touch_location, captured_events[0]->location()); | 1147 EXPECT_EQ(first_touch_location, captured_events[0]->location()); |
1144 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[1]->type()); | 1148 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[1]->type()); |
1145 EXPECT_EQ(second_touch_location, captured_events[1]->location()); | 1149 EXPECT_EQ(second_touch_location, captured_events[1]->location()); |
1146 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[2]->type()); | 1150 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[2]->type()); |
1147 EXPECT_EQ(third_touch_location, captured_events[2]->location()); | 1151 EXPECT_EQ(third_touch_location, captured_events[2]->location()); |
1148 ClearCapturedEvents(); | 1152 ClearCapturedEvents(); |
1149 | 1153 |
1150 // When we release the third finger, the other fingers should still be | 1154 // When we release the third finger, the other fingers should still be |
1151 // passed through. | 1155 // passed through. |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1634 EXPECT_FALSE(IsInSlideGestureState()); | 1638 EXPECT_FALSE(IsInSlideGestureState()); |
1635 EXPECT_FALSE(IsInTouchToMouseMode()); | 1639 EXPECT_FALSE(IsInTouchToMouseMode()); |
1636 | 1640 |
1637 AdvanceSimulatedTimePastTapDelay(); | 1641 AdvanceSimulatedTimePastTapDelay(); |
1638 EXPECT_FALSE(IsInGestureInProgressState()); | 1642 EXPECT_FALSE(IsInGestureInProgressState()); |
1639 EXPECT_FALSE(IsInSlideGestureState()); | 1643 EXPECT_FALSE(IsInSlideGestureState()); |
1640 EXPECT_TRUE(IsInTouchToMouseMode()); | 1644 EXPECT_TRUE(IsInTouchToMouseMode()); |
1641 } | 1645 } |
1642 | 1646 |
1643 } // namespace ui | 1647 } // namespace ui |
OLD | NEW |