OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), | 467 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), |
468 new_browser->GetWebContentsAt(0)->GetURL()); | 468 new_browser->GetWebContentsAt(0)->GetURL()); |
469 | 469 |
470 ASSERT_EQ(1u, BrowserList::GetBrowserCount(profile2)); | 470 ASSERT_EQ(1u, BrowserList::GetBrowserCount(profile2)); |
471 new_browser = FindOneOtherBrowserForProfile(profile2, NULL); | 471 new_browser = FindOneOtherBrowserForProfile(profile2, NULL); |
472 ASSERT_TRUE(new_browser); | 472 ASSERT_TRUE(new_browser); |
473 ASSERT_EQ(1, new_browser->tab_count()); | 473 ASSERT_EQ(1, new_browser->tab_count()); |
474 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), | 474 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), |
475 new_browser->GetWebContentsAt(0)->GetURL()); | 475 new_browser->GetWebContentsAt(0)->GetURL()); |
476 } | 476 } |
| 477 |
| 478 IN_PROC_BROWSER_TEST_F(BrowserInitTest, ProfilesWithoutPagesNotLaunched) { |
| 479 Profile* default_profile = browser()->profile(); |
| 480 |
| 481 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 482 |
| 483 // Create 4 more profiles. |
| 484 FilePath dest_path1 = profile_manager->user_data_dir().Append( |
| 485 FILE_PATH_LITERAL("New Profile 1")); |
| 486 FilePath dest_path2 = profile_manager->user_data_dir().Append( |
| 487 FILE_PATH_LITERAL("New Profile 2")); |
| 488 FilePath dest_path3 = profile_manager->user_data_dir().Append( |
| 489 FILE_PATH_LITERAL("New Profile 3")); |
| 490 FilePath dest_path4 = profile_manager->user_data_dir().Append( |
| 491 FILE_PATH_LITERAL("New Profile 4")); |
| 492 |
| 493 Profile* profile_home1 = profile_manager->GetProfile(dest_path1); |
| 494 ASSERT_TRUE(profile_home1); |
| 495 Profile* profile_home2 = profile_manager->GetProfile(dest_path2); |
| 496 ASSERT_TRUE(profile_home2); |
| 497 Profile* profile_last = profile_manager->GetProfile(dest_path3); |
| 498 ASSERT_TRUE(profile_last); |
| 499 Profile* profile_urls = profile_manager->GetProfile(dest_path4); |
| 500 ASSERT_TRUE(profile_urls); |
| 501 |
| 502 // Set the profiles to open urls, open last visited pages or display the home |
| 503 // page. |
| 504 SessionStartupPref pref_home(SessionStartupPref::DEFAULT); |
| 505 SessionStartupPref::SetStartupPref(profile_home1, pref_home); |
| 506 SessionStartupPref::SetStartupPref(profile_home2, pref_home); |
| 507 |
| 508 SessionStartupPref pref_last(SessionStartupPref::LAST); |
| 509 SessionStartupPref::SetStartupPref(profile_last, pref_last); |
| 510 |
| 511 std::vector<GURL> urls; |
| 512 urls.push_back(ui_test_utils::GetTestUrl( |
| 513 FilePath(FilePath::kCurrentDirectory), |
| 514 FilePath(FILE_PATH_LITERAL("title1.html")))); |
| 515 |
| 516 SessionStartupPref pref_urls(SessionStartupPref::URLS); |
| 517 pref_urls.urls = urls; |
| 518 SessionStartupPref::SetStartupPref(profile_urls, pref_urls); |
| 519 |
| 520 // Close the browser. |
| 521 browser()->window()->Close(); |
| 522 |
| 523 // Do a simple non-process-startup browser launch. |
| 524 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 525 |
| 526 int return_code; |
| 527 BrowserInit browser_init; |
| 528 std::vector<Profile*> last_opened_profiles; |
| 529 last_opened_profiles.push_back(profile_home1); |
| 530 last_opened_profiles.push_back(profile_home2); |
| 531 last_opened_profiles.push_back(profile_last); |
| 532 last_opened_profiles.push_back(profile_urls); |
| 533 browser_init.Start(dummy, profile_manager->user_data_dir(), profile_home1, |
| 534 last_opened_profiles, &return_code); |
| 535 |
| 536 |
| 537 while (SessionRestore::IsRestoring(default_profile) || |
| 538 SessionRestore::IsRestoring(profile_home1) || |
| 539 SessionRestore::IsRestoring(profile_home2) || |
| 540 SessionRestore::IsRestoring(profile_last) || |
| 541 SessionRestore::IsRestoring(profile_urls)) |
| 542 MessageLoop::current()->RunAllPending(); |
| 543 |
| 544 Browser* new_browser = NULL; |
| 545 // The last open profile (the profile_home1 in this case) will always be |
| 546 // launched, even if it will open just the home page. |
| 547 ASSERT_EQ(1u, BrowserList::GetBrowserCount(profile_home1)); |
| 548 new_browser = FindOneOtherBrowserForProfile(profile_home1, NULL); |
| 549 ASSERT_TRUE(new_browser); |
| 550 ASSERT_EQ(1, new_browser->tab_count()); |
| 551 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), |
| 552 new_browser->GetWebContentsAt(0)->GetURL()); |
| 553 |
| 554 // profile_urls opened the urls. |
| 555 ASSERT_EQ(1u, BrowserList::GetBrowserCount(profile_urls)); |
| 556 new_browser = FindOneOtherBrowserForProfile(profile_urls, NULL); |
| 557 ASSERT_TRUE(new_browser); |
| 558 ASSERT_EQ(1, new_browser->tab_count()); |
| 559 EXPECT_EQ(urls[0], new_browser->GetWebContentsAt(0)->GetURL()); |
| 560 |
| 561 // profile_last opened the last open pages. |
| 562 ASSERT_EQ(1u, BrowserList::GetBrowserCount(profile_last)); |
| 563 new_browser = FindOneOtherBrowserForProfile(profile_last, NULL); |
| 564 ASSERT_TRUE(new_browser); |
| 565 ASSERT_EQ(1, new_browser->tab_count()); |
| 566 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), |
| 567 new_browser->GetWebContentsAt(0)->GetURL()); |
| 568 |
| 569 // profile_home2 was not launched since it would've only opened the home page. |
| 570 ASSERT_EQ(0u, BrowserList::GetBrowserCount(profile_home2)); |
| 571 } |
OLD | NEW |