| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/test/simple_test_tick_clock.h" | 10 #include "base/test/simple_test_tick_clock.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 float GetSlopDistanceFromEdge() const { | 171 float GetSlopDistanceFromEdge() const { |
| 172 return touch_exploration_controller_->kSlopDistanceFromEdge; | 172 return touch_exploration_controller_->kSlopDistanceFromEdge; |
| 173 } | 173 } |
| 174 | 174 |
| 175 void SetTickClockForTesting(base::TickClock* simulated_clock) { | 175 void SetTickClockForTesting(base::TickClock* simulated_clock) { |
| 176 touch_exploration_controller_->tick_clock_ = simulated_clock; | 176 touch_exploration_controller_->tick_clock_ = simulated_clock; |
| 177 } | 177 } |
| 178 | 178 |
| 179 private: | 179 private: |
| 180 scoped_ptr<TouchExplorationController> touch_exploration_controller_; | 180 std::unique_ptr<TouchExplorationController> touch_exploration_controller_; |
| 181 | 181 |
| 182 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi); | 182 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi); |
| 183 }; | 183 }; |
| 184 | 184 |
| 185 class TouchExplorationTest : public aura::test::AuraTestBase { | 185 class TouchExplorationTest : public aura::test::AuraTestBase { |
| 186 public: | 186 public: |
| 187 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { | 187 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { |
| 188 // Tests fail if time is ever 0. | 188 // Tests fail if time is ever 0. |
| 189 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | 189 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); |
| 190 } | 190 } |
| 191 ~TouchExplorationTest() override {} | 191 ~TouchExplorationTest() override {} |
| 192 | 192 |
| 193 void SetUp() override { | 193 void SetUp() override { |
| 194 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone) | 194 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone) |
| 195 gfx::GLSurfaceTestSupport::InitializeOneOff(); | 195 gfx::GLSurfaceTestSupport::InitializeOneOff(); |
| 196 aura::test::AuraTestBase::SetUp(); | 196 aura::test::AuraTestBase::SetUp(); |
| 197 cursor_client_.reset(new aura::test::TestCursorClient(root_window())); | 197 cursor_client_.reset(new aura::test::TestCursorClient(root_window())); |
| 198 root_window()->AddPreTargetHandler(&event_capturer_); | 198 root_window()->AddPreTargetHandler(&event_capturer_); |
| 199 generator_.reset(new test::EventGenerator(root_window())); | 199 generator_.reset(new test::EventGenerator(root_window())); |
| 200 // The generator takes ownership of the tick clock. | 200 // The generator takes ownership of the tick clock. |
| 201 generator_->SetTickClock(scoped_ptr<base::TickClock>(simulated_clock_)); | 201 generator_->SetTickClock( |
| 202 std::unique_ptr<base::TickClock>(simulated_clock_)); |
| 202 cursor_client()->ShowCursor(); | 203 cursor_client()->ShowCursor(); |
| 203 cursor_client()->DisableMouseEvents(); | 204 cursor_client()->DisableMouseEvents(); |
| 204 } | 205 } |
| 205 | 206 |
| 206 void TearDown() override { | 207 void TearDown() override { |
| 207 root_window()->RemovePreTargetHandler(&event_capturer_); | 208 root_window()->RemovePreTargetHandler(&event_capturer_); |
| 208 SwitchTouchExplorationMode(false); | 209 SwitchTouchExplorationMode(false); |
| 209 cursor_client_.reset(); | 210 cursor_client_.reset(); |
| 210 aura::test::AuraTestBase::TearDown(); | 211 aura::test::AuraTestBase::TearDown(); |
| 211 } | 212 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 return touch_exploration_controller_->GetSlopDistanceFromEdge(); | 384 return touch_exploration_controller_->GetSlopDistanceFromEdge(); |
| 384 } | 385 } |
| 385 | 386 |
| 386 base::TimeDelta Now() { | 387 base::TimeDelta Now() { |
| 387 // This is the same as what EventTimeForNow() does, but here we do it | 388 // This is the same as what EventTimeForNow() does, but here we do it |
| 388 // with our simulated clock. | 389 // with our simulated clock. |
| 389 return base::TimeDelta::FromInternalValue( | 390 return base::TimeDelta::FromInternalValue( |
| 390 simulated_clock_->NowTicks().ToInternalValue()); | 391 simulated_clock_->NowTicks().ToInternalValue()); |
| 391 } | 392 } |
| 392 | 393 |
| 393 scoped_ptr<test::EventGenerator> generator_; | 394 std::unique_ptr<test::EventGenerator> generator_; |
| 394 ui::GestureDetector::Config gesture_detector_config_; | 395 ui::GestureDetector::Config gesture_detector_config_; |
| 395 // Owned by |generator_|. | 396 // Owned by |generator_|. |
| 396 base::SimpleTestTickClock* simulated_clock_; | 397 base::SimpleTestTickClock* simulated_clock_; |
| 397 MockTouchExplorationControllerDelegate delegate_; | 398 MockTouchExplorationControllerDelegate delegate_; |
| 398 | 399 |
| 399 private: | 400 private: |
| 400 EventCapturer event_capturer_; | 401 EventCapturer event_capturer_; |
| 401 scoped_ptr<TouchExplorationControllerTestApi> | 402 std::unique_ptr<TouchExplorationControllerTestApi> |
| 402 touch_exploration_controller_; | 403 touch_exploration_controller_; |
| 403 scoped_ptr<aura::test::TestCursorClient> cursor_client_; | 404 std::unique_ptr<aura::test::TestCursorClient> cursor_client_; |
| 404 | 405 |
| 405 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); | 406 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); |
| 406 }; | 407 }; |
| 407 | 408 |
| 408 // Executes a number of assertions to confirm that |e1| and |e2| are touch | 409 // Executes a number of assertions to confirm that |e1| and |e2| are touch |
| 409 // events and are equal to each other. | 410 // events and are equal to each other. |
| 410 void ConfirmEventsAreTouchAndEqual(ui::Event* e1, ui::Event* e2) { | 411 void ConfirmEventsAreTouchAndEqual(ui::Event* e1, ui::Event* e2) { |
| 411 ASSERT_TRUE(e1->IsTouchEvent()); | 412 ASSERT_TRUE(e1->IsTouchEvent()); |
| 412 ASSERT_TRUE(e2->IsTouchEvent()); | 413 ASSERT_TRUE(e2->IsTouchEvent()); |
| 413 ui::TouchEvent* touch_event1 = e1->AsTouchEvent(); | 414 ui::TouchEvent* touch_event1 = e1->AsTouchEvent(); |
| (...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1928 generator_->PressTouch(); | 1929 generator_->PressTouch(); |
| 1929 generator_->MoveTouch(initial_press); | 1930 generator_->MoveTouch(initial_press); |
| 1930 generator_->MoveTouch(*point); | 1931 generator_->MoveTouch(*point); |
| 1931 generator_->ReleaseTouch(); | 1932 generator_->ReleaseTouch(); |
| 1932 ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); | 1933 ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); |
| 1933 delegate_.ResetCountersToZero(); | 1934 delegate_.ResetCountersToZero(); |
| 1934 } | 1935 } |
| 1935 } | 1936 } |
| 1936 | 1937 |
| 1937 } // namespace ui | 1938 } // namespace ui |
| OLD | NEW |