| Index: chrome/browser/ui/browser_init_browsertest.cc
|
| diff --git a/chrome/browser/ui/browser_init_browsertest.cc b/chrome/browser/ui/browser_init_browsertest.cc
|
| index c64928960e4c82b7bc47898ca16ca78cbcbadabe..b6f0370c31fd63b831c5742b73e84ad7349c32f9 100644
|
| --- a/chrome/browser/ui/browser_init_browsertest.cc
|
| +++ b/chrome/browser/ui/browser_init_browsertest.cc
|
| @@ -12,6 +12,7 @@
|
| #include "chrome/browser/prefs/pref_service.h"
|
| #include "chrome/browser/prefs/session_startup_pref.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/browser_init.h"
|
| #include "chrome/browser/ui/browser_list.h"
|
| @@ -68,6 +69,19 @@ class BrowserInitTest : public ExtensionBrowserTest {
|
| ASSERT_TRUE(other_browser != browser());
|
| *out_other_browser = other_browser;
|
| }
|
| +
|
| + void FindOneOtherBrowserForProfile(Profile* profile,
|
| + Browser* not_this_browser,
|
| + Browser** out_other_browser) {
|
| + Browser* other_browser = NULL;
|
| + for (BrowserList::const_iterator i = BrowserList::begin();
|
| + i != BrowserList::end() && !other_browser; ++i) {
|
| + if (*i != not_this_browser && (*i)->profile() == profile)
|
| + other_browser = *i;
|
| + }
|
| + ASSERT_TRUE(other_browser);
|
| + *out_other_browser = other_browser;
|
| + }
|
| };
|
|
|
| class OpenURLsPopupObserver : public BrowserList::Observer {
|
| @@ -305,6 +319,8 @@ IN_PROC_BROWSER_TEST_F(BrowserInitTest, OpenAppShortcutPanel) {
|
| std::string::npos) << new_browser->app_name_;
|
| }
|
|
|
| +#endif // !defined(OS_MACOSX)
|
| +
|
| IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterRestart) {
|
| // Tests that BrowserInit::WasRestarted reads and resets the preference
|
| // kWasRestarted correctly.
|
| @@ -325,4 +341,62 @@ IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterNormalStart) {
|
| EXPECT_FALSE(BrowserInit::WasRestarted());
|
| }
|
|
|
| -#endif // !defined(OS_MACOSX)
|
| +IN_PROC_BROWSER_TEST_F(BrowserInitTest, StartupURLsForTwoProfiles) {
|
| + Profile* default_profile = browser()->profile();
|
| +
|
| + // Create another profile.
|
| + FilePath dest_path = temp_dir_.path();
|
| + dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1"));
|
| +
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
| + Profile* other_profile = profile_manager->GetProfile(dest_path);
|
| + ASSERT_TRUE(other_profile);
|
| +
|
| + // Use a couple arbitrary URLs.
|
| + std::vector<GURL> urls1;
|
| + urls1.push_back(ui_test_utils::GetTestUrl(
|
| + FilePath(FilePath::kCurrentDirectory),
|
| + FilePath(FILE_PATH_LITERAL("title1.html"))));
|
| + std::vector<GURL> urls2;
|
| + urls2.push_back(ui_test_utils::GetTestUrl(
|
| + FilePath(FilePath::kCurrentDirectory),
|
| + FilePath(FILE_PATH_LITERAL("title2.html"))));
|
| +
|
| + // Set different startup preferences for the 2 profiles.
|
| + SessionStartupPref pref1(SessionStartupPref::URLS);
|
| + pref1.urls = urls1;
|
| + SessionStartupPref::SetStartupPref(default_profile, pref1);
|
| + SessionStartupPref pref2(SessionStartupPref::URLS);
|
| + pref2.urls = urls2;
|
| + SessionStartupPref::SetStartupPref(other_profile, pref2);
|
| +
|
| + // Close the browser.
|
| + browser()->window()->Close();
|
| +
|
| + // Do a simple non-process-startup browser launch.
|
| + CommandLine dummy(CommandLine::NO_PROGRAM);
|
| +
|
| + int return_code;
|
| + BrowserInit browser_init;
|
| + std::vector<Profile*> other_profiles(1, other_profile);
|
| + browser_init.Start(dummy, temp_dir_.path(), default_profile, other_profiles,
|
| + &return_code);
|
| +
|
| + // urls1 were opened in a browser for default_profile, and urls2 were opened
|
| + // in a browser for other_profile.
|
| + Browser* new_browser = NULL;
|
| + // |browser()| is still around at this point, even though we've closed it's
|
| + // window. Thus the browser count for default_profile is 2.
|
| + ASSERT_EQ(2u, BrowserList::GetBrowserCount(default_profile));
|
| + ASSERT_NO_FATAL_FAILURE(
|
| + FindOneOtherBrowserForProfile(default_profile, browser(), &new_browser));
|
| + ASSERT_EQ(1, new_browser->tab_count());
|
| + EXPECT_EQ(urls1[0], new_browser->GetWebContentsAt(0)->GetURL());
|
| +
|
| + ASSERT_EQ(1u, BrowserList::GetBrowserCount(other_profile));
|
| + new_browser = NULL;
|
| + ASSERT_NO_FATAL_FAILURE(
|
| + FindOneOtherBrowserForProfile(other_profile, NULL, &new_browser));
|
| + ASSERT_EQ(1, new_browser->tab_count());
|
| + EXPECT_EQ(urls2[0], new_browser->GetWebContentsAt(0)->GetURL());
|
| +}
|
|
|