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 "chrome/browser/lifetime/browser_close_manager.h" | 5 #include "chrome/browser/lifetime/browser_close_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "chrome/browser/background/background_mode_manager.h" | 15 #include "chrome/browser/background/background_mode_manager.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/browser_shutdown.h" | 17 #include "chrome/browser/browser_shutdown.h" |
18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
19 #include "chrome/browser/defaults.h" | 19 #include "chrome/browser/defaults.h" |
20 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 20 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 21 #include "chrome/browser/download/download_core_service.h" |
| 22 #include "chrome/browser/download/download_core_service_factory.h" |
21 #include "chrome/browser/download/download_prefs.h" | 23 #include "chrome/browser/download/download_prefs.h" |
22 #include "chrome/browser/download/download_service.h" | |
23 #include "chrome/browser/download/download_service_factory.h" | |
24 #include "chrome/browser/lifetime/application_lifetime.h" | 24 #include "chrome/browser/lifetime/application_lifetime.h" |
25 #include "chrome/browser/lifetime/keep_alive_types.h" | 25 #include "chrome/browser/lifetime/keep_alive_types.h" |
26 #include "chrome/browser/lifetime/scoped_keep_alive.h" | 26 #include "chrome/browser/lifetime/scoped_keep_alive.h" |
27 #include "chrome/browser/net/url_request_mock_util.h" | 27 #include "chrome/browser/net/url_request_mock_util.h" |
28 #include "chrome/browser/prefs/session_startup_pref.h" | 28 #include "chrome/browser/prefs/session_startup_pref.h" |
29 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/browser/profiles/profile_manager.h" | 30 #include "chrome/browser/profiles/profile_manager.h" |
31 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 31 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
32 #include "chrome/browser/ui/browser.h" | 32 #include "chrome/browser/ui/browser.h" |
33 #include "chrome/browser/ui/browser_commands.h" | 33 #include "chrome/browser/ui/browser_commands.h" |
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); | 989 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); |
990 | 990 |
991 RepeatedNotificationObserver close_observer( | 991 RepeatedNotificationObserver close_observer( |
992 chrome::NOTIFICATION_BROWSER_CLOSED, 1); | 992 chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
993 | 993 |
994 TestBrowserCloseManager::AttemptClose( | 994 TestBrowserCloseManager::AttemptClose( |
995 TestBrowserCloseManager::NO_USER_CHOICE); | 995 TestBrowserCloseManager::NO_USER_CHOICE); |
996 close_observer.Wait(); | 996 close_observer.Wait(); |
997 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | 997 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
998 EXPECT_TRUE(BrowserList::GetInstance()->empty()); | 998 EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
999 EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles()); | 999 EXPECT_EQ(1, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
1000 | 1000 |
1001 // Attempting to close again should not crash. | 1001 // Attempting to close again should not crash. |
1002 TestBrowserCloseManager::AttemptClose( | 1002 TestBrowserCloseManager::AttemptClose( |
1003 TestBrowserCloseManager::NO_USER_CHOICE); | 1003 TestBrowserCloseManager::NO_USER_CHOICE); |
1004 } | 1004 } |
1005 #else // defined(OS_MACOSX) | 1005 #else // defined(OS_MACOSX) |
1006 | 1006 |
1007 // Test shutdown with a DANGEROUS_URL download undecided. | 1007 // Test shutdown with a DANGEROUS_URL download undecided. |
1008 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest, | 1008 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest, |
1009 TestWithDangerousUrlDownload) { | 1009 TestWithDangerousUrlDownload) { |
1010 ASSERT_TRUE(embedded_test_server()->Start()); | 1010 ASSERT_TRUE(embedded_test_server()->Start()); |
1011 SetDownloadPathForProfile(browser()->profile()); | 1011 SetDownloadPathForProfile(browser()->profile()); |
1012 | 1012 |
1013 // Set up the fake delegate that forces the download to be malicious. | 1013 // Set up the fake delegate that forces the download to be malicious. |
1014 std::unique_ptr<TestDownloadManagerDelegate> test_delegate( | 1014 std::unique_ptr<TestDownloadManagerDelegate> test_delegate( |
1015 new TestDownloadManagerDelegate(browser()->profile())); | 1015 new TestDownloadManagerDelegate(browser()->profile())); |
1016 DownloadServiceFactory::GetForBrowserContext(browser()->profile()) | 1016 DownloadCoreServiceFactory::GetForBrowserContext(browser()->profile()) |
1017 ->SetDownloadManagerDelegateForTesting(std::move(test_delegate)); | 1017 ->SetDownloadManagerDelegateForTesting(std::move(test_delegate)); |
1018 | 1018 |
1019 // Run a dangerous download, but the user doesn't make a decision. | 1019 // Run a dangerous download, but the user doesn't make a decision. |
1020 // This .swf normally would be categorized as DANGEROUS_FILE, but | 1020 // This .swf normally would be categorized as DANGEROUS_FILE, but |
1021 // TestDownloadManagerDelegate turns it into DANGEROUS_URL. | 1021 // TestDownloadManagerDelegate turns it into DANGEROUS_URL. |
1022 GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl( | 1022 GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl( |
1023 "downloads/dangerous/dangerous.swf")); | 1023 "downloads/dangerous/dangerous.swf")); |
1024 content::DownloadTestObserverInterrupted observer( | 1024 content::DownloadTestObserverInterrupted observer( |
1025 content::BrowserContext::GetDownloadManager(browser()->profile()), | 1025 content::BrowserContext::GetDownloadManager(browser()->profile()), |
1026 1, | 1026 1, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 | 1063 |
1064 RepeatedNotificationObserver close_observer( | 1064 RepeatedNotificationObserver close_observer( |
1065 chrome::NOTIFICATION_BROWSER_CLOSED, 1); | 1065 chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
1066 | 1066 |
1067 TestBrowserCloseManager::AttemptClose( | 1067 TestBrowserCloseManager::AttemptClose( |
1068 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); | 1068 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); |
1069 close_observer.Wait(); | 1069 close_observer.Wait(); |
1070 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | 1070 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
1071 EXPECT_TRUE(BrowserList::GetInstance()->empty()); | 1071 EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
1072 if (browser_defaults::kBrowserAliveWithNoWindows) | 1072 if (browser_defaults::kBrowserAliveWithNoWindows) |
1073 EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles()); | 1073 EXPECT_EQ(1, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
1074 else | 1074 else |
1075 EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles()); | 1075 EXPECT_EQ(0, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
1076 } | 1076 } |
1077 | 1077 |
1078 // Test shutdown with a download in progress in an off-the-record profile. | 1078 // Test shutdown with a download in progress in an off-the-record profile. |
1079 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest, | 1079 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest, |
1080 TestWithOffTheRecordDownloads) { | 1080 TestWithOffTheRecordDownloads) { |
1081 ASSERT_TRUE(embedded_test_server()->Start()); | 1081 ASSERT_TRUE(embedded_test_server()->Start()); |
1082 Profile* otr_profile = browser()->profile()->GetOffTheRecordProfile(); | 1082 Profile* otr_profile = browser()->profile()->GetOffTheRecordProfile(); |
1083 SetDownloadPathForProfile(otr_profile); | 1083 SetDownloadPathForProfile(otr_profile); |
1084 Browser* otr_browser = CreateBrowser(otr_profile); | 1084 Browser* otr_browser = CreateBrowser(otr_profile); |
1085 { | 1085 { |
(...skipping 13 matching lines...) Expand all Loading... |
1099 otr_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 1099 otr_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
1100 | 1100 |
1101 RepeatedNotificationObserver close_observer( | 1101 RepeatedNotificationObserver close_observer( |
1102 chrome::NOTIFICATION_BROWSER_CLOSED, 1); | 1102 chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
1103 | 1103 |
1104 TestBrowserCloseManager::AttemptClose( | 1104 TestBrowserCloseManager::AttemptClose( |
1105 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); | 1105 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); |
1106 close_observer.Wait(); | 1106 close_observer.Wait(); |
1107 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | 1107 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
1108 EXPECT_TRUE(BrowserList::GetInstance()->empty()); | 1108 EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
1109 EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles()); | 1109 EXPECT_EQ(0, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
1110 } | 1110 } |
1111 | 1111 |
1112 // Test shutdown with a download in progress in a regular profile an inconito | 1112 // Test shutdown with a download in progress in a regular profile an inconito |
1113 // browser is opened and closed. While there are active downloads, closing the | 1113 // browser is opened and closed. While there are active downloads, closing the |
1114 // incognito window shouldn't block on the active downloads which belong to the | 1114 // incognito window shouldn't block on the active downloads which belong to the |
1115 // parent profile. | 1115 // parent profile. |
1116 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest, | 1116 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest, |
1117 TestWithOffTheRecordWindowAndRegularDownload) { | 1117 TestWithOffTheRecordWindowAndRegularDownload) { |
1118 Profile* otr_profile = browser()->profile()->GetOffTheRecordProfile(); | 1118 Profile* otr_profile = browser()->profile()->GetOffTheRecordProfile(); |
1119 SetDownloadPathForProfile(otr_profile); | 1119 SetDownloadPathForProfile(otr_profile); |
(...skipping 27 matching lines...) Expand all Loading... |
1147 RepeatedNotificationObserver close_observer( | 1147 RepeatedNotificationObserver close_observer( |
1148 chrome::NOTIFICATION_BROWSER_CLOSED, 2); | 1148 chrome::NOTIFICATION_BROWSER_CLOSED, 2); |
1149 TestBrowserCloseManager::AttemptClose( | 1149 TestBrowserCloseManager::AttemptClose( |
1150 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); | 1150 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); |
1151 close_observer.Wait(); | 1151 close_observer.Wait(); |
1152 } | 1152 } |
1153 | 1153 |
1154 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | 1154 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
1155 EXPECT_TRUE(BrowserList::GetInstance()->empty()); | 1155 EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
1156 if (browser_defaults::kBrowserAliveWithNoWindows) | 1156 if (browser_defaults::kBrowserAliveWithNoWindows) |
1157 EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles()); | 1157 EXPECT_EQ(1, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
1158 else | 1158 else |
1159 EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles()); | 1159 EXPECT_EQ(0, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
1160 } | 1160 } |
1161 | 1161 |
1162 // Test shutdown with a download in progress from one profile, where the only | 1162 // Test shutdown with a download in progress from one profile, where the only |
1163 // open windows are for another profile. | 1163 // open windows are for another profile. |
1164 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest, | 1164 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest, |
1165 TestWithDownloadsFromDifferentProfiles) { | 1165 TestWithDownloadsFromDifferentProfiles) { |
1166 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1166 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
1167 Profile* other_profile = nullptr; | 1167 Profile* other_profile = nullptr; |
1168 { | 1168 { |
1169 base::FilePath path = | 1169 base::FilePath path = |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 ->GetURL()); | 1204 ->GetURL()); |
1205 | 1205 |
1206 RepeatedNotificationObserver close_observer( | 1206 RepeatedNotificationObserver close_observer( |
1207 chrome::NOTIFICATION_BROWSER_CLOSED, 2); | 1207 chrome::NOTIFICATION_BROWSER_CLOSED, 2); |
1208 TestBrowserCloseManager::AttemptClose( | 1208 TestBrowserCloseManager::AttemptClose( |
1209 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); | 1209 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); |
1210 close_observer.Wait(); | 1210 close_observer.Wait(); |
1211 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | 1211 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
1212 EXPECT_TRUE(BrowserList::GetInstance()->empty()); | 1212 EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
1213 if (browser_defaults::kBrowserAliveWithNoWindows) | 1213 if (browser_defaults::kBrowserAliveWithNoWindows) |
1214 EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles()); | 1214 EXPECT_EQ(1, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
1215 else | 1215 else |
1216 EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles()); | 1216 EXPECT_EQ(0, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
1217 } | 1217 } |
1218 | 1218 |
1219 // Test shutdown with downloads in progress and beforeunload handlers. | 1219 // Test shutdown with downloads in progress and beforeunload handlers. |
1220 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest, | 1220 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest, |
1221 TestBeforeUnloadAndDownloads) { | 1221 TestBeforeUnloadAndDownloads) { |
1222 ASSERT_TRUE(embedded_test_server()->Start()); | 1222 ASSERT_TRUE(embedded_test_server()->Start()); |
1223 SetDownloadPathForProfile(browser()->profile()); | 1223 SetDownloadPathForProfile(browser()->profile()); |
1224 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); | 1224 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); |
1225 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( | 1225 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
1226 browser(), embedded_test_server()->GetURL("/beforeunload.html"))); | 1226 browser(), embedded_test_server()->GetURL("/beforeunload.html"))); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 | 1340 |
1341 chrome::CloseAllBrowsers(); | 1341 chrome::CloseAllBrowsers(); |
1342 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); | 1342 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
1343 EXPECT_TRUE(BrowserList::GetInstance()->empty()); | 1343 EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
1344 EXPECT_TRUE(IsBackgroundModeSuspended()); | 1344 EXPECT_TRUE(IsBackgroundModeSuspended()); |
1345 } | 1345 } |
1346 | 1346 |
1347 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, | 1347 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, |
1348 BrowserCloseManagerWithBackgroundModeBrowserTest, | 1348 BrowserCloseManagerWithBackgroundModeBrowserTest, |
1349 testing::Bool()); | 1349 testing::Bool()); |
OLD | NEW |