Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: chromeos/dbus/power_policy_controller_unittest.cc

Issue 129193002: Revert of chromeos: Don't send empty power management policies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos/dbus/power_policy_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_dbus_thread_manager.h" 9 #include "chromeos/dbus/fake_dbus_thread_manager.h"
10 #include "chromeos/dbus/fake_power_manager_client.h" 10 #include "chromeos/dbus/fake_power_manager_client.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 expected_policy.set_use_audio_activity(true); 84 expected_policy.set_use_audio_activity(true);
85 expected_policy.set_use_video_activity(true); 85 expected_policy.set_use_video_activity(true);
86 expected_policy.set_ac_brightness_percent(87.0); 86 expected_policy.set_ac_brightness_percent(87.0);
87 expected_policy.set_battery_brightness_percent(43.0); 87 expected_policy.set_battery_brightness_percent(43.0);
88 expected_policy.set_presentation_screen_dim_delay_factor(3.0); 88 expected_policy.set_presentation_screen_dim_delay_factor(3.0);
89 expected_policy.set_user_activity_screen_dim_delay_factor(2.0); 89 expected_policy.set_user_activity_screen_dim_delay_factor(2.0);
90 expected_policy.set_wait_for_initial_user_activity(true); 90 expected_policy.set_wait_for_initial_user_activity(true);
91 expected_policy.set_reason("Prefs"); 91 expected_policy.set_reason("Prefs");
92 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), 92 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
93 PowerPolicyController::GetPolicyDebugString( 93 PowerPolicyController::GetPolicyDebugString(
94 fake_power_client_->policy())); 94 fake_power_client_->get_policy()));
95 95
96 // Change some prefs and check that an updated policy is sent. 96 // Change some prefs and check that an updated policy is sent.
97 prefs.ac_idle_warning_delay_ms = 700000; 97 prefs.ac_idle_warning_delay_ms = 700000;
98 prefs.battery_idle_warning_delay_ms = 400000; 98 prefs.battery_idle_warning_delay_ms = 400000;
99 prefs.lid_closed_action = PowerPolicyController::ACTION_SUSPEND; 99 prefs.lid_closed_action = PowerPolicyController::ACTION_SUSPEND;
100 prefs.ac_brightness_percent = -1.0; 100 prefs.ac_brightness_percent = -1.0;
101 policy_controller_->ApplyPrefs(prefs); 101 policy_controller_->ApplyPrefs(prefs);
102 expected_policy.mutable_ac_delays()->set_idle_warning_ms(700000); 102 expected_policy.mutable_ac_delays()->set_idle_warning_ms(700000);
103 expected_policy.mutable_battery_delays()->set_idle_warning_ms(400000); 103 expected_policy.mutable_battery_delays()->set_idle_warning_ms(400000);
104 expected_policy.set_lid_closed_action( 104 expected_policy.set_lid_closed_action(
105 power_manager::PowerManagementPolicy_Action_SUSPEND); 105 power_manager::PowerManagementPolicy_Action_SUSPEND);
106 expected_policy.clear_ac_brightness_percent(); 106 expected_policy.clear_ac_brightness_percent();
107 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), 107 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
108 PowerPolicyController::GetPolicyDebugString( 108 PowerPolicyController::GetPolicyDebugString(
109 fake_power_client_->policy())); 109 fake_power_client_->get_policy()));
110 110
111 // The enable-screen-lock pref should force the screen-lock delays to 111 // The enable-screen-lock pref should force the screen-lock delays to
112 // match the screen-off delays plus a constant value. 112 // match the screen-off delays plus a constant value.
113 prefs.enable_screen_lock = true; 113 prefs.enable_screen_lock = true;
114 policy_controller_->ApplyPrefs(prefs); 114 policy_controller_->ApplyPrefs(prefs);
115 expected_policy.mutable_ac_delays()->set_screen_lock_ms( 115 expected_policy.mutable_ac_delays()->set_screen_lock_ms(
116 660000 + PowerPolicyController::kScreenLockAfterOffDelayMs); 116 660000 + PowerPolicyController::kScreenLockAfterOffDelayMs);
117 expected_policy.mutable_battery_delays()->set_screen_lock_ms( 117 expected_policy.mutable_battery_delays()->set_screen_lock_ms(
118 360000 + PowerPolicyController::kScreenLockAfterOffDelayMs); 118 360000 + PowerPolicyController::kScreenLockAfterOffDelayMs);
119 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), 119 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
120 PowerPolicyController::GetPolicyDebugString( 120 PowerPolicyController::GetPolicyDebugString(
121 fake_power_client_->policy())); 121 fake_power_client_->get_policy()));
122 122
123 // If the screen-lock-delay prefs are set to lower values than the 123 // If the screen-lock-delay prefs are set to lower values than the
124 // screen-off delays plus the constant, the lock prefs should take 124 // screen-off delays plus the constant, the lock prefs should take
125 // precedence. 125 // precedence.
126 prefs.ac_screen_lock_delay_ms = 70000; 126 prefs.ac_screen_lock_delay_ms = 70000;
127 prefs.battery_screen_lock_delay_ms = 60000; 127 prefs.battery_screen_lock_delay_ms = 60000;
128 policy_controller_->ApplyPrefs(prefs); 128 policy_controller_->ApplyPrefs(prefs);
129 expected_policy.mutable_ac_delays()->set_screen_lock_ms(70000); 129 expected_policy.mutable_ac_delays()->set_screen_lock_ms(70000);
130 expected_policy.mutable_battery_delays()->set_screen_lock_ms(60000); 130 expected_policy.mutable_battery_delays()->set_screen_lock_ms(60000);
131 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), 131 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
132 PowerPolicyController::GetPolicyDebugString( 132 PowerPolicyController::GetPolicyDebugString(
133 fake_power_client_->policy())); 133 fake_power_client_->get_policy()));
134 134
135 // If the artificial screen-lock delays would exceed the idle delay, they 135 // If the artificial screen-lock delays would exceed the idle delay, they
136 // shouldn't be set -- the power manager would ignore them since the 136 // shouldn't be set -- the power manager would ignore them since the
137 // idle action should lock the screen in this case. 137 // idle action should lock the screen in this case.
138 prefs.ac_screen_off_delay_ms = prefs.ac_idle_delay_ms - 1; 138 prefs.ac_screen_off_delay_ms = prefs.ac_idle_delay_ms - 1;
139 prefs.battery_screen_off_delay_ms = prefs.battery_idle_delay_ms - 1; 139 prefs.battery_screen_off_delay_ms = prefs.battery_idle_delay_ms - 1;
140 prefs.ac_screen_lock_delay_ms = -1; 140 prefs.ac_screen_lock_delay_ms = -1;
141 prefs.battery_screen_lock_delay_ms = -1; 141 prefs.battery_screen_lock_delay_ms = -1;
142 policy_controller_->ApplyPrefs(prefs); 142 policy_controller_->ApplyPrefs(prefs);
143 expected_policy.mutable_ac_delays()->set_screen_off_ms( 143 expected_policy.mutable_ac_delays()->set_screen_off_ms(
144 prefs.ac_screen_off_delay_ms); 144 prefs.ac_screen_off_delay_ms);
145 expected_policy.mutable_battery_delays()->set_screen_off_ms( 145 expected_policy.mutable_battery_delays()->set_screen_off_ms(
146 prefs.battery_screen_off_delay_ms); 146 prefs.battery_screen_off_delay_ms);
147 expected_policy.mutable_ac_delays()->set_screen_lock_ms(-1); 147 expected_policy.mutable_ac_delays()->set_screen_lock_ms(-1);
148 expected_policy.mutable_battery_delays()->set_screen_lock_ms(-1); 148 expected_policy.mutable_battery_delays()->set_screen_lock_ms(-1);
149 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), 149 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
150 PowerPolicyController::GetPolicyDebugString( 150 PowerPolicyController::GetPolicyDebugString(
151 fake_power_client_->policy())); 151 fake_power_client_->get_policy()));
152 152
153 // Set the "allow screen wake locks" pref to false. The system should be 153 // Set the "allow screen wake locks" pref to false. The system should be
154 // prevented from suspending due to user inactivity on AC power but the 154 // prevented from suspending due to user inactivity on AC power but the
155 // pref-supplied screen-related delays should be left untouched. 155 // pref-supplied screen-related delays should be left untouched.
156 prefs.allow_screen_wake_locks = false; 156 prefs.allow_screen_wake_locks = false;
157 policy_controller_->ApplyPrefs(prefs); 157 policy_controller_->ApplyPrefs(prefs);
158 policy_controller_->AddScreenWakeLock("Screen"); 158 policy_controller_->AddScreenWakeLock("Screen");
159 expected_policy.set_ac_idle_action( 159 expected_policy.set_ac_idle_action(
160 power_manager::PowerManagementPolicy_Action_DO_NOTHING); 160 power_manager::PowerManagementPolicy_Action_DO_NOTHING);
161 expected_policy.set_reason("Prefs, Screen"); 161 expected_policy.set_reason("Prefs, Screen");
162 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), 162 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
163 PowerPolicyController::GetPolicyDebugString( 163 PowerPolicyController::GetPolicyDebugString(
164 fake_power_client_->policy())); 164 fake_power_client_->get_policy()));
165 } 165 }
166 166
167 TEST_F(PowerPolicyControllerTest, WakeLocks) { 167 TEST_F(PowerPolicyControllerTest, WakeLocks) {
168 const char kSystemWakeLockReason[] = "system"; 168 const char kSystemWakeLockReason[] = "system";
169 const int system_id = 169 const int system_id =
170 policy_controller_->AddSystemWakeLock(kSystemWakeLockReason); 170 policy_controller_->AddSystemWakeLock(kSystemWakeLockReason);
171 power_manager::PowerManagementPolicy expected_policy; 171 power_manager::PowerManagementPolicy expected_policy;
172 expected_policy.set_ac_idle_action( 172 expected_policy.set_ac_idle_action(
173 power_manager::PowerManagementPolicy_Action_DO_NOTHING); 173 power_manager::PowerManagementPolicy_Action_DO_NOTHING);
174 expected_policy.set_battery_idle_action( 174 expected_policy.set_battery_idle_action(
175 power_manager::PowerManagementPolicy_Action_DO_NOTHING); 175 power_manager::PowerManagementPolicy_Action_DO_NOTHING);
176 expected_policy.set_reason(kSystemWakeLockReason); 176 expected_policy.set_reason(kSystemWakeLockReason);
177 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), 177 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
178 PowerPolicyController::GetPolicyDebugString( 178 PowerPolicyController::GetPolicyDebugString(
179 fake_power_client_->policy())); 179 fake_power_client_->get_policy()));
180 180
181 const char kScreenWakeLockReason[] = "screen"; 181 const char kScreenWakeLockReason[] = "screen";
182 const int screen_id = policy_controller_->AddScreenWakeLock( 182 const int screen_id = policy_controller_->AddScreenWakeLock(
183 kScreenWakeLockReason); 183 kScreenWakeLockReason);
184 expected_policy.mutable_ac_delays()->set_screen_dim_ms(0); 184 expected_policy.mutable_ac_delays()->set_screen_dim_ms(0);
185 expected_policy.mutable_ac_delays()->set_screen_off_ms(0); 185 expected_policy.mutable_ac_delays()->set_screen_off_ms(0);
186 expected_policy.mutable_ac_delays()->set_screen_lock_ms(0); 186 expected_policy.mutable_ac_delays()->set_screen_lock_ms(0);
187 expected_policy.mutable_battery_delays()->set_screen_dim_ms(0); 187 expected_policy.mutable_battery_delays()->set_screen_dim_ms(0);
188 expected_policy.mutable_battery_delays()->set_screen_off_ms(0); 188 expected_policy.mutable_battery_delays()->set_screen_off_ms(0);
189 expected_policy.mutable_battery_delays()->set_screen_lock_ms(0); 189 expected_policy.mutable_battery_delays()->set_screen_lock_ms(0);
190 expected_policy.set_reason( 190 expected_policy.set_reason(
191 std::string(kScreenWakeLockReason) + ", " + kSystemWakeLockReason); 191 std::string(kScreenWakeLockReason) + ", " + kSystemWakeLockReason);
192 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), 192 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
193 PowerPolicyController::GetPolicyDebugString( 193 PowerPolicyController::GetPolicyDebugString(
194 fake_power_client_->policy())); 194 fake_power_client_->get_policy()));
195 195
196 policy_controller_->RemoveWakeLock(system_id); 196 policy_controller_->RemoveWakeLock(system_id);
197 expected_policy.set_reason(kScreenWakeLockReason); 197 expected_policy.set_reason(kScreenWakeLockReason);
198 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), 198 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
199 PowerPolicyController::GetPolicyDebugString( 199 PowerPolicyController::GetPolicyDebugString(
200 fake_power_client_->policy())); 200 fake_power_client_->get_policy()));
201 201
202 policy_controller_->RemoveWakeLock(screen_id); 202 policy_controller_->RemoveWakeLock(screen_id);
203 expected_policy.Clear(); 203 expected_policy.Clear();
204 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), 204 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
205 PowerPolicyController::GetPolicyDebugString( 205 PowerPolicyController::GetPolicyDebugString(
206 fake_power_client_->policy())); 206 fake_power_client_->get_policy()));
207 }
208
209 TEST_F(PowerPolicyControllerTest, AvoidSendingEmptyPolicies) {
210 // Check that empty policies aren't sent when PowerPolicyController is created
211 // or destroyed.
212 EXPECT_EQ(0, fake_power_client_->num_set_policy_calls());
213 policy_controller_.reset();
214 EXPECT_EQ(0, fake_power_client_->num_set_policy_calls());
215 } 207 }
216 208
217 } // namespace chromeos 209 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/power_policy_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698