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

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 & Randy's 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 <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
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/resource_dispatcher_host.h" 52 #include "content/browser/renderer_host/resource_dispatcher_host.h"
51 #include "content/public/browser/download_item.h" 53 #include "content/public/browser/download_item.h"
52 #include "content/public/browser/download_manager.h" 54 #include "content/public/browser/download_manager.h"
53 #include "content/public/browser/notification_source.h" 55 #include "content/public/browser/notification_source.h"
54 #include "content/public/browser/render_view_host.h" 56 #include "content/public/browser/render_view_host.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
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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 return false; 677 return false;
670 678
671 // Check the contents. 679 // Check the contents.
672 EXPECT_EQ(value, file_contents); 680 EXPECT_EQ(value, file_contents);
673 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0) 681 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0)
674 return false; 682 return false;
675 683
676 return true; 684 return true;
677 } 685 }
678 686
679 // Attempts to download a file, based on information in |download_info|. 687 void DownloadFilesCheckErrorsSetup() {
680 void DownloadFileCheckErrors(const DownloadInfo& download_info) {
681 ASSERT_TRUE(test_server()->Start()); 688 ASSERT_TRUE(test_server()->Start());
682 std::vector<DownloadItem*> download_items; 689 std::vector<DownloadItem*> download_items;
683 GetDownloads(browser(), &download_items); 690 GetDownloads(browser(), &download_items);
684 ASSERT_TRUE(download_items.empty()); 691 ASSERT_TRUE(download_items.empty());
685 692
686 NullSelectFile(browser()); 693 NullSelectFile(browser());
694 }
695
696 void DownloadFilesCheckErrorsLoop(const DownloadInfo& download_info,
Randy Smith (Not in Mondays) 2012/03/07 22:19:30 "Loop" implies that there's going to be a loop in
ahendrickson 2012/03/12 11:51:02 Done.
697 size_t i) {
698 std::stringstream s;
699 s << " " << __FUNCTION__ << "()"
700 << " index = " << i
701 << " url = '" << download_info.url_name << "'"
702 << " method = "
703 << ((download_info.download_method == DOWNLOAD_DIRECT) ?
704 "DOWNLOAD_DIRECT" : "DOWNLOAD_NAVIGATE")
705 << " show_item = " << download_info.show_download_item
706 << " reason = "
707 << InterruptReasonDebugString(download_info.reason);
708
709 std::vector<DownloadItem*> download_items;
710 GetDownloads(browser(), &download_items);
711 size_t downloads_expected = download_items.size();
687 712
688 std::string server_path = "files/downloads/"; 713 std::string server_path = "files/downloads/";
689 server_path += download_info.url_name; 714 server_path += download_info.url_name;
690 GURL url = test_server()->GetURL(server_path); 715 GURL url = test_server()->GetURL(server_path);
691 ASSERT_TRUE(url.is_valid()); 716 ASSERT_TRUE(url.is_valid()) << s.str();
692 717
693 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); 718 DownloadManager* download_manager = DownloadManagerForBrowser(browser());
719 WebContents* web_contents = browser()->GetSelectedWebContents();
720 ASSERT_TRUE(web_contents) << s.str();
721
694 scoped_ptr<DownloadTestObserverTerminal> observer( 722 scoped_ptr<DownloadTestObserverTerminal> observer(
695 new DownloadTestObserverTerminal( 723 new DownloadTestObserverTerminal(
696 download_manager, 724 download_manager,
697 1, 725 1,
698 false, // Don't bail on select file. 726 false, // Don't bail on select file.
699 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_FAIL)); 727 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_FAIL));
700 728
701 if (download_info.download_method == DOWNLOAD_DIRECT) { 729 if (download_info.download_method == DOWNLOAD_DIRECT) {
702 // Go directly to download. 730 // Go directly to download. Don't wait until it's done.
Randy Smith (Not in Mondays) 2012/03/07 22:19:30 I don't understand what "Don't wait until it's don
ahendrickson 2012/03/12 11:51:02 Clarified comment.
703 WebContents* web_contents = browser()->GetSelectedWebContents();
704 ASSERT_TRUE(web_contents);
705 DownloadSaveInfo save_info; 731 DownloadSaveInfo save_info;
732 // NOTE: |prompt_for_save_location| may change during the download.
706 save_info.prompt_for_save_location = false; 733 save_info.prompt_for_save_location = false;
707 734
708 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( 735 scoped_refptr<DownloadTestItemCreationObserver> creation_observer(
709 new DownloadTestItemCreationObserver); 736 new DownloadTestItemCreationObserver);
710 737
711 DownloadManagerForBrowser(browser())->DownloadUrl( 738 DownloadManagerForBrowser(browser())->DownloadUrl(
712 url, GURL(""), "", false, -1, save_info, web_contents, 739 url, GURL(""), "", false, -1, save_info, web_contents,
713 creation_observer->callback()); 740 creation_observer->callback());
714 741
715 // Wait until the item is created, or we have determined that it 742 // Wait until the item is created, or we have determined that it
716 // won't be. 743 // won't be.
717 creation_observer->WaitForDownloadItemCreation(); 744 creation_observer->WaitForDownloadItemCreation();
718 745
719 int32 invalid_id = content::DownloadId::Invalid().local(); 746 int32 invalid_id = content::DownloadId::Invalid().local();
720 EXPECT_EQ(download_info.show_download_item, creation_observer->started()); 747 EXPECT_EQ(download_info.show_download_item, creation_observer->started());
721 if (download_info.show_download_item) { 748 if (download_info.show_download_item) {
722 EXPECT_EQ(net::OK, creation_observer->error()); 749 EXPECT_EQ(net::OK, creation_observer->error());
723 EXPECT_NE(invalid_id, creation_observer->download_id().local()); 750 EXPECT_NE(invalid_id, creation_observer->download_id().local());
724 } else { 751 } else {
725 EXPECT_NE(net::OK, creation_observer->error()); 752 EXPECT_NE(net::OK, creation_observer->error());
726 EXPECT_EQ(invalid_id, creation_observer->download_id().local()); 753 EXPECT_EQ(invalid_id, creation_observer->download_id().local());
727 } 754 }
728 } else { 755 } else {
729 // Navigate to URL normally, wait until done. 756 // Navigate to URL normally, wait until done.
730 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), 757 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
731 url, 758 url,
732 1); 759 1);
733 } 760 }
734 761
735 if (download_info.show_download_item) 762 if (download_info.show_download_item) {
763 downloads_expected++;
736 observer->WaitForFinished(); 764 observer->WaitForFinished();
765 }
737 766
738 // Validate that the correct file was downloaded. 767 // Wait till the download files are destroyed.
Randy Smith (Not in Mondays) 2012/03/07 22:19:30 Isn't this misleading? The files won't be destroy
ahendrickson 2012/03/12 11:51:02 Clarified that I'm referring to DownloadFiles.
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.
739 download_items.clear(); 772 download_items.clear();
740 GetDownloads(browser(), &download_items); 773 GetDownloads(browser(), &download_items);
741 size_t item_count = download_info.show_download_item ? 1 : 0; 774 ASSERT_EQ(downloads_expected, download_items.size()) << s.str();
742 ASSERT_EQ(item_count, download_items.size());
743 775
744 if (download_info.show_download_item) { 776 if (download_info.show_download_item) {
777 // Find the last download item.
745 DownloadItem* item = download_items[0]; 778 DownloadItem* item = download_items[0];
746 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 }
747 783
748 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();
749 } 787 }
750 } 788 }
751 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
752 private: 851 private:
753 // Location of the test data. 852 // Location of the test data.
754 FilePath test_dir_; 853 FilePath test_dir_;
755 854
756 // Location of the downloads directory for these tests 855 // Location of the downloads directory for these tests
757 ScopedTempDir downloads_directory_; 856 ScopedTempDir downloads_directory_;
758 }; 857 };
759 858
760 // NOTES: 859 // NOTES:
761 // 860 //
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2014 2113
2015 // Validate that the correct file was downloaded via the context menu. 2114 // Validate that the correct file was downloaded via the context menu.
2016 download_items.clear(); 2115 download_items.clear();
2017 GetDownloads(browser(), &download_items); 2116 GetDownloads(browser(), &download_items);
2018 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); 2117 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen());
2019 ASSERT_EQ(2u, download_items.size()); 2118 ASSERT_EQ(2u, download_items.size());
2020 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); 2119 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl());
2021 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); 2120 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl());
2022 } 2121 }
2023 2122
2024 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadNavigate) { 2123 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsServer) {
2025 DownloadInfo download_info = { 2124 DownloadInfo download_info[] = {
2026 "a_zip_file.zip", 2125 { // Normal navigated download.
2027 DOWNLOAD_NAVIGATE, 2126 "a_zip_file.zip",
2028 DOWNLOAD_INTERRUPT_REASON_NONE, 2127 DOWNLOAD_NAVIGATE,
2029 true 2128 DOWNLOAD_INTERRUPT_REASON_NONE,
2129 true
2130 },
2131 { // Normal direct download.
2132 "a_zip_file.zip",
2133 DOWNLOAD_DIRECT,
2134 DOWNLOAD_INTERRUPT_REASON_NONE,
2135 true
2136 },
2137 { // Direct download with 404 error.
2138 "there_IS_no_spoon.zip",
2139 DOWNLOAD_DIRECT,
2140 DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2141 true
2142 },
2143 { // Navigated download with 404 error.
2144 "there_IS_no_spoon.zip",
2145 DOWNLOAD_NAVIGATE,
2146 DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2147 false
2148 },
2149 { // Direct download with 400 error.
2150 "zip_file_not_found.zip",
2151 DOWNLOAD_DIRECT,
2152 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2153 true
2154 },
2155 { // Navigated download with 400 error.
2156 "zip_file_not_found.zip",
2157 DOWNLOAD_NAVIGATE,
2158 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2159 false
2160 }
2030 }; 2161 };
2031 2162
2032 // Do initial setup. 2163 // Do initial setup.
2033 ASSERT_TRUE(InitialSetup(false)); 2164 ASSERT_TRUE(InitialSetup(false));
2034 DownloadFileCheckErrors(download_info); 2165
2166 DownloadFilesCheckErrors(ARRAYSIZE_UNSAFE(download_info), download_info);
2035 } 2167 }
2036 2168
2037 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDirect) { 2169 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsFile) {
2038 DownloadInfo download_info = { 2170 FileErrorInjectInfo error_info[] = {
2039 "a_zip_file.zip", 2171 { // Navigated download with injected "Disk full" error in Initialize().
2040 DOWNLOAD_DIRECT, 2172 { "a_zip_file.zip",
2041 DOWNLOAD_INTERRUPT_REASON_NONE, 2173 DOWNLOAD_NAVIGATE,
2042 true 2174 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2175 1
2176 },
2177 {
2178 "",
2179 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2180 0,
2181 net::ERR_FILE_NO_SPACE
2182 }
2183 },
2184 { // Direct download with injected "Disk full" error in Initialize().
2185 { "a_zip_file.zip",
2186 DOWNLOAD_DIRECT,
2187 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2188 1
2189 },
2190 {
2191 "",
2192 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2193 0,
2194 net::ERR_FILE_NO_SPACE
2195 }
2196 },
2197 { // Navigated download with injected "Disk full" error in Write().
2198 { "a_zip_file.zip",
2199 DOWNLOAD_NAVIGATE,
2200 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2201 1
2202 },
2203 {
2204 "",
2205 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2206 0,
2207 net::ERR_FILE_NO_SPACE
2208 }
2209 },
2210 { // Direct download with injected "Disk full" error in Write().
2211 { "a_zip_file.zip",
2212 DOWNLOAD_DIRECT,
2213 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2214 1
2215 },
2216 {
2217 "",
2218 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2219 0,
2220 net::ERR_FILE_NO_SPACE
2221 }
2222 },
2223 { // Navigated download with injected "Failed" error in Initialize().
2224 { "a_zip_file.zip",
2225 DOWNLOAD_NAVIGATE,
2226 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2227 1
2228 },
2229 {
2230 "",
2231 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2232 0,
2233 net::ERR_FAILED
2234 }
2235 },
2236 { // Direct download with injected "Failed" error in Initialize().
2237 { "a_zip_file.zip",
2238 DOWNLOAD_DIRECT,
2239 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2240 1
2241 },
2242 {
2243 "",
2244 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2245 0,
2246 net::ERR_FAILED
2247 }
2248 },
2249 { // Navigated download with injected "Failed" error in Write().
2250 { "a_zip_file.zip",
2251 DOWNLOAD_NAVIGATE,
2252 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2253 1
2254 },
2255 {
2256 "",
2257 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2258 0,
2259 net::ERR_FAILED
2260 }
2261 },
2262 { // Direct download with injected "Failed" error in Write().
2263 { "a_zip_file.zip",
2264 DOWNLOAD_DIRECT,
2265 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2266 1
2267 },
2268 {
2269 "",
2270 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2271 0,
2272 net::ERR_FAILED
2273 }
2274 },
2275 { // Navigated download with injected "Name too long" error in
2276 // Initialize().
2277 { "a_zip_file.zip",
2278 DOWNLOAD_NAVIGATE,
2279 DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
2280 1
2281 },
2282 {
2283 "",
2284 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2285 0,
2286 net::ERR_FILE_PATH_TOO_LONG
2287 }
2288 },
2289 { // Direct download with injected "Name too long" error in Initialize().
2290 { "a_zip_file.zip",
2291 DOWNLOAD_DIRECT,
2292 DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
2293 1
2294 },
2295 {
2296 "",
2297 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2298 0,
2299 net::ERR_FILE_PATH_TOO_LONG
2300 }
2301 },
2302 { // Navigated download with injected "Name too long" error in Write().
2303 { "a_zip_file.zip",
2304 DOWNLOAD_NAVIGATE,
2305 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2306 1
2307 },
2308 {
2309 "",
2310 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2311 0,
2312 net::ERR_INVALID_HANDLE
2313 }
2314 },
2315 { // Direct download with injected "Name too long" error in Write().
2316 { "a_zip_file.zip",
2317 DOWNLOAD_DIRECT,
2318 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2319 1
2320 },
2321 {
2322 "",
2323 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2324 0,
2325 net::ERR_INVALID_HANDLE
2326 }
2327 },
2328 { // Direct download with injected "Disk full" error in 2nd Write().
2329 { "06bESSE21Evolution.ppt",
2330 DOWNLOAD_DIRECT,
2331 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2332 1
2333 },
2334 {
2335 "",
2336 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2337 1,
2338 net::ERR_FILE_NO_SPACE
2339 }
2340 }
2043 }; 2341 };
2044 2342
2045 // Do initial setup. 2343 DownloadInsertFilesErrorCheckErrors(ARRAYSIZE_UNSAFE(error_info), error_info);
2046 ASSERT_TRUE(InitialSetup(false));
2047 DownloadFileCheckErrors(download_info);
2048 } 2344 }
2049
2050 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError404Direct) {
2051 DownloadInfo download_info = {
2052 "there_IS_no_spoon.zip",
2053 DOWNLOAD_DIRECT,
2054 DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2055 true
2056 };
2057
2058 // Do initial setup.
2059 ASSERT_TRUE(InitialSetup(false));
2060 DownloadFileCheckErrors(download_info);
2061 }
2062
2063 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError404Navigate) {
2064 DownloadInfo download_info = {
2065 "there_IS_no_spoon.zip",
2066 DOWNLOAD_NAVIGATE,
2067 DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2068 false
2069 };
2070
2071 // Do initial setup.
2072 ASSERT_TRUE(InitialSetup(false));
2073 DownloadFileCheckErrors(download_info);
2074 }
2075
2076 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError400Direct) {
2077 DownloadInfo download_info = {
2078 "zip_file_not_found.zip",
2079 DOWNLOAD_DIRECT,
2080 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2081 true
2082 };
2083
2084 // Do initial setup.
2085 ASSERT_TRUE(InitialSetup(false));
2086 DownloadFileCheckErrors(download_info);
2087 }
2088
2089 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError400Navigate) {
2090 DownloadInfo download_info = {
2091 "zip_file_not_found.zip",
2092 DOWNLOAD_NAVIGATE,
2093 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2094 false
2095 };
2096
2097 // Do initial setup.
2098 ASSERT_TRUE(InitialSetup(false));
2099 DownloadFileCheckErrors(download_info);
2100 }
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