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

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

Issue 2100453002: Remove unnecessary mocking of TickClock for events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@614409-confirm-timestamp-timebase
Patch Set: rebase Created 4 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
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 <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 169 }
170 170
171 float GetMaxDistanceFromEdge() const { 171 float GetMaxDistanceFromEdge() const {
172 return touch_exploration_controller_->kMaxDistanceFromEdge; 172 return touch_exploration_controller_->kMaxDistanceFromEdge;
173 } 173 }
174 174
175 float GetSlopDistanceFromEdge() const { 175 float GetSlopDistanceFromEdge() const {
176 return touch_exploration_controller_->kSlopDistanceFromEdge; 176 return touch_exploration_controller_->kSlopDistanceFromEdge;
177 } 177 }
178 178
179 void SetTickClockForTesting(base::TickClock* simulated_clock) {
180 touch_exploration_controller_->tick_clock_ = simulated_clock;
181 }
182
183 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) { 179 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) {
184 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location); 180 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location);
185 } 181 }
186 182
187 private: 183 private:
188 std::unique_ptr<TouchExplorationController> touch_exploration_controller_; 184 std::unique_ptr<TouchExplorationController> touch_exploration_controller_;
189 185
190 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi); 186 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi);
191 }; 187 };
192 188
193 class TouchExplorationTest : public aura::test::AuraTestBase { 189 class TouchExplorationTest : public aura::test::AuraTestBase {
194 public: 190 public:
195 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { 191 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) {
196 // Tests fail if time is ever 0. 192 // Tests fail if time is ever 0.
197 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); 193 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
198 } 194 }
199 ~TouchExplorationTest() override {} 195 ~TouchExplorationTest() override {}
200 196
201 void SetUp() override { 197 void SetUp() override {
202 if (gl::GetGLImplementation() == gl::kGLImplementationNone) 198 if (gl::GetGLImplementation() == gl::kGLImplementationNone)
203 gl::GLSurfaceTestSupport::InitializeOneOff(); 199 gl::GLSurfaceTestSupport::InitializeOneOff();
204 aura::test::AuraTestBase::SetUp(); 200 aura::test::AuraTestBase::SetUp();
205 cursor_client_.reset(new aura::test::TestCursorClient(root_window())); 201 cursor_client_.reset(new aura::test::TestCursorClient(root_window()));
206 root_window()->AddPreTargetHandler(&event_capturer_); 202 root_window()->AddPreTargetHandler(&event_capturer_);
207 generator_.reset(new test::EventGenerator(root_window())); 203 generator_.reset(new test::EventGenerator(root_window()));
208 // The generator takes ownership of the tick clock. 204 // ui takes ownership of the tick clock.
209 generator_->SetTickClock( 205 ui::SetEventTickClockForTesting(
210 std::unique_ptr<base::TickClock>(simulated_clock_)); 206 std::unique_ptr<base::TickClock>(simulated_clock_));
211 cursor_client()->ShowCursor(); 207 cursor_client()->ShowCursor();
212 cursor_client()->DisableMouseEvents(); 208 cursor_client()->DisableMouseEvents();
213 } 209 }
214 210
215 void TearDown() override { 211 void TearDown() override {
216 root_window()->RemovePreTargetHandler(&event_capturer_); 212 root_window()->RemovePreTargetHandler(&event_capturer_);
217 SwitchTouchExplorationMode(false); 213 SwitchTouchExplorationMode(false);
218 cursor_client_.reset(); 214 cursor_client_.reset();
219 aura::test::AuraTestBase::TearDown(); 215 aura::test::AuraTestBase::TearDown();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 272
277 void AdvanceSimulatedTimePastPotentialTapDelay() { 273 void AdvanceSimulatedTimePastPotentialTapDelay() {
278 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); 274 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000));
279 touch_exploration_controller_->CallTapTimerNowIfRunningForTesting(); 275 touch_exploration_controller_->CallTapTimerNowIfRunningForTesting();
280 } 276 }
281 277
282 void SuppressVLOGs(bool suppress) { 278 void SuppressVLOGs(bool suppress) {
283 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); 279 touch_exploration_controller_->SuppressVLOGsForTesting(suppress);
284 } 280 }
285 281
286 void SetTickClock() {
287 touch_exploration_controller_->SetTickClockForTesting(
288 static_cast<base::TickClock*>(simulated_clock_));
289 }
290
291 void SwitchTouchExplorationMode(bool on) { 282 void SwitchTouchExplorationMode(bool on) {
292 if (!on && touch_exploration_controller_.get()) { 283 if (!on && touch_exploration_controller_.get()) {
293 touch_exploration_controller_.reset(); 284 touch_exploration_controller_.reset();
294 } else if (on && !touch_exploration_controller_.get()) { 285 } else if (on && !touch_exploration_controller_.get()) {
295 touch_exploration_controller_.reset( 286 touch_exploration_controller_.reset(
296 new ui::TouchExplorationControllerTestApi( 287 new ui::TouchExplorationControllerTestApi(
297 new TouchExplorationController(root_window(), &delegate_))); 288 new TouchExplorationController(root_window(), &delegate_)));
298 cursor_client()->ShowCursor(); 289 cursor_client()->ShowCursor();
299 cursor_client()->DisableMouseEvents(); 290 cursor_client()->DisableMouseEvents();
300 } 291 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 376 }
386 377
387 float GetMaxDistanceFromEdge() const { 378 float GetMaxDistanceFromEdge() const {
388 return touch_exploration_controller_->GetMaxDistanceFromEdge(); 379 return touch_exploration_controller_->GetMaxDistanceFromEdge();
389 } 380 }
390 381
391 float GetSlopDistanceFromEdge() const { 382 float GetSlopDistanceFromEdge() const {
392 return touch_exploration_controller_->GetSlopDistanceFromEdge(); 383 return touch_exploration_controller_->GetSlopDistanceFromEdge();
393 } 384 }
394 385
395 base::TimeTicks Now() { 386 base::TimeTicks Now() { return ui::EventTimeForNow(); }
396 // This is the same as what EventTimeForNow() does, but here we do it
397 // with our simulated clock.
398 return simulated_clock_->NowTicks();
399 }
400 387
401 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) { 388 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) {
402 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location); 389 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location);
403 } 390 }
404 391
405 std::unique_ptr<test::EventGenerator> generator_; 392 std::unique_ptr<test::EventGenerator> generator_;
406 ui::GestureDetector::Config gesture_detector_config_; 393 ui::GestureDetector::Config gesture_detector_config_;
407 // Owned by |generator_|. 394 // Owned by |ui|.
408 base::SimpleTestTickClock* simulated_clock_; 395 base::SimpleTestTickClock* simulated_clock_;
409 MockTouchExplorationControllerDelegate delegate_; 396 MockTouchExplorationControllerDelegate delegate_;
410 397
411 private: 398 private:
412 EventCapturer event_capturer_; 399 EventCapturer event_capturer_;
413 std::unique_ptr<TouchExplorationControllerTestApi> 400 std::unique_ptr<TouchExplorationControllerTestApi>
414 touch_exploration_controller_; 401 touch_exploration_controller_;
415 std::unique_ptr<aura::test::TestCursorClient> cursor_client_; 402 std::unique_ptr<aura::test::TestCursorClient> cursor_client_;
416 403
417 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); 404 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest);
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 EXPECT_FALSE(IsInNoFingersDownState()); 826 EXPECT_FALSE(IsInNoFingersDownState());
840 generator_->ReleaseTouchId(3); 827 generator_->ReleaseTouchId(3);
841 EXPECT_TRUE(IsInNoFingersDownState()); 828 EXPECT_TRUE(IsInNoFingersDownState());
842 } 829 }
843 830
844 // Double-tapping, going into passthrough, and holding for the longpress 831 // Double-tapping, going into passthrough, and holding for the longpress
845 // time should send a touch press and released (right click) 832 // time should send a touch press and released (right click)
846 // to the location of the last successful touch exploration. 833 // to the location of the last successful touch exploration.
847 TEST_F(TouchExplorationTest, DoubleTapLongPress) { 834 TEST_F(TouchExplorationTest, DoubleTapLongPress) {
848 SwitchTouchExplorationMode(true); 835 SwitchTouchExplorationMode(true);
849 SetTickClock();
850 // Tap at one location, and get a mouse move event. 836 // Tap at one location, and get a mouse move event.
851 gfx::Point tap_location(11, 12); 837 gfx::Point tap_location(11, 12);
852 generator_->set_current_location(tap_location); 838 generator_->set_current_location(tap_location);
853 generator_->PressTouch(); 839 generator_->PressTouch();
854 generator_->ReleaseTouch(); 840 generator_->ReleaseTouch();
855 AdvanceSimulatedTimePastTapDelay(); 841 AdvanceSimulatedTimePastTapDelay();
856 842
857 std::vector<ui::LocatedEvent*> events = 843 std::vector<ui::LocatedEvent*> events =
858 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); 844 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED);
859 ASSERT_EQ(1U, events.size()); 845 ASSERT_EQ(1U, events.size());
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 generator_->PressTouch(); 1810 generator_->PressTouch();
1825 generator_->MoveTouch(initial_press); 1811 generator_->MoveTouch(initial_press);
1826 generator_->MoveTouch(*point); 1812 generator_->MoveTouch(*point);
1827 generator_->ReleaseTouch(); 1813 generator_->ReleaseTouch();
1828 ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); 1814 ASSERT_EQ(1U, delegate_.NumExitScreenSounds());
1829 delegate_.ResetCountersToZero(); 1815 delegate_.ResetCountersToZero();
1830 } 1816 }
1831 } 1817 }
1832 1818
1833 } // namespace ui 1819 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698