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

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: Merged with parent 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
« no previous file with comments | « no previous file | content/browser/download/download_file_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 return false; 679 return false;
674 680
675 // Check the contents. 681 // Check the contents.
676 EXPECT_EQ(value, file_contents); 682 EXPECT_EQ(value, file_contents);
677 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0) 683 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0)
678 return false; 684 return false;
679 685
680 return true; 686 return true;
681 } 687 }
682 688
683 // Attempts to download a file, based on information in |download_info|. 689 void DownloadFilesCheckErrorsSetup() {
684 void DownloadFileCheckErrors(const DownloadInfo& download_info) {
685 ASSERT_TRUE(test_server()->Start()); 690 ASSERT_TRUE(test_server()->Start());
686 std::vector<DownloadItem*> download_items; 691 std::vector<DownloadItem*> download_items;
687 GetDownloads(browser(), &download_items); 692 GetDownloads(browser(), &download_items);
688 ASSERT_TRUE(download_items.empty()); 693 ASSERT_TRUE(download_items.empty());
689 694
695 NullSelectFile(browser());
696 }
697
698 void DownloadFilesCheckErrorsLoop(const DownloadInfo& download_info,
699 size_t i) {
700 std::vector<DownloadItem*> download_items;
701 GetDownloads(browser(), &download_items);
702 size_t downloads_expected = download_items.size();
703
690 std::string server_path = "files/downloads/"; 704 std::string server_path = "files/downloads/";
691 server_path += download_info.url_name; 705 server_path += download_info.url_name;
692 GURL url = test_server()->GetURL(server_path); 706 GURL url = test_server()->GetURL(server_path);
693 ASSERT_TRUE(url.is_valid()); 707 ASSERT_TRUE(url.is_valid());
694 708
695 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); 709 DownloadManager* download_manager = DownloadManagerForBrowser(browser());
710 WebContents* web_contents = browser()->GetSelectedWebContents();
711 ASSERT_TRUE(web_contents);
712
713 LOG(WARNING) << " " << __FUNCTION__ << "()"
cbentzel 2012/03/01 15:44:20 Remove this LOG(WARNING)
ahendrickson 2012/03/01 20:19:31 Done.
714 << " index = " << i
715 << " url = '" << download_info.url_name << "'"
716 << " method = "
717 << ((download_info.download_method == DOWNLOAD_DIRECT) ?
718 "DOWNLOAD_DIRECT" : "DOWNLOAD_NAVIGATE")
719 << " show_item = " << download_info.show_download_item
720 << " reason = "
721 << InterruptReasonDebugString(download_info.reason);
722
723 size_t direct_downloads_expected = 0;
696 scoped_ptr<DownloadTestObserver> observer( 724 scoped_ptr<DownloadTestObserver> observer(
697 new DownloadTestObserver( 725 new DownloadTestObserver(
698 download_manager, 726 download_manager,
699 1, 727 1,
700 download_info.reason == DOWNLOAD_INTERRUPT_REASON_NONE ? 728 download_info.reason == DOWNLOAD_INTERRUPT_REASON_NONE ?
701 DownloadItem::COMPLETE : // Really done 729 DownloadItem::COMPLETE : // Really done.
702 DownloadItem::INTERRUPTED, 730 DownloadItem::INTERRUPTED, // Error detected.
703 true, // Bail on select file 731 false, // Don't bail on select file.
704 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 732 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
705 733
706 if (download_info.download_method == DOWNLOAD_DIRECT) { 734 if (download_info.download_method == DOWNLOAD_DIRECT) {
707 // Go directly to download. 735 // Go directly to download. Don't wait until it's done.
708 WebContents* web_contents = browser()->GetSelectedWebContents();
709 ASSERT_TRUE(web_contents);
710 DownloadSaveInfo save_info; 736 DownloadSaveInfo save_info;
737 // NOTE: |prompt_for_save_location| may change during the download.
711 save_info.prompt_for_save_location = false; 738 save_info.prompt_for_save_location = false;
712 739
740 scoped_refptr<DownloadTestItemCreationObserver> creation_observer(
741 new DownloadTestItemCreationObserver(1));
742
713 DownloadManagerForBrowser(browser())->DownloadUrl( 743 DownloadManagerForBrowser(browser())->DownloadUrl(
714 url, GURL(""), "", false, -1, save_info, web_contents); 744 url, GURL(""), "", false, -1, save_info, web_contents,
745 creation_observer->callback());
746
747 // Wait until the item is created, or we have determined that it
748 // won't be.
749 creation_observer->WaitForDownloadItemCreation();
750
751 direct_downloads_expected = download_info.show_download_item ? 1 : 0;
752 EXPECT_EQ(direct_downloads_expected, creation_observer->num_created());
715 } else { 753 } else {
716 // Navigate to URL normally, wait until done. 754 // Navigate to URL normally, wait until done.
cbentzel 2012/03/01 15:44:20 Does this actually wait for the download to comple
ahendrickson 2012/03/01 20:19:31 It waits until the navigation is complete.
717 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), 755 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
718 url, 756 url,
719 1); 757 1);
720 } 758 }
721 759
722 if (download_info.show_download_item) 760 if (download_info.show_download_item) {
761 downloads_expected++;
723 observer->WaitForFinished(); 762 observer->WaitForFinished();
763 }
724 764
725 // Validate that the correct file was downloaded. 765 // Wait till the download files are destroyed.
766 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
767 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::UI);
768
769 // Validate that the correct files were downloaded.
726 download_items.clear(); 770 download_items.clear();
727 GetDownloads(browser(), &download_items); 771 GetDownloads(browser(), &download_items);
728 size_t item_count = download_info.show_download_item ? 1 : 0; 772 ASSERT_EQ(downloads_expected, download_items.size());
729 ASSERT_EQ(item_count, download_items.size());
730 773
731 if (download_info.show_download_item) { 774 if (download_info.show_download_item) {
775 // Find the last download item.
732 DownloadItem* item = download_items[0]; 776 DownloadItem* item = download_items[0];
777 for (size_t d = 1; d < downloads_expected; ++d) {
778 if (download_items[d]->GetStartTime() > item->GetStartTime())
779 item = download_items[d];
780 }
781
733 ASSERT_EQ(url, item->GetOriginalUrl()); 782 ASSERT_EQ(url, item->GetOriginalUrl());
734 783
735 ASSERT_EQ(download_info.reason, item->GetLastReason()); 784 ASSERT_EQ(download_info.reason, item->GetLastReason());
736 } 785 }
737 } 786 }
738 787
788 // Attempts to download a set of files, based on information in the
789 // |download_info| array. |count| is the number of files.
790 // If a Select File dialog appears, it will choose the default and return
791 // immediately.
792 void DownloadFilesCheckErrors(size_t count, DownloadInfo* download_info) {
793 DownloadFilesCheckErrorsSetup();
794
795 size_t i;
cbentzel 2012/03/01 15:44:20 This should be scoped in the for loop.
ahendrickson 2012/03/01 20:19:31 Done.
796
797 for (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 LOG(WARNING) << " " << __FUNCTION__ << "()"
cbentzel 2012/03/01 15:44:20 Remove this LOG(WARNING)
ahendrickson 2012/03/01 20:19:31 Done.
807 << " index = " << i
808 << " url = " << info.error_info.url
809 << " operation code = " <<
810 content::TestFileErrorInjector::DebugString(
811 info.error_info.code)
812 << " instance = " << info.error_info.operation_instance
813 << " error = " << net::ErrorToString(
814 info.error_info.net_error);
815
816 injector->ClearFoundFiles();
cbentzel 2012/03/01 15:44:20 Now that you have the per-URL map and are using it
ahendrickson 2012/03/01 20:19:31 No, because we're reusing the same URL and injecti
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());
826 EXPECT_EQ(0u, injector->CurrentFileCount());
827
828 if (info.download_info.show_download_item) {
829 EXPECT_TRUE(injector->HadFile(GURL(info.error_info.url)));
830 }
831 }
832
833 void DownloadInsertFilesErrorCheckErrors(size_t count,
834 FileErrorInjectInfo* info) {
835 DownloadFilesCheckErrorsSetup();
836
837 // Set up file failures.
838 scoped_refptr<content::TestFileErrorInjector> injector(
839 content::TestFileErrorInjector::Get());
840
841 size_t i;
842 for (i = 0; i < count; ++i) {
843 // Set up the full URL, for download file tracking.
844 std::string server_path = "files/downloads/";
845 server_path += info[i].download_info.url_name;
846 GURL url = test_server()->GetURL(server_path);
847 info[i].error_info.url = url.spec();
848
849 DownloadInsertFilesErrorCheckErrorsLoop(injector, info[i], i);
850 }
851 }
852
739 private: 853 private:
740 // Location of the test data. 854 // Location of the test data.
741 FilePath test_dir_; 855 FilePath test_dir_;
742 856
743 // Location of the downloads directory for these tests 857 // Location of the downloads directory for these tests
744 ScopedTempDir downloads_directory_; 858 ScopedTempDir downloads_directory_;
745 }; 859 };
746 860
747 // NOTES: 861 // NOTES:
748 // 862 //
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
1826 1940
1827 DownloadTestObserver* observer( 1941 DownloadTestObserver* observer(
1828 new DownloadTestObserver( 1942 new DownloadTestObserver(
1829 DownloadManagerForBrowser(browser()), 1, 1943 DownloadManagerForBrowser(browser()), 1,
1830 DownloadItem::COMPLETE, // Really done 1944 DownloadItem::COMPLETE, // Really done
1831 false, // Ignore select file. 1945 false, // Ignore select file.
1832 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1946 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1833 DownloadSaveInfo save_info; 1947 DownloadSaveInfo save_info;
1834 save_info.prompt_for_save_location = true; 1948 save_info.prompt_for_save_location = true;
1835 DownloadManagerForBrowser(browser())->DownloadUrl( 1949 DownloadManagerForBrowser(browser())->DownloadUrl(
1836 url, GURL(""), "", false, -1, save_info, web_contents); 1950 url, GURL(""), "", false, -1, save_info, web_contents,
1951 DownloadManager::OnStartedCallback());
cbentzel 2012/03/01 15:44:20 Is there support for this in the CL? Or is this fr
ahendrickson 2012/03/01 20:19:31 This is from the split.
1837 observer->WaitForFinished(); 1952 observer->WaitForFinished();
1838 EXPECT_TRUE(observer->select_file_dialog_seen()); 1953 EXPECT_TRUE(observer->select_file_dialog_seen());
1839 1954
1840 // Check state. 1955 // Check state.
1841 EXPECT_EQ(1, browser()->tab_count()); 1956 EXPECT_EQ(1, browser()->tab_count());
1842 ASSERT_TRUE(CheckDownload(browser(), file, file)); 1957 ASSERT_TRUE(CheckDownload(browser(), file, file));
1843 CheckDownloadUI(browser(), true, true, file); 1958 CheckDownloadUI(browser(), true, true, file);
1844 } 1959 }
1845 1960
1846 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { 1961 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
1847 ASSERT_TRUE(InitialSetup(false)); 1962 ASSERT_TRUE(InitialSetup(false));
1848 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1963 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1849 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1964 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1850 1965
1851 WebContents* web_contents = browser()->GetSelectedWebContents(); 1966 WebContents* web_contents = browser()->GetSelectedWebContents();
1852 ASSERT_TRUE(web_contents); 1967 ASSERT_TRUE(web_contents);
1853 1968
1854 ScopedTempDir other_directory; 1969 ScopedTempDir other_directory;
1855 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 1970 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
1856 FilePath target_file_full_path 1971 FilePath target_file_full_path
1857 = other_directory.path().Append(file.BaseName()); 1972 = other_directory.path().Append(file.BaseName());
1858 DownloadSaveInfo save_info; 1973 DownloadSaveInfo save_info;
1859 save_info.file_path = target_file_full_path; 1974 save_info.file_path = target_file_full_path;
1860 1975
1861 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 1976 DownloadTestObserver* observer(CreateWaiter(browser(), 1));
1862 DownloadManagerForBrowser(browser())->DownloadUrl( 1977 DownloadManagerForBrowser(browser())->DownloadUrl(
1863 url, GURL(""), "", false, -1, save_info, web_contents); 1978 url, GURL(""), "", false, -1, save_info, web_contents,
1979 DownloadManager::OnStartedCallback());
1864 observer->WaitForFinished(); 1980 observer->WaitForFinished();
1865 1981
1866 // Check state. 1982 // Check state.
1867 EXPECT_EQ(1, browser()->tab_count()); 1983 EXPECT_EQ(1, browser()->tab_count());
1868 ASSERT_TRUE(CheckDownloadFullPaths(browser(), 1984 ASSERT_TRUE(CheckDownloadFullPaths(browser(),
1869 target_file_full_path, 1985 target_file_full_path,
1870 OriginFile(file))); 1986 OriginFile(file)));
1871 1987
1872 // Temporary downloads won't be visible. 1988 // Temporary downloads won't be visible.
1873 CheckDownloadUI(browser(), false, false, file); 1989 CheckDownloadUI(browser(), false, false, file);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 2113
1998 // Validate that the correct file was downloaded via the context menu. 2114 // Validate that the correct file was downloaded via the context menu.
1999 download_items.clear(); 2115 download_items.clear();
2000 GetDownloads(browser(), &download_items); 2116 GetDownloads(browser(), &download_items);
2001 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); 2117 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen());
2002 ASSERT_EQ(2u, download_items.size()); 2118 ASSERT_EQ(2u, download_items.size());
2003 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); 2119 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl());
2004 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); 2120 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl());
2005 } 2121 }
2006 2122
2007 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadNavigate) { 2123 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsServer) {
2008 DownloadInfo download_info = { 2124 DownloadInfo download_info[] = {
2009 "a_zip_file.zip", 2125 { // Normal navigated download.
2010 DOWNLOAD_NAVIGATE, 2126 "a_zip_file.zip",
2011 DOWNLOAD_INTERRUPT_REASON_NONE, 2127 DOWNLOAD_NAVIGATE,
2012 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 }
2013 }; 2161 };
2014 2162
2015 // Do initial setup. 2163 // Do initial setup.
2016 ASSERT_TRUE(InitialSetup(false)); 2164 ASSERT_TRUE(InitialSetup(false));
2017 DownloadFileCheckErrors(download_info); 2165
2166 DownloadFilesCheckErrors(ARRAYSIZE_UNSAFE(download_info), download_info);
2018 } 2167 }
2019 2168
2020 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDirect) { 2169 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsFile) {
2021 DownloadInfo download_info = { 2170 FileErrorInjectInfo error_info[] = {
2022 "a_zip_file.zip", 2171 { // Navigated download with injected "Disk full" error in Initialize().
2023 DOWNLOAD_DIRECT, 2172 { "a_zip_file.zip",
2024 DOWNLOAD_INTERRUPT_REASON_NONE, 2173 DOWNLOAD_NAVIGATE,
2025 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 }
2026 }; 2328 };
2027 2329
2028 // Do initial setup. 2330 DownloadInsertFilesErrorCheckErrors(ARRAYSIZE_UNSAFE(error_info), error_info);
2029 ASSERT_TRUE(InitialSetup(false));
2030 DownloadFileCheckErrors(download_info);
2031 } 2331 }
2032
2033 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError404Direct) {
2034 DownloadInfo download_info = {
2035 "there_IS_no_spoon.zip",
2036 DOWNLOAD_DIRECT,
2037 DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2038 true
2039 };
2040
2041 // Do initial setup.
2042 ASSERT_TRUE(InitialSetup(false));
2043 DownloadFileCheckErrors(download_info);
2044 }
2045
2046 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError404Navigate) {
2047 DownloadInfo download_info = {
2048 "there_IS_no_spoon.zip",
2049 DOWNLOAD_NAVIGATE,
2050 DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2051 false
2052 };
2053
2054 // Do initial setup.
2055 ASSERT_TRUE(InitialSetup(false));
2056 DownloadFileCheckErrors(download_info);
2057 }
2058
2059 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError400Direct) {
2060 DownloadInfo download_info = {
2061 "zip_file_not_found.zip",
2062 DOWNLOAD_DIRECT,
2063 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2064 true
2065 };
2066
2067 // Do initial setup.
2068 ASSERT_TRUE(InitialSetup(false));
2069 DownloadFileCheckErrors(download_info);
2070 }
2071
2072 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError400Navigate) {
2073 DownloadInfo download_info = {
2074 "zip_file_not_found.zip",
2075 DOWNLOAD_NAVIGATE,
2076 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2077 false
2078 };
2079
2080 // Do initial setup.
2081 ASSERT_TRUE(InitialSetup(false));
2082 DownloadFileCheckErrors(download_info);
2083 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/download_file_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698