| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 | 620 |
| 621 TestingProfile* profile2 = | 621 TestingProfile* profile2 = |
| 622 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2)); | 622 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2)); |
| 623 ASSERT_TRUE(profile2); | 623 ASSERT_TRUE(profile2); |
| 624 | 624 |
| 625 std::vector<Profile*> last_opened_profiles = | 625 std::vector<Profile*> last_opened_profiles = |
| 626 profile_manager->GetLastOpenedProfiles(); | 626 profile_manager->GetLastOpenedProfiles(); |
| 627 ASSERT_EQ(0U, last_opened_profiles.size()); | 627 ASSERT_EQ(0U, last_opened_profiles.size()); |
| 628 | 628 |
| 629 // Create a browser for profile1. | 629 // Create a browser for profile1. |
| 630 Browser::CreateParams profile1_params(profile1, chrome::GetActiveDesktop()); | 630 Browser::CreateParams profile1_params(profile1); |
| 631 scoped_ptr<Browser> browser1a( | 631 scoped_ptr<Browser> browser1a( |
| 632 chrome::CreateBrowserWithTestWindowForParams(&profile1_params)); | 632 chrome::CreateBrowserWithTestWindowForParams(&profile1_params)); |
| 633 | 633 |
| 634 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 634 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
| 635 ASSERT_EQ(1U, last_opened_profiles.size()); | 635 ASSERT_EQ(1U, last_opened_profiles.size()); |
| 636 EXPECT_EQ(profile1, last_opened_profiles[0]); | 636 EXPECT_EQ(profile1, last_opened_profiles[0]); |
| 637 | 637 |
| 638 // And for profile2. | 638 // And for profile2. |
| 639 Browser::CreateParams profile2_params(profile2, chrome::GetActiveDesktop()); | 639 Browser::CreateParams profile2_params(profile2); |
| 640 scoped_ptr<Browser> browser2( | 640 scoped_ptr<Browser> browser2( |
| 641 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); | 641 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); |
| 642 | 642 |
| 643 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 643 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
| 644 ASSERT_EQ(2U, last_opened_profiles.size()); | 644 ASSERT_EQ(2U, last_opened_profiles.size()); |
| 645 EXPECT_EQ(profile1, last_opened_profiles[0]); | 645 EXPECT_EQ(profile1, last_opened_profiles[0]); |
| 646 EXPECT_EQ(profile2, last_opened_profiles[1]); | 646 EXPECT_EQ(profile2, last_opened_profiles[1]); |
| 647 | 647 |
| 648 // Adding more browsers doesn't change anything. | 648 // Adding more browsers doesn't change anything. |
| 649 scoped_ptr<Browser> browser1b( | 649 scoped_ptr<Browser> browser1b( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 // Successfully create the profiles. | 682 // Successfully create the profiles. |
| 683 TestingProfile* profile1 = | 683 TestingProfile* profile1 = |
| 684 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); | 684 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); |
| 685 ASSERT_TRUE(profile1); | 685 ASSERT_TRUE(profile1); |
| 686 | 686 |
| 687 TestingProfile* profile2 = | 687 TestingProfile* profile2 = |
| 688 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2)); | 688 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2)); |
| 689 ASSERT_TRUE(profile2); | 689 ASSERT_TRUE(profile2); |
| 690 | 690 |
| 691 // Create a browser for profile1. | 691 // Create a browser for profile1. |
| 692 Browser::CreateParams profile1_params(profile1, chrome::GetActiveDesktop()); | 692 Browser::CreateParams profile1_params(profile1); |
| 693 scoped_ptr<Browser> browser1( | 693 scoped_ptr<Browser> browser1( |
| 694 chrome::CreateBrowserWithTestWindowForParams(&profile1_params)); | 694 chrome::CreateBrowserWithTestWindowForParams(&profile1_params)); |
| 695 | 695 |
| 696 // And for profile2. | 696 // And for profile2. |
| 697 Browser::CreateParams profile2_params(profile2, chrome::GetActiveDesktop()); | 697 Browser::CreateParams profile2_params(profile2); |
| 698 scoped_ptr<Browser> browser2( | 698 scoped_ptr<Browser> browser2( |
| 699 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); | 699 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); |
| 700 | 700 |
| 701 std::vector<Profile*> last_opened_profiles = | 701 std::vector<Profile*> last_opened_profiles = |
| 702 profile_manager->GetLastOpenedProfiles(); | 702 profile_manager->GetLastOpenedProfiles(); |
| 703 ASSERT_EQ(2U, last_opened_profiles.size()); | 703 ASSERT_EQ(2U, last_opened_profiles.size()); |
| 704 EXPECT_EQ(profile1, last_opened_profiles[0]); | 704 EXPECT_EQ(profile1, last_opened_profiles[0]); |
| 705 EXPECT_EQ(profile2, last_opened_profiles[1]); | 705 EXPECT_EQ(profile2, last_opened_profiles[1]); |
| 706 | 706 |
| 707 // Simulate a shutdown. | 707 // Simulate a shutdown. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 732 // Successfully create the profiles. | 732 // Successfully create the profiles. |
| 733 TestingProfile* profile1 = | 733 TestingProfile* profile1 = |
| 734 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); | 734 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); |
| 735 ASSERT_TRUE(profile1); | 735 ASSERT_TRUE(profile1); |
| 736 | 736 |
| 737 std::vector<Profile*> last_opened_profiles = | 737 std::vector<Profile*> last_opened_profiles = |
| 738 profile_manager->GetLastOpenedProfiles(); | 738 profile_manager->GetLastOpenedProfiles(); |
| 739 ASSERT_EQ(0U, last_opened_profiles.size()); | 739 ASSERT_EQ(0U, last_opened_profiles.size()); |
| 740 | 740 |
| 741 // Create a browser for profile1. | 741 // Create a browser for profile1. |
| 742 Browser::CreateParams profile1_params(profile1, chrome::GetActiveDesktop()); | 742 Browser::CreateParams profile1_params(profile1); |
| 743 scoped_ptr<Browser> browser1( | 743 scoped_ptr<Browser> browser1( |
| 744 chrome::CreateBrowserWithTestWindowForParams(&profile1_params)); | 744 chrome::CreateBrowserWithTestWindowForParams(&profile1_params)); |
| 745 | 745 |
| 746 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 746 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
| 747 ASSERT_EQ(1U, last_opened_profiles.size()); | 747 ASSERT_EQ(1U, last_opened_profiles.size()); |
| 748 EXPECT_EQ(profile1, last_opened_profiles[0]); | 748 EXPECT_EQ(profile1, last_opened_profiles[0]); |
| 749 | 749 |
| 750 // And for profile2. | 750 // And for profile2. |
| 751 Browser::CreateParams profile2_params(profile1->GetOffTheRecordProfile(), | 751 Browser::CreateParams profile2_params(profile1->GetOffTheRecordProfile()); |
| 752 chrome::GetActiveDesktop()); | |
| 753 scoped_ptr<Browser> browser2a( | 752 scoped_ptr<Browser> browser2a( |
| 754 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); | 753 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); |
| 755 | 754 |
| 756 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 755 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
| 757 ASSERT_EQ(1U, last_opened_profiles.size()); | 756 ASSERT_EQ(1U, last_opened_profiles.size()); |
| 758 EXPECT_EQ(profile1, last_opened_profiles[0]); | 757 EXPECT_EQ(profile1, last_opened_profiles[0]); |
| 759 | 758 |
| 760 // Adding more browsers doesn't change anything. | 759 // Adding more browsers doesn't change anything. |
| 761 scoped_ptr<Browser> browser2b( | 760 scoped_ptr<Browser> browser2b( |
| 762 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); | 761 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 792 TestingProfile* profile = | 791 TestingProfile* profile = |
| 793 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path)); | 792 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path)); |
| 794 ASSERT_TRUE(profile); | 793 ASSERT_TRUE(profile); |
| 795 profile->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, true); | 794 profile->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, true); |
| 796 | 795 |
| 797 // Here the last used profile is still the "Default" profile. | 796 // Here the last used profile is still the "Default" profile. |
| 798 Profile* last_used_profile = profile_manager->GetLastUsedProfile(); | 797 Profile* last_used_profile = profile_manager->GetLastUsedProfile(); |
| 799 EXPECT_NE(profile, last_used_profile); | 798 EXPECT_NE(profile, last_used_profile); |
| 800 | 799 |
| 801 // Create a browser for the profile. | 800 // Create a browser for the profile. |
| 802 Browser::CreateParams profile_params(profile, chrome::GetActiveDesktop()); | 801 Browser::CreateParams profile_params(profile); |
| 803 scoped_ptr<Browser> browser( | 802 scoped_ptr<Browser> browser( |
| 804 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); | 803 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); |
| 805 last_used_profile = profile_manager->GetLastUsedProfile(); | 804 last_used_profile = profile_manager->GetLastUsedProfile(); |
| 806 EXPECT_NE(profile, last_used_profile); | 805 EXPECT_NE(profile, last_used_profile); |
| 807 | 806 |
| 808 // Close the browser. | 807 // Close the browser. |
| 809 browser.reset(); | 808 browser.reset(); |
| 810 last_used_profile = profile_manager->GetLastUsedProfile(); | 809 last_used_profile = profile_manager->GetLastUsedProfile(); |
| 811 EXPECT_NE(profile, last_used_profile); | 810 EXPECT_NE(profile, last_used_profile); |
| 812 } | 811 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 834 ASSERT_TRUE(ephemeral_profile1); | 833 ASSERT_TRUE(ephemeral_profile1); |
| 835 ephemeral_profile1->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, | 834 ephemeral_profile1->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, |
| 836 true); | 835 true); |
| 837 | 836 |
| 838 // Add second ephemeral profile but don't mark it as such yet. | 837 // Add second ephemeral profile but don't mark it as such yet. |
| 839 TestingProfile* ephemeral_profile2 = | 838 TestingProfile* ephemeral_profile2 = |
| 840 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path3)); | 839 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path3)); |
| 841 ASSERT_TRUE(ephemeral_profile2); | 840 ASSERT_TRUE(ephemeral_profile2); |
| 842 | 841 |
| 843 // Create a browser for profile1. | 842 // Create a browser for profile1. |
| 844 Browser::CreateParams profile1_params(normal_profile, | 843 Browser::CreateParams profile1_params(normal_profile); |
| 845 chrome::GetActiveDesktop()); | |
| 846 scoped_ptr<Browser> browser1( | 844 scoped_ptr<Browser> browser1( |
| 847 chrome::CreateBrowserWithTestWindowForParams(&profile1_params)); | 845 chrome::CreateBrowserWithTestWindowForParams(&profile1_params)); |
| 848 | 846 |
| 849 // Create browsers for the ephemeral profile. | 847 // Create browsers for the ephemeral profile. |
| 850 Browser::CreateParams profile2_params(ephemeral_profile1, | 848 Browser::CreateParams profile2_params(ephemeral_profile1); |
| 851 chrome::GetActiveDesktop()); | |
| 852 scoped_ptr<Browser> browser2( | 849 scoped_ptr<Browser> browser2( |
| 853 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); | 850 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); |
| 854 | 851 |
| 855 Browser::CreateParams profile3_params(ephemeral_profile2, | 852 Browser::CreateParams profile3_params(ephemeral_profile2); |
| 856 chrome::GetActiveDesktop()); | |
| 857 scoped_ptr<Browser> browser3( | 853 scoped_ptr<Browser> browser3( |
| 858 chrome::CreateBrowserWithTestWindowForParams(&profile3_params)); | 854 chrome::CreateBrowserWithTestWindowForParams(&profile3_params)); |
| 859 | 855 |
| 860 std::vector<Profile*> last_opened_profiles = | 856 std::vector<Profile*> last_opened_profiles = |
| 861 profile_manager->GetLastOpenedProfiles(); | 857 profile_manager->GetLastOpenedProfiles(); |
| 862 ASSERT_EQ(2U, last_opened_profiles.size()); | 858 ASSERT_EQ(2U, last_opened_profiles.size()); |
| 863 EXPECT_EQ(normal_profile, last_opened_profiles[0]); | 859 EXPECT_EQ(normal_profile, last_opened_profiles[0]); |
| 864 EXPECT_EQ(ephemeral_profile2, last_opened_profiles[1]); | 860 EXPECT_EQ(ephemeral_profile2, last_opened_profiles[1]); |
| 865 | 861 |
| 866 // Mark the second profile ephemeral. | 862 // Mark the second profile ephemeral. |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 dest_path2.BaseName().MaybeAsASCII()); | 1339 dest_path2.BaseName().MaybeAsASCII()); |
| 1344 profile_manager->ScheduleProfileForDeletion(dest_path2, | 1340 profile_manager->ScheduleProfileForDeletion(dest_path2, |
| 1345 ProfileManager::CreateCallback()); | 1341 ProfileManager::CreateCallback()); |
| 1346 // Spin the message loop so that all the callbacks can finish running. | 1342 // Spin the message loop so that all the callbacks can finish running. |
| 1347 base::RunLoop().RunUntilIdle(); | 1343 base::RunLoop().RunUntilIdle(); |
| 1348 | 1344 |
| 1349 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); | 1345 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); |
| 1350 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); | 1346 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); |
| 1351 } | 1347 } |
| 1352 #endif // !defined(OS_MACOSX) | 1348 #endif // !defined(OS_MACOSX) |
| OLD | NEW |