| 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 <stddef.h> | 5 #include <stddef.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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 content::Details<const user_manager::User>(active_user)); | 283 content::Details<const user_manager::User>(active_user)); |
| 284 base::FilePath expected_logged_in( | 284 base::FilePath expected_logged_in( |
| 285 chromeos::ProfileHelper::GetUserProfileDir(active_user->username_hash())); | 285 chromeos::ProfileHelper::GetUserProfileDir(active_user->username_hash())); |
| 286 EXPECT_EQ(expected_logged_in.value(), | 286 EXPECT_EQ(expected_logged_in.value(), |
| 287 profile_manager->GetInitialProfileDir().value()); | 287 profile_manager->GetInitialProfileDir().value()); |
| 288 VLOG(1) << temp_dir_.GetPath() | 288 VLOG(1) << temp_dir_.GetPath() |
| 289 .Append(profile_manager->GetInitialProfileDir()) | 289 .Append(profile_manager->GetInitialProfileDir()) |
| 290 .value(); | 290 .value(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 // Test Get[ActiveUser|PrimaryUser|LastUsed]Profile does not load user profile. |
| 294 TEST_F(ProfileManagerTest, UserProfileLoading) { |
| 295 using chromeos::ProfileHelper; |
| 296 |
| 297 Profile* const signin_profile = ProfileHelper::GetSigninProfile(); |
| 298 |
| 299 // Get[Active|Primary|LastUsed]Profile return the sign-in profile before login |
| 300 // happens. IsSameProfile() is used to properly test against TestProfile whose |
| 301 // OTR version uses a different temp path. |
| 302 EXPECT_TRUE( |
| 303 ProfileManager::GetActiveUserProfile()->IsSameProfile(signin_profile)); |
| 304 EXPECT_TRUE( |
| 305 ProfileManager::GetPrimaryUserProfile()->IsSameProfile(signin_profile)); |
| 306 EXPECT_TRUE( |
| 307 ProfileManager::GetLastUsedProfile()->IsSameProfile(signin_profile)); |
| 308 |
| 309 // User signs in but user profile loading has not started. |
| 310 const std::string user_id = "test-user@example.com"; |
| 311 const std::string user_id_hash = |
| 312 ProfileHelper::Get()->GetUserIdHashByUserIdForTesting(user_id); |
| 313 user_manager::UserManager::Get()->UserLoggedIn( |
| 314 AccountId::FromUserEmail(user_id), user_id_hash, false); |
| 315 |
| 316 // Sign-in profile should be returned at this stage. Otherwise, login code |
| 317 // ends up in an invalid state. Strange things as in http://crbug.com/728683 |
| 318 // and http://crbug.com/718734 happens. |
| 319 EXPECT_TRUE( |
| 320 ProfileManager::GetActiveUserProfile()->IsSameProfile(signin_profile)); |
| 321 EXPECT_TRUE( |
| 322 ProfileManager::GetPrimaryUserProfile()->IsSameProfile(signin_profile)); |
| 323 EXPECT_TRUE( |
| 324 ProfileManager::GetLastUsedProfile()->IsSameProfile(signin_profile)); |
| 325 |
| 326 // Simulate UserSessionManager loads the profile. |
| 327 Profile* const user_profile = |
| 328 g_browser_process->profile_manager()->GetProfile( |
| 329 ProfileHelper::Get()->GetProfilePathByUserIdHash(user_id_hash)); |
| 330 ASSERT_FALSE(user_profile->IsSameProfile(signin_profile)); |
| 331 |
| 332 // User profile is returned thereafter. |
| 333 EXPECT_TRUE( |
| 334 ProfileManager::GetActiveUserProfile()->IsSameProfile(user_profile)); |
| 335 EXPECT_TRUE( |
| 336 ProfileManager::GetPrimaryUserProfile()->IsSameProfile(user_profile)); |
| 337 EXPECT_TRUE( |
| 338 ProfileManager::GetLastUsedProfile()->IsSameProfile(user_profile)); |
| 339 } |
| 340 |
| 293 #endif | 341 #endif |
| 294 | 342 |
| 295 TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) { | 343 TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) { |
| 296 base::FilePath dest_path1 = temp_dir_.GetPath(); | 344 base::FilePath dest_path1 = temp_dir_.GetPath(); |
| 297 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); | 345 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); |
| 298 | 346 |
| 299 base::FilePath dest_path2 = temp_dir_.GetPath(); | 347 base::FilePath dest_path2 = temp_dir_.GetPath(); |
| 300 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); | 348 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); |
| 301 | 349 |
| 302 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 350 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 // Check if the profile prefs are the same as the cache prefs | 718 // Check if the profile prefs are the same as the cache prefs |
| 671 EXPECT_EQ(profile_name, base::UTF16ToUTF8(entry->GetName())); | 719 EXPECT_EQ(profile_name, base::UTF16ToUTF8(entry->GetName())); |
| 672 EXPECT_EQ(avatar_index, entry->GetAvatarIconIndex()); | 720 EXPECT_EQ(avatar_index, entry->GetAvatarIconIndex()); |
| 673 } | 721 } |
| 674 | 722 |
| 675 TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) { | 723 TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) { |
| 676 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 724 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 677 ASSERT_TRUE(profile_manager); | 725 ASSERT_TRUE(profile_manager); |
| 678 | 726 |
| 679 #if defined(OS_CHROMEOS) | 727 #if defined(OS_CHROMEOS) |
| 680 // On CrOS, profile returned by GetLastUsedProfile is a singin profile that | 728 // On CrOS, profile returned by GetLastUsedProfile is a sign-in profile that |
| 681 // is forced to be incognito. That's why we need to create at least one user | 729 // is forced to be incognito. That's why we need to create at least one user |
| 682 // to get a regular profile. | 730 // to get a regular profile. |
| 683 RegisterUser("test-user@example.com"); | 731 RegisterUser("test-user@example.com"); |
| 684 #endif | 732 #endif |
| 685 | 733 |
| 686 Profile* profile = profile_manager->GetLastUsedProfileAllowedByPolicy(); | 734 Profile* profile = profile_manager->GetLastUsedProfileAllowedByPolicy(); |
| 687 ASSERT_TRUE(profile); | 735 ASSERT_TRUE(profile); |
| 688 EXPECT_FALSE(profile->IsOffTheRecord()); | 736 EXPECT_FALSE(profile->IsOffTheRecord()); |
| 689 PrefService* prefs = profile->GetPrefs(); | 737 PrefService* prefs = profile->GetPrefs(); |
| 690 EXPECT_EQ(IncognitoModePrefs::ENABLED, | 738 EXPECT_EQ(IncognitoModePrefs::ENABLED, |
| (...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 dest_path2.BaseName().MaybeAsASCII()); | 1504 dest_path2.BaseName().MaybeAsASCII()); |
| 1457 profile_manager->ScheduleProfileForDeletion(dest_path2, | 1505 profile_manager->ScheduleProfileForDeletion(dest_path2, |
| 1458 ProfileManager::CreateCallback()); | 1506 ProfileManager::CreateCallback()); |
| 1459 // Spin the message loop so that all the callbacks can finish running. | 1507 // Spin the message loop so that all the callbacks can finish running. |
| 1460 base::RunLoop().RunUntilIdle(); | 1508 base::RunLoop().RunUntilIdle(); |
| 1461 | 1509 |
| 1462 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); | 1510 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); |
| 1463 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); | 1511 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); |
| 1464 } | 1512 } |
| 1465 #endif // !defined(OS_MACOSX) | 1513 #endif // !defined(OS_MACOSX) |
| OLD | NEW |