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/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 CommandLine* cl = CommandLine::ForCurrentProcess(); | 113 CommandLine* cl = CommandLine::ForCurrentProcess(); |
114 cl->AppendSwitch(switches::kTestType); | 114 cl->AppendSwitch(switches::kTestType); |
115 #endif | 115 #endif |
116 } | 116 } |
117 | 117 |
118 virtual void TearDown() { | 118 virtual void TearDown() { |
119 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); | 119 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); |
120 message_loop_.RunUntilIdle(); | 120 message_loop_.RunUntilIdle(); |
121 } | 121 } |
122 | 122 |
123 virtual void CreateProfileAsync(ProfileManager* manager, | |
Alexei Svitkine (slow)
2013/06/19 14:58:31
Why is this virtual? Also, it needs a comment.
noms (inactive)
2013/06/21 23:11:47
Done.
| |
124 const std::string& name, | |
125 MockObserver* mock_observer) { | |
126 manager->CreateProfileAsync( | |
127 temp_dir_.path().Append(FILE_PATH_LITERAL(name)), | |
128 base::Bind(&MockObserver::OnProfileCreated, | |
129 base::Unretained(mock_observer)), | |
130 UTF8ToUTF16(name), | |
131 string16(), | |
132 false); | |
133 } | |
134 | |
123 #if defined(OS_CHROMEOS) | 135 #if defined(OS_CHROMEOS) |
124 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 136 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
125 chromeos::ScopedTestCrosSettings test_cros_settings_; | 137 chromeos::ScopedTestCrosSettings test_cros_settings_; |
126 #endif | 138 #endif |
127 | 139 |
128 // The path to temporary directory used to contain the test operations. | 140 // The path to temporary directory used to contain the test operations. |
129 base::ScopedTempDir temp_dir_; | 141 base::ScopedTempDir temp_dir_; |
130 ScopedTestingLocalState local_state_; | 142 ScopedTestingLocalState local_state_; |
131 scoped_refptr<extensions::EventRouterForwarder> | 143 scoped_refptr<extensions::EventRouterForwarder> |
132 extension_event_router_forwarder_; | 144 extension_event_router_forwarder_; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 } | 245 } |
234 | 246 |
235 MATCHER(NotFail, "Profile creation failure status is not reported.") { | 247 MATCHER(NotFail, "Profile creation failure status is not reported.") { |
236 return arg == Profile::CREATE_STATUS_CREATED || | 248 return arg == Profile::CREATE_STATUS_CREATED || |
237 arg == Profile::CREATE_STATUS_INITIALIZED; | 249 arg == Profile::CREATE_STATUS_INITIALIZED; |
238 } | 250 } |
239 | 251 |
240 // Tests asynchronous profile creation mechanism. | 252 // Tests asynchronous profile creation mechanism. |
241 // Crashes: http://crbug.com/89421 | 253 // Crashes: http://crbug.com/89421 |
242 TEST_F(ProfileManagerTest, DISABLED_CreateProfileAsync) { | 254 TEST_F(ProfileManagerTest, DISABLED_CreateProfileAsync) { |
243 base::FilePath dest_path = | |
244 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile")); | |
245 | |
246 MockObserver mock_observer; | 255 MockObserver mock_observer; |
247 EXPECT_CALL(mock_observer, OnProfileCreated( | 256 EXPECT_CALL(mock_observer, OnProfileCreated( |
248 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); | 257 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); |
249 | 258 |
250 g_browser_process->profile_manager()->CreateProfileAsync(dest_path, | 259 CreateProfileAsync(g_browser_process->profile_manager(), |
251 base::Bind(&MockObserver::OnProfileCreated, | 260 "New Profile", &mock_observer); |
252 base::Unretained(&mock_observer)), | |
253 string16(), string16(), false); | |
254 | 261 |
255 message_loop_.RunUntilIdle(); | 262 message_loop_.RunUntilIdle(); |
256 } | 263 } |
257 | 264 |
258 MATCHER(SameNotNull, "The same non-NULL value for all calls.") { | 265 MATCHER(SameNotNull, "The same non-NULL value for all calls.") { |
259 if (!g_created_profile) | 266 if (!g_created_profile) |
260 g_created_profile = arg; | 267 g_created_profile = arg; |
261 return arg != NULL && arg == g_created_profile; | 268 return arg != NULL && arg == g_created_profile; |
262 } | 269 } |
263 | 270 |
264 TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) { | 271 TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) { |
265 base::FilePath dest_path = | |
266 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile")); | |
267 | |
268 g_created_profile = NULL; | 272 g_created_profile = NULL; |
269 | 273 |
270 MockObserver mock_observer1; | 274 MockObserver mock_observer1; |
271 EXPECT_CALL(mock_observer1, OnProfileCreated( | 275 EXPECT_CALL(mock_observer1, OnProfileCreated( |
272 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 276 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
273 MockObserver mock_observer2; | 277 MockObserver mock_observer2; |
274 EXPECT_CALL(mock_observer2, OnProfileCreated( | 278 EXPECT_CALL(mock_observer2, OnProfileCreated( |
275 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 279 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
276 MockObserver mock_observer3; | 280 MockObserver mock_observer3; |
277 EXPECT_CALL(mock_observer3, OnProfileCreated( | 281 EXPECT_CALL(mock_observer3, OnProfileCreated( |
278 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 282 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
279 | 283 |
280 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 284 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
281 | 285 const std::string profile_name = "New Profile"; |
282 profile_manager->CreateProfileAsync(dest_path, | 286 CreateProfileAsync(profile_manager, profile_name, &mock_observer1); |
283 base::Bind(&MockObserver::OnProfileCreated, | 287 CreateProfileAsync(profile_manager, profile_name, &mock_observer2); |
284 base::Unretained(&mock_observer1)), | 288 CreateProfileAsync(profile_manager, profile_name, &mock_observer3); |
285 string16(), string16(), false); | |
286 profile_manager->CreateProfileAsync(dest_path, | |
287 base::Bind(&MockObserver::OnProfileCreated, | |
288 base::Unretained(&mock_observer2)), | |
289 string16(), string16(), false); | |
290 profile_manager->CreateProfileAsync(dest_path, | |
291 base::Bind(&MockObserver::OnProfileCreated, | |
292 base::Unretained(&mock_observer3)), | |
293 string16(), string16(), false); | |
294 | 289 |
295 message_loop_.RunUntilIdle(); | 290 message_loop_.RunUntilIdle(); |
296 } | 291 } |
297 | 292 |
298 TEST_F(ProfileManagerTest, CreateProfilesAsync) { | 293 TEST_F(ProfileManagerTest, CreateProfilesAsync) { |
299 base::FilePath dest_path1 = | 294 const std::string profile_name1 = "New Profile 1"; |
300 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); | 295 const std::string profile_name2 = "New Profile 2"; |
301 base::FilePath dest_path2 = | |
302 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); | |
303 | 296 |
304 MockObserver mock_observer; | 297 MockObserver mock_observer; |
305 EXPECT_CALL(mock_observer, OnProfileCreated( | 298 EXPECT_CALL(mock_observer, OnProfileCreated( |
306 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); | 299 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); |
307 | 300 |
308 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 301 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
309 | 302 |
310 profile_manager->CreateProfileAsync(dest_path1, | 303 CreateProfileAsync(profile_manager, profile_name1, &mock_observer); |
311 base::Bind(&MockObserver::OnProfileCreated, | 304 CreateProfileAsync(profile_manager, profile_name2, &mock_observer); |
312 base::Unretained(&mock_observer)), | |
313 string16(), string16(), false); | |
314 profile_manager->CreateProfileAsync(dest_path2, | |
315 base::Bind(&MockObserver::OnProfileCreated, | |
316 base::Unretained(&mock_observer)), | |
317 string16(), string16(), false); | |
318 | 305 |
319 message_loop_.RunUntilIdle(); | 306 message_loop_.RunUntilIdle(); |
320 } | 307 } |
321 | 308 |
322 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { | 309 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { |
323 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 310 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
324 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 311 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
325 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled, | 312 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled, |
326 Value::CreateBooleanValue(true)); | 313 Value::CreateBooleanValue(true)); |
327 | 314 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 EXPECT_FALSE( | 430 EXPECT_FALSE( |
444 profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord()); | 431 profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord()); |
445 | 432 |
446 // GetLastUsedProfileAllowedByPolicy() returns the incognito Profile when | 433 // GetLastUsedProfileAllowedByPolicy() returns the incognito Profile when |
447 // incognito mode is forced. | 434 // incognito mode is forced. |
448 IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::FORCED); | 435 IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::FORCED); |
449 EXPECT_TRUE( | 436 EXPECT_TRUE( |
450 profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord()); | 437 profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord()); |
451 } | 438 } |
452 | 439 |
440 TEST_F(ProfileManagerTest, ActiveProfileDeleted) { | |
441 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
442 ASSERT_TRUE(profile_manager); | |
443 | |
444 // Create and load two profiles. | |
445 const std::string profile_name1 = "New Profile 1"; | |
446 const std::string profile_name2 = "New Profile 2"; | |
447 base::FilePath dest_path1 = | |
448 temp_dir_.path().Append(FILE_PATH_LITERAL(profile_name1)); | |
449 base::FilePath dest_path2 = | |
450 temp_dir_.path().Append(FILE_PATH_LITERAL(profile_name2)); | |
451 | |
452 MockObserver mock_observer; | |
453 EXPECT_CALL(mock_observer, OnProfileCreated( | |
454 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); | |
455 | |
456 CreateProfileAsync(profile_manager, profile_name1, &mock_observer); | |
457 CreateProfileAsync(profile_manager, profile_name2, &mock_observer); | |
458 message_loop_.RunUntilIdle(); | |
459 | |
460 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); | |
461 EXPECT_EQ(2u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); | |
462 | |
463 // Set the active profile. | |
464 PrefService* local_state = g_browser_process->local_state(); | |
465 local_state->SetString(prefs::kProfileLastUsed, profile_name1); | |
466 | |
467 // Delete the active profile. | |
468 profile_manager->ScheduleProfileForDeletion(dest_path1, | |
469 ProfileManager::CreateCallback()); | |
470 // Spin the message loop so that all the callbacks can finish running. | |
471 message_loop_.RunUntilIdle(); | |
472 | |
473 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); | |
474 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); | |
475 } | |
476 | |
477 TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) { | |
478 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
479 ASSERT_TRUE(profile_manager); | |
480 | |
481 // Create and load one profile, and just create a second profile. | |
482 const std::string profile_name1 = "New Profile 1"; | |
483 const std::string profile_name2 = "New Profile 2"; | |
484 base::FilePath dest_path1 = | |
485 temp_dir_.path().Append(FILE_PATH_LITERAL(profile_name1)); | |
486 base::FilePath dest_path2 = | |
487 temp_dir_.path().Append(FILE_PATH_LITERAL(profile_name2)); | |
488 | |
489 MockObserver mock_observer; | |
490 EXPECT_CALL(mock_observer, OnProfileCreated( | |
491 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | |
492 CreateProfileAsync(profile_manager, profile_name1, &mock_observer); | |
493 message_loop_.RunUntilIdle(); | |
494 | |
495 // Track the profile, but don't load it. | |
496 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | |
497 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), | |
498 string16(), 0, false); | |
499 message_loop_.RunUntilIdle(); | |
500 | |
501 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | |
502 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); | |
503 | |
504 // Set the active profile. | |
505 PrefService* local_state = g_browser_process->local_state(); | |
506 local_state->SetString(prefs::kProfileLastUsed, | |
507 dest_path1.BaseName().MaybeAsASCII()); | |
508 | |
509 // Delete the active profile. This should switch and load the unloaded | |
510 // profile. | |
511 profile_manager->ScheduleProfileForDeletion(dest_path1, | |
512 ProfileManager::CreateCallback()); | |
513 | |
514 // Spin the message loop so that all the callbacks can finish running. | |
515 message_loop_.RunUntilIdle(); | |
516 | |
517 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); | |
518 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); | |
519 } | |
520 | |
521 // This tests the recursive call in ProfileManager::OnNewActiveProfileLoaded | |
522 // by simulating a scenario in which the profile that is being loaded as | |
523 // the next active profile has also been marked for deletion, so the | |
524 // ProfileManager needs to recursively select a different next profile. | |
Alexei Svitkine (slow)
2013/06/19 14:58:31
How does this work on platforms other than Mac? Th
noms (inactive)
2013/06/21 23:11:47
Tests shouldn't work, so I've ifdef'ed them.
On 20
| |
525 TEST_F(ProfileManagerTest, ActiveProfileDeletedNextProfileDeletedToo) { | |
526 | |
Alexei Svitkine (slow)
2013/06/19 14:58:31
Nit: Remove empty line.
noms (inactive)
2013/06/21 23:11:47
Done.
| |
527 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
528 ASSERT_TRUE(profile_manager); | |
529 | |
530 // Create and load one profile, and create two more profiles. | |
531 const std::string profile_name1 = "New Profile 1"; | |
532 const std::string profile_name2 = "New Profile 2"; | |
533 const std::string profile_name3 = "New Profile 3"; | |
534 base::FilePath dest_path1 = | |
535 temp_dir_.path().Append(FILE_PATH_LITERAL(profile_name1)); | |
536 base::FilePath dest_path2 = | |
537 temp_dir_.path().Append(FILE_PATH_LITERAL(profile_name2)); | |
538 base::FilePath dest_path3 = | |
539 temp_dir_.path().Append(FILE_PATH_LITERAL(profile_name3)); | |
540 | |
541 MockObserver mock_observer; | |
542 EXPECT_CALL(mock_observer, OnProfileCreated( | |
543 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | |
544 CreateProfileAsync(profile_manager, profile_name1, &mock_observer); | |
545 message_loop_.RunUntilIdle(); | |
546 | |
547 // Create the other profiles, but don't load them. Assign a fake avatar icon | |
548 // to ensure that profiles in the info cache are sorted by the profile name, | |
549 // and not randomly by the avatar name. | |
550 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | |
551 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), | |
552 ASCIIToUTF16(profile_name2), 1, false); | |
553 cache.AddProfileToCache(dest_path3, ASCIIToUTF16(profile_name3), | |
554 ASCIIToUTF16(profile_name3), 2, false); | |
555 | |
556 message_loop_.RunUntilIdle(); | |
557 | |
558 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | |
559 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); | |
560 | |
561 // Set the active profile. | |
562 PrefService* local_state = g_browser_process->local_state(); | |
563 local_state->SetString(prefs::kProfileLastUsed, | |
564 dest_path1.BaseName().MaybeAsASCII()); | |
565 | |
566 // Delete the active profile, Profile1. | |
567 // This will post a CreateProfileAsync message, that tries to load Profile2, | |
568 // which checks that the profile is not being deleted, and then calls back | |
569 // FinishDeletingProfile for Profile1. | |
570 // Try to break this flow by setting the active profile to Profile2 in the | |
571 // middle (so after the first posted message), and trying to delete Profile2, | |
572 // so that the ProfileManager has to look for a different profile to load. | |
573 profile_manager->ScheduleProfileForDeletion(dest_path1, | |
574 ProfileManager::CreateCallback()); | |
575 local_state->SetString(prefs::kProfileLastUsed, | |
576 dest_path2.BaseName().MaybeAsASCII()); | |
577 profile_manager->ScheduleProfileForDeletion(dest_path2, | |
578 ProfileManager::CreateCallback()); | |
579 // Spin the message loop so that all the callbacks can finish running. | |
580 message_loop_.RunUntilIdle(); | |
581 | |
582 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); | |
583 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); | |
584 } | |
585 | |
453 #if !defined(OS_ANDROID) | 586 #if !defined(OS_ANDROID) |
454 // There's no Browser object on Android. | 587 // There's no Browser object on Android. |
455 TEST_F(ProfileManagerTest, LastOpenedProfiles) { | 588 TEST_F(ProfileManagerTest, LastOpenedProfiles) { |
456 base::FilePath dest_path1 = temp_dir_.path(); | 589 base::FilePath dest_path1 = temp_dir_.path(); |
457 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); | 590 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); |
458 | 591 |
459 base::FilePath dest_path2 = temp_dir_.path(); | 592 base::FilePath dest_path2 = temp_dir_.path(); |
460 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); | 593 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); |
461 | 594 |
462 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 595 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 browser2b.reset(); | 766 browser2b.reset(); |
634 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 767 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
635 ASSERT_EQ(1U, last_opened_profiles.size()); | 768 ASSERT_EQ(1U, last_opened_profiles.size()); |
636 EXPECT_EQ(profile1, last_opened_profiles[0]); | 769 EXPECT_EQ(profile1, last_opened_profiles[0]); |
637 | 770 |
638 browser1.reset(); | 771 browser1.reset(); |
639 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 772 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
640 ASSERT_EQ(0U, last_opened_profiles.size()); | 773 ASSERT_EQ(0U, last_opened_profiles.size()); |
641 } | 774 } |
642 #endif // !defined(OS_ANDROID) | 775 #endif // !defined(OS_ANDROID) |
OLD | NEW |