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