Commit c929946b authored by noms's avatar noms Committed by Commit bot

[Profiles] Improve the display name for default profiles.

If a profile is signed in, but has a default name (because this is after
enabling the new profiles UI but the Gaia profile name hasn't been downloaded)
display the email address rather than the default profile name.
It's one step better.

BUG=412809
TEST=Start Chrome with an empty user data dir and
--disable-new-avatar-menu. Create two profiles, and sign one of them in
with a profile that has a clean sync (or reset the sync data after signin).
Make sure that the last active profile is the *not* signed in one
(so close all the browser windows for the signed in profile). Restart Chrome
with --enable-new-avatar-menu. You should be in the local profile. Choose "Switch
person" from the avatar menu. The user manager should display the other profile's
email address in the pod. Once you launch that profile, the name should update to
the gaia name.

Review URL: https://codereview.chromium.org/556003007

Cr-Commit-Position: refs/heads/master@{#295166}
parent 09413869
...@@ -1171,6 +1171,66 @@ TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesSignedInName) { ...@@ -1171,6 +1171,66 @@ TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesSignedInName) {
EXPECT_EQ(gaia_given_name, EXPECT_EQ(gaia_given_name,
profiles::GetAvatarNameForProfile(profile1->GetPath())); 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) #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
......
...@@ -67,16 +67,18 @@ base::string16 GetAvatarNameForProfile(const base::FilePath& profile_path) { ...@@ -67,16 +67,18 @@ base::string16 GetAvatarNameForProfile(const base::FilePath& profile_path) {
// Using the --new-avatar-menu flag, there's a couple of rules about what // Using the --new-avatar-menu flag, there's a couple of rules about what
// the avatar button displays. If there's a single profile, with a default // the avatar button displays. If there's a single profile, with a default
// name (i.e. of the form Person %d) not manually set, it should display // name (i.e. of the form Person %d) not manually set, it should display
// IDS_SINGLE_PROFILE_DISPLAY_NAME. Otherwise, it will return the actual // IDS_SINGLE_PROFILE_DISPLAY_NAME. If the profile is signed in but is using
// name of the profile. // a default name, use the profiles's email address. Otherwise, it
base::string16 profile_name = cache.GetNameOfProfileAtIndex(index); // will return the actual name of the profile.
bool has_default_name = cache.ProfileIsUsingDefaultNameAtIndex(index) && const base::string16 profile_name = cache.GetNameOfProfileAtIndex(index);
const base::string16 email = cache.GetUserNameOfProfileAtIndex(index);
bool is_default_name = cache.ProfileIsUsingDefaultNameAtIndex(index) &&
cache.IsDefaultProfileName(profile_name); cache.IsDefaultProfileName(profile_name);
if (cache.GetNumberOfProfiles() == 1 && has_default_name) if (cache.GetNumberOfProfiles() == 1 && is_default_name)
display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME);
else else
display_name = profile_name; display_name = (is_default_name && !email.empty()) ? email : profile_name;
} }
return display_name; return display_name;
} }
......
...@@ -352,6 +352,11 @@ TEST_F(ProfileChooserControllerTest, AccountManagementLayout) { ...@@ -352,6 +352,11 @@ TEST_F(ProfileChooserControllerTest, AccountManagementLayout) {
ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache();
cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail));
// Mark that we are using the profile name on purpose, so that we don't
// fallback to testing the algorithm that chooses which default name
// should be used.
cache->SetProfileIsUsingDefaultNameAtIndex(0, false);
// Set up the signin manager and the OAuth2Tokens. // Set up the signin manager and the OAuth2Tokens.
Profile* profile = browser()->profile(); Profile* profile = browser()->profile();
SigninManagerFactory::GetForProfile(profile)-> SigninManagerFactory::GetForProfile(profile)->
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment