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 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); | 1092 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); |
1101 generator_->Dispatch(&second_touch_release); | 1093 generator_->Dispatch(&second_touch_release); |
1102 captured_events = GetCapturedLocatedEvents(); | 1094 captured_events = GetCapturedLocatedEvents(); |
1103 ASSERT_EQ(captured_events.size(), 0u); | 1095 ASSERT_EQ(captured_events.size(), 0u); |
1104 EXPECT_TRUE(IsInNoFingersDownState()); | 1096 EXPECT_TRUE(IsInNoFingersDownState()); |
1105 } | 1097 } |
1106 | 1098 |
1107 // Placing three fingers should start passthrough, and all fingers should | 1099 // Placing three fingers should start passthrough, and all fingers should |
1108 // continue to be passed through until the last one is released. | 1100 // continue to be passed through until the last one is released. |
1109 TEST_F(TouchExplorationTest, Passthrough) { | 1101 TEST_F(TouchExplorationTest, Passthrough) { |
1110 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 1102 SwitchTouchExplorationMode(true); |
| 1103 std::vector<ui::LocatedEvent*> captured_events; |
1111 | 1104 |
1112 gfx::Point first_touch_location = gfx::Point(11,12); | 1105 gfx::Point first_touch_location = gfx::Point(11,12); |
| 1106 ui::TouchEvent first_touch_press( |
| 1107 ui::ET_TOUCH_PRESSED, first_touch_location, 0, Now()); |
| 1108 generator_->Dispatch(&first_touch_press); |
| 1109 |
1113 gfx::Point second_touch_location = gfx::Point(21, 22); | 1110 gfx::Point second_touch_location = gfx::Point(21, 22); |
1114 EnterTwoToOne(first_touch_location, second_touch_location); | 1111 ui::TouchEvent second_touch_press( |
| 1112 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); |
| 1113 generator_->Dispatch(&second_touch_press); |
| 1114 |
1115 captured_events = GetCapturedLocatedEvents(); | 1115 captured_events = GetCapturedLocatedEvents(); |
1116 ASSERT_EQ(captured_events.size(), 1u); | 1116 ASSERT_EQ(captured_events.size(), 1u); |
1117 | 1117 |
1118 gfx::Point third_touch_location = gfx::Point(31, 32); | 1118 gfx::Point third_touch_location = gfx::Point(31, 32); |
1119 ui::TouchEvent third_touch_press( | 1119 ui::TouchEvent third_touch_press( |
1120 ui::ET_TOUCH_PRESSED, third_touch_location, 2, Now()); | 1120 ui::ET_TOUCH_PRESSED, third_touch_location, 2, Now()); |
1121 generator_->Dispatch(&third_touch_press); | 1121 generator_->Dispatch(&third_touch_press); |
1122 captured_events = GetCapturedLocatedEvents(); | 1122 captured_events = GetCapturedLocatedEvents(); |
1123 // Now all fingers are registered as pressed. | 1123 // Now all fingers are registered as pressed. |
1124 ASSERT_EQ(captured_events.size(), 3u); | 1124 ASSERT_EQ(3u, captured_events.size()); |
1125 ClearCapturedEvents(); | 1125 ClearCapturedEvents(); |
1126 | 1126 |
1127 // All fingers should be passed through. | 1127 // All fingers should be passed through. |
1128 first_touch_location = gfx::Point(13, 14); | 1128 first_touch_location = gfx::Point(13, 14); |
1129 second_touch_location = gfx::Point(23, 24); | 1129 second_touch_location = gfx::Point(23, 24); |
1130 third_touch_location = gfx::Point(33, 34); | 1130 third_touch_location = gfx::Point(33, 34); |
1131 ui::TouchEvent first_touch_first_move( | 1131 ui::TouchEvent first_touch_first_move( |
1132 ui::ET_TOUCH_MOVED, first_touch_location, 0, Now()); | 1132 ui::ET_TOUCH_MOVED, first_touch_location, 0, Now()); |
1133 ui::TouchEvent second_touch_first_move( | 1133 ui::TouchEvent second_touch_first_move( |
1134 ui::ET_TOUCH_MOVED, second_touch_location, 1, Now()); | 1134 ui::ET_TOUCH_MOVED, second_touch_location, 1, Now()); |
1135 ui::TouchEvent third_touch_first_move( | 1135 ui::TouchEvent third_touch_first_move( |
1136 ui::ET_TOUCH_MOVED, third_touch_location, 2, Now()); | 1136 ui::ET_TOUCH_MOVED, third_touch_location, 2, Now()); |
1137 generator_->Dispatch(&first_touch_first_move); | 1137 generator_->Dispatch(&first_touch_first_move); |
1138 generator_->Dispatch(&second_touch_first_move); | 1138 generator_->Dispatch(&second_touch_first_move); |
1139 generator_->Dispatch(&third_touch_first_move); | 1139 generator_->Dispatch(&third_touch_first_move); |
1140 captured_events = GetCapturedLocatedEvents(); | 1140 captured_events = GetCapturedLocatedEvents(); |
1141 ASSERT_EQ(captured_events.size(), 3u); | 1141 ASSERT_EQ(3u, captured_events.size()); |
1142 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[0]->type()); | 1142 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[0]->type()); |
1143 EXPECT_EQ(first_touch_location, captured_events[0]->location()); | 1143 EXPECT_EQ(first_touch_location, captured_events[0]->location()); |
1144 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[1]->type()); | 1144 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[1]->type()); |
1145 EXPECT_EQ(second_touch_location, captured_events[1]->location()); | 1145 EXPECT_EQ(second_touch_location, captured_events[1]->location()); |
1146 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[2]->type()); | 1146 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[2]->type()); |
1147 EXPECT_EQ(third_touch_location, captured_events[2]->location()); | 1147 EXPECT_EQ(third_touch_location, captured_events[2]->location()); |
1148 ClearCapturedEvents(); | 1148 ClearCapturedEvents(); |
1149 | 1149 |
1150 // When we release the third finger, the other fingers should still be | 1150 // When we release the third finger, the other fingers should still be |
1151 // passed through. | 1151 // passed through. |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 EXPECT_FALSE(IsInSlideGestureState()); | 1634 EXPECT_FALSE(IsInSlideGestureState()); |
1635 EXPECT_FALSE(IsInTouchToMouseMode()); | 1635 EXPECT_FALSE(IsInTouchToMouseMode()); |
1636 | 1636 |
1637 AdvanceSimulatedTimePastTapDelay(); | 1637 AdvanceSimulatedTimePastTapDelay(); |
1638 EXPECT_FALSE(IsInGestureInProgressState()); | 1638 EXPECT_FALSE(IsInGestureInProgressState()); |
1639 EXPECT_FALSE(IsInSlideGestureState()); | 1639 EXPECT_FALSE(IsInSlideGestureState()); |
1640 EXPECT_TRUE(IsInTouchToMouseMode()); | 1640 EXPECT_TRUE(IsInTouchToMouseMode()); |
1641 } | 1641 } |
1642 | 1642 |
1643 } // namespace ui | 1643 } // namespace ui |
OLD | NEW |