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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 #include "content/browser/net/url_request_mock_http_job.h" | 47 #include "content/browser/net/url_request_mock_http_job.h" |
| 48 #include "content/browser/net/url_request_slow_download_job.h" | 48 #include "content/browser/net/url_request_slow_download_job.h" |
| 49 #include "content/browser/renderer_host/render_view_host.h" | 49 #include "content/browser/renderer_host/render_view_host.h" |
| 50 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 50 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 51 #include "content/public/browser/download_item.h" | 51 #include "content/public/browser/download_item.h" |
| 52 #include "content/public/browser/download_manager.h" | 52 #include "content/public/browser/download_manager.h" |
| 53 #include "content/public/browser/notification_source.h" | 53 #include "content/public/browser/notification_source.h" |
| 54 #include "content/public/browser/web_contents.h" | 54 #include "content/public/browser/web_contents.h" |
| 55 #include "content/public/common/context_menu_params.h" | 55 #include "content/public/common/context_menu_params.h" |
| 56 #include "content/public/common/page_transition_types.h" | 56 #include "content/public/common/page_transition_types.h" |
| 57 #include "content/test/test_file_error_injector.h" | |
| 57 #include "net/base/net_util.h" | 58 #include "net/base/net_util.h" |
| 58 #include "testing/gtest/include/gtest/gtest.h" | 59 #include "testing/gtest/include/gtest/gtest.h" |
| 59 | 60 |
| 60 using content::BrowserThread; | 61 using content::BrowserThread; |
| 61 using content::DownloadItem; | 62 using content::DownloadItem; |
| 62 using content::DownloadManager; | 63 using content::DownloadManager; |
| 63 using content::WebContents; | 64 using content::WebContents; |
| 64 | 65 |
| 65 namespace { | 66 namespace { |
| 66 | 67 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 }; | 298 }; |
| 298 | 299 |
| 299 // Information passed in to |DownloadFileCheckErrors()|. | 300 // Information passed in to |DownloadFileCheckErrors()|. |
| 300 struct DownloadInfo { | 301 struct DownloadInfo { |
| 301 const char* url_name; // URL for the download. | 302 const char* url_name; // URL for the download. |
| 302 DownloadMethod download_method; // Navigation or Direct. | 303 DownloadMethod download_method; // Navigation or Direct. |
| 303 InterruptReason reason; // Download interrupt reason (NONE is OK). | 304 InterruptReason reason; // Download interrupt reason (NONE is OK). |
| 304 int download_items_shown; // Number of download items shown on the shelf. | 305 int download_items_shown; // Number of download items shown on the shelf. |
| 305 }; | 306 }; |
| 306 | 307 |
| 308 struct FileErrorInjectInfo { | |
|
cbentzel
2012/02/24 02:25:12
Document this and fields.
ahendrickson
2012/02/24 22:48:39
Done.
| |
| 309 DownloadInfo download_info; | |
| 310 FileOperationCode code; | |
| 311 int operation_index; | |
| 312 net::Error error_to_inject; | |
| 313 }; | |
| 314 | |
| 307 DownloadTest() { | 315 DownloadTest() { |
| 308 EnableDOMAutomation(); | 316 EnableDOMAutomation(); |
| 309 } | 317 } |
| 310 | 318 |
| 311 void SetUpOnMainThread() OVERRIDE { | 319 void SetUpOnMainThread() OVERRIDE { |
| 312 BrowserThread::PostTask( | 320 BrowserThread::PostTask( |
| 313 BrowserThread::IO, FROM_HERE, | 321 BrowserThread::IO, FROM_HERE, |
| 314 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 322 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
| 315 } | 323 } |
| 316 | 324 |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 ASSERT_EQ(item_count, download_items.size()); | 740 ASSERT_EQ(item_count, download_items.size()); |
| 733 | 741 |
| 734 if (item_count > 0) { | 742 if (item_count > 0) { |
| 735 DownloadItem* item = download_items[0]; | 743 DownloadItem* item = download_items[0]; |
| 736 ASSERT_EQ(url, item->GetOriginalUrl()); | 744 ASSERT_EQ(url, item->GetOriginalUrl()); |
| 737 | 745 |
| 738 ASSERT_EQ(download_info.reason, item->GetLastReason()); | 746 ASSERT_EQ(download_info.reason, item->GetLastReason()); |
| 739 } | 747 } |
| 740 } | 748 } |
| 741 | 749 |
| 750 void DownloadInsertFileErrorCheckErrors(const FileErrorInjectInfo& info) { | |
| 751 // Do initial setup. | |
| 752 ASSERT_TRUE(InitialSetup(false)); | |
| 753 | |
| 754 // Set up file failures. | |
| 755 scoped_refptr<TestFileErrorInjector> injector( | |
| 756 TestFileErrorInjector::Create()); | |
| 757 injector->InjectError(0, // First DownloadFile created. | |
| 758 info.code, | |
| 759 info.operation_index, | |
| 760 info.error_to_inject); | |
| 761 | |
| 762 DownloadFileCheckErrors(info.download_info); | |
| 763 } | |
| 764 | |
| 742 private: | 765 private: |
| 743 // Location of the test data. | 766 // Location of the test data. |
| 744 FilePath test_dir_; | 767 FilePath test_dir_; |
| 745 | 768 |
| 746 // Location of the downloads directory for these tests | 769 // Location of the downloads directory for these tests |
| 747 ScopedTempDir downloads_directory_; | 770 ScopedTempDir downloads_directory_; |
| 748 }; | 771 }; |
| 749 | 772 |
| 750 // NOTES: | 773 // NOTES: |
| 751 // | 774 // |
| (...skipping 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2016 "zip_file_not_found.zip", | 2039 "zip_file_not_found.zip", |
| 2017 DOWNLOAD_NAVIGATE, | 2040 DOWNLOAD_NAVIGATE, |
| 2018 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | 2041 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, |
| 2019 0 | 2042 0 |
| 2020 }; | 2043 }; |
| 2021 | 2044 |
| 2022 // Do initial setup. | 2045 // Do initial setup. |
| 2023 ASSERT_TRUE(InitialSetup(false)); | 2046 ASSERT_TRUE(InitialSetup(false)); |
| 2024 DownloadFileCheckErrors(download_info); | 2047 DownloadFileCheckErrors(download_info); |
| 2025 } | 2048 } |
| 2049 | |
| 2050 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceOpenNavigate) { | |
| 2051 FileErrorInjectInfo error_info = { | |
| 2052 { "a_zip_file.zip", | |
| 2053 DOWNLOAD_NAVIGATE, | |
| 2054 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | |
| 2055 1 | |
| 2056 }, | |
| 2057 FILE_OPERATION_INITIALIZE, | |
| 2058 0, | |
| 2059 net::ERR_FILE_NO_SPACE | |
| 2060 }; | |
| 2061 | |
| 2062 DownloadInsertFileErrorCheckErrors(error_info); | |
| 2063 } | |
| 2064 | |
| 2065 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceOpenDirect) { | |
| 2066 FileErrorInjectInfo error_info = { | |
| 2067 { "a_zip_file.zip", | |
| 2068 DOWNLOAD_DIRECT, | |
| 2069 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | |
| 2070 1 | |
| 2071 }, | |
| 2072 FILE_OPERATION_INITIALIZE, | |
| 2073 0, | |
| 2074 net::ERR_FILE_NO_SPACE | |
| 2075 }; | |
| 2076 | |
| 2077 DownloadInsertFileErrorCheckErrors(error_info); | |
| 2078 } | |
| 2079 | |
| 2080 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceWriteNavigate) { | |
| 2081 FileErrorInjectInfo error_info = { | |
| 2082 { "a_zip_file.zip", | |
| 2083 DOWNLOAD_NAVIGATE, | |
| 2084 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | |
| 2085 1 | |
| 2086 }, | |
| 2087 FILE_OPERATION_WRITE, | |
| 2088 0, | |
| 2089 net::ERR_FILE_NO_SPACE | |
| 2090 }; | |
| 2091 | |
| 2092 DownloadInsertFileErrorCheckErrors(error_info); | |
| 2093 } | |
| 2094 | |
| 2095 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceWriteDirect) { | |
| 2096 FileErrorInjectInfo error_info = { | |
| 2097 { "a_zip_file.zip", | |
| 2098 DOWNLOAD_DIRECT, | |
| 2099 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | |
| 2100 1 | |
| 2101 }, | |
| 2102 FILE_OPERATION_WRITE, | |
| 2103 0, | |
| 2104 net::ERR_FILE_NO_SPACE | |
| 2105 }; | |
| 2106 | |
| 2107 DownloadInsertFileErrorCheckErrors(error_info); | |
| 2108 } | |
| 2109 | |
| 2110 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedOpenNavigate) { | |
| 2111 FileErrorInjectInfo error_info = { | |
| 2112 { "a_zip_file.zip", | |
| 2113 DOWNLOAD_NAVIGATE, | |
| 2114 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2115 1 | |
| 2116 }, | |
| 2117 FILE_OPERATION_INITIALIZE, | |
| 2118 0, | |
| 2119 net::ERR_FAILED | |
| 2120 }; | |
| 2121 | |
| 2122 DownloadInsertFileErrorCheckErrors(error_info); | |
| 2123 } | |
| 2124 | |
| 2125 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedOpenDirect) { | |
| 2126 FileErrorInjectInfo error_info = { | |
| 2127 { "a_zip_file.zip", | |
| 2128 DOWNLOAD_DIRECT, | |
| 2129 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2130 1 | |
| 2131 }, | |
| 2132 FILE_OPERATION_INITIALIZE, | |
| 2133 0, | |
| 2134 net::ERR_FAILED | |
| 2135 }; | |
| 2136 | |
| 2137 DownloadInsertFileErrorCheckErrors(error_info); | |
| 2138 } | |
| 2139 | |
| 2140 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedWriteNavigate) { | |
| 2141 FileErrorInjectInfo error_info = { | |
| 2142 { "a_zip_file.zip", | |
| 2143 DOWNLOAD_NAVIGATE, | |
| 2144 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2145 1 | |
| 2146 }, | |
| 2147 FILE_OPERATION_WRITE, | |
| 2148 0, | |
| 2149 net::ERR_FAILED | |
| 2150 }; | |
| 2151 | |
| 2152 DownloadInsertFileErrorCheckErrors(error_info); | |
| 2153 } | |
| 2154 | |
| 2155 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedWriteDirect) { | |
| 2156 FileErrorInjectInfo error_info = { | |
| 2157 { "a_zip_file.zip", | |
| 2158 DOWNLOAD_DIRECT, | |
| 2159 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2160 1 | |
| 2161 }, | |
| 2162 FILE_OPERATION_WRITE, | |
| 2163 0, | |
| 2164 net::ERR_FAILED | |
| 2165 }; | |
| 2166 | |
| 2167 DownloadInsertFileErrorCheckErrors(error_info); | |
| 2168 } | |
| 2169 | |
| 2170 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNameTooLongOpenNavigate) { | |
| 2171 FileErrorInjectInfo error_info = { | |
| 2172 { "a_zip_file.zip", | |
| 2173 DOWNLOAD_NAVIGATE, | |
| 2174 DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, | |
| 2175 1 | |
| 2176 }, | |
| 2177 FILE_OPERATION_INITIALIZE, | |
| 2178 0, | |
| 2179 net::ERR_FILE_PATH_TOO_LONG | |
| 2180 }; | |
| 2181 | |
| 2182 DownloadInsertFileErrorCheckErrors(error_info); | |
| 2183 } | |
| 2184 | |
| 2185 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNameTooLongOpenDirect) { | |
| 2186 FileErrorInjectInfo error_info = { | |
| 2187 { "a_zip_file.zip", | |
| 2188 DOWNLOAD_DIRECT, | |
| 2189 DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, | |
| 2190 1 | |
| 2191 }, | |
| 2192 FILE_OPERATION_INITIALIZE, | |
| 2193 0, | |
| 2194 net::ERR_FILE_PATH_TOO_LONG | |
| 2195 }; | |
| 2196 | |
| 2197 DownloadInsertFileErrorCheckErrors(error_info); | |
| 2198 } | |
| 2199 | |
| 2200 IN_PROC_BROWSER_TEST_F(DownloadTest, | |
| 2201 DownloadErrorFileInvalidHandleWriteNavigate) { | |
| 2202 FileErrorInjectInfo error_info = { | |
| 2203 { "a_zip_file.zip", | |
| 2204 DOWNLOAD_NAVIGATE, | |
| 2205 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2206 1 | |
| 2207 }, | |
| 2208 FILE_OPERATION_WRITE, | |
| 2209 0, | |
| 2210 net::ERR_INVALID_HANDLE | |
| 2211 }; | |
| 2212 | |
| 2213 DownloadInsertFileErrorCheckErrors(error_info); | |
| 2214 } | |
| 2215 | |
| 2216 IN_PROC_BROWSER_TEST_F(DownloadTest, | |
| 2217 DownloadErrorFileInvalidHandleWriteDirect) { | |
| 2218 FileErrorInjectInfo error_info = { | |
| 2219 { "a_zip_file.zip", | |
| 2220 DOWNLOAD_DIRECT, | |
| 2221 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | |
| 2222 1 | |
| 2223 }, | |
| 2224 FILE_OPERATION_WRITE, | |
| 2225 0, | |
| 2226 net::ERR_INVALID_HANDLE | |
| 2227 }; | |
| 2228 | |
| 2229 DownloadInsertFileErrorCheckErrors(error_info); | |
| 2230 } | |
| OLD | NEW |