Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/wm/lock_state_controller.h" | 5 #include "ash/wm/lock_state_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/common/session/session_state_delegate.h" | 10 #include "ash/common/session/session_state_delegate.h" |
| 11 #include "ash/common/test/test_session_state_delegate.h" | 11 #include "ash/common/test/test_session_state_delegate.h" |
| 12 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 12 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 13 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
| 14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 15 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
| 16 #include "ash/test/test_lock_state_controller_delegate.h" | |
| 17 #include "ash/test/test_screenshot_delegate.h" | 16 #include "ash/test/test_screenshot_delegate.h" |
| 18 #include "ash/test/test_session_state_animator.h" | 17 #include "ash/test/test_session_state_animator.h" |
| 19 #include "ash/test/test_shell_delegate.h" | 18 #include "ash/test/test_shell_delegate.h" |
| 19 #include "ash/test/test_shutdown_client.h" | |
| 20 #include "ash/wm/power_button_controller.h" | 20 #include "ash/wm/power_button_controller.h" |
| 21 #include "ash/wm/session_state_animator.h" | 21 #include "ash/wm/session_state_animator.h" |
| 22 #include "base/memory/scoped_vector.h" | 22 #include "base/memory/scoped_vector.h" |
| 23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 24 #include "chromeos/dbus/dbus_thread_manager.h" | 24 #include "chromeos/dbus/dbus_thread_manager.h" |
| 25 #include "chromeos/dbus/fake_session_manager_client.h" | 25 #include "chromeos/dbus/fake_session_manager_client.h" |
| 26 #include "ui/display/chromeos/display_configurator.h" | 26 #include "ui/display/chromeos/display_configurator.h" |
| 27 #include "ui/display/fake_display_snapshot.h" | 27 #include "ui/display/fake_display_snapshot.h" |
| 28 #include "ui/display/types/display_constants.h" | 28 #include "ui/display/types/display_constants.h" |
| 29 #include "ui/events/test/event_generator.h" | 29 #include "ui/events/test/event_generator.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 42 (*flag) = true; | 42 (*flag) = true; |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 class LockStateControllerTest : public AshTestBase { | 47 class LockStateControllerTest : public AshTestBase { |
| 48 public: | 48 public: |
| 49 LockStateControllerTest() | 49 LockStateControllerTest() |
| 50 : power_button_controller_(nullptr), | 50 : power_button_controller_(nullptr), |
| 51 lock_state_controller_(nullptr), | 51 lock_state_controller_(nullptr), |
| 52 lock_state_controller_delegate_(nullptr), | 52 shutdown_client_(nullptr), |
| 53 session_manager_client_(nullptr), | 53 session_manager_client_(nullptr), |
| 54 test_animator_(nullptr) {} | 54 test_animator_(nullptr) {} |
| 55 ~LockStateControllerTest() override {} | 55 ~LockStateControllerTest() override {} |
| 56 | 56 |
| 57 void SetUp() override { | 57 void SetUp() override { |
| 58 session_manager_client_ = new chromeos::FakeSessionManagerClient; | 58 session_manager_client_ = new chromeos::FakeSessionManagerClient; |
| 59 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( | 59 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( |
| 60 base::WrapUnique(session_manager_client_)); | 60 base::WrapUnique(session_manager_client_)); |
| 61 AshTestBase::SetUp(); | 61 AshTestBase::SetUp(); |
| 62 | 62 |
| 63 std::unique_ptr<LockStateControllerDelegate> lock_state_controller_delegate( | 63 std::unique_ptr<TestShutdownClient> shutdown_client( |
| 64 lock_state_controller_delegate_ = new TestLockStateControllerDelegate); | 64 shutdown_client_ = new TestShutdownClient); |
|
James Cook
2016/11/02 20:20:03
nit: This construct made me do a double-take. Plea
Elliot Glaysher
2016/11/02 21:45:16
Done.
| |
| 65 test_animator_ = new TestSessionStateAnimator; | 65 test_animator_ = new TestSessionStateAnimator; |
| 66 | 66 |
| 67 lock_state_controller_ = Shell::GetInstance()->lock_state_controller(); | 67 lock_state_controller_ = Shell::GetInstance()->lock_state_controller(); |
| 68 lock_state_controller_->SetDelegate( | |
| 69 std::move(lock_state_controller_delegate)); | |
| 70 lock_state_controller_->set_animator_for_test(test_animator_); | 68 lock_state_controller_->set_animator_for_test(test_animator_); |
| 71 | 69 |
| 72 test_api_.reset(new LockStateController::TestApi(lock_state_controller_)); | 70 test_api_.reset(new LockStateController::TestApi(lock_state_controller_)); |
| 71 test_api_->SetShutdownClient(std::move(shutdown_client)); | |
| 73 | 72 |
| 74 power_button_controller_ = Shell::GetInstance()->power_button_controller(); | 73 power_button_controller_ = Shell::GetInstance()->power_button_controller(); |
| 75 | 74 |
| 76 shell_delegate_ = | 75 shell_delegate_ = |
| 77 static_cast<TestShellDelegate*>(WmShell::Get()->delegate()); | 76 static_cast<TestShellDelegate*>(WmShell::Get()->delegate()); |
| 78 } | 77 } |
| 79 | 78 |
| 80 void TearDown() override { | 79 void TearDown() override { |
| 81 AshTestBase::TearDown(); | 80 AshTestBase::TearDown(); |
| 82 chromeos::DBusThreadManager::Shutdown(); | 81 chromeos::DBusThreadManager::Shutdown(); |
| 83 } | 82 } |
| 84 | 83 |
| 85 protected: | 84 protected: |
| 86 void GenerateMouseMoveEvent() { | 85 void GenerateMouseMoveEvent() { |
| 87 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 86 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 88 generator.MoveMouseTo(10, 10); | 87 generator.MoveMouseTo(10, 10); |
| 89 } | 88 } |
| 90 | 89 |
| 91 int NumShutdownRequests() { | 90 int NumShutdownRequests() { |
| 92 return lock_state_controller_delegate_->num_shutdown_requests() + | 91 return shutdown_client_->num_shutdown_requests() + |
| 93 shell_delegate_->num_exit_requests(); | 92 shell_delegate_->num_exit_requests(); |
| 94 } | 93 } |
| 95 | 94 |
| 96 void Advance(SessionStateAnimator::AnimationSpeed speed) { | 95 void Advance(SessionStateAnimator::AnimationSpeed speed) { |
| 97 test_animator_->Advance(test_animator_->GetDuration(speed)); | 96 test_animator_->Advance(test_animator_->GetDuration(speed)); |
| 98 } | 97 } |
| 99 | 98 |
| 100 void AdvancePartially(SessionStateAnimator::AnimationSpeed speed, | 99 void AdvancePartially(SessionStateAnimator::AnimationSpeed speed, |
| 101 float factor) { | 100 float factor) { |
| 102 base::TimeDelta duration = test_animator_->GetDuration(speed); | 101 base::TimeDelta duration = test_animator_->GetDuration(speed); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 legacy_button); | 318 legacy_button); |
| 320 lock_state_controller_->OnLoginStateChanged(status); | 319 lock_state_controller_->OnLoginStateChanged(status); |
| 321 SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN); | 320 SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN); |
| 322 if (status == LoginStatus::GUEST) | 321 if (status == LoginStatus::GUEST) |
| 323 TestSessionStateDelegate::SetCanLockScreen(false); | 322 TestSessionStateDelegate::SetCanLockScreen(false); |
| 324 lock_state_controller_->OnLockStateChanged(false); | 323 lock_state_controller_->OnLockStateChanged(false); |
| 325 } | 324 } |
| 326 | 325 |
| 327 PowerButtonController* power_button_controller_; // not owned | 326 PowerButtonController* power_button_controller_; // not owned |
| 328 LockStateController* lock_state_controller_; // not owned | 327 LockStateController* lock_state_controller_; // not owned |
| 329 TestLockStateControllerDelegate* | 328 TestShutdownClient* shutdown_client_; // not owned |
| 330 lock_state_controller_delegate_; // not owned | |
| 331 // Ownership is passed on to chromeos::DBusThreadManager. | 329 // Ownership is passed on to chromeos::DBusThreadManager. |
| 332 chromeos::FakeSessionManagerClient* session_manager_client_; | 330 chromeos::FakeSessionManagerClient* session_manager_client_; |
| 333 TestSessionStateAnimator* test_animator_; // not owned | 331 TestSessionStateAnimator* test_animator_; // not owned |
| 334 std::unique_ptr<LockStateController::TestApi> test_api_; | 332 std::unique_ptr<LockStateController::TestApi> test_api_; |
| 335 TestShellDelegate* shell_delegate_; // not owned | 333 TestShellDelegate* shell_delegate_; // not owned |
| 336 | 334 |
| 337 private: | 335 private: |
| 338 DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest); | 336 DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest); |
| 339 }; | 337 }; |
| 340 | 338 |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1088 ReleasePowerButton(); | 1086 ReleasePowerButton(); |
| 1089 | 1087 |
| 1090 ExpectPreLockAnimationStarted(); | 1088 ExpectPreLockAnimationStarted(); |
| 1091 | 1089 |
| 1092 test_animator_->CompleteAllAnimations(true); | 1090 test_animator_->CompleteAllAnimations(true); |
| 1093 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count()); | 1091 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count()); |
| 1094 } | 1092 } |
| 1095 | 1093 |
| 1096 } // namespace test | 1094 } // namespace test |
| 1097 } // namespace ash | 1095 } // namespace ash |
| OLD | NEW |