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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // The enable-screen-lock pref should force the screen-lock delays to |
98 // match the screen-off delays. | 98 // match the screen-off delays plus a constant value. |
99 prefs.enable_screen_lock = true; | 99 prefs.enable_screen_lock = true; |
100 policy_controller_->ApplyPrefs(prefs); | 100 policy_controller_->ApplyPrefs(prefs); |
101 expected_policy.mutable_ac_delays()->set_screen_lock_ms(660000); | 101 expected_policy.mutable_ac_delays()->set_screen_lock_ms( |
102 expected_policy.mutable_battery_delays()->set_screen_lock_ms(360000); | 102 660000 + PowerPolicyController::kScreenLockAfterOffDelayMs); |
| 103 expected_policy.mutable_battery_delays()->set_screen_lock_ms( |
| 104 360000 + PowerPolicyController::kScreenLockAfterOffDelayMs); |
103 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 105 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
104 PowerPolicyController::GetPolicyDebugString( | 106 PowerPolicyController::GetPolicyDebugString( |
105 fake_power_client_.get_policy())); | 107 fake_power_client_.get_policy())); |
106 | 108 |
107 // If the screen-lock-delay prefs are set to lower values than the | 109 // If the screen-lock-delay prefs are set to lower values than the |
108 // screen-off delays, the lock prefs should take precedence. | 110 // screen-off delays plus the constant, the lock prefs should take |
| 111 // precedence. |
109 prefs.ac_screen_lock_delay_ms = 70000; | 112 prefs.ac_screen_lock_delay_ms = 70000; |
110 prefs.battery_screen_lock_delay_ms = 60000; | 113 prefs.battery_screen_lock_delay_ms = 60000; |
111 policy_controller_->ApplyPrefs(prefs); | 114 policy_controller_->ApplyPrefs(prefs); |
112 expected_policy.mutable_ac_delays()->set_screen_lock_ms(70000); | 115 expected_policy.mutable_ac_delays()->set_screen_lock_ms(70000); |
113 expected_policy.mutable_battery_delays()->set_screen_lock_ms(60000); | 116 expected_policy.mutable_battery_delays()->set_screen_lock_ms(60000); |
114 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 117 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
115 PowerPolicyController::GetPolicyDebugString( | 118 PowerPolicyController::GetPolicyDebugString( |
116 fake_power_client_.get_policy())); | 119 fake_power_client_.get_policy())); |
117 | 120 |
| 121 // If the artificial screen-lock delays would exceed the idle delay, they |
| 122 // shouldn't be set -- the power manager would ignore them since the |
| 123 // idle action should lock the screen in this case. |
| 124 prefs.ac_screen_off_delay_ms = prefs.ac_idle_delay_ms - 1; |
| 125 prefs.battery_screen_off_delay_ms = prefs.battery_idle_delay_ms - 1; |
| 126 prefs.ac_screen_lock_delay_ms = -1; |
| 127 prefs.battery_screen_lock_delay_ms = -1; |
| 128 policy_controller_->ApplyPrefs(prefs); |
| 129 expected_policy.mutable_ac_delays()->set_screen_off_ms( |
| 130 prefs.ac_screen_off_delay_ms); |
| 131 expected_policy.mutable_battery_delays()->set_screen_off_ms( |
| 132 prefs.battery_screen_off_delay_ms); |
| 133 expected_policy.mutable_ac_delays()->set_screen_lock_ms(-1); |
| 134 expected_policy.mutable_battery_delays()->set_screen_lock_ms(-1); |
| 135 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
| 136 PowerPolicyController::GetPolicyDebugString( |
| 137 fake_power_client_.get_policy())); |
| 138 |
118 // Set the "allow screen wake locks" pref to false. The system should be | 139 // 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 | 140 // prevented from suspending due to user inactivity but the pref-supplied |
120 // screen-related delays should be left untouched. | 141 // screen-related delays should be left untouched. |
121 prefs.allow_screen_wake_locks = false; | 142 prefs.allow_screen_wake_locks = false; |
122 policy_controller_->ApplyPrefs(prefs); | 143 policy_controller_->ApplyPrefs(prefs); |
123 policy_controller_->AddScreenWakeLock("Screen"); | 144 policy_controller_->AddScreenWakeLock("Screen"); |
124 expected_policy.set_idle_action( | 145 expected_policy.set_idle_action( |
125 power_manager::PowerManagementPolicy_Action_DO_NOTHING); | 146 power_manager::PowerManagementPolicy_Action_DO_NOTHING); |
126 expected_policy.set_reason("Prefs, Screen"); | 147 expected_policy.set_reason("Prefs, Screen"); |
127 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 148 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
(...skipping 11 matching lines...) Expand all Loading... |
139 expected_policy.set_reason(kSystemWakeLockReason); | 160 expected_policy.set_reason(kSystemWakeLockReason); |
140 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 161 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
141 PowerPolicyController::GetPolicyDebugString( | 162 PowerPolicyController::GetPolicyDebugString( |
142 fake_power_client_.get_policy())); | 163 fake_power_client_.get_policy())); |
143 | 164 |
144 const char kScreenWakeLockReason[] = "screen"; | 165 const char kScreenWakeLockReason[] = "screen"; |
145 const int screen_id = policy_controller_->AddScreenWakeLock( | 166 const int screen_id = policy_controller_->AddScreenWakeLock( |
146 kScreenWakeLockReason); | 167 kScreenWakeLockReason); |
147 expected_policy.mutable_ac_delays()->set_screen_dim_ms(0); | 168 expected_policy.mutable_ac_delays()->set_screen_dim_ms(0); |
148 expected_policy.mutable_ac_delays()->set_screen_off_ms(0); | 169 expected_policy.mutable_ac_delays()->set_screen_off_ms(0); |
| 170 expected_policy.mutable_ac_delays()->set_screen_lock_ms(0); |
149 expected_policy.mutable_battery_delays()->set_screen_dim_ms(0); | 171 expected_policy.mutable_battery_delays()->set_screen_dim_ms(0); |
150 expected_policy.mutable_battery_delays()->set_screen_off_ms(0); | 172 expected_policy.mutable_battery_delays()->set_screen_off_ms(0); |
| 173 expected_policy.mutable_battery_delays()->set_screen_lock_ms(0); |
151 expected_policy.set_reason( | 174 expected_policy.set_reason( |
152 std::string(kScreenWakeLockReason) + ", " + kSystemWakeLockReason); | 175 std::string(kScreenWakeLockReason) + ", " + kSystemWakeLockReason); |
153 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 176 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
154 PowerPolicyController::GetPolicyDebugString( | 177 PowerPolicyController::GetPolicyDebugString( |
155 fake_power_client_.get_policy())); | 178 fake_power_client_.get_policy())); |
156 | 179 |
157 policy_controller_->RemoveWakeLock(system_id); | 180 policy_controller_->RemoveWakeLock(system_id); |
158 expected_policy.set_reason(kScreenWakeLockReason); | 181 expected_policy.set_reason(kScreenWakeLockReason); |
159 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 182 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
160 PowerPolicyController::GetPolicyDebugString( | 183 PowerPolicyController::GetPolicyDebugString( |
161 fake_power_client_.get_policy())); | 184 fake_power_client_.get_policy())); |
162 | 185 |
163 policy_controller_->RemoveWakeLock(screen_id); | 186 policy_controller_->RemoveWakeLock(screen_id); |
164 expected_policy.Clear(); | 187 expected_policy.Clear(); |
165 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 188 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
166 PowerPolicyController::GetPolicyDebugString( | 189 PowerPolicyController::GetPolicyDebugString( |
167 fake_power_client_.get_policy())); | 190 fake_power_client_.get_policy())); |
168 } | 191 } |
169 | 192 |
170 } // namespace chromeos | 193 } // namespace chromeos |
OLD | NEW |