Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: chrome/browser/download/download_browsertest.cc

Issue 9426029: Test file errors in downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplified injector classes further. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "content/browser/net/url_request_mock_http_job.h" 48 #include "content/browser/net/url_request_mock_http_job.h"
49 #include "content/browser/net/url_request_slow_download_job.h" 49 #include "content/browser/net/url_request_slow_download_job.h"
50 #include "content/browser/renderer_host/render_view_host.h" 50 #include "content/browser/renderer_host/render_view_host.h"
51 #include "content/browser/renderer_host/resource_dispatcher_host.h" 51 #include "content/browser/renderer_host/resource_dispatcher_host.h"
52 #include "content/public/browser/download_item.h" 52 #include "content/public/browser/download_item.h"
53 #include "content/public/browser/download_manager.h" 53 #include "content/public/browser/download_manager.h"
54 #include "content/public/browser/notification_source.h" 54 #include "content/public/browser/notification_source.h"
55 #include "content/public/browser/web_contents.h" 55 #include "content/public/browser/web_contents.h"
56 #include "content/public/common/context_menu_params.h" 56 #include "content/public/common/context_menu_params.h"
57 #include "content/public/common/page_transition_types.h" 57 #include "content/public/common/page_transition_types.h"
58 #include "content/test/test_file_error_injector.h"
58 #include "content/test/test_navigation_observer.h" 59 #include "content/test/test_navigation_observer.h"
59 #include "net/base/net_util.h" 60 #include "net/base/net_util.h"
60 #include "testing/gtest/include/gtest/gtest.h" 61 #include "testing/gtest/include/gtest/gtest.h"
61 62
62 using content::BrowserThread; 63 using content::BrowserThread;
63 using content::DownloadItem; 64 using content::DownloadItem;
64 using content::DownloadManager; 65 using content::DownloadManager;
65 using content::WebContents; 66 using content::WebContents;
66 67
67 namespace { 68 namespace {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 }; 300 };
300 301
301 // Information passed in to |DownloadFileCheckErrors()|. 302 // Information passed in to |DownloadFileCheckErrors()|.
302 struct DownloadInfo { 303 struct DownloadInfo {
303 const char* url_name; // URL for the download. 304 const char* url_name; // URL for the download.
304 DownloadMethod download_method; // Navigation or Direct. 305 DownloadMethod download_method; // Navigation or Direct.
305 InterruptReason reason; // Download interrupt reason (NONE is OK). 306 InterruptReason reason; // Download interrupt reason (NONE is OK).
306 bool show_download_item; // True if the download item appears on the shelf. 307 bool show_download_item; // True if the download item appears on the shelf.
307 }; 308 };
308 309
310 struct FileErrorInjectInfo {
311 DownloadInfo download_info; // See above.
312 content::FileOperationCode code; // A code indicating what file operation
313 // to affect.
314 int operation_index; // The number of the operation to affect (0 = first).
315 net::Error error_to_inject; // The net error to inject into the file op.
316 };
317
309 DownloadTest() { 318 DownloadTest() {
310 EnableDOMAutomation(); 319 EnableDOMAutomation();
311 } 320 }
312 321
313 void SetUpOnMainThread() OVERRIDE { 322 void SetUpOnMainThread() OVERRIDE {
314 BrowserThread::PostTask( 323 BrowserThread::PostTask(
315 BrowserThread::IO, FROM_HERE, 324 BrowserThread::IO, FROM_HERE,
316 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); 325 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
317 } 326 }
318 327
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 ASSERT_EQ(item_count, download_items.size()); 738 ASSERT_EQ(item_count, download_items.size());
730 739
731 if (download_info.show_download_item) { 740 if (download_info.show_download_item) {
732 DownloadItem* item = download_items[0]; 741 DownloadItem* item = download_items[0];
733 ASSERT_EQ(url, item->GetOriginalUrl()); 742 ASSERT_EQ(url, item->GetOriginalUrl());
734 743
735 ASSERT_EQ(download_info.reason, item->GetLastReason()); 744 ASSERT_EQ(download_info.reason, item->GetLastReason());
736 } 745 }
737 } 746 }
738 747
748 void DownloadInsertFileErrorCheckErrors(const FileErrorInjectInfo& info) {
749 // Do initial setup.
750 ASSERT_TRUE(InitialSetup(false));
751
752 // Set up file failures.
753 // |injector| will be owned by the DownloadFileManager (indirectly).
cbentzel 2012/02/27 02:18:54 How hard would it be to change this so the injecto
ahendrickson 2012/02/28 03:28:56 Switched to using RefCountedThreadSafe for the inj
754 content::TestFileErrorInjector* injector =
755 content::TestFileErrorInjector::Create();
756 injector->InjectError(0, // First DownloadFile created.
cbentzel 2012/02/27 02:18:54 I'd remove this argument for now.
ahendrickson 2012/02/28 03:28:56 How strongly do you feel about that?
cbentzel 2012/02/28 10:57:29 Pretty strongly. I don't like adding arguments tha
757 info.code,
758 info.operation_index,
cbentzel 2012/02/27 02:18:54 Do you need operation_index? It looks like it's al
ahendrickson 2012/02/28 03:28:56 Right now the unit tests only try to download smal
cbentzel 2012/02/28 10:57:29 Again, I'd hold off until you have concrete need f
759 info.error_to_inject);
760
761 DownloadFileCheckErrors(info.download_info);
762
763 EXPECT_EQ(1u, injector->FileCreationCount());
764 EXPECT_EQ(0u, injector->CurrentFileCount());
765 }
766
739 private: 767 private:
740 // Location of the test data. 768 // Location of the test data.
741 FilePath test_dir_; 769 FilePath test_dir_;
742 770
743 // Location of the downloads directory for these tests 771 // Location of the downloads directory for these tests
744 ScopedTempDir downloads_directory_; 772 ScopedTempDir downloads_directory_;
745 }; 773 };
746 774
747 // NOTES: 775 // NOTES:
748 // 776 //
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after
2074 "zip_file_not_found.zip", 2102 "zip_file_not_found.zip",
2075 DOWNLOAD_NAVIGATE, 2103 DOWNLOAD_NAVIGATE,
2076 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, 2104 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2077 false 2105 false
2078 }; 2106 };
2079 2107
2080 // Do initial setup. 2108 // Do initial setup.
2081 ASSERT_TRUE(InitialSetup(false)); 2109 ASSERT_TRUE(InitialSetup(false));
2082 DownloadFileCheckErrors(download_info); 2110 DownloadFileCheckErrors(download_info);
2083 } 2111 }
2112
2113 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceOpenNavigate) {
2114 FileErrorInjectInfo error_info = {
2115 { "a_zip_file.zip",
2116 DOWNLOAD_NAVIGATE,
2117 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2118 1
2119 },
2120 content::FILE_OPERATION_INITIALIZE,
2121 0,
2122 net::ERR_FILE_NO_SPACE
cbentzel 2012/02/27 02:18:54 Why would we get NO_SPACE on INITIALIZE?
ahendrickson 2012/02/28 03:28:56 Wouldn't we get that if there are no bytes availab
2123 };
2124
2125 DownloadInsertFileErrorCheckErrors(error_info);
2126 }
2127
2128 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceOpenDirect) {
2129 FileErrorInjectInfo error_info = {
2130 { "a_zip_file.zip",
2131 DOWNLOAD_DIRECT,
2132 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2133 1
2134 },
2135 content::FILE_OPERATION_INITIALIZE,
2136 0,
2137 net::ERR_FILE_NO_SPACE
2138 };
2139
2140 DownloadInsertFileErrorCheckErrors(error_info);
2141 }
2142
2143 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceWriteNavigate) {
2144 FileErrorInjectInfo error_info = {
2145 { "a_zip_file.zip",
2146 DOWNLOAD_NAVIGATE,
2147 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2148 1
2149 },
2150 content::FILE_OPERATION_WRITE,
2151 0,
2152 net::ERR_FILE_NO_SPACE
2153 };
2154
2155 DownloadInsertFileErrorCheckErrors(error_info);
2156 }
2157
2158 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceWriteDirect) {
2159 FileErrorInjectInfo error_info = {
2160 { "a_zip_file.zip",
2161 DOWNLOAD_DIRECT,
2162 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2163 1
2164 },
2165 content::FILE_OPERATION_WRITE,
2166 0,
2167 net::ERR_FILE_NO_SPACE
2168 };
2169
2170 DownloadInsertFileErrorCheckErrors(error_info);
2171 }
2172
2173 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedOpenNavigate) {
2174 FileErrorInjectInfo error_info = {
2175 { "a_zip_file.zip",
2176 DOWNLOAD_NAVIGATE,
2177 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2178 1
2179 },
2180 content::FILE_OPERATION_INITIALIZE,
2181 0,
2182 net::ERR_FAILED
2183 };
2184
2185 DownloadInsertFileErrorCheckErrors(error_info);
2186 }
2187
2188 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedOpenDirect) {
2189 FileErrorInjectInfo error_info = {
2190 { "a_zip_file.zip",
2191 DOWNLOAD_DIRECT,
2192 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2193 1
2194 },
2195 content::FILE_OPERATION_INITIALIZE,
2196 0,
2197 net::ERR_FAILED
2198 };
2199
2200 DownloadInsertFileErrorCheckErrors(error_info);
2201 }
2202
2203 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedWriteNavigate) {
2204 FileErrorInjectInfo error_info = {
2205 { "a_zip_file.zip",
2206 DOWNLOAD_NAVIGATE,
2207 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2208 1
2209 },
2210 content::FILE_OPERATION_WRITE,
2211 0,
2212 net::ERR_FAILED
2213 };
2214
2215 DownloadInsertFileErrorCheckErrors(error_info);
2216 }
2217
2218 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedWriteDirect) {
2219 FileErrorInjectInfo error_info = {
2220 { "a_zip_file.zip",
2221 DOWNLOAD_DIRECT,
2222 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2223 1
2224 },
2225 content::FILE_OPERATION_WRITE,
2226 0,
2227 net::ERR_FAILED
2228 };
2229
2230 DownloadInsertFileErrorCheckErrors(error_info);
2231 }
2232
2233 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNameTooLongOpenNavigate) {
2234 FileErrorInjectInfo error_info = {
2235 { "a_zip_file.zip",
2236 DOWNLOAD_NAVIGATE,
2237 DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
2238 1
2239 },
2240 content::FILE_OPERATION_INITIALIZE,
2241 0,
2242 net::ERR_FILE_PATH_TOO_LONG
2243 };
2244
2245 DownloadInsertFileErrorCheckErrors(error_info);
2246 }
2247
2248 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNameTooLongOpenDirect) {
2249 FileErrorInjectInfo error_info = {
2250 { "a_zip_file.zip",
2251 DOWNLOAD_DIRECT,
2252 DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
2253 1
2254 },
2255 content::FILE_OPERATION_INITIALIZE,
2256 0,
2257 net::ERR_FILE_PATH_TOO_LONG
2258 };
2259
2260 DownloadInsertFileErrorCheckErrors(error_info);
2261 }
2262
2263 IN_PROC_BROWSER_TEST_F(DownloadTest,
2264 DownloadErrorFileInvalidHandleWriteNavigate) {
2265 FileErrorInjectInfo error_info = {
2266 { "a_zip_file.zip",
2267 DOWNLOAD_NAVIGATE,
2268 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2269 1
2270 },
2271 content::FILE_OPERATION_WRITE,
2272 0,
2273 net::ERR_INVALID_HANDLE
2274 };
2275
2276 DownloadInsertFileErrorCheckErrors(error_info);
2277 }
2278
2279 IN_PROC_BROWSER_TEST_F(DownloadTest,
2280 DownloadErrorFileInvalidHandleWriteDirect) {
2281 FileErrorInjectInfo error_info = {
2282 { "a_zip_file.zip",
2283 DOWNLOAD_DIRECT,
2284 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2285 1
2286 },
2287 content::FILE_OPERATION_WRITE,
2288 0,
2289 net::ERR_INVALID_HANDLE
2290 };
2291
2292 DownloadInsertFileErrorCheckErrors(error_info);
2293 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/download_file_manager.h » ('j') | content/test/test_file_error_injector.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698