| OLD | NEW |
| 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 <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 using content::DownloadItem; | 112 using content::DownloadItem; |
| 113 using content::DownloadManager; | 113 using content::DownloadManager; |
| 114 using content::DownloadUrlParameters; | 114 using content::DownloadUrlParameters; |
| 115 using content::WebContents; | 115 using content::WebContents; |
| 116 using extensions::Extension; | 116 using extensions::Extension; |
| 117 using extensions::FeatureSwitch; | 117 using extensions::FeatureSwitch; |
| 118 using net::URLRequestMockHTTPJob; | 118 using net::URLRequestMockHTTPJob; |
| 119 | 119 |
| 120 namespace { | 120 namespace { |
| 121 | 121 |
| 122 const char kDownloadTest1Path[] = "download-test1.lib"; |
| 123 |
| 122 class CreatedObserver : public content::DownloadManager::Observer { | 124 class CreatedObserver : public content::DownloadManager::Observer { |
| 123 public: | 125 public: |
| 124 explicit CreatedObserver(content::DownloadManager* manager) | 126 explicit CreatedObserver(content::DownloadManager* manager) |
| 125 : manager_(manager), | 127 : manager_(manager), |
| 126 waiting_(false) { | 128 waiting_(false) { |
| 127 manager->AddObserver(this); | 129 manager->AddObserver(this); |
| 128 } | 130 } |
| 129 ~CreatedObserver() override { | 131 ~CreatedObserver() override { |
| 130 if (manager_) | 132 if (manager_) |
| 131 manager_->RemoveObserver(this); | 133 manager_->RemoveObserver(this); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 } | 237 } |
| 236 | 238 |
| 237 bool was_previously_resumable_; | 239 bool was_previously_resumable_; |
| 238 size_t transitions_left_; | 240 size_t transitions_left_; |
| 239 | 241 |
| 240 DISALLOW_COPY_AND_ASSIGN(DownloadTestObserverResumable); | 242 DISALLOW_COPY_AND_ASSIGN(DownloadTestObserverResumable); |
| 241 }; | 243 }; |
| 242 | 244 |
| 243 // IDs and paths of CRX files used in tests. | 245 // IDs and paths of CRX files used in tests. |
| 244 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 246 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 245 const base::FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); | 247 const char kGoodCrxPath[] = "extensions/good.crx"; |
| 246 | 248 |
| 247 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; | 249 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
| 248 const base::FilePath kLargeThemePath( | 250 const char kLargeThemePath[] = "extensions/theme2.crx"; |
| 249 FILE_PATH_LITERAL("extensions/theme2.crx")); | |
| 250 | 251 |
| 251 // Get History Information. | 252 // Get History Information. |
| 252 class DownloadsHistoryDataCollector { | 253 class DownloadsHistoryDataCollector { |
| 253 public: | 254 public: |
| 254 explicit DownloadsHistoryDataCollector(Profile* profile) | 255 explicit DownloadsHistoryDataCollector(Profile* profile) |
| 255 : profile_(profile), result_valid_(false) {} | 256 : profile_(profile), result_valid_(false) {} |
| 256 | 257 |
| 257 bool WaitForDownloadInfo( | 258 bool WaitForDownloadInfo( |
| 258 scoped_ptr<std::vector<history::DownloadRow> >* results) { | 259 scoped_ptr<std::vector<history::DownloadRow> >* results) { |
| 259 history::HistoryService* hs = HistoryServiceFactory::GetForProfile( | 260 history::HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| (...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 // This method: | 1067 // This method: |
| 1067 // * Starts a mock download by navigating browser() to a URLRequestMockHTTPJob | 1068 // * Starts a mock download by navigating browser() to a URLRequestMockHTTPJob |
| 1068 // mock URL. | 1069 // mock URL. |
| 1069 // * Injects |error| on the first write using |error_injector|. | 1070 // * Injects |error| on the first write using |error_injector|. |
| 1070 // * Waits for the download to be interrupted. | 1071 // * Waits for the download to be interrupted. |
| 1071 // * Clears the errors on |error_injector|. | 1072 // * Clears the errors on |error_injector|. |
| 1072 // * Returns the resulting interrupted download. | 1073 // * Returns the resulting interrupted download. |
| 1073 DownloadItem* StartMockDownloadAndInjectError( | 1074 DownloadItem* StartMockDownloadAndInjectError( |
| 1074 content::TestFileErrorInjector* error_injector, | 1075 content::TestFileErrorInjector* error_injector, |
| 1075 content::DownloadInterruptReason error) { | 1076 content::DownloadInterruptReason error) { |
| 1076 base::FilePath file_path(FILE_PATH_LITERAL("download-test1.lib")); | 1077 GURL url = URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path); |
| 1077 GURL url = URLRequestMockHTTPJob::GetMockUrl(file_path); | |
| 1078 | 1078 |
| 1079 content::TestFileErrorInjector::FileErrorInfo error_info; | 1079 content::TestFileErrorInjector::FileErrorInfo error_info; |
| 1080 error_info.url = url.spec(); | 1080 error_info.url = url.spec(); |
| 1081 error_info.code = content::TestFileErrorInjector::FILE_OPERATION_WRITE; | 1081 error_info.code = content::TestFileErrorInjector::FILE_OPERATION_WRITE; |
| 1082 error_info.operation_instance = 0; | 1082 error_info.operation_instance = 0; |
| 1083 error_info.error = error; | 1083 error_info.error = error; |
| 1084 error_injector->ClearErrors(); | 1084 error_injector->ClearErrors(); |
| 1085 error_injector->AddError(error_info); | 1085 error_injector->AddError(error_info); |
| 1086 error_injector->InjectErrors(); | 1086 error_injector->InjectErrors(); |
| 1087 | 1087 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 }; | 1124 }; |
| 1125 | 1125 |
| 1126 // NOTES: | 1126 // NOTES: |
| 1127 // | 1127 // |
| 1128 // Files for these tests are found in DIR_TEST_DATA (currently | 1128 // Files for these tests are found in DIR_TEST_DATA (currently |
| 1129 // "chrome\test\data\", see chrome_paths.cc). | 1129 // "chrome\test\data\", see chrome_paths.cc). |
| 1130 // Mock responses have extension .mock-http-headers appended to the file name. | 1130 // Mock responses have extension .mock-http-headers appended to the file name. |
| 1131 | 1131 |
| 1132 // Download a file due to the associated MIME type. | 1132 // Download a file due to the associated MIME type. |
| 1133 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { | 1133 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { |
| 1134 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1134 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 1135 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1136 | 1135 |
| 1137 // Download the file and wait. We do not expect the Select File dialog. | 1136 // Download the file and wait. We do not expect the Select File dialog. |
| 1138 DownloadAndWait(browser(), url); | 1137 DownloadAndWait(browser(), url); |
| 1139 | 1138 |
| 1140 // Check state. | 1139 // Check state. |
| 1141 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1140 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1141 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1142 CheckDownload(browser(), file, file); | 1142 CheckDownload(browser(), file, file); |
| 1143 } | 1143 } |
| 1144 | 1144 |
| 1145 #if defined(OS_WIN) | 1145 #if defined(OS_WIN) |
| 1146 // Download a file and confirm that the zone identifier (on windows) | 1146 // Download a file and confirm that the zone identifier (on windows) |
| 1147 // is set to internet. | 1147 // is set to internet. |
| 1148 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { | 1148 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { |
| 1149 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1149 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 1150 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1151 | 1150 |
| 1152 // Download the file and wait. We do not expect the Select File dialog. | 1151 // Download the file and wait. We do not expect the Select File dialog. |
| 1153 DownloadAndWait(browser(), url); | 1152 DownloadAndWait(browser(), url); |
| 1154 | 1153 |
| 1155 // Check state. Special file state must be checked before CheckDownload, | 1154 // Check state. Special file state must be checked before CheckDownload, |
| 1156 // as CheckDownload will delete the output file. | 1155 // as CheckDownload will delete the output file. |
| 1157 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1156 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1157 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1158 base::FilePath downloaded_file(DestinationFile(browser(), file)); | 1158 base::FilePath downloaded_file(DestinationFile(browser(), file)); |
| 1159 if (base::VolumeSupportsADS(downloaded_file)) | 1159 if (base::VolumeSupportsADS(downloaded_file)) |
| 1160 EXPECT_TRUE(base::HasInternetZoneIdentifier(downloaded_file)); | 1160 EXPECT_TRUE(base::HasInternetZoneIdentifier(downloaded_file)); |
| 1161 CheckDownload(browser(), file, file); | 1161 CheckDownload(browser(), file, file); |
| 1162 } | 1162 } |
| 1163 #endif | 1163 #endif |
| 1164 | 1164 |
| 1165 // Put up a Select File dialog when the file is downloaded, due to | 1165 // Put up a Select File dialog when the file is downloaded, due to |
| 1166 // downloads preferences settings. | 1166 // downloads preferences settings. |
| 1167 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { | 1167 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { |
| 1168 // Re-enable prompting. | 1168 // Re-enable prompting. |
| 1169 browser()->profile()->GetPrefs()->SetBoolean( | 1169 browser()->profile()->GetPrefs()->SetBoolean( |
| 1170 prefs::kPromptForDownload, true); | 1170 prefs::kPromptForDownload, true); |
| 1171 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1171 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 1172 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1173 | 1172 |
| 1174 EnableFileChooser(true); | 1173 EnableFileChooser(true); |
| 1175 | 1174 |
| 1176 // Download the file and wait. We expect the Select File dialog to appear | 1175 // Download the file and wait. We expect the Select File dialog to appear |
| 1177 // due to the MIME type, but we still wait until the download completes. | 1176 // due to the MIME type, but we still wait until the download completes. |
| 1178 scoped_ptr<content::DownloadTestObserver> observer( | 1177 scoped_ptr<content::DownloadTestObserver> observer( |
| 1179 new content::DownloadTestObserverTerminal( | 1178 new content::DownloadTestObserverTerminal( |
| 1180 DownloadManagerForBrowser(browser()), | 1179 DownloadManagerForBrowser(browser()), |
| 1181 1, | 1180 1, |
| 1182 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1181 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1183 ui_test_utils::NavigateToURL(browser(), url); | 1182 ui_test_utils::NavigateToURL(browser(), url); |
| 1184 observer->WaitForFinished(); | 1183 observer->WaitForFinished(); |
| 1185 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1184 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1186 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1185 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1187 EXPECT_TRUE(DidShowFileChooser()); | 1186 EXPECT_TRUE(DidShowFileChooser()); |
| 1188 | 1187 |
| 1189 // Check state. | 1188 // Check state. |
| 1190 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1189 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1190 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1191 CheckDownload(browser(), file, file); | 1191 CheckDownload(browser(), file, file); |
| 1192 } | 1192 } |
| 1193 | 1193 |
| 1194 // Access a file with a viewable mime-type, verify that a download | 1194 // Access a file with a viewable mime-type, verify that a download |
| 1195 // did not initiate. | 1195 // did not initiate. |
| 1196 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { | 1196 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { |
| 1197 base::FilePath file(FILE_PATH_LITERAL("download-test2.html")); | 1197 base::FilePath file(FILE_PATH_LITERAL("download-test2.html")); |
| 1198 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1198 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test2.html")); |
| 1199 base::FilePath file_path(DestinationFile(browser(), file)); | 1199 base::FilePath file_path(DestinationFile(browser(), file)); |
| 1200 | 1200 |
| 1201 // Open a web page and wait. | 1201 // Open a web page and wait. |
| 1202 ui_test_utils::NavigateToURL(browser(), url); | 1202 ui_test_utils::NavigateToURL(browser(), url); |
| 1203 | 1203 |
| 1204 // Check that we did not download the web page. | 1204 // Check that we did not download the web page. |
| 1205 EXPECT_FALSE(base::PathExists(file_path)); | 1205 EXPECT_FALSE(base::PathExists(file_path)); |
| 1206 | 1206 |
| 1207 // Check state. | 1207 // Check state. |
| 1208 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1208 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 EXPECT_TRUE(VerifyNoDownloads()); | 1264 EXPECT_TRUE(VerifyNoDownloads()); |
| 1265 } | 1265 } |
| 1266 } | 1266 } |
| 1267 | 1267 |
| 1268 // Verify that when the DownloadResourceThrottle cancels a download, the | 1268 // Verify that when the DownloadResourceThrottle cancels a download, the |
| 1269 // download never makes it to the downloads system. | 1269 // download never makes it to the downloads system. |
| 1270 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadResourceThrottleCancels) { | 1270 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadResourceThrottleCancels) { |
| 1271 // Navigate to a page with the same domain as the file to download. We can't | 1271 // Navigate to a page with the same domain as the file to download. We can't |
| 1272 // navigate directly to the file we don't want to download because cross-site | 1272 // navigate directly to the file we don't want to download because cross-site |
| 1273 // navigations reset the TabDownloadState. | 1273 // navigations reset the TabDownloadState. |
| 1274 base::FilePath same_site_path(FILE_PATH_LITERAL("download_script.html")); | 1274 GURL same_site_url(URLRequestMockHTTPJob::GetMockUrl("download_script.html")); |
| 1275 GURL same_site_url(URLRequestMockHTTPJob::GetMockUrl(same_site_path)); | |
| 1276 ui_test_utils::NavigateToURL(browser(), same_site_url); | 1275 ui_test_utils::NavigateToURL(browser(), same_site_url); |
| 1277 | 1276 |
| 1278 // Make sure the initial navigation didn't trigger a download. | 1277 // Make sure the initial navigation didn't trigger a download. |
| 1279 EXPECT_TRUE(VerifyNoDownloads()); | 1278 EXPECT_TRUE(VerifyNoDownloads()); |
| 1280 | 1279 |
| 1281 // Disable downloads for the tab. | 1280 // Disable downloads for the tab. |
| 1282 WebContents* web_contents = | 1281 WebContents* web_contents = |
| 1283 browser()->tab_strip_model()->GetActiveWebContents(); | 1282 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1284 DownloadRequestLimiter::TabDownloadState* tab_download_state = | 1283 DownloadRequestLimiter::TabDownloadState* tab_download_state = |
| 1285 g_browser_process->download_request_limiter()->GetDownloadState( | 1284 g_browser_process->download_request_limiter()->GetDownloadState( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1310 // Verify that there's no pending download. The resource throttle | 1309 // Verify that there's no pending download. The resource throttle |
| 1311 // should have deleted it before it created a download item, so it | 1310 // should have deleted it before it created a download item, so it |
| 1312 // shouldn't be available as a cancelled download either. | 1311 // shouldn't be available as a cancelled download either. |
| 1313 EXPECT_TRUE(VerifyNoDownloads()); | 1312 EXPECT_TRUE(VerifyNoDownloads()); |
| 1314 } | 1313 } |
| 1315 | 1314 |
| 1316 // Download a 0-size file with a content-disposition header, verify that the | 1315 // Download a 0-size file with a content-disposition header, verify that the |
| 1317 // download tab opened and the file exists as the filename specified in the | 1316 // download tab opened and the file exists as the filename specified in the |
| 1318 // header. This also ensures we properly handle empty file downloads. | 1317 // header. This also ensures we properly handle empty file downloads. |
| 1319 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { | 1318 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { |
| 1320 base::FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 1319 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test3.gif")); |
| 1321 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1322 base::FilePath download_file( | 1320 base::FilePath download_file( |
| 1323 FILE_PATH_LITERAL("download-test3-attachment.gif")); | 1321 FILE_PATH_LITERAL("download-test3-attachment.gif")); |
| 1324 | 1322 |
| 1325 // Download a file and wait. | 1323 // Download a file and wait. |
| 1326 DownloadAndWait(browser(), url); | 1324 DownloadAndWait(browser(), url); |
| 1327 | 1325 |
| 1326 base::FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
| 1328 CheckDownload(browser(), download_file, file); | 1327 CheckDownload(browser(), download_file, file); |
| 1329 | 1328 |
| 1330 // Check state. | 1329 // Check state. |
| 1331 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1330 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1332 } | 1331 } |
| 1333 | 1332 |
| 1334 // UnknownSize and KnownSize are tests which depend on | 1333 // UnknownSize and KnownSize are tests which depend on |
| 1335 // URLRequestSlowDownloadJob to serve content in a certain way. Data will be | 1334 // URLRequestSlowDownloadJob to serve content in a certain way. Data will be |
| 1336 // sent in two chunks where the first chunk is 35K and the second chunk is 10K. | 1335 // sent in two chunks where the first chunk is 35K and the second chunk is 10K. |
| 1337 // The test will first attempt to download a file; but the server will "pause" | 1336 // The test will first attempt to download a file; but the server will "pause" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1352 // Test that when downloading an item in Incognito mode, we don't crash when | 1351 // Test that when downloading an item in Incognito mode, we don't crash when |
| 1353 // closing the last Incognito window (http://crbug.com/13983). | 1352 // closing the last Incognito window (http://crbug.com/13983). |
| 1354 IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) { | 1353 IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) { |
| 1355 Browser* incognito = CreateIncognitoBrowser(); | 1354 Browser* incognito = CreateIncognitoBrowser(); |
| 1356 ASSERT_TRUE(incognito); | 1355 ASSERT_TRUE(incognito); |
| 1357 int window_count = chrome::GetTotalBrowserCount(); | 1356 int window_count = chrome::GetTotalBrowserCount(); |
| 1358 EXPECT_EQ(2, window_count); | 1357 EXPECT_EQ(2, window_count); |
| 1359 | 1358 |
| 1360 // Download a file in the Incognito window and wait. | 1359 // Download a file in the Incognito window and wait. |
| 1361 CreateAndSetDownloadsDirectory(incognito); | 1360 CreateAndSetDownloadsDirectory(incognito); |
| 1362 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1361 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 1363 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1364 // Since |incognito| is a separate browser, we have to set it up explicitly. | 1362 // Since |incognito| is a separate browser, we have to set it up explicitly. |
| 1365 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, | 1363 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, |
| 1366 false); | 1364 false); |
| 1367 DownloadAndWait(incognito, url); | 1365 DownloadAndWait(incognito, url); |
| 1368 | 1366 |
| 1369 // We should still have 2 windows. | 1367 // We should still have 2 windows. |
| 1370 ExpectWindowCountAfterDownload(2); | 1368 ExpectWindowCountAfterDownload(2); |
| 1371 | 1369 |
| 1372 #if !defined(OS_MACOSX) | 1370 #if !defined(OS_MACOSX) |
| 1373 // On Mac OS X, the UI window close is delayed until the outermost | 1371 // On Mac OS X, the UI window close is delayed until the outermost |
| 1374 // message loop runs. So it isn't possible to get a BROWSER_CLOSED | 1372 // message loop runs. So it isn't possible to get a BROWSER_CLOSED |
| 1375 // notification inside of a test. | 1373 // notification inside of a test. |
| 1376 content::WindowedNotificationObserver signal( | 1374 content::WindowedNotificationObserver signal( |
| 1377 chrome::NOTIFICATION_BROWSER_CLOSED, | 1375 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 1378 content::Source<Browser>(incognito)); | 1376 content::Source<Browser>(incognito)); |
| 1379 #endif | 1377 #endif |
| 1380 | 1378 |
| 1381 // Close the Incognito window and don't crash. | 1379 // Close the Incognito window and don't crash. |
| 1382 chrome::CloseWindow(incognito); | 1380 chrome::CloseWindow(incognito); |
| 1383 | 1381 |
| 1384 #if !defined(OS_MACOSX) | 1382 #if !defined(OS_MACOSX) |
| 1385 signal.Wait(); | 1383 signal.Wait(); |
| 1386 ExpectWindowCountAfterDownload(1); | 1384 ExpectWindowCountAfterDownload(1); |
| 1387 #endif | 1385 #endif |
| 1388 | 1386 |
| 1387 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1389 CheckDownload(browser(), file, file); | 1388 CheckDownload(browser(), file, file); |
| 1390 } | 1389 } |
| 1391 | 1390 |
| 1392 // Download one file on-record, then download the same file off-record, and test | 1391 // Download one file on-record, then download the same file off-record, and test |
| 1393 // that the filename is deduplicated. The previous test tests for a specific | 1392 // that the filename is deduplicated. The previous test tests for a specific |
| 1394 // bug; this next test tests that filename deduplication happens independently | 1393 // bug; this next test tests that filename deduplication happens independently |
| 1395 // of DownloadManager/CDMD. | 1394 // of DownloadManager/CDMD. |
| 1396 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_IncognitoRegular) { | 1395 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_IncognitoRegular) { |
| 1397 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("downloads/a_zip_file.zip"); | 1396 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("downloads/a_zip_file.zip"); |
| 1398 | 1397 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 download_items[0]->GetTargetFilePath().BaseName()); | 1452 download_items[0]->GetTargetFilePath().BaseName()); |
| 1454 ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath())); | 1453 ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath())); |
| 1455 EXPECT_TRUE(VerifyFile(download_items[0]->GetTargetFilePath(), | 1454 EXPECT_TRUE(VerifyFile(download_items[0]->GetTargetFilePath(), |
| 1456 original_contents, origin_file_size)); | 1455 original_contents, origin_file_size)); |
| 1457 } | 1456 } |
| 1458 | 1457 |
| 1459 // Navigate to a new background page, but don't download. | 1458 // Navigate to a new background page, but don't download. |
| 1460 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) { | 1459 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) { |
| 1461 // Because it's an HTML link, it should open a web page rather than | 1460 // Because it's an HTML link, it should open a web page rather than |
| 1462 // downloading. | 1461 // downloading. |
| 1463 base::FilePath file1(FILE_PATH_LITERAL("download-test2.html")); | 1462 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test2.html")); |
| 1464 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | |
| 1465 | 1463 |
| 1466 // Open a web page and wait. | 1464 // Open a web page and wait. |
| 1467 ui_test_utils::NavigateToURLWithDisposition( | 1465 ui_test_utils::NavigateToURLWithDisposition( |
| 1468 browser(), | 1466 browser(), |
| 1469 url, | 1467 url, |
| 1470 NEW_BACKGROUND_TAB, | 1468 NEW_BACKGROUND_TAB, |
| 1471 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1469 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1472 | 1470 |
| 1473 // We should have two tabs now. | 1471 // We should have two tabs now. |
| 1474 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 1472 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 1475 EXPECT_TRUE(VerifyNoDownloads()); | 1473 EXPECT_TRUE(VerifyNoDownloads()); |
| 1476 } | 1474 } |
| 1477 | 1475 |
| 1478 // Download a file in a background tab. Verify that the tab is closed | 1476 // Download a file in a background tab. Verify that the tab is closed |
| 1479 // automatically. | 1477 // automatically. |
| 1480 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) { | 1478 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) { |
| 1481 // Download a file in a new background tab and wait. The tab is automatically | 1479 // Download a file in a new background tab and wait. The tab is automatically |
| 1482 // closed when the download begins. | 1480 // closed when the download begins. |
| 1483 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1481 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 1484 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1485 DownloadAndWaitWithDisposition( | 1482 DownloadAndWaitWithDisposition( |
| 1486 browser(), | 1483 browser(), |
| 1487 url, | 1484 url, |
| 1488 NEW_BACKGROUND_TAB, | 1485 NEW_BACKGROUND_TAB, |
| 1489 0); | 1486 0); |
| 1490 | 1487 |
| 1491 // When the download finishes, we should still have one tab. | 1488 // When the download finishes, we should still have one tab. |
| 1492 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1489 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1493 | 1490 |
| 1491 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1494 CheckDownload(browser(), file, file); | 1492 CheckDownload(browser(), file, file); |
| 1495 } | 1493 } |
| 1496 | 1494 |
| 1497 // Open a web page in the current tab, then download a file in another tab via | 1495 // Open a web page in the current tab, then download a file in another tab via |
| 1498 // a Javascript call. | 1496 // a Javascript call. |
| 1499 // Verify that we have 2 tabs. | 1497 // Verify that we have 2 tabs. |
| 1500 // | 1498 // |
| 1501 // The download_page1.html page contains an openNew() function that opens a | 1499 // The download_page1.html page contains an openNew() function that opens a |
| 1502 // tab and then downloads download-test1.lib. | 1500 // tab and then downloads download-test1.lib. |
| 1503 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab2) { | 1501 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab2) { |
| 1504 // Because it's an HTML link, it should open a web page rather than | 1502 // Because it's an HTML link, it should open a web page rather than |
| 1505 // downloading. | 1503 // downloading. |
| 1506 base::FilePath file1(FILE_PATH_LITERAL("download_page1.html")); | 1504 GURL url(URLRequestMockHTTPJob::GetMockUrl("download_page1.html")); |
| 1507 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | |
| 1508 | 1505 |
| 1509 // Open a web page and wait. | 1506 // Open a web page and wait. |
| 1510 ui_test_utils::NavigateToURL(browser(), url); | 1507 ui_test_utils::NavigateToURL(browser(), url); |
| 1511 | 1508 |
| 1512 // Download a file in a new tab and wait (via Javascript). | 1509 // Download a file in a new tab and wait (via Javascript). |
| 1513 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1510 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1514 DownloadAndWaitWithDisposition(browser(), | 1511 DownloadAndWaitWithDisposition(browser(), |
| 1515 GURL("javascript:openNew()"), | 1512 GURL("javascript:openNew()"), |
| 1516 CURRENT_TAB, | 1513 CURRENT_TAB, |
| 1517 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1514 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 1518 | 1515 |
| 1519 // When the download finishes, we should have two tabs. | 1516 // When the download finishes, we should have two tabs. |
| 1520 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 1517 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 1521 | 1518 |
| 1522 CheckDownload(browser(), file, file); | 1519 CheckDownload(browser(), file, file); |
| 1523 } | 1520 } |
| 1524 | 1521 |
| 1525 // Open a web page in the current tab, open another tab via a Javascript call, | 1522 // Open a web page in the current tab, open another tab via a Javascript call, |
| 1526 // then download a file in the new tab. | 1523 // then download a file in the new tab. |
| 1527 // Verify that we have 2 tabs. | 1524 // Verify that we have 2 tabs. |
| 1528 // | 1525 // |
| 1529 // The download_page2.html page contains an openNew() function that opens a | 1526 // The download_page2.html page contains an openNew() function that opens a |
| 1530 // tab. | 1527 // tab. |
| 1531 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab3) { | 1528 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab3) { |
| 1532 // Because it's an HTML link, it should open a web page rather than | 1529 // Because it's an HTML link, it should open a web page rather than |
| 1533 // downloading. | 1530 // downloading. |
| 1534 base::FilePath file1(FILE_PATH_LITERAL("download_page2.html")); | 1531 GURL url1(URLRequestMockHTTPJob::GetMockUrl("download_page2.html")); |
| 1535 GURL url1(URLRequestMockHTTPJob::GetMockUrl(file1)); | |
| 1536 | 1532 |
| 1537 // Open a web page and wait. | 1533 // Open a web page and wait. |
| 1538 ui_test_utils::NavigateToURL(browser(), url1); | 1534 ui_test_utils::NavigateToURL(browser(), url1); |
| 1539 | 1535 |
| 1540 // Open a new tab and wait. | 1536 // Open a new tab and wait. |
| 1541 ui_test_utils::NavigateToURLWithDisposition( | 1537 ui_test_utils::NavigateToURLWithDisposition( |
| 1542 browser(), | 1538 browser(), |
| 1543 GURL("javascript:openNew()"), | 1539 GURL("javascript:openNew()"), |
| 1544 CURRENT_TAB, | 1540 CURRENT_TAB, |
| 1545 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1541 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 1546 | 1542 |
| 1547 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 1543 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 1548 | 1544 |
| 1549 // Download a file and wait. | 1545 // Download a file and wait. |
| 1550 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1546 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 1551 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1552 DownloadAndWaitWithDisposition(browser(), | 1547 DownloadAndWaitWithDisposition(browser(), |
| 1553 url, | 1548 url, |
| 1554 CURRENT_TAB, | 1549 CURRENT_TAB, |
| 1555 ui_test_utils::BROWSER_TEST_NONE); | 1550 ui_test_utils::BROWSER_TEST_NONE); |
| 1556 | 1551 |
| 1557 // When the download finishes, we should have two tabs. | 1552 // When the download finishes, we should have two tabs. |
| 1558 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 1553 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 1559 | 1554 |
| 1555 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1560 CheckDownload(browser(), file, file); | 1556 CheckDownload(browser(), file, file); |
| 1561 } | 1557 } |
| 1562 | 1558 |
| 1563 // Open a web page in the current tab, then download a file via Javascript, | 1559 // Open a web page in the current tab, then download a file via Javascript, |
| 1564 // which will do so in a temporary tab. Verify that we have 1 tab. | 1560 // which will do so in a temporary tab. Verify that we have 1 tab. |
| 1565 // | 1561 // |
| 1566 // The download_page3.html page contains an openNew() function that opens a | 1562 // The download_page3.html page contains an openNew() function that opens a |
| 1567 // tab with download-test1.lib in the URL. When the URL is determined to be | 1563 // tab with download-test1.lib in the URL. When the URL is determined to be |
| 1568 // a download, the tab is closed automatically. | 1564 // a download, the tab is closed automatically. |
| 1569 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab2) { | 1565 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab2) { |
| 1570 // Because it's an HTML link, it should open a web page rather than | 1566 // Because it's an HTML link, it should open a web page rather than |
| 1571 // downloading. | 1567 // downloading. |
| 1572 base::FilePath file1(FILE_PATH_LITERAL("download_page3.html")); | 1568 GURL url(URLRequestMockHTTPJob::GetMockUrl("download_page3.html")); |
| 1573 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | |
| 1574 | 1569 |
| 1575 // Open a web page and wait. | 1570 // Open a web page and wait. |
| 1576 ui_test_utils::NavigateToURL(browser(), url); | 1571 ui_test_utils::NavigateToURL(browser(), url); |
| 1577 | 1572 |
| 1578 // Download a file and wait. | 1573 // Download a file and wait. |
| 1579 // The file to download is "download-test1.lib". | 1574 // The file to download is "download-test1.lib". |
| 1580 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1575 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1581 DownloadAndWaitWithDisposition(browser(), | 1576 DownloadAndWaitWithDisposition(browser(), |
| 1582 GURL("javascript:openNew()"), | 1577 GURL("javascript:openNew()"), |
| 1583 CURRENT_TAB, | 1578 CURRENT_TAB, |
| 1584 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1579 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 1585 | 1580 |
| 1586 // When the download finishes, we should still have one tab. | 1581 // When the download finishes, we should still have one tab. |
| 1587 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1582 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1588 | 1583 |
| 1589 CheckDownload(browser(), file, file); | 1584 CheckDownload(browser(), file, file); |
| 1590 } | 1585 } |
| 1591 | 1586 |
| 1592 // Open a web page in the current tab, then call Javascript via a button to | 1587 // Open a web page in the current tab, then call Javascript via a button to |
| 1593 // download a file in a new tab, which is closed automatically when the | 1588 // download a file in a new tab, which is closed automatically when the |
| 1594 // download begins. | 1589 // download begins. |
| 1595 // Verify that we have 1 tab. | 1590 // Verify that we have 1 tab. |
| 1596 // | 1591 // |
| 1597 // The download_page4.html page contains a form with download-test1.lib as the | 1592 // The download_page4.html page contains a form with download-test1.lib as the |
| 1598 // action. | 1593 // action. |
| 1599 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab3) { | 1594 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab3) { |
| 1600 // Because it's an HTML link, it should open a web page rather than | 1595 // Because it's an HTML link, it should open a web page rather than |
| 1601 // downloading. | 1596 // downloading. |
| 1602 base::FilePath file1(FILE_PATH_LITERAL("download_page4.html")); | 1597 GURL url(URLRequestMockHTTPJob::GetMockUrl("download_page4.html")); |
| 1603 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | |
| 1604 | 1598 |
| 1605 // Open a web page and wait. | 1599 // Open a web page and wait. |
| 1606 ui_test_utils::NavigateToURL(browser(), url); | 1600 ui_test_utils::NavigateToURL(browser(), url); |
| 1607 | 1601 |
| 1608 // Download a file in a new tab and wait. The tab will automatically close | 1602 // Download a file in a new tab and wait. The tab will automatically close |
| 1609 // when the download begins. | 1603 // when the download begins. |
| 1610 // The file to download is "download-test1.lib". | 1604 // The file to download is "download-test1.lib". |
| 1611 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1605 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1612 DownloadAndWaitWithDisposition( | 1606 DownloadAndWaitWithDisposition( |
| 1613 browser(), | 1607 browser(), |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1788 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 1782 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 1789 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1783 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1790 switches::kAshBrowserTests)) | 1784 switches::kAshBrowserTests)) |
| 1791 return; | 1785 return; |
| 1792 #endif | 1786 #endif |
| 1793 // Disable SafeBrowsing so that danger will be determined by downloads system. | 1787 // Disable SafeBrowsing so that danger will be determined by downloads system. |
| 1794 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, | 1788 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, |
| 1795 false); | 1789 false); |
| 1796 | 1790 |
| 1797 // .swf file so that it's dangerous on all platforms (including CrOS). | 1791 // .swf file so that it's dangerous on all platforms (including CrOS). |
| 1798 base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf")); | 1792 GURL download_url( |
| 1799 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1793 URLRequestMockHTTPJob::GetMockUrl("downloads/dangerous/dangerous.swf")); |
| 1800 | 1794 |
| 1801 // Download the url and wait until the object has been stored. | 1795 // Download the url and wait until the object has been stored. |
| 1802 scoped_ptr<content::DownloadTestObserver> download_observer( | 1796 scoped_ptr<content::DownloadTestObserver> download_observer( |
| 1803 new content::DownloadTestObserverTerminal( | 1797 new content::DownloadTestObserverTerminal( |
| 1804 DownloadManagerForBrowser(browser()), 1, | 1798 DownloadManagerForBrowser(browser()), 1, |
| 1805 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_IGNORE)); | 1799 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_IGNORE)); |
| 1806 base::Time start(base::Time::Now()); | 1800 base::Time start(base::Time::Now()); |
| 1807 HistoryObserver observer(browser()->profile()); | 1801 HistoryObserver observer(browser()->profile()); |
| 1808 observer.SetFilterCallback(base::Bind(&HasDataAndName)); | 1802 observer.SetFilterCallback(base::Bind(&HasDataAndName)); |
| 1809 ui_test_utils::NavigateToURL(browser(), download_url); | 1803 ui_test_utils::NavigateToURL(browser(), download_url); |
| 1810 observer.WaitForStored(); | 1804 observer.WaitForStored(); |
| 1811 | 1805 |
| 1812 // Get the details on what was stored into the history. | 1806 // Get the details on what was stored into the history. |
| 1813 scoped_ptr<std::vector<history::DownloadRow> > downloads_in_database; | 1807 scoped_ptr<std::vector<history::DownloadRow> > downloads_in_database; |
| 1814 ASSERT_TRUE(DownloadsHistoryDataCollector( | 1808 ASSERT_TRUE(DownloadsHistoryDataCollector( |
| 1815 browser()->profile()).WaitForDownloadInfo(&downloads_in_database)); | 1809 browser()->profile()).WaitForDownloadInfo(&downloads_in_database)); |
| 1816 ASSERT_EQ(1u, downloads_in_database->size()); | 1810 ASSERT_EQ(1u, downloads_in_database->size()); |
| 1817 | 1811 |
| 1818 // Confirm history storage is what you expect for an unvalidated | 1812 // Confirm history storage is what you expect for an unvalidated |
| 1819 // dangerous file. | 1813 // dangerous file. |
| 1814 base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf")); |
| 1820 history::DownloadRow& row(downloads_in_database->at(0)); | 1815 history::DownloadRow& row(downloads_in_database->at(0)); |
| 1821 EXPECT_EQ(DestinationFile(browser(), file), row.target_path); | 1816 EXPECT_EQ(DestinationFile(browser(), file), row.target_path); |
| 1822 EXPECT_NE(DownloadTargetDeterminer::GetCrDownloadPath( | 1817 EXPECT_NE(DownloadTargetDeterminer::GetCrDownloadPath( |
| 1823 DestinationFile(browser(), file)), | 1818 DestinationFile(browser(), file)), |
| 1824 row.current_path); | 1819 row.current_path); |
| 1825 EXPECT_EQ(history::DownloadDangerType::DANGEROUS_FILE, row.danger_type); | 1820 EXPECT_EQ(history::DownloadDangerType::DANGEROUS_FILE, row.danger_type); |
| 1826 EXPECT_LE(start, row.start_time); | 1821 EXPECT_LE(start, row.start_time); |
| 1827 EXPECT_EQ(history::DownloadState::IN_PROGRESS, row.state); | 1822 EXPECT_EQ(history::DownloadState::IN_PROGRESS, row.state); |
| 1828 EXPECT_FALSE(row.opened); | 1823 EXPECT_FALSE(row.opened); |
| 1829 | 1824 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1848 EXPECT_FALSE(row1.opened); | 1843 EXPECT_FALSE(row1.opened); |
| 1849 // Not checking file size--not relevant to the point of the test, and | 1844 // Not checking file size--not relevant to the point of the test, and |
| 1850 // the file size is actually different on Windows and other platforms, | 1845 // the file size is actually different on Windows and other platforms, |
| 1851 // because for source control simplicity it's actually a text file, and | 1846 // because for source control simplicity it's actually a text file, and |
| 1852 // there are CRLF transformations for those files. | 1847 // there are CRLF transformations for those files. |
| 1853 } | 1848 } |
| 1854 | 1849 |
| 1855 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 1850 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
| 1856 // after download of a file while viewing another chrome://. | 1851 // after download of a file while viewing another chrome://. |
| 1857 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { | 1852 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { |
| 1858 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1853 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 1859 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1860 GURL flags_url(chrome::kChromeUIFlagsURL); | 1854 GURL flags_url(chrome::kChromeUIFlagsURL); |
| 1861 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); | 1855 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); |
| 1862 | 1856 |
| 1863 ui_test_utils::NavigateToURL(browser(), flags_url); | 1857 ui_test_utils::NavigateToURL(browser(), flags_url); |
| 1864 DownloadAndWait(browser(), download_url); | 1858 DownloadAndWait(browser(), download_url); |
| 1865 ui_test_utils::NavigateToURL(browser(), extensions_url); | 1859 ui_test_utils::NavigateToURL(browser(), extensions_url); |
| 1866 WebContents* contents = | 1860 WebContents* contents = |
| 1867 browser()->tab_strip_model()->GetActiveWebContents(); | 1861 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1868 ASSERT_TRUE(contents); | 1862 ASSERT_TRUE(contents); |
| 1869 bool webui_responded = false; | 1863 bool webui_responded = false; |
| 1870 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 1864 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 1871 contents, | 1865 contents, |
| 1872 "window.domAutomationController.send(window.webuiResponded);", | 1866 "window.domAutomationController.send(window.webuiResponded);", |
| 1873 &webui_responded)); | 1867 &webui_responded)); |
| 1874 EXPECT_TRUE(webui_responded); | 1868 EXPECT_TRUE(webui_responded); |
| 1875 } | 1869 } |
| 1876 | 1870 |
| 1877 // Test for crbug.com/12745. This tests that if a download is initiated from | 1871 // Test for crbug.com/12745. This tests that if a download is initiated from |
| 1878 // a chrome:// page that has registered and onunload handler, the browser | 1872 // a chrome:// page that has registered and onunload handler, the browser |
| 1879 // will be able to close. | 1873 // will be able to close. |
| 1880 IN_PROC_BROWSER_TEST_F(DownloadTest, BrowserCloseAfterDownload) { | 1874 IN_PROC_BROWSER_TEST_F(DownloadTest, BrowserCloseAfterDownload) { |
| 1881 GURL downloads_url(chrome::kChromeUIFlagsURL); | 1875 GURL downloads_url(chrome::kChromeUIFlagsURL); |
| 1882 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1876 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 1883 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1884 | 1877 |
| 1885 ui_test_utils::NavigateToURL(browser(), downloads_url); | 1878 ui_test_utils::NavigateToURL(browser(), downloads_url); |
| 1886 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | 1879 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 1887 ASSERT_TRUE(contents); | 1880 ASSERT_TRUE(contents); |
| 1888 bool result = false; | 1881 bool result = false; |
| 1889 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 1882 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 1890 contents, | 1883 contents, |
| 1891 "window.onunload = function() { var do_nothing = 0; }; " | 1884 "window.onunload = function() { var do_nothing = 0; }; " |
| 1892 "window.domAutomationController.send(true);", | 1885 "window.domAutomationController.send(true);", |
| 1893 &result)); | 1886 &result)); |
| 1894 EXPECT_TRUE(result); | 1887 EXPECT_TRUE(result); |
| 1895 | 1888 |
| 1896 DownloadAndWait(browser(), download_url); | 1889 DownloadAndWait(browser(), download_url); |
| 1897 | 1890 |
| 1898 content::WindowedNotificationObserver signal( | 1891 content::WindowedNotificationObserver signal( |
| 1899 chrome::NOTIFICATION_BROWSER_CLOSED, | 1892 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 1900 content::Source<Browser>(browser())); | 1893 content::Source<Browser>(browser())); |
| 1901 chrome::CloseWindow(browser()); | 1894 chrome::CloseWindow(browser()); |
| 1902 signal.Wait(); | 1895 signal.Wait(); |
| 1903 } | 1896 } |
| 1904 | 1897 |
| 1905 // Test to make sure the 'download' attribute in anchor tag is respected. | 1898 // Test to make sure the 'download' attribute in anchor tag is respected. |
| 1906 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { | 1899 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { |
| 1907 base::FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); | 1900 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-anchor-attrib.html")); |
| 1908 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1909 | 1901 |
| 1910 // Create a download, wait until it's complete, and confirm | 1902 // Create a download, wait until it's complete, and confirm |
| 1911 // we're in the expected state. | 1903 // we're in the expected state. |
| 1912 scoped_ptr<content::DownloadTestObserver> observer( | 1904 scoped_ptr<content::DownloadTestObserver> observer( |
| 1913 CreateWaiter(browser(), 1)); | 1905 CreateWaiter(browser(), 1)); |
| 1914 ui_test_utils::NavigateToURL(browser(), url); | 1906 ui_test_utils::NavigateToURL(browser(), url); |
| 1915 observer->WaitForFinished(); | 1907 observer->WaitForFinished(); |
| 1916 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1908 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1917 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1909 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1918 | 1910 |
| 1919 // Confirm the downloaded data exists. | 1911 // Confirm the downloaded data exists. |
| 1920 base::FilePath downloaded_file = GetDownloadDirectory(browser()); | 1912 base::FilePath downloaded_file = GetDownloadDirectory(browser()); |
| 1921 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); | 1913 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); |
| 1922 EXPECT_TRUE(base::PathExists(downloaded_file)); | 1914 EXPECT_TRUE(base::PathExists(downloaded_file)); |
| 1923 } | 1915 } |
| 1924 | 1916 |
| 1925 // Test to make sure auto-open works. | 1917 // Test to make sure auto-open works. |
| 1926 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { | 1918 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { |
| 1927 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); | 1919 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); |
| 1928 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1920 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-autoopen.txt")); |
| 1929 | 1921 |
| 1930 ASSERT_TRUE( | 1922 ASSERT_TRUE( |
| 1931 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 1923 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
| 1932 | 1924 |
| 1933 DownloadAndWait(browser(), url); | 1925 DownloadAndWait(browser(), url); |
| 1934 | 1926 |
| 1935 // Find the download and confirm it was opened. | 1927 // Find the download and confirm it was opened. |
| 1936 std::vector<DownloadItem*> downloads; | 1928 std::vector<DownloadItem*> downloads; |
| 1937 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | 1929 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
| 1938 ASSERT_EQ(1u, downloads.size()); | 1930 ASSERT_EQ(1u, downloads.size()); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2042 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); | 2034 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); |
| 2043 | 2035 |
| 2044 // Check that the extension was installed. | 2036 // Check that the extension was installed. |
| 2045 ExtensionService* extension_service = extensions::ExtensionSystem::Get( | 2037 ExtensionService* extension_service = extensions::ExtensionSystem::Get( |
| 2046 browser()->profile())->extension_service(); | 2038 browser()->profile())->extension_service(); |
| 2047 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); | 2039 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 2048 } | 2040 } |
| 2049 | 2041 |
| 2050 // Test installing a CRX that fails integrity checks. | 2042 // Test installing a CRX that fails integrity checks. |
| 2051 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { | 2043 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { |
| 2052 base::FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); | 2044 GURL extension_url( |
| 2053 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 2045 URLRequestMockHTTPJob::GetMockUrl("extensions/bad_signature.crx")); |
| 2054 | 2046 |
| 2055 // Install a mock install UI that simulates a user allowing permission to | 2047 // Install a mock install UI that simulates a user allowing permission to |
| 2056 // finish the install, and dismisses any error message. We check that the | 2048 // finish the install, and dismisses any error message. We check that the |
| 2057 // install failed below. | 2049 // install failed below. |
| 2058 SetAllowMockInstallPrompt(); | 2050 SetAllowMockInstallPrompt(); |
| 2059 | 2051 |
| 2060 scoped_ptr<content::DownloadTestObserver> observer( | 2052 scoped_ptr<content::DownloadTestObserver> observer( |
| 2061 DangerousDownloadWaiter( | 2053 DangerousDownloadWaiter( |
| 2062 browser(), 1, | 2054 browser(), 1, |
| 2063 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 2055 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2103 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); | 2095 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); |
| 2104 | 2096 |
| 2105 // Check that the extension was installed. | 2097 // Check that the extension was installed. |
| 2106 ExtensionService* extension_service = extensions::ExtensionSystem::Get( | 2098 ExtensionService* extension_service = extensions::ExtensionSystem::Get( |
| 2107 browser()->profile())->extension_service(); | 2099 browser()->profile())->extension_service(); |
| 2108 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 2100 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
| 2109 } | 2101 } |
| 2110 | 2102 |
| 2111 // Tests for download initiation functions. | 2103 // Tests for download initiation functions. |
| 2112 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { | 2104 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { |
| 2113 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 2105 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 2114 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 2115 | 2106 |
| 2116 // DownloadUrl always prompts; return acceptance of whatever it prompts. | 2107 // DownloadUrl always prompts; return acceptance of whatever it prompts. |
| 2117 EnableFileChooser(true); | 2108 EnableFileChooser(true); |
| 2118 | 2109 |
| 2119 WebContents* web_contents = | 2110 WebContents* web_contents = |
| 2120 browser()->tab_strip_model()->GetActiveWebContents(); | 2111 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2121 ASSERT_TRUE(web_contents); | 2112 ASSERT_TRUE(web_contents); |
| 2122 | 2113 |
| 2123 content::DownloadTestObserver* observer( | 2114 content::DownloadTestObserver* observer( |
| 2124 new content::DownloadTestObserverTerminal( | 2115 new content::DownloadTestObserverTerminal( |
| 2125 DownloadManagerForBrowser(browser()), 1, | 2116 DownloadManagerForBrowser(browser()), 1, |
| 2126 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 2117 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 2127 scoped_ptr<DownloadUrlParameters> params( | 2118 scoped_ptr<DownloadUrlParameters> params( |
| 2128 DownloadUrlParameters::FromWebContents(web_contents, url)); | 2119 DownloadUrlParameters::FromWebContents(web_contents, url)); |
| 2129 params->set_prompt(true); | 2120 params->set_prompt(true); |
| 2130 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); | 2121 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); |
| 2131 observer->WaitForFinished(); | 2122 observer->WaitForFinished(); |
| 2132 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2123 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 2133 CheckDownloadStates(1, DownloadItem::COMPLETE); | 2124 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 2134 EXPECT_TRUE(DidShowFileChooser()); | 2125 EXPECT_TRUE(DidShowFileChooser()); |
| 2135 | 2126 |
| 2136 // Check state. | 2127 // Check state. |
| 2128 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 2137 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 2129 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 2138 ASSERT_TRUE(CheckDownload(browser(), file, file)); | 2130 ASSERT_TRUE(CheckDownload(browser(), file, file)); |
| 2139 } | 2131 } |
| 2140 | 2132 |
| 2141 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { | 2133 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { |
| 2142 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 2134 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 2143 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 2144 | 2135 |
| 2145 WebContents* web_contents = | 2136 WebContents* web_contents = |
| 2146 browser()->tab_strip_model()->GetActiveWebContents(); | 2137 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2147 ASSERT_TRUE(web_contents); | 2138 ASSERT_TRUE(web_contents); |
| 2148 | 2139 |
| 2140 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 2149 base::ScopedTempDir other_directory; | 2141 base::ScopedTempDir other_directory; |
| 2150 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); | 2142 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); |
| 2151 base::FilePath target_file_full_path | 2143 base::FilePath target_file_full_path |
| 2152 = other_directory.path().Append(file.BaseName()); | 2144 = other_directory.path().Append(file.BaseName()); |
| 2153 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); | 2145 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); |
| 2154 scoped_ptr<DownloadUrlParameters> params( | 2146 scoped_ptr<DownloadUrlParameters> params( |
| 2155 DownloadUrlParameters::FromWebContents(web_contents, url)); | 2147 DownloadUrlParameters::FromWebContents(web_contents, url)); |
| 2156 params->set_file_path(target_file_full_path); | 2148 params->set_file_path(target_file_full_path); |
| 2157 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); | 2149 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); |
| 2158 observer->WaitForFinished(); | 2150 observer->WaitForFinished(); |
| (...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3370 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 3362 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
| 3371 download->GetDangerType()); | 3363 download->GetDangerType()); |
| 3372 | 3364 |
| 3373 download->Cancel(true); | 3365 download->Cancel(true); |
| 3374 } | 3366 } |
| 3375 | 3367 |
| 3376 #endif // OS_WIN | 3368 #endif // OS_WIN |
| 3377 | 3369 |
| 3378 IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackService) { | 3370 IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackService) { |
| 3379 // Make a dangerous file. | 3371 // Make a dangerous file. |
| 3380 base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf")); | 3372 GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl( |
| 3381 GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl(file)); | 3373 "downloads/dangerous/dangerous.swf")); |
| 3382 scoped_ptr<content::DownloadTestObserverInterrupted> observer( | 3374 scoped_ptr<content::DownloadTestObserverInterrupted> observer( |
| 3383 new content::DownloadTestObserverInterrupted( | 3375 new content::DownloadTestObserverInterrupted( |
| 3384 DownloadManagerForBrowser(browser()), 1, | 3376 DownloadManagerForBrowser(browser()), 1, |
| 3385 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); | 3377 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); |
| 3386 ui_test_utils::NavigateToURLWithDisposition( | 3378 ui_test_utils::NavigateToURLWithDisposition( |
| 3387 browser(), | 3379 browser(), |
| 3388 GURL(download_url), | 3380 GURL(download_url), |
| 3389 NEW_BACKGROUND_TAB, | 3381 NEW_BACKGROUND_TAB, |
| 3390 ui_test_utils::BROWSER_TEST_NONE); | 3382 ui_test_utils::BROWSER_TEST_NONE); |
| 3391 observer->WaitForFinished(); | 3383 observer->WaitForFinished(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3443 DownloadAndWait(browser(), url); | 3435 DownloadAndWait(browser(), url); |
| 3444 | 3436 |
| 3445 // The download shelf should be visible. | 3437 // The download shelf should be visible. |
| 3446 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 3438 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 3447 } | 3439 } |
| 3448 | 3440 |
| 3449 // Test that the download shelf is per-window by starting a download in one | 3441 // Test that the download shelf is per-window by starting a download in one |
| 3450 // tab, opening a second tab, closing the shelf, going back to the first tab, | 3442 // tab, opening a second tab, closing the shelf, going back to the first tab, |
| 3451 // and checking that the shelf is closed. | 3443 // and checking that the shelf is closed. |
| 3452 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, PerWindowShelf) { | 3444 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, PerWindowShelf) { |
| 3453 base::FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 3445 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test3.gif")); |
| 3454 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 3455 base::FilePath download_file( | 3446 base::FilePath download_file( |
| 3456 FILE_PATH_LITERAL("download-test3-attachment.gif")); | 3447 FILE_PATH_LITERAL("download-test3-attachment.gif")); |
| 3457 | 3448 |
| 3458 // Download a file and wait. | 3449 // Download a file and wait. |
| 3459 DownloadAndWait(browser(), url); | 3450 DownloadAndWait(browser(), url); |
| 3460 | 3451 |
| 3452 base::FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
| 3461 CheckDownload(browser(), download_file, file); | 3453 CheckDownload(browser(), download_file, file); |
| 3462 | 3454 |
| 3463 // Check state. | 3455 // Check state. |
| 3464 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 3456 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 3465 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 3457 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 3466 | 3458 |
| 3467 // Open a second tab and wait. | 3459 // Open a second tab and wait. |
| 3468 EXPECT_NE(static_cast<WebContents*>(NULL), | 3460 EXPECT_NE(static_cast<WebContents*>(NULL), |
| 3469 chrome::AddSelectedTabWithURL(browser(), GURL(url::kAboutBlankURL), | 3461 chrome::AddSelectedTabWithURL(browser(), GURL(url::kAboutBlankURL), |
| 3470 ui::PAGE_TRANSITION_TYPED)); | 3462 ui::PAGE_TRANSITION_TYPED)); |
| 3471 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 3463 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 3472 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 3464 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 3473 | 3465 |
| 3474 // Hide the download shelf. | 3466 // Hide the download shelf. |
| 3475 browser()->window()->GetDownloadShelf()->Close(DownloadShelf::AUTOMATIC); | 3467 browser()->window()->GetDownloadShelf()->Close(DownloadShelf::AUTOMATIC); |
| 3476 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3468 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3477 | 3469 |
| 3478 // Go to the first tab. | 3470 // Go to the first tab. |
| 3479 browser()->tab_strip_model()->ActivateTabAt(0, true); | 3471 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 3480 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 3472 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 3481 | 3473 |
| 3482 // The download shelf should not be visible. | 3474 // The download shelf should not be visible. |
| 3483 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3475 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3484 } | 3476 } |
| 3485 | 3477 |
| 3486 // Check whether the downloads shelf is closed when the downloads tab is | 3478 // Check whether the downloads shelf is closed when the downloads tab is |
| 3487 // invoked. | 3479 // invoked. |
| 3488 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, CloseShelfOnDownloadsTab) { | 3480 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, CloseShelfOnDownloadsTab) { |
| 3489 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 3481 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 3490 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 3491 | 3482 |
| 3492 // Download the file and wait. We do not expect the Select File dialog. | 3483 // Download the file and wait. We do not expect the Select File dialog. |
| 3493 DownloadAndWait(browser(), url); | 3484 DownloadAndWait(browser(), url); |
| 3494 | 3485 |
| 3495 // Check state. | 3486 // Check state. |
| 3496 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 3487 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 3497 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 3488 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 3498 | 3489 |
| 3499 // Open the downloads tab. | 3490 // Open the downloads tab. |
| 3500 chrome::ShowDownloads(browser()); | 3491 chrome::ShowDownloads(browser()); |
| 3501 // The shelf should now be closed. | 3492 // The shelf should now be closed. |
| 3502 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3493 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3503 } | 3494 } |
| 3504 | 3495 |
| 3505 // Test that when downloading an item in Incognito mode, check that the | 3496 // Test that when downloading an item in Incognito mode, check that the |
| 3506 // download shelf is not visible after closing the Incognito window. | 3497 // download shelf is not visible after closing the Incognito window. |
| 3507 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, IncognitoDownload) { | 3498 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, IncognitoDownload) { |
| 3508 Browser* incognito = CreateIncognitoBrowser(); | 3499 Browser* incognito = CreateIncognitoBrowser(); |
| 3509 ASSERT_TRUE(incognito); | 3500 ASSERT_TRUE(incognito); |
| 3510 | 3501 |
| 3511 // Download a file in the Incognito window and wait. | 3502 // Download a file in the Incognito window and wait. |
| 3512 CreateAndSetDownloadsDirectory(incognito); | 3503 CreateAndSetDownloadsDirectory(incognito); |
| 3513 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 3504 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 3514 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 3515 // Since |incognito| is a separate browser, we have to set it up explicitly. | 3505 // Since |incognito| is a separate browser, we have to set it up explicitly. |
| 3516 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, | 3506 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, |
| 3517 false); | 3507 false); |
| 3518 DownloadAndWait(incognito, url); | 3508 DownloadAndWait(incognito, url); |
| 3519 | 3509 |
| 3520 // Verify that the download shelf is showing for the Incognito window. | 3510 // Verify that the download shelf is showing for the Incognito window. |
| 3521 EXPECT_TRUE(incognito->window()->IsDownloadShelfVisible()); | 3511 EXPECT_TRUE(incognito->window()->IsDownloadShelfVisible()); |
| 3522 | 3512 |
| 3523 // Verify that the regular window does not have a download shelf. | 3513 // Verify that the regular window does not have a download shelf. |
| 3524 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3514 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3525 } | 3515 } |
| 3526 | 3516 |
| 3527 // Download a file in a new window. | 3517 // Download a file in a new window. |
| 3528 // Verify that we have 2 windows, and the download shelf is not visible in the | 3518 // Verify that we have 2 windows, and the download shelf is not visible in the |
| 3529 // first window, but is visible in the second window. | 3519 // first window, but is visible in the second window. |
| 3530 // Close the new window. | 3520 // Close the new window. |
| 3531 // Verify that we have 1 window, and the download shelf is not visible. | 3521 // Verify that we have 1 window, and the download shelf is not visible. |
| 3532 // | 3522 // |
| 3533 // Regression test for http://crbug.com/44454 | 3523 // Regression test for http://crbug.com/44454 |
| 3534 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, NewWindow) { | 3524 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, NewWindow) { |
| 3535 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 3525 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 3536 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 3537 #if !defined(OS_MACOSX) | 3526 #if !defined(OS_MACOSX) |
| 3538 // See below. | 3527 // See below. |
| 3539 Browser* first_browser = browser(); | 3528 Browser* first_browser = browser(); |
| 3540 #endif | 3529 #endif |
| 3541 | 3530 |
| 3542 // Download a file in a new window and wait. | 3531 // Download a file in a new window and wait. |
| 3543 DownloadAndWaitWithDisposition(browser(), url, NEW_WINDOW, | 3532 DownloadAndWaitWithDisposition(browser(), url, NEW_WINDOW, |
| 3544 ui_test_utils::BROWSER_TEST_NONE); | 3533 ui_test_utils::BROWSER_TEST_NONE); |
| 3545 | 3534 |
| 3546 // When the download finishes, the download shelf SHOULD NOT be visible in | 3535 // When the download finishes, the download shelf SHOULD NOT be visible in |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3575 #if !defined(OS_MACOSX) | 3564 #if !defined(OS_MACOSX) |
| 3576 signal.Wait(); | 3565 signal.Wait(); |
| 3577 EXPECT_EQ(first_browser, browser()); | 3566 EXPECT_EQ(first_browser, browser()); |
| 3578 ExpectWindowCountAfterDownload(1); | 3567 ExpectWindowCountAfterDownload(1); |
| 3579 #endif | 3568 #endif |
| 3580 | 3569 |
| 3581 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 3570 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 3582 // Download shelf should close. Download panel stays open on ChromeOS. | 3571 // Download shelf should close. Download panel stays open on ChromeOS. |
| 3583 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3572 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3584 | 3573 |
| 3574 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 3585 CheckDownload(browser(), file, file); | 3575 CheckDownload(browser(), file, file); |
| 3586 } | 3576 } |
| 3587 | 3577 |
| 3588 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, PRE_DownloadTest_History) { | 3578 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, PRE_DownloadTest_History) { |
| 3589 // Download a file and wait for it to be stored. | 3579 // Download a file and wait for it to be stored. |
| 3590 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 3580 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 3591 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 3592 HistoryObserver observer(browser()->profile()); | 3581 HistoryObserver observer(browser()->profile()); |
| 3593 DownloadAndWait(browser(), download_url); | 3582 DownloadAndWait(browser(), download_url); |
| 3594 observer.WaitForStored(); | 3583 observer.WaitForStored(); |
| 3595 HistoryServiceFactory::GetForProfile(browser()->profile(), | 3584 HistoryServiceFactory::GetForProfile(browser()->profile(), |
| 3596 ServiceAccessType::IMPLICIT_ACCESS) | 3585 ServiceAccessType::IMPLICIT_ACCESS) |
| 3597 ->FlushForTest(base::Bind( | 3586 ->FlushForTest(base::Bind( |
| 3598 &base::MessageLoop::QuitWhenIdle, | 3587 &base::MessageLoop::QuitWhenIdle, |
| 3599 base::Unretained(base::MessageLoop::current()->current()))); | 3588 base::Unretained(base::MessageLoop::current()->current()))); |
| 3600 content::RunMessageLoop(); | 3589 content::RunMessageLoop(); |
| 3601 } | 3590 } |
| 3602 | 3591 |
| 3603 #if defined(OS_CHROMEOS) | 3592 #if defined(OS_CHROMEOS) |
| 3604 // Times out on ChromeOS: http://crbug.com/217810 | 3593 // Times out on ChromeOS: http://crbug.com/217810 |
| 3605 #define MAYBE_DownloadTest_History DISABLED_DownloadTest_History | 3594 #define MAYBE_DownloadTest_History DISABLED_DownloadTest_History |
| 3606 #else | 3595 #else |
| 3607 #define MAYBE_DownloadTest_History DownloadTest_History | 3596 #define MAYBE_DownloadTest_History DownloadTest_History |
| 3608 #endif | 3597 #endif |
| 3609 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, MAYBE_DownloadTest_History) { | 3598 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, MAYBE_DownloadTest_History) { |
| 3610 // This starts up right after PRE_DownloadTest_History and shares the same | 3599 // This starts up right after PRE_DownloadTest_History and shares the same |
| 3611 // profile directory. | 3600 // profile directory. |
| 3612 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 3601 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 3613 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 3614 std::vector<DownloadItem*> downloads; | 3602 std::vector<DownloadItem*> downloads; |
| 3615 content::DownloadManager* manager = DownloadManagerForBrowser(browser()); | 3603 content::DownloadManager* manager = DownloadManagerForBrowser(browser()); |
| 3616 | 3604 |
| 3617 // Wait for the history to be loaded with a single DownloadItem. Check that | 3605 // Wait for the history to be loaded with a single DownloadItem. Check that |
| 3618 // it's the file that was downloaded in PRE_DownloadTest_History. | 3606 // it's the file that was downloaded in PRE_DownloadTest_History. |
| 3607 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 3619 CreatedObserver created_observer(manager); | 3608 CreatedObserver created_observer(manager); |
| 3620 created_observer.Wait(); | 3609 created_observer.Wait(); |
| 3621 manager->GetAllDownloads(&downloads); | 3610 manager->GetAllDownloads(&downloads); |
| 3622 ASSERT_EQ(1UL, downloads.size()); | 3611 ASSERT_EQ(1UL, downloads.size()); |
| 3623 DownloadItem* item = downloads[0]; | 3612 DownloadItem* item = downloads[0]; |
| 3624 EXPECT_EQ(file.value(), item->GetFullPath().BaseName().value()); | 3613 EXPECT_EQ(file.value(), item->GetFullPath().BaseName().value()); |
| 3625 EXPECT_EQ(file.value(), item->GetTargetFilePath().BaseName().value()); | 3614 EXPECT_EQ(file.value(), item->GetTargetFilePath().BaseName().value()); |
| 3626 EXPECT_EQ(download_url, item->GetURL()); | 3615 EXPECT_EQ(download_url, item->GetURL()); |
| 3627 // The following are set by download-test1.lib.mock-http-headers. | 3616 // The following are set by download-test1.lib.mock-http-headers. |
| 3628 std::string etag = item->GetETag(); | 3617 std::string etag = item->GetETag(); |
| 3629 base::TrimWhitespaceASCII(etag, base::TRIM_ALL, &etag); | 3618 base::TrimWhitespaceASCII(etag, base::TRIM_ALL, &etag); |
| 3630 EXPECT_EQ("abracadabra", etag); | 3619 EXPECT_EQ("abracadabra", etag); |
| 3631 | 3620 |
| 3632 std::string last_modified = item->GetLastModifiedTime(); | 3621 std::string last_modified = item->GetLastModifiedTime(); |
| 3633 base::TrimWhitespaceASCII(last_modified, base::TRIM_ALL, &last_modified); | 3622 base::TrimWhitespaceASCII(last_modified, base::TRIM_ALL, &last_modified); |
| 3634 EXPECT_EQ("Mon, 13 Nov 2006 20:31:09 GMT", last_modified); | 3623 EXPECT_EQ("Mon, 13 Nov 2006 20:31:09 GMT", last_modified); |
| 3635 | 3624 |
| 3636 // Downloads that were restored from history shouldn't cause the download | 3625 // Downloads that were restored from history shouldn't cause the download |
| 3637 // shelf to be displayed. | 3626 // shelf to be displayed. |
| 3638 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3627 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3639 } | 3628 } |
| 3640 | 3629 |
| 3641 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, HiddenDownload) { | 3630 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, HiddenDownload) { |
| 3642 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 3631 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 3643 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 3644 | 3632 |
| 3645 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); | 3633 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); |
| 3646 scoped_ptr<content::DownloadTestObserver> observer( | 3634 scoped_ptr<content::DownloadTestObserver> observer( |
| 3647 new content::DownloadTestObserverTerminal( | 3635 new content::DownloadTestObserverTerminal( |
| 3648 download_manager, 1, | 3636 download_manager, 1, |
| 3649 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 3637 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 3650 | 3638 |
| 3651 // Download and set IsHiddenDownload to true. | 3639 // Download and set IsHiddenDownload to true. |
| 3652 WebContents* web_contents = | 3640 WebContents* web_contents = |
| 3653 browser()->tab_strip_model()->GetActiveWebContents(); | 3641 browser()->tab_strip_model()->GetActiveWebContents(); |
| 3654 scoped_ptr<DownloadUrlParameters> params( | 3642 scoped_ptr<DownloadUrlParameters> params( |
| 3655 DownloadUrlParameters::FromWebContents(web_contents, url)); | 3643 DownloadUrlParameters::FromWebContents(web_contents, url)); |
| 3656 params->set_callback(base::Bind(&SetHiddenDownloadCallback)); | 3644 params->set_callback(base::Bind(&SetHiddenDownloadCallback)); |
| 3657 download_manager->DownloadUrl(params.Pass()); | 3645 download_manager->DownloadUrl(params.Pass()); |
| 3658 observer->WaitForFinished(); | 3646 observer->WaitForFinished(); |
| 3659 | 3647 |
| 3660 // Verify that download shelf is not shown. | 3648 // Verify that download shelf is not shown. |
| 3661 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3649 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3662 } | 3650 } |
| 3663 | 3651 |
| 3664 // Test to make sure auto-open works. | 3652 // Test to make sure auto-open works. |
| 3665 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, AutoOpen) { | 3653 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, AutoOpen) { |
| 3666 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); | 3654 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); |
| 3667 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 3655 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-autoopen.txt")); |
| 3668 | 3656 |
| 3669 ASSERT_TRUE( | 3657 ASSERT_TRUE( |
| 3670 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 3658 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
| 3671 | 3659 |
| 3672 DownloadAndWait(browser(), url); | 3660 DownloadAndWait(browser(), url); |
| 3673 | 3661 |
| 3674 // Download shelf should close. Download panel stays open on ChromeOS. | 3662 // Download shelf should close. Download panel stays open on ChromeOS. |
| 3675 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3663 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3676 } | 3664 } |
| 3677 | 3665 |
| 3678 // Download an extension. Expect a dangerous download warning. | 3666 // Download an extension. Expect a dangerous download warning. |
| 3679 // Deny the download. | 3667 // Deny the download. |
| 3680 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, CrxDenyInstall) { | 3668 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, CrxDenyInstall) { |
| 3681 FeatureSwitch::ScopedOverride enable_easy_off_store_install( | 3669 FeatureSwitch::ScopedOverride enable_easy_off_store_install( |
| 3682 FeatureSwitch::easy_off_store_install(), true); | 3670 FeatureSwitch::easy_off_store_install(), true); |
| 3683 | 3671 |
| 3684 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 3672 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 3685 | 3673 |
| 3686 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( | 3674 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( |
| 3687 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 3675 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 3688 ui_test_utils::NavigateToURL(browser(), extension_url); | 3676 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 3689 | 3677 |
| 3690 observer->WaitForFinished(); | 3678 observer->WaitForFinished(); |
| 3691 | 3679 |
| 3692 // Download shelf should close. | 3680 // Download shelf should close. |
| 3693 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3681 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3694 } | 3682 } |
| OLD | NEW |