| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 using testing::_; | 61 using testing::_; |
| 62 using testing::Return; | 62 using testing::Return; |
| 63 #endif // defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS) | 63 #endif // defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS) |
| 64 | 64 |
| 65 #if defined(ENABLE_SUPERVISED_USERS) | 65 #if defined(ENABLE_SUPERVISED_USERS) |
| 66 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h" | 66 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h" |
| 67 #include "chrome/browser/supervised_user/supervised_user_service.h" | 67 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 68 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 68 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 69 #endif | 69 #endif |
| 70 | 70 |
| 71 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 72 #include "base/mac/scoped_nsautorelease_pool.h" |
| 73 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 74 |
| 71 using extensions::Extension; | 75 using extensions::Extension; |
| 72 | 76 |
| 73 namespace { | 77 namespace { |
| 74 | 78 |
| 75 // Check that there are two browsers. Find the one that is not |browser|. | 79 // Check that there are two browsers. Find the one that is not |browser|. |
| 76 Browser* FindOneOtherBrowser(Browser* browser) { | 80 Browser* FindOneOtherBrowser(Browser* browser) { |
| 77 // There should only be one other browser. | 81 // There should only be one other browser. |
| 78 EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile(), | 82 EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile(), |
| 79 browser->host_desktop_type())); | 83 browser->host_desktop_type())); |
| 80 | 84 |
| 81 // Find the new browser. | 85 // Find the new browser. |
| 82 Browser* other_browser = NULL; | 86 Browser* other_browser = NULL; |
| 83 for (chrome::BrowserIterator it; !it.done() && !other_browser; it.Next()) { | 87 for (chrome::BrowserIterator it; !it.done() && !other_browser; it.Next()) { |
| 84 if (*it != browser) | 88 if (*it != browser) |
| 85 other_browser = *it; | 89 other_browser = *it; |
| 86 } | 90 } |
| 87 return other_browser; | 91 return other_browser; |
| 88 } | 92 } |
| 89 | 93 |
| 90 } // namespace | 94 } // namespace |
| 91 | 95 |
| 92 class StartupBrowserCreatorTest : public ExtensionBrowserTest { | 96 class StartupBrowserCreatorTest : public ExtensionBrowserTest { |
| 93 protected: | 97 protected: |
| 94 StartupBrowserCreatorTest() {} | 98 StartupBrowserCreatorTest() {} |
| 95 | 99 |
| 96 bool SetUpUserDataDirectory() override { | 100 bool SetUpUserDataDirectory() override { |
| 97 return ExtensionBrowserTest::SetUpUserDataDirectory(); | 101 return ExtensionBrowserTest::SetUpUserDataDirectory(); |
| 98 } | 102 } |
| 99 | 103 |
| 104 void CloseBrowser(Browser* browser) { |
| 105 browser->window()->Close(); |
| 106 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 107 AutoreleasePool()->Recycle(); |
| 108 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 109 } |
| 110 |
| 100 void SetUpCommandLine(base::CommandLine* command_line) override { | 111 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 101 ExtensionBrowserTest::SetUpCommandLine(command_line); | 112 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 102 command_line->AppendSwitch(switches::kEnablePanels); | 113 command_line->AppendSwitch(switches::kEnablePanels); |
| 103 command_line->AppendSwitchASCII(switches::kHomePage, url::kAboutBlankURL); | 114 command_line->AppendSwitchASCII(switches::kHomePage, url::kAboutBlankURL); |
| 104 #if defined(OS_CHROMEOS) | 115 #if defined(OS_CHROMEOS) |
| 105 // TODO(nkostylev): Investigate if we can remove this switch. | 116 // TODO(nkostylev): Investigate if we can remove this switch. |
| 106 command_line->AppendSwitch(switches::kCreateBrowserOnStartupForTests); | 117 command_line->AppendSwitch(switches::kCreateBrowserOnStartupForTests); |
| 107 #endif | 118 #endif |
| 108 } | 119 } |
| 109 | 120 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 std::vector<GURL> urls; | 221 std::vector<GURL> urls; |
| 211 urls.push_back(test_server()->GetURL("files/title1.html")); | 222 urls.push_back(test_server()->GetURL("files/title1.html")); |
| 212 urls.push_back(test_server()->GetURL("files/title2.html")); | 223 urls.push_back(test_server()->GetURL("files/title2.html")); |
| 213 | 224 |
| 214 // Set the startup preference to open these URLs. | 225 // Set the startup preference to open these URLs. |
| 215 SessionStartupPref pref(SessionStartupPref::URLS); | 226 SessionStartupPref pref(SessionStartupPref::URLS); |
| 216 pref.urls = urls; | 227 pref.urls = urls; |
| 217 SessionStartupPref::SetStartupPref(browser()->profile(), pref); | 228 SessionStartupPref::SetStartupPref(browser()->profile(), pref); |
| 218 | 229 |
| 219 // Close the browser. | 230 // Close the browser. |
| 220 browser()->window()->Close(); | 231 CloseBrowser(browser()); |
| 221 | 232 |
| 222 // Do a simple non-process-startup browser launch. | 233 // Do a simple non-process-startup browser launch. |
| 223 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); | 234 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); |
| 224 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? | 235 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? |
| 225 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | 236 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; |
| 226 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); | 237 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); |
| 227 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, | 238 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, |
| 228 browser()->host_desktop_type())); | 239 browser()->host_desktop_type())); |
| 229 | 240 |
| 230 // This should have created a new browser window. |browser()| is still | 241 // This should have created a new browser window. |browser()| is still |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 | 636 |
| 626 // Set different startup preferences for the 2 profiles. | 637 // Set different startup preferences for the 2 profiles. |
| 627 SessionStartupPref pref1(SessionStartupPref::URLS); | 638 SessionStartupPref pref1(SessionStartupPref::URLS); |
| 628 pref1.urls = urls1; | 639 pref1.urls = urls1; |
| 629 SessionStartupPref::SetStartupPref(default_profile, pref1); | 640 SessionStartupPref::SetStartupPref(default_profile, pref1); |
| 630 SessionStartupPref pref2(SessionStartupPref::URLS); | 641 SessionStartupPref pref2(SessionStartupPref::URLS); |
| 631 pref2.urls = urls2; | 642 pref2.urls = urls2; |
| 632 SessionStartupPref::SetStartupPref(other_profile, pref2); | 643 SessionStartupPref::SetStartupPref(other_profile, pref2); |
| 633 | 644 |
| 634 // Close the browser. | 645 // Close the browser. |
| 635 browser()->window()->Close(); | 646 CloseBrowser(browser()); |
| 636 | 647 |
| 637 // Do a simple non-process-startup browser launch. | 648 // Do a simple non-process-startup browser launch. |
| 638 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); | 649 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); |
| 639 | 650 |
| 640 StartupBrowserCreator browser_creator; | 651 StartupBrowserCreator browser_creator; |
| 641 std::vector<Profile*> last_opened_profiles; | 652 std::vector<Profile*> last_opened_profiles; |
| 642 last_opened_profiles.push_back(default_profile); | 653 last_opened_profiles.push_back(default_profile); |
| 643 last_opened_profiles.push_back(other_profile); | 654 last_opened_profiles.push_back(other_profile); |
| 644 browser_creator.Start(dummy, profile_manager->user_data_dir(), | 655 browser_creator.Start(dummy, profile_manager->user_data_dir(), |
| 645 default_profile, last_opened_profiles); | 656 default_profile, last_opened_profiles); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 dest_path.Append(FILE_PATH_LITERAL("New Profile 2"))); | 694 dest_path.Append(FILE_PATH_LITERAL("New Profile 2"))); |
| 684 ASSERT_TRUE(profile2); | 695 ASSERT_TRUE(profile2); |
| 685 | 696 |
| 686 // Open some urls with the browsers, and close them. | 697 // Open some urls with the browsers, and close them. |
| 687 Browser* browser1 = new Browser( | 698 Browser* browser1 = new Browser( |
| 688 Browser::CreateParams(Browser::TYPE_TABBED, profile1, | 699 Browser::CreateParams(Browser::TYPE_TABBED, profile1, |
| 689 browser()->host_desktop_type())); | 700 browser()->host_desktop_type())); |
| 690 chrome::NewTab(browser1); | 701 chrome::NewTab(browser1); |
| 691 ui_test_utils::NavigateToURL(browser1, | 702 ui_test_utils::NavigateToURL(browser1, |
| 692 test_server()->GetURL("files/empty.html")); | 703 test_server()->GetURL("files/empty.html")); |
| 693 browser1->window()->Close(); | 704 CloseBrowser(browser1); |
| 694 | 705 |
| 695 Browser* browser2 = new Browser( | 706 Browser* browser2 = new Browser( |
| 696 Browser::CreateParams(Browser::TYPE_TABBED, profile2, | 707 Browser::CreateParams(Browser::TYPE_TABBED, profile2, |
| 697 browser()->host_desktop_type())); | 708 browser()->host_desktop_type())); |
| 698 chrome::NewTab(browser2); | 709 chrome::NewTab(browser2); |
| 699 ui_test_utils::NavigateToURL(browser2, | 710 ui_test_utils::NavigateToURL(browser2, |
| 700 test_server()->GetURL("files/form.html")); | 711 test_server()->GetURL("files/form.html")); |
| 701 browser2->window()->Close(); | 712 CloseBrowser(browser2); |
| 702 | 713 |
| 703 // Set different startup preferences for the 2 profiles. | 714 // Set different startup preferences for the 2 profiles. |
| 704 std::vector<GURL> urls1; | 715 std::vector<GURL> urls1; |
| 705 urls1.push_back(ui_test_utils::GetTestUrl( | 716 urls1.push_back(ui_test_utils::GetTestUrl( |
| 706 base::FilePath(base::FilePath::kCurrentDirectory), | 717 base::FilePath(base::FilePath::kCurrentDirectory), |
| 707 base::FilePath(FILE_PATH_LITERAL("title1.html")))); | 718 base::FilePath(FILE_PATH_LITERAL("title1.html")))); |
| 708 std::vector<GURL> urls2; | 719 std::vector<GURL> urls2; |
| 709 urls2.push_back(ui_test_utils::GetTestUrl( | 720 urls2.push_back(ui_test_utils::GetTestUrl( |
| 710 base::FilePath(base::FilePath::kCurrentDirectory), | 721 base::FilePath(base::FilePath::kCurrentDirectory), |
| 711 base::FilePath(FILE_PATH_LITERAL("title2.html")))); | 722 base::FilePath(FILE_PATH_LITERAL("title2.html")))); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 pref_urls.urls = urls; | 850 pref_urls.urls = urls; |
| 840 SessionStartupPref::SetStartupPref(profile_urls, pref_urls); | 851 SessionStartupPref::SetStartupPref(profile_urls, pref_urls); |
| 841 | 852 |
| 842 // Open a page with profile_last. | 853 // Open a page with profile_last. |
| 843 Browser* browser_last = new Browser( | 854 Browser* browser_last = new Browser( |
| 844 Browser::CreateParams(Browser::TYPE_TABBED, profile_last, | 855 Browser::CreateParams(Browser::TYPE_TABBED, profile_last, |
| 845 browser()->host_desktop_type())); | 856 browser()->host_desktop_type())); |
| 846 chrome::NewTab(browser_last); | 857 chrome::NewTab(browser_last); |
| 847 ui_test_utils::NavigateToURL(browser_last, | 858 ui_test_utils::NavigateToURL(browser_last, |
| 848 test_server()->GetURL("files/empty.html")); | 859 test_server()->GetURL("files/empty.html")); |
| 849 browser_last->window()->Close(); | 860 CloseBrowser(browser_last); |
| 850 | 861 |
| 851 // Close the main browser. | 862 // Close the main browser. |
| 852 chrome::HostDesktopType original_desktop_type = | 863 chrome::HostDesktopType original_desktop_type = |
| 853 browser()->host_desktop_type(); | 864 browser()->host_desktop_type(); |
| 854 browser()->window()->Close(); | 865 CloseBrowser(browser()); |
| 855 | 866 |
| 856 // Do a simple non-process-startup browser launch. | 867 // Do a simple non-process-startup browser launch. |
| 857 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); | 868 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); |
| 858 | 869 |
| 859 StartupBrowserCreator browser_creator; | 870 StartupBrowserCreator browser_creator; |
| 860 std::vector<Profile*> last_opened_profiles; | 871 std::vector<Profile*> last_opened_profiles; |
| 861 last_opened_profiles.push_back(profile_home1); | 872 last_opened_profiles.push_back(profile_home1); |
| 862 last_opened_profiles.push_back(profile_home2); | 873 last_opened_profiles.push_back(profile_home2); |
| 863 last_opened_profiles.push_back(profile_last); | 874 last_opened_profiles.push_back(profile_last); |
| 864 last_opened_profiles.push_back(profile_urls); | 875 last_opened_profiles.push_back(profile_urls); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 std::vector<GURL> urls; | 953 std::vector<GURL> urls; |
| 943 urls.push_back(ui_test_utils::GetTestUrl( | 954 urls.push_back(ui_test_utils::GetTestUrl( |
| 944 base::FilePath(base::FilePath::kCurrentDirectory), | 955 base::FilePath(base::FilePath::kCurrentDirectory), |
| 945 base::FilePath(FILE_PATH_LITERAL("title1.html")))); | 956 base::FilePath(FILE_PATH_LITERAL("title1.html")))); |
| 946 | 957 |
| 947 SessionStartupPref pref_urls(SessionStartupPref::URLS); | 958 SessionStartupPref pref_urls(SessionStartupPref::URLS); |
| 948 pref_urls.urls = urls; | 959 pref_urls.urls = urls; |
| 949 SessionStartupPref::SetStartupPref(profile_urls, pref_urls); | 960 SessionStartupPref::SetStartupPref(profile_urls, pref_urls); |
| 950 | 961 |
| 951 // Simulate a launch after an unclear exit. | 962 // Simulate a launch after an unclear exit. |
| 952 browser()->window()->Close(); | 963 CloseBrowser(browser()); |
| 953 static_cast<ProfileImpl*>(profile_home)->last_session_exit_type_ = | 964 static_cast<ProfileImpl*>(profile_home)->last_session_exit_type_ = |
| 954 Profile::EXIT_CRASHED; | 965 Profile::EXIT_CRASHED; |
| 955 static_cast<ProfileImpl*>(profile_last)->last_session_exit_type_ = | 966 static_cast<ProfileImpl*>(profile_last)->last_session_exit_type_ = |
| 956 Profile::EXIT_CRASHED; | 967 Profile::EXIT_CRASHED; |
| 957 static_cast<ProfileImpl*>(profile_urls)->last_session_exit_type_ = | 968 static_cast<ProfileImpl*>(profile_urls)->last_session_exit_type_ = |
| 958 Profile::EXIT_CRASHED; | 969 Profile::EXIT_CRASHED; |
| 959 | 970 |
| 960 #if !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD) | 971 #if !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD) |
| 961 // Use HistogramTester to make sure a bubble is shown when it's not on | 972 // Use HistogramTester to make sure a bubble is shown when it's not on |
| 962 // platform Mac OS X and it's not official Chrome build. | 973 // platform Mac OS X and it's not official Chrome build. |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 ASSERT_EQ(1, tab_strip->count()); | 1477 ASSERT_EQ(1, tab_strip->count()); |
| 1467 EXPECT_EQ("title1.html", | 1478 EXPECT_EQ("title1.html", |
| 1468 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); | 1479 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); |
| 1469 } | 1480 } |
| 1470 #endif // defined(ENABLE_CONFIGURATION_POLICY) | 1481 #endif // defined(ENABLE_CONFIGURATION_POLICY) |
| 1471 | 1482 |
| 1472 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) || | 1483 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) || |
| 1473 // defined(ENABLE_CONFIGURATION_POLICY) | 1484 // defined(ENABLE_CONFIGURATION_POLICY) |
| 1474 | 1485 |
| 1475 #endif // !defined(OS_CHROMEOS) | 1486 #endif // !defined(OS_CHROMEOS) |
| OLD | NEW |