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

Unified Diff: chrome/browser/ui/browser_init_browsertest.cc

Issue 9087009: Restore all profiles which were active when restoring the last open pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/browser_init.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ef471a6c387971882d1e8b11bd457d0e1e91ab79 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,16 @@ class BrowserInitTest : public ExtensionBrowserTest {
ASSERT_TRUE(other_browser != browser());
*out_other_browser = other_browser;
}
+
+ Browser* FindOneOtherBrowserForProfile(Profile* profile,
+ Browser* not_this_browser) {
+ for (BrowserList::const_iterator i = BrowserList::begin();
+ i != BrowserList::end(); ++i) {
+ if (*i != not_this_browser && (*i)->profile() == profile)
+ return *i;
+ }
+ return NULL;
+ }
};
class OpenURLsPopupObserver : public BrowserList::Observer {
@@ -305,6 +316,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 +338,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();
+
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ // Create another profile.
+ FilePath dest_path = profile_manager->user_data_dir();
+ dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1"));
+
+ 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, profile_manager->user_data_dir(), 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));
+ new_browser = FindOneOtherBrowserForProfile(default_profile,
+ browser());
+ ASSERT_TRUE(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 = FindOneOtherBrowserForProfile(other_profile, NULL);
+ ASSERT_TRUE(new_browser);
+ ASSERT_EQ(1, new_browser->tab_count());
+ EXPECT_EQ(urls2[0], new_browser->GetWebContentsAt(0)->GetURL());
+}
« no previous file with comments | « chrome/browser/ui/browser_init.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698