| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chromeos/dbus/power_policy_controller.h" | 5 #include "chromeos/dbus/power_policy_controller.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chromeos/dbus/dbus_thread_manager.h" | 8 #include "chromeos/dbus/dbus_thread_manager.h" |
| 9 #include "chromeos/dbus/fake_power_manager_client.h" | 9 #include "chromeos/dbus/fake_power_manager_client.h" |
| 10 #include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.h" | 10 #include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 prefs.use_audio_activity = true; | 53 prefs.use_audio_activity = true; |
| 54 prefs.use_video_activity = true; | 54 prefs.use_video_activity = true; |
| 55 prefs.enable_screen_lock = false; | 55 prefs.enable_screen_lock = false; |
| 56 prefs.presentation_idle_delay_factor = 3.0; | 56 prefs.presentation_idle_delay_factor = 3.0; |
| 57 prefs.user_activity_screen_dim_delay_factor = 2.0; | 57 prefs.user_activity_screen_dim_delay_factor = 2.0; |
| 58 policy_controller_->ApplyPrefs(prefs); | 58 policy_controller_->ApplyPrefs(prefs); |
| 59 | 59 |
| 60 power_manager::PowerManagementPolicy expected_policy; | 60 power_manager::PowerManagementPolicy expected_policy; |
| 61 expected_policy.mutable_ac_delays()->set_screen_dim_ms(600000); | 61 expected_policy.mutable_ac_delays()->set_screen_dim_ms(600000); |
| 62 expected_policy.mutable_ac_delays()->set_screen_off_ms(660000); | 62 expected_policy.mutable_ac_delays()->set_screen_off_ms(660000); |
| 63 expected_policy.mutable_ac_delays()->set_screen_lock_ms(-1); | 63 expected_policy.mutable_ac_delays()->set_screen_lock_ms(0); |
| 64 expected_policy.mutable_ac_delays()->set_idle_warning_ms(-1); | 64 expected_policy.mutable_ac_delays()->set_idle_warning_ms(-1); |
| 65 expected_policy.mutable_ac_delays()->set_idle_ms(720000); | 65 expected_policy.mutable_ac_delays()->set_idle_ms(720000); |
| 66 expected_policy.mutable_battery_delays()->set_screen_dim_ms(300000); | 66 expected_policy.mutable_battery_delays()->set_screen_dim_ms(300000); |
| 67 expected_policy.mutable_battery_delays()->set_screen_off_ms(360000); | 67 expected_policy.mutable_battery_delays()->set_screen_off_ms(360000); |
| 68 expected_policy.mutable_battery_delays()->set_screen_lock_ms(-1); | 68 expected_policy.mutable_battery_delays()->set_screen_lock_ms(0); |
| 69 expected_policy.mutable_battery_delays()->set_idle_warning_ms(-1); | 69 expected_policy.mutable_battery_delays()->set_idle_warning_ms(-1); |
| 70 expected_policy.mutable_battery_delays()->set_idle_ms(420000); | 70 expected_policy.mutable_battery_delays()->set_idle_ms(420000); |
| 71 expected_policy.set_idle_action( | 71 expected_policy.set_idle_action( |
| 72 power_manager::PowerManagementPolicy_Action_SUSPEND); | 72 power_manager::PowerManagementPolicy_Action_SUSPEND); |
| 73 expected_policy.set_lid_closed_action( | 73 expected_policy.set_lid_closed_action( |
| 74 power_manager::PowerManagementPolicy_Action_SHUT_DOWN); | 74 power_manager::PowerManagementPolicy_Action_SHUT_DOWN); |
| 75 expected_policy.set_use_audio_activity(true); | 75 expected_policy.set_use_audio_activity(true); |
| 76 expected_policy.set_use_video_activity(true); | 76 expected_policy.set_use_video_activity(true); |
| 77 expected_policy.set_presentation_idle_delay_factor(3.0); | 77 expected_policy.set_presentation_idle_delay_factor(3.0); |
| 78 expected_policy.set_user_activity_screen_dim_delay_factor(2.0); | 78 expected_policy.set_user_activity_screen_dim_delay_factor(2.0); |
| 79 expected_policy.set_reason("Prefs"); | 79 expected_policy.set_reason("Prefs"); |
| 80 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 80 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
| 81 PowerPolicyController::GetPolicyDebugString( | 81 PowerPolicyController::GetPolicyDebugString( |
| 82 fake_power_client_.get_policy())); | 82 fake_power_client_.get_policy())); |
| 83 | 83 |
| 84 // Change some prefs and check that an updated policy is sent. | 84 // Change some prefs and check that an updated policy is sent. |
| 85 prefs.ac_idle_warning_delay_ms = 700000; | 85 prefs.ac_idle_warning_delay_ms = 700000; |
| 86 prefs.battery_idle_warning_delay_ms = 400000; | 86 prefs.battery_idle_warning_delay_ms = 400000; |
| 87 prefs.lid_closed_action = PowerPolicyController::ACTION_SUSPEND; | 87 prefs.lid_closed_action = PowerPolicyController::ACTION_SUSPEND; |
| 88 policy_controller_->ApplyPrefs(prefs); | 88 policy_controller_->ApplyPrefs(prefs); |
| 89 expected_policy.mutable_ac_delays()->set_idle_warning_ms(700000); | 89 expected_policy.mutable_ac_delays()->set_idle_warning_ms(700000); |
| 90 expected_policy.mutable_battery_delays()->set_idle_warning_ms(400000); | 90 expected_policy.mutable_battery_delays()->set_idle_warning_ms(400000); |
| 91 expected_policy.set_lid_closed_action( | 91 expected_policy.set_lid_closed_action( |
| 92 power_manager::PowerManagementPolicy_Action_SUSPEND); | 92 power_manager::PowerManagementPolicy_Action_SUSPEND); |
| 93 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 93 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
| 94 PowerPolicyController::GetPolicyDebugString( | 94 PowerPolicyController::GetPolicyDebugString( |
| 95 fake_power_client_.get_policy())); | 95 fake_power_client_.get_policy())); |
| 96 | 96 |
| 97 // The enable-screen-lock pref should force the screen-lock delays to | 97 // Screen lock delays should be ignored if the enable-screen-lock pref is |
| 98 // match the screen-off delays. | 98 // false. |
| 99 prefs.enable_screen_lock = true; | 99 prefs.ac_screen_lock_delay_ms = 670000; |
| 100 prefs.battery_screen_lock_delay_ms = 370000; |
| 100 policy_controller_->ApplyPrefs(prefs); | 101 policy_controller_->ApplyPrefs(prefs); |
| 101 expected_policy.mutable_ac_delays()->set_screen_lock_ms(660000); | |
| 102 expected_policy.mutable_battery_delays()->set_screen_lock_ms(360000); | |
| 103 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 102 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
| 104 PowerPolicyController::GetPolicyDebugString( | 103 PowerPolicyController::GetPolicyDebugString( |
| 105 fake_power_client_.get_policy())); | 104 fake_power_client_.get_policy())); |
| 106 | 105 |
| 107 // If the screen-lock-delay prefs are set to lower values than the | 106 // After setting the enable-screen-lock pref, the lock delays should be sent. |
| 108 // screen-off delays, the lock prefs should take precedence. | 107 prefs.enable_screen_lock = true; |
| 109 prefs.ac_screen_lock_delay_ms = 70000; | |
| 110 prefs.battery_screen_lock_delay_ms = 60000; | |
| 111 policy_controller_->ApplyPrefs(prefs); | 108 policy_controller_->ApplyPrefs(prefs); |
| 112 expected_policy.mutable_ac_delays()->set_screen_lock_ms(70000); | 109 expected_policy.mutable_ac_delays()->set_screen_lock_ms(670000); |
| 113 expected_policy.mutable_battery_delays()->set_screen_lock_ms(60000); | 110 expected_policy.mutable_battery_delays()->set_screen_lock_ms(370000); |
| 114 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 111 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
| 115 PowerPolicyController::GetPolicyDebugString( | 112 PowerPolicyController::GetPolicyDebugString( |
| 116 fake_power_client_.get_policy())); | 113 fake_power_client_.get_policy())); |
| 117 | 114 |
| 118 // Set the "allow screen wake locks" pref to false. The system should be | 115 // Set the "allow screen wake locks" pref to false. The system should be |
| 119 // prevented from suspending due to user inactivity but the pref-supplied | 116 // prevented from suspending due to user inactivity but the pref-supplied |
| 120 // screen-related delays should be left untouched. | 117 // screen-related delays should be left untouched. |
| 121 prefs.allow_screen_wake_locks = false; | 118 prefs.allow_screen_wake_locks = false; |
| 122 policy_controller_->ApplyPrefs(prefs); | 119 policy_controller_->ApplyPrefs(prefs); |
| 123 policy_controller_->AddScreenWakeLock("Screen"); | 120 policy_controller_->AddScreenWakeLock("Screen"); |
| 124 expected_policy.set_idle_action( | 121 expected_policy.set_idle_action( |
| 125 power_manager::PowerManagementPolicy_Action_DO_NOTHING); | 122 power_manager::PowerManagementPolicy_Action_DO_NOTHING); |
| 126 expected_policy.set_reason("Prefs, Screen"); | 123 expected_policy.set_reason("Prefs, Screen"); |
| 127 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 124 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
| 128 PowerPolicyController::GetPolicyDebugString( | 125 PowerPolicyController::GetPolicyDebugString( |
| 129 fake_power_client_.get_policy())); | 126 fake_power_client_.get_policy())); |
| 127 |
| 128 // Allow screen wake locks and check that the screen-related delays from |
| 129 // the prefs are overridden. |
| 130 prefs.allow_screen_wake_locks = true; |
| 131 policy_controller_->ApplyPrefs(prefs); |
| 132 expected_policy.mutable_ac_delays()->set_screen_dim_ms(0); |
| 133 expected_policy.mutable_ac_delays()->set_screen_off_ms(0); |
| 134 expected_policy.mutable_ac_delays()->set_screen_lock_ms(0); |
| 135 expected_policy.mutable_battery_delays()->set_screen_dim_ms(0); |
| 136 expected_policy.mutable_battery_delays()->set_screen_off_ms(0); |
| 137 expected_policy.mutable_battery_delays()->set_screen_lock_ms(0); |
| 138 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
| 139 PowerPolicyController::GetPolicyDebugString( |
| 140 fake_power_client_.get_policy())); |
| 130 } | 141 } |
| 131 | 142 |
| 132 TEST_F(PowerPolicyControllerTest, WakeLocks) { | 143 TEST_F(PowerPolicyControllerTest, WakeLocks) { |
| 133 const char kSystemWakeLockReason[] = "system"; | 144 const char kSystemWakeLockReason[] = "system"; |
| 134 const int system_id = | 145 const int system_id = |
| 135 policy_controller_->AddSystemWakeLock(kSystemWakeLockReason); | 146 policy_controller_->AddSystemWakeLock(kSystemWakeLockReason); |
| 136 power_manager::PowerManagementPolicy expected_policy; | 147 power_manager::PowerManagementPolicy expected_policy; |
| 137 expected_policy.set_idle_action( | 148 expected_policy.set_idle_action( |
| 138 power_manager::PowerManagementPolicy_Action_DO_NOTHING); | 149 power_manager::PowerManagementPolicy_Action_DO_NOTHING); |
| 139 expected_policy.set_reason(kSystemWakeLockReason); | 150 expected_policy.set_reason(kSystemWakeLockReason); |
| 140 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 151 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
| 141 PowerPolicyController::GetPolicyDebugString( | 152 PowerPolicyController::GetPolicyDebugString( |
| 142 fake_power_client_.get_policy())); | 153 fake_power_client_.get_policy())); |
| 143 | 154 |
| 144 const char kScreenWakeLockReason[] = "screen"; | 155 const char kScreenWakeLockReason[] = "screen"; |
| 145 const int screen_id = policy_controller_->AddScreenWakeLock( | 156 const int screen_id = policy_controller_->AddScreenWakeLock( |
| 146 kScreenWakeLockReason); | 157 kScreenWakeLockReason); |
| 147 expected_policy.mutable_ac_delays()->set_screen_dim_ms(0); | 158 expected_policy.mutable_ac_delays()->set_screen_dim_ms(0); |
| 148 expected_policy.mutable_ac_delays()->set_screen_off_ms(0); | 159 expected_policy.mutable_ac_delays()->set_screen_off_ms(0); |
| 160 expected_policy.mutable_ac_delays()->set_screen_lock_ms(0); |
| 149 expected_policy.mutable_battery_delays()->set_screen_dim_ms(0); | 161 expected_policy.mutable_battery_delays()->set_screen_dim_ms(0); |
| 150 expected_policy.mutable_battery_delays()->set_screen_off_ms(0); | 162 expected_policy.mutable_battery_delays()->set_screen_off_ms(0); |
| 163 expected_policy.mutable_battery_delays()->set_screen_lock_ms(0); |
| 151 expected_policy.set_reason( | 164 expected_policy.set_reason( |
| 152 std::string(kScreenWakeLockReason) + ", " + kSystemWakeLockReason); | 165 std::string(kScreenWakeLockReason) + ", " + kSystemWakeLockReason); |
| 153 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 166 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
| 154 PowerPolicyController::GetPolicyDebugString( | 167 PowerPolicyController::GetPolicyDebugString( |
| 155 fake_power_client_.get_policy())); | 168 fake_power_client_.get_policy())); |
| 156 | 169 |
| 157 policy_controller_->RemoveWakeLock(system_id); | 170 policy_controller_->RemoveWakeLock(system_id); |
| 158 expected_policy.set_reason(kScreenWakeLockReason); | 171 expected_policy.set_reason(kScreenWakeLockReason); |
| 159 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 172 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
| 160 PowerPolicyController::GetPolicyDebugString( | 173 PowerPolicyController::GetPolicyDebugString( |
| 161 fake_power_client_.get_policy())); | 174 fake_power_client_.get_policy())); |
| 162 | 175 |
| 163 policy_controller_->RemoveWakeLock(screen_id); | 176 policy_controller_->RemoveWakeLock(screen_id); |
| 164 expected_policy.Clear(); | 177 expected_policy.Clear(); |
| 165 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 178 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
| 166 PowerPolicyController::GetPolicyDebugString( | 179 PowerPolicyController::GetPolicyDebugString( |
| 167 fake_power_client_.get_policy())); | 180 fake_power_client_.get_policy())); |
| 168 } | 181 } |
| 169 | 182 |
| 170 } // namespace chromeos | 183 } // namespace chromeos |
| OLD | NEW |