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

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

Powered by Google App Engine
This is Rietveld 408576698