| 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" |
| 11 #include "ui/aura/test/event_generator.h" | 11 #include "ui/aura/test/event_generator.h" |
| 12 #include "ui/aura/test/test_cursor_client.h" | 12 #include "ui/aura/test/test_cursor_client.h" |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 15 #include "ui/events/event_utils.h" | 15 #include "ui/events/event_utils.h" |
| 16 #include "ui/events/gestures/gesture_provider_aura.h" | 16 #include "ui/events/gestures/gesture_provider_aura.h" |
| 17 #include "ui/events/test/events_test_utils.h" | 17 #include "ui/events/test/events_test_utils.h" |
| 18 #include "ui/gfx/geometry/point.h" | 18 #include "ui/gfx/geometry/point.h" |
| 19 #include "ui/gl/gl_implementation.h" | 19 #include "ui/gl/gl_implementation.h" |
| 20 #include "ui/gl/gl_surface.h" | 20 #include "ui/gl/gl_surface.h" |
| 21 | 21 |
| 22 namespace ui { | 22 namespace ui { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | |
| 26 // Records all mouse, touch, gesture, and key events. | 25 // Records all mouse, touch, gesture, and key events. |
| 27 class EventCapturer : public ui::EventHandler { | 26 class EventCapturer : public ui::EventHandler { |
| 28 public: | 27 public: |
| 29 EventCapturer() {} | 28 EventCapturer() {} |
| 30 virtual ~EventCapturer() {} | 29 virtual ~EventCapturer() {} |
| 31 | 30 |
| 32 void Reset() { | 31 void Reset() { |
| 33 events_.clear(); | 32 events_.clear(); |
| 34 } | 33 } |
| 35 | 34 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 int Factorial(int n) { | 66 int Factorial(int n) { |
| 68 if (n <= 0) | 67 if (n <= 0) |
| 69 return 0; | 68 return 0; |
| 70 if (n == 1) | 69 if (n == 1) |
| 71 return 1; | 70 return 1; |
| 72 return n * Factorial(n - 1); | 71 return n * Factorial(n - 1); |
| 73 } | 72 } |
| 74 | 73 |
| 75 } // namespace | 74 } // namespace |
| 76 | 75 |
| 77 class TouchExplorationControllerTestApi { | |
| 78 public: | |
| 79 TouchExplorationControllerTestApi( | |
| 80 TouchExplorationController* touch_exploration_controller) | |
| 81 : touch_exploration_controller_(touch_exploration_controller) {} | |
| 82 | |
| 83 void CallTapTimerNowForTesting() { | |
| 84 DCHECK(touch_exploration_controller_->tap_timer_.IsRunning()); | |
| 85 touch_exploration_controller_->tap_timer_.Stop(); | |
| 86 touch_exploration_controller_->OnTapTimerFired(); | |
| 87 } | |
| 88 | |
| 89 void CallTapTimerNowIfRunningForTesting() { | |
| 90 if (touch_exploration_controller_->tap_timer_.IsRunning()) { | |
| 91 touch_exploration_controller_->tap_timer_.Stop(); | |
| 92 touch_exploration_controller_->OnTapTimerFired(); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 void SetEventHandlerForTesting( | |
| 97 ui::EventHandler* event_handler_for_testing) { | |
| 98 touch_exploration_controller_->event_handler_for_testing_ = | |
| 99 event_handler_for_testing; | |
| 100 } | |
| 101 | |
| 102 bool IsInNoFingersDownStateForTesting() const { | |
| 103 return touch_exploration_controller_->state_ == | |
| 104 touch_exploration_controller_->NO_FINGERS_DOWN; | |
| 105 } | |
| 106 | |
| 107 bool IsInGestureInProgressStateForTesting() const { | |
| 108 return touch_exploration_controller_->state_ == | |
| 109 touch_exploration_controller_->GESTURE_IN_PROGRESS; | |
| 110 } | |
| 111 | |
| 112 // VLOGs should be suppressed in tests that generate a lot of logs, | |
| 113 // for example permutations of nine touch events. | |
| 114 void SuppressVLOGsForTesting(bool suppress) { | |
| 115 touch_exploration_controller_->VLOG_on_ = !suppress; | |
| 116 } | |
| 117 | |
| 118 private: | |
| 119 TouchExplorationController* touch_exploration_controller_; | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi); | |
| 122 }; | |
| 123 | |
| 124 class TouchExplorationTest : public aura::test::AuraTestBase { | 76 class TouchExplorationTest : public aura::test::AuraTestBase { |
| 125 public: | 77 public: |
| 126 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { | 78 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { |
| 127 // Tests fail if time is ever 0. | 79 // Tests fail if time is ever 0. |
| 128 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | 80 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); |
| 129 } | 81 } |
| 130 virtual ~TouchExplorationTest() {} | 82 virtual ~TouchExplorationTest() {} |
| 131 | 83 |
| 132 virtual void SetUp() OVERRIDE { | 84 virtual void SetUp() OVERRIDE { |
| 133 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone) | 85 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 156 } |
| 205 | 157 |
| 206 void SuppressVLOGs(bool suppress) { | 158 void SuppressVLOGs(bool suppress) { |
| 207 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); | 159 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); |
| 208 } | 160 } |
| 209 | 161 |
| 210 void SwitchTouchExplorationMode(bool on) { | 162 void SwitchTouchExplorationMode(bool on) { |
| 211 if (!on && touch_exploration_controller_.get()) { | 163 if (!on && touch_exploration_controller_.get()) { |
| 212 touch_exploration_controller_.reset(); | 164 touch_exploration_controller_.reset(); |
| 213 } else if (on && !touch_exploration_controller_.get()) { | 165 } else if (on && !touch_exploration_controller_.get()) { |
| 214 touch_exploration_controller_.reset(new TouchExplorationControllerTestApi( | 166 touch_exploration_controller_.reset( |
| 215 new ui::TouchExplorationController(root_window()))); | 167 new ui::TouchExplorationController(root_window())); |
| 216 touch_exploration_controller_->SetEventHandlerForTesting( | 168 touch_exploration_controller_->SetEventHandlerForTesting( |
| 217 &event_capturer_); | 169 &event_capturer_); |
| 218 cursor_client()->ShowCursor(); | 170 cursor_client()->ShowCursor(); |
| 219 cursor_client()->DisableMouseEvents(); | 171 cursor_client()->DisableMouseEvents(); |
| 220 } | 172 } |
| 221 } | 173 } |
| 222 | 174 |
| 223 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) { | 175 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) { |
| 224 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now()); | 176 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now()); |
| 225 generator_->Dispatch(&touch_press); | 177 generator_->Dispatch(&touch_press); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 simulated_clock_->NowTicks().ToInternalValue()); | 214 simulated_clock_->NowTicks().ToInternalValue()); |
| 263 } | 215 } |
| 264 | 216 |
| 265 scoped_ptr<aura::test::EventGenerator> generator_; | 217 scoped_ptr<aura::test::EventGenerator> generator_; |
| 266 ui::GestureDetector::Config gesture_detector_config_; | 218 ui::GestureDetector::Config gesture_detector_config_; |
| 267 // Owned by |generator_|. | 219 // Owned by |generator_|. |
| 268 base::SimpleTestTickClock* simulated_clock_; | 220 base::SimpleTestTickClock* simulated_clock_; |
| 269 | 221 |
| 270 private: | 222 private: |
| 271 EventCapturer event_capturer_; | 223 EventCapturer event_capturer_; |
| 272 scoped_ptr<TouchExplorationControllerTestApi> | 224 scoped_ptr<ui::TouchExplorationController> touch_exploration_controller_; |
| 273 touch_exploration_controller_; | |
| 274 scoped_ptr<aura::test::TestCursorClient> cursor_client_; | 225 scoped_ptr<aura::test::TestCursorClient> cursor_client_; |
| 275 | 226 |
| 276 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); | 227 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); |
| 277 }; | 228 }; |
| 278 | 229 |
| 279 // Executes a number of assertions to confirm that |e1| and |e2| are touch | 230 // Executes a number of assertions to confirm that |e1| and |e2| are touch |
| 280 // events and are equal to each other. | 231 // events and are equal to each other. |
| 281 void ConfirmEventsAreTouchAndEqual(ui::Event* e1, ui::Event* e2) { | 232 void ConfirmEventsAreTouchAndEqual(ui::Event* e1, ui::Event* e2) { |
| 282 ASSERT_TRUE(e1->IsTouchEvent()); | 233 ASSERT_TRUE(e1->IsTouchEvent()); |
| 283 ASSERT_TRUE(e2->IsTouchEvent()); | 234 ASSERT_TRUE(e2->IsTouchEvent()); |
| (...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1381 // The rest of the events should occur in passthrough. | 1332 // The rest of the events should occur in passthrough. |
| 1382 generator_->ReleaseTouchId(0); | 1333 generator_->ReleaseTouchId(0); |
| 1383 ASSERT_EQ(1U, captured_events.size()); | 1334 ASSERT_EQ(1U, captured_events.size()); |
| 1384 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type()); | 1335 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type()); |
| 1385 ClearCapturedEvents(); | 1336 ClearCapturedEvents(); |
| 1386 generator_->ReleaseTouchId(1); | 1337 generator_->ReleaseTouchId(1); |
| 1387 ASSERT_EQ(0U, captured_events.size()); | 1338 ASSERT_EQ(0U, captured_events.size()); |
| 1388 } | 1339 } |
| 1389 | 1340 |
| 1390 } // namespace ui | 1341 } // namespace ui |
| OLD | NEW |