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

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

Issue 1228723002: Extract duplicated code in browser_tests for closing a browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/WithoutWaiting/Asynchronously Created 5 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
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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 std::vector<GURL> urls; 210 std::vector<GURL> urls;
211 urls.push_back(test_server()->GetURL("files/title1.html")); 211 urls.push_back(test_server()->GetURL("files/title1.html"));
212 urls.push_back(test_server()->GetURL("files/title2.html")); 212 urls.push_back(test_server()->GetURL("files/title2.html"));
213 213
214 // Set the startup preference to open these URLs. 214 // Set the startup preference to open these URLs.
215 SessionStartupPref pref(SessionStartupPref::URLS); 215 SessionStartupPref pref(SessionStartupPref::URLS);
216 pref.urls = urls; 216 pref.urls = urls;
217 SessionStartupPref::SetStartupPref(browser()->profile(), pref); 217 SessionStartupPref::SetStartupPref(browser()->profile(), pref);
218 218
219 // Close the browser. 219 // Close the browser.
220 browser()->window()->Close(); 220 CloseBrowserAsynchronously(browser());
221 221
222 // Do a simple non-process-startup browser launch. 222 // Do a simple non-process-startup browser launch.
223 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); 223 base::CommandLine dummy(base::CommandLine::NO_PROGRAM);
224 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? 224 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
225 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; 225 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
226 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); 226 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
227 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, 227 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
228 browser()->host_desktop_type())); 228 browser()->host_desktop_type()));
229 229
230 // This should have created a new browser window. |browser()| is still 230 // This should have created a new browser window. |browser()| is still
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 625
626 // Set different startup preferences for the 2 profiles. 626 // Set different startup preferences for the 2 profiles.
627 SessionStartupPref pref1(SessionStartupPref::URLS); 627 SessionStartupPref pref1(SessionStartupPref::URLS);
628 pref1.urls = urls1; 628 pref1.urls = urls1;
629 SessionStartupPref::SetStartupPref(default_profile, pref1); 629 SessionStartupPref::SetStartupPref(default_profile, pref1);
630 SessionStartupPref pref2(SessionStartupPref::URLS); 630 SessionStartupPref pref2(SessionStartupPref::URLS);
631 pref2.urls = urls2; 631 pref2.urls = urls2;
632 SessionStartupPref::SetStartupPref(other_profile, pref2); 632 SessionStartupPref::SetStartupPref(other_profile, pref2);
633 633
634 // Close the browser. 634 // Close the browser.
635 browser()->window()->Close(); 635 CloseBrowserAsynchronously(browser());
636 636
637 // Do a simple non-process-startup browser launch. 637 // Do a simple non-process-startup browser launch.
638 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); 638 base::CommandLine dummy(base::CommandLine::NO_PROGRAM);
639 639
640 StartupBrowserCreator browser_creator; 640 StartupBrowserCreator browser_creator;
641 std::vector<Profile*> last_opened_profiles; 641 std::vector<Profile*> last_opened_profiles;
642 last_opened_profiles.push_back(default_profile); 642 last_opened_profiles.push_back(default_profile);
643 last_opened_profiles.push_back(other_profile); 643 last_opened_profiles.push_back(other_profile);
644 browser_creator.Start(dummy, profile_manager->user_data_dir(), 644 browser_creator.Start(dummy, profile_manager->user_data_dir(),
645 default_profile, last_opened_profiles); 645 default_profile, last_opened_profiles);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 dest_path.Append(FILE_PATH_LITERAL("New Profile 2"))); 683 dest_path.Append(FILE_PATH_LITERAL("New Profile 2")));
684 ASSERT_TRUE(profile2); 684 ASSERT_TRUE(profile2);
685 685
686 // Open some urls with the browsers, and close them. 686 // Open some urls with the browsers, and close them.
687 Browser* browser1 = new Browser( 687 Browser* browser1 = new Browser(
688 Browser::CreateParams(Browser::TYPE_TABBED, profile1, 688 Browser::CreateParams(Browser::TYPE_TABBED, profile1,
689 browser()->host_desktop_type())); 689 browser()->host_desktop_type()));
690 chrome::NewTab(browser1); 690 chrome::NewTab(browser1);
691 ui_test_utils::NavigateToURL(browser1, 691 ui_test_utils::NavigateToURL(browser1,
692 test_server()->GetURL("files/empty.html")); 692 test_server()->GetURL("files/empty.html"));
693 browser1->window()->Close(); 693 CloseBrowserSynchronously(browser1);
694 694
695 Browser* browser2 = new Browser( 695 Browser* browser2 = new Browser(
696 Browser::CreateParams(Browser::TYPE_TABBED, profile2, 696 Browser::CreateParams(Browser::TYPE_TABBED, profile2,
697 browser()->host_desktop_type())); 697 browser()->host_desktop_type()));
698 chrome::NewTab(browser2); 698 chrome::NewTab(browser2);
699 ui_test_utils::NavigateToURL(browser2, 699 ui_test_utils::NavigateToURL(browser2,
700 test_server()->GetURL("files/form.html")); 700 test_server()->GetURL("files/form.html"));
701 browser2->window()->Close(); 701 CloseBrowserSynchronously(browser2);
702 702
703 // Set different startup preferences for the 2 profiles. 703 // Set different startup preferences for the 2 profiles.
704 std::vector<GURL> urls1; 704 std::vector<GURL> urls1;
705 urls1.push_back(ui_test_utils::GetTestUrl( 705 urls1.push_back(ui_test_utils::GetTestUrl(
706 base::FilePath(base::FilePath::kCurrentDirectory), 706 base::FilePath(base::FilePath::kCurrentDirectory),
707 base::FilePath(FILE_PATH_LITERAL("title1.html")))); 707 base::FilePath(FILE_PATH_LITERAL("title1.html"))));
708 std::vector<GURL> urls2; 708 std::vector<GURL> urls2;
709 urls2.push_back(ui_test_utils::GetTestUrl( 709 urls2.push_back(ui_test_utils::GetTestUrl(
710 base::FilePath(base::FilePath::kCurrentDirectory), 710 base::FilePath(base::FilePath::kCurrentDirectory),
711 base::FilePath(FILE_PATH_LITERAL("title2.html")))); 711 base::FilePath(FILE_PATH_LITERAL("title2.html"))));
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 pref_urls.urls = urls; 839 pref_urls.urls = urls;
840 SessionStartupPref::SetStartupPref(profile_urls, pref_urls); 840 SessionStartupPref::SetStartupPref(profile_urls, pref_urls);
841 841
842 // Open a page with profile_last. 842 // Open a page with profile_last.
843 Browser* browser_last = new Browser( 843 Browser* browser_last = new Browser(
844 Browser::CreateParams(Browser::TYPE_TABBED, profile_last, 844 Browser::CreateParams(Browser::TYPE_TABBED, profile_last,
845 browser()->host_desktop_type())); 845 browser()->host_desktop_type()));
846 chrome::NewTab(browser_last); 846 chrome::NewTab(browser_last);
847 ui_test_utils::NavigateToURL(browser_last, 847 ui_test_utils::NavigateToURL(browser_last,
848 test_server()->GetURL("files/empty.html")); 848 test_server()->GetURL("files/empty.html"));
849 browser_last->window()->Close(); 849 CloseBrowserAsynchronously(browser_last);
850 850
851 // Close the main browser. 851 // Close the main browser.
852 chrome::HostDesktopType original_desktop_type = 852 chrome::HostDesktopType original_desktop_type =
853 browser()->host_desktop_type(); 853 browser()->host_desktop_type();
854 browser()->window()->Close(); 854 CloseBrowserAsynchronously(browser());
855 855
856 // Do a simple non-process-startup browser launch. 856 // Do a simple non-process-startup browser launch.
857 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); 857 base::CommandLine dummy(base::CommandLine::NO_PROGRAM);
858 858
859 StartupBrowserCreator browser_creator; 859 StartupBrowserCreator browser_creator;
860 std::vector<Profile*> last_opened_profiles; 860 std::vector<Profile*> last_opened_profiles;
861 last_opened_profiles.push_back(profile_home1); 861 last_opened_profiles.push_back(profile_home1);
862 last_opened_profiles.push_back(profile_home2); 862 last_opened_profiles.push_back(profile_home2);
863 last_opened_profiles.push_back(profile_last); 863 last_opened_profiles.push_back(profile_last);
864 last_opened_profiles.push_back(profile_urls); 864 last_opened_profiles.push_back(profile_urls);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 std::vector<GURL> urls; 942 std::vector<GURL> urls;
943 urls.push_back(ui_test_utils::GetTestUrl( 943 urls.push_back(ui_test_utils::GetTestUrl(
944 base::FilePath(base::FilePath::kCurrentDirectory), 944 base::FilePath(base::FilePath::kCurrentDirectory),
945 base::FilePath(FILE_PATH_LITERAL("title1.html")))); 945 base::FilePath(FILE_PATH_LITERAL("title1.html"))));
946 946
947 SessionStartupPref pref_urls(SessionStartupPref::URLS); 947 SessionStartupPref pref_urls(SessionStartupPref::URLS);
948 pref_urls.urls = urls; 948 pref_urls.urls = urls;
949 SessionStartupPref::SetStartupPref(profile_urls, pref_urls); 949 SessionStartupPref::SetStartupPref(profile_urls, pref_urls);
950 950
951 // Simulate a launch after an unclear exit. 951 // Simulate a launch after an unclear exit.
952 browser()->window()->Close(); 952 CloseBrowserAsynchronously(browser());
953 static_cast<ProfileImpl*>(profile_home)->last_session_exit_type_ = 953 static_cast<ProfileImpl*>(profile_home)->last_session_exit_type_ =
954 Profile::EXIT_CRASHED; 954 Profile::EXIT_CRASHED;
955 static_cast<ProfileImpl*>(profile_last)->last_session_exit_type_ = 955 static_cast<ProfileImpl*>(profile_last)->last_session_exit_type_ =
956 Profile::EXIT_CRASHED; 956 Profile::EXIT_CRASHED;
957 static_cast<ProfileImpl*>(profile_urls)->last_session_exit_type_ = 957 static_cast<ProfileImpl*>(profile_urls)->last_session_exit_type_ =
958 Profile::EXIT_CRASHED; 958 Profile::EXIT_CRASHED;
959 959
960 #if !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD) 960 #if !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD)
961 // Use HistogramTester to make sure a bubble is shown when it's not on 961 // Use HistogramTester to make sure a bubble is shown when it's not on
962 // platform Mac OS X and it's not official Chrome build. 962 // platform Mac OS X and it's not official Chrome build.
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 ASSERT_EQ(1, tab_strip->count()); 1466 ASSERT_EQ(1, tab_strip->count());
1467 EXPECT_EQ("title1.html", 1467 EXPECT_EQ("title1.html",
1468 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); 1468 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName());
1469 } 1469 }
1470 #endif // defined(ENABLE_CONFIGURATION_POLICY) 1470 #endif // defined(ENABLE_CONFIGURATION_POLICY)
1471 1471
1472 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) || 1472 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) ||
1473 // defined(ENABLE_CONFIGURATION_POLICY) 1473 // defined(ENABLE_CONFIGURATION_POLICY)
1474 1474
1475 #endif // !defined(OS_CHROMEOS) 1475 #endif // !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « chrome/browser/ui/settings_window_manager_browsertest.cc ('k') | chrome/test/base/in_process_browser_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698