Chromium Code Reviews| 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_(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 | |
| 76 class TouchExplorationTest : public aura::test::AuraTestBase { | 124 class TouchExplorationTest : public aura::test::AuraTestBase { |
| 77 public: | 125 public: |
| 78 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { | 126 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { |
| 79 // Tests fail if time is ever 0. | 127 // Tests fail if time is ever 0. |
| 80 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | 128 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); |
| 81 } | 129 } |
| 82 virtual ~TouchExplorationTest() {} | 130 virtual ~TouchExplorationTest() {} |
| 83 | 131 |
| 84 virtual void SetUp() OVERRIDE { | 132 virtual void SetUp() OVERRIDE { |
| 85 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone) | 133 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 } | 204 } |
| 157 | 205 |
| 158 void SuppressVLOGs(bool suppress) { | 206 void SuppressVLOGs(bool suppress) { |
| 159 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); | 207 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); |
| 160 } | 208 } |
| 161 | 209 |
| 162 void SwitchTouchExplorationMode(bool on) { | 210 void SwitchTouchExplorationMode(bool on) { |
| 163 if (!on && touch_exploration_controller_.get()) { | 211 if (!on && touch_exploration_controller_.get()) { |
| 164 touch_exploration_controller_.reset(); | 212 touch_exploration_controller_.reset(); |
| 165 } else if (on && !touch_exploration_controller_.get()) { | 213 } else if (on && !touch_exploration_controller_.get()) { |
| 166 touch_exploration_controller_.reset( | 214 touch_exploration_controller_.reset(new TouchExplorationControllerTestApi( |
| 167 new ui::TouchExplorationController(root_window())); | 215 new ui::TouchExplorationController(root_window()))); |
|
gab
2014/07/17 17:46:09
The ui::TouchExplorationController passed into the
evy
2014/07/17 21:06:46
Thank you for pointing to the problematic line of
gab
2014/07/17 21:17:42
NP :)
| |
| 168 touch_exploration_controller_->SetEventHandlerForTesting( | 216 touch_exploration_controller_->SetEventHandlerForTesting( |
| 169 &event_capturer_); | 217 &event_capturer_); |
| 170 cursor_client()->ShowCursor(); | 218 cursor_client()->ShowCursor(); |
| 171 cursor_client()->DisableMouseEvents(); | 219 cursor_client()->DisableMouseEvents(); |
| 172 } | 220 } |
| 173 } | 221 } |
| 174 | 222 |
| 175 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) { | 223 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) { |
| 176 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now()); | 224 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now()); |
| 177 generator_->Dispatch(&touch_press); | 225 generator_->Dispatch(&touch_press); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 simulated_clock_->NowTicks().ToInternalValue()); | 262 simulated_clock_->NowTicks().ToInternalValue()); |
| 215 } | 263 } |
| 216 | 264 |
| 217 scoped_ptr<aura::test::EventGenerator> generator_; | 265 scoped_ptr<aura::test::EventGenerator> generator_; |
| 218 ui::GestureDetector::Config gesture_detector_config_; | 266 ui::GestureDetector::Config gesture_detector_config_; |
| 219 // Owned by |generator_|. | 267 // Owned by |generator_|. |
| 220 base::SimpleTestTickClock* simulated_clock_; | 268 base::SimpleTestTickClock* simulated_clock_; |
| 221 | 269 |
| 222 private: | 270 private: |
| 223 EventCapturer event_capturer_; | 271 EventCapturer event_capturer_; |
| 224 scoped_ptr<ui::TouchExplorationController> touch_exploration_controller_; | 272 scoped_ptr<TouchExplorationControllerTestApi> |
| 273 touch_exploration_controller_; | |
| 225 scoped_ptr<aura::test::TestCursorClient> cursor_client_; | 274 scoped_ptr<aura::test::TestCursorClient> cursor_client_; |
| 226 | 275 |
| 227 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); | 276 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); |
| 228 }; | 277 }; |
| 229 | 278 |
| 230 // Executes a number of assertions to confirm that |e1| and |e2| are touch | 279 // Executes a number of assertions to confirm that |e1| and |e2| are touch |
| 231 // events and are equal to each other. | 280 // events and are equal to each other. |
| 232 void ConfirmEventsAreTouchAndEqual(ui::Event* e1, ui::Event* e2) { | 281 void ConfirmEventsAreTouchAndEqual(ui::Event* e1, ui::Event* e2) { |
| 233 ASSERT_TRUE(e1->IsTouchEvent()); | 282 ASSERT_TRUE(e1->IsTouchEvent()); |
| 234 ASSERT_TRUE(e2->IsTouchEvent()); | 283 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. | 1381 // The rest of the events should occur in passthrough. |
| 1333 generator_->ReleaseTouchId(0); | 1382 generator_->ReleaseTouchId(0); |
| 1334 ASSERT_EQ(1U, captured_events.size()); | 1383 ASSERT_EQ(1U, captured_events.size()); |
| 1335 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type()); | 1384 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type()); |
| 1336 ClearCapturedEvents(); | 1385 ClearCapturedEvents(); |
| 1337 generator_->ReleaseTouchId(1); | 1386 generator_->ReleaseTouchId(1); |
| 1338 ASSERT_EQ(0U, captured_events.size()); | 1387 ASSERT_EQ(0U, captured_events.size()); |
| 1339 } | 1388 } |
| 1340 | 1389 |
| 1341 } // namespace ui | 1390 } // namespace ui |
| OLD | NEW |