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

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: Created DownloadId default constructor. Cleaned up 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 <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/render_view_host.h" 52 #include "content/browser/renderer_host/render_view_host.h"
51 #include "content/browser/renderer_host/resource_dispatcher_host.h" 53 #include "content/browser/renderer_host/resource_dispatcher_host.h"
52 #include "content/public/browser/download_item.h" 54 #include "content/public/browser/download_item.h"
53 #include "content/public/browser/download_manager.h" 55 #include "content/public/browser/download_manager.h"
54 #include "content/public/browser/notification_source.h" 56 #include "content/public/browser/notification_source.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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 return false; 681 return false;
674 682
675 // Check the contents. 683 // Check the contents.
676 EXPECT_EQ(value, file_contents); 684 EXPECT_EQ(value, file_contents);
677 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0) 685 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0)
678 return false; 686 return false;
679 687
680 return true; 688 return true;
681 } 689 }
682 690
683 // Attempts to download a file, based on information in |download_info|. 691 void DownloadFilesCheckErrorsSetup() {
684 void DownloadFileCheckErrors(const DownloadInfo& download_info) {
685 ASSERT_TRUE(test_server()->Start()); 692 ASSERT_TRUE(test_server()->Start());
686 std::vector<DownloadItem*> download_items; 693 std::vector<DownloadItem*> download_items;
687 GetDownloads(browser(), &download_items); 694 GetDownloads(browser(), &download_items);
688 ASSERT_TRUE(download_items.empty()); 695 ASSERT_TRUE(download_items.empty());
689 696
697 NullSelectFile(browser());
698 }
699
700 void DownloadFilesCheckErrorsLoop(const DownloadInfo& download_info,
701 size_t i) {
702 std::stringstream s;
703 s << " " << __FUNCTION__ << "()"
704 << " index = " << i
705 << " url = '" << download_info.url_name << "'"
706 << " method = "
707 << ((download_info.download_method == DOWNLOAD_DIRECT) ?
708 "DOWNLOAD_DIRECT" : "DOWNLOAD_NAVIGATE")
709 << " show_item = " << download_info.show_download_item
710 << " reason = "
711 << InterruptReasonDebugString(download_info.reason);
712
713 std::vector<DownloadItem*> download_items;
714 GetDownloads(browser(), &download_items);
715 size_t downloads_expected = download_items.size();
716
690 std::string server_path = "files/downloads/"; 717 std::string server_path = "files/downloads/";
691 server_path += download_info.url_name; 718 server_path += download_info.url_name;
692 GURL url = test_server()->GetURL(server_path); 719 GURL url = test_server()->GetURL(server_path);
693 ASSERT_TRUE(url.is_valid()); 720 ASSERT_TRUE(url.is_valid()) << s.str();
694 721
695 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); 722 DownloadManager* download_manager = DownloadManagerForBrowser(browser());
723 WebContents* web_contents = browser()->GetSelectedWebContents();
724 ASSERT_TRUE(web_contents) << s.str();
725
726 size_t direct_downloads_expected = 0;
696 scoped_ptr<DownloadTestObserver> observer( 727 scoped_ptr<DownloadTestObserver> observer(
697 new DownloadTestObserver( 728 new DownloadTestObserver(
698 download_manager, 729 download_manager,
699 1, 730 1,
700 download_info.reason == DOWNLOAD_INTERRUPT_REASON_NONE ? 731 download_info.reason == DOWNLOAD_INTERRUPT_REASON_NONE ?
701 DownloadItem::COMPLETE : // Really done 732 DownloadItem::COMPLETE : // Really done.
702 DownloadItem::INTERRUPTED, 733 DownloadItem::INTERRUPTED, // Error detected.
703 true, // Bail on select file 734 false, // Don't bail on select file.
704 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 735 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
705 736
706 if (download_info.download_method == DOWNLOAD_DIRECT) { 737 if (download_info.download_method == DOWNLOAD_DIRECT) {
707 // Go directly to download. 738 // 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; 739 DownloadSaveInfo save_info;
740 // NOTE: |prompt_for_save_location| may change during the download.
711 save_info.prompt_for_save_location = false; 741 save_info.prompt_for_save_location = false;
712 742
743 scoped_refptr<DownloadTestItemCreationObserver> creation_observer(
744 new DownloadTestItemCreationObserver(1));
745
713 DownloadManagerForBrowser(browser())->DownloadUrl( 746 DownloadManagerForBrowser(browser())->DownloadUrl(
714 url, GURL(""), "", false, -1, save_info, web_contents); 747 url, GURL(""), "", false, -1, save_info, web_contents,
748 creation_observer->callback());
749
750 // Wait until the item is created, or we have determined that it
751 // won't be.
752 creation_observer->WaitForDownloadItemCreation();
753
754 direct_downloads_expected = download_info.show_download_item ? 1 : 0;
755 EXPECT_EQ(direct_downloads_expected, creation_observer->num_created());
715 } else { 756 } else {
716 // Navigate to URL normally, wait until done. 757 // Navigate to URL normally, wait until done.
717 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), 758 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
718 url, 759 url,
719 1); 760 1);
720 } 761 }
721 762
722 if (download_info.show_download_item) 763 if (download_info.show_download_item) {
764 downloads_expected++;
723 observer->WaitForFinished(); 765 observer->WaitForFinished();
766 }
724 767
725 // Validate that the correct file was downloaded. 768 // Wait till the download files are destroyed.
769 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
770 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::UI);
771
772 // Validate that the correct files were downloaded.
726 download_items.clear(); 773 download_items.clear();
727 GetDownloads(browser(), &download_items); 774 GetDownloads(browser(), &download_items);
728 size_t item_count = download_info.show_download_item ? 1 : 0; 775 ASSERT_EQ(downloads_expected, download_items.size()) << s.str();
729 ASSERT_EQ(item_count, download_items.size());
730 776
731 if (download_info.show_download_item) { 777 if (download_info.show_download_item) {
778 // Find the last download item.
732 DownloadItem* item = download_items[0]; 779 DownloadItem* item = download_items[0];
733 ASSERT_EQ(url, item->GetOriginalUrl()); 780 for (size_t d = 1; d < downloads_expected; ++d) {
781 if (download_items[d]->GetStartTime() > item->GetStartTime())
782 item = download_items[d];
783 }
734 784
735 ASSERT_EQ(download_info.reason, item->GetLastReason()); 785 ASSERT_EQ(url, item->GetOriginalUrl()) << s.str();
786
787 ASSERT_EQ(download_info.reason, item->GetLastReason()) << s.str();
736 } 788 }
737 } 789 }
738 790
791 // Attempts to download a set of files, based on information in the
792 // |download_info| array. |count| is the number of files.
793 // If a Select File dialog appears, it will choose the default and return
794 // immediately.
795 void DownloadFilesCheckErrors(size_t count, DownloadInfo* download_info) {
796 DownloadFilesCheckErrorsSetup();
797
798 for (size_t i = 0; i < count; ++i) {
799 DownloadFilesCheckErrorsLoop(download_info[i], i);
800 }
801 }
802
803 void DownloadInsertFilesErrorCheckErrorsLoop(
804 scoped_refptr<content::TestFileErrorInjector> injector,
805 const FileErrorInjectInfo& info,
806 size_t i) {
807 std::stringstream s;
808 s << " " << __FUNCTION__ << "()"
809 << " index = " << i
810 << " url = " << info.error_info.url
811 << " operation code = " <<
812 content::TestFileErrorInjector::DebugString(
813 info.error_info.code)
814 << " instance = " << info.error_info.operation_instance
815 << " error = " << net::ErrorToString(
816 info.error_info.net_error);
817
818 injector->ClearErrors();
819 injector->AddError(info.error_info);
820
821 injector->InjectErrors();
822
823 DownloadFilesCheckErrorsLoop(info.download_info, i);
824
825 size_t expected_successes = info.download_info.show_download_item ? 1u : 0u;
826 EXPECT_EQ(expected_successes, injector->TotalFileCount()) << s.str();
827 EXPECT_EQ(0u, injector->CurrentFileCount()) << s.str();
828
829 if (info.download_info.show_download_item)
830 EXPECT_TRUE(injector->HadFile(GURL(info.error_info.url))) << s.str();
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 for (size_t i = 0; i < count; ++i) {
842 // Set up the full URL, for download file tracking.
843 std::string server_path = "files/downloads/";
844 server_path += info[i].download_info.url_name;
845 GURL url = test_server()->GetURL(server_path);
846 info[i].error_info.url = url.spec();
847
848 DownloadInsertFilesErrorCheckErrorsLoop(injector, info[i], i);
849 }
850 }
851
739 private: 852 private:
740 // Location of the test data. 853 // Location of the test data.
741 FilePath test_dir_; 854 FilePath test_dir_;
742 855
743 // Location of the downloads directory for these tests 856 // Location of the downloads directory for these tests
744 ScopedTempDir downloads_directory_; 857 ScopedTempDir downloads_directory_;
745 }; 858 };
746 859
747 // NOTES: 860 // NOTES:
748 // 861 //
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
1826 1939
1827 DownloadTestObserver* observer( 1940 DownloadTestObserver* observer(
1828 new DownloadTestObserver( 1941 new DownloadTestObserver(
1829 DownloadManagerForBrowser(browser()), 1, 1942 DownloadManagerForBrowser(browser()), 1,
1830 DownloadItem::COMPLETE, // Really done 1943 DownloadItem::COMPLETE, // Really done
1831 false, // Ignore select file. 1944 false, // Ignore select file.
1832 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1945 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1833 DownloadSaveInfo save_info; 1946 DownloadSaveInfo save_info;
1834 save_info.prompt_for_save_location = true; 1947 save_info.prompt_for_save_location = true;
1835 DownloadManagerForBrowser(browser())->DownloadUrl( 1948 DownloadManagerForBrowser(browser())->DownloadUrl(
1836 url, GURL(""), "", false, -1, save_info, web_contents); 1949 url, GURL(""), "", false, -1, save_info, web_contents,
1950 DownloadManager::OnStartedCallback());
1837 observer->WaitForFinished(); 1951 observer->WaitForFinished();
1838 EXPECT_TRUE(observer->select_file_dialog_seen()); 1952 EXPECT_TRUE(observer->select_file_dialog_seen());
1839 1953
1840 // Check state. 1954 // Check state.
1841 EXPECT_EQ(1, browser()->tab_count()); 1955 EXPECT_EQ(1, browser()->tab_count());
1842 ASSERT_TRUE(CheckDownload(browser(), file, file)); 1956 ASSERT_TRUE(CheckDownload(browser(), file, file));
1843 CheckDownloadUI(browser(), true, true, file); 1957 CheckDownloadUI(browser(), true, true, file);
1844 } 1958 }
1845 1959
1846 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { 1960 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
1847 ASSERT_TRUE(InitialSetup(false)); 1961 ASSERT_TRUE(InitialSetup(false));
1848 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1962 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1849 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1963 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1850 1964
1851 WebContents* web_contents = browser()->GetSelectedWebContents(); 1965 WebContents* web_contents = browser()->GetSelectedWebContents();
1852 ASSERT_TRUE(web_contents); 1966 ASSERT_TRUE(web_contents);
1853 1967
1854 ScopedTempDir other_directory; 1968 ScopedTempDir other_directory;
1855 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 1969 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
1856 FilePath target_file_full_path 1970 FilePath target_file_full_path
1857 = other_directory.path().Append(file.BaseName()); 1971 = other_directory.path().Append(file.BaseName());
1858 DownloadSaveInfo save_info; 1972 DownloadSaveInfo save_info;
1859 save_info.file_path = target_file_full_path; 1973 save_info.file_path = target_file_full_path;
1860 1974
1861 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 1975 DownloadTestObserver* observer(CreateWaiter(browser(), 1));
1862 DownloadManagerForBrowser(browser())->DownloadUrl( 1976 DownloadManagerForBrowser(browser())->DownloadUrl(
1863 url, GURL(""), "", false, -1, save_info, web_contents); 1977 url, GURL(""), "", false, -1, save_info, web_contents,
1978 DownloadManager::OnStartedCallback());
1864 observer->WaitForFinished(); 1979 observer->WaitForFinished();
1865 1980
1866 // Check state. 1981 // Check state.
1867 EXPECT_EQ(1, browser()->tab_count()); 1982 EXPECT_EQ(1, browser()->tab_count());
1868 ASSERT_TRUE(CheckDownloadFullPaths(browser(), 1983 ASSERT_TRUE(CheckDownloadFullPaths(browser(),
1869 target_file_full_path, 1984 target_file_full_path,
1870 OriginFile(file))); 1985 OriginFile(file)));
1871 1986
1872 // Temporary downloads won't be visible. 1987 // Temporary downloads won't be visible.
1873 CheckDownloadUI(browser(), false, false, file); 1988 CheckDownloadUI(browser(), false, false, file);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 2112
1998 // Validate that the correct file was downloaded via the context menu. 2113 // Validate that the correct file was downloaded via the context menu.
1999 download_items.clear(); 2114 download_items.clear();
2000 GetDownloads(browser(), &download_items); 2115 GetDownloads(browser(), &download_items);
2001 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); 2116 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen());
2002 ASSERT_EQ(2u, download_items.size()); 2117 ASSERT_EQ(2u, download_items.size());
2003 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); 2118 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl());
2004 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); 2119 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl());
2005 } 2120 }
2006 2121
2007 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadNavigate) { 2122 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsServer) {
2008 DownloadInfo download_info = { 2123 DownloadInfo download_info[] = {
2009 "a_zip_file.zip", 2124 { // Normal navigated download.
2010 DOWNLOAD_NAVIGATE, 2125 "a_zip_file.zip",
2011 DOWNLOAD_INTERRUPT_REASON_NONE, 2126 DOWNLOAD_NAVIGATE,
2012 true 2127 DOWNLOAD_INTERRUPT_REASON_NONE,
2128 true
2129 },
2130 { // Normal direct download.
2131 "a_zip_file.zip",
2132 DOWNLOAD_DIRECT,
2133 DOWNLOAD_INTERRUPT_REASON_NONE,
2134 true
2135 },
2136 { // Direct download with 404 error.
2137 "there_IS_no_spoon.zip",
2138 DOWNLOAD_DIRECT,
2139 DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2140 true
2141 },
2142 { // Navigated download with 404 error.
2143 "there_IS_no_spoon.zip",
2144 DOWNLOAD_NAVIGATE,
2145 DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2146 false
2147 },
2148 { // Direct download with 400 error.
2149 "zip_file_not_found.zip",
2150 DOWNLOAD_DIRECT,
2151 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2152 true
2153 },
2154 { // Navigated download with 400 error.
2155 "zip_file_not_found.zip",
2156 DOWNLOAD_NAVIGATE,
2157 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2158 false
2159 }
2013 }; 2160 };
2014 2161
2015 // Do initial setup. 2162 // Do initial setup.
2016 ASSERT_TRUE(InitialSetup(false)); 2163 ASSERT_TRUE(InitialSetup(false));
2017 DownloadFileCheckErrors(download_info); 2164
2165 DownloadFilesCheckErrors(ARRAYSIZE_UNSAFE(download_info), download_info);
2018 } 2166 }
2019 2167
2020 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDirect) { 2168 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsFile) {
2021 DownloadInfo download_info = { 2169 FileErrorInjectInfo error_info[] = {
2022 "a_zip_file.zip", 2170 { // Navigated download with injected "Disk full" error in Initialize().
2023 DOWNLOAD_DIRECT, 2171 { "a_zip_file.zip",
2024 DOWNLOAD_INTERRUPT_REASON_NONE, 2172 DOWNLOAD_NAVIGATE,
2025 true 2173 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2174 1
2175 },
2176 {
2177 "",
2178 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2179 0,
2180 net::ERR_FILE_NO_SPACE
2181 }
2182 },
2183 { // Direct download with injected "Disk full" error in Initialize().
2184 { "a_zip_file.zip",
2185 DOWNLOAD_DIRECT,
2186 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2187 1
2188 },
2189 {
2190 "",
2191 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2192 0,
2193 net::ERR_FILE_NO_SPACE
2194 }
2195 },
2196 { // Navigated download with injected "Disk full" error in Write().
2197 { "a_zip_file.zip",
2198 DOWNLOAD_NAVIGATE,
2199 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2200 1
2201 },
2202 {
2203 "",
2204 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2205 0,
2206 net::ERR_FILE_NO_SPACE
2207 }
2208 },
2209 { // Direct download with injected "Disk full" error in Write().
2210 { "a_zip_file.zip",
2211 DOWNLOAD_DIRECT,
2212 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2213 1
2214 },
2215 {
2216 "",
2217 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2218 0,
2219 net::ERR_FILE_NO_SPACE
2220 }
2221 },
2222 { // Navigated download with injected "Failed" error in Initialize().
2223 { "a_zip_file.zip",
2224 DOWNLOAD_NAVIGATE,
2225 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2226 1
2227 },
2228 {
2229 "",
2230 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2231 0,
2232 net::ERR_FAILED
2233 }
2234 },
2235 { // Direct download with injected "Failed" error in Initialize().
2236 { "a_zip_file.zip",
2237 DOWNLOAD_DIRECT,
2238 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2239 1
2240 },
2241 {
2242 "",
2243 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2244 0,
2245 net::ERR_FAILED
2246 }
2247 },
2248 { // Navigated download with injected "Failed" error in Write().
2249 { "a_zip_file.zip",
2250 DOWNLOAD_NAVIGATE,
2251 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2252 1
2253 },
2254 {
2255 "",
2256 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2257 0,
2258 net::ERR_FAILED
2259 }
2260 },
2261 { // Direct download with injected "Failed" error in Write().
2262 { "a_zip_file.zip",
2263 DOWNLOAD_DIRECT,
2264 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2265 1
2266 },
2267 {
2268 "",
2269 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2270 0,
2271 net::ERR_FAILED
2272 }
2273 },
2274 { // Navigated download with injected "Name too long" error in
2275 // Initialize().
2276 { "a_zip_file.zip",
2277 DOWNLOAD_NAVIGATE,
2278 DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
2279 1
2280 },
2281 {
2282 "",
2283 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2284 0,
2285 net::ERR_FILE_PATH_TOO_LONG
2286 }
2287 },
2288 { // Direct download with injected "Name too long" error in Initialize().
2289 { "a_zip_file.zip",
2290 DOWNLOAD_DIRECT,
2291 DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
2292 1
2293 },
2294 {
2295 "",
2296 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2297 0,
2298 net::ERR_FILE_PATH_TOO_LONG
2299 }
2300 },
2301 { // Navigated download with injected "Name too long" error in Write().
2302 { "a_zip_file.zip",
2303 DOWNLOAD_NAVIGATE,
2304 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2305 1
2306 },
2307 {
2308 "",
2309 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2310 0,
2311 net::ERR_INVALID_HANDLE
2312 }
2313 },
2314 { // Direct download with injected "Name too long" error in Write().
2315 { "a_zip_file.zip",
2316 DOWNLOAD_DIRECT,
2317 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2318 1
2319 },
2320 {
2321 "",
2322 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2323 0,
2324 net::ERR_INVALID_HANDLE
2325 }
2326 }
2026 }; 2327 };
2027 2328
2028 // Do initial setup. 2329 DownloadInsertFilesErrorCheckErrors(ARRAYSIZE_UNSAFE(error_info), error_info);
2029 ASSERT_TRUE(InitialSetup(false));
2030 DownloadFileCheckErrors(download_info);
2031 } 2330 }
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') | content/test/test_file_error_injector.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698