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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/browser_init.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/extension_browsertest.h" 9 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/first_run/first_run.h" 11 #include "chrome/browser/first_run/first_run.h"
12 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/prefs/session_startup_pref.h" 13 #include "chrome/browser/prefs/session_startup_pref.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_init.h" 17 #include "chrome/browser/ui/browser_init.h"
17 #include "chrome/browser/ui/browser_list.h" 18 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/browser/ui/browser_window.h" 19 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/in_process_browser_test.h" 22 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
23 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 Browser* other_browser = NULL; 62 Browser* other_browser = NULL;
62 for (BrowserList::const_iterator i = BrowserList::begin(); 63 for (BrowserList::const_iterator i = BrowserList::begin();
63 i != BrowserList::end() && !other_browser; ++i) { 64 i != BrowserList::end() && !other_browser; ++i) {
64 if (*i != browser()) 65 if (*i != browser())
65 other_browser = *i; 66 other_browser = *i;
66 } 67 }
67 ASSERT_TRUE(other_browser); 68 ASSERT_TRUE(other_browser);
68 ASSERT_TRUE(other_browser != browser()); 69 ASSERT_TRUE(other_browser != browser());
69 *out_other_browser = other_browser; 70 *out_other_browser = other_browser;
70 } 71 }
72
73 Browser* FindOneOtherBrowserForProfile(Profile* profile,
74 Browser* not_this_browser) {
75 for (BrowserList::const_iterator i = BrowserList::begin();
76 i != BrowserList::end(); ++i) {
77 if (*i != not_this_browser && (*i)->profile() == profile)
78 return *i;
79 }
80 return NULL;
81 }
71 }; 82 };
72 83
73 class OpenURLsPopupObserver : public BrowserList::Observer { 84 class OpenURLsPopupObserver : public BrowserList::Observer {
74 public: 85 public:
75 OpenURLsPopupObserver() : added_browser_(NULL) { } 86 OpenURLsPopupObserver() : added_browser_(NULL) { }
76 87
77 virtual void OnBrowserAdded(const Browser* browser) { 88 virtual void OnBrowserAdded(const Browser* browser) {
78 added_browser_ = browser; 89 added_browser_ = browser;
79 } 90 }
80 91
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 309
299 // Expect an app panel. 310 // Expect an app panel.
300 EXPECT_TRUE(new_browser->is_type_panel() && new_browser->is_app()); 311 EXPECT_TRUE(new_browser->is_type_panel() && new_browser->is_app());
301 312
302 // The new browser's app_name should include the app's ID. 313 // The new browser's app_name should include the app's ID.
303 EXPECT_NE( 314 EXPECT_NE(
304 new_browser->app_name_.find(extension_app->id()), 315 new_browser->app_name_.find(extension_app->id()),
305 std::string::npos) << new_browser->app_name_; 316 std::string::npos) << new_browser->app_name_;
306 } 317 }
307 318
319 #endif // !defined(OS_MACOSX)
320
308 IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterRestart) { 321 IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterRestart) {
309 // Tests that BrowserInit::WasRestarted reads and resets the preference 322 // Tests that BrowserInit::WasRestarted reads and resets the preference
310 // kWasRestarted correctly. 323 // kWasRestarted correctly.
311 PrefService* pref_service = g_browser_process->local_state(); 324 PrefService* pref_service = g_browser_process->local_state();
312 pref_service->SetBoolean(prefs::kWasRestarted, true); 325 pref_service->SetBoolean(prefs::kWasRestarted, true);
313 EXPECT_TRUE(BrowserInit::WasRestarted()); 326 EXPECT_TRUE(BrowserInit::WasRestarted());
314 EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted)); 327 EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted));
315 EXPECT_TRUE(BrowserInit::WasRestarted()); 328 EXPECT_TRUE(BrowserInit::WasRestarted());
316 } 329 }
317 330
318 IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterNormalStart) { 331 IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterNormalStart) {
319 // Tests that BrowserInit::WasRestarted reads and resets the preference 332 // Tests that BrowserInit::WasRestarted reads and resets the preference
320 // kWasRestarted correctly. 333 // kWasRestarted correctly.
321 PrefService* pref_service = g_browser_process->local_state(); 334 PrefService* pref_service = g_browser_process->local_state();
322 pref_service->SetBoolean(prefs::kWasRestarted, false); 335 pref_service->SetBoolean(prefs::kWasRestarted, false);
323 EXPECT_FALSE(BrowserInit::WasRestarted()); 336 EXPECT_FALSE(BrowserInit::WasRestarted());
324 EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted)); 337 EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted));
325 EXPECT_FALSE(BrowserInit::WasRestarted()); 338 EXPECT_FALSE(BrowserInit::WasRestarted());
326 } 339 }
327 340
328 #endif // !defined(OS_MACOSX) 341 IN_PROC_BROWSER_TEST_F(BrowserInitTest, StartupURLsForTwoProfiles) {
342 Profile* default_profile = browser()->profile();
343
344 ProfileManager* profile_manager = g_browser_process->profile_manager();
345 // Create another profile.
346 FilePath dest_path = profile_manager->user_data_dir();
347 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1"));
348
349 Profile* other_profile = profile_manager->GetProfile(dest_path);
350 ASSERT_TRUE(other_profile);
351
352 // Use a couple arbitrary URLs.
353 std::vector<GURL> urls1;
354 urls1.push_back(ui_test_utils::GetTestUrl(
355 FilePath(FilePath::kCurrentDirectory),
356 FilePath(FILE_PATH_LITERAL("title1.html"))));
357 std::vector<GURL> urls2;
358 urls2.push_back(ui_test_utils::GetTestUrl(
359 FilePath(FilePath::kCurrentDirectory),
360 FilePath(FILE_PATH_LITERAL("title2.html"))));
361
362 // Set different startup preferences for the 2 profiles.
363 SessionStartupPref pref1(SessionStartupPref::URLS);
364 pref1.urls = urls1;
365 SessionStartupPref::SetStartupPref(default_profile, pref1);
366 SessionStartupPref pref2(SessionStartupPref::URLS);
367 pref2.urls = urls2;
368 SessionStartupPref::SetStartupPref(other_profile, pref2);
369
370 // Close the browser.
371 browser()->window()->Close();
372
373 // Do a simple non-process-startup browser launch.
374 CommandLine dummy(CommandLine::NO_PROGRAM);
375
376 int return_code;
377 BrowserInit browser_init;
378 std::vector<Profile*> other_profiles(1, other_profile);
379 browser_init.Start(dummy, profile_manager->user_data_dir(), default_profile,
380 other_profiles, &return_code);
381
382 // urls1 were opened in a browser for default_profile, and urls2 were opened
383 // in a browser for other_profile.
384 Browser* new_browser = NULL;
385 // |browser()| is still around at this point, even though we've closed it's
386 // window. Thus the browser count for default_profile is 2.
387 ASSERT_EQ(2u, BrowserList::GetBrowserCount(default_profile));
388 new_browser = FindOneOtherBrowserForProfile(default_profile,
389 browser());
390 ASSERT_TRUE(new_browser);
391 ASSERT_EQ(1, new_browser->tab_count());
392 EXPECT_EQ(urls1[0], new_browser->GetWebContentsAt(0)->GetURL());
393
394 ASSERT_EQ(1u, BrowserList::GetBrowserCount(other_profile));
395 new_browser = FindOneOtherBrowserForProfile(other_profile, NULL);
396 ASSERT_TRUE(new_browser);
397 ASSERT_EQ(1, new_browser->tab_count());
398 EXPECT_EQ(urls2[0], new_browser->GetWebContentsAt(0)->GetURL());
399 }
OLDNEW
« 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