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/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 141 |
142 // Helper function to add a profile with |profile_name| to | 142 // Helper function to add a profile with |profile_name| to |
143 // |profile_manager|'s ProfileInfoCache, and return the profile created. | 143 // |profile_manager|'s ProfileInfoCache, and return the profile created. |
144 Profile* AddProfileToCache(ProfileManager* profile_manager, | 144 Profile* AddProfileToCache(ProfileManager* profile_manager, |
145 const std::string& path_suffix, | 145 const std::string& path_suffix, |
146 const base::string16& profile_name) { | 146 const base::string16& profile_name) { |
147 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 147 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
148 size_t num_profiles = cache.GetNumberOfProfiles(); | 148 size_t num_profiles = cache.GetNumberOfProfiles(); |
149 base::FilePath path = temp_dir_.path().AppendASCII(path_suffix); | 149 base::FilePath path = temp_dir_.path().AppendASCII(path_suffix); |
150 cache.AddProfileToCache(path, profile_name, | 150 cache.AddProfileToCache(path, profile_name, |
151 base::string16(), 0, std::string()); | 151 std::string(), base::string16(), 0, std::string()); |
152 EXPECT_EQ(num_profiles + 1, cache.GetNumberOfProfiles()); | 152 EXPECT_EQ(num_profiles + 1, cache.GetNumberOfProfiles()); |
153 return profile_manager->GetProfile(path); | 153 return profile_manager->GetProfile(path); |
154 } | 154 } |
155 | 155 |
156 #if defined(OS_CHROMEOS) | 156 #if defined(OS_CHROMEOS) |
157 // Helper function to register an user with id |user_id| and create profile | 157 // Helper function to register an user with id |user_id| and create profile |
158 // with a correct path. | 158 // with a correct path. |
159 void RegisterUser(const std::string& user_id) { | 159 void RegisterUser(const std::string& user_id) { |
160 chromeos::ProfileHelper* profile_helper = chromeos::ProfileHelper::Get(); | 160 chromeos::ProfileHelper* profile_helper = chromeos::ProfileHelper::Get(); |
161 const std::string user_id_hash = | 161 const std::string user_id_hash = |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 | 469 |
470 // Setting a pref which is not applicable to a system (i.e., Android in this | 470 // Setting a pref which is not applicable to a system (i.e., Android in this |
471 // case) does not necessarily create it. Don't bother continuing with the | 471 // case) does not necessarily create it. Don't bother continuing with the |
472 // test if this pref doesn't exist because it will not load the profiles if | 472 // test if this pref doesn't exist because it will not load the profiles if |
473 // it cannot verify that the pref for background mode is enabled. | 473 // it cannot verify that the pref for background mode is enabled. |
474 if (!local_state_.Get()->HasPrefPath(prefs::kBackgroundModeEnabled)) | 474 if (!local_state_.Get()->HasPrefPath(prefs::kBackgroundModeEnabled)) |
475 return; | 475 return; |
476 | 476 |
477 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 477 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); |
478 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"), | 478 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"), |
479 ASCIIToUTF16("name_1"), base::string16(), 0, | 479 ASCIIToUTF16("name_1"), "12345", base::string16(), 0, |
480 std::string()); | 480 std::string()); |
481 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_2"), | 481 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_2"), |
482 ASCIIToUTF16("name_2"), base::string16(), 0, | 482 ASCIIToUTF16("name_2"), "23456", base::string16(), 0, |
483 std::string()); | 483 std::string()); |
484 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_3"), | 484 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_3"), |
485 ASCIIToUTF16("name_3"), base::string16(), 0, | 485 ASCIIToUTF16("name_3"), "34567", base::string16(), 0, |
486 std::string()); | 486 std::string()); |
487 cache.SetBackgroundStatusOfProfileAtIndex(0, true); | 487 cache.SetBackgroundStatusOfProfileAtIndex(0, true); |
488 cache.SetBackgroundStatusOfProfileAtIndex(2, true); | 488 cache.SetBackgroundStatusOfProfileAtIndex(2, true); |
489 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); | 489 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); |
490 | 490 |
491 profile_manager->AutoloadProfiles(); | 491 profile_manager->AutoloadProfiles(); |
492 | 492 |
493 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); | 493 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); |
494 } | 494 } |
495 | 495 |
496 TEST_F(ProfileManagerTest, DoNotAutoloadProfilesIfBackgroundModeOff) { | 496 TEST_F(ProfileManagerTest, DoNotAutoloadProfilesIfBackgroundModeOff) { |
497 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 497 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
498 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 498 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
499 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled, | 499 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled, |
500 new base::FundamentalValue(false)); | 500 new base::FundamentalValue(false)); |
501 | 501 |
502 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 502 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); |
503 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"), | 503 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"), |
504 ASCIIToUTF16("name_1"), base::string16(), 0, | 504 ASCIIToUTF16("name_1"), "12345", base::string16(), 0, |
505 std::string()); | 505 std::string()); |
506 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_2"), | 506 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_2"), |
507 ASCIIToUTF16("name_2"), base::string16(), 0, | 507 ASCIIToUTF16("name_2"), "23456", base::string16(), 0, |
508 std::string()); | 508 std::string()); |
509 cache.SetBackgroundStatusOfProfileAtIndex(0, false); | 509 cache.SetBackgroundStatusOfProfileAtIndex(0, false); |
510 cache.SetBackgroundStatusOfProfileAtIndex(1, true); | 510 cache.SetBackgroundStatusOfProfileAtIndex(1, true); |
511 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); | 511 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); |
512 | 512 |
513 profile_manager->AutoloadProfiles(); | 513 profile_manager->AutoloadProfiles(); |
514 | 514 |
515 EXPECT_EQ(0u, profile_manager->GetLoadedProfiles().size()); | 515 EXPECT_EQ(0u, profile_manager->GetLoadedProfiles().size()); |
516 } | 516 } |
517 | 517 |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 const base::string16 default_profile_name = | 1105 const base::string16 default_profile_name = |
1106 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 1106 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
1107 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); | 1107 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); |
1108 Profile* profile1 = AddProfileToCache(profile_manager, | 1108 Profile* profile1 = AddProfileToCache(profile_manager, |
1109 "path_1", profile_name1); | 1109 "path_1", profile_name1); |
1110 EXPECT_EQ(default_profile_name, | 1110 EXPECT_EQ(default_profile_name, |
1111 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1111 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
1112 | 1112 |
1113 // For a signed in profile with a default name we still display | 1113 // For a signed in profile with a default name we still display |
1114 // IDS_SINGLE_PROFILE_DISPLAY_NAME. | 1114 // IDS_SINGLE_PROFILE_DISPLAY_NAME. |
1115 cache.SetUserNameOfProfileAtIndex(0, ASCIIToUTF16("user@gmail.com")); | 1115 cache.SetAuthInfoOfProfileAtIndex(0, "12345", ASCIIToUTF16("user@gmail.com")); |
1116 EXPECT_EQ(profile_name1, cache.GetNameOfProfileAtIndex(0)); | 1116 EXPECT_EQ(profile_name1, cache.GetNameOfProfileAtIndex(0)); |
1117 EXPECT_EQ(default_profile_name, | 1117 EXPECT_EQ(default_profile_name, |
1118 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1118 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
1119 | 1119 |
1120 // For a signed in profile with a non-default Gaia given name we display the | 1120 // For a signed in profile with a non-default Gaia given name we display the |
1121 // Gaia given name. | 1121 // Gaia given name. |
1122 cache.SetUserNameOfProfileAtIndex(0, ASCIIToUTF16("user@gmail.com")); | 1122 cache.SetAuthInfoOfProfileAtIndex(0, "12345", ASCIIToUTF16("user@gmail.com")); |
1123 const base::string16 gaia_given_name(ASCIIToUTF16("given name")); | 1123 const base::string16 gaia_given_name(ASCIIToUTF16("given name")); |
1124 cache.SetGAIAGivenNameOfProfileAtIndex(0, gaia_given_name); | 1124 cache.SetGAIAGivenNameOfProfileAtIndex(0, gaia_given_name); |
1125 EXPECT_EQ(gaia_given_name, cache.GetNameOfProfileAtIndex(0)); | 1125 EXPECT_EQ(gaia_given_name, cache.GetNameOfProfileAtIndex(0)); |
1126 EXPECT_EQ(gaia_given_name, | 1126 EXPECT_EQ(gaia_given_name, |
1127 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1127 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
1128 | 1128 |
1129 // Multiple profiles means displaying the actual profile names. | 1129 // Multiple profiles means displaying the actual profile names. |
1130 const base::string16 profile_name2 = cache.ChooseNameForNewProfile(1); | 1130 const base::string16 profile_name2 = cache.ChooseNameForNewProfile(1); |
1131 Profile* profile2 = AddProfileToCache(profile_manager, | 1131 Profile* profile2 = AddProfileToCache(profile_manager, |
1132 "path_2", profile_name2); | 1132 "path_2", profile_name2); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 Profile* profile3 = AddProfileToCache( | 1166 Profile* profile3 = AddProfileToCache( |
1167 profile_manager, "path_3", profile_name3); | 1167 profile_manager, "path_3", profile_name3); |
1168 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); | 1168 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); |
1169 | 1169 |
1170 // Sign in all profiles, and make sure they do not have a Gaia name set. | 1170 // Sign in all profiles, and make sure they do not have a Gaia name set. |
1171 const base::string16 email1(ASCIIToUTF16("user1@gmail.com")); | 1171 const base::string16 email1(ASCIIToUTF16("user1@gmail.com")); |
1172 const base::string16 email2(ASCIIToUTF16("user2@gmail.com")); | 1172 const base::string16 email2(ASCIIToUTF16("user2@gmail.com")); |
1173 const base::string16 email3(ASCIIToUTF16("user3@gmail.com")); | 1173 const base::string16 email3(ASCIIToUTF16("user3@gmail.com")); |
1174 | 1174 |
1175 int index = cache.GetIndexOfProfileWithPath(profile1->GetPath()); | 1175 int index = cache.GetIndexOfProfileWithPath(profile1->GetPath()); |
1176 cache.SetUserNameOfProfileAtIndex(index, email1); | 1176 cache.SetAuthInfoOfProfileAtIndex(index, "12345", email1); |
1177 cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16()); | 1177 cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16()); |
1178 cache.SetGAIANameOfProfileAtIndex(index, base::string16()); | 1178 cache.SetGAIANameOfProfileAtIndex(index, base::string16()); |
1179 | 1179 |
1180 // This may resort the cache, so be extra cautious to use the right profile. | 1180 // This may resort the cache, so be extra cautious to use the right profile. |
1181 index = cache.GetIndexOfProfileWithPath(profile2->GetPath()); | 1181 index = cache.GetIndexOfProfileWithPath(profile2->GetPath()); |
1182 cache.SetUserNameOfProfileAtIndex(index, email2); | 1182 cache.SetAuthInfoOfProfileAtIndex(index, "23456", email2); |
1183 cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16()); | 1183 cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16()); |
1184 cache.SetGAIANameOfProfileAtIndex(index, base::string16()); | 1184 cache.SetGAIANameOfProfileAtIndex(index, base::string16()); |
1185 | 1185 |
1186 index = cache.GetIndexOfProfileWithPath(profile3->GetPath()); | 1186 index = cache.GetIndexOfProfileWithPath(profile3->GetPath()); |
1187 cache.SetUserNameOfProfileAtIndex(index, email3); | 1187 cache.SetAuthInfoOfProfileAtIndex(index, "34567", email3); |
1188 cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16()); | 1188 cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16()); |
1189 cache.SetGAIANameOfProfileAtIndex(index, base::string16()); | 1189 cache.SetGAIANameOfProfileAtIndex(index, base::string16()); |
1190 | 1190 |
1191 // The profiles with default names should display the email address. | 1191 // The profiles with default names should display the email address. |
1192 EXPECT_EQ(email1, profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1192 EXPECT_EQ(email1, profiles::GetAvatarNameForProfile(profile1->GetPath())); |
1193 EXPECT_EQ(email2, profiles::GetAvatarNameForProfile(profile2->GetPath())); | 1193 EXPECT_EQ(email2, profiles::GetAvatarNameForProfile(profile2->GetPath())); |
1194 | 1194 |
1195 // The profile with the custom name should display that. | 1195 // The profile with the custom name should display that. |
1196 EXPECT_EQ(profile_name3, | 1196 EXPECT_EQ(profile_name3, |
1197 profiles::GetAvatarNameForProfile(profile3->GetPath())); | 1197 profiles::GetAvatarNameForProfile(profile3->GetPath())); |
(...skipping 22 matching lines...) Expand all Loading... |
1220 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 1220 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); |
1221 | 1221 |
1222 MockObserver mock_observer; | 1222 MockObserver mock_observer; |
1223 EXPECT_CALL(mock_observer, OnProfileCreated( | 1223 EXPECT_CALL(mock_observer, OnProfileCreated( |
1224 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 1224 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
1225 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 1225 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
1226 base::RunLoop().RunUntilIdle(); | 1226 base::RunLoop().RunUntilIdle(); |
1227 | 1227 |
1228 // Track the profile, but don't load it. | 1228 // Track the profile, but don't load it. |
1229 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1229 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
1230 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), | 1230 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), "23456", |
1231 base::string16(), 0, std::string()); | 1231 base::string16(), 0, std::string()); |
1232 base::RunLoop().RunUntilIdle(); | 1232 base::RunLoop().RunUntilIdle(); |
1233 | 1233 |
1234 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | 1234 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); |
1235 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); | 1235 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); |
1236 | 1236 |
1237 // Set the active profile. | 1237 // Set the active profile. |
1238 PrefService* local_state = g_browser_process->local_state(); | 1238 PrefService* local_state = g_browser_process->local_state(); |
1239 local_state->SetString(prefs::kProfileLastUsed, | 1239 local_state->SetString(prefs::kProfileLastUsed, |
1240 dest_path1.BaseName().MaybeAsASCII()); | 1240 dest_path1.BaseName().MaybeAsASCII()); |
(...skipping 30 matching lines...) Expand all Loading... |
1271 EXPECT_CALL(mock_observer, OnProfileCreated( | 1271 EXPECT_CALL(mock_observer, OnProfileCreated( |
1272 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 1272 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
1273 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 1273 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
1274 base::RunLoop().RunUntilIdle(); | 1274 base::RunLoop().RunUntilIdle(); |
1275 | 1275 |
1276 // Create the other profiles, but don't load them. Assign a fake avatar icon | 1276 // Create the other profiles, but don't load them. Assign a fake avatar icon |
1277 // to ensure that profiles in the info cache are sorted by the profile name, | 1277 // to ensure that profiles in the info cache are sorted by the profile name, |
1278 // and not randomly by the avatar name. | 1278 // and not randomly by the avatar name. |
1279 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1279 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
1280 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), | 1280 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), |
1281 ASCIIToUTF16(profile_name2), 1, std::string()); | 1281 "23456", ASCIIToUTF16(profile_name2), 1, |
| 1282 std::string()); |
1282 cache.AddProfileToCache(dest_path3, ASCIIToUTF16(profile_name3), | 1283 cache.AddProfileToCache(dest_path3, ASCIIToUTF16(profile_name3), |
1283 ASCIIToUTF16(profile_name3), 2, std::string()); | 1284 "34567", ASCIIToUTF16(profile_name3), 2, |
| 1285 std::string()); |
1284 | 1286 |
1285 base::RunLoop().RunUntilIdle(); | 1287 base::RunLoop().RunUntilIdle(); |
1286 | 1288 |
1287 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | 1289 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); |
1288 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); | 1290 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); |
1289 | 1291 |
1290 // Set the active profile. | 1292 // Set the active profile. |
1291 PrefService* local_state = g_browser_process->local_state(); | 1293 PrefService* local_state = g_browser_process->local_state(); |
1292 local_state->SetString(prefs::kProfileLastUsed, | 1294 local_state->SetString(prefs::kProfileLastUsed, |
1293 dest_path1.BaseName().MaybeAsASCII()); | 1295 dest_path1.BaseName().MaybeAsASCII()); |
(...skipping 11 matching lines...) Expand all Loading... |
1305 dest_path2.BaseName().MaybeAsASCII()); | 1307 dest_path2.BaseName().MaybeAsASCII()); |
1306 profile_manager->ScheduleProfileForDeletion(dest_path2, | 1308 profile_manager->ScheduleProfileForDeletion(dest_path2, |
1307 ProfileManager::CreateCallback()); | 1309 ProfileManager::CreateCallback()); |
1308 // Spin the message loop so that all the callbacks can finish running. | 1310 // Spin the message loop so that all the callbacks can finish running. |
1309 base::RunLoop().RunUntilIdle(); | 1311 base::RunLoop().RunUntilIdle(); |
1310 | 1312 |
1311 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); | 1313 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); |
1312 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); | 1314 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); |
1313 } | 1315 } |
1314 #endif // !defined(OS_MACOSX) | 1316 #endif // !defined(OS_MACOSX) |
OLD | NEW |