Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 void FindOneOtherBrowserForProfile(Profile* profile, | |
| 74 Browser* not_this_browser, | |
| 75 Browser** out_other_browser) { | |
|
Peter Kasting
2012/01/10 02:20:12
Nit: Return a Browser* rather than using an outpar
marja
2012/01/10 14:12:03
Done.
| |
| 76 Browser* other_browser = NULL; | |
| 77 for (BrowserList::const_iterator i = BrowserList::begin(); | |
| 78 i != BrowserList::end() && !other_browser; ++i) { | |
| 79 if (*i != not_this_browser && (*i)->profile() == profile) | |
| 80 other_browser = *i; | |
|
Peter Kasting
2012/01/10 02:20:12
Nit: "break" here instead of using the "!other_bro
marja
2012/01/10 14:12:03
Done.
| |
| 81 } | |
| 82 ASSERT_TRUE(other_browser); | |
| 83 *out_other_browser = other_browser; | |
| 84 } | |
| 71 }; | 85 }; |
| 72 | 86 |
| 73 class OpenURLsPopupObserver : public BrowserList::Observer { | 87 class OpenURLsPopupObserver : public BrowserList::Observer { |
| 74 public: | 88 public: |
| 75 OpenURLsPopupObserver() : added_browser_(NULL) { } | 89 OpenURLsPopupObserver() : added_browser_(NULL) { } |
| 76 | 90 |
| 77 virtual void OnBrowserAdded(const Browser* browser) { | 91 virtual void OnBrowserAdded(const Browser* browser) { |
| 78 added_browser_ = browser; | 92 added_browser_ = browser; |
| 79 } | 93 } |
| 80 | 94 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 | 312 |
| 299 // Expect an app panel. | 313 // Expect an app panel. |
| 300 EXPECT_TRUE(new_browser->is_type_panel() && new_browser->is_app()); | 314 EXPECT_TRUE(new_browser->is_type_panel() && new_browser->is_app()); |
| 301 | 315 |
| 302 // The new browser's app_name should include the app's ID. | 316 // The new browser's app_name should include the app's ID. |
| 303 EXPECT_NE( | 317 EXPECT_NE( |
| 304 new_browser->app_name_.find(extension_app->id()), | 318 new_browser->app_name_.find(extension_app->id()), |
| 305 std::string::npos) << new_browser->app_name_; | 319 std::string::npos) << new_browser->app_name_; |
| 306 } | 320 } |
| 307 | 321 |
| 322 #endif // !defined(OS_MACOSX) | |
| 323 | |
| 308 IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterRestart) { | 324 IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterRestart) { |
| 309 // Tests that BrowserInit::WasRestarted reads and resets the preference | 325 // Tests that BrowserInit::WasRestarted reads and resets the preference |
| 310 // kWasRestarted correctly. | 326 // kWasRestarted correctly. |
| 311 PrefService* pref_service = g_browser_process->local_state(); | 327 PrefService* pref_service = g_browser_process->local_state(); |
| 312 pref_service->SetBoolean(prefs::kWasRestarted, true); | 328 pref_service->SetBoolean(prefs::kWasRestarted, true); |
| 313 EXPECT_TRUE(BrowserInit::WasRestarted()); | 329 EXPECT_TRUE(BrowserInit::WasRestarted()); |
| 314 EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted)); | 330 EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted)); |
| 315 EXPECT_TRUE(BrowserInit::WasRestarted()); | 331 EXPECT_TRUE(BrowserInit::WasRestarted()); |
| 316 } | 332 } |
| 317 | 333 |
| 318 IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterNormalStart) { | 334 IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterNormalStart) { |
| 319 // Tests that BrowserInit::WasRestarted reads and resets the preference | 335 // Tests that BrowserInit::WasRestarted reads and resets the preference |
| 320 // kWasRestarted correctly. | 336 // kWasRestarted correctly. |
| 321 PrefService* pref_service = g_browser_process->local_state(); | 337 PrefService* pref_service = g_browser_process->local_state(); |
| 322 pref_service->SetBoolean(prefs::kWasRestarted, false); | 338 pref_service->SetBoolean(prefs::kWasRestarted, false); |
| 323 EXPECT_FALSE(BrowserInit::WasRestarted()); | 339 EXPECT_FALSE(BrowserInit::WasRestarted()); |
| 324 EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted)); | 340 EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted)); |
| 325 EXPECT_FALSE(BrowserInit::WasRestarted()); | 341 EXPECT_FALSE(BrowserInit::WasRestarted()); |
| 326 } | 342 } |
| 327 | 343 |
| 328 #endif // !defined(OS_MACOSX) | 344 IN_PROC_BROWSER_TEST_F(BrowserInitTest, StartupURLsForTwoProfiles) { |
| 345 Profile* default_profile = browser()->profile(); | |
| 346 | |
| 347 // Create another profile. | |
| 348 FilePath dest_path = temp_dir_.path(); | |
| 349 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1")); | |
| 350 | |
| 351 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 352 Profile* other_profile = profile_manager->GetProfile(dest_path); | |
| 353 ASSERT_TRUE(other_profile); | |
| 354 | |
| 355 // Use a couple arbitrary URLs. | |
| 356 std::vector<GURL> urls1; | |
| 357 urls1.push_back(ui_test_utils::GetTestUrl( | |
| 358 FilePath(FilePath::kCurrentDirectory), | |
| 359 FilePath(FILE_PATH_LITERAL("title1.html")))); | |
| 360 std::vector<GURL> urls2; | |
| 361 urls2.push_back(ui_test_utils::GetTestUrl( | |
| 362 FilePath(FilePath::kCurrentDirectory), | |
| 363 FilePath(FILE_PATH_LITERAL("title2.html")))); | |
| 364 | |
| 365 // Set different startup preferences for the 2 profiles. | |
| 366 SessionStartupPref pref1(SessionStartupPref::URLS); | |
| 367 pref1.urls = urls1; | |
| 368 SessionStartupPref::SetStartupPref(default_profile, pref1); | |
| 369 SessionStartupPref pref2(SessionStartupPref::URLS); | |
| 370 pref2.urls = urls2; | |
| 371 SessionStartupPref::SetStartupPref(other_profile, pref2); | |
| 372 | |
| 373 // Close the browser. | |
| 374 browser()->window()->Close(); | |
| 375 | |
| 376 // Do a simple non-process-startup browser launch. | |
| 377 CommandLine dummy(CommandLine::NO_PROGRAM); | |
| 378 | |
| 379 int return_code; | |
| 380 BrowserInit browser_init; | |
| 381 std::vector<Profile*> other_profiles(1, other_profile); | |
| 382 browser_init.Start(dummy, temp_dir_.path(), default_profile, other_profiles, | |
| 383 &return_code); | |
| 384 | |
| 385 // urls1 were opened in a browser for default_profile, and urls2 were opened | |
| 386 // in a browser for other_profile. | |
| 387 Browser* new_browser = NULL; | |
| 388 // |browser()| is still around at this point, even though we've closed it's | |
| 389 // window. Thus the browser count for default_profile is 2. | |
| 390 ASSERT_EQ(2u, BrowserList::GetBrowserCount(default_profile)); | |
| 391 ASSERT_NO_FATAL_FAILURE( | |
| 392 FindOneOtherBrowserForProfile(default_profile, browser(), &new_browser)); | |
| 393 ASSERT_EQ(1, new_browser->tab_count()); | |
| 394 EXPECT_EQ(urls1[0], new_browser->GetWebContentsAt(0)->GetURL()); | |
| 395 | |
| 396 ASSERT_EQ(1u, BrowserList::GetBrowserCount(other_profile)); | |
| 397 new_browser = NULL; | |
| 398 ASSERT_NO_FATAL_FAILURE( | |
| 399 FindOneOtherBrowserForProfile(other_profile, NULL, &new_browser)); | |
| 400 ASSERT_EQ(1, new_browser->tab_count()); | |
| 401 EXPECT_EQ(urls2[0], new_browser->GetWebContentsAt(0)->GetURL()); | |
| 402 } | |
| OLD | NEW |