| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 for (Profile* profile : profiles) | 114 for (Profile* profile : profiles) |
| 115 profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true); | 115 profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true); |
| 116 | 116 |
| 117 #if defined(OS_WIN) | 117 #if defined(OS_WIN) |
| 118 g_browser_process->local_state()->SetBoolean(prefs::kHasSeenWin10PromoPage, | 118 g_browser_process->local_state()->SetBoolean(prefs::kHasSeenWin10PromoPage, |
| 119 true); | 119 true); |
| 120 #endif | 120 #endif |
| 121 } | 121 } |
| 122 #endif | 122 #endif |
| 123 | 123 |
| 124 Browser* OpenNewBrowser(Profile* profile) { |
| 125 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); |
| 126 { |
| 127 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, |
| 128 chrome::startup::IS_FIRST_RUN); |
| 129 launch.Launch(profile, std::vector<GURL>(), false); |
| 130 } |
| 131 return chrome::FindBrowserWithProfile(profile); |
| 132 } |
| 133 |
| 134 Browser* CloseBrowserAndOpenNew(Browser* browser, Profile* profile) { |
| 135 { |
| 136 content::WindowedNotificationObserver observer( |
| 137 chrome::NOTIFICATION_BROWSER_CLOSED, content::Source<Browser>(browser)); |
| 138 browser->window()->Close(); |
| 139 observer.Wait(); |
| 140 } |
| 141 return OpenNewBrowser(profile); |
| 142 } |
| 143 |
| 124 } // namespace | 144 } // namespace |
| 125 | 145 |
| 126 class StartupBrowserCreatorTest : public ExtensionBrowserTest { | 146 class StartupBrowserCreatorTest : public ExtensionBrowserTest { |
| 127 protected: | 147 protected: |
| 128 StartupBrowserCreatorTest() {} | 148 StartupBrowserCreatorTest() {} |
| 129 | 149 |
| 130 bool SetUpUserDataDirectory() override { | 150 bool SetUpUserDataDirectory() override { |
| 131 return ExtensionBrowserTest::SetUpUserDataDirectory(); | 151 return ExtensionBrowserTest::SetUpUserDataDirectory(); |
| 132 } | 152 } |
| 133 | 153 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 pref.urls = urls; | 271 pref.urls = urls; |
| 252 SessionStartupPref::SetStartupPref(profile, pref); | 272 SessionStartupPref::SetStartupPref(profile, pref); |
| 253 | 273 |
| 254 // Keep the browser process running while browsers are closed. | 274 // Keep the browser process running while browsers are closed. |
| 255 ScopedKeepAlive keep_alive(KeepAliveOrigin::BROWSER, | 275 ScopedKeepAlive keep_alive(KeepAliveOrigin::BROWSER, |
| 256 KeepAliveRestartOption::DISABLED); | 276 KeepAliveRestartOption::DISABLED); |
| 257 | 277 |
| 258 // Close the browser. | 278 // Close the browser. |
| 259 CloseBrowserAsynchronously(browser()); | 279 CloseBrowserAsynchronously(browser()); |
| 260 | 280 |
| 261 // Do a simple non-process-startup browser launch. | 281 Browser* new_browser = OpenNewBrowser(profile); |
| 262 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); | |
| 263 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? | |
| 264 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | |
| 265 { | |
| 266 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); | |
| 267 ASSERT_TRUE(launch.Launch(profile, std::vector<GURL>(), false)); | |
| 268 } | |
| 269 | |
| 270 // This should have created a new browser window. |browser()| is still | |
| 271 // around at this point, even though we've closed its window. | |
| 272 Browser* new_browser = FindOneOtherBrowser(browser()); | |
| 273 ASSERT_TRUE(new_browser); | 282 ASSERT_TRUE(new_browser); |
| 274 | 283 |
| 275 std::vector<GURL> expected_urls(urls); | 284 std::vector<GURL> expected_urls(urls); |
| 276 | 285 |
| 277 TabStripModel* tab_strip = new_browser->tab_strip_model(); | 286 TabStripModel* tab_strip = new_browser->tab_strip_model(); |
| 278 ASSERT_EQ(static_cast<int>(expected_urls.size()), tab_strip->count()); | 287 ASSERT_EQ(static_cast<int>(expected_urls.size()), tab_strip->count()); |
| 279 for (size_t i = 0; i < expected_urls.size(); i++) | 288 for (size_t i = 0; i < expected_urls.size(); i++) |
| 280 EXPECT_EQ(expected_urls[i], tab_strip->GetWebContentsAt(i)->GetURL()); | 289 EXPECT_EQ(expected_urls[i], tab_strip->GetWebContentsAt(i)->GetURL()); |
| 281 | 290 |
| 282 // The two test_server tabs, despite having the same site, should be in | 291 // The two test_server tabs, despite having the same site, should be in |
| 283 // different SiteInstances. | 292 // different SiteInstances. |
| 284 EXPECT_NE( | 293 EXPECT_NE( |
| 285 tab_strip->GetWebContentsAt(tab_strip->count() - 2)->GetSiteInstance(), | 294 tab_strip->GetWebContentsAt(tab_strip->count() - 2)->GetSiteInstance(), |
| 286 tab_strip->GetWebContentsAt(tab_strip->count() - 1)->GetSiteInstance()); | 295 tab_strip->GetWebContentsAt(tab_strip->count() - 1)->GetSiteInstance()); |
| 287 | |
| 288 } | 296 } |
| 289 | 297 |
| 290 // Verify that startup URLs aren't used when the process already exists | 298 // Verify that startup URLs aren't used when the process already exists |
| 291 // and has other tabbed browser windows. This is the common case of starting a | 299 // and has other tabbed browser windows. This is the common case of starting a |
| 292 // new browser. | 300 // new browser. |
| 293 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, | 301 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, |
| 294 StartupURLsOnNewWindow) { | 302 StartupURLsOnNewWindow) { |
| 295 // Use a couple arbitrary URLs. | 303 // Use a couple arbitrary URLs. |
| 296 std::vector<GURL> urls; | 304 std::vector<GURL> urls; |
| 297 urls.push_back(ui_test_utils::GetTestUrl( | 305 urls.push_back(ui_test_utils::GetTestUrl( |
| 298 base::FilePath(base::FilePath::kCurrentDirectory), | 306 base::FilePath(base::FilePath::kCurrentDirectory), |
| 299 base::FilePath(FILE_PATH_LITERAL("title1.html")))); | 307 base::FilePath(FILE_PATH_LITERAL("title1.html")))); |
| 300 urls.push_back(ui_test_utils::GetTestUrl( | 308 urls.push_back(ui_test_utils::GetTestUrl( |
| 301 base::FilePath(base::FilePath::kCurrentDirectory), | 309 base::FilePath(base::FilePath::kCurrentDirectory), |
| 302 base::FilePath(FILE_PATH_LITERAL("title2.html")))); | 310 base::FilePath(FILE_PATH_LITERAL("title2.html")))); |
| 303 | 311 |
| 304 // Set the startup preference to open these URLs. | 312 // Set the startup preference to open these URLs. |
| 305 SessionStartupPref pref(SessionStartupPref::URLS); | 313 SessionStartupPref pref(SessionStartupPref::URLS); |
| 306 pref.urls = urls; | 314 pref.urls = urls; |
| 307 SessionStartupPref::SetStartupPref(browser()->profile(), pref); | 315 SessionStartupPref::SetStartupPref(browser()->profile(), pref); |
| 308 | 316 |
| 309 // Do a simple non-process-startup browser launch. | 317 DisableWelcomePages({browser()->profile()}); |
| 310 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); | |
| 311 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? | |
| 312 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | |
| 313 { | |
| 314 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); | |
| 315 ASSERT_TRUE( | |
| 316 launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | |
| 317 } | |
| 318 | 318 |
| 319 // This should have created a new browser window. | 319 Browser* new_browser = OpenNewBrowser(browser()->profile()); |
| 320 Browser* new_browser = FindOneOtherBrowser(browser()); | |
| 321 ASSERT_TRUE(new_browser); | 320 ASSERT_TRUE(new_browser); |
| 322 | 321 |
| 323 // The new browser should have exactly one tab (not the startup URLs). | 322 // The new browser should have exactly one tab (not the startup URLs). |
| 324 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); | 323 TabStripModel* tab_strip = new_browser->tab_strip_model(); |
| 325 | 324 ASSERT_EQ(1, tab_strip->count()); |
| 326 // Test that the welcome page is not shown the second time through if it was | 325 EXPECT_EQ("chrome://newtab/", |
| 327 // above. | 326 tab_strip->GetWebContentsAt(0)->GetURL().possibly_invalid_spec()); |
| 328 if (!IsWindows10OrNewer()) { | |
| 329 // Close the browser opened above. | |
| 330 { | |
| 331 content::WindowedNotificationObserver observer( | |
| 332 chrome::NOTIFICATION_BROWSER_CLOSED, | |
| 333 content::Source<Browser>(new_browser)); | |
| 334 new_browser->window()->Close(); | |
| 335 observer.Wait(); | |
| 336 } | |
| 337 | |
| 338 { | |
| 339 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); | |
| 340 ASSERT_TRUE( | |
| 341 launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | |
| 342 } | |
| 343 | |
| 344 // Find the new browser and ensure that it has only the one tab this time. | |
| 345 new_browser = FindOneOtherBrowser(browser()); | |
| 346 ASSERT_TRUE(new_browser); | |
| 347 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); | |
| 348 } | |
| 349 } | 327 } |
| 350 | 328 |
| 351 // App shortcuts are not implemented on mac os. | 329 // App shortcuts are not implemented on mac os. |
| 352 #if !defined(OS_MACOSX) | 330 #if !defined(OS_MACOSX) |
| 353 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutNoPref) { | 331 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutNoPref) { |
| 354 // Load an app with launch.container = 'tab'. | 332 // Load an app with launch.container = 'tab'. |
| 355 const Extension* extension_app = NULL; | 333 const Extension* extension_app = NULL; |
| 356 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); | 334 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); |
| 357 | 335 |
| 358 // Add --app-id=<extension->id()> to the command line. | 336 // Add --app-id=<extension->id()> to the command line. |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 ASSERT_TRUE(new_browser); | 875 ASSERT_TRUE(new_browser); |
| 898 | 876 |
| 899 TabStripModel* tab_strip = new_browser->tab_strip_model(); | 877 TabStripModel* tab_strip = new_browser->tab_strip_model(); |
| 900 | 878 |
| 901 EXPECT_EQ(1, tab_strip->count()); | 879 EXPECT_EQ(1, tab_strip->count()); |
| 902 } | 880 } |
| 903 | 881 |
| 904 #endif // !defined(OS_CHROMEOS) | 882 #endif // !defined(OS_CHROMEOS) |
| 905 | 883 |
| 906 // These tests are not applicable to Chrome OS as neither master_preferences nor | 884 // These tests are not applicable to Chrome OS as neither master_preferences nor |
| 907 // the sync promo exist there. | 885 // the onboarding promos exist there. |
| 908 #if !defined(OS_CHROMEOS) | 886 #if !defined(OS_CHROMEOS) |
| 909 | 887 |
| 910 class StartupBrowserCreatorFirstRunTest : public InProcessBrowserTest { | 888 class StartupBrowserCreatorFirstRunTest : public InProcessBrowserTest { |
| 911 protected: | 889 protected: |
| 912 void SetUpCommandLine(base::CommandLine* command_line) override; | 890 void SetUpCommandLine(base::CommandLine* command_line) override; |
| 913 void SetUpInProcessBrowserTestFixture() override; | 891 void SetUpInProcessBrowserTestFixture() override; |
| 914 | 892 |
| 915 policy::MockConfigurationPolicyProvider provider_; | 893 policy::MockConfigurationPolicyProvider provider_; |
| 916 policy::PolicyMap policy_map_; | 894 policy::PolicyMap policy_map_; |
| 917 }; | 895 }; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 Browser* new_browser = FindOneOtherBrowser(browser()); | 1043 Browser* new_browser = FindOneOtherBrowser(browser()); |
| 1066 ASSERT_TRUE(new_browser); | 1044 ASSERT_TRUE(new_browser); |
| 1067 | 1045 |
| 1068 // Verify that the first-run tab is shown and no other pages are present. | 1046 // Verify that the first-run tab is shown and no other pages are present. |
| 1069 TabStripModel* tab_strip = new_browser->tab_strip_model(); | 1047 TabStripModel* tab_strip = new_browser->tab_strip_model(); |
| 1070 ASSERT_EQ(1, tab_strip->count()); | 1048 ASSERT_EQ(1, tab_strip->count()); |
| 1071 EXPECT_EQ("title1.html", | 1049 EXPECT_EQ("title1.html", |
| 1072 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); | 1050 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); |
| 1073 } | 1051 } |
| 1074 | 1052 |
| 1053 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest, WelcomePages) { |
| 1054 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1055 |
| 1056 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1057 |
| 1058 // Open the two profiles. |
| 1059 base::FilePath dest_path = profile_manager->user_data_dir(); |
| 1060 |
| 1061 Profile* profile1 = Profile::CreateProfile( |
| 1062 dest_path.Append(FILE_PATH_LITERAL("New Profile 1")), nullptr, |
| 1063 Profile::CreateMode::CREATE_MODE_SYNCHRONOUS); |
| 1064 ASSERT_TRUE(profile1); |
| 1065 profile_manager->RegisterTestingProfile(profile1, true, false); |
| 1066 |
| 1067 Browser* browser = OpenNewBrowser(profile1); |
| 1068 ASSERT_TRUE(browser); |
| 1069 |
| 1070 TabStripModel* tab_strip; |
| 1071 |
| 1072 // Windows 10 has its own Welcome page; the standard Welcome page does not |
| 1073 // appear until second run. |
| 1074 if (IsWindows10OrNewer()) { |
| 1075 ASSERT_TRUE(browser); |
| 1076 tab_strip = browser->tab_strip_model(); |
| 1077 |
| 1078 ASSERT_EQ(1, tab_strip->count()); |
| 1079 ASSERT_EQ("chrome://welcome-win10/", |
| 1080 tab_strip->GetWebContentsAt(0)->GetURL().possibly_invalid_spec()); |
| 1081 |
| 1082 browser = CloseBrowserAndOpenNew(browser, profile1); |
| 1083 ASSERT_TRUE(browser); |
| 1084 } |
| 1085 |
| 1086 tab_strip = browser->tab_strip_model(); |
| 1087 |
| 1088 // Ensure that the standard Welcome page appears on second run on Win 10, and |
| 1089 // on first run on all other platforms. |
| 1090 ASSERT_EQ(1, tab_strip->count()); |
| 1091 ASSERT_EQ("chrome://welcome/", |
| 1092 tab_strip->GetWebContentsAt(0)->GetURL().possibly_invalid_spec()); |
| 1093 |
| 1094 browser = CloseBrowserAndOpenNew(browser, profile1); |
| 1095 ASSERT_TRUE(browser); |
| 1096 tab_strip = browser->tab_strip_model(); |
| 1097 |
| 1098 // Ensure that the new tab page appears on subsequent runs. |
| 1099 ASSERT_EQ(1, tab_strip->count()); |
| 1100 ASSERT_EQ("chrome://newtab/", |
| 1101 tab_strip->GetWebContentsAt(0)->GetURL().possibly_invalid_spec()); |
| 1102 } |
| 1103 |
| 1075 #endif // !defined(OS_CHROMEOS) | 1104 #endif // !defined(OS_CHROMEOS) |
| OLD | NEW |