| 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 "ash/common/accessibility_delegate.h" | 7 #include "ash/common/accessibility_delegate.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 root_window_->RemovePreTargetHandler(event_handler_.get()); | 56 root_window_->RemovePreTargetHandler(event_handler_.get()); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void SwitchTouchExplorationMode(bool on) { | 59 void SwitchTouchExplorationMode(bool on) { |
| 60 ash::AccessibilityDelegate* ad = | 60 ash::AccessibilityDelegate* ad = |
| 61 ash::Shell::GetInstance()->accessibility_delegate(); | 61 ash::Shell::GetInstance()->accessibility_delegate(); |
| 62 if (on != ad->IsSpokenFeedbackEnabled()) | 62 if (on != ad->IsSpokenFeedbackEnabled()) |
| 63 ad->ToggleSpokenFeedback(ui::A11Y_NOTIFICATION_NONE); | 63 ad->ToggleSpokenFeedback(ui::A11Y_NOTIFICATION_NONE); |
| 64 } | 64 } |
| 65 | 65 |
| 66 base::TimeDelta Now() { | 66 base::TimeTicks Now() { return simulated_clock_->NowTicks(); } |
| 67 return base::TimeDelta::FromInternalValue( | |
| 68 simulated_clock_->NowTicks().ToInternalValue()); | |
| 69 } | |
| 70 | 67 |
| 71 ui::GestureDetector::Config gesture_detector_config_; | 68 ui::GestureDetector::Config gesture_detector_config_; |
| 72 base::SimpleTestTickClock* simulated_clock_; | 69 base::SimpleTestTickClock* simulated_clock_; |
| 73 aura::Window* root_window_; | 70 aura::Window* root_window_; |
| 74 std::unique_ptr<ui::test::TestEventHandler> event_handler_; | 71 std::unique_ptr<ui::test::TestEventHandler> event_handler_; |
| 75 | 72 |
| 76 private: | 73 private: |
| 77 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); | 74 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); |
| 78 }; | 75 }; |
| 79 | 76 |
| 80 #if defined(OS_CHROMEOS) | 77 #if defined(OS_CHROMEOS) |
| 81 // crbug.com/422943 | 78 // crbug.com/422943 |
| 82 #define MAYBE_NoRewritingEventsWhenOff DISABLED_NoRewritingEventsWhenOff | 79 #define MAYBE_NoRewritingEventsWhenOff DISABLED_NoRewritingEventsWhenOff |
| 83 #else | 80 #else |
| 84 #define MAYBE_NoRewritingEventsWhenOff NoRewritingEventsWhenOff | 81 #define MAYBE_NoRewritingEventsWhenOff NoRewritingEventsWhenOff |
| 85 #endif | 82 #endif |
| 86 | 83 |
| 87 // This test turns the touch exploration mode off and confirms that events | 84 // This test turns the touch exploration mode off and confirms that events |
| 88 // aren't modified. | 85 // aren't modified. |
| 89 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, MAYBE_NoRewritingEventsWhenOff) { | 86 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, MAYBE_NoRewritingEventsWhenOff) { |
| 90 SwitchTouchExplorationMode(false); | 87 SwitchTouchExplorationMode(false); |
| 91 ui::test::EventGenerator generator(root_window_); | 88 ui::test::EventGenerator generator(root_window_); |
| 92 | 89 |
| 93 base::TimeDelta initial_time = Now(); | 90 base::TimeTicks initial_time = Now(); |
| 94 ui::TouchEvent initial_press( | 91 ui::TouchEvent initial_press( |
| 95 ui::ET_TOUCH_PRESSED, gfx::Point(99, 200), 1, initial_time); | 92 ui::ET_TOUCH_PRESSED, gfx::Point(99, 200), 1, initial_time); |
| 96 generator.Dispatch(&initial_press); | 93 generator.Dispatch(&initial_press); |
| 97 | 94 |
| 98 // Since the touch exploration controller doesn't know if the user is | 95 // Since the touch exploration controller doesn't know if the user is |
| 99 // double-tapping or not, touch exploration is only initiated if the | 96 // double-tapping or not, touch exploration is only initiated if the |
| 100 // 300 ms has elapsed and the finger does not move fast enough to begin | 97 // 300 ms has elapsed and the finger does not move fast enough to begin |
| 101 // gestures. Here, the touch move event is not important as a move, but | 98 // gestures. Here, the touch move event is not important as a move, but |
| 102 // a way to create time advancement. | 99 // a way to create time advancement. |
| 103 ui::TouchEvent touch_time_advance(ui::ET_TOUCH_MOVED, | 100 ui::TouchEvent touch_time_advance(ui::ET_TOUCH_MOVED, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 132 EXPECT_EQ(2, event_handler_->num_touch_events()); | 129 EXPECT_EQ(2, event_handler_->num_touch_events()); |
| 133 } | 130 } |
| 134 | 131 |
| 135 // This test turns the touch exploration mode on and confirms that events get | 132 // This test turns the touch exploration mode on and confirms that events get |
| 136 // rewritten. | 133 // rewritten. |
| 137 // Disabling due to failing over 10% of the time. (crbug.com/469119) | 134 // Disabling due to failing over 10% of the time. (crbug.com/469119) |
| 138 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, DISABLED_RewritesEventsWhenOn) { | 135 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, DISABLED_RewritesEventsWhenOn) { |
| 139 SwitchTouchExplorationMode(true); | 136 SwitchTouchExplorationMode(true); |
| 140 ui::test::EventGenerator generator(root_window_); | 137 ui::test::EventGenerator generator(root_window_); |
| 141 | 138 |
| 142 base::TimeDelta initial_time = Now(); | 139 base::TimeTicks initial_time = Now(); |
| 143 ui::TouchEvent initial_press( | 140 ui::TouchEvent initial_press( |
| 144 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, initial_time); | 141 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, initial_time); |
| 145 generator.Dispatch(&initial_press); | 142 generator.Dispatch(&initial_press); |
| 146 | 143 |
| 147 // Since the touch exploration controller doesn't know if the user is | 144 // Since the touch exploration controller doesn't know if the user is |
| 148 // double-tapping or not, touch exploration is only initiated if the | 145 // double-tapping or not, touch exploration is only initiated if the |
| 149 // 300 ms has elapsed and the finger does not move fast enough to begin | 146 // 300 ms has elapsed and the finger does not move fast enough to begin |
| 150 // gestures. Here, the touch move event is not important as a move, but | 147 // gestures. Here, the touch move event is not important as a move, but |
| 151 // a way to create time advancement. | 148 // a way to create time advancement. |
| 152 ui::TouchEvent touch_time_advance(ui::ET_TOUCH_MOVED, | 149 ui::TouchEvent touch_time_advance(ui::ET_TOUCH_MOVED, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 aura::client::CursorClient* cursor_client = | 199 aura::client::CursorClient* cursor_client = |
| 203 aura::client::GetCursorClient(root_window_); | 200 aura::client::GetCursorClient(root_window_); |
| 204 | 201 |
| 205 // Mouse events should show the cursor. | 202 // Mouse events should show the cursor. |
| 206 generator.MoveMouseTo(gfx::Point(30, 31)); | 203 generator.MoveMouseTo(gfx::Point(30, 31)); |
| 207 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); | 204 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); |
| 208 EXPECT_TRUE(cursor_client->IsCursorVisible()); | 205 EXPECT_TRUE(cursor_client->IsCursorVisible()); |
| 209 | 206 |
| 210 // The cursor should be shown immediately after the press, and hidden | 207 // The cursor should be shown immediately after the press, and hidden |
| 211 // after the move. | 208 // after the move. |
| 212 base::TimeDelta initial_time = Now(); | 209 base::TimeTicks initial_time = Now(); |
| 213 ui::TouchEvent initial_press( | 210 ui::TouchEvent initial_press( |
| 214 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, initial_time); | 211 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, initial_time); |
| 215 generator.Dispatch(&initial_press); | 212 generator.Dispatch(&initial_press); |
| 216 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); | 213 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); |
| 217 EXPECT_TRUE(cursor_client->IsCursorVisible()); | 214 EXPECT_TRUE(cursor_client->IsCursorVisible()); |
| 218 | 215 |
| 219 // Initiate touch explore by waiting for the tap timer timeout. Time is | 216 // Initiate touch explore by waiting for the tap timer timeout. Time is |
| 220 // advanced by sending a move event after the timeout period. | 217 // advanced by sending a move event after the timeout period. |
| 221 ui::TouchEvent touch_time_advance( | 218 ui::TouchEvent touch_time_advance( |
| 222 ui::ET_TOUCH_MOVED, | 219 ui::ET_TOUCH_MOVED, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 245 | 242 |
| 246 // Continuing to move the touch exploration finger should send more mouse | 243 // Continuing to move the touch exploration finger should send more mouse |
| 247 // events. | 244 // events. |
| 248 generator.MoveTouchId(gfx::Point(509, 609), 1); | 245 generator.MoveTouchId(gfx::Point(509, 609), 1); |
| 249 EXPECT_EQ(0, event_handler_->num_touch_events()); | 246 EXPECT_EQ(0, event_handler_->num_touch_events()); |
| 250 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); | 247 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); |
| 251 EXPECT_FALSE(cursor_client->IsCursorVisible()); | 248 EXPECT_FALSE(cursor_client->IsCursorVisible()); |
| 252 } | 249 } |
| 253 | 250 |
| 254 } // namespace ui | 251 } // namespace ui |
| OLD | NEW |