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

Side by Side Diff: chrome/browser/profiles/profile_manager_unittest.cc

Issue 9087009: Restore all profiles which were active when restoring the last open pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix. Created 8 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); 378 profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex);
379 379
380 size_t profile_index = cache.GetIndexOfProfileWithPath(dest_path); 380 size_t profile_index = cache.GetIndexOfProfileWithPath(dest_path);
381 381
382 // Check if the profile prefs are the same as the cache prefs 382 // Check if the profile prefs are the same as the cache prefs
383 EXPECT_EQ(profile_name, 383 EXPECT_EQ(profile_name,
384 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); 384 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index)));
385 EXPECT_EQ(avatar_index, 385 EXPECT_EQ(avatar_index,
386 cache.GetAvatarIconIndexOfProfileAtIndex(profile_index)); 386 cache.GetAvatarIconIndexOfProfileAtIndex(profile_index));
387 } 387 }
388
389 TEST_F(ProfileManagerTest, LastActiveProfiles) {
390 FilePath dest_path1 = temp_dir_.path();
391 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1"));
392
393 FilePath dest_path2 = temp_dir_.path();
394 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2"));
395
396 ProfileManager* profile_manager = g_browser_process->profile_manager();
397
398 // Successfully create the profiles.
399 TestingProfile* profile1 =
400 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1));
401 ASSERT_TRUE(profile1);
402
403 TestingProfile* profile2 =
404 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2));
405 ASSERT_TRUE(profile2);
406
407 std::vector<Profile*> last_active_profiles =
408 profile_manager->GetLastActiveProfiles();
409 ASSERT_EQ(0U, last_active_profiles.size());
410
411 // Create a browser for profile1.
412 scoped_ptr<Browser> browser1a(new Browser(Browser::TYPE_TABBED, profile1));
413
414 last_active_profiles = profile_manager->GetLastActiveProfiles();
415 ASSERT_EQ(1U, last_active_profiles.size());
416 EXPECT_EQ(profile1, last_active_profiles[0]);
417
418 // And for profile2.
419 scoped_ptr<Browser> browser2(new Browser(Browser::TYPE_TABBED, profile2));
420
421 last_active_profiles = profile_manager->GetLastActiveProfiles();
422 ASSERT_EQ(2U, last_active_profiles.size());
423 EXPECT_EQ(profile1, last_active_profiles[0]);
424 EXPECT_EQ(profile2, last_active_profiles[1]);
425
426 // Adding more browsers doesn't change anything.
427 scoped_ptr<Browser> browser1b(new Browser(Browser::TYPE_TABBED, profile1));
428 last_active_profiles = profile_manager->GetLastActiveProfiles();
429 ASSERT_EQ(2U, last_active_profiles.size());
430 EXPECT_EQ(profile1, last_active_profiles[0]);
431 EXPECT_EQ(profile2, last_active_profiles[1]);
432
433 // Close the browsers.
434 browser1a.reset();
435 last_active_profiles = profile_manager->GetLastActiveProfiles();
436 ASSERT_EQ(2U, last_active_profiles.size());
437 EXPECT_EQ(profile1, last_active_profiles[0]);
438 EXPECT_EQ(profile2, last_active_profiles[1]);
439
440 browser1b.reset();
441 last_active_profiles = profile_manager->GetLastActiveProfiles();
442 ASSERT_EQ(1U, last_active_profiles.size());
443 EXPECT_EQ(profile2, last_active_profiles[0]);
444
445 browser2.reset();
446 last_active_profiles = profile_manager->GetLastActiveProfiles();
447 ASSERT_EQ(0U, last_active_profiles.size());
448 }
449
450 TEST_F(ProfileManagerTest, LastActiveProfilesAtShutdown) {
451 FilePath dest_path1 = temp_dir_.path();
452 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1"));
453
454 FilePath dest_path2 = temp_dir_.path();
455 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2"));
456
457 ProfileManager* profile_manager = g_browser_process->profile_manager();
458
459 // Successfully create the profiles.
460 TestingProfile* profile1 =
461 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1));
462 ASSERT_TRUE(profile1);
463
464 TestingProfile* profile2 =
465 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2));
466 ASSERT_TRUE(profile2);
467
468 // Create a browser for profile1.
469 scoped_ptr<Browser> browser1(new Browser(Browser::TYPE_TABBED, profile1));
470
471 // And for profile2.
472 scoped_ptr<Browser> browser2(new Browser(Browser::TYPE_TABBED, profile2));
473
474 std::vector<Profile*> last_active_profiles =
475 profile_manager->GetLastActiveProfiles();
476 ASSERT_EQ(2U, last_active_profiles.size());
477 EXPECT_EQ(profile1, last_active_profiles[0]);
478 EXPECT_EQ(profile2, last_active_profiles[1]);
479
480 // Simulate a shutdown.
481 content::NotificationService::current()->Notify(
482 content::NOTIFICATION_APP_EXITING,
483 content::NotificationService::AllSources(),
484 content::NotificationService::NoDetails());
485
486 // Even if the browsers are destructed during shutdown, the profiles stay
487 // active.
488 browser1.reset();
489 browser2.reset();
490
491 last_active_profiles = profile_manager->GetLastActiveProfiles();
492 ASSERT_EQ(2U, last_active_profiles.size());
493 EXPECT_EQ(profile1, last_active_profiles[0]);
494 EXPECT_EQ(profile2, last_active_profiles[1]);
495 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698