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

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: Code review. 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
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | chrome/browser/ui/browser_init.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); 377 profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex);
378 378
379 size_t profile_index = cache.GetIndexOfProfileWithPath(dest_path); 379 size_t profile_index = cache.GetIndexOfProfileWithPath(dest_path);
380 380
381 // Check if the profile prefs are the same as the cache prefs 381 // Check if the profile prefs are the same as the cache prefs
382 EXPECT_EQ(profile_name, 382 EXPECT_EQ(profile_name,
383 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); 383 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index)));
384 EXPECT_EQ(avatar_index, 384 EXPECT_EQ(avatar_index,
385 cache.GetAvatarIconIndexOfProfileAtIndex(profile_index)); 385 cache.GetAvatarIconIndexOfProfileAtIndex(profile_index));
386 } 386 }
387
388 TEST_F(ProfileManagerTest, LastOpenedProfiles) {
389 FilePath dest_path1 = temp_dir_.path();
390 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1"));
391
392 FilePath dest_path2 = temp_dir_.path();
393 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2"));
394
395 ProfileManager* profile_manager = g_browser_process->profile_manager();
396
397 // Successfully create the profiles.
398 TestingProfile* profile1 =
399 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1));
400 ASSERT_TRUE(profile1);
401
402 TestingProfile* profile2 =
403 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2));
404 ASSERT_TRUE(profile2);
405
406 std::vector<Profile*> last_opened_profiles =
407 profile_manager->GetLastOpenedProfiles();
408 ASSERT_EQ(0U, last_opened_profiles.size());
409
410 // Create a browser for profile1.
411 scoped_ptr<Browser> browser1a(new Browser(Browser::TYPE_TABBED, profile1));
412
413 last_opened_profiles = profile_manager->GetLastOpenedProfiles();
414 ASSERT_EQ(1U, last_opened_profiles.size());
415 EXPECT_EQ(profile1, last_opened_profiles[0]);
416
417 // And for profile2.
418 scoped_ptr<Browser> browser2(new Browser(Browser::TYPE_TABBED, profile2));
419
420 last_opened_profiles = profile_manager->GetLastOpenedProfiles();
421 ASSERT_EQ(2U, last_opened_profiles.size());
422 EXPECT_EQ(profile1, last_opened_profiles[0]);
423 EXPECT_EQ(profile2, last_opened_profiles[1]);
424
425 // Adding more browsers doesn't change anything.
426 scoped_ptr<Browser> browser1b(new Browser(Browser::TYPE_TABBED, profile1));
427 last_opened_profiles = profile_manager->GetLastOpenedProfiles();
428 ASSERT_EQ(2U, last_opened_profiles.size());
429 EXPECT_EQ(profile1, last_opened_profiles[0]);
430 EXPECT_EQ(profile2, last_opened_profiles[1]);
431
432 // Close the browsers.
433 browser1a.reset();
434 last_opened_profiles = profile_manager->GetLastOpenedProfiles();
435 ASSERT_EQ(2U, last_opened_profiles.size());
436 EXPECT_EQ(profile1, last_opened_profiles[0]);
437 EXPECT_EQ(profile2, last_opened_profiles[1]);
438
439 browser1b.reset();
440 last_opened_profiles = profile_manager->GetLastOpenedProfiles();
441 ASSERT_EQ(1U, last_opened_profiles.size());
442 EXPECT_EQ(profile2, last_opened_profiles[0]);
443
444 browser2.reset();
445 last_opened_profiles = profile_manager->GetLastOpenedProfiles();
446 ASSERT_EQ(0U, last_opened_profiles.size());
447 }
448
449 TEST_F(ProfileManagerTest, LastOpenedProfilesAtShutdown) {
450 FilePath dest_path1 = temp_dir_.path();
451 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1"));
452
453 FilePath dest_path2 = temp_dir_.path();
454 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2"));
455
456 ProfileManager* profile_manager = g_browser_process->profile_manager();
457
458 // Successfully create the profiles.
459 TestingProfile* profile1 =
460 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1));
461 ASSERT_TRUE(profile1);
462
463 TestingProfile* profile2 =
464 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2));
465 ASSERT_TRUE(profile2);
466
467 // Create a browser for profile1.
468 scoped_ptr<Browser> browser1(new Browser(Browser::TYPE_TABBED, profile1));
469
470 // And for profile2.
471 scoped_ptr<Browser> browser2(new Browser(Browser::TYPE_TABBED, profile2));
472
473 std::vector<Profile*> last_opened_profiles =
474 profile_manager->GetLastOpenedProfiles();
475 ASSERT_EQ(2U, last_opened_profiles.size());
476 EXPECT_EQ(profile1, last_opened_profiles[0]);
477 EXPECT_EQ(profile2, last_opened_profiles[1]);
478
479 // Simulate a shutdown.
480 content::NotificationService::current()->Notify(
481 content::NOTIFICATION_APP_EXITING,
482 content::NotificationService::AllSources(),
483 content::NotificationService::NoDetails());
484
485 // Even if the browsers are destructed during shutdown, the profiles stay
486 // open.
487 browser1.reset();
488 browser2.reset();
489
490 last_opened_profiles = profile_manager->GetLastOpenedProfiles();
491 ASSERT_EQ(2U, last_opened_profiles.size());
492 EXPECT_EQ(profile1, last_opened_profiles[0]);
493 EXPECT_EQ(profile2, last_opened_profiles[1]);
494 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | chrome/browser/ui/browser_init.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698