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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/profiles/profiles_state.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/profiles/profile_manager_unittest.cc
diff --git a/chrome/browser/profiles/profile_manager_unittest.cc b/chrome/browser/profiles/profile_manager_unittest.cc
index 4685581b5ad358d1bf932b468480bff2b720f862..82c7f89fbcbc8c2163189b6158aa152dfb1fa3e9 100644
--- a/chrome/browser/profiles/profile_manager_unittest.cc
+++ b/chrome/browser/profiles/profile_manager_unittest.cc
@@ -1178,6 +1178,66 @@ TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesSignedInName) {
EXPECT_EQ(gaia_given_name,
profiles::GetAvatarNameForProfile(profile1->GetPath()));
}
+
+TEST_F(ProfileManagerTest, ProfileDisplayNameIsEmailIfDefaultName) {
+ if (!profiles::IsMultipleProfilesEnabled())
+ return;
+
+ // The command line is reset at the end of every test by the test suite.
+ switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess());
+
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
+ EXPECT_EQ(0u, cache.GetNumberOfProfiles());
+
+ // Create two signed in profiles, with both new and legacy default names, and
+ // a profile with a custom name.
+ Profile* profile1 = AddProfileToCache(
+ profile_manager, "path_1", ASCIIToUTF16("Person 1"));
+ Profile* profile2 = AddProfileToCache(
+ profile_manager, "path_2", ASCIIToUTF16("Default Profile"));
+ const base::string16 profile_name3(ASCIIToUTF16("Batman"));
+ Profile* profile3 = AddProfileToCache(
+ profile_manager, "path_3", profile_name3);
+ EXPECT_EQ(3u, cache.GetNumberOfProfiles());
+
+ // Sign in all profiles, and make sure they do not have a Gaia name set.
+ const base::string16 email1(ASCIIToUTF16("user1@gmail.com"));
+ const base::string16 email2(ASCIIToUTF16("user2@gmail.com"));
+ const base::string16 email3(ASCIIToUTF16("user3@gmail.com"));
+
+ int index = cache.GetIndexOfProfileWithPath(profile1->GetPath());
+ cache.SetUserNameOfProfileAtIndex(index, email1);
+ cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16());
+ cache.SetGAIANameOfProfileAtIndex(index, base::string16());
+
+ // This may resort the cache, so be extra cautious to use the right profile.
+ index = cache.GetIndexOfProfileWithPath(profile2->GetPath());
+ cache.SetUserNameOfProfileAtIndex(index, email2);
+ cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16());
+ cache.SetGAIANameOfProfileAtIndex(index, base::string16());
+
+ index = cache.GetIndexOfProfileWithPath(profile3->GetPath());
+ cache.SetUserNameOfProfileAtIndex(index, email3);
+ cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16());
+ cache.SetGAIANameOfProfileAtIndex(index, base::string16());
+
+ // The profiles with default names should display the email address.
+ EXPECT_EQ(email1, profiles::GetAvatarNameForProfile(profile1->GetPath()));
+ EXPECT_EQ(email2, profiles::GetAvatarNameForProfile(profile2->GetPath()));
+
+ // The profile with the custom name should display that.
+ EXPECT_EQ(profile_name3,
+ profiles::GetAvatarNameForProfile(profile3->GetPath()));
+
+ // Adding a Gaia name to a profile that previously had a default name should
+ // start displaying it.
+ const base::string16 gaia_given_name(ASCIIToUTF16("Robin"));
+ cache.SetGAIAGivenNameOfProfileAtIndex(
+ cache.GetIndexOfProfileWithPath(profile1->GetPath()), gaia_given_name);
+ EXPECT_EQ(gaia_given_name,
+ profiles::GetAvatarNameForProfile(profile1->GetPath()));
+}
#endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
#if defined(OS_MACOSX)
« 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