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

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

Issue 556003007: [Profiles] Improve the display name for default profiles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test + typo 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 | « no previous file | chrome/browser/profiles/profiles_state.cc » ('j') | 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 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 profiles::GetAvatarNameForProfile(profile2->GetPath())); 1171 profiles::GetAvatarNameForProfile(profile2->GetPath()));
1172 1172
1173 // Deleting a profile means returning to the original, actual profile name. 1173 // Deleting a profile means returning to the original, actual profile name.
1174 profile_manager->ScheduleProfileForDeletion(profile2->GetPath(), 1174 profile_manager->ScheduleProfileForDeletion(profile2->GetPath(),
1175 ProfileManager::CreateCallback()); 1175 ProfileManager::CreateCallback());
1176 // Spin the message loop so that all the callbacks can finish running. 1176 // Spin the message loop so that all the callbacks can finish running.
1177 base::RunLoop().RunUntilIdle(); 1177 base::RunLoop().RunUntilIdle();
1178 EXPECT_EQ(gaia_given_name, 1178 EXPECT_EQ(gaia_given_name,
1179 profiles::GetAvatarNameForProfile(profile1->GetPath())); 1179 profiles::GetAvatarNameForProfile(profile1->GetPath()));
1180 } 1180 }
1181
1182 TEST_F(ProfileManagerTest, ProfileDisplayNameIsEmailIfDefaultName) {
1183 if (!profiles::IsMultipleProfilesEnabled())
1184 return;
1185
1186 // The command line is reset at the end of every test by the test suite.
1187 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess());
1188
1189 ProfileManager* profile_manager = g_browser_process->profile_manager();
1190 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
1191 EXPECT_EQ(0u, cache.GetNumberOfProfiles());
1192
1193 // Create two signed in profiles, with both new and legacy default names, and
1194 // a profile with a custom name.
1195 Profile* profile1 = AddProfileToCache(
1196 profile_manager, "path_1", ASCIIToUTF16("Person 1"));
1197 Profile* profile2 = AddProfileToCache(
1198 profile_manager, "path_2", ASCIIToUTF16("Default Profile"));
1199 const base::string16 profile_name3(ASCIIToUTF16("Batman"));
1200 Profile* profile3 = AddProfileToCache(
1201 profile_manager, "path_3", profile_name3);
1202 EXPECT_EQ(3u, cache.GetNumberOfProfiles());
1203
1204 // Sign in all profiles, and make sure they do not have a Gaia name set.
1205 const base::string16 email1(ASCIIToUTF16("user1@gmail.com"));
1206 const base::string16 email2(ASCIIToUTF16("user2@gmail.com"));
1207 const base::string16 email3(ASCIIToUTF16("user3@gmail.com"));
1208
1209 int index = cache.GetIndexOfProfileWithPath(profile1->GetPath());
1210 cache.SetUserNameOfProfileAtIndex(index, email1);
1211 cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16());
1212 cache.SetGAIANameOfProfileAtIndex(index, base::string16());
1213
1214 // This may resort the cache, so be extra cautious to use the right profile.
1215 index = cache.GetIndexOfProfileWithPath(profile2->GetPath());
1216 cache.SetUserNameOfProfileAtIndex(index, email2);
1217 cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16());
1218 cache.SetGAIANameOfProfileAtIndex(index, base::string16());
1219
1220 index = cache.GetIndexOfProfileWithPath(profile3->GetPath());
1221 cache.SetUserNameOfProfileAtIndex(index, email3);
1222 cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16());
1223 cache.SetGAIANameOfProfileAtIndex(index, base::string16());
1224
1225 // The profiles with default names should display the email address.
1226 EXPECT_EQ(email1, profiles::GetAvatarNameForProfile(profile1->GetPath()));
1227 EXPECT_EQ(email2, profiles::GetAvatarNameForProfile(profile2->GetPath()));
1228
1229 // The profile with the custom name should display that.
1230 EXPECT_EQ(profile_name3,
1231 profiles::GetAvatarNameForProfile(profile3->GetPath()));
1232
1233 // Adding a Gaia name to a profile that previously had a default name should
1234 // start displaying it.
1235 const base::string16 gaia_given_name(ASCIIToUTF16("Robin"));
1236 cache.SetGAIAGivenNameOfProfileAtIndex(
1237 cache.GetIndexOfProfileWithPath(profile1->GetPath()), gaia_given_name);
1238 EXPECT_EQ(gaia_given_name,
1239 profiles::GetAvatarNameForProfile(profile1->GetPath()));
1240 }
1181 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 1241 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
1182 1242
1183 #if defined(OS_MACOSX) 1243 #if defined(OS_MACOSX)
1184 // These tests are for a Mac-only code path that assumes the browser 1244 // These tests are for a Mac-only code path that assumes the browser
1185 // process isn't killed when all browser windows are closed. 1245 // process isn't killed when all browser windows are closed.
1186 TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) { 1246 TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) {
1187 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1247 ProfileManager* profile_manager = g_browser_process->profile_manager();
1188 ASSERT_TRUE(profile_manager); 1248 ASSERT_TRUE(profile_manager);
1189 1249
1190 // Create and load one profile, and just create a second profile. 1250 // Create and load one profile, and just create a second profile.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 dest_path2.BaseName().MaybeAsASCII()); 1339 dest_path2.BaseName().MaybeAsASCII());
1280 profile_manager->ScheduleProfileForDeletion(dest_path2, 1340 profile_manager->ScheduleProfileForDeletion(dest_path2,
1281 ProfileManager::CreateCallback()); 1341 ProfileManager::CreateCallback());
1282 // Spin the message loop so that all the callbacks can finish running. 1342 // Spin the message loop so that all the callbacks can finish running.
1283 base::RunLoop().RunUntilIdle(); 1343 base::RunLoop().RunUntilIdle();
1284 1344
1285 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); 1345 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath());
1286 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); 1346 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed));
1287 } 1347 }
1288 #endif // !defined(OS_MACOSX) 1348 #endif // !defined(OS_MACOSX)
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/profiles/profiles_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698