Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: ui/chromeos/touch_exploration_controller_unittest.cc

Issue 386043002: Added wrapper test class for touch_exploration_controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/chromeos/touch_exploration_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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()
103 const {
dmazzoni 2014/07/16 15:01:02 nit: this fits on the previous line
evy 2014/07/16 17:22:08 Done.
104 return touch_exploration_controller_->state_ ==
105 touch_exploration_controller_->NO_FINGERS_DOWN;
106 }
107
108 bool IsInGestureInProgressStateForTesting()
109 const {
dmazzoni 2014/07/16 15:01:02 nit: same
evy 2014/07/16 17:22:08 Done.
110 return touch_exploration_controller_->state_ ==
111 touch_exploration_controller_->GESTURE_IN_PROGRESS;
112 }
113
114 // VLOGs should be suppressed in tests that generate a lot of logs,
115 // for example permutations of nine touch events.
116 void SuppressVLOGsForTesting(
117 bool suppress) {
dmazzoni 2014/07/16 15:01:02 same
evy 2014/07/16 17:22:08 Done.
118 touch_exploration_controller_->VLOG_on_ = !suppress;
119 }
120
121 private:
122 TouchExplorationController* touch_exploration_controller_;
123
124 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi);
125 };
126
76 class TouchExplorationTest : public aura::test::AuraTestBase { 127 class TouchExplorationTest : public aura::test::AuraTestBase {
77 public: 128 public:
78 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { 129 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) {
79 // Tests fail if time is ever 0. 130 // Tests fail if time is ever 0.
80 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); 131 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
81 } 132 }
82 virtual ~TouchExplorationTest() {} 133 virtual ~TouchExplorationTest() {}
83 134
84 virtual void SetUp() OVERRIDE { 135 virtual void SetUp() OVERRIDE {
85 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone) 136 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 207 }
157 208
158 void SuppressVLOGs(bool suppress) { 209 void SuppressVLOGs(bool suppress) {
159 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); 210 touch_exploration_controller_->SuppressVLOGsForTesting(suppress);
160 } 211 }
161 212
162 void SwitchTouchExplorationMode(bool on) { 213 void SwitchTouchExplorationMode(bool on) {
163 if (!on && touch_exploration_controller_.get()) { 214 if (!on && touch_exploration_controller_.get()) {
164 touch_exploration_controller_.reset(); 215 touch_exploration_controller_.reset();
165 } else if (on && !touch_exploration_controller_.get()) { 216 } else if (on && !touch_exploration_controller_.get()) {
166 touch_exploration_controller_.reset( 217 touch_exploration_controller_.reset(new TouchExplorationControllerTestApi(
167 new ui::TouchExplorationController(root_window())); 218 new ui::TouchExplorationController(root_window())));
168 touch_exploration_controller_->SetEventHandlerForTesting( 219 touch_exploration_controller_->SetEventHandlerForTesting(
169 &event_capturer_); 220 &event_capturer_);
170 cursor_client()->ShowCursor(); 221 cursor_client()->ShowCursor();
171 cursor_client()->DisableMouseEvents(); 222 cursor_client()->DisableMouseEvents();
172 } 223 }
173 } 224 }
174 225
175 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) { 226 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) {
176 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now()); 227 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now());
177 generator_->Dispatch(&touch_press); 228 generator_->Dispatch(&touch_press);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 simulated_clock_->NowTicks().ToInternalValue()); 265 simulated_clock_->NowTicks().ToInternalValue());
215 } 266 }
216 267
217 scoped_ptr<aura::test::EventGenerator> generator_; 268 scoped_ptr<aura::test::EventGenerator> generator_;
218 ui::GestureDetector::Config gesture_detector_config_; 269 ui::GestureDetector::Config gesture_detector_config_;
219 // Owned by |generator_|. 270 // Owned by |generator_|.
220 base::SimpleTestTickClock* simulated_clock_; 271 base::SimpleTestTickClock* simulated_clock_;
221 272
222 private: 273 private:
223 EventCapturer event_capturer_; 274 EventCapturer event_capturer_;
224 scoped_ptr<ui::TouchExplorationController> touch_exploration_controller_; 275 scoped_ptr<TouchExplorationControllerTestApi>
276 touch_exploration_controller_;
225 scoped_ptr<aura::test::TestCursorClient> cursor_client_; 277 scoped_ptr<aura::test::TestCursorClient> cursor_client_;
226 278
227 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); 279 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest);
228 }; 280 };
229 281
230 // Executes a number of assertions to confirm that |e1| and |e2| are touch 282 // Executes a number of assertions to confirm that |e1| and |e2| are touch
231 // events and are equal to each other. 283 // events and are equal to each other.
232 void ConfirmEventsAreTouchAndEqual(ui::Event* e1, ui::Event* e2) { 284 void ConfirmEventsAreTouchAndEqual(ui::Event* e1, ui::Event* e2) {
233 ASSERT_TRUE(e1->IsTouchEvent()); 285 ASSERT_TRUE(e1->IsTouchEvent());
234 ASSERT_TRUE(e2->IsTouchEvent()); 286 ASSERT_TRUE(e2->IsTouchEvent());
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 // The rest of the events should occur in passthrough. 1384 // The rest of the events should occur in passthrough.
1333 generator_->ReleaseTouchId(0); 1385 generator_->ReleaseTouchId(0);
1334 ASSERT_EQ(1U, captured_events.size()); 1386 ASSERT_EQ(1U, captured_events.size());
1335 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type()); 1387 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type());
1336 ClearCapturedEvents(); 1388 ClearCapturedEvents();
1337 generator_->ReleaseTouchId(1); 1389 generator_->ReleaseTouchId(1);
1338 ASSERT_EQ(0U, captured_events.size()); 1390 ASSERT_EQ(0U, captured_events.size());
1339 } 1391 }
1340 1392
1341 } // namespace ui 1393 } // namespace ui
OLDNEW
« no previous file with comments | « ui/chromeos/touch_exploration_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698