15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
57d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include <algorithm>
67d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include <string>
77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h"
117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/browser_process.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/extensions/extension_browsertest.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/extensions/extension_service.h"
15a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/extensions/launch_util.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/first_run/first_run.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/infobars/infobar_service.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/prefs/session_startup_pref.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile_impl.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile_manager.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sessions/session_restore.h"
23a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/browser/signin/signin_promo.h"
24f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "chrome/browser/supervised_user/supervised_user_navigation_observer.h"
25f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "chrome/browser/supervised_user/supervised_user_service.h"
26f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h"
28cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/ui/browser_commands.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_finder.h"
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_iterator.h"
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_list.h"
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_list_observer.h"
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_window.h"
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/host_desktop.h"
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/startup/startup_browser_creator.h"
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h"
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h"
39a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/common/extensions/extension_constants.h"
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/pref_names.h"
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/url_constants.h"
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h"
43a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/test/base/test_switches.h"
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/ui_test_utils.h"
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h"
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/browser/extension_system.h"
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
482385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch#include "url/gurl.h"
497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS)
517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/callback.h"
527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/run_loop.h"
537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/values.h"
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/policy/core/browser/browser_policy_connector.h"
55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/policy/core/common/external_data_fetcher.h"
56a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/common/mock_configuration_policy_provider.h"
57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/policy/core/common/policy_map.h"
58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/policy/core/common/policy_types.h"
597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "policy/policy_constants.h"
607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "testing/gmock/include/gmock/gmock.h"
617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)using testing::_;
637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)using testing::Return;
647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#endif  // defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS)
65c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using extensions::Extension;
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
68c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace {
69c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
70c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Check that there are two browsers. Find the one that is not |browser|.
71c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)Browser* FindOneOtherBrowser(Browser* browser) {
72c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // There should only be one other browser.
73c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile(),
74c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                        browser->host_desktop_type()));
75c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
76c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Find the new browser.
77c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Browser* other_browser = NULL;
78c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (chrome::BrowserIterator it; !it.done() && !other_browser; it.Next()) {
79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (*it != browser)
80c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      other_browser = *it;
81c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
82c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return other_browser;
83c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
84c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}  // namespace
86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class StartupBrowserCreatorTest : public ExtensionBrowserTest {
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool SetUpUserDataDirectory() OVERRIDE {
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return ExtensionBrowserTest::SetUpUserDataDirectory();
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ExtensionBrowserTest::SetUpCommandLine(command_line);
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    command_line->AppendSwitch(switches::kEnablePanels);
96f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    command_line->AppendSwitchASCII(switches::kHomePage, url::kAboutBlankURL);
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_CHROMEOS)
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // TODO(nkostylev): Investigate if we can remove this switch.
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    command_line->AppendSwitch(switches::kCreateBrowserOnStartupForTests);
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Helper functions return void so that we can ASSERT*().
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Use ASSERT_NO_FATAL_FAILURE around calls to these functions to stop the
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // test if an assert fails.
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void LoadApp(const std::string& app_name,
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               const Extension** out_app_extension) {
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(app_name.c_str())));
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ExtensionService* service = extensions::ExtensionSystem::Get(
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        browser()->profile())->extension_service();
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    *out_app_extension = service->GetExtensionById(
1138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        last_loaded_extension_id(), false);
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ASSERT_TRUE(*out_app_extension);
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Code that opens a new browser assumes we start with exactly one.
1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                          browser()->host_desktop_type()));
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetAppLaunchPref(const std::string& app_id,
122a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                        extensions::LaunchType launch_type) {
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ExtensionService* service = extensions::ExtensionSystem::Get(
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        browser()->profile())->extension_service();
1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    extensions::SetLaunchType(service, app_id, launch_type);
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Browser* FindOneOtherBrowserForProfile(Profile* profile,
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                         Browser* not_this_browser) {
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    for (chrome::BrowserIterator it; !it.done(); it.Next()) {
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      if (*it != not_this_browser && it->profile() == profile)
1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        return *it;
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return NULL;
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class OpenURLsPopupObserver : public chrome::BrowserListObserver {
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  OpenURLsPopupObserver() : added_browser_(NULL) { }
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnBrowserAdded(Browser* browser) OVERRIDE {
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    added_browser_ = browser;
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnBrowserRemoved(Browser* browser) OVERRIDE { }
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Browser* added_browser_;
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that when there is a popup as the active browser any requests to
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// StartupBrowserCreatorImpl::OpenURLsInBrowser don't crash because there's no
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// explicit profile given.
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenURLsPopup) {
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<GURL> urls;
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  urls.push_back(GURL("http://localhost"));
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note that in our testing we do not ever query the BrowserList for the "last
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // active" browser. That's because the browsers are set as "active" by
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // platform UI toolkit messages, and those messages are not sent during unit
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // testing sessions.
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  OpenURLsPopupObserver observer;
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BrowserList::AddObserver(&observer);
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Browser* popup = new Browser(
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile(),
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                            browser()->host_desktop_type()));
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(popup->is_type_popup());
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_EQ(popup, observer.added_browser_);
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CommandLine dummy(CommandLine::NO_PROGRAM);
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This should create a new window, but re-use the profile from |popup|. If
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // it used a NULL or invalid profile, it would crash.
178bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  launch.OpenURLsInBrowser(popup, false, urls, chrome::GetActiveDesktop());
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NE(popup, observer.added_browser_);
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BrowserList::RemoveObserver(&observer);
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// We don't do non-process-startup browser launches on ChromeOS.
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Session restore for process-startup browser launches is tested
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// in session_restore_uitest.
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_CHROMEOS)
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Verify that startup URLs are honored when the process already exists but has
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// no tabbed browser windows (eg. as if the process is running only due to a
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// background application.
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest,
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       StartupURLsOnNewWindowWithNoTabbedBrowsers) {
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Use a couple same-site HTTP URLs.
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(test_server()->Start());
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<GURL> urls;
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  urls.push_back(test_server()->GetURL("files/title1.html"));
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  urls.push_back(test_server()->GetURL("files/title2.html"));
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set the startup preference to open these URLs.
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref pref(SessionStartupPref::URLS);
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  pref.urls = urls;
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref::SetStartupPref(browser()->profile(), pref);
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Close the browser.
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  browser()->window()->Close();
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Do a simple non-process-startup browser launch.
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CommandLine dummy(CommandLine::NO_PROGRAM);
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
21190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
21290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                            browser()->host_desktop_type()));
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This should have created a new browser window.  |browser()| is still
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // around at this point, even though we've closed its window.
216c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Browser* new_browser = FindOneOtherBrowser(browser());
217c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(new_browser);
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The new browser should have one tab for each URL.
2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TabStripModel* tab_strip = new_browser->tab_strip_model();
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(static_cast<int>(urls.size()), tab_strip->count());
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (size_t i=0; i < urls.size(); i++) {
2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(urls[i], tab_strip->GetWebContentsAt(i)->GetURL());
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The two tabs, despite having the same site, should be in different
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // SiteInstances.
2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_NE(tab_strip->GetWebContentsAt(0)->GetSiteInstance(),
2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            tab_strip->GetWebContentsAt(1)->GetSiteInstance());
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Verify that startup URLs aren't used when the process already exists
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// and has other tabbed browser windows.  This is the common case of starting a
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// new browser.
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest,
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       StartupURLsOnNewWindow) {
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Use a couple arbitrary URLs.
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<GURL> urls;
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  urls.push_back(ui_test_utils::GetTestUrl(
2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath(base::FilePath::kCurrentDirectory),
2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath(FILE_PATH_LITERAL("title1.html"))));
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  urls.push_back(ui_test_utils::GetTestUrl(
2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath(base::FilePath::kCurrentDirectory),
2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath(FILE_PATH_LITERAL("title2.html"))));
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set the startup preference to open these URLs.
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref pref(SessionStartupPref::URLS);
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  pref.urls = urls;
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref::SetStartupPref(browser()->profile(), pref);
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Do a simple non-process-startup browser launch.
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CommandLine dummy(CommandLine::NO_PROGRAM);
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
25690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
25790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                            browser()->host_desktop_type()));
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This should have created a new browser window.
260c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Browser* new_browser = FindOneOtherBrowser(browser());
261c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(new_browser);
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The new browser should have exactly one tab (not the startup URLs).
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(1, new_browser->tab_strip_model()->count());
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// App shortcuts are not implemented on mac os.
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_MACOSX)
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutNoPref) {
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Load an app with launch.container = 'tab'.
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Extension* extension_app = NULL;
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app));
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Add --app-id=<extension->id()> to the command line.
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CommandLine command_line(CommandLine::NO_PROGRAM);
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  command_line.AppendSwitchASCII(switches::kAppId, extension_app->id());
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run);
28190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
28290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                            browser()->host_desktop_type()));
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // No pref was set, so the app should have opened in a window.
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The launch should have created a new browser.
286c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Browser* new_browser = FindOneOtherBrowser(browser());
287c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(new_browser);
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Expect an app window.
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(new_browser->is_app());
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The browser's app_name should include the app's ID.
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_NE(
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      new_browser->app_name_.find(extension_app->id()),
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      std::string::npos) << new_browser->app_name_;
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutWindowPref) {
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Extension* extension_app = NULL;
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app));
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set a pref indicating that the user wants to open this app in a window.
303a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  SetAppLaunchPref(extension_app->id(), extensions::LAUNCH_TYPE_WINDOW);
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CommandLine command_line(CommandLine::NO_PROGRAM);
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  command_line.AppendSwitchASCII(switches::kAppId, extension_app->id());
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run);
31090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
31190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                            browser()->host_desktop_type()));
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Pref was set to open in a window, so the app should have opened in a
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // window.  The launch should have created a new browser. Find the new
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // browser.
316c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Browser* new_browser = FindOneOtherBrowser(browser());
317c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(new_browser);
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Expect an app window.
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(new_browser->is_app());
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The browser's app_name should include the app's ID.
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_NE(
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      new_browser->app_name_.find(extension_app->id()),
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      std::string::npos) << new_browser->app_name_;
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutTabPref) {
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Load an app with launch.container = 'tab'.
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Extension* extension_app = NULL;
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app));
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set a pref indicating that the user wants to open this app in a window.
334a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  SetAppLaunchPref(extension_app->id(), extensions::LAUNCH_TYPE_REGULAR);
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CommandLine command_line(CommandLine::NO_PROGRAM);
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  command_line.AppendSwitchASCII(switches::kAppId, extension_app->id());
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
3402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run);
34190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
34290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                            browser()->host_desktop_type()));
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // When an app shortcut is open and the pref indicates a tab should
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // open, the tab is open in a new browser window.  Expect a new window.
3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(),
3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                        browser()->host_desktop_type()));
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
349c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Browser* new_browser = FindOneOtherBrowser(browser());
350c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(new_browser);
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The tab should be in a tabbed window.
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(new_browser->is_type_tabbed());
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The browser's app_name should not include the app's ID: It is in a
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // normal browser.
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      new_browser->app_name_.find(extension_app->id()),
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      std::string::npos) << new_browser->app_name_;
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // !defined(OS_MACOSX)
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // !defined(OS_CHROMEOS)
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest,
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       ReadingWasRestartedAfterRestart) {
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Tests that StartupBrowserCreator::WasRestarted reads and resets the
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // preference kWasRestarted correctly.
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  StartupBrowserCreator::was_restarted_read_ = false;
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PrefService* pref_service = g_browser_process->local_state();
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  pref_service->SetBoolean(prefs::kWasRestarted, true);
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(StartupBrowserCreator::WasRestarted());
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted));
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(StartupBrowserCreator::WasRestarted());
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest,
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       ReadingWasRestartedAfterNormalStart) {
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Tests that StartupBrowserCreator::WasRestarted reads and resets the
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // preference kWasRestarted correctly.
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  StartupBrowserCreator::was_restarted_read_ = false;
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PrefService* pref_service = g_browser_process->local_state();
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  pref_service->SetBoolean(prefs::kWasRestarted, false);
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(StartupBrowserCreator::WasRestarted());
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted));
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(StartupBrowserCreator::WasRestarted());
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
390f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Fails on official builds. See http://crbug.com/313856
391f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(GOOGLE_CHROME_BUILD)
392f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define MAYBE_AddFirstRunTab DISABLED_AddFirstRunTab
393f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#else
394f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define MAYBE_AddFirstRunTab AddFirstRunTab
395f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif
396f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, MAYBE_AddFirstRunTab) {
3972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreator browser_creator;
3982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
3992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  browser_creator.AddFirstRunTab(test_server()->GetURL("files/title2.html"));
4002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Do a simple non-process-startup browser launch.
4022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CommandLine dummy(CommandLine::NO_PROGRAM);
4032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
4042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                   chrome::startup::IS_FIRST_RUN);
40590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
40690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                            browser()->host_desktop_type()));
4072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This should have created a new browser window.
409c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Browser* new_browser = FindOneOtherBrowser(browser());
410c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(new_browser);
4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TabStripModel* tab_strip = new_browser->tab_strip_model();
4132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(2, tab_strip->count());
4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("title1.html",
4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName());
4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("title2.html",
4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName());
4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Test hard-coded special first run tabs (defined in
4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// StartupBrowserCreatorImpl::AddStartupURLs()).
423f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Fails on official builds. See http://crbug.com/313856
424f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(GOOGLE_CHROME_BUILD)
425f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define MAYBE_AddCustomFirstRunTab DISABLED_AddCustomFirstRunTab
426f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#else
427f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define MAYBE_AddCustomFirstRunTab AddCustomFirstRunTab
428f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif
429f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, MAYBE_AddCustomFirstRunTab) {
4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreator browser_creator;
4312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
4322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  browser_creator.AddFirstRunTab(GURL("http://new_tab_page"));
4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  browser_creator.AddFirstRunTab(test_server()->GetURL("files/title2.html"));
4342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  browser_creator.AddFirstRunTab(GURL("http://welcome_page"));
4352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Do a simple non-process-startup browser launch.
4372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CommandLine dummy(CommandLine::NO_PROGRAM);
4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                   chrome::startup::IS_FIRST_RUN);
44090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
44190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                            browser()->host_desktop_type()));
4422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This should have created a new browser window.
444c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Browser* new_browser = FindOneOtherBrowser(browser());
445c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(new_browser);
4462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TabStripModel* tab_strip = new_browser->tab_strip_model();
4482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(4, tab_strip->count());
4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("title1.html",
4512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName());
4522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
4532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            tab_strip->GetWebContentsAt(1)->GetURL());
4542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("title2.html",
4552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            tab_strip->GetWebContentsAt(2)->GetURL().ExtractFileName());
4562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(internals::GetWelcomePageURL(),
4572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            tab_strip->GetWebContentsAt(3)->GetURL());
4582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
4592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoNoWelcomePage) {
4612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Do a simple non-process-startup browser launch.
4622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CommandLine dummy(CommandLine::NO_PROGRAM);
4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreatorImpl launch(base::FilePath(), dummy,
4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                   chrome::startup::IS_FIRST_RUN);
46590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
46690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                            browser()->host_desktop_type()));
4672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This should have created a new browser window.
469c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Browser* new_browser = FindOneOtherBrowser(browser());
470c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(new_browser);
4712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TabStripModel* tab_strip = new_browser->tab_strip_model();
4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1, tab_strip->count());
4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
475a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (signin::ShouldShowPromoAtStartup(browser()->profile(), true)) {
4762385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch    EXPECT_EQ(signin::GetPromoURL(signin::SOURCE_START_PAGE, false),
4772385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch              tab_strip->GetWebContentsAt(0)->GetURL());
4782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } else {
4792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
4802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              tab_strip->GetWebContentsAt(0)->GetURL());
4812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
4832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoWithWelcomePage) {
4852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  first_run::SetShouldShowWelcomePage();
4862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Do a simple non-process-startup browser launch.
4882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CommandLine dummy(CommandLine::NO_PROGRAM);
4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreatorImpl launch(base::FilePath(), dummy,
4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                   chrome::startup::IS_FIRST_RUN);
49190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
49290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                            browser()->host_desktop_type()));
4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This should have created a new browser window.
495c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Browser* new_browser = FindOneOtherBrowser(browser());
496c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(new_browser);
4972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TabStripModel* tab_strip = new_browser->tab_strip_model();
4992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(2, tab_strip->count());
5002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
501a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (signin::ShouldShowPromoAtStartup(browser()->profile(), true)) {
5022385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch    EXPECT_EQ(signin::GetPromoURL(signin::SOURCE_START_PAGE, false),
5032385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch              tab_strip->GetWebContentsAt(0)->GetURL());
5042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } else {
5052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
5062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              tab_strip->GetWebContentsAt(0)->GetURL());
5072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(internals::GetWelcomePageURL(),
5092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            tab_strip->GetWebContentsAt(1)->GetURL());
5102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoWithFirstRunTabs) {
5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreator browser_creator;
5142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The welcome page should not be shown, even if
5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // first_run::ShouldShowWelcomePage() says so, when there are already
5182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // more than 2 first run tabs.
5192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  first_run::SetShouldShowWelcomePage();
5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Do a simple non-process-startup browser launch.
5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CommandLine dummy(CommandLine::NO_PROGRAM);
5232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
5242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                   chrome::startup::IS_FIRST_RUN);
52590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
52690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                            browser()->host_desktop_type()));
5272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This should have created a new browser window.
529c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Browser* new_browser = FindOneOtherBrowser(browser());
530c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(new_browser);
5312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TabStripModel* tab_strip = new_browser->tab_strip_model();
533a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (signin::ShouldShowPromoAtStartup(browser()->profile(), true)) {
5342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(2, tab_strip->count());
5352385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch    EXPECT_EQ(signin::GetPromoURL(signin::SOURCE_START_PAGE, false),
5362385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch              tab_strip->GetWebContentsAt(0)->GetURL());
5372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ("title1.html",
5382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName());
5392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } else {
5402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(1, tab_strip->count());
5412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ("title1.html",
5422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName());
5432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The welcome page should still be shown if there are more than 2 first run
5472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// tabs, but the welcome page was explcitly added to the first run tabs.
5482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest,
5492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                       SyncPromoWithFirstRunTabsIncludingWelcomePage) {
5502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreator browser_creator;
5512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
5522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  browser_creator.AddFirstRunTab(GURL("http://welcome_page"));
5532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Do a simple non-process-startup browser launch.
5552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CommandLine dummy(CommandLine::NO_PROGRAM);
5562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
5572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                   chrome::startup::IS_FIRST_RUN);
55890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
55990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                            browser()->host_desktop_type()));
5602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This should have created a new browser window.
562c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Browser* new_browser = FindOneOtherBrowser(browser());
563c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(new_browser);
5642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TabStripModel* tab_strip = new_browser->tab_strip_model();
566a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (signin::ShouldShowPromoAtStartup(browser()->profile(), true)) {
5672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(3, tab_strip->count());
5682385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch    EXPECT_EQ(signin::GetPromoURL(signin::SOURCE_START_PAGE, false),
5692385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch              tab_strip->GetWebContentsAt(0)->GetURL());
5702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ("title1.html",
5712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName());
5722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(internals::GetWelcomePageURL(),
5732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              tab_strip->GetWebContentsAt(2)->GetURL());
5742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } else {
5752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(2, tab_strip->count());
5762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ("title1.html",
5772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName());
5782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(internals::GetWelcomePageURL(),
5792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              tab_strip->GetWebContentsAt(1)->GetURL());
5802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_CHROMEOS)
5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, StartupURLsForTwoProfiles) {
585558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#if defined(OS_WIN) && defined(USE_ASH)
586558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // Disable this test in Metro+Ash for now (http://crbug.com/262796).
587a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
588558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch    return;
589558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif
590558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* default_profile = browser()->profile();
5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ProfileManager* profile_manager = g_browser_process->profile_manager();
5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Create another profile.
5952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath dest_path = profile_manager->user_data_dir();
5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1"));
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* other_profile = profile_manager->GetProfile(dest_path);
5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(other_profile);
6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Use a couple arbitrary URLs.
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<GURL> urls1;
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  urls1.push_back(ui_test_utils::GetTestUrl(
6042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath(base::FilePath::kCurrentDirectory),
6052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath(FILE_PATH_LITERAL("title1.html"))));
6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<GURL> urls2;
6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  urls2.push_back(ui_test_utils::GetTestUrl(
6082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath(base::FilePath::kCurrentDirectory),
6092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath(FILE_PATH_LITERAL("title2.html"))));
6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set different startup preferences for the 2 profiles.
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref pref1(SessionStartupPref::URLS);
6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  pref1.urls = urls1;
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref::SetStartupPref(default_profile, pref1);
6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref pref2(SessionStartupPref::URLS);
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  pref2.urls = urls2;
6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref::SetStartupPref(other_profile, pref2);
6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Close the browser.
6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  browser()->window()->Close();
6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Do a simple non-process-startup browser launch.
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CommandLine dummy(CommandLine::NO_PROGRAM);
6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int return_code;
6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  StartupBrowserCreator browser_creator;
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<Profile*> last_opened_profiles;
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  last_opened_profiles.push_back(default_profile);
6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  last_opened_profiles.push_back(other_profile);
6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  browser_creator.Start(dummy, profile_manager->user_data_dir(),
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        default_profile, last_opened_profiles, &return_code);
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // urls1 were opened in a browser for default_profile, and urls2 were opened
6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // in a browser for other_profile.
6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Browser* new_browser = NULL;
6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |browser()| is still around at this point, even though we've closed its
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // window. Thus the browser count for default_profile is 2.
6382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(2u, chrome::GetBrowserCount(default_profile,
6392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                        browser()->host_desktop_type()));
6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  new_browser = FindOneOtherBrowserForProfile(default_profile, browser());
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(new_browser);
6422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TabStripModel* tab_strip = new_browser->tab_strip_model();
6432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(1, tab_strip->count());
6442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(urls1[0], tab_strip->GetWebContentsAt(0)->GetURL());
6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(1u, chrome::GetBrowserCount(other_profile,
6472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                        browser()->host_desktop_type()));
6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  new_browser = FindOneOtherBrowserForProfile(other_profile, NULL);
6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(new_browser);
6502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  tab_strip = new_browser->tab_strip_model();
6512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(1, tab_strip->count());
6522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(urls2[0], tab_strip->GetWebContentsAt(0)->GetURL());
6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
65590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, PRE_UpdateWithTwoProfiles) {
65690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Simulate a browser restart by creating the profiles in the PRE_ part.
6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ProfileManager* profile_manager = g_browser_process->profile_manager();
6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
659cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ASSERT_TRUE(test_server()->Start());
660cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Create two profiles.
6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath dest_path = profile_manager->user_data_dir();
6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* profile1 = profile_manager->GetProfile(
6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      dest_path.Append(FILE_PATH_LITERAL("New Profile 1")));
6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(profile1);
6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* profile2 = profile_manager->GetProfile(
6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      dest_path.Append(FILE_PATH_LITERAL("New Profile 2")));
6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(profile2);
6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
672cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Open some urls with the browsers, and close them.
673cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  Browser* browser1 = new Browser(
674cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      Browser::CreateParams(Browser::TYPE_TABBED, profile1,
675cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                            browser()->host_desktop_type()));
676cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  chrome::NewTab(browser1);
677cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ui_test_utils::NavigateToURL(browser1,
678cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                               test_server()->GetURL("files/empty.html"));
679cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  browser1->window()->Close();
680cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
681cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  Browser* browser2 = new Browser(
682cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      Browser::CreateParams(Browser::TYPE_TABBED, profile2,
683cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                            browser()->host_desktop_type()));
684cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  chrome::NewTab(browser2);
685cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ui_test_utils::NavigateToURL(browser2,
686cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                               test_server()->GetURL("files/form.html"));
687cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  browser2->window()->Close();
688cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
689cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Set different startup preferences for the 2 profiles.
6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<GURL> urls1;
6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  urls1.push_back(ui_test_utils::GetTestUrl(
6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath(base::FilePath::kCurrentDirectory),
6932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath(FILE_PATH_LITERAL("title1.html"))));
6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<GURL> urls2;
6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  urls2.push_back(ui_test_utils::GetTestUrl(
6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath(base::FilePath::kCurrentDirectory),
6972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath(FILE_PATH_LITERAL("title2.html"))));
6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set different startup preferences for the 2 profiles.
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref pref1(SessionStartupPref::URLS);
7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  pref1.urls = urls1;
7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref::SetStartupPref(profile1, pref1);
7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref pref2(SessionStartupPref::URLS);
7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  pref2.urls = urls2;
7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref::SetStartupPref(profile2, pref2);
7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
70790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  profile1->GetPrefs()->CommitPendingWrite();
70890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  profile2->GetPrefs()->CommitPendingWrite();
70990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
71090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
71146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// See crbug.com/376184 about improvements to this test on Mac.
71246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Disabled because it's flaky. http://crbug.com/379579
71346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest,
71446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                       DISABLED_UpdateWithTwoProfiles) {
715558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#if defined(OS_WIN) && defined(USE_ASH)
716558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // Disable this test in Metro+Ash for now (http://crbug.com/262796).
717a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
718558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch    return;
719558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif
720558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
72190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Make StartupBrowserCreator::WasRestarted() return true.
72290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  StartupBrowserCreator::was_restarted_read_ = false;
72390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  PrefService* pref_service = g_browser_process->local_state();
72490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  pref_service->SetBoolean(prefs::kWasRestarted, true);
72590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
72690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ProfileManager* profile_manager = g_browser_process->profile_manager();
72790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
72890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Open the two profiles.
72990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  base::FilePath dest_path = profile_manager->user_data_dir();
73090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
73190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  Profile* profile1 = profile_manager->GetProfile(
73290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      dest_path.Append(FILE_PATH_LITERAL("New Profile 1")));
73390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(profile1);
73490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
73590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  Profile* profile2 = profile_manager->GetProfile(
73690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      dest_path.Append(FILE_PATH_LITERAL("New Profile 2")));
73790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(profile2);
73890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Simulate a launch after a browser update.
7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CommandLine dummy(CommandLine::NO_PROGRAM);
7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int return_code;
7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  StartupBrowserCreator browser_creator;
7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<Profile*> last_opened_profiles;
7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  last_opened_profiles.push_back(profile1);
7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  last_opened_profiles.push_back(profile2);
7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  browser_creator.Start(dummy, profile_manager->user_data_dir(), profile1,
7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        last_opened_profiles, &return_code);
7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  while (SessionRestore::IsRestoring(profile1) ||
7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         SessionRestore::IsRestoring(profile2))
751b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    base::MessageLoop::current()->RunUntilIdle();
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The startup URLs are ignored, and instead the last open sessions are
7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // restored.
7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(profile1->restored_last_session());
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(profile2->restored_last_session());
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Browser* new_browser = NULL;
7592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(1u, chrome::GetBrowserCount(profile1,
7602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                        browser()->host_desktop_type()));
7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  new_browser = FindOneOtherBrowserForProfile(profile1, NULL);
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(new_browser);
7632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TabStripModel* tab_strip = new_browser->tab_strip_model();
7642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(1, tab_strip->count());
765cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ("/files/empty.html",
766cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)            tab_strip->GetWebContentsAt(0)->GetURL().path());
7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(1u, chrome::GetBrowserCount(profile2,
7692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                        browser()->host_desktop_type()));
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  new_browser = FindOneOtherBrowserForProfile(profile2, NULL);
7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(new_browser);
7722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  tab_strip = new_browser->tab_strip_model();
7732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(1, tab_strip->count());
774cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ("/files/form.html",
775cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)            tab_strip->GetWebContentsAt(0)->GetURL().path());
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest,
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       ProfilesWithoutPagesNotLaunched) {
780558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#if defined(OS_WIN) && defined(USE_ASH)
781558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // Disable this test in Metro+Ash for now (http://crbug.com/262796).
782a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
783558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch    return;
784558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif
785558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* default_profile = browser()->profile();
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ProfileManager* profile_manager = g_browser_process->profile_manager();
7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Create 4 more profiles.
7912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath dest_path1 = profile_manager->user_data_dir().Append(
7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      FILE_PATH_LITERAL("New Profile 1"));
7932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath dest_path2 = profile_manager->user_data_dir().Append(
7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      FILE_PATH_LITERAL("New Profile 2"));
7952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath dest_path3 = profile_manager->user_data_dir().Append(
7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      FILE_PATH_LITERAL("New Profile 3"));
7972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath dest_path4 = profile_manager->user_data_dir().Append(
7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      FILE_PATH_LITERAL("New Profile 4"));
7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* profile_home1 = profile_manager->GetProfile(dest_path1);
8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(profile_home1);
8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* profile_home2 = profile_manager->GetProfile(dest_path2);
8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(profile_home2);
8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* profile_last = profile_manager->GetProfile(dest_path3);
8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(profile_last);
8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* profile_urls = profile_manager->GetProfile(dest_path4);
8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(profile_urls);
8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set the profiles to open urls, open last visited pages or display the home
8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // page.
8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref pref_home(SessionStartupPref::DEFAULT);
8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref::SetStartupPref(profile_home1, pref_home);
8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref::SetStartupPref(profile_home2, pref_home);
8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref pref_last(SessionStartupPref::LAST);
8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref::SetStartupPref(profile_last, pref_last);
8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<GURL> urls;
8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  urls.push_back(ui_test_utils::GetTestUrl(
8202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath(base::FilePath::kCurrentDirectory),
8212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::FilePath(FILE_PATH_LITERAL("title1.html"))));
8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref pref_urls(SessionStartupPref::URLS);
8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  pref_urls.urls = urls;
8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionStartupPref::SetStartupPref(profile_urls, pref_urls);
8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
827cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Open a page with profile_last.
828cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  Browser* browser_last = new Browser(
829cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      Browser::CreateParams(Browser::TYPE_TABBED, profile_last,
830cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                            browser()->host_desktop_type()));
831cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  chrome::NewTab(browser_last);
832cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ui_test_utils::NavigateToURL(browser_last,
833cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                               test_server()->GetURL("files/empty.html"));
834cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  browser_last->window()->Close();
835cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
836cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Close the main browser.
8372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  chrome::HostDesktopType original_desktop_type =
8382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      browser()->host_desktop_type();
8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  browser()->window()->Close();
8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Do a simple non-process-startup browser launch.
8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CommandLine dummy(CommandLine::NO_PROGRAM);
8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int return_code;
8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  StartupBrowserCreator browser_creator;
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<Profile*> last_opened_profiles;
8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  last_opened_profiles.push_back(profile_home1);
8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  last_opened_profiles.push_back(profile_home2);
8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  last_opened_profiles.push_back(profile_last);
8505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  last_opened_profiles.push_back(profile_urls);
8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  browser_creator.Start(dummy, profile_manager->user_data_dir(), profile_home1,
8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        last_opened_profiles, &return_code);
8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  while (SessionRestore::IsRestoring(default_profile) ||
8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         SessionRestore::IsRestoring(profile_home1) ||
8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         SessionRestore::IsRestoring(profile_home2) ||
8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         SessionRestore::IsRestoring(profile_last) ||
8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         SessionRestore::IsRestoring(profile_urls))
859b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    base::MessageLoop::current()->RunUntilIdle();
8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Browser* new_browser = NULL;
8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The last open profile (the profile_home1 in this case) will always be
8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // launched, even if it will open just the home page.
8642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(1u, chrome::GetBrowserCount(profile_home1, original_desktop_type));
8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  new_browser = FindOneOtherBrowserForProfile(profile_home1, NULL);
8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(new_browser);
8672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TabStripModel* tab_strip = new_browser->tab_strip_model();
8682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(1, tab_strip->count());
8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
8702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            tab_strip->GetWebContentsAt(0)->GetURL());
8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // profile_urls opened the urls.
8732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(1u, chrome::GetBrowserCount(profile_urls, original_desktop_type));
8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  new_browser = FindOneOtherBrowserForProfile(profile_urls, NULL);
8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(new_browser);
8762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  tab_strip = new_browser->tab_strip_model();
8772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(1, tab_strip->count());
8782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(urls[0], tab_strip->GetWebContentsAt(0)->GetURL());
8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // profile_last opened the last open pages.
8812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(1u, chrome::GetBrowserCount(profile_last, original_desktop_type));
8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  new_browser = FindOneOtherBrowserForProfile(profile_last, NULL);
8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(new_browser);
8842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  tab_strip = new_browser->tab_strip_model();
8852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(1, tab_strip->count());
886cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ("/files/empty.html",
887cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)            tab_strip->GetWebContentsAt(0)->GetURL().path());
8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // profile_home2 was not launched since it would've only opened the home page.
8902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(0u, chrome::GetBrowserCount(profile_home2, original_desktop_type));
8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, ProfilesLaunchedAfterCrash) {
894558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#if defined(OS_WIN) && defined(USE_ASH)
895558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // Disable this test in Metro+Ash for now (http://crbug.com/262796).
896a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
897558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch    return;
898558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif
899558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // After an unclean exit, all profiles will be launched. However, they won't
9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // open any pages automatically.
9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ProfileManager* profile_manager = g_browser_process->profile_manager();
9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Create 3 profiles.
9062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath dest_path1 = profile_manager->user_data_dir().Append(
9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      FILE_PATH_LITERAL("New Profile 1"));
9082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath dest_path2 = profile_manager->user_data_dir().Append(
9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      FILE_PATH_LITERAL("New Profile 2"));
9102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath dest_path3 = profile_manager->user_data_dir().Append(
9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      FILE_PATH_LITERAL("New Profile 3"));
9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* profile_home = profile_manager->GetProfile(dest_path1);
9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(profile_home);
915