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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 : local_state_(TestingBrowserProcess::GetGlobal()) { | 103 : local_state_(TestingBrowserProcess::GetGlobal()) { |
104 } | 104 } |
105 | 105 |
106 void SetUp() override { | 106 void SetUp() override { |
107 // Create a new temporary directory, and store the path | 107 // Create a new temporary directory, and store the path |
108 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 108 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
109 TestingBrowserProcess::GetGlobal()->SetProfileManager( | 109 TestingBrowserProcess::GetGlobal()->SetProfileManager( |
110 new UnittestProfileManager(temp_dir_.path())); | 110 new UnittestProfileManager(temp_dir_.path())); |
111 | 111 |
112 #if defined(OS_CHROMEOS) | 112 #if defined(OS_CHROMEOS) |
113 CommandLine* cl = CommandLine::ForCurrentProcess(); | 113 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
114 cl->AppendSwitch(switches::kTestType); | 114 cl->AppendSwitch(switches::kTestType); |
115 #endif | 115 #endif |
116 } | 116 } |
117 | 117 |
118 void TearDown() override { | 118 void TearDown() override { |
119 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); | 119 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); |
120 base::RunLoop().RunUntilIdle(); | 120 base::RunLoop().RunUntilIdle(); |
121 } | 121 } |
122 | 122 |
123 // Helper function to create a profile with |name| for a profile |manager|. | 123 // Helper function to create a profile with |name| for a profile |manager|. |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 401 |
402 class ProfileManagerGuestTest : public ProfileManagerTest { | 402 class ProfileManagerGuestTest : public ProfileManagerTest { |
403 protected: | 403 protected: |
404 void SetUp() override { | 404 void SetUp() override { |
405 // Create a new temporary directory, and store the path | 405 // Create a new temporary directory, and store the path |
406 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 406 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
407 TestingBrowserProcess::GetGlobal()->SetProfileManager( | 407 TestingBrowserProcess::GetGlobal()->SetProfileManager( |
408 new UnittestGuestProfileManager(temp_dir_.path())); | 408 new UnittestGuestProfileManager(temp_dir_.path())); |
409 | 409 |
410 #if defined(OS_CHROMEOS) | 410 #if defined(OS_CHROMEOS) |
411 CommandLine* cl = CommandLine::ForCurrentProcess(); | 411 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
412 // This switch is needed to skip non-test specific behavior in | 412 // This switch is needed to skip non-test specific behavior in |
413 // ProfileManager (accessing DBusThreadManager). | 413 // ProfileManager (accessing DBusThreadManager). |
414 cl->AppendSwitch(switches::kTestType); | 414 cl->AppendSwitch(switches::kTestType); |
415 | 415 |
416 cl->AppendSwitch(chromeos::switches::kGuestSession); | 416 cl->AppendSwitch(chromeos::switches::kGuestSession); |
417 cl->AppendSwitch(::switches::kIncognito); | 417 cl->AppendSwitch(::switches::kIncognito); |
418 | 418 |
419 RegisterUser(chromeos::login::kGuestUserName); | 419 RegisterUser(chromeos::login::kGuestUserName); |
420 #endif | 420 #endif |
421 } | 421 } |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 EXPECT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); | 987 EXPECT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); |
988 EXPECT_EQ(dest_path2, | 988 EXPECT_EQ(dest_path2, |
989 profile_manager->GetProfileInfoCache().GetPathOfProfileAtIndex(0)); | 989 profile_manager->GetProfileInfoCache().GetPathOfProfileAtIndex(0)); |
990 } | 990 } |
991 | 991 |
992 TEST_F(ProfileManagerTest, ProfileDisplayNameResetsDefaultName) { | 992 TEST_F(ProfileManagerTest, ProfileDisplayNameResetsDefaultName) { |
993 if (!profiles::IsMultipleProfilesEnabled()) | 993 if (!profiles::IsMultipleProfilesEnabled()) |
994 return; | 994 return; |
995 | 995 |
996 // The command line is reset at the end of every test by the test suite. | 996 // The command line is reset at the end of every test by the test suite. |
997 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); | 997 switches::EnableNewAvatarMenuForTesting( |
| 998 base::CommandLine::ForCurrentProcess()); |
998 | 999 |
999 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1000 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
1000 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1001 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
1001 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 1002 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); |
1002 | 1003 |
1003 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. | 1004 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. |
1004 const base::string16 default_profile_name = | 1005 const base::string16 default_profile_name = |
1005 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 1006 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
1006 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); | 1007 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); |
1007 Profile* profile1 = AddProfileToCache(profile_manager, | 1008 Profile* profile1 = AddProfileToCache(profile_manager, |
(...skipping 17 matching lines...) Expand all Loading... |
1025 base::RunLoop().RunUntilIdle(); | 1026 base::RunLoop().RunUntilIdle(); |
1026 EXPECT_EQ(default_profile_name, | 1027 EXPECT_EQ(default_profile_name, |
1027 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1028 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
1028 } | 1029 } |
1029 | 1030 |
1030 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesCustomName) { | 1031 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesCustomName) { |
1031 if (!profiles::IsMultipleProfilesEnabled()) | 1032 if (!profiles::IsMultipleProfilesEnabled()) |
1032 return; | 1033 return; |
1033 | 1034 |
1034 // The command line is reset at the end of every test by the test suite. | 1035 // The command line is reset at the end of every test by the test suite. |
1035 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); | 1036 switches::EnableNewAvatarMenuForTesting( |
| 1037 base::CommandLine::ForCurrentProcess()); |
1036 | 1038 |
1037 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1039 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
1038 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1040 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
1039 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 1041 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); |
1040 | 1042 |
1041 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. | 1043 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. |
1042 const base::string16 default_profile_name = | 1044 const base::string16 default_profile_name = |
1043 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 1045 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
1044 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); | 1046 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); |
1045 Profile* profile1 = AddProfileToCache(profile_manager, | 1047 Profile* profile1 = AddProfileToCache(profile_manager, |
(...skipping 25 matching lines...) Expand all Loading... |
1071 base::RunLoop().RunUntilIdle(); | 1073 base::RunLoop().RunUntilIdle(); |
1072 EXPECT_EQ(custom_profile_name, | 1074 EXPECT_EQ(custom_profile_name, |
1073 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1075 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
1074 } | 1076 } |
1075 | 1077 |
1076 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesSignedInName) { | 1078 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesSignedInName) { |
1077 if (!profiles::IsMultipleProfilesEnabled()) | 1079 if (!profiles::IsMultipleProfilesEnabled()) |
1078 return; | 1080 return; |
1079 | 1081 |
1080 // The command line is reset at the end of every test by the test suite. | 1082 // The command line is reset at the end of every test by the test suite. |
1081 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); | 1083 switches::EnableNewAvatarMenuForTesting( |
| 1084 base::CommandLine::ForCurrentProcess()); |
1082 | 1085 |
1083 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1086 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
1084 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1087 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
1085 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 1088 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); |
1086 | 1089 |
1087 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. | 1090 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. |
1088 const base::string16 default_profile_name = | 1091 const base::string16 default_profile_name = |
1089 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 1092 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
1090 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); | 1093 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); |
1091 Profile* profile1 = AddProfileToCache(profile_manager, | 1094 Profile* profile1 = AddProfileToCache(profile_manager, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 base::RunLoop().RunUntilIdle(); | 1128 base::RunLoop().RunUntilIdle(); |
1126 EXPECT_EQ(gaia_given_name, | 1129 EXPECT_EQ(gaia_given_name, |
1127 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1130 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
1128 } | 1131 } |
1129 | 1132 |
1130 TEST_F(ProfileManagerTest, ProfileDisplayNameIsEmailIfDefaultName) { | 1133 TEST_F(ProfileManagerTest, ProfileDisplayNameIsEmailIfDefaultName) { |
1131 if (!profiles::IsMultipleProfilesEnabled()) | 1134 if (!profiles::IsMultipleProfilesEnabled()) |
1132 return; | 1135 return; |
1133 | 1136 |
1134 // The command line is reset at the end of every test by the test suite. | 1137 // The command line is reset at the end of every test by the test suite. |
1135 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); | 1138 switches::EnableNewAvatarMenuForTesting( |
| 1139 base::CommandLine::ForCurrentProcess()); |
1136 | 1140 |
1137 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1141 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
1138 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1142 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
1139 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 1143 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); |
1140 | 1144 |
1141 // Create two signed in profiles, with both new and legacy default names, and | 1145 // Create two signed in profiles, with both new and legacy default names, and |
1142 // a profile with a custom name. | 1146 // a profile with a custom name. |
1143 Profile* profile1 = AddProfileToCache( | 1147 Profile* profile1 = AddProfileToCache( |
1144 profile_manager, "path_1", ASCIIToUTF16("Person 1")); | 1148 profile_manager, "path_1", ASCIIToUTF16("Person 1")); |
1145 Profile* profile2 = AddProfileToCache( | 1149 Profile* profile2 = AddProfileToCache( |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 dest_path2.BaseName().MaybeAsASCII()); | 1291 dest_path2.BaseName().MaybeAsASCII()); |
1288 profile_manager->ScheduleProfileForDeletion(dest_path2, | 1292 profile_manager->ScheduleProfileForDeletion(dest_path2, |
1289 ProfileManager::CreateCallback()); | 1293 ProfileManager::CreateCallback()); |
1290 // Spin the message loop so that all the callbacks can finish running. | 1294 // Spin the message loop so that all the callbacks can finish running. |
1291 base::RunLoop().RunUntilIdle(); | 1295 base::RunLoop().RunUntilIdle(); |
1292 | 1296 |
1293 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); | 1297 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); |
1294 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); | 1298 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); |
1295 } | 1299 } |
1296 #endif // !defined(OS_MACOSX) | 1300 #endif // !defined(OS_MACOSX) |
OLD | NEW |