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

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator_browsertest.cc

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
OLDNEW
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"
11 #include "chrome/browser/first_run/first_run.h" 11 #include "chrome/browser/first_run/first_run.h"
12 #include "chrome/browser/infobars/infobar_tab_helper.h" 12 #include "chrome/browser/infobars/infobar_tab_helper.h"
13 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/prefs/session_startup_pref.h" 14 #include "chrome/browser/prefs/session_startup_pref.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_impl.h" 16 #include "chrome/browser/profiles/profile_impl.h"
17 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/sessions/session_restore.h" 18 #include "chrome/browser/sessions/session_restore.h"
19 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_finder.h" 20 #include "chrome/browser/ui/browser_finder.h"
21 #include "chrome/browser/ui/browser_list.h" 21 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/browser/ui/browser_tabstrip.h"
22 #include "chrome/browser/ui/browser_window.h" 23 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/startup/startup_browser_creator.h" 24 #include "chrome/browser/ui/startup/startup_browser_creator.h"
24 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" 25 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
25 #include "chrome/browser/ui/tab_contents/tab_contents.h" 26 #include "chrome/browser/ui/tab_contents/tab_contents.h"
26 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
28 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
29 #include "chrome/test/base/in_process_browser_test.h" 30 #include "chrome/test/base/in_process_browser_test.h"
30 #include "chrome/test/base/ui_test_utils.h" 31 #include "chrome/test/base/ui_test_utils.h"
31 #include "content/public/browser/web_contents.h" 32 #include "content/public/browser/web_contents.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 177 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
177 178
178 // This should have created a new browser window. |browser()| is still 179 // This should have created a new browser window. |browser()| is still
179 // around at this point, even though we've closed its window. 180 // around at this point, even though we've closed its window.
180 Browser* new_browser = NULL; 181 Browser* new_browser = NULL;
181 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 182 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser));
182 183
183 // The new browser should have one tab for each URL. 184 // The new browser should have one tab for each URL.
184 ASSERT_EQ(static_cast<int>(urls.size()), new_browser->tab_count()); 185 ASSERT_EQ(static_cast<int>(urls.size()), new_browser->tab_count());
185 for (size_t i=0; i < urls.size(); i++) { 186 for (size_t i=0; i < urls.size(); i++) {
186 EXPECT_EQ(urls[i], new_browser->GetWebContentsAt(i)->GetURL()); 187 EXPECT_EQ(urls[i], chrome::GetWebContentsAt(new_browser, i)->GetURL());
187 } 188 }
188 189
189 // The two tabs, despite having the same site, should be in different 190 // The two tabs, despite having the same site, should be in different
190 // SiteInstances. 191 // SiteInstances.
191 EXPECT_NE(new_browser->GetWebContentsAt(0)->GetSiteInstance(), 192 EXPECT_NE(chrome::GetWebContentsAt(new_browser, 0)->GetSiteInstance(),
192 new_browser->GetWebContentsAt(1)->GetSiteInstance()); 193 chrome::GetWebContentsAt(new_browser, 1)->GetSiteInstance());
193 } 194 }
194 195
195 // Verify that startup URLs aren't used when the process already exists 196 // Verify that startup URLs aren't used when the process already exists
196 // and has other tabbed browser windows. This is the common case of starting a 197 // and has other tabbed browser windows. This is the common case of starting a
197 // new browser. 198 // new browser.
198 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, 199 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest,
199 StartupURLsOnNewWindow) { 200 StartupURLsOnNewWindow) {
200 // Use a couple arbitrary URLs. 201 // Use a couple arbitrary URLs.
201 std::vector<GURL> urls; 202 std::vector<GURL> urls;
202 urls.push_back(ui_test_utils::GetTestUrl( 203 urls.push_back(ui_test_utils::GetTestUrl(
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 417
417 // urls1 were opened in a browser for default_profile, and urls2 were opened 418 // urls1 were opened in a browser for default_profile, and urls2 were opened
418 // in a browser for other_profile. 419 // in a browser for other_profile.
419 Browser* new_browser = NULL; 420 Browser* new_browser = NULL;
420 // |browser()| is still around at this point, even though we've closed its 421 // |browser()| is still around at this point, even though we've closed its
421 // window. Thus the browser count for default_profile is 2. 422 // window. Thus the browser count for default_profile is 2.
422 ASSERT_EQ(2u, browser::GetBrowserCount(default_profile)); 423 ASSERT_EQ(2u, browser::GetBrowserCount(default_profile));
423 new_browser = FindOneOtherBrowserForProfile(default_profile, browser()); 424 new_browser = FindOneOtherBrowserForProfile(default_profile, browser());
424 ASSERT_TRUE(new_browser); 425 ASSERT_TRUE(new_browser);
425 ASSERT_EQ(1, new_browser->tab_count()); 426 ASSERT_EQ(1, new_browser->tab_count());
426 EXPECT_EQ(urls1[0], new_browser->GetWebContentsAt(0)->GetURL()); 427 EXPECT_EQ(urls1[0], chrome::GetWebContentsAt(new_browser, 0)->GetURL());
427 428
428 ASSERT_EQ(1u, browser::GetBrowserCount(other_profile)); 429 ASSERT_EQ(1u, browser::GetBrowserCount(other_profile));
429 new_browser = FindOneOtherBrowserForProfile(other_profile, NULL); 430 new_browser = FindOneOtherBrowserForProfile(other_profile, NULL);
430 ASSERT_TRUE(new_browser); 431 ASSERT_TRUE(new_browser);
431 ASSERT_EQ(1, new_browser->tab_count()); 432 ASSERT_EQ(1, new_browser->tab_count());
432 EXPECT_EQ(urls2[0], new_browser->GetWebContentsAt(0)->GetURL()); 433 EXPECT_EQ(urls2[0], chrome::GetWebContentsAt(new_browser, 0)->GetURL());
433 } 434 }
434 435
435 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, UpdateWithTwoProfiles) { 436 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, UpdateWithTwoProfiles) {
436 // Make StartupBrowserCreator::WasRestarted() return true. 437 // Make StartupBrowserCreator::WasRestarted() return true.
437 StartupBrowserCreator::was_restarted_read_ = false; 438 StartupBrowserCreator::was_restarted_read_ = false;
438 PrefService* pref_service = g_browser_process->local_state(); 439 PrefService* pref_service = g_browser_process->local_state();
439 pref_service->SetBoolean(prefs::kWasRestarted, true); 440 pref_service->SetBoolean(prefs::kWasRestarted, true);
440 441
441 ProfileManager* profile_manager = g_browser_process->profile_manager(); 442 ProfileManager* profile_manager = g_browser_process->profile_manager();
442 443
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 // restored. 488 // restored.
488 EXPECT_TRUE(profile1->restored_last_session()); 489 EXPECT_TRUE(profile1->restored_last_session());
489 EXPECT_TRUE(profile2->restored_last_session()); 490 EXPECT_TRUE(profile2->restored_last_session());
490 491
491 Browser* new_browser = NULL; 492 Browser* new_browser = NULL;
492 ASSERT_EQ(1u, browser::GetBrowserCount(profile1)); 493 ASSERT_EQ(1u, browser::GetBrowserCount(profile1));
493 new_browser = FindOneOtherBrowserForProfile(profile1, NULL); 494 new_browser = FindOneOtherBrowserForProfile(profile1, NULL);
494 ASSERT_TRUE(new_browser); 495 ASSERT_TRUE(new_browser);
495 ASSERT_EQ(1, new_browser->tab_count()); 496 ASSERT_EQ(1, new_browser->tab_count());
496 EXPECT_EQ(GURL(chrome::kAboutBlankURL), 497 EXPECT_EQ(GURL(chrome::kAboutBlankURL),
497 new_browser->GetWebContentsAt(0)->GetURL()); 498 chrome::GetWebContentsAt(new_browser, 0)->GetURL());
498 499
499 ASSERT_EQ(1u, browser::GetBrowserCount(profile2)); 500 ASSERT_EQ(1u, browser::GetBrowserCount(profile2));
500 new_browser = FindOneOtherBrowserForProfile(profile2, NULL); 501 new_browser = FindOneOtherBrowserForProfile(profile2, NULL);
501 ASSERT_TRUE(new_browser); 502 ASSERT_TRUE(new_browser);
502 ASSERT_EQ(1, new_browser->tab_count()); 503 ASSERT_EQ(1, new_browser->tab_count());
503 EXPECT_EQ(GURL(chrome::kAboutBlankURL), 504 EXPECT_EQ(GURL(chrome::kAboutBlankURL),
504 new_browser->GetWebContentsAt(0)->GetURL()); 505 chrome::GetWebContentsAt(new_browser, 0)->GetURL());
505 } 506 }
506 507
507 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, 508 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest,
508 ProfilesWithoutPagesNotLaunched) { 509 ProfilesWithoutPagesNotLaunched) {
509 Profile* default_profile = browser()->profile(); 510 Profile* default_profile = browser()->profile();
510 511
511 ProfileManager* profile_manager = g_browser_process->profile_manager(); 512 ProfileManager* profile_manager = g_browser_process->profile_manager();
512 513
513 // Create 4 more profiles. 514 // Create 4 more profiles.
514 FilePath dest_path1 = profile_manager->user_data_dir().Append( 515 FilePath dest_path1 = profile_manager->user_data_dir().Append(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 MessageLoop::current()->RunAllPending(); 573 MessageLoop::current()->RunAllPending();
573 574
574 Browser* new_browser = NULL; 575 Browser* new_browser = NULL;
575 // The last open profile (the profile_home1 in this case) will always be 576 // The last open profile (the profile_home1 in this case) will always be
576 // launched, even if it will open just the home page. 577 // launched, even if it will open just the home page.
577 ASSERT_EQ(1u, browser::GetBrowserCount(profile_home1)); 578 ASSERT_EQ(1u, browser::GetBrowserCount(profile_home1));
578 new_browser = FindOneOtherBrowserForProfile(profile_home1, NULL); 579 new_browser = FindOneOtherBrowserForProfile(profile_home1, NULL);
579 ASSERT_TRUE(new_browser); 580 ASSERT_TRUE(new_browser);
580 ASSERT_EQ(1, new_browser->tab_count()); 581 ASSERT_EQ(1, new_browser->tab_count());
581 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), 582 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
582 new_browser->GetWebContentsAt(0)->GetURL()); 583 chrome::GetWebContentsAt(new_browser, 0)->GetURL());
583 584
584 // profile_urls opened the urls. 585 // profile_urls opened the urls.
585 ASSERT_EQ(1u, browser::GetBrowserCount(profile_urls)); 586 ASSERT_EQ(1u, browser::GetBrowserCount(profile_urls));
586 new_browser = FindOneOtherBrowserForProfile(profile_urls, NULL); 587 new_browser = FindOneOtherBrowserForProfile(profile_urls, NULL);
587 ASSERT_TRUE(new_browser); 588 ASSERT_TRUE(new_browser);
588 ASSERT_EQ(1, new_browser->tab_count()); 589 ASSERT_EQ(1, new_browser->tab_count());
589 EXPECT_EQ(urls[0], new_browser->GetWebContentsAt(0)->GetURL()); 590 EXPECT_EQ(urls[0], chrome::GetWebContentsAt(new_browser, 0)->GetURL());
590 591
591 // profile_last opened the last open pages. 592 // profile_last opened the last open pages.
592 ASSERT_EQ(1u, browser::GetBrowserCount(profile_last)); 593 ASSERT_EQ(1u, browser::GetBrowserCount(profile_last));
593 new_browser = FindOneOtherBrowserForProfile(profile_last, NULL); 594 new_browser = FindOneOtherBrowserForProfile(profile_last, NULL);
594 ASSERT_TRUE(new_browser); 595 ASSERT_TRUE(new_browser);
595 ASSERT_EQ(1, new_browser->tab_count()); 596 ASSERT_EQ(1, new_browser->tab_count());
596 EXPECT_EQ(GURL(chrome::kAboutBlankURL), 597 EXPECT_EQ(GURL(chrome::kAboutBlankURL),
597 new_browser->GetWebContentsAt(0)->GetURL()); 598 chrome::GetWebContentsAt(new_browser, 0)->GetURL());
598 599
599 // profile_home2 was not launched since it would've only opened the home page. 600 // profile_home2 was not launched since it would've only opened the home page.
600 ASSERT_EQ(0u, browser::GetBrowserCount(profile_home2)); 601 ASSERT_EQ(0u, browser::GetBrowserCount(profile_home2));
601 } 602 }
602 603
603 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, ProfilesLaunchedAfterCrash) { 604 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, ProfilesLaunchedAfterCrash) {
604 // After an unclean exit, all profiles will be launched. However, they won't 605 // After an unclean exit, all profiles will be launched. However, they won't
605 // open any pages automatically. 606 // open any pages automatically.
606 607
607 ProfileManager* profile_manager = g_browser_process->profile_manager(); 608 ProfileManager* profile_manager = g_browser_process->profile_manager();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 EXPECT_FALSE(SessionRestore::IsRestoring(profile_last)); 660 EXPECT_FALSE(SessionRestore::IsRestoring(profile_last));
660 EXPECT_FALSE(SessionRestore::IsRestoring(profile_urls)); 661 EXPECT_FALSE(SessionRestore::IsRestoring(profile_urls));
661 662
662 // The profile which normally opens the home page displays the new tab page. 663 // The profile which normally opens the home page displays the new tab page.
663 Browser* new_browser = NULL; 664 Browser* new_browser = NULL;
664 ASSERT_EQ(1u, browser::GetBrowserCount(profile_home)); 665 ASSERT_EQ(1u, browser::GetBrowserCount(profile_home));
665 new_browser = FindOneOtherBrowserForProfile(profile_home, NULL); 666 new_browser = FindOneOtherBrowserForProfile(profile_home, NULL);
666 ASSERT_TRUE(new_browser); 667 ASSERT_TRUE(new_browser);
667 ASSERT_EQ(1, new_browser->tab_count()); 668 ASSERT_EQ(1, new_browser->tab_count());
668 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), 669 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
669 new_browser->GetWebContentsAt(0)->GetURL()); 670 chrome::GetWebContentsAt(new_browser, 0)->GetURL());
670 EXPECT_EQ(1U, new_browser->GetTabContentsAt(0)->infobar_tab_helper()-> 671 EXPECT_EQ(1U, chrome::GetTabContentsAt(new_browser, 0)->infobar_tab_helper()->
671 infobar_count()); 672 infobar_count());
672 673
673 // The profile which normally opens last open pages displays the new tab page. 674 // The profile which normally opens last open pages displays the new tab page.
674 ASSERT_EQ(1u, browser::GetBrowserCount(profile_last)); 675 ASSERT_EQ(1u, browser::GetBrowserCount(profile_last));
675 new_browser = FindOneOtherBrowserForProfile(profile_last, NULL); 676 new_browser = FindOneOtherBrowserForProfile(profile_last, NULL);
676 ASSERT_TRUE(new_browser); 677 ASSERT_TRUE(new_browser);
677 ASSERT_EQ(1, new_browser->tab_count()); 678 ASSERT_EQ(1, new_browser->tab_count());
678 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), 679 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
679 new_browser->GetWebContentsAt(0)->GetURL()); 680 chrome::GetWebContentsAt(new_browser, 0)->GetURL());
680 EXPECT_EQ(1U, new_browser->GetTabContentsAt(0)->infobar_tab_helper()-> 681 EXPECT_EQ(1U, chrome::GetTabContentsAt(new_browser, 0)->infobar_tab_helper()->
681 infobar_count()); 682 infobar_count());
682 683
683 // The profile which normally opens URLs displays the new tab page. 684 // The profile which normally opens URLs displays the new tab page.
684 ASSERT_EQ(1u, browser::GetBrowserCount(profile_urls)); 685 ASSERT_EQ(1u, browser::GetBrowserCount(profile_urls));
685 new_browser = FindOneOtherBrowserForProfile(profile_urls, NULL); 686 new_browser = FindOneOtherBrowserForProfile(profile_urls, NULL);
686 ASSERT_TRUE(new_browser); 687 ASSERT_TRUE(new_browser);
687 ASSERT_EQ(1, new_browser->tab_count()); 688 ASSERT_EQ(1, new_browser->tab_count());
688 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), 689 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
689 new_browser->GetWebContentsAt(0)->GetURL()); 690 chrome::GetWebContentsAt(new_browser, 0)->GetURL());
690 EXPECT_EQ(1U, new_browser->GetTabContentsAt(0)->infobar_tab_helper()-> 691 EXPECT_EQ(1U, chrome::GetTabContentsAt(new_browser, 0)->infobar_tab_helper()->
691 infobar_count()); 692 infobar_count());
692 } 693 }
693 #endif // !OS_CHROMEOS 694 #endif // !OS_CHROMEOS
OLDNEW
« no previous file with comments | « chrome/browser/ui/startup/session_crashed_prompt.cc ('k') | chrome/browser/ui/startup/startup_browser_creator_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698