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
3 // found in the LICENSE file.
8 #include "base/command_line.h"
9 #include "base/files/file_path.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "base/test/histogram_tester.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/extensions/extension_browsertest.h"
15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/extension_util.h"
17 #include "chrome/browser/extensions/launch_util.h"
18 #include "chrome/browser/first_run/first_run.h"
19 #include "chrome/browser/infobars/infobar_service.h"
20 #include "chrome/browser/prefs/session_startup_pref.h"
21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/profiles/profile_impl.h"
23 #include "chrome/browser/profiles/profile_manager.h"
24 #include "chrome/browser/sessions/session_restore.h"
25 #include "chrome/browser/signin/signin_promo.h"
26 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_commands.h"
28 #include "chrome/browser/ui/browser_finder.h"
29 #include "chrome/browser/ui/browser_iterator.h"
30 #include "chrome/browser/ui/browser_list.h"
31 #include "chrome/browser/ui/browser_list_observer.h"
32 #include "chrome/browser/ui/browser_window.h"
33 #include "chrome/browser/ui/host_desktop.h"
34 #include "chrome/browser/ui/startup/startup_browser_creator.h"
35 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
36 #include "chrome/browser/ui/tabs/tab_strip_model.h"
37 #include "chrome/common/chrome_switches.h"
38 #include "chrome/common/extensions/extension_constants.h"
39 #include "chrome/common/pref_names.h"
40 #include "chrome/common/url_constants.h"
41 #include "chrome/test/base/in_process_browser_test.h"
42 #include "chrome/test/base/test_switches.h"
43 #include "chrome/test/base/ui_test_utils.h"
44 #include "content/public/browser/web_contents.h"
45 #include "content/public/test/test_utils.h"
46 #include "extensions/browser/extension_system.h"
47 #include "testing/gtest/include/gtest/gtest.h"
50 #if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS)
51 #include "base/callback.h"
52 #include "base/run_loop.h"
53 #include "base/values.h"
54 #include "components/policy/core/browser/browser_policy_connector.h"
55 #include "components/policy/core/common/external_data_fetcher.h"
56 #include "components/policy/core/common/mock_configuration_policy_provider.h"
57 #include "components/policy/core/common/policy_map.h"
58 #include "components/policy/core/common/policy_types.h"
59 #include "policy/policy_constants.h"
60 #include "testing/gmock/include/gmock/gmock.h"
63 using testing::Return
;
64 #endif // defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS)
66 #if defined(ENABLE_SUPERVISED_USERS)
67 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h"
68 #include "chrome/browser/supervised_user/supervised_user_service.h"
69 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
73 #include "base/win/windows_version.h"
76 using extensions::Extension
;
80 // Check that there are two browsers. Find the one that is not |browser|.
81 Browser
* FindOneOtherBrowser(Browser
* browser
) {
82 // There should only be one other browser.
83 EXPECT_EQ(2u, chrome::GetBrowserCount(browser
->profile(),
84 browser
->host_desktop_type()));
86 // Find the new browser.
87 Browser
* other_browser
= NULL
;
88 for (chrome::BrowserIterator it
; !it
.done() && !other_browser
; it
.Next()) {
95 bool IsWindows10OrNewer() {
97 return base::win::GetVersion() >= base::win::VERSION_WIN10
;
105 class StartupBrowserCreatorTest
: public ExtensionBrowserTest
{
107 StartupBrowserCreatorTest() {}
109 bool SetUpUserDataDirectory() override
{
110 return ExtensionBrowserTest::SetUpUserDataDirectory();
113 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
114 ExtensionBrowserTest::SetUpCommandLine(command_line
);
115 command_line
->AppendSwitch(switches::kEnablePanels
);
116 command_line
->AppendSwitchASCII(switches::kHomePage
, url::kAboutBlankURL
);
117 #if defined(OS_CHROMEOS)
118 // TODO(nkostylev): Investigate if we can remove this switch.
119 command_line
->AppendSwitch(switches::kCreateBrowserOnStartupForTests
);
123 // Helper functions return void so that we can ASSERT*().
124 // Use ASSERT_NO_FATAL_FAILURE around calls to these functions to stop the
125 // test if an assert fails.
126 void LoadApp(const std::string
& app_name
,
127 const Extension
** out_app_extension
) {
128 ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII(app_name
.c_str())));
130 ExtensionService
* service
= extensions::ExtensionSystem::Get(
131 browser()->profile())->extension_service();
132 *out_app_extension
= service
->GetExtensionById(
133 last_loaded_extension_id(), false);
134 ASSERT_TRUE(*out_app_extension
);
136 // Code that opens a new browser assumes we start with exactly one.
137 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
138 browser()->host_desktop_type()));
141 void SetAppLaunchPref(const std::string
& app_id
,
142 extensions::LaunchType launch_type
) {
143 extensions::SetLaunchType(browser()->profile(), app_id
, launch_type
);
146 Browser
* FindOneOtherBrowserForProfile(Profile
* profile
,
147 Browser
* not_this_browser
) {
148 for (chrome::BrowserIterator it
; !it
.done(); it
.Next()) {
149 if (*it
!= not_this_browser
&& it
->profile() == profile
)
155 // A helper function that checks the session restore UI (infobar) is shown
156 // when Chrome starts up after crash.
157 void EnsureRestoreUIWasShown(content::WebContents
* web_contents
) {
158 #if defined(OS_MACOSX)
159 InfoBarService
* infobar_service
=
160 InfoBarService::FromWebContents(web_contents
);
161 EXPECT_EQ(1U, infobar_service
->infobar_count());
162 #endif // defined(OS_MACOSX)
166 DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreatorTest
);
169 class OpenURLsPopupObserver
: public chrome::BrowserListObserver
{
171 OpenURLsPopupObserver() : added_browser_(NULL
) { }
173 void OnBrowserAdded(Browser
* browser
) override
{ added_browser_
= browser
; }
175 void OnBrowserRemoved(Browser
* browser
) override
{}
177 Browser
* added_browser_
;
180 // Test that when there is a popup as the active browser any requests to
181 // StartupBrowserCreatorImpl::OpenURLsInBrowser don't crash because there's no
182 // explicit profile given.
183 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
, OpenURLsPopup
) {
184 std::vector
<GURL
> urls
;
185 urls
.push_back(GURL("http://localhost"));
187 // Note that in our testing we do not ever query the BrowserList for the "last
188 // active" browser. That's because the browsers are set as "active" by
189 // platform UI toolkit messages, and those messages are not sent during unit
192 OpenURLsPopupObserver observer
;
193 BrowserList::AddObserver(&observer
);
195 Browser
* popup
= new Browser(
196 Browser::CreateParams(Browser::TYPE_POPUP
, browser()->profile(),
197 browser()->host_desktop_type()));
198 ASSERT_TRUE(popup
->is_type_popup());
199 ASSERT_EQ(popup
, observer
.added_browser_
);
201 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
202 chrome::startup::IsFirstRun first_run
= first_run::IsChromeFirstRun() ?
203 chrome::startup::IS_FIRST_RUN
: chrome::startup::IS_NOT_FIRST_RUN
;
204 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, first_run
);
205 // This should create a new window, but re-use the profile from |popup|. If
206 // it used a NULL or invalid profile, it would crash.
207 launch
.OpenURLsInBrowser(popup
, false, urls
, chrome::GetActiveDesktop());
208 ASSERT_NE(popup
, observer
.added_browser_
);
209 BrowserList::RemoveObserver(&observer
);
212 // We don't do non-process-startup browser launches on ChromeOS.
213 // Session restore for process-startup browser launches is tested
214 // in session_restore_uitest.
215 #if !defined(OS_CHROMEOS)
216 // Verify that startup URLs are honored when the process already exists but has
217 // no tabbed browser windows (eg. as if the process is running only due to a
218 // background application.
219 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
,
220 StartupURLsOnNewWindowWithNoTabbedBrowsers
) {
221 // Use a couple same-site HTTP URLs.
222 ASSERT_TRUE(test_server()->Start());
223 std::vector
<GURL
> urls
;
224 urls
.push_back(test_server()->GetURL("files/title1.html"));
225 urls
.push_back(test_server()->GetURL("files/title2.html"));
227 Profile
* profile
= browser()->profile();
228 chrome::HostDesktopType host_desktop_type
= browser()->host_desktop_type();
230 // Set the startup preference to open these URLs.
231 SessionStartupPref
pref(SessionStartupPref::URLS
);
233 SessionStartupPref::SetStartupPref(profile
, pref
);
235 // Keep the browser process running while browsers are closed.
236 g_browser_process
->AddRefModule();
238 // Close the browser.
239 CloseBrowserAsynchronously(browser());
241 // Do a simple non-process-startup browser launch.
242 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
243 chrome::startup::IsFirstRun first_run
= first_run::IsChromeFirstRun() ?
244 chrome::startup::IS_FIRST_RUN
: chrome::startup::IS_NOT_FIRST_RUN
;
246 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, first_run
);
248 launch
.Launch(profile
, std::vector
<GURL
>(), false, host_desktop_type
));
251 // This should have created a new browser window. |browser()| is still
252 // around at this point, even though we've closed its window.
253 Browser
* new_browser
= FindOneOtherBrowser(browser());
254 ASSERT_TRUE(new_browser
);
256 std::vector
<GURL
> expected_urls(urls
);
257 if (IsWindows10OrNewer())
258 expected_urls
.insert(expected_urls
.begin(), internals::GetWelcomePageURL());
260 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
261 ASSERT_EQ(static_cast<int>(expected_urls
.size()), tab_strip
->count());
262 for (size_t i
= 0; i
< expected_urls
.size(); i
++)
263 EXPECT_EQ(expected_urls
[i
], tab_strip
->GetWebContentsAt(i
)->GetURL());
265 // The two test_server tabs, despite having the same site, should be in
266 // different SiteInstances.
268 tab_strip
->GetWebContentsAt(tab_strip
->count() - 2)->GetSiteInstance(),
269 tab_strip
->GetWebContentsAt(tab_strip
->count() - 1)->GetSiteInstance());
271 // Test that the welcome page is not shown the second time through if it was
273 if (IsWindows10OrNewer()) {
274 // Close the browser opened above.
276 content::WindowedNotificationObserver
observer(
277 chrome::NOTIFICATION_BROWSER_CLOSED
,
278 content::Source
<Browser
>(new_browser
));
279 new_browser
->window()->Close();
284 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, first_run
);
285 ASSERT_TRUE(launch
.Launch(profile
, std::vector
<GURL
>(), false,
289 // Find the new browser and ensure that it has only the specified URLs this
290 // time. Both the original browser created by the fixture and the one
291 // created above have been closed, so the new browser is the only one
293 new_browser
= FindTabbedBrowser(profile
, true, host_desktop_type
);
294 ASSERT_TRUE(new_browser
);
295 ASSERT_EQ(static_cast<int>(urls
.size()),
296 new_browser
->tab_strip_model()->count());
299 g_browser_process
->ReleaseModule();
302 // Verify that startup URLs aren't used when the process already exists
303 // and has other tabbed browser windows. This is the common case of starting a
305 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
,
306 StartupURLsOnNewWindow
) {
307 // Use a couple arbitrary URLs.
308 std::vector
<GURL
> urls
;
309 urls
.push_back(ui_test_utils::GetTestUrl(
310 base::FilePath(base::FilePath::kCurrentDirectory
),
311 base::FilePath(FILE_PATH_LITERAL("title1.html"))));
312 urls
.push_back(ui_test_utils::GetTestUrl(
313 base::FilePath(base::FilePath::kCurrentDirectory
),
314 base::FilePath(FILE_PATH_LITERAL("title2.html"))));
316 // Set the startup preference to open these URLs.
317 SessionStartupPref
pref(SessionStartupPref::URLS
);
319 SessionStartupPref::SetStartupPref(browser()->profile(), pref
);
321 // Do a simple non-process-startup browser launch.
322 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
323 chrome::startup::IsFirstRun first_run
= first_run::IsChromeFirstRun() ?
324 chrome::startup::IS_FIRST_RUN
: chrome::startup::IS_NOT_FIRST_RUN
;
326 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, first_run
);
327 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), false,
328 browser()->host_desktop_type()));
331 // This should have created a new browser window.
332 Browser
* new_browser
= FindOneOtherBrowser(browser());
333 ASSERT_TRUE(new_browser
);
335 if (IsWindows10OrNewer()) {
336 // The new browser should have two tabs (not the startup URLs).
337 ASSERT_EQ(2, new_browser
->tab_strip_model()->count());
339 // The new browser should have exactly one tab (not the startup URLs).
340 ASSERT_EQ(1, new_browser
->tab_strip_model()->count());
343 // Test that the welcome page is not shown the second time through if it was
345 if (!IsWindows10OrNewer()) {
346 // Close the browser opened above.
348 content::WindowedNotificationObserver
observer(
349 chrome::NOTIFICATION_BROWSER_CLOSED
,
350 content::Source
<Browser
>(new_browser
));
351 new_browser
->window()->Close();
356 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, first_run
);
357 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(),
358 false, browser()->host_desktop_type()));
361 // Find the new browser and ensure that it has only the one tab this time.
362 new_browser
= FindOneOtherBrowser(browser());
363 ASSERT_TRUE(new_browser
);
364 ASSERT_EQ(1, new_browser
->tab_strip_model()->count());
368 // App shortcuts are not implemented on mac os.
369 #if !defined(OS_MACOSX)
370 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
, OpenAppShortcutNoPref
) {
371 // Load an app with launch.container = 'tab'.
372 const Extension
* extension_app
= NULL
;
373 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app
));
375 // Add --app-id=<extension->id()> to the command line.
376 base::CommandLine
command_line(base::CommandLine::NO_PROGRAM
);
377 command_line
.AppendSwitchASCII(switches::kAppId
, extension_app
->id());
379 chrome::startup::IsFirstRun first_run
= first_run::IsChromeFirstRun() ?
380 chrome::startup::IS_FIRST_RUN
: chrome::startup::IS_NOT_FIRST_RUN
;
381 StartupBrowserCreatorImpl
launch(base::FilePath(), command_line
, first_run
);
382 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), false,
383 browser()->host_desktop_type()));
385 // No pref was set, so the app should have opened in a tab in a new window.
386 // The launch should have created a new browser.
387 Browser
* new_browser
= FindOneOtherBrowser(browser());
388 ASSERT_TRUE(new_browser
);
390 // If new bookmark apps are enabled, it should be a standard tabbed window,
391 // not an app window; otherwise the reverse should be true.
392 bool new_bookmark_apps_enabled
= extensions::util::IsNewBookmarkAppsEnabled();
393 EXPECT_EQ(!new_bookmark_apps_enabled
, new_browser
->is_app());
394 EXPECT_EQ(new_bookmark_apps_enabled
, new_browser
->is_type_tabbed());
397 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
, OpenAppShortcutWindowPref
) {
398 const Extension
* extension_app
= NULL
;
399 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app
));
401 // Set a pref indicating that the user wants to open this app in a window.
402 SetAppLaunchPref(extension_app
->id(), extensions::LAUNCH_TYPE_WINDOW
);
404 base::CommandLine
command_line(base::CommandLine::NO_PROGRAM
);
405 command_line
.AppendSwitchASCII(switches::kAppId
, extension_app
->id());
406 chrome::startup::IsFirstRun first_run
= first_run::IsChromeFirstRun() ?
407 chrome::startup::IS_FIRST_RUN
: chrome::startup::IS_NOT_FIRST_RUN
;
408 StartupBrowserCreatorImpl
launch(base::FilePath(), command_line
, first_run
);
409 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), false,
410 browser()->host_desktop_type()));
412 // Pref was set to open in a window, so the app should have opened in a
413 // window. The launch should have created a new browser. Find the new
415 Browser
* new_browser
= FindOneOtherBrowser(browser());
416 ASSERT_TRUE(new_browser
);
418 // Expect an app window.
419 EXPECT_TRUE(new_browser
->is_app());
421 // The browser's app_name should include the app's ID.
423 new_browser
->app_name_
.find(extension_app
->id()),
424 std::string::npos
) << new_browser
->app_name_
;
427 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
, OpenAppShortcutTabPref
) {
428 // Load an app with launch.container = 'tab'.
429 const Extension
* extension_app
= NULL
;
430 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app
));
432 // Set a pref indicating that the user wants to open this app in a window.
433 SetAppLaunchPref(extension_app
->id(), extensions::LAUNCH_TYPE_REGULAR
);
435 base::CommandLine
command_line(base::CommandLine::NO_PROGRAM
);
436 command_line
.AppendSwitchASCII(switches::kAppId
, extension_app
->id());
437 chrome::startup::IsFirstRun first_run
= first_run::IsChromeFirstRun() ?
438 chrome::startup::IS_FIRST_RUN
: chrome::startup::IS_NOT_FIRST_RUN
;
439 StartupBrowserCreatorImpl
launch(base::FilePath(), command_line
, first_run
);
440 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), false,
441 browser()->host_desktop_type()));
443 // When an app shortcut is open and the pref indicates a tab should
444 // open, the tab is open in a new browser window. Expect a new window.
445 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(),
446 browser()->host_desktop_type()));
448 Browser
* new_browser
= FindOneOtherBrowser(browser());
449 ASSERT_TRUE(new_browser
);
451 // The tab should be in a tabbed window.
452 EXPECT_TRUE(new_browser
->is_type_tabbed());
454 // The browser's app_name should not include the app's ID: It is in a
457 new_browser
->app_name_
.find(extension_app
->id()),
458 std::string::npos
) << new_browser
->app_name_
;
461 #endif // !defined(OS_MACOSX)
463 #endif // !defined(OS_CHROMEOS)
465 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
,
466 ReadingWasRestartedAfterRestart
) {
467 // Tests that StartupBrowserCreator::WasRestarted reads and resets the
468 // preference kWasRestarted correctly.
469 StartupBrowserCreator::was_restarted_read_
= false;
470 PrefService
* pref_service
= g_browser_process
->local_state();
471 pref_service
->SetBoolean(prefs::kWasRestarted
, true);
472 EXPECT_TRUE(StartupBrowserCreator::WasRestarted());
473 EXPECT_FALSE(pref_service
->GetBoolean(prefs::kWasRestarted
));
474 EXPECT_TRUE(StartupBrowserCreator::WasRestarted());
477 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
,
478 ReadingWasRestartedAfterNormalStart
) {
479 // Tests that StartupBrowserCreator::WasRestarted reads and resets the
480 // preference kWasRestarted correctly.
481 StartupBrowserCreator::was_restarted_read_
= false;
482 PrefService
* pref_service
= g_browser_process
->local_state();
483 pref_service
->SetBoolean(prefs::kWasRestarted
, false);
484 EXPECT_FALSE(StartupBrowserCreator::WasRestarted());
485 EXPECT_FALSE(pref_service
->GetBoolean(prefs::kWasRestarted
));
486 EXPECT_FALSE(StartupBrowserCreator::WasRestarted());
489 // Fails on official builds. See http://crbug.com/313856
490 #if defined(GOOGLE_CHROME_BUILD)
491 #define MAYBE_AddFirstRunTab DISABLED_AddFirstRunTab
493 #define MAYBE_AddFirstRunTab AddFirstRunTab
495 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
, MAYBE_AddFirstRunTab
) {
496 StartupBrowserCreator browser_creator
;
497 browser_creator
.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
498 browser_creator
.AddFirstRunTab(test_server()->GetURL("files/title2.html"));
500 // Do a simple non-process-startup browser launch.
501 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
502 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, &browser_creator
,
503 chrome::startup::IS_FIRST_RUN
);
504 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), false,
505 browser()->host_desktop_type()));
507 // This should have created a new browser window.
508 Browser
* new_browser
= FindOneOtherBrowser(browser());
509 ASSERT_TRUE(new_browser
);
511 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
512 EXPECT_EQ(2, tab_strip
->count());
514 EXPECT_EQ("title1.html",
515 tab_strip
->GetWebContentsAt(0)->GetURL().ExtractFileName());
516 EXPECT_EQ("title2.html",
517 tab_strip
->GetWebContentsAt(1)->GetURL().ExtractFileName());
520 // Test hard-coded special first run tabs (defined in
521 // StartupBrowserCreatorImpl::AddStartupURLs()).
522 // Fails on official builds. See http://crbug.com/313856
523 #if defined(GOOGLE_CHROME_BUILD)
524 #define MAYBE_AddCustomFirstRunTab DISABLED_AddCustomFirstRunTab
526 #define MAYBE_AddCustomFirstRunTab AddCustomFirstRunTab
528 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
, MAYBE_AddCustomFirstRunTab
) {
529 StartupBrowserCreator browser_creator
;
530 browser_creator
.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
531 browser_creator
.AddFirstRunTab(GURL("http://new_tab_page"));
532 browser_creator
.AddFirstRunTab(test_server()->GetURL("files/title2.html"));
533 browser_creator
.AddFirstRunTab(GURL("http://welcome_page"));
535 // Do a simple non-process-startup browser launch.
536 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
537 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, &browser_creator
,
538 chrome::startup::IS_FIRST_RUN
);
539 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), false,
540 browser()->host_desktop_type()));
542 // This should have created a new browser window.
543 Browser
* new_browser
= FindOneOtherBrowser(browser());
544 ASSERT_TRUE(new_browser
);
546 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
547 EXPECT_EQ(4, tab_strip
->count());
549 EXPECT_EQ("title1.html",
550 tab_strip
->GetWebContentsAt(0)->GetURL().ExtractFileName());
551 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
552 tab_strip
->GetWebContentsAt(1)->GetURL());
553 EXPECT_EQ("title2.html",
554 tab_strip
->GetWebContentsAt(2)->GetURL().ExtractFileName());
555 EXPECT_EQ(internals::GetWelcomePageURL(),
556 tab_strip
->GetWebContentsAt(3)->GetURL());
559 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
, SyncPromoNoWelcomePage
) {
560 // Do a simple non-process-startup browser launch.
561 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
562 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
,
563 chrome::startup::IS_FIRST_RUN
);
564 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), false,
565 browser()->host_desktop_type()));
567 // This should have created a new browser window.
568 Browser
* new_browser
= FindOneOtherBrowser(browser());
569 ASSERT_TRUE(new_browser
);
571 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
573 if (signin::ShouldShowPromoAtStartup(browser()->profile(), true)) {
574 // The browser should show only the promo.
575 ASSERT_EQ(1, tab_strip
->count());
576 EXPECT_EQ(signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE
, false),
577 tab_strip
->GetWebContentsAt(0)->GetURL());
578 } else if (IsWindows10OrNewer()) {
579 // The browser should show the welcome page and the NTP.
580 ASSERT_EQ(2, tab_strip
->count());
581 EXPECT_EQ(GURL(internals::GetWelcomePageURL()),
582 tab_strip
->GetWebContentsAt(0)->GetURL());
583 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
584 tab_strip
->GetWebContentsAt(1)->GetURL());
586 // The browser should show only the NTP.
587 ASSERT_EQ(1, tab_strip
->count());
588 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
589 tab_strip
->GetWebContentsAt(0)->GetURL());
593 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
, SyncPromoWithWelcomePage
) {
594 first_run::SetShouldShowWelcomePage();
596 // Do a simple non-process-startup browser launch.
597 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
598 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
,
599 chrome::startup::IS_FIRST_RUN
);
600 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), false,
601 browser()->host_desktop_type()));
603 // This should have created a new browser window.
604 Browser
* new_browser
= FindOneOtherBrowser(browser());
605 ASSERT_TRUE(new_browser
);
607 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
608 EXPECT_EQ(2, tab_strip
->count());
610 if (IsWindows10OrNewer()) {
611 EXPECT_EQ(internals::GetWelcomePageURL(),
612 tab_strip
->GetWebContentsAt(0)->GetURL());
613 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
614 tab_strip
->GetWebContentsAt(1)->GetURL());
616 if (signin::ShouldShowPromoAtStartup(browser()->profile(), true)) {
617 EXPECT_EQ(signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE
, false),
618 tab_strip
->GetWebContentsAt(0)->GetURL());
620 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
621 tab_strip
->GetWebContentsAt(0)->GetURL());
623 EXPECT_EQ(internals::GetWelcomePageURL(),
624 tab_strip
->GetWebContentsAt(1)->GetURL());
628 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
, SyncPromoWithFirstRunTabs
) {
629 StartupBrowserCreator browser_creator
;
630 browser_creator
.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
632 // The welcome page should not be shown, even if
633 // first_run::ShouldShowWelcomePage() says so, when there are already
634 // more than 2 first run tabs.
635 first_run::SetShouldShowWelcomePage();
637 // Do a simple non-process-startup browser launch.
638 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
639 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, &browser_creator
,
640 chrome::startup::IS_FIRST_RUN
);
641 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), false,
642 browser()->host_desktop_type()));
644 // This should have created a new browser window.
645 Browser
* new_browser
= FindOneOtherBrowser(browser());
646 ASSERT_TRUE(new_browser
);
648 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
649 if (signin::ShouldShowPromoAtStartup(browser()->profile(), true)) {
650 EXPECT_EQ(2, tab_strip
->count());
651 EXPECT_EQ(signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE
, false),
652 tab_strip
->GetWebContentsAt(0)->GetURL());
653 EXPECT_EQ("title1.html",
654 tab_strip
->GetWebContentsAt(1)->GetURL().ExtractFileName());
656 EXPECT_EQ(1, tab_strip
->count());
657 EXPECT_EQ("title1.html",
658 tab_strip
->GetWebContentsAt(0)->GetURL().ExtractFileName());
662 // The welcome page should still be shown if there are more than 2 first run
663 // tabs, but the welcome page was explcitly added to the first run tabs.
664 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
,
665 SyncPromoWithFirstRunTabsIncludingWelcomePage
) {
666 StartupBrowserCreator browser_creator
;
667 browser_creator
.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
668 browser_creator
.AddFirstRunTab(GURL("http://welcome_page"));
670 // Do a simple non-process-startup browser launch.
671 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
672 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, &browser_creator
,
673 chrome::startup::IS_FIRST_RUN
);
674 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), false,
675 browser()->host_desktop_type()));
677 // This should have created a new browser window.
678 Browser
* new_browser
= FindOneOtherBrowser(browser());
679 ASSERT_TRUE(new_browser
);
681 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
682 if (signin::ShouldShowPromoAtStartup(browser()->profile(), true)) {
683 EXPECT_EQ(3, tab_strip
->count());
684 EXPECT_EQ(signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE
, false),
685 tab_strip
->GetWebContentsAt(0)->GetURL());
686 EXPECT_EQ("title1.html",
687 tab_strip
->GetWebContentsAt(1)->GetURL().ExtractFileName());
688 EXPECT_EQ(internals::GetWelcomePageURL(),
689 tab_strip
->GetWebContentsAt(2)->GetURL());
691 EXPECT_EQ(2, tab_strip
->count());
692 EXPECT_EQ("title1.html",
693 tab_strip
->GetWebContentsAt(0)->GetURL().ExtractFileName());
694 EXPECT_EQ(internals::GetWelcomePageURL(),
695 tab_strip
->GetWebContentsAt(1)->GetURL());
699 #if !defined(OS_CHROMEOS)
700 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
, StartupURLsForTwoProfiles
) {
701 #if defined(OS_WIN) && defined(USE_ASH)
702 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
703 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
704 switches::kAshBrowserTests
))
708 Profile
* default_profile
= browser()->profile();
710 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
711 // Create another profile.
712 base::FilePath dest_path
= profile_manager
->user_data_dir();
713 dest_path
= dest_path
.Append(FILE_PATH_LITERAL("New Profile 1"));
715 Profile
* other_profile
= profile_manager
->GetProfile(dest_path
);
716 ASSERT_TRUE(other_profile
);
718 // Use a couple arbitrary URLs.
719 std::vector
<GURL
> urls1
;
720 urls1
.push_back(ui_test_utils::GetTestUrl(
721 base::FilePath(base::FilePath::kCurrentDirectory
),
722 base::FilePath(FILE_PATH_LITERAL("title1.html"))));
723 std::vector
<GURL
> urls2
;
724 urls2
.push_back(ui_test_utils::GetTestUrl(
725 base::FilePath(base::FilePath::kCurrentDirectory
),
726 base::FilePath(FILE_PATH_LITERAL("title2.html"))));
728 // Set different startup preferences for the 2 profiles.
729 SessionStartupPref
pref1(SessionStartupPref::URLS
);
731 SessionStartupPref::SetStartupPref(default_profile
, pref1
);
732 SessionStartupPref
pref2(SessionStartupPref::URLS
);
734 SessionStartupPref::SetStartupPref(other_profile
, pref2
);
736 // Close the browser.
737 CloseBrowserAsynchronously(browser());
739 // Do a simple non-process-startup browser launch.
740 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
742 StartupBrowserCreator browser_creator
;
743 std::vector
<Profile
*> last_opened_profiles
;
744 last_opened_profiles
.push_back(default_profile
);
745 last_opened_profiles
.push_back(other_profile
);
746 browser_creator
.Start(dummy
, profile_manager
->user_data_dir(),
747 default_profile
, last_opened_profiles
);
749 // urls1 were opened in a browser for default_profile, and urls2 were opened
750 // in a browser for other_profile.
751 Browser
* new_browser
= NULL
;
752 // |browser()| is still around at this point, even though we've closed its
753 // window. Thus the browser count for default_profile is 2.
754 ASSERT_EQ(2u, chrome::GetBrowserCount(default_profile
,
755 browser()->host_desktop_type()));
756 new_browser
= FindOneOtherBrowserForProfile(default_profile
, browser());
757 ASSERT_TRUE(new_browser
);
758 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
759 if (IsWindows10OrNewer()) {
760 // The new browser should have the welcome tab and the URL for the profile.
761 ASSERT_EQ(2, tab_strip
->count());
762 EXPECT_EQ(GURL(internals::GetWelcomePageURL()),
763 tab_strip
->GetWebContentsAt(0)->GetURL());
764 EXPECT_EQ(urls1
[0], tab_strip
->GetWebContentsAt(1)->GetURL());
766 // The new browser should have only the desired URL for the profile.
767 ASSERT_EQ(1, tab_strip
->count());
768 EXPECT_EQ(urls1
[0], tab_strip
->GetWebContentsAt(0)->GetURL());
771 ASSERT_EQ(1u, chrome::GetBrowserCount(other_profile
,
772 browser()->host_desktop_type()));
773 new_browser
= FindOneOtherBrowserForProfile(other_profile
, NULL
);
774 ASSERT_TRUE(new_browser
);
775 tab_strip
= new_browser
->tab_strip_model();
776 ASSERT_EQ(1, tab_strip
->count());
777 EXPECT_EQ(urls2
[0], tab_strip
->GetWebContentsAt(0)->GetURL());
780 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
, PRE_UpdateWithTwoProfiles
) {
781 // Simulate a browser restart by creating the profiles in the PRE_ part.
782 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
784 ASSERT_TRUE(test_server()->Start());
786 // Create two profiles.
787 base::FilePath dest_path
= profile_manager
->user_data_dir();
789 Profile
* profile1
= profile_manager
->GetProfile(
790 dest_path
.Append(FILE_PATH_LITERAL("New Profile 1")));
791 ASSERT_TRUE(profile1
);
793 Profile
* profile2
= profile_manager
->GetProfile(
794 dest_path
.Append(FILE_PATH_LITERAL("New Profile 2")));
795 ASSERT_TRUE(profile2
);
797 // Open some urls with the browsers, and close them.
798 Browser
* browser1
= new Browser(
799 Browser::CreateParams(Browser::TYPE_TABBED
, profile1
,
800 browser()->host_desktop_type()));
801 chrome::NewTab(browser1
);
802 ui_test_utils::NavigateToURL(browser1
,
803 test_server()->GetURL("files/empty.html"));
804 CloseBrowserSynchronously(browser1
);
806 Browser
* browser2
= new Browser(
807 Browser::CreateParams(Browser::TYPE_TABBED
, profile2
,
808 browser()->host_desktop_type()));
809 chrome::NewTab(browser2
);
810 ui_test_utils::NavigateToURL(browser2
,
811 test_server()->GetURL("files/form.html"));
812 CloseBrowserSynchronously(browser2
);
814 // Set different startup preferences for the 2 profiles.
815 std::vector
<GURL
> urls1
;
816 urls1
.push_back(ui_test_utils::GetTestUrl(
817 base::FilePath(base::FilePath::kCurrentDirectory
),
818 base::FilePath(FILE_PATH_LITERAL("title1.html"))));
819 std::vector
<GURL
> urls2
;
820 urls2
.push_back(ui_test_utils::GetTestUrl(
821 base::FilePath(base::FilePath::kCurrentDirectory
),
822 base::FilePath(FILE_PATH_LITERAL("title2.html"))));
824 // Set different startup preferences for the 2 profiles.
825 SessionStartupPref
pref1(SessionStartupPref::URLS
);
827 SessionStartupPref::SetStartupPref(profile1
, pref1
);
828 SessionStartupPref
pref2(SessionStartupPref::URLS
);
830 SessionStartupPref::SetStartupPref(profile2
, pref2
);
832 profile1
->GetPrefs()->CommitPendingWrite();
833 profile2
->GetPrefs()->CommitPendingWrite();
836 // See crbug.com/376184 about improvements to this test on Mac.
837 // Disabled because it's flaky. http://crbug.com/379579
838 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
,
839 DISABLED_UpdateWithTwoProfiles
) {
840 #if defined(OS_WIN) && defined(USE_ASH)
841 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
842 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
843 switches::kAshBrowserTests
))
847 // Make StartupBrowserCreator::WasRestarted() return true.
848 StartupBrowserCreator::was_restarted_read_
= false;
849 PrefService
* pref_service
= g_browser_process
->local_state();
850 pref_service
->SetBoolean(prefs::kWasRestarted
, true);
852 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
854 // Open the two profiles.
855 base::FilePath dest_path
= profile_manager
->user_data_dir();
857 Profile
* profile1
= profile_manager
->GetProfile(
858 dest_path
.Append(FILE_PATH_LITERAL("New Profile 1")));
859 ASSERT_TRUE(profile1
);
861 Profile
* profile2
= profile_manager
->GetProfile(
862 dest_path
.Append(FILE_PATH_LITERAL("New Profile 2")));
863 ASSERT_TRUE(profile2
);
865 // Simulate a launch after a browser update.
866 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
867 StartupBrowserCreator browser_creator
;
868 std::vector
<Profile
*> last_opened_profiles
;
869 last_opened_profiles
.push_back(profile1
);
870 last_opened_profiles
.push_back(profile2
);
871 browser_creator
.Start(dummy
, profile_manager
->user_data_dir(), profile1
,
872 last_opened_profiles
);
874 while (SessionRestore::IsRestoring(profile1
) ||
875 SessionRestore::IsRestoring(profile2
))
876 base::MessageLoop::current()->RunUntilIdle();
878 // The startup URLs are ignored, and instead the last open sessions are
880 EXPECT_TRUE(profile1
->restored_last_session());
881 EXPECT_TRUE(profile2
->restored_last_session());
883 Browser
* new_browser
= NULL
;
884 ASSERT_EQ(1u, chrome::GetBrowserCount(profile1
,
885 browser()->host_desktop_type()));
886 new_browser
= FindOneOtherBrowserForProfile(profile1
, NULL
);
887 ASSERT_TRUE(new_browser
);
888 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
889 ASSERT_EQ(1, tab_strip
->count());
890 EXPECT_EQ("/files/empty.html",
891 tab_strip
->GetWebContentsAt(0)->GetURL().path());
893 ASSERT_EQ(1u, chrome::GetBrowserCount(profile2
,
894 browser()->host_desktop_type()));
895 new_browser
= FindOneOtherBrowserForProfile(profile2
, NULL
);
896 ASSERT_TRUE(new_browser
);
897 tab_strip
= new_browser
->tab_strip_model();
898 ASSERT_EQ(1, tab_strip
->count());
899 EXPECT_EQ("/files/form.html",
900 tab_strip
->GetWebContentsAt(0)->GetURL().path());
903 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
,
904 ProfilesWithoutPagesNotLaunched
) {
905 #if defined(OS_WIN) && defined(USE_ASH)
906 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
907 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
908 switches::kAshBrowserTests
))
912 Profile
* default_profile
= browser()->profile();
914 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
916 // Create 4 more profiles.
917 base::FilePath dest_path1
= profile_manager
->user_data_dir().Append(
918 FILE_PATH_LITERAL("New Profile 1"));
919 base::FilePath dest_path2
= profile_manager
->user_data_dir().Append(
920 FILE_PATH_LITERAL("New Profile 2"));
921 base::FilePath dest_path3
= profile_manager
->user_data_dir().Append(
922 FILE_PATH_LITERAL("New Profile 3"));
923 base::FilePath dest_path4
= profile_manager
->user_data_dir().Append(
924 FILE_PATH_LITERAL("New Profile 4"));
926 Profile
* profile_home1
= profile_manager
->GetProfile(dest_path1
);
927 ASSERT_TRUE(profile_home1
);
928 Profile
* profile_home2
= profile_manager
->GetProfile(dest_path2
);
929 ASSERT_TRUE(profile_home2
);
930 Profile
* profile_last
= profile_manager
->GetProfile(dest_path3
);
931 ASSERT_TRUE(profile_last
);
932 Profile
* profile_urls
= profile_manager
->GetProfile(dest_path4
);
933 ASSERT_TRUE(profile_urls
);
935 // Set the profiles to open urls, open last visited pages or display the home
937 SessionStartupPref
pref_home(SessionStartupPref::DEFAULT
);
938 SessionStartupPref::SetStartupPref(profile_home1
, pref_home
);
939 SessionStartupPref::SetStartupPref(profile_home2
, pref_home
);
941 SessionStartupPref
pref_last(SessionStartupPref::LAST
);
942 SessionStartupPref::SetStartupPref(profile_last
, pref_last
);
944 std::vector
<GURL
> urls
;
945 urls
.push_back(ui_test_utils::GetTestUrl(
946 base::FilePath(base::FilePath::kCurrentDirectory
),
947 base::FilePath(FILE_PATH_LITERAL("title1.html"))));
949 SessionStartupPref
pref_urls(SessionStartupPref::URLS
);
950 pref_urls
.urls
= urls
;
951 SessionStartupPref::SetStartupPref(profile_urls
, pref_urls
);
953 // Open a page with profile_last.
954 Browser
* browser_last
= new Browser(
955 Browser::CreateParams(Browser::TYPE_TABBED
, profile_last
,
956 browser()->host_desktop_type()));
957 chrome::NewTab(browser_last
);
958 ui_test_utils::NavigateToURL(browser_last
,
959 test_server()->GetURL("files/empty.html"));
960 CloseBrowserAsynchronously(browser_last
);
962 // Close the main browser.
963 chrome::HostDesktopType original_desktop_type
=
964 browser()->host_desktop_type();
965 CloseBrowserAsynchronously(browser());
967 // Do a simple non-process-startup browser launch.
968 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
970 StartupBrowserCreator browser_creator
;
971 std::vector
<Profile
*> last_opened_profiles
;
972 last_opened_profiles
.push_back(profile_home1
);
973 last_opened_profiles
.push_back(profile_home2
);
974 last_opened_profiles
.push_back(profile_last
);
975 last_opened_profiles
.push_back(profile_urls
);
976 browser_creator
.Start(dummy
, profile_manager
->user_data_dir(), profile_home1
,
977 last_opened_profiles
);
979 while (SessionRestore::IsRestoring(default_profile
) ||
980 SessionRestore::IsRestoring(profile_home1
) ||
981 SessionRestore::IsRestoring(profile_home2
) ||
982 SessionRestore::IsRestoring(profile_last
) ||
983 SessionRestore::IsRestoring(profile_urls
))
984 base::MessageLoop::current()->RunUntilIdle();
986 Browser
* new_browser
= NULL
;
987 // The last open profile (the profile_home1 in this case) will always be
988 // launched, even if it will open just the NTP (and the welcome page on
989 // relevant platforms).
990 ASSERT_EQ(1u, chrome::GetBrowserCount(profile_home1
, original_desktop_type
));
991 new_browser
= FindOneOtherBrowserForProfile(profile_home1
, NULL
);
992 ASSERT_TRUE(new_browser
);
993 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
994 if (IsWindows10OrNewer()) {
995 // The new browser should have the welcome tab and the NTP.
996 ASSERT_EQ(2, tab_strip
->count());
997 EXPECT_EQ(GURL(internals::GetWelcomePageURL()),
998 tab_strip
->GetWebContentsAt(0)->GetURL());
999 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
1000 tab_strip
->GetWebContentsAt(1)->GetURL());
1002 // The new browser should have only the NTP.
1003 ASSERT_EQ(1, tab_strip
->count());
1004 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
1005 tab_strip
->GetWebContentsAt(0)->GetURL());
1008 // profile_urls opened the urls.
1009 ASSERT_EQ(1u, chrome::GetBrowserCount(profile_urls
, original_desktop_type
));
1010 new_browser
= FindOneOtherBrowserForProfile(profile_urls
, NULL
);
1011 ASSERT_TRUE(new_browser
);
1012 tab_strip
= new_browser
->tab_strip_model();
1013 ASSERT_EQ(1, tab_strip
->count());
1014 EXPECT_EQ(urls
[0], tab_strip
->GetWebContentsAt(0)->GetURL());
1016 // profile_last opened the last open pages.
1017 ASSERT_EQ(1u, chrome::GetBrowserCount(profile_last
, original_desktop_type
));
1018 new_browser
= FindOneOtherBrowserForProfile(profile_last
, NULL
);
1019 ASSERT_TRUE(new_browser
);
1020 tab_strip
= new_browser
->tab_strip_model();
1021 ASSERT_EQ(1, tab_strip
->count());
1022 EXPECT_EQ("/files/empty.html",
1023 tab_strip
->GetWebContentsAt(0)->GetURL().path());
1025 // profile_home2 was not launched since it would've only opened the home page.
1026 ASSERT_EQ(0u, chrome::GetBrowserCount(profile_home2
, original_desktop_type
));
1029 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest
, ProfilesLaunchedAfterCrash
) {
1030 #if defined(OS_WIN) && defined(USE_ASH)
1031 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
1032 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1033 switches::kAshBrowserTests
))
1037 // After an unclean exit, all profiles will be launched. However, they won't
1038 // open any pages automatically.
1040 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1042 // Create 3 profiles.
1043 base::FilePath dest_path1
= profile_manager
->user_data_dir().Append(
1044 FILE_PATH_LITERAL("New Profile 1"));
1045 base::FilePath dest_path2
= profile_manager
->user_data_dir().Append(
1046 FILE_PATH_LITERAL("New Profile 2"));
1047 base::FilePath dest_path3
= profile_manager
->user_data_dir().Append(
1048 FILE_PATH_LITERAL("New Profile 3"));
1050 Profile
* profile_home
= profile_manager
->GetProfile(dest_path1
);
1051 ASSERT_TRUE(profile_home
);
1052 Profile
* profile_last
= profile_manager
->GetProfile(dest_path2
);
1053 ASSERT_TRUE(profile_last
);
1054 Profile
* profile_urls
= profile_manager
->GetProfile(dest_path3
);
1055 ASSERT_TRUE(profile_urls
);
1057 // Set the profiles to open the home page, last visited pages or URLs.
1058 SessionStartupPref
pref_home(SessionStartupPref::DEFAULT
);
1059 SessionStartupPref::SetStartupPref(profile_home
, pref_home
);
1061 SessionStartupPref
pref_last(SessionStartupPref::LAST
);
1062 SessionStartupPref::SetStartupPref(profile_last
, pref_last
);
1064 std::vector
<GURL
> urls
;
1065 urls
.push_back(ui_test_utils::GetTestUrl(
1066 base::FilePath(base::FilePath::kCurrentDirectory
),
1067 base::FilePath(FILE_PATH_LITERAL("title1.html"))));
1069 SessionStartupPref
pref_urls(SessionStartupPref::URLS
);
1070 pref_urls
.urls
= urls
;
1071 SessionStartupPref::SetStartupPref(profile_urls
, pref_urls
);
1073 // Simulate a launch after an unclear exit.
1074 CloseBrowserAsynchronously(browser());
1075 static_cast<ProfileImpl
*>(profile_home
)->last_session_exit_type_
=
1076 Profile::EXIT_CRASHED
;
1077 static_cast<ProfileImpl
*>(profile_last
)->last_session_exit_type_
=
1078 Profile::EXIT_CRASHED
;
1079 static_cast<ProfileImpl
*>(profile_urls
)->last_session_exit_type_
=
1080 Profile::EXIT_CRASHED
;
1082 #if !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD)
1083 // Use HistogramTester to make sure a bubble is shown when it's not on
1084 // platform Mac OS X and it's not official Chrome build.
1086 // On Mac OS X, an infobar is shown to restore the previous session, which
1087 // is tested by function EnsureRestoreUIWasShown.
1089 // Under a Google Chrome build, it is not tested because a task is posted to
1090 // the file thread before the bubble is shown. It is difficult to make sure
1091 // that the histogram check runs after all threads have finished their tasks.
1092 base::HistogramTester histogram_tester
;
1093 #endif // !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD)
1095 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
1096 dummy
.AppendSwitchASCII(switches::kTestType
, "browser");
1097 StartupBrowserCreator browser_creator
;
1098 std::vector
<Profile
*> last_opened_profiles
;
1099 last_opened_profiles
.push_back(profile_home
);
1100 last_opened_profiles
.push_back(profile_last
);
1101 last_opened_profiles
.push_back(profile_urls
);
1102 browser_creator
.Start(dummy
, profile_manager
->user_data_dir(), profile_home
,
1103 last_opened_profiles
);
1105 // No profiles are getting restored, since they all display the crash info
1107 EXPECT_FALSE(SessionRestore::IsRestoring(profile_home
));
1108 EXPECT_FALSE(SessionRestore::IsRestoring(profile_last
));
1109 EXPECT_FALSE(SessionRestore::IsRestoring(profile_urls
));
1111 // The profile which normally opens the home page displays the new tab page.
1112 // The welcome page is also shown for relevant platforms.
1113 Browser
* new_browser
= NULL
;
1114 ASSERT_EQ(1u, chrome::GetBrowserCount(profile_home
,
1115 browser()->host_desktop_type()));
1116 new_browser
= FindOneOtherBrowserForProfile(profile_home
, NULL
);
1117 ASSERT_TRUE(new_browser
);
1118 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
1119 if (IsWindows10OrNewer()) {
1120 // The new browser should have the welcome tab and the NTP.
1121 ASSERT_EQ(2, tab_strip
->count());
1122 EXPECT_EQ(GURL(internals::GetWelcomePageURL()),
1123 tab_strip
->GetWebContentsAt(0)->GetURL());
1124 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
1125 tab_strip
->GetWebContentsAt(1)->GetURL());
1127 // The new browser should have only the NTP.
1128 ASSERT_EQ(1, tab_strip
->count());
1129 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
1130 tab_strip
->GetWebContentsAt(0)->GetURL());
1132 EnsureRestoreUIWasShown(tab_strip
->GetWebContentsAt(0));
1134 // The profile which normally opens last open pages displays the new tab page.
1135 ASSERT_EQ(1u, chrome::GetBrowserCount(profile_last
,
1136 browser()->host_desktop_type()));
1137 new_browser
= FindOneOtherBrowserForProfile(profile_last
, NULL
);
1138 ASSERT_TRUE(new_browser
);
1139 tab_strip
= new_browser
->tab_strip_model();
1140 ASSERT_EQ(1, tab_strip
->count());
1141 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
1142 tab_strip
->GetWebContentsAt(0)->GetURL());
1143 EnsureRestoreUIWasShown(tab_strip
->GetWebContentsAt(0));
1145 // The profile which normally opens URLs displays the new tab page.
1146 ASSERT_EQ(1u, chrome::GetBrowserCount(profile_urls
,
1147 browser()->host_desktop_type()));
1148 new_browser
= FindOneOtherBrowserForProfile(profile_urls
, NULL
);
1149 ASSERT_TRUE(new_browser
);
1150 tab_strip
= new_browser
->tab_strip_model();
1151 ASSERT_EQ(1, tab_strip
->count());
1152 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
1153 tab_strip
->GetWebContentsAt(0)->GetURL());
1154 EnsureRestoreUIWasShown(tab_strip
->GetWebContentsAt(0));
1156 #if !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD)
1157 // Each profile should have one session restore bubble shown, so we should
1158 // observe count 3 in bucket 0 (which represents bubble shown).
1159 histogram_tester
.ExpectBucketCount("SessionCrashed.Bubble", 0, 3);
1160 #endif // !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD)
1163 class SupervisedUserBrowserCreatorTest
: public InProcessBrowserTest
{
1165 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
1166 InProcessBrowserTest::SetUpCommandLine(command_line
);
1167 command_line
->AppendSwitchASCII(switches::kSupervisedUserId
, "asdf");
1171 IN_PROC_BROWSER_TEST_F(SupervisedUserBrowserCreatorTest
,
1172 StartupSupervisedUserProfile
) {
1173 StartupBrowserCreator browser_creator
;
1175 // Do a simple non-process-startup browser launch.
1176 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
1177 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, &browser_creator
,
1178 chrome::startup::IS_FIRST_RUN
);
1179 content::WindowedNotificationObserver
observer(
1180 content::NOTIFICATION_LOAD_STOP
,
1181 content::NotificationService::AllSources());
1182 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), false,
1183 browser()->host_desktop_type()));
1185 // This should have created a new browser window.
1186 Browser
* new_browser
= FindOneOtherBrowser(browser());
1187 ASSERT_TRUE(new_browser
);
1189 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
1190 // There should be only one tab, except on Windows 10. See crbug.com/505029.
1191 const int tab_count
= IsWindows10OrNewer() ? 2 : 1;
1192 EXPECT_EQ(tab_count
, tab_strip
->count());
1195 #endif // !defined(OS_CHROMEOS)
1197 // These tests are not applicable to Chrome OS as neither master_preferences nor
1198 // the sync promo exist there.
1199 #if !defined(OS_CHROMEOS)
1201 // On a branded Linux build, policy is required to suppress the first-run
1203 #if !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) || \
1204 defined(ENABLE_CONFIGURATION_POLICY)
1206 class StartupBrowserCreatorFirstRunTest
: public InProcessBrowserTest
{
1208 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
1209 void SetUpInProcessBrowserTestFixture() override
;
1211 // Returns true if the platform supports showing the sync promo on first run.
1212 static bool PlatformSupportsSyncPromo() {
1213 return !IsWindows10OrNewer();
1216 #if defined(ENABLE_CONFIGURATION_POLICY)
1217 policy::MockConfigurationPolicyProvider provider_
;
1218 policy::PolicyMap policy_map_
;
1219 #endif // defined(ENABLE_CONFIGURATION_POLICY)
1222 void StartupBrowserCreatorFirstRunTest::SetUpCommandLine(
1223 base::CommandLine
* command_line
) {
1224 command_line
->AppendSwitch(switches::kForceFirstRun
);
1227 void StartupBrowserCreatorFirstRunTest::SetUpInProcessBrowserTestFixture() {
1228 #if defined(ENABLE_CONFIGURATION_POLICY)
1229 #if defined(OS_LINUX) && defined(GOOGLE_CHROME_BUILD)
1230 // Set a policy that prevents the first-run dialog from being shown.
1231 policy_map_
.Set(policy::key::kMetricsReportingEnabled
,
1232 policy::POLICY_LEVEL_MANDATORY
,
1233 policy::POLICY_SCOPE_USER
,
1234 new base::FundamentalValue(false),
1236 provider_
.UpdateChromePolicy(policy_map_
);
1237 #endif // defined(OS_LINUX) && defined(GOOGLE_CHROME_BUILD)
1239 EXPECT_CALL(provider_
, IsInitializationComplete(_
))
1240 .WillRepeatedly(Return(true));
1241 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_
);
1242 #endif // defined(ENABLE_CONFIGURATION_POLICY)
1245 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_MACOSX)
1246 // http://crbug.com/314819
1247 #define MAYBE_SyncPromoForbidden DISABLED_SyncPromoForbidden
1249 #define MAYBE_SyncPromoForbidden SyncPromoForbidden
1251 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest
,
1252 MAYBE_SyncPromoForbidden
) {
1253 // Consistently enable the welcome page on all platforms.
1254 first_run::SetShouldShowWelcomePage();
1256 // Simulate the following master_preferences:
1259 // "show_on_first_run_allowed": false
1262 StartupBrowserCreator browser_creator
;
1263 browser()->profile()->GetPrefs()->SetBoolean(
1264 prefs::kSignInPromoShowOnFirstRunAllowed
, false);
1266 // Do a process-startup browser launch.
1267 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
1268 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, &browser_creator
,
1269 chrome::startup::IS_FIRST_RUN
);
1270 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), true,
1271 browser()->host_desktop_type()));
1273 // This should have created a new browser window.
1274 Browser
* new_browser
= FindOneOtherBrowser(browser());
1275 ASSERT_TRUE(new_browser
);
1277 // Verify that the NTP and the welcome page are shown.
1278 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
1279 ASSERT_EQ(2, tab_strip
->count());
1280 if (IsWindows10OrNewer()) {
1281 EXPECT_EQ(internals::GetWelcomePageURL(),
1282 tab_strip
->GetWebContentsAt(0)->GetURL());
1283 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
1284 tab_strip
->GetWebContentsAt(1)->GetURL());
1286 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
1287 tab_strip
->GetWebContentsAt(0)->GetURL());
1288 EXPECT_EQ(internals::GetWelcomePageURL(),
1289 tab_strip
->GetWebContentsAt(1)->GetURL());
1293 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_MACOSX)
1294 // http://crbug.com/314819
1295 #define MAYBE_SyncPromoAllowed DISABLED_SyncPromoAllowed
1297 #define MAYBE_SyncPromoAllowed SyncPromoAllowed
1299 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest
,
1300 MAYBE_SyncPromoAllowed
) {
1301 if (!PlatformSupportsSyncPromo())
1303 // Consistently enable the welcome page on all platforms.
1304 first_run::SetShouldShowWelcomePage();
1306 // Simulate the following master_preferences:
1309 // "show_on_first_run_allowed": true
1312 StartupBrowserCreator browser_creator
;
1313 browser()->profile()->GetPrefs()->SetBoolean(
1314 prefs::kSignInPromoShowOnFirstRunAllowed
, true);
1316 // Do a process-startup browser launch.
1317 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
1318 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, &browser_creator
,
1319 chrome::startup::IS_FIRST_RUN
);
1320 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), true,
1321 browser()->host_desktop_type()));
1323 // This should have created a new browser window.
1324 Browser
* new_browser
= FindOneOtherBrowser(browser());
1325 ASSERT_TRUE(new_browser
);
1327 // Verify that the sync promo and the welcome page are shown.
1328 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
1329 ASSERT_EQ(2, tab_strip
->count());
1330 EXPECT_EQ(signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE
, false),
1331 tab_strip
->GetWebContentsAt(0)->GetURL());
1332 EXPECT_EQ(internals::GetWelcomePageURL(),
1333 tab_strip
->GetWebContentsAt(1)->GetURL());
1336 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_MACOSX)
1337 // http://crbug.com/314819
1338 #define MAYBE_FirstRunTabsPromoAllowed DISABLED_FirstRunTabsPromoAllowed
1340 #define MAYBE_FirstRunTabsPromoAllowed FirstRunTabsPromoAllowed
1342 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest
,
1343 MAYBE_FirstRunTabsPromoAllowed
) {
1344 if (!PlatformSupportsSyncPromo())
1346 // Simulate the following master_preferences:
1348 // "first_run_tabs" : [
1349 // "files/title1.html"
1352 // "show_on_first_run_allowed": true
1355 StartupBrowserCreator browser_creator
;
1356 browser_creator
.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
1357 browser()->profile()->GetPrefs()->SetBoolean(
1358 prefs::kSignInPromoShowOnFirstRunAllowed
, true);
1360 // Do a process-startup browser launch.
1361 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
1362 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, &browser_creator
,
1363 chrome::startup::IS_FIRST_RUN
);
1364 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), true,
1365 browser()->host_desktop_type()));
1367 // This should have created a new browser window.
1368 Browser
* new_browser
= FindOneOtherBrowser(browser());
1369 ASSERT_TRUE(new_browser
);
1371 // Verify that the first-run tab is shown and the sync promo has been added.
1372 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
1373 ASSERT_EQ(2, tab_strip
->count());
1374 EXPECT_EQ(signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE
, false),
1375 tab_strip
->GetWebContentsAt(0)->GetURL());
1376 EXPECT_EQ("title1.html",
1377 tab_strip
->GetWebContentsAt(1)->GetURL().ExtractFileName());
1380 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_MACOSX)
1381 // http://crbug.com/314819
1382 #define MAYBE_FirstRunTabsContainSyncPromo \
1383 DISABLED_FirstRunTabsContainSyncPromo
1385 #define MAYBE_FirstRunTabsContainSyncPromo FirstRunTabsContainSyncPromo
1387 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest
,
1388 MAYBE_FirstRunTabsContainSyncPromo
) {
1389 if (!PlatformSupportsSyncPromo())
1391 // Simulate the following master_preferences:
1393 // "first_run_tabs" : [
1394 // "files/title1.html",
1395 // "chrome://signin/?source=0&next_page=chrome%3A%2F%2Fnewtab%2F"
1398 // "show_on_first_run_allowed": true
1401 ASSERT_TRUE(test_server()->Start());
1402 StartupBrowserCreator browser_creator
;
1403 browser_creator
.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
1404 browser_creator
.AddFirstRunTab(
1405 signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE
, false));
1406 browser()->profile()->GetPrefs()->SetBoolean(
1407 prefs::kSignInPromoShowOnFirstRunAllowed
, true);
1409 // Do a process-startup browser launch.
1410 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
1411 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, &browser_creator
,
1412 chrome::startup::IS_FIRST_RUN
);
1413 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), true,
1414 browser()->host_desktop_type()));
1416 // This should have created a new browser window.
1417 Browser
* new_browser
= FindOneOtherBrowser(browser());
1418 ASSERT_TRUE(new_browser
);
1420 // Verify that the first-run tabs are shown and no sync promo has been added
1421 // as the first-run tabs contain it already.
1422 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
1423 ASSERT_EQ(2, tab_strip
->count());
1424 EXPECT_EQ("title1.html",
1425 tab_strip
->GetWebContentsAt(0)->GetURL().ExtractFileName());
1426 EXPECT_EQ(signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE
, false),
1427 tab_strip
->GetWebContentsAt(1)->GetURL());
1430 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_MACOSX)
1431 // http://crbug.com/314819
1432 #define MAYBE_FirstRunTabsContainNTPSyncPromoAllowed \
1433 DISABLED_FirstRunTabsContainNTPSyncPromoAllowed
1435 #define MAYBE_FirstRunTabsContainNTPSyncPromoAllowed \
1436 FirstRunTabsContainNTPSyncPromoAllowed
1438 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest
,
1439 MAYBE_FirstRunTabsContainNTPSyncPromoAllowed
) {
1440 if (!PlatformSupportsSyncPromo())
1442 // Simulate the following master_preferences:
1444 // "first_run_tabs" : [
1446 // "files/title1.html"
1449 // "show_on_first_run_allowed": true
1452 StartupBrowserCreator browser_creator
;
1453 browser_creator
.AddFirstRunTab(GURL("http://new_tab_page"));
1454 browser_creator
.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
1455 browser()->profile()->GetPrefs()->SetBoolean(
1456 prefs::kSignInPromoShowOnFirstRunAllowed
, true);
1458 // Do a process-startup browser launch.
1459 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
1460 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, &browser_creator
,
1461 chrome::startup::IS_FIRST_RUN
);
1462 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), true,
1463 browser()->host_desktop_type()));
1465 // This should have created a new browser window.
1466 Browser
* new_browser
= FindOneOtherBrowser(browser());
1467 ASSERT_TRUE(new_browser
);
1469 // Verify that the first-run tabs are shown but the NTP that they contain has
1470 // been replaced by the sync promo.
1471 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
1472 ASSERT_EQ(2, tab_strip
->count());
1473 EXPECT_EQ(signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE
, false),
1474 tab_strip
->GetWebContentsAt(0)->GetURL());
1475 EXPECT_EQ("title1.html",
1476 tab_strip
->GetWebContentsAt(1)->GetURL().ExtractFileName());
1479 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_MACOSX)
1480 // http://crbug.com/314819
1481 #define MAYBE_FirstRunTabsContainNTPSyncPromoForbidden \
1482 DISABLED_FirstRunTabsContainNTPSyncPromoForbidden
1484 #define MAYBE_FirstRunTabsContainNTPSyncPromoForbidden \
1485 FirstRunTabsContainNTPSyncPromoForbidden
1487 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest
,
1488 MAYBE_FirstRunTabsContainNTPSyncPromoForbidden
) {
1489 if (!PlatformSupportsSyncPromo())
1491 // Simulate the following master_preferences:
1493 // "first_run_tabs" : [
1495 // "files/title1.html"
1498 // "show_on_first_run_allowed": false
1501 StartupBrowserCreator browser_creator
;
1502 browser_creator
.AddFirstRunTab(GURL("http://new_tab_page"));
1503 browser_creator
.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
1504 browser()->profile()->GetPrefs()->SetBoolean(
1505 prefs::kSignInPromoShowOnFirstRunAllowed
, false);
1507 // Do a process-startup browser launch.
1508 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
1509 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, &browser_creator
,
1510 chrome::startup::IS_FIRST_RUN
);
1511 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), true,
1512 browser()->host_desktop_type()));
1514 // This should have created a new browser window.
1515 Browser
* new_browser
= FindOneOtherBrowser(browser());
1516 ASSERT_TRUE(new_browser
);
1518 // Verify that the first-run tabs are shown, the NTP that they contain has not
1519 // not been replaced by the sync promo and no sync promo has been added.
1520 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
1521 ASSERT_EQ(2, tab_strip
->count());
1522 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
1523 tab_strip
->GetWebContentsAt(0)->GetURL());
1524 EXPECT_EQ("title1.html",
1525 tab_strip
->GetWebContentsAt(1)->GetURL().ExtractFileName());
1528 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_MACOSX)
1529 // http://crbug.com/314819
1530 #define MAYBE_FirstRunTabsSyncPromoForbidden \
1531 DISABLED_FirstRunTabsSyncPromoForbidden
1533 #define MAYBE_FirstRunTabsSyncPromoForbidden FirstRunTabsSyncPromoForbidden
1535 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest
,
1536 MAYBE_FirstRunTabsSyncPromoForbidden
) {
1537 if (!PlatformSupportsSyncPromo())
1539 // Simulate the following master_preferences:
1541 // "first_run_tabs" : [
1542 // "files/title1.html"
1545 // "show_on_first_run_allowed": false
1548 StartupBrowserCreator browser_creator
;
1549 browser_creator
.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
1550 browser()->profile()->GetPrefs()->SetBoolean(
1551 prefs::kSignInPromoShowOnFirstRunAllowed
, false);
1553 // Do a process-startup browser launch.
1554 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
1555 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, &browser_creator
,
1556 chrome::startup::IS_FIRST_RUN
);
1557 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), true,
1558 browser()->host_desktop_type()));
1560 // This should have created a new browser window.
1561 Browser
* new_browser
= FindOneOtherBrowser(browser());
1562 ASSERT_TRUE(new_browser
);
1564 // Verify that the first-run tab is shown and no sync promo has been added.
1565 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
1566 ASSERT_EQ(1, tab_strip
->count());
1567 EXPECT_EQ("title1.html",
1568 tab_strip
->GetWebContentsAt(0)->GetURL().ExtractFileName());
1571 #if defined(ENABLE_CONFIGURATION_POLICY)
1572 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_MACOSX)
1573 // http://crbug.com/314819
1574 #define MAYBE_RestoreOnStartupURLsPolicySpecified \
1575 DISABLED_RestoreOnStartupURLsPolicySpecified
1577 #define MAYBE_RestoreOnStartupURLsPolicySpecified \
1578 RestoreOnStartupURLsPolicySpecified
1580 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest
,
1581 MAYBE_RestoreOnStartupURLsPolicySpecified
) {
1582 if (!PlatformSupportsSyncPromo())
1584 // Simulate the following master_preferences:
1587 // "show_on_first_run_allowed": true
1590 StartupBrowserCreator browser_creator
;
1591 browser()->profile()->GetPrefs()->SetBoolean(
1592 prefs::kSignInPromoShowOnFirstRunAllowed
, true);
1594 // Set the following user policies:
1595 // * RestoreOnStartup = RestoreOnStartupIsURLs
1596 // * RestoreOnStartupURLs = [ "files/title1.html" ]
1598 policy::key::kRestoreOnStartup
,
1599 policy::POLICY_LEVEL_MANDATORY
,
1600 policy::POLICY_SCOPE_USER
,
1601 new base::FundamentalValue(SessionStartupPref::kPrefValueURLs
),
1603 base::ListValue startup_urls
;
1604 startup_urls
.Append(
1605 new base::StringValue(test_server()->GetURL("files/title1.html").spec()));
1606 policy_map_
.Set(policy::key::kRestoreOnStartupURLs
,
1607 policy::POLICY_LEVEL_MANDATORY
, policy::POLICY_SCOPE_USER
,
1608 startup_urls
.DeepCopy(), NULL
);
1609 provider_
.UpdateChromePolicy(policy_map_
);
1610 base::RunLoop().RunUntilIdle();
1612 // Do a process-startup browser launch.
1613 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
1614 StartupBrowserCreatorImpl
launch(base::FilePath(), dummy
, &browser_creator
,
1615 chrome::startup::IS_FIRST_RUN
);
1616 ASSERT_TRUE(launch
.Launch(browser()->profile(), std::vector
<GURL
>(), true,
1617 browser()->host_desktop_type()));
1619 // This should have created a new browser window.
1620 Browser
* new_browser
= FindOneOtherBrowser(browser());
1621 ASSERT_TRUE(new_browser
);
1623 // Verify that the URL specified through policy is shown and no sync promo has
1625 TabStripModel
* tab_strip
= new_browser
->tab_strip_model();
1626 ASSERT_EQ(1, tab_strip
->count());
1627 EXPECT_EQ("title1.html",
1628 tab_strip
->GetWebContentsAt(0)->GetURL().ExtractFileName());
1630 #endif // defined(ENABLE_CONFIGURATION_POLICY)
1632 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) ||
1633 // defined(ENABLE_CONFIGURATION_POLICY)
1635 #endif // !defined(OS_CHROMEOS)