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/wm_shell.h" | |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 12 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/test/test_lock_state_controller_delegate.h" | 14 #include "ash/test/test_lock_state_controller_delegate.h" |
| 14 #include "ash/test/test_screenshot_delegate.h" | 15 #include "ash/test/test_screenshot_delegate.h" |
| 15 #include "ash/test/test_session_state_animator.h" | 16 #include "ash/test/test_session_state_animator.h" |
| 16 #include "ash/test/test_shell_delegate.h" | 17 #include "ash/test/test_shell_delegate.h" |
| 17 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 18 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| 18 #include "ash/wm/power_button_controller.h" | 19 #include "ash/wm/power_button_controller.h" |
| 19 #include "ash/wm/session_state_animator.h" | 20 #include "ash/wm/session_state_animator.h" |
| 20 #include "base/memory/scoped_vector.h" | 21 #include "base/memory/scoped_vector.h" |
| 21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 22 #include "ui/events/test/event_generator.h" | 23 #include "ui/events/test/event_generator.h" |
| 23 #include "ui/gfx/geometry/size.h" | 24 #include "ui/gfx/geometry/size.h" |
| 24 | 25 |
| 25 #if defined(OS_CHROMEOS) | 26 #if defined(OS_CHROMEOS) |
| 26 #include "ui/display/chromeos/display_configurator.h" | 27 #include "ui/display/chromeos/display_configurator.h" |
| 27 #include "ui/display/chromeos/test/test_display_snapshot.h" | 28 #include "ui/display/chromeos/test/test_display_snapshot.h" |
| 28 #include "ui/display/types/display_constants.h" | 29 #include "ui/display/types/display_constants.h" |
| 29 #endif | 30 #endif |
| 30 | 31 |
| 31 namespace ash { | 32 namespace ash { |
| 32 namespace test { | 33 namespace test { |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 bool cursor_visible() { | 36 bool cursor_visible() { |
| 36 return ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible(); | 37 return Shell::GetInstance()->cursor_manager()->IsCursorVisible(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 void CheckCalledCallback(bool* flag) { | 40 void CheckCalledCallback(bool* flag) { |
| 40 if (flag) | 41 if (flag) |
| 41 (*flag) = true; | 42 (*flag) = true; |
| 42 } | 43 } |
| 43 | 44 |
| 44 } // namespace | 45 } // namespace |
| 45 | 46 |
| 46 class LockStateControllerTest : public AshTestBase { | 47 class LockStateControllerTest : public AshTestBase { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 60 test_animator_ = new TestSessionStateAnimator; | 61 test_animator_ = new TestSessionStateAnimator; |
| 61 | 62 |
| 62 lock_state_controller_ = Shell::GetInstance()->lock_state_controller(); | 63 lock_state_controller_ = Shell::GetInstance()->lock_state_controller(); |
| 63 lock_state_controller_->SetDelegate( | 64 lock_state_controller_->SetDelegate( |
| 64 std::move(lock_state_controller_delegate)); | 65 std::move(lock_state_controller_delegate)); |
| 65 lock_state_controller_->set_animator_for_test(test_animator_); | 66 lock_state_controller_->set_animator_for_test(test_animator_); |
| 66 | 67 |
| 67 test_api_.reset(new LockStateController::TestApi(lock_state_controller_)); | 68 test_api_.reset(new LockStateController::TestApi(lock_state_controller_)); |
| 68 | 69 |
| 69 power_button_controller_ = Shell::GetInstance()->power_button_controller(); | 70 power_button_controller_ = Shell::GetInstance()->power_button_controller(); |
| 70 session_state_delegate_ = Shell::GetInstance()->session_state_delegate(); | |
| 71 | 71 |
| 72 shell_delegate_ = reinterpret_cast<TestShellDelegate*>( | 72 shell_delegate_ = |
| 73 ash::Shell::GetInstance()->delegate()); | 73 reinterpret_cast<TestShellDelegate*>(Shell::GetInstance()->delegate()); |
|
James Cook
2016/06/29 21:12:23
optional: I wonder if static_cast<> would work her
msw
2016/06/29 21:43:34
Done.
| |
| 74 } | 74 } |
| 75 | 75 |
| 76 protected: | 76 protected: |
| 77 void GenerateMouseMoveEvent() { | 77 void GenerateMouseMoveEvent() { |
| 78 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 78 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 79 generator.MoveMouseTo(10, 10); | 79 generator.MoveMouseTo(10, 10); |
| 80 } | 80 } |
| 81 | 81 |
| 82 int NumShutdownRequests() { | 82 int NumShutdownRequests() { |
| 83 return lock_state_controller_delegate_->num_shutdown_requests() + | 83 return lock_state_controller_delegate_->num_shutdown_requests() + |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 SCOPED_TRACE("Failure in ExpectRestoringBackgroundVisibility"); | 243 SCOPED_TRACE("Failure in ExpectRestoringBackgroundVisibility"); |
| 244 EXPECT_LT(0u, test_animator_->GetAnimationCount()); | 244 EXPECT_LT(0u, test_animator_->GetAnimationCount()); |
| 245 EXPECT_TRUE(test_animator_->AreContainersAnimated( | 245 EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 246 SessionStateAnimator::DESKTOP_BACKGROUND, | 246 SessionStateAnimator::DESKTOP_BACKGROUND, |
| 247 SessionStateAnimator::ANIMATION_FADE_IN)); | 247 SessionStateAnimator::ANIMATION_FADE_IN)); |
| 248 } | 248 } |
| 249 | 249 |
| 250 void ExpectUnlockedState() { | 250 void ExpectUnlockedState() { |
| 251 SCOPED_TRACE("Failure in ExpectUnlockedState"); | 251 SCOPED_TRACE("Failure in ExpectUnlockedState"); |
| 252 EXPECT_EQ(0u, test_animator_->GetAnimationCount()); | 252 EXPECT_EQ(0u, test_animator_->GetAnimationCount()); |
| 253 EXPECT_FALSE(session_state_delegate_->IsScreenLocked()); | 253 EXPECT_FALSE(WmShell::Get()->GetSessionStateDelegate()->IsScreenLocked()); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void ExpectLockedState() { | 256 void ExpectLockedState() { |
| 257 SCOPED_TRACE("Failure in ExpectLockedState"); | 257 SCOPED_TRACE("Failure in ExpectLockedState"); |
| 258 EXPECT_EQ(0u, test_animator_->GetAnimationCount()); | 258 EXPECT_EQ(0u, test_animator_->GetAnimationCount()); |
| 259 EXPECT_TRUE(session_state_delegate_->IsScreenLocked()); | 259 EXPECT_TRUE(WmShell::Get()->GetSessionStateDelegate()->IsScreenLocked()); |
| 260 } | 260 } |
| 261 | 261 |
| 262 void HideBackground() { test_animator_->HideBackground(); } | 262 void HideBackground() { test_animator_->HideBackground(); } |
| 263 | 263 |
| 264 void PressPowerButton() { | 264 void PressPowerButton() { |
| 265 power_button_controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 265 power_button_controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void ReleasePowerButton() { | 268 void ReleasePowerButton() { |
| 269 power_button_controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 269 power_button_controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 280 void PressVolumeDown() { | 280 void PressVolumeDown() { |
| 281 GetEventGenerator().PressKey(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); | 281 GetEventGenerator().PressKey(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); |
| 282 } | 282 } |
| 283 | 283 |
| 284 void ReleaseVolumeDown() { | 284 void ReleaseVolumeDown() { |
| 285 GetEventGenerator().ReleaseKey(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); | 285 GetEventGenerator().ReleaseKey(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); |
| 286 } | 286 } |
| 287 | 287 |
| 288 void SystemLocks() { | 288 void SystemLocks() { |
| 289 lock_state_controller_->OnLockStateChanged(true); | 289 lock_state_controller_->OnLockStateChanged(true); |
| 290 session_state_delegate_->LockScreen(); | 290 WmShell::Get()->GetSessionStateDelegate()->LockScreen(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void SuccessfulAuthentication(bool* call_flag) { | 293 void SuccessfulAuthentication(bool* call_flag) { |
| 294 base::Closure closure = base::Bind(&CheckCalledCallback, call_flag); | 294 base::Closure closure = base::Bind(&CheckCalledCallback, call_flag); |
| 295 lock_state_controller_->OnLockScreenHide(closure); | 295 lock_state_controller_->OnLockScreenHide(closure); |
| 296 } | 296 } |
| 297 | 297 |
| 298 void SystemUnlocks() { | 298 void SystemUnlocks() { |
| 299 lock_state_controller_->OnLockStateChanged(false); | 299 lock_state_controller_->OnLockStateChanged(false); |
| 300 session_state_delegate_->UnlockScreen(); | 300 WmShell::Get()->GetSessionStateDelegate()->UnlockScreen(); |
| 301 } | 301 } |
| 302 | 302 |
| 303 void EnableMaximizeMode(bool enable) { | 303 void EnableMaximizeMode(bool enable) { |
| 304 Shell::GetInstance() | 304 Shell::GetInstance() |
| 305 ->maximize_mode_controller() | 305 ->maximize_mode_controller() |
| 306 ->EnableMaximizeModeWindowManager(enable); | 306 ->EnableMaximizeModeWindowManager(enable); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void Initialize(bool legacy_button, LoginStatus status) { | 309 void Initialize(bool legacy_button, LoginStatus status) { |
| 310 power_button_controller_->set_has_legacy_power_button_for_test( | 310 power_button_controller_->set_has_legacy_power_button_for_test( |
| 311 legacy_button); | 311 legacy_button); |
| 312 lock_state_controller_->OnLoginStateChanged(status); | 312 lock_state_controller_->OnLoginStateChanged(status); |
| 313 SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN); | 313 SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN); |
| 314 if (status == LoginStatus::GUEST) | 314 if (status == LoginStatus::GUEST) |
| 315 SetCanLockScreen(false); | 315 SetCanLockScreen(false); |
| 316 lock_state_controller_->OnLockStateChanged(false); | 316 lock_state_controller_->OnLockStateChanged(false); |
| 317 } | 317 } |
| 318 | 318 |
| 319 PowerButtonController* power_button_controller_; // not owned | 319 PowerButtonController* power_button_controller_; // not owned |
| 320 LockStateController* lock_state_controller_; // not owned | 320 LockStateController* lock_state_controller_; // not owned |
| 321 TestLockStateControllerDelegate* | 321 TestLockStateControllerDelegate* |
| 322 lock_state_controller_delegate_; // not owned | 322 lock_state_controller_delegate_; // not owned |
| 323 TestSessionStateAnimator* test_animator_; // not owned | 323 TestSessionStateAnimator* test_animator_; // not owned |
| 324 SessionStateDelegate* session_state_delegate_; // not owned | |
| 325 std::unique_ptr<LockStateController::TestApi> test_api_; | 324 std::unique_ptr<LockStateController::TestApi> test_api_; |
| 326 TestShellDelegate* shell_delegate_; // not owned | 325 TestShellDelegate* shell_delegate_; // not owned |
| 327 | 326 |
| 328 private: | 327 private: |
| 329 DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest); | 328 DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest); |
| 330 }; | 329 }; |
| 331 | 330 |
| 332 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't | 331 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't |
| 333 // correctly report power button releases. We should lock immediately the first | 332 // correctly report power button releases. We should lock immediately the first |
| 334 // time the button is pressed and shut down when it's pressed from the locked | 333 // time the button is pressed and shut down when it's pressed from the locked |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1081 ReleasePowerButton(); | 1080 ReleasePowerButton(); |
| 1082 | 1081 |
| 1083 ExpectPreLockAnimationStarted(); | 1082 ExpectPreLockAnimationStarted(); |
| 1084 | 1083 |
| 1085 test_animator_->CompleteAllAnimations(true); | 1084 test_animator_->CompleteAllAnimations(true); |
| 1086 EXPECT_EQ(1, lock_state_controller_delegate_->num_lock_requests()); | 1085 EXPECT_EQ(1, lock_state_controller_delegate_->num_lock_requests()); |
| 1087 } | 1086 } |
| 1088 | 1087 |
| 1089 } // namespace test | 1088 } // namespace test |
| 1090 } // namespace ash | 1089 } // namespace ash |
| OLD | NEW |