| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/system/chromeos/power/tablet_power_button_controller.h" | 5 #include "ash/system/chromeos/power/tablet_power_button_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/common/ash_switches.h" | 9 #include "ash/common/ash_switches.h" |
| 10 #include "ash/common/session/session_state_delegate.h" | 10 #include "ash/common/session/session_controller.h" |
| 11 #include "ash/common/test/test_session_controller_client.h" |
| 11 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 12 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 12 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
| 13 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 14 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
| 15 #include "ash/test/lock_state_controller_test_api.h" | 16 #include "ash/test/lock_state_controller_test_api.h" |
| 16 #include "ash/test/test_shell_delegate.h" | 17 #include "ash/test/test_shell_delegate.h" |
| 17 #include "ash/wm/lock_state_controller.h" | 18 #include "ash/wm/lock_state_controller.h" |
| 18 #include "ash/wm/power_button_controller.h" | 19 #include "ash/wm/power_button_controller.h" |
| 19 #include "base/command_line.h" | 20 #include "base/command_line.h" |
| 20 #include "base/compiler_specific.h" | 21 #include "base/compiler_specific.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 void PressPowerButton() { | 87 void PressPowerButton() { |
| 87 tablet_controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 88 tablet_controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void ReleasePowerButton() { | 91 void ReleasePowerButton() { |
| 91 tablet_controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 92 tablet_controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 92 } | 93 } |
| 93 | 94 |
| 94 void UnlockScreen() { | 95 void UnlockScreen() { |
| 95 lock_state_controller_->OnLockStateChanged(false); | 96 lock_state_controller_->OnLockStateChanged(false); |
| 96 WmShell::Get()->GetSessionStateDelegate()->UnlockScreen(); | 97 GetSessionControllerClient()->UnlockScreen(); |
| 97 } | 98 } |
| 98 | 99 |
| 99 void Initialize(LoginStatus status) { | 100 void Initialize(LoginStatus status) { |
| 100 lock_state_controller_->OnLoginStateChanged(status); | 101 lock_state_controller_->OnLoginStateChanged(status); |
| 101 SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN); | 102 SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN); |
| 102 lock_state_controller_->OnLockStateChanged(false); | 103 lock_state_controller_->OnLockStateChanged(false); |
| 103 } | 104 } |
| 104 | 105 |
| 105 void EnableMaximizeMode(bool enabled) { | 106 void EnableMaximizeMode(bool enabled) { |
| 106 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 107 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 107 enabled); | 108 enabled); |
| 108 } | 109 } |
| 109 | 110 |
| 110 bool GetLockedState() { | 111 bool GetLockedState() { |
| 111 return WmShell::Get()->GetSessionStateDelegate()->IsScreenLocked(); | 112 // LockScreen is an async mojo call. Spin message loop to ensure it is |
| 113 // delivered. |
| 114 SessionController* const session_controller = |
| 115 WmShell::Get()->session_controller(); |
| 116 session_controller->FlushMojoForTest(); |
| 117 return session_controller->IsScreenLocked(); |
| 112 } | 118 } |
| 113 | 119 |
| 114 bool GetBacklightsForcedOff() WARN_UNUSED_RESULT { | 120 bool GetBacklightsForcedOff() WARN_UNUSED_RESULT { |
| 115 bool forced_off = false; | 121 bool forced_off = false; |
| 116 power_manager_client_->GetBacklightsForcedOff( | 122 power_manager_client_->GetBacklightsForcedOff( |
| 117 base::Bind(&CopyResult, base::Unretained(&forced_off))); | 123 base::Bind(&CopyResult, base::Unretained(&forced_off))); |
| 118 base::RunLoop().RunUntilIdle(); | 124 base::RunLoop().RunUntilIdle(); |
| 119 return forced_off; | 125 return forced_off; |
| 120 } | 126 } |
| 121 | 127 |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 // Test that after another long duration, backlights should be forced off. | 478 // Test that after another long duration, backlights should be forced off. |
| 473 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(800)); | 479 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(800)); |
| 474 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); | 480 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); |
| 475 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); | 481 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); |
| 476 power_manager_client_->SendBrightnessChanged(0, false); | 482 power_manager_client_->SendBrightnessChanged(0, false); |
| 477 EXPECT_TRUE(GetBacklightsForcedOff()); | 483 EXPECT_TRUE(GetBacklightsForcedOff()); |
| 478 } | 484 } |
| 479 | 485 |
| 480 } // namespace test | 486 } // namespace test |
| 481 } // namespace ash | 487 } // namespace ash |
| OLD | NEW |