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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 | 74 |
75 class MockTouchExplorationControllerDelegate | 75 class MockTouchExplorationControllerDelegate |
76 : public ui::TouchExplorationControllerDelegate { | 76 : public ui::TouchExplorationControllerDelegate { |
77 public: | 77 public: |
78 virtual void PlayVolumeAdjustSound() OVERRIDE { | 78 virtual void PlayVolumeAdjustSound() OVERRIDE { |
79 ++num_times_adjust_sound_played_; | 79 ++num_times_adjust_sound_played_; |
80 } | 80 } |
81 virtual void SetOutputLevel(int volume) OVERRIDE { | 81 virtual void SetOutputLevel(int volume) OVERRIDE { |
82 volume_changes_.push_back(volume); | 82 volume_changes_.push_back(volume); |
83 } | 83 } |
84 virtual void PlayCornerPassthroughEarcon() OVERRIDE { | |
85 } | |
84 | 86 |
85 const std::vector<float> VolumeChanges() { return volume_changes_; } | 87 const std::vector<float> VolumeChanges() { return volume_changes_; } |
86 const size_t NumAdjustSounds() { return num_times_adjust_sound_played_; } | 88 const size_t NumAdjustSounds() { return num_times_adjust_sound_played_; } |
87 | 89 |
88 private: | 90 private: |
89 std::vector<float> volume_changes_; | 91 std::vector<float> volume_changes_; |
90 size_t num_times_adjust_sound_played_ = 0; | 92 size_t num_times_adjust_sound_played_ = 0; |
91 }; | 93 }; |
92 | 94 |
93 } // namespace | 95 } // namespace |
94 | 96 |
95 class TouchExplorationControllerTestApi { | 97 class TouchExplorationControllerTestApi { |
96 public: | 98 public: |
97 TouchExplorationControllerTestApi( | 99 TouchExplorationControllerTestApi( |
98 TouchExplorationController* touch_exploration_controller) { | 100 TouchExplorationController* touch_exploration_controller) { |
99 touch_exploration_controller_.reset(touch_exploration_controller); | 101 touch_exploration_controller_.reset(touch_exploration_controller); |
100 } | 102 } |
101 | 103 |
102 void CallTapTimerNowForTesting() { | 104 void CallTapTimerNowForTesting() { |
103 DCHECK(touch_exploration_controller_->tap_timer_.IsRunning()); | 105 DCHECK(touch_exploration_controller_->tap_timer_.IsRunning()); |
104 touch_exploration_controller_->tap_timer_.Stop(); | 106 touch_exploration_controller_->tap_timer_.Stop(); |
105 touch_exploration_controller_->OnTapTimerFired(); | 107 touch_exploration_controller_->OnTapTimerFired(); |
106 } | 108 } |
107 | 109 |
110 void CallLongPressTimerNowForTesting() { | |
111 DCHECK(touch_exploration_controller_->long_press_timer_.IsRunning()); | |
112 touch_exploration_controller_->long_press_timer_.Stop(); | |
113 touch_exploration_controller_->OnLongPressTimerFired(); | |
114 } | |
115 | |
108 void CallTapTimerNowIfRunningForTesting() { | 116 void CallTapTimerNowIfRunningForTesting() { |
109 if (touch_exploration_controller_->tap_timer_.IsRunning()) { | 117 if (touch_exploration_controller_->tap_timer_.IsRunning()) { |
110 touch_exploration_controller_->tap_timer_.Stop(); | 118 touch_exploration_controller_->tap_timer_.Stop(); |
111 touch_exploration_controller_->OnTapTimerFired(); | 119 touch_exploration_controller_->OnTapTimerFired(); |
112 } | 120 } |
113 } | 121 } |
114 | 122 |
115 void SetEventHandlerForTesting( | 123 void SetEventHandlerForTesting( |
116 ui::EventHandler* event_handler_for_testing) { | 124 ui::EventHandler* event_handler_for_testing) { |
117 touch_exploration_controller_->event_handler_for_testing_ = | 125 touch_exploration_controller_->event_handler_for_testing_ = |
118 event_handler_for_testing; | 126 event_handler_for_testing; |
119 } | 127 } |
120 | 128 |
121 bool IsInNoFingersDownStateForTesting() const { | 129 bool IsInNoFingersDownStateForTesting() const { |
122 return touch_exploration_controller_->state_ == | 130 return touch_exploration_controller_->state_ == |
123 touch_exploration_controller_->NO_FINGERS_DOWN; | 131 touch_exploration_controller_->NO_FINGERS_DOWN; |
124 } | 132 } |
125 | 133 |
126 bool IsInGestureInProgressStateForTesting() const { | 134 bool IsInGestureInProgressStateForTesting() const { |
127 return touch_exploration_controller_->state_ == | 135 return touch_exploration_controller_->state_ == |
128 touch_exploration_controller_->GESTURE_IN_PROGRESS; | 136 touch_exploration_controller_->GESTURE_IN_PROGRESS; |
129 } | 137 } |
130 | 138 |
131 bool IsInSlideGestureStateForTesting() const { | 139 bool IsInSlideGestureStateForTesting() const { |
132 return touch_exploration_controller_->state_ == | 140 return touch_exploration_controller_->state_ == |
133 touch_exploration_controller_->SLIDE_GESTURE; | 141 touch_exploration_controller_->SLIDE_GESTURE; |
134 } | 142 } |
135 | 143 |
144 bool IsInCornerPassthroughStateForTesting() const { | |
145 return touch_exploration_controller_->state_ == | |
146 touch_exploration_controller_->CORNER_PASSTHROUGH; | |
147 } | |
148 | |
136 gfx::Rect BoundsOfRootWindowInDIPForTesting() const { | 149 gfx::Rect BoundsOfRootWindowInDIPForTesting() const { |
137 return touch_exploration_controller_->root_window_->GetBoundsInScreen(); | 150 return touch_exploration_controller_->root_window_->GetBoundsInScreen(); |
138 } | 151 } |
139 | 152 |
140 // VLOGs should be suppressed in tests that generate a lot of logs, | 153 // VLOGs should be suppressed in tests that generate a lot of logs, |
141 // for example permutations of nine touch events. | 154 // for example permutations of nine touch events. |
142 void SuppressVLOGsForTesting(bool suppress) { | 155 void SuppressVLOGsForTesting(bool suppress) { |
143 touch_exploration_controller_->VLOG_on_ = !suppress; | 156 touch_exploration_controller_->VLOG_on_ = !suppress; |
144 } | 157 } |
145 | 158 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 | 240 |
228 void ClearCapturedEvents() { | 241 void ClearCapturedEvents() { |
229 event_capturer_.Reset(); | 242 event_capturer_.Reset(); |
230 } | 243 } |
231 | 244 |
232 void AdvanceSimulatedTimePastTapDelay() { | 245 void AdvanceSimulatedTimePastTapDelay() { |
233 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); | 246 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
234 touch_exploration_controller_->CallTapTimerNowForTesting(); | 247 touch_exploration_controller_->CallTapTimerNowForTesting(); |
235 } | 248 } |
236 | 249 |
250 void AdvanceSimulatedTimePastLongPressDelay() { | |
251 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); | |
252 touch_exploration_controller_->CallLongPressTimerNowForTesting(); | |
253 } | |
254 | |
237 void AdvanceSimulatedTimePastPotentialTapDelay() { | 255 void AdvanceSimulatedTimePastPotentialTapDelay() { |
238 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); | 256 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
239 touch_exploration_controller_->CallTapTimerNowIfRunningForTesting(); | 257 touch_exploration_controller_->CallTapTimerNowIfRunningForTesting(); |
240 } | 258 } |
241 | 259 |
242 void SuppressVLOGs(bool suppress) { | 260 void SuppressVLOGs(bool suppress) { |
243 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); | 261 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); |
244 } | 262 } |
245 | 263 |
246 void SwitchTouchExplorationMode(bool on) { | 264 void SwitchTouchExplorationMode(bool on) { |
(...skipping 21 matching lines...) Expand all Loading... | |
268 gfx::Point second_touch_location) { | 286 gfx::Point second_touch_location) { |
269 SwitchTouchExplorationMode(true); | 287 SwitchTouchExplorationMode(true); |
270 ui::TouchEvent first_touch_press( | 288 ui::TouchEvent first_touch_press( |
271 ui::ET_TOUCH_PRESSED, first_touch_location, 0, Now()); | 289 ui::ET_TOUCH_PRESSED, first_touch_location, 0, Now()); |
272 generator_->Dispatch(&first_touch_press); | 290 generator_->Dispatch(&first_touch_press); |
273 ui::TouchEvent second_touch_press( | 291 ui::TouchEvent second_touch_press( |
274 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); | 292 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); |
275 generator_->Dispatch(&second_touch_press); | 293 generator_->Dispatch(&second_touch_press); |
276 } | 294 } |
277 | 295 |
296 // Checks that Corner Passthrough is working. Assumes that corner is the | |
297 // bottom | |
aboxhall
2014/07/28 16:00:38
nit: comment formatting
lisayin
2014/07/28 16:28:54
Done.
| |
298 // left corner or the bottom right corner. | |
299 void AssertCornerPassthroughWorking(gfx::Point corner, | |
300 gfx::Point passthrough) { | |
aboxhall
2014/07/28 16:00:38
|passthrough| seems to be identical both times thi
lisayin
2014/07/28 16:28:54
Done.
| |
301 ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, corner, 0, Now()); | |
302 generator_->Dispatch(&first_press); | |
303 | |
304 AdvanceSimulatedTimePastLongPressDelay(); | |
305 EXPECT_FALSE(IsInGestureInProgressState()); | |
306 EXPECT_FALSE(IsInSlideGestureState()); | |
307 EXPECT_FALSE(IsInTouchToMouseMode()); | |
308 EXPECT_TRUE(IsInCornerPassthroughState()); | |
309 | |
310 // The following events should be passed through. | |
311 ui::TouchEvent passthrough_press( | |
312 ui::ET_TOUCH_PRESSED, passthrough, 1, Now()); | |
313 generator_->Dispatch(&passthrough_press); | |
314 generator_->ReleaseTouchId(1); | |
315 generator_->PressTouchId(1); | |
316 EXPECT_FALSE(IsInGestureInProgressState()); | |
317 EXPECT_FALSE(IsInSlideGestureState()); | |
318 EXPECT_TRUE(IsInCornerPassthroughState()); | |
319 | |
320 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | |
321 ASSERT_EQ(3U, captured_events.size()); | |
322 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | |
323 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); | |
324 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[2]->type()); | |
325 generator_->ReleaseTouchId(1); | |
326 ClearCapturedEvents(); | |
327 | |
328 generator_->ReleaseTouchId(0); | |
329 captured_events = GetCapturedLocatedEvents(); | |
330 ASSERT_EQ(0U, captured_events.size()); | |
331 EXPECT_FALSE(IsInTouchToMouseMode()); | |
332 EXPECT_FALSE(IsInCornerPassthroughState()); | |
333 ClearCapturedEvents(); | |
334 } | |
335 | |
278 bool IsInTouchToMouseMode() { | 336 bool IsInTouchToMouseMode() { |
279 aura::client::CursorClient* cursor_client = | 337 aura::client::CursorClient* cursor_client = |
280 aura::client::GetCursorClient(root_window()); | 338 aura::client::GetCursorClient(root_window()); |
281 return cursor_client && | 339 return cursor_client && cursor_client->IsMouseEventsEnabled() && |
282 cursor_client->IsMouseEventsEnabled() && | |
283 !cursor_client->IsCursorVisible(); | 340 !cursor_client->IsCursorVisible(); |
284 } | 341 } |
285 | 342 |
286 bool IsInNoFingersDownState() { | 343 bool IsInNoFingersDownState() { |
287 return touch_exploration_controller_->IsInNoFingersDownStateForTesting(); | 344 return touch_exploration_controller_->IsInNoFingersDownStateForTesting(); |
288 } | 345 } |
289 | 346 |
290 bool IsInGestureInProgressState() { | 347 bool IsInGestureInProgressState() { |
291 return touch_exploration_controller_ | 348 return touch_exploration_controller_ |
292 ->IsInGestureInProgressStateForTesting(); | 349 ->IsInGestureInProgressStateForTesting(); |
293 } | 350 } |
294 | 351 |
295 bool IsInSlideGestureState() { | 352 bool IsInSlideGestureState() { |
296 return touch_exploration_controller_->IsInSlideGestureStateForTesting(); | 353 return touch_exploration_controller_->IsInSlideGestureStateForTesting(); |
297 } | 354 } |
298 | 355 |
356 bool IsInCornerPassthroughState() { | |
357 return touch_exploration_controller_ | |
358 ->IsInCornerPassthroughStateForTesting(); | |
359 } | |
360 | |
299 gfx::Rect BoundsOfRootWindowInDIP() { | 361 gfx::Rect BoundsOfRootWindowInDIP() { |
300 return touch_exploration_controller_->BoundsOfRootWindowInDIPForTesting(); | 362 return touch_exploration_controller_->BoundsOfRootWindowInDIPForTesting(); |
301 } | 363 } |
302 | 364 |
303 float GetMaxDistanceFromEdge() const{ | 365 float GetMaxDistanceFromEdge() const { |
304 return touch_exploration_controller_->GetMaxDistanceFromEdge(); | 366 return touch_exploration_controller_->GetMaxDistanceFromEdge(); |
305 } | 367 } |
306 | 368 |
307 float GetSlopDistanceFromEdge() const{ | 369 float GetSlopDistanceFromEdge() const{ |
308 return touch_exploration_controller_->GetSlopDistanceFromEdge(); | 370 return touch_exploration_controller_->GetSlopDistanceFromEdge(); |
309 } | 371 } |
310 | 372 |
311 base::TimeDelta Now() { | 373 base::TimeDelta Now() { |
312 // This is the same as what EventTimeForNow() does, but here we do it | 374 // This is the same as what EventTimeForNow() does, but here we do it |
313 // with our simulated clock. | 375 // with our simulated clock. |
(...skipping 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1627 EXPECT_FALSE(IsInGestureInProgressState()); | 1689 EXPECT_FALSE(IsInGestureInProgressState()); |
1628 EXPECT_FALSE(IsInSlideGestureState()); | 1690 EXPECT_FALSE(IsInSlideGestureState()); |
1629 EXPECT_FALSE(IsInTouchToMouseMode()); | 1691 EXPECT_FALSE(IsInTouchToMouseMode()); |
1630 | 1692 |
1631 AdvanceSimulatedTimePastTapDelay(); | 1693 AdvanceSimulatedTimePastTapDelay(); |
1632 EXPECT_FALSE(IsInGestureInProgressState()); | 1694 EXPECT_FALSE(IsInGestureInProgressState()); |
1633 EXPECT_FALSE(IsInSlideGestureState()); | 1695 EXPECT_FALSE(IsInSlideGestureState()); |
1634 EXPECT_TRUE(IsInTouchToMouseMode()); | 1696 EXPECT_TRUE(IsInTouchToMouseMode()); |
1635 } | 1697 } |
1636 | 1698 |
1699 // Corner passthrough should turn on if the user first holds down on either the | |
1700 // right or left corner past a delay and then places a finger anywhere else on | |
1701 // the screen. | |
1702 TEST_F(TouchExplorationTest, ActivateLeftCornerPassthrough) { | |
1703 SwitchTouchExplorationMode(true); | |
1704 | |
1705 gfx::Rect window = BoundsOfRootWindowInDIP(); | |
1706 gfx::Point left_corner(10, window.bottom() - GetMaxDistanceFromEdge() / 2); | |
1707 gfx::Point passthrough(window.right() / 2, window.bottom() / 2); | |
1708 AssertCornerPassthroughWorking(left_corner, passthrough); | |
1709 } | |
1710 | |
1711 TEST_F(TouchExplorationTest, ActivateRightCornerPassthrough) { | |
1712 SwitchTouchExplorationMode(true); | |
1713 | |
1714 gfx::Rect window = BoundsOfRootWindowInDIP(); | |
1715 gfx::Point right_corner(window.right() - GetMaxDistanceFromEdge() / 2, | |
1716 window.bottom() - GetMaxDistanceFromEdge() / 2); | |
1717 gfx::Point passthrough(window.right() / 2, window.bottom() / 2); | |
1718 AssertCornerPassthroughWorking(right_corner, passthrough); | |
1719 } | |
1720 | |
1637 } // namespace ui | 1721 } // namespace ui |
OLD | NEW |