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

Side by Side Diff: chrome/browser/chromeos/power/power_prefs_unittest.cc

Issue 116983008: chromeos: Don't send empty power management policies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: don't crash in d'tor if uninitialized 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
OLDNEW
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 "chrome/browser/chromeos/power/power_prefs.h" 5 #include "chrome/browser/chromeos/power/power_prefs.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 expected_policy.set_user_activity_screen_dim_delay_factor( 133 expected_policy.set_user_activity_screen_dim_delay_factor(
134 prefs->GetDouble(prefs::kPowerUserActivityScreenDimDelayFactor)); 134 prefs->GetDouble(prefs::kPowerUserActivityScreenDimDelayFactor));
135 expected_policy.set_wait_for_initial_user_activity( 135 expected_policy.set_wait_for_initial_user_activity(
136 prefs->GetBoolean(prefs::kPowerWaitForInitialUserActivity)); 136 prefs->GetBoolean(prefs::kPowerWaitForInitialUserActivity));
137 expected_policy.set_reason("Prefs"); 137 expected_policy.set_reason("Prefs");
138 return PowerPolicyController::GetPolicyDebugString(expected_policy); 138 return PowerPolicyController::GetPolicyDebugString(expected_policy);
139 } 139 }
140 140
141 std::string PowerPrefsTest::GetCurrentPowerPolicy() const { 141 std::string PowerPrefsTest::GetCurrentPowerPolicy() const {
142 return PowerPolicyController::GetPolicyDebugString( 142 return PowerPolicyController::GetPolicyDebugString(
143 fake_power_manager_client_->get_policy()); 143 fake_power_manager_client_->policy());
144 } 144 }
145 145
146 bool PowerPrefsTest::GetCurrentAllowScreenWakeLocks() const { 146 bool PowerPrefsTest::GetCurrentAllowScreenWakeLocks() const {
147 return power_policy_controller_->honor_screen_wake_locks_; 147 return power_policy_controller_->honor_screen_wake_locks_;
148 } 148 }
149 149
150 bool PowerPrefsTest::GetExpectedAllowScreenWakeLocksForProfile( 150 bool PowerPrefsTest::GetExpectedAllowScreenWakeLocksForProfile(
151 Profile* profile) const { 151 Profile* profile) const {
152 return profile->GetPrefs()->GetBoolean(prefs::kPowerAllowScreenWakeLocks); 152 return profile->GetPrefs()->GetBoolean(prefs::kPowerAllowScreenWakeLocks);
153 } 153 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 EXPECT_EQ(GetExpectedPowerPolicyForProfile(login_profile), 195 EXPECT_EQ(GetExpectedPowerPolicyForProfile(login_profile),
196 GetCurrentPowerPolicy()); 196 GetCurrentPowerPolicy());
197 EXPECT_EQ(GetExpectedAllowScreenWakeLocksForProfile(login_profile), 197 EXPECT_EQ(GetExpectedAllowScreenWakeLocksForProfile(login_profile),
198 GetCurrentAllowScreenWakeLocks()); 198 GetCurrentAllowScreenWakeLocks());
199 199
200 // Inform power_prefs_ that the login profile has been destroyed. 200 // Inform power_prefs_ that the login profile has been destroyed.
201 power_prefs_->Observe(chrome::NOTIFICATION_PROFILE_DESTROYED, 201 power_prefs_->Observe(chrome::NOTIFICATION_PROFILE_DESTROYED,
202 content::Source<Profile>(login_profile), 202 content::Source<Profile>(login_profile),
203 content::NotificationService::NoDetails()); 203 content::NotificationService::NoDetails());
204 204
205 // The login profile's prefs should still be used.
205 EXPECT_FALSE(GetProfile()); 206 EXPECT_FALSE(GetProfile());
206 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString( 207 EXPECT_EQ(GetExpectedPowerPolicyForProfile(login_profile),
207 power_manager::PowerManagementPolicy()),
208 GetCurrentPowerPolicy()); 208 GetCurrentPowerPolicy());
209 } 209 }
210 210
211 TEST_F(PowerPrefsTest, UserSession) { 211 TEST_F(PowerPrefsTest, UserSession) {
212 // Set up user profile. 212 // Set up user profile.
213 TestingProfile* user_profile = profile_manager_.CreateTestingProfile("user"); 213 TestingProfile* user_profile = profile_manager_.CreateTestingProfile("user");
214 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kLoginProfile, 214 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kLoginProfile,
215 "user"); 215 "user");
216 profile_manager_.SetLoggedIn(true); 216 profile_manager_.SetLoggedIn(true);
217 217
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 GetCurrentPowerPolicy()); 252 GetCurrentPowerPolicy());
253 EXPECT_EQ(GetExpectedAllowScreenWakeLocksForProfile(user_profile), 253 EXPECT_EQ(GetExpectedAllowScreenWakeLocksForProfile(user_profile),
254 GetCurrentAllowScreenWakeLocks()); 254 GetCurrentAllowScreenWakeLocks());
255 255
256 // Inform power_prefs_ that the session has ended and the user profile has 256 // Inform power_prefs_ that the session has ended and the user profile has
257 // been destroyed. 257 // been destroyed.
258 power_prefs_->Observe(chrome::NOTIFICATION_PROFILE_DESTROYED, 258 power_prefs_->Observe(chrome::NOTIFICATION_PROFILE_DESTROYED,
259 content::Source<Profile>(user_profile), 259 content::Source<Profile>(user_profile),
260 content::NotificationService::NoDetails()); 260 content::NotificationService::NoDetails());
261 261
262 // The user profile's prefs should still be used.
262 EXPECT_FALSE(GetProfile()); 263 EXPECT_FALSE(GetProfile());
263 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString( 264 EXPECT_EQ(GetExpectedPowerPolicyForProfile(user_profile),
264 power_manager::PowerManagementPolicy()),
265 GetCurrentPowerPolicy()); 265 GetCurrentPowerPolicy());
266 } 266 }
267 267
268 } // namespace chromeos 268 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698