OLD | NEW |
---|---|
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 Loading... | |
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 BrowserCloseManagerBrowserTestWithDownloads : | |
James Cook
2014/05/10 04:23:18
nit: I would call this BrowserCloseManagerWithDown
asanka
2014/05/10 04:32:27
Done.
| |
702 public BrowserCloseManagerBrowserTest { | |
703 public: | |
704 virtual void SetUpOnMainThread() OVERRIDE { | |
James Cook
2014/05/10 04:23:18
nit: maybe add BrowserCloseManagerWithDownloadsBro
asanka
2014/05/10 04:32:27
Done.
| |
705 BrowserCloseManagerBrowserTest::SetUpOnMainThread(); | |
706 ASSERT_TRUE(scoped_download_directory_.CreateUniqueTempDir()); | |
707 } | |
708 | |
709 void SetDownloadPathForProfile(Profile* profile) { | |
710 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(profile); | |
711 download_prefs->SetDownloadPath(download_path()); | |
712 } | |
713 | |
714 const base::FilePath& download_path() const { | |
715 return scoped_download_directory_.path(); | |
716 } | |
717 | |
718 private: | |
719 base::ScopedTempDir scoped_download_directory_; | |
720 }; | |
721 | |
695 // Test shutdown with a DANGEROUS_URL download undecided. | 722 // Test shutdown with a DANGEROUS_URL download undecided. |
696 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, | 723 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTestWithDownloads, |
697 TestWithDangerousUrlDownload) { | 724 TestWithDangerousUrlDownload) { |
698 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 725 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
726 SetDownloadPathForProfile(browser()->profile()); | |
699 | 727 |
700 // Set up the fake delegate that forces the download to be malicious. | 728 // Set up the fake delegate that forces the download to be malicious. |
701 scoped_ptr<TestDownloadManagerDelegate> test_delegate( | 729 scoped_ptr<TestDownloadManagerDelegate> test_delegate( |
702 new TestDownloadManagerDelegate(browser()->profile())); | 730 new TestDownloadManagerDelegate(browser()->profile())); |
703 DownloadServiceFactory::GetForBrowserContext(browser()->profile())-> | 731 DownloadServiceFactory::GetForBrowserContext(browser()->profile())-> |
704 SetDownloadManagerDelegateForTesting( | 732 SetDownloadManagerDelegateForTesting( |
705 test_delegate.PassAs<ChromeDownloadManagerDelegate>()); | 733 test_delegate.PassAs<ChromeDownloadManagerDelegate>()); |
706 | 734 |
707 // Run a dangerous download, but the user doesn't make a decision. | 735 // Run a dangerous download, but the user doesn't make a decision. |
708 // This .swf normally would be categorized as DANGEROUS_FILE, but | 736 // This .swf normally would be categorized as DANGEROUS_FILE, but |
(...skipping 21 matching lines...) Expand all Loading... | |
730 RepeatedNotificationObserver close_observer( | 758 RepeatedNotificationObserver close_observer( |
731 chrome::NOTIFICATION_BROWSER_CLOSED, 1); | 759 chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
732 TestBrowserCloseManager::AttemptClose( | 760 TestBrowserCloseManager::AttemptClose( |
733 TestBrowserCloseManager::NO_USER_CHOICE); | 761 TestBrowserCloseManager::NO_USER_CHOICE); |
734 close_observer.Wait(); | 762 close_observer.Wait(); |
735 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | 763 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
736 EXPECT_TRUE(chrome::BrowserIterator().done()); | 764 EXPECT_TRUE(chrome::BrowserIterator().done()); |
737 } | 765 } |
738 | 766 |
739 // Test shutdown with a download in progress. | 767 // Test shutdown with a download in progress. |
740 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, TestWithDownloads) { | 768 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTestWithDownloads, |
769 TestWithDownloads) { | |
741 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 770 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
771 SetDownloadPathForProfile(browser()->profile()); | |
742 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); | 772 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); |
743 content::TestNavigationObserver navigation_observer( | 773 content::TestNavigationObserver navigation_observer( |
744 browser()->tab_strip_model()->GetActiveWebContents(), 1); | 774 browser()->tab_strip_model()->GetActiveWebContents(), 1); |
745 TestBrowserCloseManager::AttemptClose( | 775 TestBrowserCloseManager::AttemptClose( |
746 TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); | 776 TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); |
747 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); | 777 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
748 navigation_observer.Wait(); | 778 navigation_observer.Wait(); |
749 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL), | 779 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL), |
750 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); | 780 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); |
751 | 781 |
752 RepeatedNotificationObserver close_observer( | 782 RepeatedNotificationObserver close_observer( |
753 chrome::NOTIFICATION_BROWSER_CLOSED, 1); | 783 chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
754 | 784 |
755 TestBrowserCloseManager::AttemptClose( | 785 TestBrowserCloseManager::AttemptClose( |
756 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); | 786 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); |
757 close_observer.Wait(); | 787 close_observer.Wait(); |
758 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | 788 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
759 EXPECT_TRUE(chrome::BrowserIterator().done()); | 789 EXPECT_TRUE(chrome::BrowserIterator().done()); |
760 if (browser_defaults::kBrowserAliveWithNoWindows) | 790 if (browser_defaults::kBrowserAliveWithNoWindows) |
761 EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles()); | 791 EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles()); |
762 else | 792 else |
763 EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles()); | 793 EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles()); |
764 } | 794 } |
765 | 795 |
766 // Test shutdown with a download in progress from one profile, where the only | 796 // Test shutdown with a download in progress from one profile, where the only |
767 // open windows are for another profile. | 797 // open windows are for another profile. |
768 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, | 798 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTestWithDownloads, |
769 TestWithDownloadsFromDifferentProfiles) { | 799 TestWithDownloadsFromDifferentProfiles) { |
770 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 800 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
771 base::FilePath path = | 801 base::FilePath path = |
772 profile_manager->user_data_dir().AppendASCII("test_profile"); | 802 profile_manager->user_data_dir().AppendASCII("test_profile"); |
773 if (!base::PathExists(path)) | 803 if (!base::PathExists(path)) |
774 ASSERT_TRUE(base::CreateDirectory(path)); | 804 ASSERT_TRUE(base::CreateDirectory(path)); |
775 Profile* other_profile = | 805 Profile* other_profile = |
776 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); | 806 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); |
777 profile_manager->RegisterTestingProfile(other_profile, true, false); | 807 profile_manager->RegisterTestingProfile(other_profile, true, false); |
778 Browser* other_profile_browser = CreateBrowser(other_profile); | 808 Browser* other_profile_browser = CreateBrowser(other_profile); |
779 | 809 |
780 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 810 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
811 SetDownloadPathForProfile(browser()->profile()); | |
812 SetDownloadPathForProfile(other_profile); | |
781 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); | 813 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); |
782 { | 814 { |
783 RepeatedNotificationObserver close_observer( | 815 RepeatedNotificationObserver close_observer( |
784 chrome::NOTIFICATION_BROWSER_CLOSED, 1); | 816 chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
785 browser()->window()->Close(); | 817 browser()->window()->Close(); |
786 close_observer.Wait(); | 818 close_observer.Wait(); |
787 } | 819 } |
788 | 820 |
789 // When the shutdown is cancelled, the downloads page should be opened in a | 821 // 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 | 822 // browser for that profile. Because there are no browsers for that profile, a |
(...skipping 18 matching lines...) Expand all Loading... | |
809 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | 841 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
810 EXPECT_TRUE(chrome::BrowserIterator().done()); | 842 EXPECT_TRUE(chrome::BrowserIterator().done()); |
811 if (browser_defaults::kBrowserAliveWithNoWindows) | 843 if (browser_defaults::kBrowserAliveWithNoWindows) |
812 EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles()); | 844 EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles()); |
813 else | 845 else |
814 EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles()); | 846 EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles()); |
815 } | 847 } |
816 | 848 |
817 // Test shutdown with downloads in progress and beforeunload handlers. | 849 // Test shutdown with downloads in progress and beforeunload handlers. |
818 // Disabled, see http://crbug.com/315754. | 850 // Disabled, see http://crbug.com/315754. |
819 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, | 851 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTestWithDownloads, |
820 DISABLED_TestBeforeUnloadAndDownloads) { | 852 DISABLED_TestBeforeUnloadAndDownloads) { |
821 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 853 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
854 SetDownloadPathForProfile(browser()->profile()); | |
822 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); | 855 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); |
823 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( | 856 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
824 browser(), embedded_test_server()->GetURL("/beforeunload.html"))); | 857 browser(), embedded_test_server()->GetURL("/beforeunload.html"))); |
825 | 858 |
826 content::WindowedNotificationObserver cancel_observer( | 859 content::WindowedNotificationObserver cancel_observer( |
827 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, | 860 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, |
828 content::NotificationService::AllSources()); | 861 content::NotificationService::AllSources()); |
829 TestBrowserCloseManager::AttemptClose( | 862 TestBrowserCloseManager::AttemptClose( |
830 TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); | 863 TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); |
831 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); | 864 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
832 cancel_observer.Wait(); | 865 cancel_observer.Wait(); |
833 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); | 866 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
834 | 867 |
835 RepeatedNotificationObserver close_observer( | 868 RepeatedNotificationObserver close_observer( |
836 chrome::NOTIFICATION_BROWSER_CLOSED, 1); | 869 chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
837 TestBrowserCloseManager::AttemptClose( | 870 TestBrowserCloseManager::AttemptClose( |
838 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); | 871 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); |
839 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); | 872 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
840 close_observer.Wait(); | 873 close_observer.Wait(); |
841 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | 874 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
842 EXPECT_TRUE(chrome::BrowserIterator().done()); | 875 EXPECT_TRUE(chrome::BrowserIterator().done()); |
843 } | 876 } |
844 | 877 |
845 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerBrowserTest, | 878 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerBrowserTestWithDownloads, |
846 BrowserCloseManagerBrowserTest, | 879 BrowserCloseManagerBrowserTestWithDownloads, |
847 testing::Bool()); | 880 testing::Bool()); |
848 | 881 |
849 class BrowserCloseManagerWithBackgroundModeBrowserTest | 882 class BrowserCloseManagerWithBackgroundModeBrowserTest |
850 : public BrowserCloseManagerBrowserTest { | 883 : public BrowserCloseManagerBrowserTest { |
851 public: | 884 public: |
852 BrowserCloseManagerWithBackgroundModeBrowserTest() {} | 885 BrowserCloseManagerWithBackgroundModeBrowserTest() {} |
853 | 886 |
854 virtual void SetUpOnMainThread() OVERRIDE { | 887 virtual void SetUpOnMainThread() OVERRIDE { |
855 BrowserCloseManagerBrowserTest::SetUpOnMainThread(); | 888 BrowserCloseManagerBrowserTest::SetUpOnMainThread(); |
856 g_browser_process->set_background_mode_manager_for_test( | 889 g_browser_process->set_background_mode_manager_for_test( |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
933 | 966 |
934 chrome::CloseAllBrowsers(); | 967 chrome::CloseAllBrowsers(); |
935 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); | 968 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
936 EXPECT_TRUE(chrome::BrowserIterator().done()); | 969 EXPECT_TRUE(chrome::BrowserIterator().done()); |
937 EXPECT_TRUE(IsBackgroundModeSuspended()); | 970 EXPECT_TRUE(IsBackgroundModeSuspended()); |
938 } | 971 } |
939 | 972 |
940 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, | 973 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, |
941 BrowserCloseManagerWithBackgroundModeBrowserTest, | 974 BrowserCloseManagerWithBackgroundModeBrowserTest, |
942 testing::Bool()); | 975 testing::Bool()); |
OLD | NEW |