Chromium Code Reviews| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 } | 234 } |
| 235 | 235 |
| 236 bool was_previously_resumable_; | 236 bool was_previously_resumable_; |
| 237 size_t transitions_left_; | 237 size_t transitions_left_; |
| 238 | 238 |
| 239 DISALLOW_COPY_AND_ASSIGN(DownloadTestObserverResumable); | 239 DISALLOW_COPY_AND_ASSIGN(DownloadTestObserverResumable); |
| 240 }; | 240 }; |
| 241 | 241 |
| 242 // IDs and paths of CRX files used in tests. | 242 // IDs and paths of CRX files used in tests. |
| 243 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 243 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 244 const base::FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); | 244 const char kGoodCrxPath[] = "extensions/good.crx"; |
| 245 | 245 |
| 246 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; | 246 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
| 247 const base::FilePath kLargeThemePath( | 247 const char kLargeThemePath[] = "extensions/theme2.crx"; |
| 248 FILE_PATH_LITERAL("extensions/theme2.crx")); | |
| 249 | 248 |
| 250 // Get History Information. | 249 // Get History Information. |
| 251 class DownloadsHistoryDataCollector { | 250 class DownloadsHistoryDataCollector { |
| 252 public: | 251 public: |
| 253 explicit DownloadsHistoryDataCollector(Profile* profile) | 252 explicit DownloadsHistoryDataCollector(Profile* profile) |
| 254 : profile_(profile), result_valid_(false) {} | 253 : profile_(profile), result_valid_(false) {} |
| 255 | 254 |
| 256 bool WaitForDownloadInfo( | 255 bool WaitForDownloadInfo( |
| 257 scoped_ptr<std::vector<history::DownloadRow> >* results) { | 256 scoped_ptr<std::vector<history::DownloadRow> >* results) { |
| 258 history::HistoryService* hs = HistoryServiceFactory::GetForProfile( | 257 history::HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| (...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1065 // This method: | 1064 // This method: |
| 1066 // * Starts a mock download by navigating browser() to a URLRequestMockHTTPJob | 1065 // * Starts a mock download by navigating browser() to a URLRequestMockHTTPJob |
| 1067 // mock URL. | 1066 // mock URL. |
| 1068 // * Injects |error| on the first write using |error_injector|. | 1067 // * Injects |error| on the first write using |error_injector|. |
| 1069 // * Waits for the download to be interrupted. | 1068 // * Waits for the download to be interrupted. |
| 1070 // * Clears the errors on |error_injector|. | 1069 // * Clears the errors on |error_injector|. |
| 1071 // * Returns the resulting interrupted download. | 1070 // * Returns the resulting interrupted download. |
| 1072 DownloadItem* StartMockDownloadAndInjectError( | 1071 DownloadItem* StartMockDownloadAndInjectError( |
| 1073 content::TestFileErrorInjector* error_injector, | 1072 content::TestFileErrorInjector* error_injector, |
| 1074 content::DownloadInterruptReason error) { | 1073 content::DownloadInterruptReason error) { |
| 1075 base::FilePath file_path(FILE_PATH_LITERAL("download-test1.lib")); | 1074 GURL url = URLRequestMockHTTPJob::GetMockUrl("download-test1.lib"); |
| 1076 GURL url = URLRequestMockHTTPJob::GetMockUrl(file_path); | |
| 1077 | 1075 |
| 1078 content::TestFileErrorInjector::FileErrorInfo error_info; | 1076 content::TestFileErrorInjector::FileErrorInfo error_info; |
| 1079 error_info.url = url.spec(); | 1077 error_info.url = url.spec(); |
| 1080 error_info.code = content::TestFileErrorInjector::FILE_OPERATION_WRITE; | 1078 error_info.code = content::TestFileErrorInjector::FILE_OPERATION_WRITE; |
| 1081 error_info.operation_instance = 0; | 1079 error_info.operation_instance = 0; |
| 1082 error_info.error = error; | 1080 error_info.error = error; |
| 1083 error_injector->ClearErrors(); | 1081 error_injector->ClearErrors(); |
| 1084 error_injector->AddError(error_info); | 1082 error_injector->AddError(error_info); |
| 1085 error_injector->InjectErrors(); | 1083 error_injector->InjectErrors(); |
| 1086 | 1084 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1123 }; | 1121 }; |
| 1124 | 1122 |
| 1125 // NOTES: | 1123 // NOTES: |
| 1126 // | 1124 // |
| 1127 // Files for these tests are found in DIR_TEST_DATA (currently | 1125 // Files for these tests are found in DIR_TEST_DATA (currently |
| 1128 // "chrome\test\data\", see chrome_paths.cc). | 1126 // "chrome\test\data\", see chrome_paths.cc). |
| 1129 // Mock responses have extension .mock-http-headers appended to the file name. | 1127 // Mock responses have extension .mock-http-headers appended to the file name. |
| 1130 | 1128 |
| 1131 // Download a file due to the associated MIME type. | 1129 // Download a file due to the associated MIME type. |
| 1132 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { | 1130 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { |
| 1133 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1131 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
|
mmenke
2015/10/14 16:43:20
Suggest making the path a constant char[] (Either
tfarina
2015/10/17 22:24:44
Done.
| |
| 1134 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1135 | 1132 |
| 1136 // Download the file and wait. We do not expect the Select File dialog. | 1133 // Download the file and wait. We do not expect the Select File dialog. |
| 1137 DownloadAndWait(browser(), url); | 1134 DownloadAndWait(browser(), url); |
| 1138 | 1135 |
| 1139 // Check state. | 1136 // Check state. |
| 1140 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1137 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1138 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
| 1141 CheckDownload(browser(), file, file); | 1139 CheckDownload(browser(), file, file); |
| 1142 } | 1140 } |
| 1143 | 1141 |
| 1144 #if defined(OS_WIN) | 1142 #if defined(OS_WIN) |
| 1145 // Download a file and confirm that the zone identifier (on windows) | 1143 // Download a file and confirm that the zone identifier (on windows) |
| 1146 // is set to internet. | 1144 // is set to internet. |
| 1147 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { | 1145 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { |
| 1148 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1146 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
| 1149 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1150 | 1147 |
| 1151 // Download the file and wait. We do not expect the Select File dialog. | 1148 // Download the file and wait. We do not expect the Select File dialog. |
| 1152 DownloadAndWait(browser(), url); | 1149 DownloadAndWait(browser(), url); |
| 1153 | 1150 |
| 1154 // Check state. Special file state must be checked before CheckDownload, | 1151 // Check state. Special file state must be checked before CheckDownload, |
| 1155 // as CheckDownload will delete the output file. | 1152 // as CheckDownload will delete the output file. |
| 1156 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1153 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1154 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
| 1157 base::FilePath downloaded_file(DestinationFile(browser(), file)); | 1155 base::FilePath downloaded_file(DestinationFile(browser(), file)); |
| 1158 if (base::VolumeSupportsADS(downloaded_file)) | 1156 if (base::VolumeSupportsADS(downloaded_file)) |
| 1159 EXPECT_TRUE(base::HasInternetZoneIdentifier(downloaded_file)); | 1157 EXPECT_TRUE(base::HasInternetZoneIdentifier(downloaded_file)); |
| 1160 CheckDownload(browser(), file, file); | 1158 CheckDownload(browser(), file, file); |
| 1161 } | 1159 } |
| 1162 #endif | 1160 #endif |
| 1163 | 1161 |
| 1164 // Put up a Select File dialog when the file is downloaded, due to | 1162 // Put up a Select File dialog when the file is downloaded, due to |
| 1165 // downloads preferences settings. | 1163 // downloads preferences settings. |
| 1166 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { | 1164 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { |
| 1167 // Re-enable prompting. | 1165 // Re-enable prompting. |
| 1168 browser()->profile()->GetPrefs()->SetBoolean( | 1166 browser()->profile()->GetPrefs()->SetBoolean( |
| 1169 prefs::kPromptForDownload, true); | 1167 prefs::kPromptForDownload, true); |
| 1170 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1168 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
| 1171 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1172 | 1169 |
| 1173 EnableFileChooser(true); | 1170 EnableFileChooser(true); |
| 1174 | 1171 |
| 1175 // Download the file and wait. We expect the Select File dialog to appear | 1172 // Download the file and wait. We expect the Select File dialog to appear |
| 1176 // due to the MIME type, but we still wait until the download completes. | 1173 // due to the MIME type, but we still wait until the download completes. |
| 1177 scoped_ptr<content::DownloadTestObserver> observer( | 1174 scoped_ptr<content::DownloadTestObserver> observer( |
| 1178 new content::DownloadTestObserverTerminal( | 1175 new content::DownloadTestObserverTerminal( |
| 1179 DownloadManagerForBrowser(browser()), | 1176 DownloadManagerForBrowser(browser()), |
| 1180 1, | 1177 1, |
| 1181 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1178 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1182 ui_test_utils::NavigateToURL(browser(), url); | 1179 ui_test_utils::NavigateToURL(browser(), url); |
| 1183 observer->WaitForFinished(); | 1180 observer->WaitForFinished(); |
| 1184 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1181 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1185 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1182 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1186 EXPECT_TRUE(DidShowFileChooser()); | 1183 EXPECT_TRUE(DidShowFileChooser()); |
| 1187 | 1184 |
| 1188 // Check state. | 1185 // Check state. |
| 1189 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1186 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1187 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
| 1190 CheckDownload(browser(), file, file); | 1188 CheckDownload(browser(), file, file); |
| 1191 } | 1189 } |
| 1192 | 1190 |
| 1193 // Access a file with a viewable mime-type, verify that a download | 1191 // Access a file with a viewable mime-type, verify that a download |
| 1194 // did not initiate. | 1192 // did not initiate. |
| 1195 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { | 1193 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { |
| 1196 base::FilePath file(FILE_PATH_LITERAL("download-test2.html")); | 1194 base::FilePath file(FILE_PATH_LITERAL("download-test2.html")); |
| 1197 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1195 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test2.html")); |
| 1198 base::FilePath file_path(DestinationFile(browser(), file)); | 1196 base::FilePath file_path(DestinationFile(browser(), file)); |
| 1199 | 1197 |
| 1200 // Open a web page and wait. | 1198 // Open a web page and wait. |
| 1201 ui_test_utils::NavigateToURL(browser(), url); | 1199 ui_test_utils::NavigateToURL(browser(), url); |
| 1202 | 1200 |
| 1203 // Check that we did not download the web page. | 1201 // Check that we did not download the web page. |
| 1204 EXPECT_FALSE(base::PathExists(file_path)); | 1202 EXPECT_FALSE(base::PathExists(file_path)); |
| 1205 | 1203 |
| 1206 // Check state. | 1204 // Check state. |
| 1207 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1205 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1263 EXPECT_TRUE(VerifyNoDownloads()); | 1261 EXPECT_TRUE(VerifyNoDownloads()); |
| 1264 } | 1262 } |
| 1265 } | 1263 } |
| 1266 | 1264 |
| 1267 // Verify that when the DownloadResourceThrottle cancels a download, the | 1265 // Verify that when the DownloadResourceThrottle cancels a download, the |
| 1268 // download never makes it to the downloads system. | 1266 // download never makes it to the downloads system. |
| 1269 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadResourceThrottleCancels) { | 1267 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadResourceThrottleCancels) { |
| 1270 // Navigate to a page with the same domain as the file to download. We can't | 1268 // Navigate to a page with the same domain as the file to download. We can't |
| 1271 // navigate directly to the file we don't want to download because cross-site | 1269 // navigate directly to the file we don't want to download because cross-site |
| 1272 // navigations reset the TabDownloadState. | 1270 // navigations reset the TabDownloadState. |
| 1273 base::FilePath same_site_path(FILE_PATH_LITERAL("download_script.html")); | 1271 GURL same_site_url(URLRequestMockHTTPJob::GetMockUrl("download_script.html")); |
| 1274 GURL same_site_url(URLRequestMockHTTPJob::GetMockUrl(same_site_path)); | |
| 1275 ui_test_utils::NavigateToURL(browser(), same_site_url); | 1272 ui_test_utils::NavigateToURL(browser(), same_site_url); |
| 1276 | 1273 |
| 1277 // Make sure the initial navigation didn't trigger a download. | 1274 // Make sure the initial navigation didn't trigger a download. |
| 1278 EXPECT_TRUE(VerifyNoDownloads()); | 1275 EXPECT_TRUE(VerifyNoDownloads()); |
| 1279 | 1276 |
| 1280 // Disable downloads for the tab. | 1277 // Disable downloads for the tab. |
| 1281 WebContents* web_contents = | 1278 WebContents* web_contents = |
| 1282 browser()->tab_strip_model()->GetActiveWebContents(); | 1279 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1283 DownloadRequestLimiter::TabDownloadState* tab_download_state = | 1280 DownloadRequestLimiter::TabDownloadState* tab_download_state = |
| 1284 g_browser_process->download_request_limiter()->GetDownloadState( | 1281 g_browser_process->download_request_limiter()->GetDownloadState( |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1309 // Verify that there's no pending download. The resource throttle | 1306 // Verify that there's no pending download. The resource throttle |
| 1310 // should have deleted it before it created a download item, so it | 1307 // should have deleted it before it created a download item, so it |
| 1311 // shouldn't be available as a cancelled download either. | 1308 // shouldn't be available as a cancelled download either. |
| 1312 EXPECT_TRUE(VerifyNoDownloads()); | 1309 EXPECT_TRUE(VerifyNoDownloads()); |
| 1313 } | 1310 } |
| 1314 | 1311 |
| 1315 // Download a 0-size file with a content-disposition header, verify that the | 1312 // Download a 0-size file with a content-disposition header, verify that the |
| 1316 // download tab opened and the file exists as the filename specified in the | 1313 // download tab opened and the file exists as the filename specified in the |
| 1317 // header. This also ensures we properly handle empty file downloads. | 1314 // header. This also ensures we properly handle empty file downloads. |
| 1318 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { | 1315 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { |
| 1319 base::FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 1316 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test3.gif")); |
| 1320 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1321 base::FilePath download_file( | 1317 base::FilePath download_file( |
| 1322 FILE_PATH_LITERAL("download-test3-attachment.gif")); | 1318 FILE_PATH_LITERAL("download-test3-attachment.gif")); |
| 1323 | 1319 |
| 1324 // Download a file and wait. | 1320 // Download a file and wait. |
| 1325 DownloadAndWait(browser(), url); | 1321 DownloadAndWait(browser(), url); |
| 1326 | 1322 |
| 1323 base::FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | |
| 1327 CheckDownload(browser(), download_file, file); | 1324 CheckDownload(browser(), download_file, file); |
| 1328 | 1325 |
| 1329 // Check state. | 1326 // Check state. |
| 1330 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1327 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1331 } | 1328 } |
| 1332 | 1329 |
| 1333 // UnknownSize and KnownSize are tests which depend on | 1330 // UnknownSize and KnownSize are tests which depend on |
| 1334 // URLRequestSlowDownloadJob to serve content in a certain way. Data will be | 1331 // URLRequestSlowDownloadJob to serve content in a certain way. Data will be |
| 1335 // sent in two chunks where the first chunk is 35K and the second chunk is 10K. | 1332 // sent in two chunks where the first chunk is 35K and the second chunk is 10K. |
| 1336 // The test will first attempt to download a file; but the server will "pause" | 1333 // The test will first attempt to download a file; but the server will "pause" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1351 // Test that when downloading an item in Incognito mode, we don't crash when | 1348 // Test that when downloading an item in Incognito mode, we don't crash when |
| 1352 // closing the last Incognito window (http://crbug.com/13983). | 1349 // closing the last Incognito window (http://crbug.com/13983). |
| 1353 IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) { | 1350 IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) { |
| 1354 Browser* incognito = CreateIncognitoBrowser(); | 1351 Browser* incognito = CreateIncognitoBrowser(); |
| 1355 ASSERT_TRUE(incognito); | 1352 ASSERT_TRUE(incognito); |
| 1356 int window_count = chrome::GetTotalBrowserCount(); | 1353 int window_count = chrome::GetTotalBrowserCount(); |
| 1357 EXPECT_EQ(2, window_count); | 1354 EXPECT_EQ(2, window_count); |
| 1358 | 1355 |
| 1359 // Download a file in the Incognito window and wait. | 1356 // Download a file in the Incognito window and wait. |
| 1360 CreateAndSetDownloadsDirectory(incognito); | 1357 CreateAndSetDownloadsDirectory(incognito); |
| 1361 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1358 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
| 1362 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1363 // Since |incognito| is a separate browser, we have to set it up explicitly. | 1359 // Since |incognito| is a separate browser, we have to set it up explicitly. |
| 1364 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, | 1360 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, |
| 1365 false); | 1361 false); |
| 1366 DownloadAndWait(incognito, url); | 1362 DownloadAndWait(incognito, url); |
| 1367 | 1363 |
| 1368 // We should still have 2 windows. | 1364 // We should still have 2 windows. |
| 1369 ExpectWindowCountAfterDownload(2); | 1365 ExpectWindowCountAfterDownload(2); |
| 1370 | 1366 |
| 1371 #if !defined(OS_MACOSX) | 1367 #if !defined(OS_MACOSX) |
| 1372 // On Mac OS X, the UI window close is delayed until the outermost | 1368 // On Mac OS X, the UI window close is delayed until the outermost |
| 1373 // message loop runs. So it isn't possible to get a BROWSER_CLOSED | 1369 // message loop runs. So it isn't possible to get a BROWSER_CLOSED |
| 1374 // notification inside of a test. | 1370 // notification inside of a test. |
| 1375 content::WindowedNotificationObserver signal( | 1371 content::WindowedNotificationObserver signal( |
| 1376 chrome::NOTIFICATION_BROWSER_CLOSED, | 1372 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 1377 content::Source<Browser>(incognito)); | 1373 content::Source<Browser>(incognito)); |
| 1378 #endif | 1374 #endif |
| 1379 | 1375 |
| 1380 // Close the Incognito window and don't crash. | 1376 // Close the Incognito window and don't crash. |
| 1381 chrome::CloseWindow(incognito); | 1377 chrome::CloseWindow(incognito); |
| 1382 | 1378 |
| 1383 #if !defined(OS_MACOSX) | 1379 #if !defined(OS_MACOSX) |
| 1384 signal.Wait(); | 1380 signal.Wait(); |
| 1385 ExpectWindowCountAfterDownload(1); | 1381 ExpectWindowCountAfterDownload(1); |
| 1386 #endif | 1382 #endif |
| 1387 | 1383 |
| 1384 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
| 1388 CheckDownload(browser(), file, file); | 1385 CheckDownload(browser(), file, file); |
| 1389 } | 1386 } |
| 1390 | 1387 |
| 1391 // Download one file on-record, then download the same file off-record, and test | 1388 // Download one file on-record, then download the same file off-record, and test |
| 1392 // that the filename is deduplicated. The previous test tests for a specific | 1389 // that the filename is deduplicated. The previous test tests for a specific |
| 1393 // bug; this next test tests that filename deduplication happens independently | 1390 // bug; this next test tests that filename deduplication happens independently |
| 1394 // of DownloadManager/CDMD. | 1391 // of DownloadManager/CDMD. |
| 1395 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_IncognitoRegular) { | 1392 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_IncognitoRegular) { |
| 1396 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("downloads/a_zip_file.zip"); | 1393 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("downloads/a_zip_file.zip"); |
| 1397 | 1394 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1452 download_items[0]->GetTargetFilePath().BaseName()); | 1449 download_items[0]->GetTargetFilePath().BaseName()); |
| 1453 ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath())); | 1450 ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath())); |
| 1454 EXPECT_TRUE(VerifyFile(download_items[0]->GetTargetFilePath(), | 1451 EXPECT_TRUE(VerifyFile(download_items[0]->GetTargetFilePath(), |
| 1455 original_contents, origin_file_size)); | 1452 original_contents, origin_file_size)); |
| 1456 } | 1453 } |
| 1457 | 1454 |
| 1458 // Navigate to a new background page, but don't download. | 1455 // Navigate to a new background page, but don't download. |
| 1459 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) { | 1456 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) { |
| 1460 // Because it's an HTML link, it should open a web page rather than | 1457 // Because it's an HTML link, it should open a web page rather than |
| 1461 // downloading. | 1458 // downloading. |
| 1462 base::FilePath file1(FILE_PATH_LITERAL("download-test2.html")); | 1459 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test2.html")); |
| 1463 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | |
| 1464 | 1460 |
| 1465 // Open a web page and wait. | 1461 // Open a web page and wait. |
| 1466 ui_test_utils::NavigateToURLWithDisposition( | 1462 ui_test_utils::NavigateToURLWithDisposition( |
| 1467 browser(), | 1463 browser(), |
| 1468 url, | 1464 url, |
| 1469 NEW_BACKGROUND_TAB, | 1465 NEW_BACKGROUND_TAB, |
| 1470 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1466 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1471 | 1467 |
| 1472 // We should have two tabs now. | 1468 // We should have two tabs now. |
| 1473 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 1469 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 1474 EXPECT_TRUE(VerifyNoDownloads()); | 1470 EXPECT_TRUE(VerifyNoDownloads()); |
| 1475 } | 1471 } |
| 1476 | 1472 |
| 1477 // Download a file in a background tab. Verify that the tab is closed | 1473 // Download a file in a background tab. Verify that the tab is closed |
| 1478 // automatically. | 1474 // automatically. |
| 1479 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) { | 1475 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) { |
| 1480 // Download a file in a new background tab and wait. The tab is automatically | 1476 // Download a file in a new background tab and wait. The tab is automatically |
| 1481 // closed when the download begins. | 1477 // closed when the download begins. |
| 1482 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1478 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
| 1483 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1484 DownloadAndWaitWithDisposition( | 1479 DownloadAndWaitWithDisposition( |
| 1485 browser(), | 1480 browser(), |
| 1486 url, | 1481 url, |
| 1487 NEW_BACKGROUND_TAB, | 1482 NEW_BACKGROUND_TAB, |
| 1488 0); | 1483 0); |
| 1489 | 1484 |
| 1490 // When the download finishes, we should still have one tab. | 1485 // When the download finishes, we should still have one tab. |
| 1491 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1486 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1492 | 1487 |
| 1488 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
| 1493 CheckDownload(browser(), file, file); | 1489 CheckDownload(browser(), file, file); |
| 1494 } | 1490 } |
| 1495 | 1491 |
| 1496 // Open a web page in the current tab, then download a file in another tab via | 1492 // Open a web page in the current tab, then download a file in another tab via |
| 1497 // a Javascript call. | 1493 // a Javascript call. |
| 1498 // Verify that we have 2 tabs. | 1494 // Verify that we have 2 tabs. |
| 1499 // | 1495 // |
| 1500 // The download_page1.html page contains an openNew() function that opens a | 1496 // The download_page1.html page contains an openNew() function that opens a |
| 1501 // tab and then downloads download-test1.lib. | 1497 // tab and then downloads download-test1.lib. |
| 1502 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab2) { | 1498 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab2) { |
| 1503 // Because it's an HTML link, it should open a web page rather than | 1499 // Because it's an HTML link, it should open a web page rather than |
| 1504 // downloading. | 1500 // downloading. |
| 1505 base::FilePath file1(FILE_PATH_LITERAL("download_page1.html")); | 1501 GURL url(URLRequestMockHTTPJob::GetMockUrl("download_page1.html")); |
| 1506 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | |
| 1507 | 1502 |
| 1508 // Open a web page and wait. | 1503 // Open a web page and wait. |
| 1509 ui_test_utils::NavigateToURL(browser(), url); | 1504 ui_test_utils::NavigateToURL(browser(), url); |
| 1510 | 1505 |
| 1511 // Download a file in a new tab and wait (via Javascript). | 1506 // Download a file in a new tab and wait (via Javascript). |
| 1512 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1507 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1513 DownloadAndWaitWithDisposition(browser(), | 1508 DownloadAndWaitWithDisposition(browser(), |
| 1514 GURL("javascript:openNew()"), | 1509 GURL("javascript:openNew()"), |
| 1515 CURRENT_TAB, | 1510 CURRENT_TAB, |
| 1516 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1511 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 1517 | 1512 |
| 1518 // When the download finishes, we should have two tabs. | 1513 // When the download finishes, we should have two tabs. |
| 1519 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 1514 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 1520 | 1515 |
| 1521 CheckDownload(browser(), file, file); | 1516 CheckDownload(browser(), file, file); |
| 1522 } | 1517 } |
| 1523 | 1518 |
| 1524 // Open a web page in the current tab, open another tab via a Javascript call, | 1519 // Open a web page in the current tab, open another tab via a Javascript call, |
| 1525 // then download a file in the new tab. | 1520 // then download a file in the new tab. |
| 1526 // Verify that we have 2 tabs. | 1521 // Verify that we have 2 tabs. |
| 1527 // | 1522 // |
| 1528 // The download_page2.html page contains an openNew() function that opens a | 1523 // The download_page2.html page contains an openNew() function that opens a |
| 1529 // tab. | 1524 // tab. |
| 1530 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab3) { | 1525 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab3) { |
| 1531 // Because it's an HTML link, it should open a web page rather than | 1526 // Because it's an HTML link, it should open a web page rather than |
| 1532 // downloading. | 1527 // downloading. |
| 1533 base::FilePath file1(FILE_PATH_LITERAL("download_page2.html")); | 1528 GURL url1(URLRequestMockHTTPJob::GetMockUrl("download_page2.html")); |
| 1534 GURL url1(URLRequestMockHTTPJob::GetMockUrl(file1)); | |
| 1535 | 1529 |
| 1536 // Open a web page and wait. | 1530 // Open a web page and wait. |
| 1537 ui_test_utils::NavigateToURL(browser(), url1); | 1531 ui_test_utils::NavigateToURL(browser(), url1); |
| 1538 | 1532 |
| 1539 // Open a new tab and wait. | 1533 // Open a new tab and wait. |
| 1540 ui_test_utils::NavigateToURLWithDisposition( | 1534 ui_test_utils::NavigateToURLWithDisposition( |
| 1541 browser(), | 1535 browser(), |
| 1542 GURL("javascript:openNew()"), | 1536 GURL("javascript:openNew()"), |
| 1543 CURRENT_TAB, | 1537 CURRENT_TAB, |
| 1544 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1538 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 1545 | 1539 |
| 1546 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 1540 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 1547 | 1541 |
| 1548 // Download a file and wait. | 1542 // Download a file and wait. |
| 1549 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1543 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
| 1550 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1551 DownloadAndWaitWithDisposition(browser(), | 1544 DownloadAndWaitWithDisposition(browser(), |
| 1552 url, | 1545 url, |
| 1553 CURRENT_TAB, | 1546 CURRENT_TAB, |
| 1554 ui_test_utils::BROWSER_TEST_NONE); | 1547 ui_test_utils::BROWSER_TEST_NONE); |
| 1555 | 1548 |
| 1556 // When the download finishes, we should have two tabs. | 1549 // When the download finishes, we should have two tabs. |
| 1557 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 1550 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 1558 | 1551 |
| 1552 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
| 1559 CheckDownload(browser(), file, file); | 1553 CheckDownload(browser(), file, file); |
| 1560 } | 1554 } |
| 1561 | 1555 |
| 1562 // Open a web page in the current tab, then download a file via Javascript, | 1556 // Open a web page in the current tab, then download a file via Javascript, |
| 1563 // which will do so in a temporary tab. Verify that we have 1 tab. | 1557 // which will do so in a temporary tab. Verify that we have 1 tab. |
| 1564 // | 1558 // |
| 1565 // The download_page3.html page contains an openNew() function that opens a | 1559 // The download_page3.html page contains an openNew() function that opens a |
| 1566 // tab with download-test1.lib in the URL. When the URL is determined to be | 1560 // tab with download-test1.lib in the URL. When the URL is determined to be |
| 1567 // a download, the tab is closed automatically. | 1561 // a download, the tab is closed automatically. |
| 1568 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab2) { | 1562 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab2) { |
| 1569 // Because it's an HTML link, it should open a web page rather than | 1563 // Because it's an HTML link, it should open a web page rather than |
| 1570 // downloading. | 1564 // downloading. |
| 1571 base::FilePath file1(FILE_PATH_LITERAL("download_page3.html")); | 1565 GURL url(URLRequestMockHTTPJob::GetMockUrl("download_page3.html")); |
| 1572 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | |
| 1573 | 1566 |
| 1574 // Open a web page and wait. | 1567 // Open a web page and wait. |
| 1575 ui_test_utils::NavigateToURL(browser(), url); | 1568 ui_test_utils::NavigateToURL(browser(), url); |
| 1576 | 1569 |
| 1577 // Download a file and wait. | 1570 // Download a file and wait. |
| 1578 // The file to download is "download-test1.lib". | 1571 // The file to download is "download-test1.lib". |
| 1579 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1572 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1580 DownloadAndWaitWithDisposition(browser(), | 1573 DownloadAndWaitWithDisposition(browser(), |
| 1581 GURL("javascript:openNew()"), | 1574 GURL("javascript:openNew()"), |
| 1582 CURRENT_TAB, | 1575 CURRENT_TAB, |
| 1583 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1576 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 1584 | 1577 |
| 1585 // When the download finishes, we should still have one tab. | 1578 // When the download finishes, we should still have one tab. |
| 1586 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1579 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1587 | 1580 |
| 1588 CheckDownload(browser(), file, file); | 1581 CheckDownload(browser(), file, file); |
| 1589 } | 1582 } |
| 1590 | 1583 |
| 1591 // Open a web page in the current tab, then call Javascript via a button to | 1584 // Open a web page in the current tab, then call Javascript via a button to |
| 1592 // download a file in a new tab, which is closed automatically when the | 1585 // download a file in a new tab, which is closed automatically when the |
| 1593 // download begins. | 1586 // download begins. |
| 1594 // Verify that we have 1 tab. | 1587 // Verify that we have 1 tab. |
| 1595 // | 1588 // |
| 1596 // The download_page4.html page contains a form with download-test1.lib as the | 1589 // The download_page4.html page contains a form with download-test1.lib as the |
| 1597 // action. | 1590 // action. |
| 1598 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab3) { | 1591 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab3) { |
| 1599 // Because it's an HTML link, it should open a web page rather than | 1592 // Because it's an HTML link, it should open a web page rather than |
| 1600 // downloading. | 1593 // downloading. |
| 1601 base::FilePath file1(FILE_PATH_LITERAL("download_page4.html")); | 1594 GURL url(URLRequestMockHTTPJob::GetMockUrl("download_page4.html")); |
| 1602 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | |
| 1603 | 1595 |
| 1604 // Open a web page and wait. | 1596 // Open a web page and wait. |
| 1605 ui_test_utils::NavigateToURL(browser(), url); | 1597 ui_test_utils::NavigateToURL(browser(), url); |
| 1606 | 1598 |
| 1607 // Download a file in a new tab and wait. The tab will automatically close | 1599 // Download a file in a new tab and wait. The tab will automatically close |
| 1608 // when the download begins. | 1600 // when the download begins. |
| 1609 // The file to download is "download-test1.lib". | 1601 // The file to download is "download-test1.lib". |
| 1610 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1602 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1611 DownloadAndWaitWithDisposition( | 1603 DownloadAndWaitWithDisposition( |
| 1612 browser(), | 1604 browser(), |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1746 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 1738 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 1747 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1739 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1748 switches::kAshBrowserTests)) | 1740 switches::kAshBrowserTests)) |
| 1749 return; | 1741 return; |
| 1750 #endif | 1742 #endif |
| 1751 // Disable SafeBrowsing so that danger will be determined by downloads system. | 1743 // Disable SafeBrowsing so that danger will be determined by downloads system. |
| 1752 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, | 1744 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, |
| 1753 false); | 1745 false); |
| 1754 | 1746 |
| 1755 // .swf file so that it's dangerous on all platforms (including CrOS). | 1747 // .swf file so that it's dangerous on all platforms (including CrOS). |
| 1756 base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf")); | 1748 GURL download_url( |
| 1757 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1749 URLRequestMockHTTPJob::GetMockUrl("downloads/dangerous/dangerous.swf")); |
| 1758 | 1750 |
| 1759 // Download the url and wait until the object has been stored. | 1751 // Download the url and wait until the object has been stored. |
| 1760 scoped_ptr<content::DownloadTestObserver> download_observer( | 1752 scoped_ptr<content::DownloadTestObserver> download_observer( |
| 1761 new content::DownloadTestObserverTerminal( | 1753 new content::DownloadTestObserverTerminal( |
| 1762 DownloadManagerForBrowser(browser()), 1, | 1754 DownloadManagerForBrowser(browser()), 1, |
| 1763 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_IGNORE)); | 1755 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_IGNORE)); |
| 1764 base::Time start(base::Time::Now()); | 1756 base::Time start(base::Time::Now()); |
| 1765 HistoryObserver observer(browser()->profile()); | 1757 HistoryObserver observer(browser()->profile()); |
| 1766 observer.SetFilterCallback(base::Bind(&HasDataAndName)); | 1758 observer.SetFilterCallback(base::Bind(&HasDataAndName)); |
| 1767 ui_test_utils::NavigateToURL(browser(), download_url); | 1759 ui_test_utils::NavigateToURL(browser(), download_url); |
| 1768 observer.WaitForStored(); | 1760 observer.WaitForStored(); |
| 1769 | 1761 |
| 1770 // Get the details on what was stored into the history. | 1762 // Get the details on what was stored into the history. |
| 1771 scoped_ptr<std::vector<history::DownloadRow> > downloads_in_database; | 1763 scoped_ptr<std::vector<history::DownloadRow> > downloads_in_database; |
| 1772 ASSERT_TRUE(DownloadsHistoryDataCollector( | 1764 ASSERT_TRUE(DownloadsHistoryDataCollector( |
| 1773 browser()->profile()).WaitForDownloadInfo(&downloads_in_database)); | 1765 browser()->profile()).WaitForDownloadInfo(&downloads_in_database)); |
| 1774 ASSERT_EQ(1u, downloads_in_database->size()); | 1766 ASSERT_EQ(1u, downloads_in_database->size()); |
| 1775 | 1767 |
| 1776 // Confirm history storage is what you expect for an unvalidated | 1768 // Confirm history storage is what you expect for an unvalidated |
| 1777 // dangerous file. | 1769 // dangerous file. |
| 1770 base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf")); | |
| 1778 history::DownloadRow& row(downloads_in_database->at(0)); | 1771 history::DownloadRow& row(downloads_in_database->at(0)); |
| 1779 EXPECT_EQ(DestinationFile(browser(), file), row.target_path); | 1772 EXPECT_EQ(DestinationFile(browser(), file), row.target_path); |
| 1780 EXPECT_NE(DownloadTargetDeterminer::GetCrDownloadPath( | 1773 EXPECT_NE(DownloadTargetDeterminer::GetCrDownloadPath( |
| 1781 DestinationFile(browser(), file)), | 1774 DestinationFile(browser(), file)), |
| 1782 row.current_path); | 1775 row.current_path); |
| 1783 EXPECT_EQ(history::DownloadDangerType::DANGEROUS_FILE, row.danger_type); | 1776 EXPECT_EQ(history::DownloadDangerType::DANGEROUS_FILE, row.danger_type); |
| 1784 EXPECT_LE(start, row.start_time); | 1777 EXPECT_LE(start, row.start_time); |
| 1785 EXPECT_EQ(history::DownloadState::IN_PROGRESS, row.state); | 1778 EXPECT_EQ(history::DownloadState::IN_PROGRESS, row.state); |
| 1786 EXPECT_FALSE(row.opened); | 1779 EXPECT_FALSE(row.opened); |
| 1787 | 1780 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1806 EXPECT_FALSE(row1.opened); | 1799 EXPECT_FALSE(row1.opened); |
| 1807 // Not checking file size--not relevant to the point of the test, and | 1800 // Not checking file size--not relevant to the point of the test, and |
| 1808 // the file size is actually different on Windows and other platforms, | 1801 // the file size is actually different on Windows and other platforms, |
| 1809 // because for source control simplicity it's actually a text file, and | 1802 // because for source control simplicity it's actually a text file, and |
| 1810 // there are CRLF transformations for those files. | 1803 // there are CRLF transformations for those files. |
| 1811 } | 1804 } |
| 1812 | 1805 |
| 1813 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 1806 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
| 1814 // after download of a file while viewing another chrome://. | 1807 // after download of a file while viewing another chrome://. |
| 1815 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { | 1808 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { |
| 1816 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1809 GURL download_url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
| 1817 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1818 GURL flags_url(chrome::kChromeUIFlagsURL); | 1810 GURL flags_url(chrome::kChromeUIFlagsURL); |
| 1819 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); | 1811 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); |
| 1820 | 1812 |
| 1821 ui_test_utils::NavigateToURL(browser(), flags_url); | 1813 ui_test_utils::NavigateToURL(browser(), flags_url); |
| 1822 DownloadAndWait(browser(), download_url); | 1814 DownloadAndWait(browser(), download_url); |
| 1823 ui_test_utils::NavigateToURL(browser(), extensions_url); | 1815 ui_test_utils::NavigateToURL(browser(), extensions_url); |
| 1824 WebContents* contents = | 1816 WebContents* contents = |
| 1825 browser()->tab_strip_model()->GetActiveWebContents(); | 1817 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1826 ASSERT_TRUE(contents); | 1818 ASSERT_TRUE(contents); |
| 1827 bool webui_responded = false; | 1819 bool webui_responded = false; |
| 1828 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 1820 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 1829 contents, | 1821 contents, |
| 1830 "window.domAutomationController.send(window.webuiResponded);", | 1822 "window.domAutomationController.send(window.webuiResponded);", |
| 1831 &webui_responded)); | 1823 &webui_responded)); |
| 1832 EXPECT_TRUE(webui_responded); | 1824 EXPECT_TRUE(webui_responded); |
| 1833 } | 1825 } |
| 1834 | 1826 |
| 1835 // Test for crbug.com/12745. This tests that if a download is initiated from | 1827 // Test for crbug.com/12745. This tests that if a download is initiated from |
| 1836 // a chrome:// page that has registered and onunload handler, the browser | 1828 // a chrome:// page that has registered and onunload handler, the browser |
| 1837 // will be able to close. | 1829 // will be able to close. |
| 1838 IN_PROC_BROWSER_TEST_F(DownloadTest, BrowserCloseAfterDownload) { | 1830 IN_PROC_BROWSER_TEST_F(DownloadTest, BrowserCloseAfterDownload) { |
| 1839 GURL downloads_url(chrome::kChromeUIFlagsURL); | 1831 GURL downloads_url(chrome::kChromeUIFlagsURL); |
| 1840 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1832 GURL download_url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
| 1841 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1842 | 1833 |
| 1843 ui_test_utils::NavigateToURL(browser(), downloads_url); | 1834 ui_test_utils::NavigateToURL(browser(), downloads_url); |
| 1844 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | 1835 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 1845 ASSERT_TRUE(contents); | 1836 ASSERT_TRUE(contents); |
| 1846 bool result = false; | 1837 bool result = false; |
| 1847 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 1838 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 1848 contents, | 1839 contents, |
| 1849 "window.onunload = function() { var do_nothing = 0; }; " | 1840 "window.onunload = function() { var do_nothing = 0; }; " |
| 1850 "window.domAutomationController.send(true);", | 1841 "window.domAutomationController.send(true);", |
| 1851 &result)); | 1842 &result)); |
| 1852 EXPECT_TRUE(result); | 1843 EXPECT_TRUE(result); |
| 1853 | 1844 |
| 1854 DownloadAndWait(browser(), download_url); | 1845 DownloadAndWait(browser(), download_url); |
| 1855 | 1846 |
| 1856 content::WindowedNotificationObserver signal( | 1847 content::WindowedNotificationObserver signal( |
| 1857 chrome::NOTIFICATION_BROWSER_CLOSED, | 1848 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 1858 content::Source<Browser>(browser())); | 1849 content::Source<Browser>(browser())); |
| 1859 chrome::CloseWindow(browser()); | 1850 chrome::CloseWindow(browser()); |
| 1860 signal.Wait(); | 1851 signal.Wait(); |
| 1861 } | 1852 } |
| 1862 | 1853 |
| 1863 // Test to make sure the 'download' attribute in anchor tag is respected. | 1854 // Test to make sure the 'download' attribute in anchor tag is respected. |
| 1864 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { | 1855 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { |
| 1865 base::FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); | 1856 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-anchor-attrib.html")); |
| 1866 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1867 | 1857 |
| 1868 // Create a download, wait until it's complete, and confirm | 1858 // Create a download, wait until it's complete, and confirm |
| 1869 // we're in the expected state. | 1859 // we're in the expected state. |
| 1870 scoped_ptr<content::DownloadTestObserver> observer( | 1860 scoped_ptr<content::DownloadTestObserver> observer( |
| 1871 CreateWaiter(browser(), 1)); | 1861 CreateWaiter(browser(), 1)); |
| 1872 ui_test_utils::NavigateToURL(browser(), url); | 1862 ui_test_utils::NavigateToURL(browser(), url); |
| 1873 observer->WaitForFinished(); | 1863 observer->WaitForFinished(); |
| 1874 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1864 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1875 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1865 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1876 | 1866 |
| 1877 // Confirm the downloaded data exists. | 1867 // Confirm the downloaded data exists. |
| 1878 base::FilePath downloaded_file = GetDownloadDirectory(browser()); | 1868 base::FilePath downloaded_file = GetDownloadDirectory(browser()); |
| 1879 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); | 1869 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); |
| 1880 EXPECT_TRUE(base::PathExists(downloaded_file)); | 1870 EXPECT_TRUE(base::PathExists(downloaded_file)); |
| 1881 } | 1871 } |
| 1882 | 1872 |
| 1883 // Test to make sure auto-open works. | 1873 // Test to make sure auto-open works. |
| 1884 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { | 1874 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { |
| 1885 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); | 1875 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); |
| 1886 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1876 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-autoopen.txt")); |
| 1887 | 1877 |
| 1888 ASSERT_TRUE( | 1878 ASSERT_TRUE( |
| 1889 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 1879 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
| 1890 | 1880 |
| 1891 DownloadAndWait(browser(), url); | 1881 DownloadAndWait(browser(), url); |
| 1892 | 1882 |
| 1893 // Find the download and confirm it was opened. | 1883 // Find the download and confirm it was opened. |
| 1894 std::vector<DownloadItem*> downloads; | 1884 std::vector<DownloadItem*> downloads; |
| 1895 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | 1885 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
| 1896 ASSERT_EQ(1u, downloads.size()); | 1886 ASSERT_EQ(1u, downloads.size()); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2000 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); | 1990 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); |
| 2001 | 1991 |
| 2002 // Check that the extension was installed. | 1992 // Check that the extension was installed. |
| 2003 ExtensionService* extension_service = extensions::ExtensionSystem::Get( | 1993 ExtensionService* extension_service = extensions::ExtensionSystem::Get( |
| 2004 browser()->profile())->extension_service(); | 1994 browser()->profile())->extension_service(); |
| 2005 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1995 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 2006 } | 1996 } |
| 2007 | 1997 |
| 2008 // Test installing a CRX that fails integrity checks. | 1998 // Test installing a CRX that fails integrity checks. |
| 2009 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { | 1999 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { |
| 2010 base::FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); | 2000 GURL extension_url( |
| 2011 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 2001 URLRequestMockHTTPJob::GetMockUrl("extensions/bad_signature.crx")); |
| 2012 | 2002 |
| 2013 // Install a mock install UI that simulates a user allowing permission to | 2003 // Install a mock install UI that simulates a user allowing permission to |
| 2014 // finish the install, and dismisses any error message. We check that the | 2004 // finish the install, and dismisses any error message. We check that the |
| 2015 // install failed below. | 2005 // install failed below. |
| 2016 SetAllowMockInstallPrompt(); | 2006 SetAllowMockInstallPrompt(); |
| 2017 | 2007 |
| 2018 scoped_ptr<content::DownloadTestObserver> observer( | 2008 scoped_ptr<content::DownloadTestObserver> observer( |
| 2019 DangerousDownloadWaiter( | 2009 DangerousDownloadWaiter( |
| 2020 browser(), 1, | 2010 browser(), 1, |
| 2021 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 2011 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2061 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); | 2051 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); |
| 2062 | 2052 |
| 2063 // Check that the extension was installed. | 2053 // Check that the extension was installed. |
| 2064 ExtensionService* extension_service = extensions::ExtensionSystem::Get( | 2054 ExtensionService* extension_service = extensions::ExtensionSystem::Get( |
| 2065 browser()->profile())->extension_service(); | 2055 browser()->profile())->extension_service(); |
| 2066 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 2056 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
| 2067 } | 2057 } |
| 2068 | 2058 |
| 2069 // Tests for download initiation functions. | 2059 // Tests for download initiation functions. |
| 2070 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { | 2060 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { |
| 2071 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 2061 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
| 2072 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 2073 | 2062 |
| 2074 // DownloadUrl always prompts; return acceptance of whatever it prompts. | 2063 // DownloadUrl always prompts; return acceptance of whatever it prompts. |
| 2075 EnableFileChooser(true); | 2064 EnableFileChooser(true); |
| 2076 | 2065 |
| 2077 WebContents* web_contents = | 2066 WebContents* web_contents = |
| 2078 browser()->tab_strip_model()->GetActiveWebContents(); | 2067 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2079 ASSERT_TRUE(web_contents); | 2068 ASSERT_TRUE(web_contents); |
| 2080 | 2069 |
| 2081 content::DownloadTestObserver* observer( | 2070 content::DownloadTestObserver* observer( |
| 2082 new content::DownloadTestObserverTerminal( | 2071 new content::DownloadTestObserverTerminal( |
| 2083 DownloadManagerForBrowser(browser()), 1, | 2072 DownloadManagerForBrowser(browser()), 1, |
| 2084 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 2073 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 2085 scoped_ptr<DownloadUrlParameters> params( | 2074 scoped_ptr<DownloadUrlParameters> params( |
| 2086 DownloadUrlParameters::FromWebContents(web_contents, url)); | 2075 DownloadUrlParameters::FromWebContents(web_contents, url)); |
| 2087 params->set_prompt(true); | 2076 params->set_prompt(true); |
| 2088 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); | 2077 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); |
| 2089 observer->WaitForFinished(); | 2078 observer->WaitForFinished(); |
| 2090 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2079 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 2091 CheckDownloadStates(1, DownloadItem::COMPLETE); | 2080 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 2092 EXPECT_TRUE(DidShowFileChooser()); | 2081 EXPECT_TRUE(DidShowFileChooser()); |
| 2093 | 2082 |
| 2094 // Check state. | 2083 // Check state. |
| 2084 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
| 2095 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 2085 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 2096 ASSERT_TRUE(CheckDownload(browser(), file, file)); | 2086 ASSERT_TRUE(CheckDownload(browser(), file, file)); |
| 2097 } | 2087 } |
| 2098 | 2088 |
| 2099 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { | 2089 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { |
| 2100 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 2090 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
| 2101 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 2102 | 2091 |
| 2103 WebContents* web_contents = | 2092 WebContents* web_contents = |
| 2104 browser()->tab_strip_model()->GetActiveWebContents(); | 2093 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2105 ASSERT_TRUE(web_contents); | 2094 ASSERT_TRUE(web_contents); |
| 2106 | 2095 |
| 2096 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
| 2107 base::ScopedTempDir other_directory; | 2097 base::ScopedTempDir other_directory; |
| 2108 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); | 2098 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); |
| 2109 base::FilePath target_file_full_path | 2099 base::FilePath target_file_full_path |
| 2110 = other_directory.path().Append(file.BaseName()); | 2100 = other_directory.path().Append(file.BaseName()); |
| 2111 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); | 2101 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); |
| 2112 scoped_ptr<DownloadUrlParameters> params( | 2102 scoped_ptr<DownloadUrlParameters> params( |
| 2113 DownloadUrlParameters::FromWebContents(web_contents, url)); | 2103 DownloadUrlParameters::FromWebContents(web_contents, url)); |
| 2114 params->set_file_path(target_file_full_path); | 2104 params->set_file_path(target_file_full_path); |
| 2115 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); | 2105 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); |
| 2116 observer->WaitForFinished(); | 2106 observer->WaitForFinished(); |
| (...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3328 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 3318 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
| 3329 download->GetDangerType()); | 3319 download->GetDangerType()); |
| 3330 | 3320 |
| 3331 download->Cancel(true); | 3321 download->Cancel(true); |
| 3332 } | 3322 } |
| 3333 | 3323 |
| 3334 #endif // OS_WIN | 3324 #endif // OS_WIN |
| 3335 | 3325 |
| 3336 IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackService) { | 3326 IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackService) { |
| 3337 // Make a dangerous file. | 3327 // Make a dangerous file. |
| 3338 base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf")); | 3328 GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl( |
| 3339 GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl(file)); | 3329 "downloads/dangerous/dangerous.swf")); |
| 3340 scoped_ptr<content::DownloadTestObserverInterrupted> observer( | 3330 scoped_ptr<content::DownloadTestObserverInterrupted> observer( |
| 3341 new content::DownloadTestObserverInterrupted( | 3331 new content::DownloadTestObserverInterrupted( |
| 3342 DownloadManagerForBrowser(browser()), 1, | 3332 DownloadManagerForBrowser(browser()), 1, |
| 3343 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); | 3333 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); |
| 3344 ui_test_utils::NavigateToURLWithDisposition( | 3334 ui_test_utils::NavigateToURLWithDisposition( |
| 3345 browser(), | 3335 browser(), |
| 3346 GURL(download_url), | 3336 GURL(download_url), |
| 3347 NEW_BACKGROUND_TAB, | 3337 NEW_BACKGROUND_TAB, |
| 3348 ui_test_utils::BROWSER_TEST_NONE); | 3338 ui_test_utils::BROWSER_TEST_NONE); |
| 3349 observer->WaitForFinished(); | 3339 observer->WaitForFinished(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3401 DownloadAndWait(browser(), url); | 3391 DownloadAndWait(browser(), url); |
| 3402 | 3392 |
| 3403 // The download shelf should be visible. | 3393 // The download shelf should be visible. |
| 3404 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 3394 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 3405 } | 3395 } |
| 3406 | 3396 |
| 3407 // Test that the download shelf is per-window by starting a download in one | 3397 // Test that the download shelf is per-window by starting a download in one |
| 3408 // tab, opening a second tab, closing the shelf, going back to the first tab, | 3398 // tab, opening a second tab, closing the shelf, going back to the first tab, |
| 3409 // and checking that the shelf is closed. | 3399 // and checking that the shelf is closed. |
| 3410 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, PerWindowShelf) { | 3400 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, PerWindowShelf) { |
| 3411 base::FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 3401 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test3.gif")); |
| 3412 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 3413 base::FilePath download_file( | 3402 base::FilePath download_file( |
| 3414 FILE_PATH_LITERAL("download-test3-attachment.gif")); | 3403 FILE_PATH_LITERAL("download-test3-attachment.gif")); |
| 3415 | 3404 |
| 3416 // Download a file and wait. | 3405 // Download a file and wait. |
| 3417 DownloadAndWait(browser(), url); | 3406 DownloadAndWait(browser(), url); |
| 3418 | 3407 |
| 3408 base::FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | |
| 3419 CheckDownload(browser(), download_file, file); | 3409 CheckDownload(browser(), download_file, file); |
| 3420 | 3410 |
| 3421 // Check state. | 3411 // Check state. |
| 3422 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 3412 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 3423 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 3413 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 3424 | 3414 |
| 3425 // Open a second tab and wait. | 3415 // Open a second tab and wait. |
| 3426 EXPECT_NE(static_cast<WebContents*>(NULL), | 3416 EXPECT_NE(static_cast<WebContents*>(NULL), |
| 3427 chrome::AddSelectedTabWithURL(browser(), GURL(url::kAboutBlankURL), | 3417 chrome::AddSelectedTabWithURL(browser(), GURL(url::kAboutBlankURL), |
| 3428 ui::PAGE_TRANSITION_TYPED)); | 3418 ui::PAGE_TRANSITION_TYPED)); |
| 3429 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 3419 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 3430 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 3420 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 3431 | 3421 |
| 3432 // Hide the download shelf. | 3422 // Hide the download shelf. |
| 3433 browser()->window()->GetDownloadShelf()->Close(DownloadShelf::AUTOMATIC); | 3423 browser()->window()->GetDownloadShelf()->Close(DownloadShelf::AUTOMATIC); |
| 3434 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3424 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3435 | 3425 |
| 3436 // Go to the first tab. | 3426 // Go to the first tab. |
| 3437 browser()->tab_strip_model()->ActivateTabAt(0, true); | 3427 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 3438 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 3428 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 3439 | 3429 |
| 3440 // The download shelf should not be visible. | 3430 // The download shelf should not be visible. |
| 3441 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3431 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3442 } | 3432 } |
| 3443 | 3433 |
| 3444 // Check whether the downloads shelf is closed when the downloads tab is | 3434 // Check whether the downloads shelf is closed when the downloads tab is |
| 3445 // invoked. | 3435 // invoked. |
| 3446 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, CloseShelfOnDownloadsTab) { | 3436 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, CloseShelfOnDownloadsTab) { |
| 3447 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 3437 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
| 3448 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 3449 | 3438 |
| 3450 // Download the file and wait. We do not expect the Select File dialog. | 3439 // Download the file and wait. We do not expect the Select File dialog. |
| 3451 DownloadAndWait(browser(), url); | 3440 DownloadAndWait(browser(), url); |
| 3452 | 3441 |
| 3453 // Check state. | 3442 // Check state. |
| 3454 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 3443 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 3455 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 3444 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 3456 | 3445 |
| 3457 // Open the downloads tab. | 3446 // Open the downloads tab. |
| 3458 chrome::ShowDownloads(browser()); | 3447 chrome::ShowDownloads(browser()); |
| 3459 // The shelf should now be closed. | 3448 // The shelf should now be closed. |
| 3460 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3449 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3461 } | 3450 } |
| 3462 | 3451 |
| 3463 // Test that when downloading an item in Incognito mode, check that the | 3452 // Test that when downloading an item in Incognito mode, check that the |
| 3464 // download shelf is not visible after closing the Incognito window. | 3453 // download shelf is not visible after closing the Incognito window. |
| 3465 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, IncognitoDownload) { | 3454 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, IncognitoDownload) { |
| 3466 Browser* incognito = CreateIncognitoBrowser(); | 3455 Browser* incognito = CreateIncognitoBrowser(); |
| 3467 ASSERT_TRUE(incognito); | 3456 ASSERT_TRUE(incognito); |
| 3468 | 3457 |
| 3469 // Download a file in the Incognito window and wait. | 3458 // Download a file in the Incognito window and wait. |
| 3470 CreateAndSetDownloadsDirectory(incognito); | 3459 CreateAndSetDownloadsDirectory(incognito); |
| 3471 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 3460 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
| 3472 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 3473 // Since |incognito| is a separate browser, we have to set it up explicitly. | 3461 // Since |incognito| is a separate browser, we have to set it up explicitly. |
| 3474 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, | 3462 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, |
| 3475 false); | 3463 false); |
| 3476 DownloadAndWait(incognito, url); | 3464 DownloadAndWait(incognito, url); |
| 3477 | 3465 |
| 3478 // Verify that the download shelf is showing for the Incognito window. | 3466 // Verify that the download shelf is showing for the Incognito window. |
| 3479 EXPECT_TRUE(incognito->window()->IsDownloadShelfVisible()); | 3467 EXPECT_TRUE(incognito->window()->IsDownloadShelfVisible()); |
| 3480 | 3468 |
| 3481 // Verify that the regular window does not have a download shelf. | 3469 // Verify that the regular window does not have a download shelf. |
| 3482 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3470 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3483 } | 3471 } |
| 3484 | 3472 |
| 3485 // Download a file in a new window. | 3473 // Download a file in a new window. |
| 3486 // Verify that we have 2 windows, and the download shelf is not visible in the | 3474 // Verify that we have 2 windows, and the download shelf is not visible in the |
| 3487 // first window, but is visible in the second window. | 3475 // first window, but is visible in the second window. |
| 3488 // Close the new window. | 3476 // Close the new window. |
| 3489 // Verify that we have 1 window, and the download shelf is not visible. | 3477 // Verify that we have 1 window, and the download shelf is not visible. |
| 3490 // | 3478 // |
| 3491 // Regression test for http://crbug.com/44454 | 3479 // Regression test for http://crbug.com/44454 |
| 3492 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, NewWindow) { | 3480 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, NewWindow) { |
| 3493 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 3481 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
| 3494 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 3495 #if !defined(OS_MACOSX) | 3482 #if !defined(OS_MACOSX) |
| 3496 // See below. | 3483 // See below. |
| 3497 Browser* first_browser = browser(); | 3484 Browser* first_browser = browser(); |
| 3498 #endif | 3485 #endif |
| 3499 | 3486 |
| 3500 // Download a file in a new window and wait. | 3487 // Download a file in a new window and wait. |
| 3501 DownloadAndWaitWithDisposition(browser(), url, NEW_WINDOW, | 3488 DownloadAndWaitWithDisposition(browser(), url, NEW_WINDOW, |
| 3502 ui_test_utils::BROWSER_TEST_NONE); | 3489 ui_test_utils::BROWSER_TEST_NONE); |
| 3503 | 3490 |
| 3504 // When the download finishes, the download shelf SHOULD NOT be visible in | 3491 // When the download finishes, the download shelf SHOULD NOT be visible in |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 3533 #if !defined(OS_MACOSX) | 3520 #if !defined(OS_MACOSX) |
| 3534 signal.Wait(); | 3521 signal.Wait(); |
| 3535 EXPECT_EQ(first_browser, browser()); | 3522 EXPECT_EQ(first_browser, browser()); |
| 3536 ExpectWindowCountAfterDownload(1); | 3523 ExpectWindowCountAfterDownload(1); |
| 3537 #endif | 3524 #endif |
| 3538 | 3525 |
| 3539 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 3526 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 3540 // Download shelf should close. Download panel stays open on ChromeOS. | 3527 // Download shelf should close. Download panel stays open on ChromeOS. |
| 3541 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3528 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3542 | 3529 |
| 3530 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
| 3543 CheckDownload(browser(), file, file); | 3531 CheckDownload(browser(), file, file); |
| 3544 } | 3532 } |
| 3545 | 3533 |
| 3546 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, PRE_DownloadTest_History) { | 3534 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, PRE_DownloadTest_History) { |
| 3547 // Download a file and wait for it to be stored. | 3535 // Download a file and wait for it to be stored. |
| 3548 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 3536 GURL download_url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
| 3549 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 3550 HistoryObserver observer(browser()->profile()); | 3537 HistoryObserver observer(browser()->profile()); |
| 3551 DownloadAndWait(browser(), download_url); | 3538 DownloadAndWait(browser(), download_url); |
| 3552 observer.WaitForStored(); | 3539 observer.WaitForStored(); |
| 3553 HistoryServiceFactory::GetForProfile(browser()->profile(), | 3540 HistoryServiceFactory::GetForProfile(browser()->profile(), |
| 3554 ServiceAccessType::IMPLICIT_ACCESS) | 3541 ServiceAccessType::IMPLICIT_ACCESS) |
| 3555 ->FlushForTest(base::Bind( | 3542 ->FlushForTest(base::Bind( |
| 3556 &base::MessageLoop::Quit, | 3543 &base::MessageLoop::Quit, |
| 3557 base::Unretained(base::MessageLoop::current()->current()))); | 3544 base::Unretained(base::MessageLoop::current()->current()))); |
| 3558 content::RunMessageLoop(); | 3545 content::RunMessageLoop(); |
| 3559 } | 3546 } |
| 3560 | 3547 |
| 3561 #if defined(OS_CHROMEOS) | 3548 #if defined(OS_CHROMEOS) |
| 3562 // Times out on ChromeOS: http://crbug.com/217810 | 3549 // Times out on ChromeOS: http://crbug.com/217810 |
| 3563 #define MAYBE_DownloadTest_History DISABLED_DownloadTest_History | 3550 #define MAYBE_DownloadTest_History DISABLED_DownloadTest_History |
| 3564 #else | 3551 #else |
| 3565 #define MAYBE_DownloadTest_History DownloadTest_History | 3552 #define MAYBE_DownloadTest_History DownloadTest_History |
| 3566 #endif | 3553 #endif |
| 3567 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, MAYBE_DownloadTest_History) { | 3554 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, MAYBE_DownloadTest_History) { |
| 3568 // This starts up right after PRE_DownloadTest_History and shares the same | 3555 // This starts up right after PRE_DownloadTest_History and shares the same |
| 3569 // profile directory. | 3556 // profile directory. |
| 3570 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 3557 GURL download_url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
| 3571 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 3572 std::vector<DownloadItem*> downloads; | 3558 std::vector<DownloadItem*> downloads; |
| 3573 content::DownloadManager* manager = DownloadManagerForBrowser(browser()); | 3559 content::DownloadManager* manager = DownloadManagerForBrowser(browser()); |
| 3574 | 3560 |
| 3575 // Wait for the history to be loaded with a single DownloadItem. Check that | 3561 // Wait for the history to be loaded with a single DownloadItem. Check that |
| 3576 // it's the file that was downloaded in PRE_DownloadTest_History. | 3562 // it's the file that was downloaded in PRE_DownloadTest_History. |
| 3563 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
| 3577 CreatedObserver created_observer(manager); | 3564 CreatedObserver created_observer(manager); |
| 3578 created_observer.Wait(); | 3565 created_observer.Wait(); |
| 3579 manager->GetAllDownloads(&downloads); | 3566 manager->GetAllDownloads(&downloads); |
| 3580 ASSERT_EQ(1UL, downloads.size()); | 3567 ASSERT_EQ(1UL, downloads.size()); |
| 3581 DownloadItem* item = downloads[0]; | 3568 DownloadItem* item = downloads[0]; |
| 3582 EXPECT_EQ(file.value(), item->GetFullPath().BaseName().value()); | 3569 EXPECT_EQ(file.value(), item->GetFullPath().BaseName().value()); |
| 3583 EXPECT_EQ(file.value(), item->GetTargetFilePath().BaseName().value()); | 3570 EXPECT_EQ(file.value(), item->GetTargetFilePath().BaseName().value()); |
| 3584 EXPECT_EQ(download_url, item->GetURL()); | 3571 EXPECT_EQ(download_url, item->GetURL()); |
| 3585 // The following are set by download-test1.lib.mock-http-headers. | 3572 // The following are set by download-test1.lib.mock-http-headers. |
| 3586 std::string etag = item->GetETag(); | 3573 std::string etag = item->GetETag(); |
| 3587 base::TrimWhitespaceASCII(etag, base::TRIM_ALL, &etag); | 3574 base::TrimWhitespaceASCII(etag, base::TRIM_ALL, &etag); |
| 3588 EXPECT_EQ("abracadabra", etag); | 3575 EXPECT_EQ("abracadabra", etag); |
| 3589 | 3576 |
| 3590 std::string last_modified = item->GetLastModifiedTime(); | 3577 std::string last_modified = item->GetLastModifiedTime(); |
| 3591 base::TrimWhitespaceASCII(last_modified, base::TRIM_ALL, &last_modified); | 3578 base::TrimWhitespaceASCII(last_modified, base::TRIM_ALL, &last_modified); |
| 3592 EXPECT_EQ("Mon, 13 Nov 2006 20:31:09 GMT", last_modified); | 3579 EXPECT_EQ("Mon, 13 Nov 2006 20:31:09 GMT", last_modified); |
| 3593 | 3580 |
| 3594 // Downloads that were restored from history shouldn't cause the download | 3581 // Downloads that were restored from history shouldn't cause the download |
| 3595 // shelf to be displayed. | 3582 // shelf to be displayed. |
| 3596 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3583 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3597 } | 3584 } |
| 3598 | 3585 |
| 3599 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, HiddenDownload) { | 3586 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, HiddenDownload) { |
| 3600 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 3587 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib")); |
| 3601 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 3602 | 3588 |
| 3603 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); | 3589 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); |
| 3604 scoped_ptr<content::DownloadTestObserver> observer( | 3590 scoped_ptr<content::DownloadTestObserver> observer( |
| 3605 new content::DownloadTestObserverTerminal( | 3591 new content::DownloadTestObserverTerminal( |
| 3606 download_manager, 1, | 3592 download_manager, 1, |
| 3607 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 3593 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 3608 | 3594 |
| 3609 // Download and set IsHiddenDownload to true. | 3595 // Download and set IsHiddenDownload to true. |
| 3610 WebContents* web_contents = | 3596 WebContents* web_contents = |
| 3611 browser()->tab_strip_model()->GetActiveWebContents(); | 3597 browser()->tab_strip_model()->GetActiveWebContents(); |
| 3612 scoped_ptr<DownloadUrlParameters> params( | 3598 scoped_ptr<DownloadUrlParameters> params( |
| 3613 DownloadUrlParameters::FromWebContents(web_contents, url)); | 3599 DownloadUrlParameters::FromWebContents(web_contents, url)); |
| 3614 params->set_callback(base::Bind(&SetHiddenDownloadCallback)); | 3600 params->set_callback(base::Bind(&SetHiddenDownloadCallback)); |
| 3615 download_manager->DownloadUrl(params.Pass()); | 3601 download_manager->DownloadUrl(params.Pass()); |
| 3616 observer->WaitForFinished(); | 3602 observer->WaitForFinished(); |
| 3617 | 3603 |
| 3618 // Verify that download shelf is not shown. | 3604 // Verify that download shelf is not shown. |
| 3619 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3605 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3620 } | 3606 } |
| 3621 | 3607 |
| 3622 // Test to make sure auto-open works. | 3608 // Test to make sure auto-open works. |
| 3623 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, AutoOpen) { | 3609 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, AutoOpen) { |
| 3624 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); | 3610 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); |
| 3625 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 3611 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-autoopen.txt")); |
| 3626 | 3612 |
| 3627 ASSERT_TRUE( | 3613 ASSERT_TRUE( |
| 3628 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 3614 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
| 3629 | 3615 |
| 3630 DownloadAndWait(browser(), url); | 3616 DownloadAndWait(browser(), url); |
| 3631 | 3617 |
| 3632 // Download shelf should close. Download panel stays open on ChromeOS. | 3618 // Download shelf should close. Download panel stays open on ChromeOS. |
| 3633 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3619 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3634 } | 3620 } |
| 3635 | 3621 |
| 3636 // Download an extension. Expect a dangerous download warning. | 3622 // Download an extension. Expect a dangerous download warning. |
| 3637 // Deny the download. | 3623 // Deny the download. |
| 3638 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, CrxDenyInstall) { | 3624 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, CrxDenyInstall) { |
| 3639 FeatureSwitch::ScopedOverride enable_easy_off_store_install( | 3625 FeatureSwitch::ScopedOverride enable_easy_off_store_install( |
| 3640 FeatureSwitch::easy_off_store_install(), true); | 3626 FeatureSwitch::easy_off_store_install(), true); |
| 3641 | 3627 |
| 3642 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 3628 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 3643 | 3629 |
| 3644 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( | 3630 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( |
| 3645 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 3631 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 3646 ui_test_utils::NavigateToURL(browser(), extension_url); | 3632 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 3647 | 3633 |
| 3648 observer->WaitForFinished(); | 3634 observer->WaitForFinished(); |
| 3649 | 3635 |
| 3650 // Download shelf should close. | 3636 // Download shelf should close. |
| 3651 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3637 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3652 } | 3638 } |
| OLD | NEW |