| 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" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // Records all mouse, touch, gesture, and key events. | 26 // Records all mouse, touch, gesture, and key events. |
| 27 class EventCapturer : public ui::EventHandler { | 27 class EventCapturer : public ui::EventHandler { |
| 28 public: | 28 public: |
| 29 EventCapturer() {} | 29 EventCapturer() {} |
| 30 virtual ~EventCapturer() {} | 30 virtual ~EventCapturer() {} |
| 31 | 31 |
| 32 void Reset() { | 32 void Reset() { |
| 33 events_.clear(); | 33 events_.clear(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 virtual void OnEvent(ui::Event* event) OVERRIDE { | 36 virtual void OnEvent(ui::Event* event) override { |
| 37 if (event->IsMouseEvent()) { | 37 if (event->IsMouseEvent()) { |
| 38 events_.push_back( | 38 events_.push_back( |
| 39 new ui::MouseEvent(static_cast<ui::MouseEvent&>(*event))); | 39 new ui::MouseEvent(static_cast<ui::MouseEvent&>(*event))); |
| 40 } else if (event->IsTouchEvent()) { | 40 } else if (event->IsTouchEvent()) { |
| 41 events_.push_back( | 41 events_.push_back( |
| 42 new ui::TouchEvent(static_cast<ui::TouchEvent&>(*event))); | 42 new ui::TouchEvent(static_cast<ui::TouchEvent&>(*event))); |
| 43 } else if (event->IsGestureEvent()) { | 43 } else if (event->IsGestureEvent()) { |
| 44 events_.push_back( | 44 events_.push_back( |
| 45 new ui::GestureEvent(static_cast<ui::GestureEvent&>(*event))); | 45 new ui::GestureEvent(static_cast<ui::GestureEvent&>(*event))); |
| 46 } else if (event->IsKeyEvent()) { | 46 } else if (event->IsKeyEvent()) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 68 if (n <= 0) | 68 if (n <= 0) |
| 69 return 0; | 69 return 0; |
| 70 if (n == 1) | 70 if (n == 1) |
| 71 return 1; | 71 return 1; |
| 72 return n * Factorial(n - 1); | 72 return n * Factorial(n - 1); |
| 73 } | 73 } |
| 74 | 74 |
| 75 class MockTouchExplorationControllerDelegate | 75 class MockTouchExplorationControllerDelegate |
| 76 : public ui::TouchExplorationControllerDelegate { | 76 : public ui::TouchExplorationControllerDelegate { |
| 77 public: | 77 public: |
| 78 virtual void SetOutputLevel(int volume) OVERRIDE { | 78 virtual void SetOutputLevel(int volume) override { |
| 79 volume_changes_.push_back(volume); | 79 volume_changes_.push_back(volume); |
| 80 } | 80 } |
| 81 virtual void SilenceSpokenFeedback() OVERRIDE { | 81 virtual void SilenceSpokenFeedback() override { |
| 82 } | 82 } |
| 83 virtual void PlayVolumeAdjustEarcon() OVERRIDE { | 83 virtual void PlayVolumeAdjustEarcon() override { |
| 84 ++num_times_adjust_sound_played_; | 84 ++num_times_adjust_sound_played_; |
| 85 } | 85 } |
| 86 virtual void PlayPassthroughEarcon() OVERRIDE { | 86 virtual void PlayPassthroughEarcon() override { |
| 87 ++num_times_passthrough_played_; | 87 ++num_times_passthrough_played_; |
| 88 } | 88 } |
| 89 virtual void PlayExitScreenEarcon() OVERRIDE { | 89 virtual void PlayExitScreenEarcon() override { |
| 90 ++num_times_exit_screen_played_; | 90 ++num_times_exit_screen_played_; |
| 91 } | 91 } |
| 92 virtual void PlayEnterScreenEarcon() OVERRIDE { | 92 virtual void PlayEnterScreenEarcon() override { |
| 93 ++num_times_enter_screen_played_; | 93 ++num_times_enter_screen_played_; |
| 94 } | 94 } |
| 95 | 95 |
| 96 const std::vector<float> VolumeChanges() { return volume_changes_; } | 96 const std::vector<float> VolumeChanges() { return volume_changes_; } |
| 97 const size_t NumAdjustSounds() { return num_times_adjust_sound_played_; } | 97 const size_t NumAdjustSounds() { return num_times_adjust_sound_played_; } |
| 98 const size_t NumPassthroughSounds() { return num_times_passthrough_played_; } | 98 const size_t NumPassthroughSounds() { return num_times_passthrough_played_; } |
| 99 const size_t NumExitScreenSounds() { return num_times_exit_screen_played_; } | 99 const size_t NumExitScreenSounds() { return num_times_exit_screen_played_; } |
| 100 const size_t NumEnterScreenSounds() { | 100 const size_t NumEnterScreenSounds() { |
| 101 return num_times_enter_screen_played_; | 101 return num_times_enter_screen_played_; |
| 102 } | 102 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 class TouchExplorationTest : public aura::test::AuraTestBase { | 199 class TouchExplorationTest : public aura::test::AuraTestBase { |
| 200 public: | 200 public: |
| 201 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { | 201 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { |
| 202 // Tests fail if time is ever 0. | 202 // Tests fail if time is ever 0. |
| 203 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | 203 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); |
| 204 } | 204 } |
| 205 virtual ~TouchExplorationTest() {} | 205 virtual ~TouchExplorationTest() {} |
| 206 | 206 |
| 207 virtual void SetUp() OVERRIDE { | 207 virtual void SetUp() override { |
| 208 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone) | 208 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone) |
| 209 gfx::GLSurface::InitializeOneOffForTests(); | 209 gfx::GLSurface::InitializeOneOffForTests(); |
| 210 aura::test::AuraTestBase::SetUp(); | 210 aura::test::AuraTestBase::SetUp(); |
| 211 cursor_client_.reset(new aura::test::TestCursorClient(root_window())); | 211 cursor_client_.reset(new aura::test::TestCursorClient(root_window())); |
| 212 root_window()->AddPreTargetHandler(&event_capturer_); | 212 root_window()->AddPreTargetHandler(&event_capturer_); |
| 213 generator_.reset(new test::EventGenerator(root_window())); | 213 generator_.reset(new test::EventGenerator(root_window())); |
| 214 // The generator takes ownership of the tick clock. | 214 // The generator takes ownership of the tick clock. |
| 215 generator_->SetTickClock(scoped_ptr<base::TickClock>(simulated_clock_)); | 215 generator_->SetTickClock(scoped_ptr<base::TickClock>(simulated_clock_)); |
| 216 cursor_client()->ShowCursor(); | 216 cursor_client()->ShowCursor(); |
| 217 cursor_client()->DisableMouseEvents(); | 217 cursor_client()->DisableMouseEvents(); |
| 218 } | 218 } |
| 219 | 219 |
| 220 virtual void TearDown() OVERRIDE { | 220 virtual void TearDown() override { |
| 221 root_window()->RemovePreTargetHandler(&event_capturer_); | 221 root_window()->RemovePreTargetHandler(&event_capturer_); |
| 222 SwitchTouchExplorationMode(false); | 222 SwitchTouchExplorationMode(false); |
| 223 cursor_client_.reset(); | 223 cursor_client_.reset(); |
| 224 aura::test::AuraTestBase::TearDown(); | 224 aura::test::AuraTestBase::TearDown(); |
| 225 } | 225 } |
| 226 | 226 |
| 227 protected: | 227 protected: |
| 228 aura::client::CursorClient* cursor_client() { return cursor_client_.get(); } | 228 aura::client::CursorClient* cursor_client() { return cursor_client_.get(); } |
| 229 | 229 |
| 230 const ScopedVector<ui::Event>& GetCapturedEvents() { | 230 const ScopedVector<ui::Event>& GetCapturedEvents() { |
| (...skipping 1713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1944 generator_->PressTouch(); | 1944 generator_->PressTouch(); |
| 1945 generator_->MoveTouch(initial_press); | 1945 generator_->MoveTouch(initial_press); |
| 1946 generator_->MoveTouch(*point); | 1946 generator_->MoveTouch(*point); |
| 1947 generator_->ReleaseTouch(); | 1947 generator_->ReleaseTouch(); |
| 1948 ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); | 1948 ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); |
| 1949 delegate_.ResetCountersToZero(); | 1949 delegate_.ResetCountersToZero(); |
| 1950 } | 1950 } |
| 1951 } | 1951 } |
| 1952 | 1952 |
| 1953 } // namespace ui | 1953 } // namespace ui |
| OLD | NEW |