| 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/accessibility_delegate.h" | 7 #include "ash/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/test/simple_test_tick_clock.h" | 10 #include "base/test/simple_test_tick_clock.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 ui::GestureDetector::Config gesture_detector_config_; | 70 ui::GestureDetector::Config gesture_detector_config_; |
| 71 base::SimpleTestTickClock* simulated_clock_; | 71 base::SimpleTestTickClock* simulated_clock_; |
| 72 aura::Window* root_window_; | 72 aura::Window* root_window_; |
| 73 scoped_ptr<ui::test::TestEventHandler> event_handler_; | 73 scoped_ptr<ui::test::TestEventHandler> event_handler_; |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); | 76 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 // This test turns the touch exploration mode on/off and confirms that events | 79 // This test turns the touch exploration mode off and confirms that events |
| 80 // get rewritten when the touch exploration mode is on, and aren't affected | 80 // aren't modified. |
| 81 // after the touch exploration mode is turned off. | 81 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, NoRewritingEventsWhenOff) { |
| 82 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, ToggleOnOff) { | 82 SwitchTouchExplorationMode(false); |
| 83 SwitchTouchExplorationMode(true); | |
| 84 ui::test::EventGenerator generator(root_window_); | 83 ui::test::EventGenerator generator(root_window_); |
| 85 | 84 |
| 86 base::TimeDelta initial_time = Now(); | 85 base::TimeDelta initial_time = Now(); |
| 87 ui::TouchEvent initial_press( | 86 ui::TouchEvent initial_press( |
| 88 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, initial_time); | 87 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, initial_time); |
| 89 generator.Dispatch(&initial_press); | 88 generator.Dispatch(&initial_press); |
| 90 | 89 |
| 91 // Since the touch exploration controller doesn't know if the user is | 90 // Since the touch exploration controller doesn't know if the user is |
| 92 // double-tapping or not, touch exploration is only initiated if the | 91 // double-tapping or not, touch exploration is only initiated if the |
| 93 // 300 ms has elapsed and the finger does not move fast enough to begin | 92 // 300 ms has elapsed and the finger does not move fast enough to begin |
| 94 // gestures. Here, the touch move event is not important as a move, but | 93 // gestures. Here, the touch move event is not important as a move, but |
| 95 // a way to create time advancement. | 94 // a way to create time advancement. |
| 96 ui::TouchEvent touch_time_advance(ui::ET_TOUCH_MOVED, | 95 ui::TouchEvent touch_time_advance(ui::ET_TOUCH_MOVED, |
| 97 gfx::Point(100, 200), | 96 gfx::Point(100, 200), |
| 98 1, | 97 1, |
| 99 initial_time + | 98 initial_time + |
| 100 gesture_detector_config_.double_tap_timeout + | 99 gesture_detector_config_.double_tap_timeout + |
| 101 base::TimeDelta::FromMilliseconds(1)); | 100 base::TimeDelta::FromMilliseconds(1)); |
| 102 generator.Dispatch(&touch_time_advance); | 101 generator.Dispatch(&touch_time_advance); |
| 103 | 102 |
| 104 // Number of mouse events may be greater than 1 because of ET_MOUSE_ENTERED. | 103 // Number of mouse events may be greater than 1 because of ET_MOUSE_ENTERED. |
| 105 EXPECT_GT(event_handler_->num_mouse_events(), 0); | 104 EXPECT_EQ(0, event_handler_->num_mouse_events()); |
| 106 EXPECT_EQ(0, event_handler_->num_touch_events()); | 105 EXPECT_EQ(2, event_handler_->num_touch_events()); |
| 107 event_handler_->Reset(); | 106 event_handler_->Reset(); |
| 108 | 107 |
| 109 SwitchTouchExplorationMode(false); | |
| 110 generator.MoveTouchId(gfx::Point(11, 12), 1); | 108 generator.MoveTouchId(gfx::Point(11, 12), 1); |
| 111 EXPECT_EQ(0, event_handler_->num_mouse_events()); | 109 EXPECT_EQ(0, event_handler_->num_mouse_events()); |
| 112 EXPECT_EQ(1, event_handler_->num_touch_events()); | 110 EXPECT_EQ(1, event_handler_->num_touch_events()); |
| 113 event_handler_->Reset(); | 111 event_handler_->Reset(); |
| 114 | 112 |
| 115 SwitchTouchExplorationMode(true); | |
| 116 initial_time = Now(); | 113 initial_time = Now(); |
| 117 ui::TouchEvent second_initial_press( | 114 ui::TouchEvent second_initial_press( |
| 118 ui::ET_TOUCH_PRESSED, gfx::Point(500, 600), 2, initial_time); | 115 ui::ET_TOUCH_PRESSED, gfx::Point(500, 600), 2, initial_time); |
| 119 generator.Dispatch(&second_initial_press); | 116 generator.Dispatch(&second_initial_press); |
| 120 ui::TouchEvent second_touch_time_advance( | 117 ui::TouchEvent second_touch_time_advance( |
| 121 ui::ET_TOUCH_MOVED, | 118 ui::ET_TOUCH_MOVED, |
| 122 gfx::Point(500, 600), | 119 gfx::Point(500, 600), |
| 123 2, | 120 2, |
| 124 initial_time + gesture_detector_config_.double_tap_timeout + | 121 initial_time + gesture_detector_config_.double_tap_timeout + |
| 125 base::TimeDelta::FromMilliseconds(1)); | 122 base::TimeDelta::FromMilliseconds(1)); |
| 126 generator.Dispatch(&second_touch_time_advance); | 123 generator.Dispatch(&second_touch_time_advance); |
| 124 EXPECT_EQ(0, event_handler_->num_mouse_events()); |
| 125 EXPECT_EQ(2, event_handler_->num_touch_events()); |
| 126 } |
| 127 |
| 128 // This test turns the touch exploration mode on and confirms that events get |
| 129 // rewritten. |
| 130 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, RewritesEventsWhenOn) { |
| 131 SwitchTouchExplorationMode(true); |
| 132 ui::test::EventGenerator generator(root_window_); |
| 133 |
| 134 base::TimeDelta initial_time = Now(); |
| 135 ui::TouchEvent initial_press( |
| 136 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, initial_time); |
| 137 generator.Dispatch(&initial_press); |
| 138 |
| 139 // Since the touch exploration controller doesn't know if the user is |
| 140 // double-tapping or not, touch exploration is only initiated if the |
| 141 // 300 ms has elapsed and the finger does not move fast enough to begin |
| 142 // gestures. Here, the touch move event is not important as a move, but |
| 143 // a way to create time advancement. |
| 144 ui::TouchEvent touch_time_advance(ui::ET_TOUCH_MOVED, |
| 145 gfx::Point(100, 200), |
| 146 1, |
| 147 initial_time + |
| 148 gesture_detector_config_.double_tap_timeout + |
| 149 base::TimeDelta::FromMilliseconds(1)); |
| 150 generator.Dispatch(&touch_time_advance); |
| 151 |
| 152 // Number of mouse events may be greater than 1 because of ET_MOUSE_ENTERED. |
| 153 EXPECT_GT(event_handler_->num_mouse_events(), 0); |
| 154 EXPECT_EQ(0, event_handler_->num_touch_events()); |
| 155 event_handler_->Reset(); |
| 156 |
| 157 initial_time = Now(); |
| 158 ui::TouchEvent second_initial_press( |
| 159 ui::ET_TOUCH_PRESSED, gfx::Point(500, 600), 2, initial_time); |
| 160 generator.Dispatch(&second_initial_press); |
| 161 ui::TouchEvent second_touch_time_advance( |
| 162 ui::ET_TOUCH_MOVED, |
| 163 gfx::Point(500, 600), |
| 164 2, |
| 165 initial_time + gesture_detector_config_.double_tap_timeout + |
| 166 base::TimeDelta::FromMilliseconds(1)); |
| 167 generator.Dispatch(&second_touch_time_advance); |
| 127 EXPECT_GT(event_handler_->num_mouse_events(), 0); | 168 EXPECT_GT(event_handler_->num_mouse_events(), 0); |
| 128 EXPECT_EQ(0, event_handler_->num_touch_events()); | 169 EXPECT_EQ(1, event_handler_->num_touch_events()); |
| 129 } | 170 } |
| 130 | 171 |
| 131 // This test makes sure that after the user clicks with split tap, | 172 // This test makes sure that after the user clicks with split tap, |
| 132 // they continue to touch exploration mode if the original touch exploration | 173 // they continue to touch exploration mode if the original touch exploration |
| 133 // finger is still on the screen. | 174 // finger is still on the screen. |
| 134 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, SplitTapExplore) { | 175 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, SplitTapExplore) { |
| 135 SwitchTouchExplorationMode(true); | 176 SwitchTouchExplorationMode(true); |
| 136 ui::test::EventGenerator generator(root_window_); | 177 ui::test::EventGenerator generator(root_window_); |
| 137 aura::client::CursorClient* cursor_client = | 178 aura::client::CursorClient* cursor_client = |
| 138 aura::client::GetCursorClient(root_window_); | 179 aura::client::GetCursorClient(root_window_); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 221 |
| 181 // Continuing to move the touch exploration finger should send more mouse | 222 // Continuing to move the touch exploration finger should send more mouse |
| 182 // events. | 223 // events. |
| 183 generator.MoveTouchId(gfx::Point(509, 609), 1); | 224 generator.MoveTouchId(gfx::Point(509, 609), 1); |
| 184 EXPECT_EQ(0, event_handler_->num_touch_events()); | 225 EXPECT_EQ(0, event_handler_->num_touch_events()); |
| 185 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); | 226 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); |
| 186 EXPECT_FALSE(cursor_client->IsCursorVisible()); | 227 EXPECT_FALSE(cursor_client->IsCursorVisible()); |
| 187 } | 228 } |
| 188 | 229 |
| 189 } // namespace ui | 230 } // namespace ui |
| OLD | NEW |