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> |
| 6 |
5 #include "base/bind.h" | 7 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
7 #include "base/file_path.h" | 9 #include "base/file_path.h" |
8 #include "base/file_util.h" | 10 #include "base/file_util.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "base/path_service.h" | 12 #include "base/path_service.h" |
11 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.h" |
12 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
13 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
14 #include "base/test/test_file_util.h" | 16 #include "base/test/test_file_util.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #include "content/browser/net/url_request_mock_http_job.h" | 50 #include "content/browser/net/url_request_mock_http_job.h" |
49 #include "content/browser/net/url_request_slow_download_job.h" | 51 #include "content/browser/net/url_request_slow_download_job.h" |
50 #include "content/browser/renderer_host/render_view_host.h" | 52 #include "content/browser/renderer_host/render_view_host.h" |
51 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 53 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
52 #include "content/public/browser/download_item.h" | 54 #include "content/public/browser/download_item.h" |
53 #include "content/public/browser/download_manager.h" | 55 #include "content/public/browser/download_manager.h" |
54 #include "content/public/browser/notification_source.h" | 56 #include "content/public/browser/notification_source.h" |
55 #include "content/public/browser/web_contents.h" | 57 #include "content/public/browser/web_contents.h" |
56 #include "content/public/common/context_menu_params.h" | 58 #include "content/public/common/context_menu_params.h" |
57 #include "content/public/common/page_transition_types.h" | 59 #include "content/public/common/page_transition_types.h" |
| 60 #include "content/test/test_file_error_injector.h" |
58 #include "content/test/test_navigation_observer.h" | 61 #include "content/test/test_navigation_observer.h" |
59 #include "net/base/net_util.h" | 62 #include "net/base/net_util.h" |
60 #include "testing/gtest/include/gtest/gtest.h" | 63 #include "testing/gtest/include/gtest/gtest.h" |
61 | 64 |
62 using content::BrowserThread; | 65 using content::BrowserThread; |
63 using content::DownloadItem; | 66 using content::DownloadItem; |
64 using content::DownloadManager; | 67 using content::DownloadManager; |
65 using content::WebContents; | 68 using content::WebContents; |
66 | 69 |
67 namespace { | 70 namespace { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 }; | 302 }; |
300 | 303 |
301 // Information passed in to |DownloadFileCheckErrors()|. | 304 // Information passed in to |DownloadFileCheckErrors()|. |
302 struct DownloadInfo { | 305 struct DownloadInfo { |
303 const char* url_name; // URL for the download. | 306 const char* url_name; // URL for the download. |
304 DownloadMethod download_method; // Navigation or Direct. | 307 DownloadMethod download_method; // Navigation or Direct. |
305 InterruptReason reason; // Download interrupt reason (NONE is OK). | 308 InterruptReason reason; // Download interrupt reason (NONE is OK). |
306 bool show_download_item; // True if the download item appears on the shelf. | 309 bool show_download_item; // True if the download item appears on the shelf. |
307 }; | 310 }; |
308 | 311 |
| 312 struct FileErrorInjectInfo { |
| 313 DownloadInfo download_info; |
| 314 content::TestFileErrorInjector::FileErrorInfo error_info; |
| 315 }; |
| 316 |
309 DownloadTest() { | 317 DownloadTest() { |
310 EnableDOMAutomation(); | 318 EnableDOMAutomation(); |
311 } | 319 } |
312 | 320 |
313 void SetUpOnMainThread() OVERRIDE { | 321 void SetUpOnMainThread() OVERRIDE { |
314 BrowserThread::PostTask( | 322 BrowserThread::PostTask( |
315 BrowserThread::IO, FROM_HERE, | 323 BrowserThread::IO, FROM_HERE, |
316 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 324 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
317 } | 325 } |
318 | 326 |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 return false; | 681 return false; |
674 | 682 |
675 // Check the contents. | 683 // Check the contents. |
676 EXPECT_EQ(value, file_contents); | 684 EXPECT_EQ(value, file_contents); |
677 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0) | 685 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0) |
678 return false; | 686 return false; |
679 | 687 |
680 return true; | 688 return true; |
681 } | 689 } |
682 | 690 |
683 // Attempts to download a file, based on information in |download_info|. | 691 void DownloadFilesCheckErrorsSetup() { |
684 void DownloadFileCheckErrors(const DownloadInfo& download_info) { | |
685 ASSERT_TRUE(test_server()->Start()); | 692 ASSERT_TRUE(test_server()->Start()); |
686 std::vector<DownloadItem*> download_items; | 693 std::vector<DownloadItem*> download_items; |
687 GetDownloads(browser(), &download_items); | 694 GetDownloads(browser(), &download_items); |
688 ASSERT_TRUE(download_items.empty()); | 695 ASSERT_TRUE(download_items.empty()); |
689 | 696 |
690 NullSelectFile(browser()); | 697 NullSelectFile(browser()); |
| 698 } |
| 699 |
| 700 void DownloadFilesCheckErrorsLoop(const DownloadInfo& download_info, |
| 701 size_t i) { |
| 702 std::stringstream s; |
| 703 s << " " << __FUNCTION__ << "()" |
| 704 << " index = " << i |
| 705 << " url = '" << download_info.url_name << "'" |
| 706 << " method = " |
| 707 << ((download_info.download_method == DOWNLOAD_DIRECT) ? |
| 708 "DOWNLOAD_DIRECT" : "DOWNLOAD_NAVIGATE") |
| 709 << " show_item = " << download_info.show_download_item |
| 710 << " reason = " |
| 711 << InterruptReasonDebugString(download_info.reason); |
| 712 |
| 713 std::vector<DownloadItem*> download_items; |
| 714 GetDownloads(browser(), &download_items); |
| 715 size_t downloads_expected = download_items.size(); |
691 | 716 |
692 std::string server_path = "files/downloads/"; | 717 std::string server_path = "files/downloads/"; |
693 server_path += download_info.url_name; | 718 server_path += download_info.url_name; |
694 GURL url = test_server()->GetURL(server_path); | 719 GURL url = test_server()->GetURL(server_path); |
695 ASSERT_TRUE(url.is_valid()); | 720 ASSERT_TRUE(url.is_valid()) << s.str(); |
696 | 721 |
697 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); | 722 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); |
| 723 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 724 ASSERT_TRUE(web_contents) << s.str(); |
| 725 |
698 scoped_ptr<DownloadTestObserver> observer( | 726 scoped_ptr<DownloadTestObserver> observer( |
699 new DownloadTestObserver( | 727 new DownloadTestObserver( |
700 download_manager, | 728 download_manager, |
701 1, | 729 1, |
702 download_info.reason == DOWNLOAD_INTERRUPT_REASON_NONE ? | 730 download_info.reason == DOWNLOAD_INTERRUPT_REASON_NONE ? |
703 DownloadItem::COMPLETE : // Really done | 731 DownloadItem::COMPLETE : // Really done. |
704 DownloadItem::INTERRUPTED, | 732 DownloadItem::INTERRUPTED, // Error detected. |
705 false, // Don't bail on select file. | 733 false, // Don't bail on select file. |
706 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 734 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
707 | 735 |
708 if (download_info.download_method == DOWNLOAD_DIRECT) { | 736 if (download_info.download_method == DOWNLOAD_DIRECT) { |
709 // Go directly to download. | 737 // Go directly to download. Don't wait until it's done. |
710 WebContents* web_contents = browser()->GetSelectedWebContents(); | |
711 ASSERT_TRUE(web_contents); | |
712 DownloadSaveInfo save_info; | 738 DownloadSaveInfo save_info; |
| 739 // NOTE: |prompt_for_save_location| may change during the download. |
713 save_info.prompt_for_save_location = false; | 740 save_info.prompt_for_save_location = false; |
714 | 741 |
715 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( | 742 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( |
716 new DownloadTestItemCreationObserver); | 743 new DownloadTestItemCreationObserver); |
717 | 744 |
718 DownloadManagerForBrowser(browser())->DownloadUrl( | 745 DownloadManagerForBrowser(browser())->DownloadUrl( |
719 url, GURL(""), "", false, -1, save_info, web_contents, | 746 url, GURL(""), "", false, -1, save_info, web_contents, |
720 creation_observer->callback()); | 747 creation_observer->callback()); |
721 | 748 |
722 // Wait until the item is created, or we have determined that it | 749 // Wait until the item is created, or we have determined that it |
723 // won't be. | 750 // won't be. |
724 creation_observer->WaitForDownloadItemCreation(); | 751 creation_observer->WaitForDownloadItemCreation(); |
725 | 752 |
726 EXPECT_EQ(download_info.show_download_item, creation_observer->started()); | 753 EXPECT_EQ(download_info.show_download_item, creation_observer->started()); |
727 } else { | 754 } else { |
728 // Navigate to URL normally, wait until done. | 755 // Navigate to URL normally, wait until done. |
729 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), | 756 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), |
730 url, | 757 url, |
731 1); | 758 1); |
732 } | 759 } |
733 | 760 |
734 if (download_info.show_download_item) { | 761 if (download_info.show_download_item) { |
| 762 downloads_expected++; |
735 observer->WaitForFinished(); | 763 observer->WaitForFinished(); |
736 DCHECK_EQ(0u, observer->NumOtherDownloadsSeen()); | 764 DCHECK_EQ(0u, observer->NumOtherDownloadsSeen()); |
737 } | 765 } |
738 | 766 |
739 // Validate that the correct file was downloaded. | 767 // Wait till the download files are destroyed. |
| 768 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
| 769 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::UI); |
| 770 |
| 771 // Validate that the correct files were downloaded. |
740 download_items.clear(); | 772 download_items.clear(); |
741 GetDownloads(browser(), &download_items); | 773 GetDownloads(browser(), &download_items); |
742 size_t item_count = download_info.show_download_item ? 1 : 0; | 774 ASSERT_EQ(downloads_expected, download_items.size()) << s.str(); |
743 ASSERT_EQ(item_count, download_items.size()); | |
744 | 775 |
745 if (download_info.show_download_item) { | 776 if (download_info.show_download_item) { |
| 777 // Find the last download item. |
746 DownloadItem* item = download_items[0]; | 778 DownloadItem* item = download_items[0]; |
747 ASSERT_EQ(url, item->GetOriginalUrl()); | 779 for (size_t d = 1; d < downloads_expected; ++d) { |
| 780 if (download_items[d]->GetStartTime() > item->GetStartTime()) |
| 781 item = download_items[d]; |
| 782 } |
748 | 783 |
749 ASSERT_EQ(download_info.reason, item->GetLastReason()); | 784 ASSERT_EQ(url, item->GetOriginalUrl()) << s.str(); |
| 785 |
| 786 ASSERT_EQ(download_info.reason, item->GetLastReason()) << s.str(); |
750 } | 787 } |
751 } | 788 } |
752 | 789 |
| 790 // Attempts to download a set of files, based on information in the |
| 791 // |download_info| array. |count| is the number of files. |
| 792 // If a Select File dialog appears, it will choose the default and return |
| 793 // immediately. |
| 794 void DownloadFilesCheckErrors(size_t count, DownloadInfo* download_info) { |
| 795 DownloadFilesCheckErrorsSetup(); |
| 796 |
| 797 for (size_t i = 0; i < count; ++i) { |
| 798 DownloadFilesCheckErrorsLoop(download_info[i], i); |
| 799 } |
| 800 } |
| 801 |
| 802 void DownloadInsertFilesErrorCheckErrorsLoop( |
| 803 scoped_refptr<content::TestFileErrorInjector> injector, |
| 804 const FileErrorInjectInfo& info, |
| 805 size_t i) { |
| 806 std::stringstream s; |
| 807 s << " " << __FUNCTION__ << "()" |
| 808 << " index = " << i |
| 809 << " url = " << info.error_info.url |
| 810 << " operation code = " << |
| 811 content::TestFileErrorInjector::DebugString( |
| 812 info.error_info.code) |
| 813 << " instance = " << info.error_info.operation_instance |
| 814 << " error = " << net::ErrorToString( |
| 815 info.error_info.net_error); |
| 816 |
| 817 injector->ClearErrors(); |
| 818 injector->AddError(info.error_info); |
| 819 |
| 820 injector->InjectErrors(); |
| 821 |
| 822 DownloadFilesCheckErrorsLoop(info.download_info, i); |
| 823 |
| 824 size_t expected_successes = info.download_info.show_download_item ? 1u : 0u; |
| 825 EXPECT_EQ(expected_successes, injector->TotalFileCount()) << s.str(); |
| 826 EXPECT_EQ(0u, injector->CurrentFileCount()) << s.str(); |
| 827 |
| 828 if (info.download_info.show_download_item) |
| 829 EXPECT_TRUE(injector->HadFile(GURL(info.error_info.url))) << s.str(); |
| 830 } |
| 831 |
| 832 void DownloadInsertFilesErrorCheckErrors(size_t count, |
| 833 FileErrorInjectInfo* info) { |
| 834 DownloadFilesCheckErrorsSetup(); |
| 835 |
| 836 // Set up file failures. |
| 837 scoped_refptr<content::TestFileErrorInjector> injector( |
| 838 content::TestFileErrorInjector::Create()); |
| 839 |
| 840 for (size_t i = 0; i < count; ++i) { |
| 841 // Set up the full URL, for download file tracking. |
| 842 std::string server_path = "files/downloads/"; |
| 843 server_path += info[i].download_info.url_name; |
| 844 GURL url = test_server()->GetURL(server_path); |
| 845 info[i].error_info.url = url.spec(); |
| 846 |
| 847 DownloadInsertFilesErrorCheckErrorsLoop(injector, info[i], i); |
| 848 } |
| 849 } |
| 850 |
753 private: | 851 private: |
754 // Location of the test data. | 852 // Location of the test data. |
755 FilePath test_dir_; | 853 FilePath test_dir_; |
756 | 854 |
757 // Location of the downloads directory for these tests | 855 // Location of the downloads directory for these tests |
758 ScopedTempDir downloads_directory_; | 856 ScopedTempDir downloads_directory_; |
759 }; | 857 }; |
760 | 858 |
761 // NOTES: | 859 // NOTES: |
762 // | 860 // |
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2013 | 2111 |
2014 // Validate that the correct file was downloaded via the context menu. | 2112 // Validate that the correct file was downloaded via the context menu. |
2015 download_items.clear(); | 2113 download_items.clear(); |
2016 GetDownloads(browser(), &download_items); | 2114 GetDownloads(browser(), &download_items); |
2017 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); | 2115 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); |
2018 ASSERT_EQ(2u, download_items.size()); | 2116 ASSERT_EQ(2u, download_items.size()); |
2019 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); | 2117 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); |
2020 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); | 2118 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); |
2021 } | 2119 } |
2022 | 2120 |
2023 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadNavigate) { | 2121 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsServer) { |
2024 DownloadInfo download_info = { | 2122 DownloadInfo download_info[] = { |
2025 "a_zip_file.zip", | 2123 { // Normal navigated download. |
2026 DOWNLOAD_NAVIGATE, | 2124 "a_zip_file.zip", |
2027 DOWNLOAD_INTERRUPT_REASON_NONE, | 2125 DOWNLOAD_NAVIGATE, |
2028 true | 2126 DOWNLOAD_INTERRUPT_REASON_NONE, |
| 2127 true |
| 2128 }, |
| 2129 { // Normal direct download. |
| 2130 "a_zip_file.zip", |
| 2131 DOWNLOAD_DIRECT, |
| 2132 DOWNLOAD_INTERRUPT_REASON_NONE, |
| 2133 true |
| 2134 }, |
| 2135 { // Direct download with 404 error. |
| 2136 "there_IS_no_spoon.zip", |
| 2137 DOWNLOAD_DIRECT, |
| 2138 DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, |
| 2139 true |
| 2140 }, |
| 2141 { // Navigated download with 404 error. |
| 2142 "there_IS_no_spoon.zip", |
| 2143 DOWNLOAD_NAVIGATE, |
| 2144 DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, |
| 2145 false |
| 2146 }, |
| 2147 { // Direct download with 400 error. |
| 2148 "zip_file_not_found.zip", |
| 2149 DOWNLOAD_DIRECT, |
| 2150 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, |
| 2151 true |
| 2152 }, |
| 2153 { // Navigated download with 400 error. |
| 2154 "zip_file_not_found.zip", |
| 2155 DOWNLOAD_NAVIGATE, |
| 2156 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, |
| 2157 false |
| 2158 } |
2029 }; | 2159 }; |
2030 | 2160 |
2031 // Do initial setup. | 2161 // Do initial setup. |
2032 ASSERT_TRUE(InitialSetup(false)); | 2162 ASSERT_TRUE(InitialSetup(false)); |
2033 DownloadFileCheckErrors(download_info); | 2163 |
| 2164 DownloadFilesCheckErrors(ARRAYSIZE_UNSAFE(download_info), download_info); |
2034 } | 2165 } |
2035 | 2166 |
2036 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDirect) { | 2167 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsFile) { |
2037 DownloadInfo download_info = { | 2168 FileErrorInjectInfo error_info[] = { |
2038 "a_zip_file.zip", | 2169 { // Navigated download with injected "Disk full" error in Initialize(). |
2039 DOWNLOAD_DIRECT, | 2170 { "a_zip_file.zip", |
2040 DOWNLOAD_INTERRUPT_REASON_NONE, | 2171 DOWNLOAD_NAVIGATE, |
2041 true | 2172 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
| 2173 1 |
| 2174 }, |
| 2175 { |
| 2176 "", |
| 2177 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, |
| 2178 0, |
| 2179 net::ERR_FILE_NO_SPACE |
| 2180 } |
| 2181 }, |
| 2182 { // Direct download with injected "Disk full" error in Initialize(). |
| 2183 { "a_zip_file.zip", |
| 2184 DOWNLOAD_DIRECT, |
| 2185 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
| 2186 1 |
| 2187 }, |
| 2188 { |
| 2189 "", |
| 2190 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, |
| 2191 0, |
| 2192 net::ERR_FILE_NO_SPACE |
| 2193 } |
| 2194 }, |
| 2195 { // Navigated download with injected "Disk full" error in Write(). |
| 2196 { "a_zip_file.zip", |
| 2197 DOWNLOAD_NAVIGATE, |
| 2198 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
| 2199 1 |
| 2200 }, |
| 2201 { |
| 2202 "", |
| 2203 content::TestFileErrorInjector::FILE_OPERATION_WRITE, |
| 2204 0, |
| 2205 net::ERR_FILE_NO_SPACE |
| 2206 } |
| 2207 }, |
| 2208 { // Direct download with injected "Disk full" error in Write(). |
| 2209 { "a_zip_file.zip", |
| 2210 DOWNLOAD_DIRECT, |
| 2211 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
| 2212 1 |
| 2213 }, |
| 2214 { |
| 2215 "", |
| 2216 content::TestFileErrorInjector::FILE_OPERATION_WRITE, |
| 2217 0, |
| 2218 net::ERR_FILE_NO_SPACE |
| 2219 } |
| 2220 }, |
| 2221 { // Navigated download with injected "Failed" error in Initialize(). |
| 2222 { "a_zip_file.zip", |
| 2223 DOWNLOAD_NAVIGATE, |
| 2224 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
| 2225 1 |
| 2226 }, |
| 2227 { |
| 2228 "", |
| 2229 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, |
| 2230 0, |
| 2231 net::ERR_FAILED |
| 2232 } |
| 2233 }, |
| 2234 { // Direct download with injected "Failed" error in Initialize(). |
| 2235 { "a_zip_file.zip", |
| 2236 DOWNLOAD_DIRECT, |
| 2237 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
| 2238 1 |
| 2239 }, |
| 2240 { |
| 2241 "", |
| 2242 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, |
| 2243 0, |
| 2244 net::ERR_FAILED |
| 2245 } |
| 2246 }, |
| 2247 { // Navigated download with injected "Failed" error in Write(). |
| 2248 { "a_zip_file.zip", |
| 2249 DOWNLOAD_NAVIGATE, |
| 2250 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
| 2251 1 |
| 2252 }, |
| 2253 { |
| 2254 "", |
| 2255 content::TestFileErrorInjector::FILE_OPERATION_WRITE, |
| 2256 0, |
| 2257 net::ERR_FAILED |
| 2258 } |
| 2259 }, |
| 2260 { // Direct download with injected "Failed" error in Write(). |
| 2261 { "a_zip_file.zip", |
| 2262 DOWNLOAD_DIRECT, |
| 2263 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
| 2264 1 |
| 2265 }, |
| 2266 { |
| 2267 "", |
| 2268 content::TestFileErrorInjector::FILE_OPERATION_WRITE, |
| 2269 0, |
| 2270 net::ERR_FAILED |
| 2271 } |
| 2272 }, |
| 2273 { // Navigated download with injected "Name too long" error in |
| 2274 // Initialize(). |
| 2275 { "a_zip_file.zip", |
| 2276 DOWNLOAD_NAVIGATE, |
| 2277 DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, |
| 2278 1 |
| 2279 }, |
| 2280 { |
| 2281 "", |
| 2282 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, |
| 2283 0, |
| 2284 net::ERR_FILE_PATH_TOO_LONG |
| 2285 } |
| 2286 }, |
| 2287 { // Direct download with injected "Name too long" error in Initialize(). |
| 2288 { "a_zip_file.zip", |
| 2289 DOWNLOAD_DIRECT, |
| 2290 DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, |
| 2291 1 |
| 2292 }, |
| 2293 { |
| 2294 "", |
| 2295 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, |
| 2296 0, |
| 2297 net::ERR_FILE_PATH_TOO_LONG |
| 2298 } |
| 2299 }, |
| 2300 { // Navigated download with injected "Name too long" error in Write(). |
| 2301 { "a_zip_file.zip", |
| 2302 DOWNLOAD_NAVIGATE, |
| 2303 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
| 2304 1 |
| 2305 }, |
| 2306 { |
| 2307 "", |
| 2308 content::TestFileErrorInjector::FILE_OPERATION_WRITE, |
| 2309 0, |
| 2310 net::ERR_INVALID_HANDLE |
| 2311 } |
| 2312 }, |
| 2313 { // Direct download with injected "Name too long" error in Write(). |
| 2314 { "a_zip_file.zip", |
| 2315 DOWNLOAD_DIRECT, |
| 2316 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
| 2317 1 |
| 2318 }, |
| 2319 { |
| 2320 "", |
| 2321 content::TestFileErrorInjector::FILE_OPERATION_WRITE, |
| 2322 0, |
| 2323 net::ERR_INVALID_HANDLE |
| 2324 } |
| 2325 }, |
| 2326 { // Direct download with injected "Disk full" error in 2nd Write(). |
| 2327 { "06bESSE21Evolution.ppt", |
| 2328 DOWNLOAD_DIRECT, |
| 2329 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
| 2330 1 |
| 2331 }, |
| 2332 { |
| 2333 "", |
| 2334 content::TestFileErrorInjector::FILE_OPERATION_WRITE, |
| 2335 1, |
| 2336 net::ERR_FILE_NO_SPACE |
| 2337 } |
| 2338 } |
2042 }; | 2339 }; |
2043 | 2340 |
2044 // Do initial setup. | 2341 DownloadInsertFilesErrorCheckErrors(ARRAYSIZE_UNSAFE(error_info), error_info); |
2045 ASSERT_TRUE(InitialSetup(false)); | |
2046 DownloadFileCheckErrors(download_info); | |
2047 } | 2342 } |
2048 | |
2049 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError404Direct) { | |
2050 DownloadInfo download_info = { | |
2051 "there_IS_no_spoon.zip", | |
2052 DOWNLOAD_DIRECT, | |
2053 DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, | |
2054 true | |
2055 }; | |
2056 | |
2057 // Do initial setup. | |
2058 ASSERT_TRUE(InitialSetup(false)); | |
2059 DownloadFileCheckErrors(download_info); | |
2060 } | |
2061 | |
2062 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError404Navigate) { | |
2063 DownloadInfo download_info = { | |
2064 "there_IS_no_spoon.zip", | |
2065 DOWNLOAD_NAVIGATE, | |
2066 DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, | |
2067 false | |
2068 }; | |
2069 | |
2070 // Do initial setup. | |
2071 ASSERT_TRUE(InitialSetup(false)); | |
2072 DownloadFileCheckErrors(download_info); | |
2073 } | |
2074 | |
2075 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError400Direct) { | |
2076 DownloadInfo download_info = { | |
2077 "zip_file_not_found.zip", | |
2078 DOWNLOAD_DIRECT, | |
2079 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | |
2080 true | |
2081 }; | |
2082 | |
2083 // Do initial setup. | |
2084 ASSERT_TRUE(InitialSetup(false)); | |
2085 DownloadFileCheckErrors(download_info); | |
2086 } | |
2087 | |
2088 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError400Navigate) { | |
2089 DownloadInfo download_info = { | |
2090 "zip_file_not_found.zip", | |
2091 DOWNLOAD_NAVIGATE, | |
2092 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | |
2093 false | |
2094 }; | |
2095 | |
2096 // Do initial setup. | |
2097 ASSERT_TRUE(InitialSetup(false)); | |
2098 DownloadFileCheckErrors(download_info); | |
2099 } | |
OLD | NEW |