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

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: Fix touch_unittests 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
« no previous file with comments | « ui/chromeos/touch_exploration_controller.cc ('k') | ui/events/test/event_generator.h » ('j') | 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 <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_(nullptr) {}
196 // Tests fail if time is ever 0.
197 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
198 }
199 ~TouchExplorationTest() override {} 192 ~TouchExplorationTest() override {}
200 193
201 void SetUp() override { 194 void SetUp() override {
202 if (gl::GetGLImplementation() == gl::kGLImplementationNone) 195 if (gl::GetGLImplementation() == gl::kGLImplementationNone)
203 gl::GLSurfaceTestSupport::InitializeOneOff(); 196 gl::GLSurfaceTestSupport::InitializeOneOff();
204 aura::test::AuraTestBase::SetUp(); 197 aura::test::AuraTestBase::SetUp();
205 cursor_client_.reset(new aura::test::TestCursorClient(root_window())); 198 cursor_client_.reset(new aura::test::TestCursorClient(root_window()));
206 root_window()->AddPreTargetHandler(&event_capturer_); 199 root_window()->AddPreTargetHandler(&event_capturer_);
207 generator_.reset(new test::EventGenerator(root_window())); 200 generator_.reset(new test::EventGenerator(root_window()));
208 // The generator takes ownership of the tick clock. 201
209 generator_->SetTickClock( 202 simulated_clock_ = new base::SimpleTestTickClock();
203 // Tests fail if time is ever 0.
204 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
205 // ui takes ownership of the tick clock.
206 ui::SetEventTickClockForTesting(
210 std::unique_ptr<base::TickClock>(simulated_clock_)); 207 std::unique_ptr<base::TickClock>(simulated_clock_));
208
211 cursor_client()->ShowCursor(); 209 cursor_client()->ShowCursor();
212 cursor_client()->DisableMouseEvents(); 210 cursor_client()->DisableMouseEvents();
213 } 211 }
214 212
215 void TearDown() override { 213 void TearDown() override {
214 ui::SetEventTickClockForTesting(nullptr);
216 root_window()->RemovePreTargetHandler(&event_capturer_); 215 root_window()->RemovePreTargetHandler(&event_capturer_);
217 SwitchTouchExplorationMode(false); 216 SwitchTouchExplorationMode(false);
218 cursor_client_.reset(); 217 cursor_client_.reset();
219 aura::test::AuraTestBase::TearDown(); 218 aura::test::AuraTestBase::TearDown();
220 } 219 }
221 220
222 protected: 221 protected:
223 aura::client::CursorClient* cursor_client() { return cursor_client_.get(); } 222 aura::client::CursorClient* cursor_client() { return cursor_client_.get(); }
224 223
225 const ScopedVector<ui::Event>& GetCapturedEvents() { 224 const ScopedVector<ui::Event>& GetCapturedEvents() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 275
277 void AdvanceSimulatedTimePastPotentialTapDelay() { 276 void AdvanceSimulatedTimePastPotentialTapDelay() {
278 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); 277 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000));
279 touch_exploration_controller_->CallTapTimerNowIfRunningForTesting(); 278 touch_exploration_controller_->CallTapTimerNowIfRunningForTesting();
280 } 279 }
281 280
282 void SuppressVLOGs(bool suppress) { 281 void SuppressVLOGs(bool suppress) {
283 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); 282 touch_exploration_controller_->SuppressVLOGsForTesting(suppress);
284 } 283 }
285 284
286 void SetTickClock() {
287 touch_exploration_controller_->SetTickClockForTesting(
288 static_cast<base::TickClock*>(simulated_clock_));
289 }
290
291 void SwitchTouchExplorationMode(bool on) { 285 void SwitchTouchExplorationMode(bool on) {
292 if (!on && touch_exploration_controller_.get()) { 286 if (!on && touch_exploration_controller_.get()) {
293 touch_exploration_controller_.reset(); 287 touch_exploration_controller_.reset();
294 } else if (on && !touch_exploration_controller_.get()) { 288 } else if (on && !touch_exploration_controller_.get()) {
295 touch_exploration_controller_.reset( 289 touch_exploration_controller_.reset(
296 new ui::TouchExplorationControllerTestApi( 290 new ui::TouchExplorationControllerTestApi(
297 new TouchExplorationController(root_window(), &delegate_))); 291 new TouchExplorationController(root_window(), &delegate_)));
298 cursor_client()->ShowCursor(); 292 cursor_client()->ShowCursor();
299 cursor_client()->DisableMouseEvents(); 293 cursor_client()->DisableMouseEvents();
300 } 294 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 379 }
386 380
387 float GetMaxDistanceFromEdge() const { 381 float GetMaxDistanceFromEdge() const {
388 return touch_exploration_controller_->GetMaxDistanceFromEdge(); 382 return touch_exploration_controller_->GetMaxDistanceFromEdge();
389 } 383 }
390 384
391 float GetSlopDistanceFromEdge() const { 385 float GetSlopDistanceFromEdge() const {
392 return touch_exploration_controller_->GetSlopDistanceFromEdge(); 386 return touch_exploration_controller_->GetSlopDistanceFromEdge();
393 } 387 }
394 388
395 base::TimeTicks Now() { 389 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 390
401 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) { 391 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) {
402 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location); 392 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location);
403 } 393 }
404 394
405 std::unique_ptr<test::EventGenerator> generator_; 395 std::unique_ptr<test::EventGenerator> generator_;
406 ui::GestureDetector::Config gesture_detector_config_; 396 ui::GestureDetector::Config gesture_detector_config_;
407 // Owned by |generator_|. 397 // Owned by |ui|.
408 base::SimpleTestTickClock* simulated_clock_; 398 base::SimpleTestTickClock* simulated_clock_;
409 MockTouchExplorationControllerDelegate delegate_; 399 MockTouchExplorationControllerDelegate delegate_;
410 400
411 private: 401 private:
412 EventCapturer event_capturer_; 402 EventCapturer event_capturer_;
413 std::unique_ptr<TouchExplorationControllerTestApi> 403 std::unique_ptr<TouchExplorationControllerTestApi>
414 touch_exploration_controller_; 404 touch_exploration_controller_;
415 std::unique_ptr<aura::test::TestCursorClient> cursor_client_; 405 std::unique_ptr<aura::test::TestCursorClient> cursor_client_;
416 406
417 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); 407 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest);
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 EXPECT_FALSE(IsInNoFingersDownState()); 829 EXPECT_FALSE(IsInNoFingersDownState());
840 generator_->ReleaseTouchId(3); 830 generator_->ReleaseTouchId(3);
841 EXPECT_TRUE(IsInNoFingersDownState()); 831 EXPECT_TRUE(IsInNoFingersDownState());
842 } 832 }
843 833
844 // Double-tapping, going into passthrough, and holding for the longpress 834 // Double-tapping, going into passthrough, and holding for the longpress
845 // time should send a touch press and released (right click) 835 // time should send a touch press and released (right click)
846 // to the location of the last successful touch exploration. 836 // to the location of the last successful touch exploration.
847 TEST_F(TouchExplorationTest, DoubleTapLongPress) { 837 TEST_F(TouchExplorationTest, DoubleTapLongPress) {
848 SwitchTouchExplorationMode(true); 838 SwitchTouchExplorationMode(true);
849 SetTickClock();
850 // Tap at one location, and get a mouse move event. 839 // Tap at one location, and get a mouse move event.
851 gfx::Point tap_location(11, 12); 840 gfx::Point tap_location(11, 12);
852 generator_->set_current_location(tap_location); 841 generator_->set_current_location(tap_location);
853 generator_->PressTouch(); 842 generator_->PressTouch();
854 generator_->ReleaseTouch(); 843 generator_->ReleaseTouch();
855 AdvanceSimulatedTimePastTapDelay(); 844 AdvanceSimulatedTimePastTapDelay();
856 845
857 std::vector<ui::LocatedEvent*> events = 846 std::vector<ui::LocatedEvent*> events =
858 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); 847 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED);
859 ASSERT_EQ(1U, events.size()); 848 ASSERT_EQ(1U, events.size());
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 generator_->PressTouch(); 1813 generator_->PressTouch();
1825 generator_->MoveTouch(initial_press); 1814 generator_->MoveTouch(initial_press);
1826 generator_->MoveTouch(*point); 1815 generator_->MoveTouch(*point);
1827 generator_->ReleaseTouch(); 1816 generator_->ReleaseTouch();
1828 ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); 1817 ASSERT_EQ(1U, delegate_.NumExitScreenSounds());
1829 delegate_.ResetCountersToZero(); 1818 delegate_.ResetCountersToZero();
1830 } 1819 }
1831 } 1820 }
1832 1821
1833 } // namespace ui 1822 } // namespace ui
OLDNEW
« no previous file with comments | « ui/chromeos/touch_exploration_controller.cc ('k') | ui/events/test/event_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698