| 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 "chrome/browser/download/download_browsertest.h" | 5 #include "chrome/browser/download/download_browsertest.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 class DownloadTest : public InProcessBrowserTest { | 391 class DownloadTest : public InProcessBrowserTest { |
| 392 public: | 392 public: |
| 393 // Choice of navigation or direct fetch. Used by |DownloadFileCheckErrors()|. | 393 // Choice of navigation or direct fetch. Used by |DownloadFileCheckErrors()|. |
| 394 enum DownloadMethod { | 394 enum DownloadMethod { |
| 395 DOWNLOAD_NAVIGATE, | 395 DOWNLOAD_NAVIGATE, |
| 396 DOWNLOAD_DIRECT | 396 DOWNLOAD_DIRECT |
| 397 }; | 397 }; |
| 398 | 398 |
| 399 // Information passed in to |DownloadFileCheckErrors()|. | 399 // Information passed in to |DownloadFileCheckErrors()|. |
| 400 struct DownloadInfo { | 400 struct DownloadInfo { |
| 401 const char* url_name; // URL for the download. | 401 const char* starting_url; // URL for initiating the download. |
| 402 DownloadMethod download_method; // Navigation or Direct. | 402 const char* expected_download_url; // Expected value of DI::GetURL(). Can |
| 403 // be different if |starting_url| |
| 404 // initiates a download from another |
| 405 // URL. |
| 406 DownloadMethod download_method; // Navigation or Direct. |
| 403 // Download interrupt reason (NONE is OK). | 407 // Download interrupt reason (NONE is OK). |
| 404 content::DownloadInterruptReason reason; | 408 content::DownloadInterruptReason reason; |
| 405 bool show_download_item; // True if the download item appears on the shelf. | 409 bool show_download_item; // True if the download item appears on the shelf. |
| 406 bool should_redirect_to_documents; // True if we save it in "My Documents". | 410 bool should_redirect_to_documents; // True if we save it in "My Documents". |
| 407 }; | 411 }; |
| 408 | 412 |
| 409 struct FileErrorInjectInfo { | 413 struct FileErrorInjectInfo { |
| 410 DownloadInfo download_info; | 414 DownloadInfo download_info; |
| 411 content::TestFileErrorInjector::FileErrorInfo error_info; | 415 content::TestFileErrorInjector::FileErrorInfo error_info; |
| 412 }; | 416 }; |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 ASSERT_TRUE(embedded_test_server()->Start()); | 829 ASSERT_TRUE(embedded_test_server()->Start()); |
| 826 std::vector<DownloadItem*> download_items; | 830 std::vector<DownloadItem*> download_items; |
| 827 GetDownloads(browser(), &download_items); | 831 GetDownloads(browser(), &download_items); |
| 828 ASSERT_TRUE(download_items.empty()); | 832 ASSERT_TRUE(download_items.empty()); |
| 829 | 833 |
| 830 EnableFileChooser(true); | 834 EnableFileChooser(true); |
| 831 } | 835 } |
| 832 | 836 |
| 833 void DownloadFilesCheckErrorsLoopBody(const DownloadInfo& download_info, | 837 void DownloadFilesCheckErrorsLoopBody(const DownloadInfo& download_info, |
| 834 size_t i) { | 838 size_t i) { |
| 835 SCOPED_TRACE( | 839 SCOPED_TRACE(testing::Message() |
| 836 ::testing::Message() | 840 << " " << __FUNCTION__ << "()" |
| 837 << " " << __FUNCTION__ << "()" | 841 << " index = " << i << " starting_url = '" |
| 838 << " index = " << i << " url = '" << download_info.url_name << "'" | 842 << download_info.starting_url << "'" |
| 839 << " method = " << ((download_info.download_method == DOWNLOAD_DIRECT) | 843 << " download_url = '" << download_info.expected_download_url |
| 840 ? "DOWNLOAD_DIRECT" | 844 << "'" |
| 841 : "DOWNLOAD_NAVIGATE") | 845 << " method = " |
| 842 << " show_item = " << download_info.show_download_item << " reason = " | 846 << ((download_info.download_method == DOWNLOAD_DIRECT) |
| 843 << DownloadInterruptReasonToString(download_info.reason)); | 847 ? "DOWNLOAD_DIRECT" |
| 848 : "DOWNLOAD_NAVIGATE") |
| 849 << " show_item = " << download_info.show_download_item |
| 850 << " reason = " |
| 851 << DownloadInterruptReasonToString(download_info.reason)); |
| 844 | 852 |
| 845 std::vector<DownloadItem*> download_items; | 853 std::vector<DownloadItem*> download_items; |
| 846 GetDownloads(browser(), &download_items); | 854 GetDownloads(browser(), &download_items); |
| 847 size_t downloads_expected = download_items.size(); | 855 size_t downloads_expected = download_items.size(); |
| 848 | 856 |
| 849 std::string server_path = "/downloads/"; | 857 // GURL("http://foo/bar").Resolve("baz") => "http://foo/bar/baz" |
| 850 server_path += download_info.url_name; | 858 // GURL("http://foo/bar").Resolve("http://baz") => "http://baz" |
| 851 GURL url = embedded_test_server()->GetURL(server_path); | 859 // I.e. both starting_url and expected_download_url can either be relative |
| 852 ASSERT_TRUE(url.is_valid()); | 860 // to the base test server URL or be an absolute URL. |
| 861 GURL base_url = embedded_test_server()->GetURL("/downloads/"); |
| 862 GURL starting_url = base_url.Resolve(download_info.starting_url); |
| 863 GURL download_url = base_url.Resolve(download_info.expected_download_url); |
| 864 ASSERT_TRUE(starting_url.is_valid()); |
| 865 ASSERT_TRUE(download_url.is_valid()); |
| 853 | 866 |
| 854 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); | 867 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); |
| 855 WebContents* web_contents = | 868 WebContents* web_contents = |
| 856 browser()->tab_strip_model()->GetActiveWebContents(); | 869 browser()->tab_strip_model()->GetActiveWebContents(); |
| 857 ASSERT_TRUE(web_contents); | 870 ASSERT_TRUE(web_contents); |
| 858 | 871 |
| 859 scoped_ptr<content::DownloadTestObserver> observer; | 872 scoped_ptr<content::DownloadTestObserver> observer; |
| 860 if (download_info.reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) { | 873 if (download_info.reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 861 observer.reset(new content::DownloadTestObserverTerminal( | 874 observer.reset(new content::DownloadTestObserverTerminal( |
| 862 download_manager, 1, | 875 download_manager, 1, |
| 863 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 876 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 864 } else { | 877 } else { |
| 865 observer.reset(new content::DownloadTestObserverInterrupted( | 878 observer.reset(new content::DownloadTestObserverInterrupted( |
| 866 download_manager, 1, | 879 download_manager, 1, |
| 867 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 880 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 868 } | 881 } |
| 869 | 882 |
| 870 if (download_info.download_method == DOWNLOAD_DIRECT) { | 883 if (download_info.download_method == DOWNLOAD_DIRECT) { |
| 871 // Go directly to download. Don't wait for navigation. | 884 // Go directly to download. Don't wait for navigation. |
| 872 scoped_refptr<content::DownloadTestItemCreationObserver> | 885 scoped_refptr<content::DownloadTestItemCreationObserver> |
| 873 creation_observer(new content::DownloadTestItemCreationObserver); | 886 creation_observer(new content::DownloadTestItemCreationObserver); |
| 874 | 887 |
| 875 scoped_ptr<DownloadUrlParameters> params( | 888 scoped_ptr<DownloadUrlParameters> params( |
| 876 DownloadUrlParameters::FromWebContents(web_contents, url)); | 889 DownloadUrlParameters::FromWebContents(web_contents, starting_url)); |
| 877 params->set_callback(creation_observer->callback()); | 890 params->set_callback(creation_observer->callback()); |
| 878 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); | 891 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); |
| 879 | 892 |
| 880 // Wait until the item is created, or we have determined that it | 893 // Wait until the item is created, or we have determined that it |
| 881 // won't be. | 894 // won't be. |
| 882 creation_observer->WaitForDownloadItemCreation(); | 895 creation_observer->WaitForDownloadItemCreation(); |
| 883 | 896 |
| 884 ASSERT_EQ(download_info.show_download_item, | 897 EXPECT_NE(content::DownloadItem::kInvalidId, |
| 885 creation_observer->succeeded()); | 898 creation_observer->download_id()); |
| 886 if (download_info.show_download_item) { | |
| 887 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, | |
| 888 creation_observer->interrupt_reason()); | |
| 889 EXPECT_NE(content::DownloadItem::kInvalidId, | |
| 890 creation_observer->download_id()); | |
| 891 } else { | |
| 892 EXPECT_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE, | |
| 893 creation_observer->interrupt_reason()); | |
| 894 EXPECT_EQ(content::DownloadItem::kInvalidId, | |
| 895 creation_observer->download_id()); | |
| 896 } | |
| 897 } else { | 899 } else { |
| 898 // Navigate to URL normally, wait until done. | 900 // Navigate to URL normally, wait until done. |
| 899 ui_test_utils::NavigateToURL(browser(), url); | 901 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 902 browser(), starting_url, 1); |
| 900 } | 903 } |
| 901 | 904 |
| 902 if (download_info.show_download_item) { | 905 if (download_info.show_download_item) { |
| 903 downloads_expected++; | 906 downloads_expected++; |
| 904 observer->WaitForFinished(); | 907 observer->WaitForFinished(); |
| 905 DownloadItem::DownloadState final_state = | 908 DownloadItem::DownloadState final_state = |
| 906 (download_info.reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) ? | 909 (download_info.reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) ? |
| 907 DownloadItem::COMPLETE : | 910 DownloadItem::COMPLETE : |
| 908 DownloadItem::INTERRUPTED; | 911 DownloadItem::INTERRUPTED; |
| 909 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(final_state)); | 912 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(final_state)); |
| 910 } | 913 } |
| 911 | 914 |
| 912 // Wait till the |DownloadFile|s are destroyed. | 915 // Wait till the |DownloadFile|s are destroyed. |
| 913 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | 916 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
| 914 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); | 917 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); |
| 915 | 918 |
| 916 // Validate that the correct files were downloaded. | 919 // Validate that the correct files were downloaded. |
| 917 download_items.clear(); | 920 download_items.clear(); |
| 918 GetDownloads(browser(), &download_items); | 921 GetDownloads(browser(), &download_items); |
| 919 ASSERT_EQ(downloads_expected, download_items.size()); | 922 ASSERT_EQ(downloads_expected, download_items.size()); |
| 920 | 923 |
| 921 if (download_info.show_download_item) { | 924 if (download_info.show_download_item) { |
| 922 // Find the last download item. | 925 // Find the last download item. |
| 923 DownloadItem* item = download_items[0]; | 926 DownloadItem* item = download_items[0]; |
| 924 for (size_t d = 1; d < downloads_expected; ++d) { | 927 for (size_t d = 1; d < downloads_expected; ++d) { |
| 925 if (download_items[d]->GetStartTime() > item->GetStartTime()) | 928 if (download_items[d]->GetStartTime() > item->GetStartTime()) |
| 926 item = download_items[d]; | 929 item = download_items[d]; |
| 927 } | 930 } |
| 928 | 931 |
| 929 ASSERT_EQ(url, item->GetOriginalUrl()); | 932 EXPECT_EQ(download_url, item->GetURL()); |
| 930 ASSERT_EQ(download_info.reason, item->GetLastReason()); | 933 EXPECT_EQ(download_info.reason, item->GetLastReason()); |
| 931 | 934 |
| 932 if (item->GetState() == content::DownloadItem::COMPLETE) { | 935 if (item->GetState() == content::DownloadItem::COMPLETE) { |
| 933 // Clean up the file, in case it ended up in the My Documents folder. | 936 // Clean up the file, in case it ended up in the My Documents folder. |
| 934 base::FilePath destination_folder = GetDownloadDirectory(browser()); | 937 base::FilePath destination_folder = GetDownloadDirectory(browser()); |
| 935 base::FilePath my_downloaded_file = item->GetTargetFilePath(); | 938 base::FilePath my_downloaded_file = item->GetTargetFilePath(); |
| 936 EXPECT_TRUE(base::PathExists(my_downloaded_file)); | 939 EXPECT_TRUE(base::PathExists(my_downloaded_file)); |
| 937 EXPECT_TRUE(base::DeleteFile(my_downloaded_file, false)); | 940 EXPECT_TRUE(base::DeleteFile(my_downloaded_file, false)); |
| 938 | 941 |
| 939 EXPECT_EQ(download_info.should_redirect_to_documents ? | 942 EXPECT_EQ(download_info.should_redirect_to_documents ? |
| 940 std::string::npos : | 943 std::string::npos : |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 DownloadFilesCheckErrorsSetup(); | 1002 DownloadFilesCheckErrorsSetup(); |
| 1000 | 1003 |
| 1001 // Set up file failures. | 1004 // Set up file failures. |
| 1002 scoped_refptr<content::TestFileErrorInjector> injector( | 1005 scoped_refptr<content::TestFileErrorInjector> injector( |
| 1003 content::TestFileErrorInjector::Create( | 1006 content::TestFileErrorInjector::Create( |
| 1004 DownloadManagerForBrowser(browser()))); | 1007 DownloadManagerForBrowser(browser()))); |
| 1005 | 1008 |
| 1006 for (size_t i = 0; i < count; ++i) { | 1009 for (size_t i = 0; i < count; ++i) { |
| 1007 // Set up the full URL, for download file tracking. | 1010 // Set up the full URL, for download file tracking. |
| 1008 std::string server_path = "/downloads/"; | 1011 std::string server_path = "/downloads/"; |
| 1009 server_path += info[i].download_info.url_name; | 1012 server_path += info[i].download_info.starting_url; |
| 1010 GURL url = embedded_test_server()->GetURL(server_path); | 1013 GURL url = embedded_test_server()->GetURL(server_path); |
| 1011 info[i].error_info.url = url.spec(); | 1014 info[i].error_info.url = url.spec(); |
| 1012 | 1015 |
| 1013 DownloadInsertFilesErrorCheckErrorsLoopBody(injector, info[i], i); | 1016 DownloadInsertFilesErrorCheckErrorsLoopBody(injector, info[i], i); |
| 1014 } | 1017 } |
| 1015 } | 1018 } |
| 1016 | 1019 |
| 1017 // Attempts to download a file to a read-only folder, based on information | 1020 // Attempts to download a file to a read-only folder, based on information |
| 1018 // in |download_info|. | 1021 // in |download_info|. |
| 1019 void DownloadFilesToReadonlyFolder(size_t count, | 1022 void DownloadFilesToReadonlyFolder(size_t count, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 DownloadRequestLimiter::TabDownloadState* tab_download_state = | 1254 DownloadRequestLimiter::TabDownloadState* tab_download_state = |
| 1252 g_browser_process->download_request_limiter()->GetDownloadState( | 1255 g_browser_process->download_request_limiter()->GetDownloadState( |
| 1253 web_contents, web_contents, true); | 1256 web_contents, web_contents, true); |
| 1254 ASSERT_TRUE(tab_download_state); | 1257 ASSERT_TRUE(tab_download_state); |
| 1255 tab_download_state->set_download_status( | 1258 tab_download_state->set_download_status( |
| 1256 DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED); | 1259 DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED); |
| 1257 | 1260 |
| 1258 // Try to start the download via Javascript and wait for the corresponding | 1261 // Try to start the download via Javascript and wait for the corresponding |
| 1259 // load stop event. | 1262 // load stop event. |
| 1260 content::TestNavigationObserver observer(web_contents); | 1263 content::TestNavigationObserver observer(web_contents); |
| 1261 bool download_assempted; | 1264 bool download_attempted; |
| 1262 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 1265 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 1263 browser()->tab_strip_model()->GetActiveWebContents(), | 1266 browser()->tab_strip_model()->GetActiveWebContents(), |
| 1264 "window.domAutomationController.send(startDownload());", | 1267 "window.domAutomationController.send(startDownload());", |
| 1265 &download_assempted)); | 1268 &download_attempted)); |
| 1266 ASSERT_TRUE(download_assempted); | 1269 ASSERT_TRUE(download_attempted); |
| 1267 observer.Wait(); | 1270 observer.Wait(); |
| 1268 | 1271 |
| 1269 // Check that we did not download the file. | 1272 // Check that we did not download the file. |
| 1270 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1273 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1271 base::FilePath file_path(DestinationFile(browser(), file)); | 1274 base::FilePath file_path(DestinationFile(browser(), file)); |
| 1272 EXPECT_FALSE(base::PathExists(file_path)); | 1275 EXPECT_FALSE(base::PathExists(file_path)); |
| 1273 | 1276 |
| 1274 // Check state. | 1277 // Check state. |
| 1275 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1278 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1276 | 1279 |
| (...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2284 download_items.clear(); | 2287 download_items.clear(); |
| 2285 GetDownloads(browser(), &download_items); | 2288 GetDownloads(browser(), &download_items); |
| 2286 EXPECT_TRUE(DidShowFileChooser()); | 2289 EXPECT_TRUE(DidShowFileChooser()); |
| 2287 ASSERT_EQ(2u, download_items.size()); | 2290 ASSERT_EQ(2u, download_items.size()); |
| 2288 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); | 2291 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); |
| 2289 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); | 2292 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); |
| 2290 } | 2293 } |
| 2291 | 2294 |
| 2292 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsServer) { | 2295 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsServer) { |
| 2293 DownloadInfo download_info[] = { | 2296 DownloadInfo download_info[] = { |
| 2294 { // Normal navigated download. | 2297 {// Normal navigated download. |
| 2295 "a_zip_file.zip", | 2298 "a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_NAVIGATE, |
| 2296 DOWNLOAD_NAVIGATE, | 2299 content::DOWNLOAD_INTERRUPT_REASON_NONE, true, false}, |
| 2297 content::DOWNLOAD_INTERRUPT_REASON_NONE, | 2300 {// Normal direct download. |
| 2298 true, | 2301 "a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_DIRECT, |
| 2299 false | 2302 content::DOWNLOAD_INTERRUPT_REASON_NONE, true, false}, |
| 2300 }, | 2303 {// Direct download with 404 error. |
| 2301 { // Normal direct download. | 2304 "there_IS_no_spoon.zip", "there_IS_no_spoon.zip", DOWNLOAD_DIRECT, |
| 2302 "a_zip_file.zip", | 2305 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, true, false}, |
| 2303 DOWNLOAD_DIRECT, | 2306 {// Navigated download with 404 error. |
| 2304 content::DOWNLOAD_INTERRUPT_REASON_NONE, | 2307 "there_IS_no_spoon.zip", "there_IS_no_spoon.zip", DOWNLOAD_NAVIGATE, |
| 2305 true, | 2308 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, false, false}, |
| 2306 false | 2309 {// Direct download with 400 error. |
| 2307 }, | 2310 "zip_file_not_found.zip", "zip_file_not_found.zip", DOWNLOAD_DIRECT, |
| 2308 { // Direct download with 404 error. | 2311 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, true, false}, |
| 2309 "there_IS_no_spoon.zip", | 2312 {// Navigated download with 400 error. |
| 2310 DOWNLOAD_DIRECT, | 2313 "zip_file_not_found.zip", "", DOWNLOAD_NAVIGATE, |
| 2311 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, | 2314 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, false, false}, |
| 2312 true, | 2315 {// Simulates clicking on <a href="http://..." download="">. The name does |
| 2313 false | 2316 // not resolve. But since this is an explicit download, the download |
| 2314 }, | 2317 // should appear on the shelf and the error should be indicated. |
| 2315 { // Navigated download with 404 error. | 2318 "download-anchor-attrib-name-not-resolved.html", |
| 2316 "there_IS_no_spoon.zip", | 2319 "http://doesnotexist/shouldnotberesolved", DOWNLOAD_NAVIGATE, |
| 2317 DOWNLOAD_NAVIGATE, | 2320 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, true, false}, |
| 2318 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, | 2321 {// Simulates clicking on <a href="http://..." download=""> where the URL |
| 2319 false, | 2322 // leads to a 404 response. This is different from the previous test case |
| 2320 false | 2323 // in that the ResourceLoader issues a OnResponseStarted() callback since |
| 2321 }, | 2324 // the headers are successfully received. |
| 2322 { // Direct download with 400 error. | 2325 "download-anchor-attrib-404.html", "there_IS_no_spoon.zip", |
| 2323 "zip_file_not_found.zip", | 2326 DOWNLOAD_NAVIGATE, content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, |
| 2324 DOWNLOAD_DIRECT, | 2327 true, false}, |
| 2325 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | 2328 {// Similar to the above, but the resulting response contains a status |
| 2326 true, | 2329 // code of 400. |
| 2327 false | 2330 "download-anchor-attrib-400.html", "zip_file_not_found.zip", |
| 2328 }, | 2331 DOWNLOAD_NAVIGATE, content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, |
| 2329 { // Navigated download with 400 error. | 2332 true, false}, |
| 2330 "zip_file_not_found.zip", | 2333 {// Direct download of a URL where the hostname doesn't resolve. |
| 2331 DOWNLOAD_NAVIGATE, | 2334 "http://doesnotexist/shouldnotdownloadsuccessfully", |
| 2332 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | 2335 "http://doesnotexist/shouldnotdownloadsuccessfully", DOWNLOAD_DIRECT, |
| 2333 false, | 2336 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, true, false}}; |
| 2334 false | |
| 2335 } | |
| 2336 }; | |
| 2337 | 2337 |
| 2338 DownloadFilesCheckErrors(arraysize(download_info), download_info); | 2338 DownloadFilesCheckErrors(arraysize(download_info), download_info); |
| 2339 } | 2339 } |
| 2340 | 2340 |
| 2341 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsFile) { | 2341 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsFile) { |
| 2342 FileErrorInjectInfo error_info[] = { | 2342 FileErrorInjectInfo error_info[] = { |
| 2343 { // Navigated download with injected "Disk full" error in Initialize(). | 2343 {// Navigated download with injected "Disk full" error in Initialize(). |
| 2344 { "a_zip_file.zip", | 2344 {"a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_NAVIGATE, |
| 2345 DOWNLOAD_NAVIGATE, | 2345 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, true, false}, |
| 2346 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 2346 { |
| 2347 1 | 2347 "", content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 0, |
| 2348 }, | 2348 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
| 2349 { | 2349 }}, |
| 2350 "", | 2350 {// Direct download with injected "Disk full" error in Initialize(). |
| 2351 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, | 2351 {"a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_DIRECT, |
| 2352 0, | 2352 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, true, false}, |
| 2353 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 2353 { |
| 2354 } | 2354 "", content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 0, |
| 2355 }, | 2355 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
| 2356 { // Direct download with injected "Disk full" error in Initialize(). | 2356 }}, |
| 2357 { "a_zip_file.zip", | 2357 {// Navigated download with injected "Disk full" error in Write(). |
| 2358 DOWNLOAD_DIRECT, | 2358 {"a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_NAVIGATE, |
| 2359 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 2359 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, true, false}, |
| 2360 1 | 2360 { |
| 2361 }, | 2361 "", content::TestFileErrorInjector::FILE_OPERATION_WRITE, 0, |
| 2362 { | 2362 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
| 2363 "", | 2363 }}, |
| 2364 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, | 2364 {// Direct download with injected "Disk full" error in Write(). |
| 2365 0, | 2365 {"a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_DIRECT, |
| 2366 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 2366 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, true, false}, |
| 2367 } | 2367 { |
| 2368 }, | 2368 "", content::TestFileErrorInjector::FILE_OPERATION_WRITE, 0, |
| 2369 { // Navigated download with injected "Disk full" error in Write(). | 2369 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
| 2370 { "a_zip_file.zip", | 2370 }}, |
| 2371 DOWNLOAD_NAVIGATE, | 2371 {// Navigated download with injected "Failed" error in Initialize(). |
| 2372 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 2372 {"a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_NAVIGATE, |
| 2373 1 | 2373 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, true, false}, |
| 2374 }, | 2374 { |
| 2375 { | 2375 "", content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 0, |
| 2376 "", | 2376 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
| 2377 content::TestFileErrorInjector::FILE_OPERATION_WRITE, | 2377 }}, |
| 2378 0, | 2378 {// Direct download with injected "Failed" error in Initialize(). |
| 2379 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 2379 {"a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_DIRECT, |
| 2380 } | 2380 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, true, false}, |
| 2381 }, | 2381 { |
| 2382 { // Direct download with injected "Disk full" error in Write(). | 2382 "", content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 0, |
| 2383 { "a_zip_file.zip", | 2383 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
| 2384 DOWNLOAD_DIRECT, | 2384 }}, |
| 2385 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 2385 {// Navigated download with injected "Failed" error in Write(). |
| 2386 1 | 2386 {"a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_NAVIGATE, |
| 2387 }, | 2387 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, true, false}, |
| 2388 { | 2388 { |
| 2389 "", | 2389 "", content::TestFileErrorInjector::FILE_OPERATION_WRITE, 0, |
| 2390 content::TestFileErrorInjector::FILE_OPERATION_WRITE, | 2390 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
| 2391 0, | 2391 }}, |
| 2392 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 2392 {// Direct download with injected "Failed" error in Write(). |
| 2393 } | 2393 {"a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_DIRECT, |
| 2394 }, | 2394 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, true, false}, |
| 2395 { // Navigated download with injected "Failed" error in Initialize(). | 2395 { |
| 2396 { "a_zip_file.zip", | 2396 "", content::TestFileErrorInjector::FILE_OPERATION_WRITE, 0, |
| 2397 DOWNLOAD_NAVIGATE, | 2397 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
| 2398 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | 2398 }}, |
| 2399 1 | 2399 {// Navigated download with injected "Name too long" error in |
| 2400 }, | |
| 2401 { | |
| 2402 "", | |
| 2403 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, | |
| 2404 0, | |
| 2405 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2406 } | |
| 2407 }, | |
| 2408 { // Direct download with injected "Failed" error in Initialize(). | |
| 2409 { "a_zip_file.zip", | |
| 2410 DOWNLOAD_DIRECT, | |
| 2411 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2412 1 | |
| 2413 }, | |
| 2414 { | |
| 2415 "", | |
| 2416 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, | |
| 2417 0, | |
| 2418 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2419 } | |
| 2420 }, | |
| 2421 { // Navigated download with injected "Failed" error in Write(). | |
| 2422 { "a_zip_file.zip", | |
| 2423 DOWNLOAD_NAVIGATE, | |
| 2424 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2425 1 | |
| 2426 }, | |
| 2427 { | |
| 2428 "", | |
| 2429 content::TestFileErrorInjector::FILE_OPERATION_WRITE, | |
| 2430 0, | |
| 2431 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2432 } | |
| 2433 }, | |
| 2434 { // Direct download with injected "Failed" error in Write(). | |
| 2435 { "a_zip_file.zip", | |
| 2436 DOWNLOAD_DIRECT, | |
| 2437 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2438 1 | |
| 2439 }, | |
| 2440 { | |
| 2441 "", | |
| 2442 content::TestFileErrorInjector::FILE_OPERATION_WRITE, | |
| 2443 0, | |
| 2444 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2445 } | |
| 2446 }, | |
| 2447 { // Navigated download with injected "Name too long" error in | |
| 2448 // Initialize(). | 2400 // Initialize(). |
| 2449 { "a_zip_file.zip", | 2401 {"a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_NAVIGATE, |
| 2450 DOWNLOAD_NAVIGATE, | 2402 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, true, false}, |
| 2451 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, | 2403 { |
| 2452 1 | 2404 "", content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 0, |
| 2453 }, | 2405 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, |
| 2454 { | 2406 }}, |
| 2455 "", | 2407 {// Direct download with injected "Name too long" error in Initialize(). |
| 2456 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, | 2408 {"a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_DIRECT, |
| 2457 0, | 2409 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, true, false}, |
| 2458 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, | 2410 { |
| 2459 } | 2411 "", content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 0, |
| 2460 }, | 2412 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, |
| 2461 { // Direct download with injected "Name too long" error in Initialize(). | 2413 }}, |
| 2462 { "a_zip_file.zip", | 2414 {// Navigated download with injected "Name too long" error in Write(). |
| 2463 DOWNLOAD_DIRECT, | 2415 {"a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_NAVIGATE, |
| 2464 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, | 2416 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, true, false}, |
| 2465 1 | 2417 { |
| 2466 }, | 2418 "", content::TestFileErrorInjector::FILE_OPERATION_WRITE, 0, |
| 2467 { | 2419 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
| 2468 "", | 2420 }}, |
| 2469 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, | 2421 {// Direct download with injected "Name too long" error in Write(). |
| 2470 0, | 2422 {"a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_DIRECT, |
| 2471 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, | 2423 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, true, false}, |
| 2472 } | 2424 { |
| 2473 }, | 2425 "", content::TestFileErrorInjector::FILE_OPERATION_WRITE, 0, |
| 2474 { // Navigated download with injected "Name too long" error in Write(). | 2426 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
| 2475 { "a_zip_file.zip", | 2427 }}, |
| 2476 DOWNLOAD_NAVIGATE, | 2428 {// Direct download with injected "Disk full" error in 2nd Write(). |
| 2477 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | 2429 {"06bESSE21Evolution.ppt", "06bESSE21Evolution.ppt", DOWNLOAD_DIRECT, |
| 2478 1 | 2430 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, true, false}, |
| 2479 }, | 2431 { |
| 2480 { | 2432 "", content::TestFileErrorInjector::FILE_OPERATION_WRITE, 1, |
| 2481 "", | 2433 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
| 2482 content::TestFileErrorInjector::FILE_OPERATION_WRITE, | 2434 }}}; |
| 2483 0, | |
| 2484 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2485 } | |
| 2486 }, | |
| 2487 { // Direct download with injected "Name too long" error in Write(). | |
| 2488 { "a_zip_file.zip", | |
| 2489 DOWNLOAD_DIRECT, | |
| 2490 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2491 1 | |
| 2492 }, | |
| 2493 { | |
| 2494 "", | |
| 2495 content::TestFileErrorInjector::FILE_OPERATION_WRITE, | |
| 2496 0, | |
| 2497 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2498 } | |
| 2499 }, | |
| 2500 { // Direct download with injected "Disk full" error in 2nd Write(). | |
| 2501 { "06bESSE21Evolution.ppt", | |
| 2502 DOWNLOAD_DIRECT, | |
| 2503 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | |
| 2504 1 | |
| 2505 }, | |
| 2506 { | |
| 2507 "", | |
| 2508 content::TestFileErrorInjector::FILE_OPERATION_WRITE, | |
| 2509 1, | |
| 2510 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | |
| 2511 } | |
| 2512 } | |
| 2513 }; | |
| 2514 | 2435 |
| 2515 DownloadInsertFilesErrorCheckErrors(arraysize(error_info), error_info); | 2436 DownloadInsertFilesErrorCheckErrors(arraysize(error_info), error_info); |
| 2516 } | 2437 } |
| 2517 | 2438 |
| 2518 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorReadonlyFolder) { | 2439 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorReadonlyFolder) { |
| 2519 DownloadInfo download_info[] = { | 2440 DownloadInfo download_info[] = { |
| 2520 { | 2441 {"a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_DIRECT, |
| 2521 "a_zip_file.zip", | 2442 // This passes because we switch to the My Documents folder. |
| 2522 DOWNLOAD_DIRECT, | 2443 content::DOWNLOAD_INTERRUPT_REASON_NONE, true, true}, |
| 2523 // This passes because we switch to the My Documents folder. | 2444 {"a_zip_file.zip", "a_zip_file.zip", DOWNLOAD_NAVIGATE, |
| 2524 content::DOWNLOAD_INTERRUPT_REASON_NONE, | 2445 // This passes because we switch to the My Documents folder. |
| 2525 true, | 2446 content::DOWNLOAD_INTERRUPT_REASON_NONE, true, true}}; |
| 2526 true | |
| 2527 }, | |
| 2528 { | |
| 2529 "a_zip_file.zip", | |
| 2530 DOWNLOAD_NAVIGATE, | |
| 2531 // This passes because we switch to the My Documents folder. | |
| 2532 content::DOWNLOAD_INTERRUPT_REASON_NONE, | |
| 2533 true, | |
| 2534 true | |
| 2535 } | |
| 2536 }; | |
| 2537 | 2447 |
| 2538 DownloadFilesToReadonlyFolder(arraysize(download_info), download_info); | 2448 DownloadFilesToReadonlyFolder(arraysize(download_info), download_info); |
| 2539 } | 2449 } |
| 2540 | 2450 |
| 2541 // Test that we show a dangerous downloads warning for a dangerous file | 2451 // Test that we show a dangerous downloads warning for a dangerous file |
| 2542 // downloaded through a blob: URL. | 2452 // downloaded through a blob: URL. |
| 2543 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDangerousBlobData) { | 2453 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDangerousBlobData) { |
| 2544 #if defined(OS_WIN) | 2454 #if defined(OS_WIN) |
| 2545 // On Windows, if SafeBrowsing is enabled, certain file types (.exe, .cab, | 2455 // On Windows, if SafeBrowsing is enabled, certain file types (.exe, .cab, |
| 2546 // .msi) will be handled by the DownloadProtectionService. However, if the URL | 2456 // .msi) will be handled by the DownloadProtectionService. However, if the URL |
| (...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3636 | 3546 |
| 3637 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( | 3547 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( |
| 3638 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 3548 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 3639 ui_test_utils::NavigateToURL(browser(), extension_url); | 3549 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 3640 | 3550 |
| 3641 observer->WaitForFinished(); | 3551 observer->WaitForFinished(); |
| 3642 | 3552 |
| 3643 // Download shelf should close. | 3553 // Download shelf should close. |
| 3644 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3554 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3645 } | 3555 } |
| OLD | NEW |