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

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: Refactored per Chris' comments Created 8 years, 9 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;
312 content::TestFileErrorInjector::FileErrorInfo error_info;
313 };
314
309 DownloadTest() { 315 DownloadTest() {
310 EnableDOMAutomation(); 316 EnableDOMAutomation();
311 } 317 }
312 318
313 void SetUpOnMainThread() OVERRIDE { 319 void SetUpOnMainThread() OVERRIDE {
314 BrowserThread::PostTask( 320 BrowserThread::PostTask(
315 BrowserThread::IO, FROM_HERE, 321 BrowserThread::IO, FROM_HERE,
316 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); 322 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
317 } 323 }
318 324
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 ASSERT_EQ(item_count, download_items.size()); 735 ASSERT_EQ(item_count, download_items.size());
730 736
731 if (download_info.show_download_item) { 737 if (download_info.show_download_item) {
732 DownloadItem* item = download_items[0]; 738 DownloadItem* item = download_items[0];
733 ASSERT_EQ(url, item->GetOriginalUrl()); 739 ASSERT_EQ(url, item->GetOriginalUrl());
734 740
735 ASSERT_EQ(download_info.reason, item->GetLastReason()); 741 ASSERT_EQ(download_info.reason, item->GetLastReason());
736 } 742 }
737 } 743 }
738 744
745 void DownloadInsertFileErrorCheckErrors(const FileErrorInjectInfo& info) {
746 // Do initial setup.
747 ASSERT_TRUE(InitialSetup(false));
748
749 // Set up file failures.
750 // |injector| will be owned by the DownloadFileManager (indirectly).
cbentzel 2012/02/28 14:51:41 This comment about ownership is no longer true - i
ahendrickson 2012/03/01 09:17:32 Done.
751 scoped_refptr<content::TestFileErrorInjector> injector(
752 content::TestFileErrorInjector::Create());
753 injector->AddError(info.error_info);
754 injector->InjectErrors();
755
756 DownloadFileCheckErrors(info.download_info);
757
758 ui_test_utils::RunAllPendingInMessageLoop();
cbentzel 2012/02/28 14:51:41 Are you guaranteed that all of the work on the fil
ahendrickson 2012/03/01 09:17:32 Added code to run all pending messages on the FILE
759
760 EXPECT_EQ(1u, injector->FileCreationCount());
761 EXPECT_EQ(false, injector->HasFile(0));
cbentzel 2012/02/28 14:51:41 Do you need this HasFile call? Doesn't the Current
ahendrickson 2012/03/01 09:17:32 Hmm, I guess it's not needed. Removed.
762 EXPECT_EQ(0u, injector->CurrentFileCount());
763 }
764
739 private: 765 private:
740 // Location of the test data. 766 // Location of the test data.
741 FilePath test_dir_; 767 FilePath test_dir_;
742 768
743 // Location of the downloads directory for these tests 769 // Location of the downloads directory for these tests
744 ScopedTempDir downloads_directory_; 770 ScopedTempDir downloads_directory_;
745 }; 771 };
746 772
747 // NOTES: 773 // NOTES:
748 // 774 //
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after
2074 "zip_file_not_found.zip", 2100 "zip_file_not_found.zip",
2075 DOWNLOAD_NAVIGATE, 2101 DOWNLOAD_NAVIGATE,
2076 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, 2102 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2077 false 2103 false
2078 }; 2104 };
2079 2105
2080 // Do initial setup. 2106 // Do initial setup.
2081 ASSERT_TRUE(InitialSetup(false)); 2107 ASSERT_TRUE(InitialSetup(false));
2082 DownloadFileCheckErrors(download_info); 2108 DownloadFileCheckErrors(download_info);
2083 } 2109 }
2110
2111 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceOpenNavigate) {
Randy Smith (Not in Mondays) 2012/02/28 22:06:13 There's a fair amount of overhead in starting up a
ahendrickson 2012/03/01 09:17:32 Done.
2112 FileErrorInjectInfo error_info = {
2113 { "a_zip_file.zip",
2114 DOWNLOAD_NAVIGATE,
2115 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2116 1
2117 },
2118 {
2119 0,
2120 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2121 0,
2122 net::ERR_FILE_NO_SPACE
2123 }
2124 };
2125
2126 DownloadInsertFileErrorCheckErrors(error_info);
2127 }
2128
2129 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceOpenDirect) {
2130 FileErrorInjectInfo error_info = {
2131 { "a_zip_file.zip",
2132 DOWNLOAD_DIRECT,
2133 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2134 1
2135 },
2136 {
2137 0,
2138 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2139 0,
2140 net::ERR_FILE_NO_SPACE
2141 }
2142 };
2143
2144 DownloadInsertFileErrorCheckErrors(error_info);
2145 }
2146
2147 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceWriteNavigate) {
2148 FileErrorInjectInfo error_info = {
2149 { "a_zip_file.zip",
2150 DOWNLOAD_NAVIGATE,
2151 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2152 1
2153 },
2154 {
2155 0,
2156 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2157 0,
2158 net::ERR_FILE_NO_SPACE
2159 }
2160 };
2161
2162 DownloadInsertFileErrorCheckErrors(error_info);
2163 }
2164
2165 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceWriteDirect) {
2166 FileErrorInjectInfo error_info = {
2167 { "a_zip_file.zip",
2168 DOWNLOAD_DIRECT,
2169 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2170 1
2171 },
2172 {
2173 0,
2174 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2175 0,
2176 net::ERR_FILE_NO_SPACE
2177 }
2178 };
2179
2180 DownloadInsertFileErrorCheckErrors(error_info);
2181 }
2182
2183 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedOpenNavigate) {
2184 FileErrorInjectInfo error_info = {
2185 { "a_zip_file.zip",
2186 DOWNLOAD_NAVIGATE,
2187 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2188 1
2189 },
2190 {
2191 0,
2192 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2193 0,
2194 net::ERR_FAILED
2195 }
2196 };
2197
2198 DownloadInsertFileErrorCheckErrors(error_info);
2199 }
2200
2201 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedOpenDirect) {
2202 FileErrorInjectInfo error_info = {
2203 { "a_zip_file.zip",
2204 DOWNLOAD_DIRECT,
2205 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2206 1
2207 },
2208 {
2209 0,
2210 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2211 0,
2212 net::ERR_FAILED
2213 }
2214 };
2215
2216 DownloadInsertFileErrorCheckErrors(error_info);
2217 }
2218
2219 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedWriteNavigate) {
2220 FileErrorInjectInfo error_info = {
2221 { "a_zip_file.zip",
2222 DOWNLOAD_NAVIGATE,
2223 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2224 1
2225 },
2226 {
2227 0,
2228 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2229 0,
2230 net::ERR_FAILED
2231 }
2232 };
2233
2234 DownloadInsertFileErrorCheckErrors(error_info);
2235 }
2236
2237 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedWriteDirect) {
2238 FileErrorInjectInfo error_info = {
2239 { "a_zip_file.zip",
2240 DOWNLOAD_DIRECT,
2241 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2242 1
2243 },
2244 {
2245 0,
2246 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2247 0,
2248 net::ERR_FAILED
2249 }
2250 };
2251
2252 DownloadInsertFileErrorCheckErrors(error_info);
2253 }
2254
2255 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNameTooLongOpenNavigate) {
2256 FileErrorInjectInfo error_info = {
2257 { "a_zip_file.zip",
2258 DOWNLOAD_NAVIGATE,
2259 DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
2260 1
2261 },
2262 {
2263 0,
2264 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2265 0,
2266 net::ERR_FILE_PATH_TOO_LONG
2267 }
2268 };
2269
2270 DownloadInsertFileErrorCheckErrors(error_info);
2271 }
2272
2273 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNameTooLongOpenDirect) {
2274 FileErrorInjectInfo error_info = {
2275 { "a_zip_file.zip",
2276 DOWNLOAD_DIRECT,
2277 DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
2278 1
2279 },
2280 {
2281 0,
2282 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2283 0,
2284 net::ERR_FILE_PATH_TOO_LONG
2285 }
2286 };
2287
2288 DownloadInsertFileErrorCheckErrors(error_info);
2289 }
2290
2291 IN_PROC_BROWSER_TEST_F(DownloadTest,
2292 DownloadErrorFileInvalidHandleWriteNavigate) {
2293 FileErrorInjectInfo error_info = {
2294 { "a_zip_file.zip",
2295 DOWNLOAD_NAVIGATE,
2296 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2297 1
2298 },
2299 {
2300 0,
2301 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2302 0,
2303 net::ERR_INVALID_HANDLE
2304 }
2305 };
2306
2307 DownloadInsertFileErrorCheckErrors(error_info);
2308 }
2309
2310 IN_PROC_BROWSER_TEST_F(DownloadTest,
2311 DownloadErrorFileInvalidHandleWriteDirect) {
2312 FileErrorInjectInfo error_info = {
2313 { "a_zip_file.zip",
2314 DOWNLOAD_DIRECT,
2315 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2316 1
2317 },
2318 {
2319 0,
2320 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2321 0,
2322 net::ERR_INVALID_HANDLE
2323 }
2324 };
2325
2326 DownloadInsertFileErrorCheckErrors(error_info);
2327 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/download_file_manager.h » ('j') | content/browser/download/download_file_manager.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698