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

Side by Side Diff: chrome/browser/lifetime/browser_close_manager_browsertest.cc

Issue 274273003: Create a temp download direcgtory for BrowserCloseManagerBrowserTests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits. Created 6 years, 7 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <vector> 5 #include <vector>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/scoped_temp_dir.h"
8 #include "chrome/browser/background/background_mode_manager.h" 9 #include "chrome/browser/background/background_mode_manager.h"
9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/browser_shutdown.h" 11 #include "chrome/browser/browser_shutdown.h"
11 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/defaults.h" 13 #include "chrome/browser/defaults.h"
13 #include "chrome/browser/download/chrome_download_manager_delegate.h" 14 #include "chrome/browser/download/chrome_download_manager_delegate.h"
15 #include "chrome/browser/download/download_prefs.h"
14 #include "chrome/browser/download/download_service.h" 16 #include "chrome/browser/download/download_service.h"
15 #include "chrome/browser/download/download_service_factory.h" 17 #include "chrome/browser/download/download_service_factory.h"
16 #include "chrome/browser/lifetime/application_lifetime.h" 18 #include "chrome/browser/lifetime/application_lifetime.h"
17 #include "chrome/browser/lifetime/browser_close_manager.h" 19 #include "chrome/browser/lifetime/browser_close_manager.h"
18 #include "chrome/browser/net/url_request_mock_util.h" 20 #include "chrome/browser/net/url_request_mock_util.h"
19 #include "chrome/browser/prefs/session_startup_pref.h" 21 #include "chrome/browser/prefs/session_startup_pref.h"
20 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/profiles/profile_manager.h" 23 #include "chrome/browser/profiles/profile_manager.h"
22 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" 24 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h"
23 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" 25 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h"
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 chrome::CloseAllBrowsersAndQuit(); 687 chrome::CloseAllBrowsersAndQuit();
686 ASSERT_FALSE(browsers_[0]->ShouldCloseWindow()); 688 ASSERT_FALSE(browsers_[0]->ShouldCloseWindow());
687 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); 689 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
688 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); 690 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
689 691
690 close_observer.Wait(); 692 close_observer.Wait();
691 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); 693 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
692 EXPECT_TRUE(chrome::BrowserIterator().done()); 694 EXPECT_TRUE(chrome::BrowserIterator().done());
693 } 695 }
694 696
697 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerBrowserTest,
698 BrowserCloseManagerBrowserTest,
699 testing::Bool());
700
701 class BrowserCloseManagerWithDownloadsBrowserTest :
702 public BrowserCloseManagerBrowserTest {
703 public:
704 BrowserCloseManagerWithDownloadsBrowserTest() {}
705 virtual ~BrowserCloseManagerWithDownloadsBrowserTest() {}
706
707 virtual void SetUpOnMainThread() OVERRIDE {
708 BrowserCloseManagerBrowserTest::SetUpOnMainThread();
709 ASSERT_TRUE(scoped_download_directory_.CreateUniqueTempDir());
710 }
711
712 void SetDownloadPathForProfile(Profile* profile) {
713 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(profile);
714 download_prefs->SetDownloadPath(download_path());
715 }
716
717 const base::FilePath& download_path() const {
718 return scoped_download_directory_.path();
719 }
720
721 private:
722 base::ScopedTempDir scoped_download_directory_;
723 };
724
695 // Test shutdown with a DANGEROUS_URL download undecided. 725 // Test shutdown with a DANGEROUS_URL download undecided.
696 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, 726 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest,
697 TestWithDangerousUrlDownload) { 727 TestWithDangerousUrlDownload) {
698 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 728 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
729 SetDownloadPathForProfile(browser()->profile());
699 730
700 // Set up the fake delegate that forces the download to be malicious. 731 // Set up the fake delegate that forces the download to be malicious.
701 scoped_ptr<TestDownloadManagerDelegate> test_delegate( 732 scoped_ptr<TestDownloadManagerDelegate> test_delegate(
702 new TestDownloadManagerDelegate(browser()->profile())); 733 new TestDownloadManagerDelegate(browser()->profile()));
703 DownloadServiceFactory::GetForBrowserContext(browser()->profile())-> 734 DownloadServiceFactory::GetForBrowserContext(browser()->profile())->
704 SetDownloadManagerDelegateForTesting( 735 SetDownloadManagerDelegateForTesting(
705 test_delegate.PassAs<ChromeDownloadManagerDelegate>()); 736 test_delegate.PassAs<ChromeDownloadManagerDelegate>());
706 737
707 // Run a dangerous download, but the user doesn't make a decision. 738 // Run a dangerous download, but the user doesn't make a decision.
708 // This .swf normally would be categorized as DANGEROUS_FILE, but 739 // This .swf normally would be categorized as DANGEROUS_FILE, but
(...skipping 21 matching lines...) Expand all
730 RepeatedNotificationObserver close_observer( 761 RepeatedNotificationObserver close_observer(
731 chrome::NOTIFICATION_BROWSER_CLOSED, 1); 762 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
732 TestBrowserCloseManager::AttemptClose( 763 TestBrowserCloseManager::AttemptClose(
733 TestBrowserCloseManager::NO_USER_CHOICE); 764 TestBrowserCloseManager::NO_USER_CHOICE);
734 close_observer.Wait(); 765 close_observer.Wait();
735 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); 766 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
736 EXPECT_TRUE(chrome::BrowserIterator().done()); 767 EXPECT_TRUE(chrome::BrowserIterator().done());
737 } 768 }
738 769
739 // Test shutdown with a download in progress. 770 // Test shutdown with a download in progress.
740 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, TestWithDownloads) { 771 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest,
772 TestWithDownloads) {
741 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 773 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
774 SetDownloadPathForProfile(browser()->profile());
742 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); 775 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser()));
743 content::TestNavigationObserver navigation_observer( 776 content::TestNavigationObserver navigation_observer(
744 browser()->tab_strip_model()->GetActiveWebContents(), 1); 777 browser()->tab_strip_model()->GetActiveWebContents(), 1);
745 TestBrowserCloseManager::AttemptClose( 778 TestBrowserCloseManager::AttemptClose(
746 TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); 779 TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE);
747 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); 780 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
748 navigation_observer.Wait(); 781 navigation_observer.Wait();
749 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL), 782 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
750 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 783 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
751 784
752 RepeatedNotificationObserver close_observer( 785 RepeatedNotificationObserver close_observer(
753 chrome::NOTIFICATION_BROWSER_CLOSED, 1); 786 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
754 787
755 TestBrowserCloseManager::AttemptClose( 788 TestBrowserCloseManager::AttemptClose(
756 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); 789 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE);
757 close_observer.Wait(); 790 close_observer.Wait();
758 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); 791 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
759 EXPECT_TRUE(chrome::BrowserIterator().done()); 792 EXPECT_TRUE(chrome::BrowserIterator().done());
760 if (browser_defaults::kBrowserAliveWithNoWindows) 793 if (browser_defaults::kBrowserAliveWithNoWindows)
761 EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles()); 794 EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles());
762 else 795 else
763 EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles()); 796 EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles());
764 } 797 }
765 798
766 // Test shutdown with a download in progress from one profile, where the only 799 // Test shutdown with a download in progress from one profile, where the only
767 // open windows are for another profile. 800 // open windows are for another profile.
768 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, 801 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest,
769 TestWithDownloadsFromDifferentProfiles) { 802 TestWithDownloadsFromDifferentProfiles) {
770 ProfileManager* profile_manager = g_browser_process->profile_manager(); 803 ProfileManager* profile_manager = g_browser_process->profile_manager();
771 base::FilePath path = 804 base::FilePath path =
772 profile_manager->user_data_dir().AppendASCII("test_profile"); 805 profile_manager->user_data_dir().AppendASCII("test_profile");
773 if (!base::PathExists(path)) 806 if (!base::PathExists(path))
774 ASSERT_TRUE(base::CreateDirectory(path)); 807 ASSERT_TRUE(base::CreateDirectory(path));
775 Profile* other_profile = 808 Profile* other_profile =
776 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); 809 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS);
777 profile_manager->RegisterTestingProfile(other_profile, true, false); 810 profile_manager->RegisterTestingProfile(other_profile, true, false);
778 Browser* other_profile_browser = CreateBrowser(other_profile); 811 Browser* other_profile_browser = CreateBrowser(other_profile);
779 812
780 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 813 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
814 SetDownloadPathForProfile(browser()->profile());
815 SetDownloadPathForProfile(other_profile);
781 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); 816 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser()));
782 { 817 {
783 RepeatedNotificationObserver close_observer( 818 RepeatedNotificationObserver close_observer(
784 chrome::NOTIFICATION_BROWSER_CLOSED, 1); 819 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
785 browser()->window()->Close(); 820 browser()->window()->Close();
786 close_observer.Wait(); 821 close_observer.Wait();
787 } 822 }
788 823
789 // When the shutdown is cancelled, the downloads page should be opened in a 824 // When the shutdown is cancelled, the downloads page should be opened in a
790 // browser for that profile. Because there are no browsers for that profile, a 825 // browser for that profile. Because there are no browsers for that profile, a
(...skipping 18 matching lines...) Expand all
809 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); 844 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
810 EXPECT_TRUE(chrome::BrowserIterator().done()); 845 EXPECT_TRUE(chrome::BrowserIterator().done());
811 if (browser_defaults::kBrowserAliveWithNoWindows) 846 if (browser_defaults::kBrowserAliveWithNoWindows)
812 EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles()); 847 EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles());
813 else 848 else
814 EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles()); 849 EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles());
815 } 850 }
816 851
817 // Test shutdown with downloads in progress and beforeunload handlers. 852 // Test shutdown with downloads in progress and beforeunload handlers.
818 // Disabled, see http://crbug.com/315754. 853 // Disabled, see http://crbug.com/315754.
819 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, 854 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest,
820 DISABLED_TestBeforeUnloadAndDownloads) { 855 DISABLED_TestBeforeUnloadAndDownloads) {
821 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 856 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
857 SetDownloadPathForProfile(browser()->profile());
822 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); 858 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser()));
823 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( 859 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(
824 browser(), embedded_test_server()->GetURL("/beforeunload.html"))); 860 browser(), embedded_test_server()->GetURL("/beforeunload.html")));
825 861
826 content::WindowedNotificationObserver cancel_observer( 862 content::WindowedNotificationObserver cancel_observer(
827 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 863 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
828 content::NotificationService::AllSources()); 864 content::NotificationService::AllSources());
829 TestBrowserCloseManager::AttemptClose( 865 TestBrowserCloseManager::AttemptClose(
830 TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); 866 TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE);
831 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); 867 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
832 cancel_observer.Wait(); 868 cancel_observer.Wait();
833 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); 869 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
834 870
835 RepeatedNotificationObserver close_observer( 871 RepeatedNotificationObserver close_observer(
836 chrome::NOTIFICATION_BROWSER_CLOSED, 1); 872 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
837 TestBrowserCloseManager::AttemptClose( 873 TestBrowserCloseManager::AttemptClose(
838 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); 874 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE);
839 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); 875 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
840 close_observer.Wait(); 876 close_observer.Wait();
841 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); 877 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
842 EXPECT_TRUE(chrome::BrowserIterator().done()); 878 EXPECT_TRUE(chrome::BrowserIterator().done());
843 } 879 }
844 880
845 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerBrowserTest, 881 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithDownloadsBrowserTest,
846 BrowserCloseManagerBrowserTest, 882 BrowserCloseManagerWithDownloadsBrowserTest,
847 testing::Bool()); 883 testing::Bool());
848 884
849 class BrowserCloseManagerWithBackgroundModeBrowserTest 885 class BrowserCloseManagerWithBackgroundModeBrowserTest
850 : public BrowserCloseManagerBrowserTest { 886 : public BrowserCloseManagerBrowserTest {
851 public: 887 public:
852 BrowserCloseManagerWithBackgroundModeBrowserTest() {} 888 BrowserCloseManagerWithBackgroundModeBrowserTest() {}
853 889
854 virtual void SetUpOnMainThread() OVERRIDE { 890 virtual void SetUpOnMainThread() OVERRIDE {
855 BrowserCloseManagerBrowserTest::SetUpOnMainThread(); 891 BrowserCloseManagerBrowserTest::SetUpOnMainThread();
856 g_browser_process->set_background_mode_manager_for_test( 892 g_browser_process->set_background_mode_manager_for_test(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 969
934 chrome::CloseAllBrowsers(); 970 chrome::CloseAllBrowsers();
935 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); 971 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
936 EXPECT_TRUE(chrome::BrowserIterator().done()); 972 EXPECT_TRUE(chrome::BrowserIterator().done());
937 EXPECT_TRUE(IsBackgroundModeSuspended()); 973 EXPECT_TRUE(IsBackgroundModeSuspended());
938 } 974 }
939 975
940 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, 976 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest,
941 BrowserCloseManagerWithBackgroundModeBrowserTest, 977 BrowserCloseManagerWithBackgroundModeBrowserTest,
942 testing::Bool()); 978 testing::Bool());
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698