| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" | 9 #include "chrome/browser/extensions/extension_browsertest.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
| 12 #include "chrome/browser/first_run/first_run.h" | 12 #include "chrome/browser/first_run/first_run.h" |
| 13 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
| 14 #include "chrome/browser/operation_output.h" |
| 14 #include "chrome/browser/prefs/session_startup_pref.h" | 15 #include "chrome/browser/prefs/session_startup_pref.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/profiles/profile_impl.h" | 17 #include "chrome/browser/profiles/profile_impl.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/browser/sessions/session_restore.h" | 19 #include "chrome/browser/sessions/session_restore.h" |
| 19 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
| 21 #include "chrome/browser/ui/browser_iterator.h" | 22 #include "chrome/browser/ui/browser_iterator.h" |
| 22 #include "chrome/browser/ui/browser_list.h" | 23 #include "chrome/browser/ui/browser_list.h" |
| 23 #include "chrome/browser/ui/browser_list_observer.h" | 24 #include "chrome/browser/ui/browser_list_observer.h" |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 SessionStartupPref pref2(SessionStartupPref::URLS); | 580 SessionStartupPref pref2(SessionStartupPref::URLS); |
| 580 pref2.urls = urls2; | 581 pref2.urls = urls2; |
| 581 SessionStartupPref::SetStartupPref(other_profile, pref2); | 582 SessionStartupPref::SetStartupPref(other_profile, pref2); |
| 582 | 583 |
| 583 // Close the browser. | 584 // Close the browser. |
| 584 browser()->window()->Close(); | 585 browser()->window()->Close(); |
| 585 | 586 |
| 586 // Do a simple non-process-startup browser launch. | 587 // Do a simple non-process-startup browser launch. |
| 587 CommandLine dummy(CommandLine::NO_PROGRAM); | 588 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 588 | 589 |
| 589 int return_code; | |
| 590 StartupBrowserCreator browser_creator; | 590 StartupBrowserCreator browser_creator; |
| 591 std::vector<Profile*> last_opened_profiles; | 591 std::vector<Profile*> last_opened_profiles; |
| 592 last_opened_profiles.push_back(default_profile); | 592 last_opened_profiles.push_back(default_profile); |
| 593 last_opened_profiles.push_back(other_profile); | 593 last_opened_profiles.push_back(other_profile); |
| 594 browser_creator.Start(dummy, profile_manager->user_data_dir(), | 594 browser_creator.Start(dummy, profile_manager->user_data_dir(), |
| 595 default_profile, last_opened_profiles, &return_code); | 595 default_profile, last_opened_profiles, |
| 596 scoped_ptr<OperationOutput>()); |
| 596 | 597 |
| 597 // urls1 were opened in a browser for default_profile, and urls2 were opened | 598 // urls1 were opened in a browser for default_profile, and urls2 were opened |
| 598 // in a browser for other_profile. | 599 // in a browser for other_profile. |
| 599 Browser* new_browser = NULL; | 600 Browser* new_browser = NULL; |
| 600 // |browser()| is still around at this point, even though we've closed its | 601 // |browser()| is still around at this point, even though we've closed its |
| 601 // window. Thus the browser count for default_profile is 2. | 602 // window. Thus the browser count for default_profile is 2. |
| 602 ASSERT_EQ(2u, chrome::GetBrowserCount(default_profile, | 603 ASSERT_EQ(2u, chrome::GetBrowserCount(default_profile, |
| 603 browser()->host_desktop_type())); | 604 browser()->host_desktop_type())); |
| 604 new_browser = FindOneOtherBrowserForProfile(default_profile, browser()); | 605 new_browser = FindOneOtherBrowserForProfile(default_profile, browser()); |
| 605 ASSERT_TRUE(new_browser); | 606 ASSERT_TRUE(new_browser); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 // Set different startup preferences for the 2 profiles. | 649 // Set different startup preferences for the 2 profiles. |
| 649 SessionStartupPref pref1(SessionStartupPref::URLS); | 650 SessionStartupPref pref1(SessionStartupPref::URLS); |
| 650 pref1.urls = urls1; | 651 pref1.urls = urls1; |
| 651 SessionStartupPref::SetStartupPref(profile1, pref1); | 652 SessionStartupPref::SetStartupPref(profile1, pref1); |
| 652 SessionStartupPref pref2(SessionStartupPref::URLS); | 653 SessionStartupPref pref2(SessionStartupPref::URLS); |
| 653 pref2.urls = urls2; | 654 pref2.urls = urls2; |
| 654 SessionStartupPref::SetStartupPref(profile2, pref2); | 655 SessionStartupPref::SetStartupPref(profile2, pref2); |
| 655 | 656 |
| 656 // Simulate a launch after a browser update. | 657 // Simulate a launch after a browser update. |
| 657 CommandLine dummy(CommandLine::NO_PROGRAM); | 658 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 658 int return_code; | |
| 659 StartupBrowserCreator browser_creator; | 659 StartupBrowserCreator browser_creator; |
| 660 std::vector<Profile*> last_opened_profiles; | 660 std::vector<Profile*> last_opened_profiles; |
| 661 last_opened_profiles.push_back(profile1); | 661 last_opened_profiles.push_back(profile1); |
| 662 last_opened_profiles.push_back(profile2); | 662 last_opened_profiles.push_back(profile2); |
| 663 browser_creator.Start(dummy, profile_manager->user_data_dir(), profile1, | 663 browser_creator.Start(dummy, profile_manager->user_data_dir(), profile1, |
| 664 last_opened_profiles, &return_code); | 664 last_opened_profiles, scoped_ptr<OperationOutput>()); |
| 665 | 665 |
| 666 while (SessionRestore::IsRestoring(profile1) || | 666 while (SessionRestore::IsRestoring(profile1) || |
| 667 SessionRestore::IsRestoring(profile2)) | 667 SessionRestore::IsRestoring(profile2)) |
| 668 MessageLoop::current()->RunUntilIdle(); | 668 MessageLoop::current()->RunUntilIdle(); |
| 669 | 669 |
| 670 // The startup URLs are ignored, and instead the last open sessions are | 670 // The startup URLs are ignored, and instead the last open sessions are |
| 671 // restored. | 671 // restored. |
| 672 EXPECT_TRUE(profile1->restored_last_session()); | 672 EXPECT_TRUE(profile1->restored_last_session()); |
| 673 EXPECT_TRUE(profile2->restored_last_session()); | 673 EXPECT_TRUE(profile2->restored_last_session()); |
| 674 | 674 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 SessionStartupPref::SetStartupPref(profile_urls, pref_urls); | 736 SessionStartupPref::SetStartupPref(profile_urls, pref_urls); |
| 737 | 737 |
| 738 // Close the browser. | 738 // Close the browser. |
| 739 chrome::HostDesktopType original_desktop_type = | 739 chrome::HostDesktopType original_desktop_type = |
| 740 browser()->host_desktop_type(); | 740 browser()->host_desktop_type(); |
| 741 browser()->window()->Close(); | 741 browser()->window()->Close(); |
| 742 | 742 |
| 743 // Do a simple non-process-startup browser launch. | 743 // Do a simple non-process-startup browser launch. |
| 744 CommandLine dummy(CommandLine::NO_PROGRAM); | 744 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 745 | 745 |
| 746 int return_code; | |
| 747 StartupBrowserCreator browser_creator; | 746 StartupBrowserCreator browser_creator; |
| 748 std::vector<Profile*> last_opened_profiles; | 747 std::vector<Profile*> last_opened_profiles; |
| 749 last_opened_profiles.push_back(profile_home1); | 748 last_opened_profiles.push_back(profile_home1); |
| 750 last_opened_profiles.push_back(profile_home2); | 749 last_opened_profiles.push_back(profile_home2); |
| 751 last_opened_profiles.push_back(profile_last); | 750 last_opened_profiles.push_back(profile_last); |
| 752 last_opened_profiles.push_back(profile_urls); | 751 last_opened_profiles.push_back(profile_urls); |
| 753 browser_creator.Start(dummy, profile_manager->user_data_dir(), profile_home1, | 752 browser_creator.Start(dummy, profile_manager->user_data_dir(), profile_home1, |
| 754 last_opened_profiles, &return_code); | 753 last_opened_profiles, scoped_ptr<OperationOutput>()); |
| 755 | 754 |
| 756 while (SessionRestore::IsRestoring(default_profile) || | 755 while (SessionRestore::IsRestoring(default_profile) || |
| 757 SessionRestore::IsRestoring(profile_home1) || | 756 SessionRestore::IsRestoring(profile_home1) || |
| 758 SessionRestore::IsRestoring(profile_home2) || | 757 SessionRestore::IsRestoring(profile_home2) || |
| 759 SessionRestore::IsRestoring(profile_last) || | 758 SessionRestore::IsRestoring(profile_last) || |
| 760 SessionRestore::IsRestoring(profile_urls)) | 759 SessionRestore::IsRestoring(profile_urls)) |
| 761 MessageLoop::current()->RunUntilIdle(); | 760 MessageLoop::current()->RunUntilIdle(); |
| 762 | 761 |
| 763 Browser* new_browser = NULL; | 762 Browser* new_browser = NULL; |
| 764 // The last open profile (the profile_home1 in this case) will always be | 763 // The last open profile (the profile_home1 in this case) will always be |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 browser()->window()->Close(); | 832 browser()->window()->Close(); |
| 834 static_cast<ProfileImpl*>(profile_home)->last_session_exit_type_ = | 833 static_cast<ProfileImpl*>(profile_home)->last_session_exit_type_ = |
| 835 Profile::EXIT_CRASHED; | 834 Profile::EXIT_CRASHED; |
| 836 static_cast<ProfileImpl*>(profile_last)->last_session_exit_type_ = | 835 static_cast<ProfileImpl*>(profile_last)->last_session_exit_type_ = |
| 837 Profile::EXIT_CRASHED; | 836 Profile::EXIT_CRASHED; |
| 838 static_cast<ProfileImpl*>(profile_urls)->last_session_exit_type_ = | 837 static_cast<ProfileImpl*>(profile_urls)->last_session_exit_type_ = |
| 839 Profile::EXIT_CRASHED; | 838 Profile::EXIT_CRASHED; |
| 840 | 839 |
| 841 CommandLine dummy(CommandLine::NO_PROGRAM); | 840 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 842 dummy.AppendSwitchASCII(switches::kTestType, "browser"); | 841 dummy.AppendSwitchASCII(switches::kTestType, "browser"); |
| 843 int return_code; | |
| 844 StartupBrowserCreator browser_creator; | 842 StartupBrowserCreator browser_creator; |
| 845 std::vector<Profile*> last_opened_profiles; | 843 std::vector<Profile*> last_opened_profiles; |
| 846 last_opened_profiles.push_back(profile_home); | 844 last_opened_profiles.push_back(profile_home); |
| 847 last_opened_profiles.push_back(profile_last); | 845 last_opened_profiles.push_back(profile_last); |
| 848 last_opened_profiles.push_back(profile_urls); | 846 last_opened_profiles.push_back(profile_urls); |
| 849 browser_creator.Start(dummy, profile_manager->user_data_dir(), profile_home, | 847 browser_creator.Start(dummy, profile_manager->user_data_dir(), profile_home, |
| 850 last_opened_profiles, &return_code); | 848 last_opened_profiles, scoped_ptr<OperationOutput>()); |
| 851 | 849 |
| 852 // No profiles are getting restored, since they all display the crash info | 850 // No profiles are getting restored, since they all display the crash info |
| 853 // bar. | 851 // bar. |
| 854 EXPECT_FALSE(SessionRestore::IsRestoring(profile_home)); | 852 EXPECT_FALSE(SessionRestore::IsRestoring(profile_home)); |
| 855 EXPECT_FALSE(SessionRestore::IsRestoring(profile_last)); | 853 EXPECT_FALSE(SessionRestore::IsRestoring(profile_last)); |
| 856 EXPECT_FALSE(SessionRestore::IsRestoring(profile_urls)); | 854 EXPECT_FALSE(SessionRestore::IsRestoring(profile_urls)); |
| 857 | 855 |
| 858 // The profile which normally opens the home page displays the new tab page. | 856 // The profile which normally opens the home page displays the new tab page. |
| 859 Browser* new_browser = NULL; | 857 Browser* new_browser = NULL; |
| 860 ASSERT_EQ(1u, chrome::GetBrowserCount(profile_home, | 858 ASSERT_EQ(1u, chrome::GetBrowserCount(profile_home, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 886 new_browser = FindOneOtherBrowserForProfile(profile_urls, NULL); | 884 new_browser = FindOneOtherBrowserForProfile(profile_urls, NULL); |
| 887 ASSERT_TRUE(new_browser); | 885 ASSERT_TRUE(new_browser); |
| 888 tab_strip = new_browser->tab_strip_model(); | 886 tab_strip = new_browser->tab_strip_model(); |
| 889 ASSERT_EQ(1, tab_strip->count()); | 887 ASSERT_EQ(1, tab_strip->count()); |
| 890 web_contents = tab_strip->GetWebContentsAt(0); | 888 web_contents = tab_strip->GetWebContentsAt(0); |
| 891 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), web_contents->GetURL()); | 889 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), web_contents->GetURL()); |
| 892 EXPECT_EQ(1U, | 890 EXPECT_EQ(1U, |
| 893 InfoBarService::FromWebContents(web_contents)->GetInfoBarCount()); | 891 InfoBarService::FromWebContents(web_contents)->GetInfoBarCount()); |
| 894 } | 892 } |
| 895 #endif // !OS_CHROMEOS | 893 #endif // !OS_CHROMEOS |
| OLD | NEW |