Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator_browsertest.cc

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

Powered by Google App Engine
This is Rietveld 408576698