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