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

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

Issue 442043002: ProfileManager doesn't depend on "--login-profile" switch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased and comments addressed. Created 6 years, 4 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"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/chromeos/login/users/fake_user_manager.h"
15 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
16 #include "chrome/browser/chromeos/profiles/profile_helper.h"
14 #include "chrome/browser/extensions/extension_special_storage_policy.h" 17 #include "chrome/browser/extensions/extension_special_storage_policy.h"
15 #include "chrome/browser/prefs/browser_prefs.h" 18 #include "chrome/browser/prefs/browser_prefs.h"
16 #include "chrome/browser/prefs/pref_service_syncable.h" 19 #include "chrome/browser/prefs/pref_service_syncable.h"
17 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/common/chrome_constants.h" 22 #include "chrome/common/chrome_constants.h"
20 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/testing_browser_process.h" 24 #include "chrome/test/base/testing_browser_process.h"
22 #include "chrome/test/base/testing_pref_service_syncable.h" 25 #include "chrome/test/base/testing_pref_service_syncable.h"
23 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 content::Source<Profile>(login_profile), 205 content::Source<Profile>(login_profile),
203 content::NotificationService::NoDetails()); 206 content::NotificationService::NoDetails());
204 207
205 // The login profile's prefs should still be used. 208 // The login profile's prefs should still be used.
206 EXPECT_FALSE(GetProfile()); 209 EXPECT_FALSE(GetProfile());
207 EXPECT_EQ(GetExpectedPowerPolicyForProfile(login_profile), 210 EXPECT_EQ(GetExpectedPowerPolicyForProfile(login_profile),
208 GetCurrentPowerPolicy()); 211 GetCurrentPowerPolicy());
209 } 212 }
210 213
211 TEST_F(PowerPrefsTest, UserSession) { 214 TEST_F(PowerPrefsTest, UserSession) {
215 FakeUserManager* user_manager = new FakeUserManager();
216 ScopedUserManagerEnabler user_manager_enabler(user_manager);
217
212 // Set up user profile. 218 // Set up user profile.
213 TestingProfile* user_profile = profile_manager_.CreateTestingProfile("user"); 219 const char test_user1[] = "test-user1@example.com";
214 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kLoginProfile, 220 user_manager->AddUser(test_user1);
215 "user"); 221 user_manager->LoginUser(test_user1);
222 TestingProfile* user_profile =
223 profile_manager_.CreateTestingProfile(test_user1);
224
216 profile_manager_.SetLoggedIn(true); 225 profile_manager_.SetLoggedIn(true);
217 226
218 // Inform power_prefs_ that a session has started. 227 // Inform power_prefs_ that a session has started.
219 power_prefs_->Observe(chrome::NOTIFICATION_SESSION_STARTED, 228 power_prefs_->Observe(chrome::NOTIFICATION_SESSION_STARTED,
220 content::Source<PowerPrefsTest>(this), 229 content::Source<PowerPrefsTest>(this),
221 content::NotificationService::NoDetails()); 230 content::NotificationService::NoDetails());
222 231
223 EXPECT_EQ(user_profile, GetProfile()); 232 EXPECT_EQ(user_profile, GetProfile());
224 EXPECT_EQ(GetExpectedPowerPolicyForProfile(user_profile), 233 EXPECT_EQ(GetExpectedPowerPolicyForProfile(user_profile),
225 GetCurrentPowerPolicy()); 234 GetCurrentPowerPolicy());
226 EXPECT_EQ(GetExpectedAllowScreenWakeLocksForProfile(user_profile), 235 EXPECT_EQ(GetExpectedAllowScreenWakeLocksForProfile(user_profile),
227 GetCurrentAllowScreenWakeLocks()); 236 GetCurrentAllowScreenWakeLocks());
228 237
238 const char test_user2[] = "test-user2@example.com";
239 user_manager->AddUser(test_user2);
240 user_manager->LoginUser(test_user2);
229 TestingProfile* other_profile = 241 TestingProfile* other_profile =
230 profile_manager_.CreateTestingProfile("other"); 242 profile_manager_.CreateTestingProfile(test_user2);
231 243
232 // Inform power_prefs_ that an unrelated profile has been destroyed. 244 // Inform power_prefs_ that an unrelated profile has been destroyed.
233 power_prefs_->Observe(chrome::NOTIFICATION_PROFILE_DESTROYED, 245 power_prefs_->Observe(chrome::NOTIFICATION_PROFILE_DESTROYED,
234 content::Source<Profile>(other_profile), 246 content::Source<Profile>(other_profile),
235 content::NotificationService::NoDetails()); 247 content::NotificationService::NoDetails());
236 248
237 // Verify that the user profile's power prefs are still being used. 249 // Verify that the user profile's power prefs are still being used.
238 EXPECT_EQ(user_profile, GetProfile()); 250 EXPECT_EQ(user_profile, GetProfile());
239 EXPECT_EQ(GetExpectedPowerPolicyForProfile(user_profile), 251 EXPECT_EQ(GetExpectedPowerPolicyForProfile(user_profile),
240 GetCurrentPowerPolicy()); 252 GetCurrentPowerPolicy());
(...skipping 18 matching lines...) Expand all
259 content::Source<Profile>(user_profile), 271 content::Source<Profile>(user_profile),
260 content::NotificationService::NoDetails()); 272 content::NotificationService::NoDetails());
261 273
262 // The user profile's prefs should still be used. 274 // The user profile's prefs should still be used.
263 EXPECT_FALSE(GetProfile()); 275 EXPECT_FALSE(GetProfile());
264 EXPECT_EQ(GetExpectedPowerPolicyForProfile(user_profile), 276 EXPECT_EQ(GetExpectedPowerPolicyForProfile(user_profile),
265 GetCurrentPowerPolicy()); 277 GetCurrentPowerPolicy());
266 } 278 }
267 279
268 } // namespace chromeos 280 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698