| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 base::SystemMonitor::AllocateSystemIOPorts(); | 90 base::SystemMonitor::AllocateSystemIOPorts(); |
| 91 #endif | 91 #endif |
| 92 system_monitor_dummy_.reset(new base::SystemMonitor); | 92 system_monitor_dummy_.reset(new base::SystemMonitor); |
| 93 static_cast<TestingBrowserProcess*>(g_browser_process)->SetIOThread( | 93 static_cast<TestingBrowserProcess*>(g_browser_process)->SetIOThread( |
| 94 &io_thread_); | 94 &io_thread_); |
| 95 } | 95 } |
| 96 | 96 |
| 97 virtual void SetUp() { | 97 virtual void SetUp() { |
| 98 // Create a new temporary directory, and store the path | 98 // Create a new temporary directory, and store the path |
| 99 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 99 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 100 profile_manager_.reset(new testing::ProfileManager(temp_dir_.path())); | 100 static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager( |
| 101 new testing::ProfileManager(temp_dir_.path())); |
| 101 #if defined(OS_WIN) | 102 #if defined(OS_WIN) |
| 102 // Force the ProfileInfoCache to be created immediately, so we can | 103 // Force the ProfileInfoCache to be created immediately, so we can |
| 103 // remove the shortcut manager for testing. | 104 // remove the shortcut manager for testing. |
| 104 profile_manager_->GetProfileInfoCache(); | 105 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 105 profile_manager_->RemoveProfileShortcutManagerForTesting(); | 106 profile_manager->GetProfileInfoCache(); |
| 107 profile_manager->RemoveProfileShortcutManagerForTesting(); |
| 106 #endif | 108 #endif |
| 107 #if defined(OS_CHROMEOS) | 109 #if defined(OS_CHROMEOS) |
| 108 CommandLine *cl = CommandLine::ForCurrentProcess(); | 110 CommandLine *cl = CommandLine::ForCurrentProcess(); |
| 109 cl->AppendSwitch(switches::kTestType); | 111 cl->AppendSwitch(switches::kTestType); |
| 110 #endif | 112 #endif |
| 111 } | 113 } |
| 112 | 114 |
| 113 virtual void TearDown() { | 115 virtual void TearDown() { |
| 114 profile_manager_.reset(); | 116 static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager( |
| 117 NULL); |
| 115 message_loop_.RunAllPending(); | 118 message_loop_.RunAllPending(); |
| 116 } | 119 } |
| 117 | 120 |
| 118 class MockObserver { | 121 class MockObserver { |
| 119 public: | 122 public: |
| 120 MOCK_METHOD2(OnProfileCreated, | 123 MOCK_METHOD2(OnProfileCreated, |
| 121 void(Profile* profile, Profile::CreateStatus status)); | 124 void(Profile* profile, Profile::CreateStatus status)); |
| 122 }; | 125 }; |
| 123 | 126 |
| 124 #if defined(OS_CHROMEOS) | 127 #if defined(OS_CHROMEOS) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 135 extension_event_router_forwarder_; | 138 extension_event_router_forwarder_; |
| 136 | 139 |
| 137 MessageLoopForUI message_loop_; | 140 MessageLoopForUI message_loop_; |
| 138 content::TestBrowserThread ui_thread_; | 141 content::TestBrowserThread ui_thread_; |
| 139 content::TestBrowserThread db_thread_; | 142 content::TestBrowserThread db_thread_; |
| 140 content::TestBrowserThread file_thread_; | 143 content::TestBrowserThread file_thread_; |
| 141 // IOThread is necessary for the creation of some services below. | 144 // IOThread is necessary for the creation of some services below. |
| 142 IOThread io_thread_; | 145 IOThread io_thread_; |
| 143 | 146 |
| 144 scoped_ptr<base::SystemMonitor> system_monitor_dummy_; | 147 scoped_ptr<base::SystemMonitor> system_monitor_dummy_; |
| 145 | |
| 146 // Also will test profile deletion. | |
| 147 scoped_ptr<ProfileManager> profile_manager_; | |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 TEST_F(ProfileManagerTest, GetProfile) { | 150 TEST_F(ProfileManagerTest, GetProfile) { |
| 151 FilePath dest_path = temp_dir_.path(); | 151 FilePath dest_path = temp_dir_.path(); |
| 152 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); | 152 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); |
| 153 | 153 |
| 154 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 155 |
| 154 Profile* profile; | 156 Profile* profile; |
| 155 | 157 |
| 156 // Successfully create a profile. | 158 // Successfully create a profile. |
| 157 profile = profile_manager_->GetProfile(dest_path); | 159 profile = profile_manager->GetProfile(dest_path); |
| 158 EXPECT_TRUE(profile); | 160 EXPECT_TRUE(profile); |
| 159 | 161 |
| 160 // The profile already exists when we call GetProfile. Just load it. | 162 // The profile already exists when we call GetProfile. Just load it. |
| 161 EXPECT_EQ(profile, profile_manager_->GetProfile(dest_path)); | 163 EXPECT_EQ(profile, profile_manager->GetProfile(dest_path)); |
| 162 } | 164 } |
| 163 | 165 |
| 164 TEST_F(ProfileManagerTest, DefaultProfileDir) { | 166 TEST_F(ProfileManagerTest, DefaultProfileDir) { |
| 165 FilePath expected_default = | 167 FilePath expected_default = |
| 166 FilePath().AppendASCII(chrome::kInitialProfile); | 168 FilePath().AppendASCII(chrome::kInitialProfile); |
| 167 EXPECT_EQ(expected_default.value(), | 169 EXPECT_EQ( |
| 168 profile_manager_->GetInitialProfileDir().value()); | 170 expected_default.value(), |
| 171 g_browser_process->profile_manager()->GetInitialProfileDir().value()); |
| 169 } | 172 } |
| 170 | 173 |
| 171 #if defined(OS_CHROMEOS) | 174 #if defined(OS_CHROMEOS) |
| 172 // This functionality only exists on Chrome OS. | 175 // This functionality only exists on Chrome OS. |
| 173 TEST_F(ProfileManagerTest, LoggedInProfileDir) { | 176 TEST_F(ProfileManagerTest, LoggedInProfileDir) { |
| 174 CommandLine *cl = CommandLine::ForCurrentProcess(); | 177 CommandLine *cl = CommandLine::ForCurrentProcess(); |
| 175 std::string profile_dir("my_user"); | 178 std::string profile_dir("my_user"); |
| 176 | 179 |
| 177 cl->AppendSwitchASCII(switches::kLoginProfile, profile_dir); | 180 cl->AppendSwitchASCII(switches::kLoginProfile, profile_dir); |
| 178 | 181 |
| 179 FilePath expected_default = | 182 FilePath expected_default = |
| 180 FilePath().AppendASCII(chrome::kInitialProfile); | 183 FilePath().AppendASCII(chrome::kInitialProfile); |
| 184 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 181 EXPECT_EQ(expected_default.value(), | 185 EXPECT_EQ(expected_default.value(), |
| 182 profile_manager_->GetInitialProfileDir().value()); | 186 profile_manager->GetInitialProfileDir().value()); |
| 183 | 187 |
| 184 profile_manager_->Observe(chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 188 profile_manager->Observe(chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 185 content::NotificationService::AllSources(), | 189 content::NotificationService::AllSources(), |
| 186 content::NotificationService::NoDetails()); | 190 content::NotificationService::NoDetails()); |
| 187 FilePath expected_logged_in(profile_dir); | 191 FilePath expected_logged_in(profile_dir); |
| 188 EXPECT_EQ(expected_logged_in.value(), | 192 EXPECT_EQ(expected_logged_in.value(), |
| 189 profile_manager_->GetInitialProfileDir().value()); | 193 profile_manager->GetInitialProfileDir().value()); |
| 190 VLOG(1) << temp_dir_.path().Append( | 194 VLOG(1) << temp_dir_.path().Append( |
| 191 profile_manager_->GetInitialProfileDir()).value(); | 195 profile_manager->GetInitialProfileDir()).value(); |
| 192 } | 196 } |
| 193 | 197 |
| 194 #endif | 198 #endif |
| 195 | 199 |
| 196 TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) { | 200 TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) { |
| 197 FilePath dest_path1 = temp_dir_.path(); | 201 FilePath dest_path1 = temp_dir_.path(); |
| 198 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); | 202 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); |
| 199 | 203 |
| 200 FilePath dest_path2 = temp_dir_.path(); | 204 FilePath dest_path2 = temp_dir_.path(); |
| 201 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); | 205 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); |
| 202 | 206 |
| 207 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 208 |
| 203 // Successfully create the profiles. | 209 // Successfully create the profiles. |
| 204 TestingProfile* profile1 = | 210 TestingProfile* profile1 = |
| 205 static_cast<TestingProfile*>(profile_manager_->GetProfile(dest_path1)); | 211 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); |
| 206 ASSERT_TRUE(profile1); | 212 ASSERT_TRUE(profile1); |
| 207 | 213 |
| 208 TestingProfile* profile2 = | 214 TestingProfile* profile2 = |
| 209 static_cast<TestingProfile*>(profile_manager_->GetProfile(dest_path2)); | 215 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2)); |
| 210 ASSERT_TRUE(profile2); | 216 ASSERT_TRUE(profile2); |
| 211 | 217 |
| 212 // Force lazy-init of some profile services to simulate use. | 218 // Force lazy-init of some profile services to simulate use. |
| 213 profile1->CreateHistoryService(true, false); | 219 profile1->CreateHistoryService(true, false); |
| 214 EXPECT_TRUE(profile1->GetHistoryService(Profile::EXPLICIT_ACCESS)); | 220 EXPECT_TRUE(profile1->GetHistoryService(Profile::EXPLICIT_ACCESS)); |
| 215 profile1->CreateBookmarkModel(true); | 221 profile1->CreateBookmarkModel(true); |
| 216 EXPECT_TRUE(profile1->GetBookmarkModel()); | 222 EXPECT_TRUE(profile1->GetBookmarkModel()); |
| 217 profile2->CreateBookmarkModel(true); | 223 profile2->CreateBookmarkModel(true); |
| 218 EXPECT_TRUE(profile2->GetBookmarkModel()); | 224 EXPECT_TRUE(profile2->GetBookmarkModel()); |
| 219 profile2->CreateHistoryService(true, false); | 225 profile2->CreateHistoryService(true, false); |
| 220 EXPECT_TRUE(profile2->GetHistoryService(Profile::EXPLICIT_ACCESS)); | 226 EXPECT_TRUE(profile2->GetHistoryService(Profile::EXPLICIT_ACCESS)); |
| 221 | 227 |
| 222 // Make sure any pending tasks run before we destroy the profiles. | 228 // Make sure any pending tasks run before we destroy the profiles. |
| 223 message_loop_.RunAllPending(); | 229 message_loop_.RunAllPending(); |
| 224 | 230 |
| 225 profile_manager_.reset(); | 231 static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager( |
| 232 NULL); |
| 226 | 233 |
| 227 // Make sure history cleans up correctly. | 234 // Make sure history cleans up correctly. |
| 228 message_loop_.RunAllPending(); | 235 message_loop_.RunAllPending(); |
| 229 } | 236 } |
| 230 | 237 |
| 231 MATCHER(NotFail, "Profile creation failure status is not reported.") { | 238 MATCHER(NotFail, "Profile creation failure status is not reported.") { |
| 232 return arg == Profile::CREATE_STATUS_CREATED || | 239 return arg == Profile::CREATE_STATUS_CREATED || |
| 233 arg == Profile::CREATE_STATUS_INITIALIZED; | 240 arg == Profile::CREATE_STATUS_INITIALIZED; |
| 234 } | 241 } |
| 235 | 242 |
| 236 // Tests asynchronous profile creation mechanism. | 243 // Tests asynchronous profile creation mechanism. |
| 237 TEST_F(ProfileManagerTest, DISABLED_CreateProfileAsync) { | 244 TEST_F(ProfileManagerTest, DISABLED_CreateProfileAsync) { |
| 238 FilePath dest_path = | 245 FilePath dest_path = |
| 239 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile")); | 246 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile")); |
| 240 | 247 |
| 241 MockObserver mock_observer; | 248 MockObserver mock_observer; |
| 242 EXPECT_CALL(mock_observer, OnProfileCreated( | 249 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 243 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); | 250 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); |
| 244 | 251 |
| 245 profile_manager_->CreateProfileAsync(dest_path, | 252 g_browser_process->profile_manager()->CreateProfileAsync(dest_path, |
| 246 base::Bind(&MockObserver::OnProfileCreated, | 253 base::Bind(&MockObserver::OnProfileCreated, |
| 247 base::Unretained(&mock_observer))); | 254 base::Unretained(&mock_observer))); |
| 248 | 255 |
| 249 message_loop_.RunAllPending(); | 256 message_loop_.RunAllPending(); |
| 250 } | 257 } |
| 251 | 258 |
| 252 MATCHER(SameNotNull, "The same non-NULL value for all calls.") { | 259 MATCHER(SameNotNull, "The same non-NULL value for all calls.") { |
| 253 if (!g_created_profile) | 260 if (!g_created_profile) |
| 254 g_created_profile = arg; | 261 g_created_profile = arg; |
| 255 return arg != NULL && arg == g_created_profile; | 262 return arg != NULL && arg == g_created_profile; |
| 256 } | 263 } |
| 257 | 264 |
| 258 TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) { | 265 TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) { |
| 259 FilePath dest_path = | 266 FilePath dest_path = |
| 260 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile")); | 267 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile")); |
| 261 | 268 |
| 262 g_created_profile = NULL; | 269 g_created_profile = NULL; |
| 263 | 270 |
| 264 MockObserver mock_observer1; | 271 MockObserver mock_observer1; |
| 265 EXPECT_CALL(mock_observer1, OnProfileCreated( | 272 EXPECT_CALL(mock_observer1, OnProfileCreated( |
| 266 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 273 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
| 267 MockObserver mock_observer2; | 274 MockObserver mock_observer2; |
| 268 EXPECT_CALL(mock_observer2, OnProfileCreated( | 275 EXPECT_CALL(mock_observer2, OnProfileCreated( |
| 269 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 276 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
| 270 MockObserver mock_observer3; | 277 MockObserver mock_observer3; |
| 271 EXPECT_CALL(mock_observer3, OnProfileCreated( | 278 EXPECT_CALL(mock_observer3, OnProfileCreated( |
| 272 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 279 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
| 273 | 280 |
| 274 profile_manager_->CreateProfileAsync(dest_path, | 281 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 282 |
| 283 profile_manager->CreateProfileAsync(dest_path, |
| 275 base::Bind(&MockObserver::OnProfileCreated, | 284 base::Bind(&MockObserver::OnProfileCreated, |
| 276 base::Unretained(&mock_observer1))); | 285 base::Unretained(&mock_observer1))); |
| 277 profile_manager_->CreateProfileAsync(dest_path, | 286 profile_manager->CreateProfileAsync(dest_path, |
| 278 base::Bind(&MockObserver::OnProfileCreated, | 287 base::Bind(&MockObserver::OnProfileCreated, |
| 279 base::Unretained(&mock_observer2))); | 288 base::Unretained(&mock_observer2))); |
| 280 profile_manager_->CreateProfileAsync(dest_path, | 289 profile_manager->CreateProfileAsync(dest_path, |
| 281 base::Bind(&MockObserver::OnProfileCreated, | 290 base::Bind(&MockObserver::OnProfileCreated, |
| 282 base::Unretained(&mock_observer3))); | 291 base::Unretained(&mock_observer3))); |
| 283 | 292 |
| 284 message_loop_.RunAllPending(); | 293 message_loop_.RunAllPending(); |
| 285 } | 294 } |
| 286 | 295 |
| 287 TEST_F(ProfileManagerTest, CreateProfilesAsync) { | 296 TEST_F(ProfileManagerTest, CreateProfilesAsync) { |
| 288 FilePath dest_path1 = | 297 FilePath dest_path1 = |
| 289 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); | 298 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); |
| 290 FilePath dest_path2 = | 299 FilePath dest_path2 = |
| 291 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); | 300 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); |
| 292 | 301 |
| 293 MockObserver mock_observer; | 302 MockObserver mock_observer; |
| 294 EXPECT_CALL(mock_observer, OnProfileCreated( | 303 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 295 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); | 304 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); |
| 296 | 305 |
| 297 profile_manager_->CreateProfileAsync(dest_path1, | 306 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 307 |
| 308 profile_manager->CreateProfileAsync(dest_path1, |
| 298 base::Bind(&MockObserver::OnProfileCreated, | 309 base::Bind(&MockObserver::OnProfileCreated, |
| 299 base::Unretained(&mock_observer))); | 310 base::Unretained(&mock_observer))); |
| 300 profile_manager_->CreateProfileAsync(dest_path2, | 311 profile_manager->CreateProfileAsync(dest_path2, |
| 301 base::Bind(&MockObserver::OnProfileCreated, | 312 base::Bind(&MockObserver::OnProfileCreated, |
| 302 base::Unretained(&mock_observer))); | 313 base::Unretained(&mock_observer))); |
| 303 | 314 |
| 304 message_loop_.RunAllPending(); | 315 message_loop_.RunAllPending(); |
| 305 } | 316 } |
| 306 | 317 |
| 307 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { | 318 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { |
| 308 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 319 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 320 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 309 | 321 |
| 310 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 322 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); |
| 311 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"), | 323 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"), |
| 312 ASCIIToUTF16("name_1"), string16(), 0); | 324 ASCIIToUTF16("name_1"), string16(), 0); |
| 313 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_2"), | 325 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_2"), |
| 314 ASCIIToUTF16("name_2"), string16(), 0); | 326 ASCIIToUTF16("name_2"), string16(), 0); |
| 315 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_3"), | 327 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_3"), |
| 316 ASCIIToUTF16("name_3"), string16(), 0); | 328 ASCIIToUTF16("name_3"), string16(), 0); |
| 317 cache.SetBackgroundStatusOfProfileAtIndex(0, true); | 329 cache.SetBackgroundStatusOfProfileAtIndex(0, true); |
| 318 cache.SetBackgroundStatusOfProfileAtIndex(2, true); | 330 cache.SetBackgroundStatusOfProfileAtIndex(2, true); |
| 319 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); | 331 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); |
| 320 | 332 |
| 321 profile_manager_->AutoloadProfiles(); | 333 profile_manager->AutoloadProfiles(); |
| 322 | 334 |
| 323 EXPECT_EQ(2u, profile_manager_->GetLoadedProfiles().size()); | 335 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); |
| 324 } | 336 } |
| 337 |
| 338 TEST_F(ProfileManagerTest, InitProfileUserPrefs) { |
| 339 FilePath dest_path = temp_dir_.path(); |
| 340 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); |
| 341 |
| 342 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 343 |
| 344 Profile* profile; |
| 345 |
| 346 // Successfully create the profile |
| 347 profile = profile_manager->GetProfile(dest_path); |
| 348 ASSERT_TRUE(profile); |
| 349 |
| 350 // Check that the profile name is non empty |
| 351 std::string profile_name = |
| 352 profile->GetPrefs()->GetString(prefs::kProfileName); |
| 353 EXPECT_FALSE(profile_name.empty()); |
| 354 |
| 355 // Check that the profile avatar index is valid |
| 356 size_t avatar_index = |
| 357 profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); |
| 358 EXPECT_TRUE(profile_manager->GetProfileInfoCache().IsDefaultAvatarIconIndex( |
| 359 avatar_index)); |
| 360 } |
| 361 |
| 362 // Tests that a new profile's entry in the profile info cache is setup with the |
| 363 // same values that are in the profile prefs. |
| 364 TEST_F(ProfileManagerTest, InitProfileInfoCacheForAProfile) { |
| 365 FilePath dest_path = temp_dir_.path(); |
| 366 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); |
| 367 |
| 368 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 369 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 370 |
| 371 // Successfully create the profile |
| 372 Profile* profile = profile_manager->GetProfile(dest_path); |
| 373 ASSERT_TRUE(profile); |
| 374 |
| 375 std::string profile_name = |
| 376 profile->GetPrefs()->GetString(prefs::kProfileName); |
| 377 size_t avatar_index = |
| 378 profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); |
| 379 |
| 380 size_t profile_index = cache.GetIndexOfProfileWithPath(dest_path); |
| 381 |
| 382 // Check if the profile prefs are the same as the cache prefs |
| 383 EXPECT_EQ(profile_name, |
| 384 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); |
| 385 EXPECT_EQ(avatar_index, |
| 386 cache.GetAvatarIconIndexOfProfileAtIndex(profile_index)); |
| 387 } |
| OLD | NEW |