| OLD | NEW |
| 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 content::NotificationService::AllSources(), | 236 content::NotificationService::AllSources(), |
| 237 content::Details<const user_manager::User>(active_user)); | 237 content::Details<const user_manager::User>(active_user)); |
| 238 base::FilePath expected_logged_in( | 238 base::FilePath expected_logged_in( |
| 239 chromeos::ProfileHelper::GetUserProfileDir(active_user->username_hash())); | 239 chromeos::ProfileHelper::GetUserProfileDir(active_user->username_hash())); |
| 240 EXPECT_EQ(expected_logged_in.value(), | 240 EXPECT_EQ(expected_logged_in.value(), |
| 241 profile_manager->GetInitialProfileDir().value()); | 241 profile_manager->GetInitialProfileDir().value()); |
| 242 VLOG(1) << temp_dir_.path().Append( | 242 VLOG(1) << temp_dir_.path().Append( |
| 243 profile_manager->GetInitialProfileDir()).value(); | 243 profile_manager->GetInitialProfileDir()).value(); |
| 244 } | 244 } |
| 245 | 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 | |
| 288 #endif | 246 #endif |
| 289 | 247 |
| 290 TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) { | 248 TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) { |
| 291 base::FilePath dest_path1 = temp_dir_.path(); | 249 base::FilePath dest_path1 = temp_dir_.path(); |
| 292 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); | 250 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); |
| 293 | 251 |
| 294 base::FilePath dest_path2 = temp_dir_.path(); | 252 base::FilePath dest_path2 = temp_dir_.path(); |
| 295 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); | 253 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); |
| 296 | 254 |
| 297 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 255 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| (...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 dest_path2.BaseName().MaybeAsASCII()); | 1290 dest_path2.BaseName().MaybeAsASCII()); |
| 1333 profile_manager->ScheduleProfileForDeletion(dest_path2, | 1291 profile_manager->ScheduleProfileForDeletion(dest_path2, |
| 1334 ProfileManager::CreateCallback()); | 1292 ProfileManager::CreateCallback()); |
| 1335 // Spin the message loop so that all the callbacks can finish running. | 1293 // Spin the message loop so that all the callbacks can finish running. |
| 1336 base::RunLoop().RunUntilIdle(); | 1294 base::RunLoop().RunUntilIdle(); |
| 1337 | 1295 |
| 1338 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); | 1296 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); |
| 1339 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); | 1297 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); |
| 1340 } | 1298 } |
| 1341 #endif // !defined(OS_MACOSX) | 1299 #endif // !defined(OS_MACOSX) |
| OLD | NEW |