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

Side by Side Diff: chrome/browser/profiles/profile_manager_unittest.cc

Issue 544383003: Fixing problem that after a browser crash in multi user mode, an incorrect user might show up. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving function declaration into conditional section Created 6 years, 3 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
« no previous file with comments | « chrome/browser/profiles/profile_manager.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 195 }
196 196
197 TEST_F(ProfileManagerTest, DefaultProfileDir) { 197 TEST_F(ProfileManagerTest, DefaultProfileDir) {
198 base::FilePath expected_default = 198 base::FilePath expected_default =
199 base::FilePath().AppendASCII(chrome::kInitialProfile); 199 base::FilePath().AppendASCII(chrome::kInitialProfile);
200 EXPECT_EQ( 200 EXPECT_EQ(
201 expected_default.value(), 201 expected_default.value(),
202 g_browser_process->profile_manager()->GetInitialProfileDir().value()); 202 g_browser_process->profile_manager()->GetInitialProfileDir().value());
203 } 203 }
204 204
205 MATCHER(NotFail, "Profile creation failure status is not reported.") {
206 return arg == Profile::CREATE_STATUS_CREATED ||
207 arg == Profile::CREATE_STATUS_INITIALIZED;
208 }
209
210 MATCHER(SameNotNull, "The same non-NULL value for all calls.") {
211 if (!g_created_profile)
212 g_created_profile = arg;
213 return arg != NULL && arg == g_created_profile;
214 }
215
205 #if defined(OS_CHROMEOS) 216 #if defined(OS_CHROMEOS)
206 217
207 // This functionality only exists on Chrome OS. 218 // This functionality only exists on Chrome OS.
208 TEST_F(ProfileManagerTest, LoggedInProfileDir) { 219 TEST_F(ProfileManagerTest, LoggedInProfileDir) {
209 base::FilePath expected_default = 220 base::FilePath expected_default =
210 base::FilePath().AppendASCII(chrome::kInitialProfile); 221 base::FilePath().AppendASCII(chrome::kInitialProfile);
211 ProfileManager* profile_manager = g_browser_process->profile_manager(); 222 ProfileManager* profile_manager = g_browser_process->profile_manager();
212 EXPECT_EQ(expected_default.value(), 223 EXPECT_EQ(expected_default.value(),
213 profile_manager->GetInitialProfileDir().value()); 224 profile_manager->GetInitialProfileDir().value());
214 225
(...skipping 10 matching lines...) Expand all
225 content::NotificationService::AllSources(), 236 content::NotificationService::AllSources(),
226 content::Details<const user_manager::User>(active_user)); 237 content::Details<const user_manager::User>(active_user));
227 base::FilePath expected_logged_in( 238 base::FilePath expected_logged_in(
228 chromeos::ProfileHelper::GetUserProfileDir(active_user->username_hash())); 239 chromeos::ProfileHelper::GetUserProfileDir(active_user->username_hash()));
229 EXPECT_EQ(expected_logged_in.value(), 240 EXPECT_EQ(expected_logged_in.value(),
230 profile_manager->GetInitialProfileDir().value()); 241 profile_manager->GetInitialProfileDir().value());
231 VLOG(1) << temp_dir_.path().Append( 242 VLOG(1) << temp_dir_.path().Append(
232 profile_manager->GetInitialProfileDir()).value(); 243 profile_manager->GetInitialProfileDir()).value();
233 } 244 }
234 245
246 // Switching the user should switch also the last used user.
247 TEST_F(ProfileManagerTest, ActiveProfileChanged) {
248 ProfileManager* profile_manager = g_browser_process->profile_manager();
249 ASSERT_TRUE(profile_manager);
250
251 // Create and load two profiles.
252 const std::string user_name1 = "user1@example.com";
253 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(user_name1);
254
255 MockObserver mock_observer;
256 EXPECT_CALL(mock_observer, OnProfileCreated(
257 testing::NotNull(), NotFail())).Times(testing::AtLeast(2));
258
259 CreateProfileAsync(profile_manager, user_name1, false, &mock_observer);
260 base::RunLoop().RunUntilIdle();
261
262 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager();
263 chromeos::ScopedUserManagerEnabler enabler(user_manager);
264
265 PrefService* local_state = g_browser_process->local_state();
266 local_state->SetString(prefs::kProfileLastUsed, "");
267
268 const user_manager::User* active_user = user_manager->AddUser(user_name1);
269 user_manager->LoginUser(user_name1);
270
271 // None of the calls above should have changed the last user.
272 EXPECT_EQ("", local_state->GetString(prefs::kProfileLastUsed));
273
274 // The FakeUserManager will not switch the user either.
275 user_manager->SwitchActiveUser(user_name1);
276 EXPECT_EQ("", local_state->GetString(prefs::kProfileLastUsed));
277
278 // After triggering the LOGIN_USER_CHANGED observer call ourselves, the user
279 // has changed.
280 profile_manager->Observe(
281 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
282 content::NotificationService::AllSources(),
283 content::Details<const user_manager::User>(active_user));
284 EXPECT_EQ("u-" + user_name1 + "-hash",
285 local_state->GetString(prefs::kProfileLastUsed));
286 }
287
235 #endif 288 #endif
236 289
237 TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) { 290 TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) {
238 base::FilePath dest_path1 = temp_dir_.path(); 291 base::FilePath dest_path1 = temp_dir_.path();
239 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); 292 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1"));
240 293
241 base::FilePath dest_path2 = temp_dir_.path(); 294 base::FilePath dest_path2 = temp_dir_.path();
242 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); 295 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2"));
243 296
244 ProfileManager* profile_manager = g_browser_process->profile_manager(); 297 ProfileManager* profile_manager = g_browser_process->profile_manager();
(...skipping 21 matching lines...) Expand all
266 319
267 // Make sure any pending tasks run before we destroy the profiles. 320 // Make sure any pending tasks run before we destroy the profiles.
268 base::RunLoop().RunUntilIdle(); 321 base::RunLoop().RunUntilIdle();
269 322
270 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); 323 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
271 324
272 // Make sure history cleans up correctly. 325 // Make sure history cleans up correctly.
273 base::RunLoop().RunUntilIdle(); 326 base::RunLoop().RunUntilIdle();
274 } 327 }
275 328
276 MATCHER(NotFail, "Profile creation failure status is not reported.") {
277 return arg == Profile::CREATE_STATUS_CREATED ||
278 arg == Profile::CREATE_STATUS_INITIALIZED;
279 }
280
281 MATCHER(SameNotNull, "The same non-NULL value for all calls.") {
282 if (!g_created_profile)
283 g_created_profile = arg;
284 return arg != NULL && arg == g_created_profile;
285 }
286
287 TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) { 329 TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) {
288 g_created_profile = NULL; 330 g_created_profile = NULL;
289 331
290 MockObserver mock_observer1; 332 MockObserver mock_observer1;
291 EXPECT_CALL(mock_observer1, OnProfileCreated( 333 EXPECT_CALL(mock_observer1, OnProfileCreated(
292 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); 334 SameNotNull(), NotFail())).Times(testing::AtLeast(1));
293 MockObserver mock_observer2; 335 MockObserver mock_observer2;
294 EXPECT_CALL(mock_observer2, OnProfileCreated( 336 EXPECT_CALL(mock_observer2, OnProfileCreated(
295 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); 337 SameNotNull(), NotFail())).Times(testing::AtLeast(1));
296 MockObserver mock_observer3; 338 MockObserver mock_observer3;
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 dest_path2.BaseName().MaybeAsASCII()); 1279 dest_path2.BaseName().MaybeAsASCII());
1238 profile_manager->ScheduleProfileForDeletion(dest_path2, 1280 profile_manager->ScheduleProfileForDeletion(dest_path2,
1239 ProfileManager::CreateCallback()); 1281 ProfileManager::CreateCallback());
1240 // Spin the message loop so that all the callbacks can finish running. 1282 // Spin the message loop so that all the callbacks can finish running.
1241 base::RunLoop().RunUntilIdle(); 1283 base::RunLoop().RunUntilIdle();
1242 1284
1243 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); 1285 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath());
1244 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); 1286 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed));
1245 } 1287 }
1246 #endif // !defined(OS_MACOSX) 1288 #endif // !defined(OS_MACOSX)
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698