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

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 trunk. 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 <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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "content/public/browser/download_manager.h" 49 #include "content/public/browser/download_manager.h"
48 #include "content/public/browser/download_persistent_store_info.h" 50 #include "content/public/browser/download_persistent_store_info.h"
49 #include "content/public/browser/download_save_info.h" 51 #include "content/public/browser/download_save_info.h"
50 #include "content/public/browser/notification_source.h" 52 #include "content/public/browser/notification_source.h"
51 #include "content/public/browser/render_view_host.h" 53 #include "content/public/browser/render_view_host.h"
52 #include "content/public/browser/web_contents.h" 54 #include "content/public/browser/web_contents.h"
53 #include "content/public/common/context_menu_params.h" 55 #include "content/public/common/context_menu_params.h"
54 #include "content/public/common/page_transition_types.h" 56 #include "content/public/common/page_transition_types.h"
55 #include "content/test/net/url_request_mock_http_job.h" 57 #include "content/test/net/url_request_mock_http_job.h"
56 #include "content/test/net/url_request_slow_download_job.h" 58 #include "content/test/net/url_request_slow_download_job.h"
59 #include "content/test/test_file_error_injector.h"
57 #include "content/test/test_navigation_observer.h" 60 #include "content/test/test_navigation_observer.h"
58 #include "net/base/net_util.h" 61 #include "net/base/net_util.h"
59 #include "testing/gtest/include/gtest/gtest.h" 62 #include "testing/gtest/include/gtest/gtest.h"
60 63
61 using content::BrowserThread; 64 using content::BrowserThread;
62 using content::DownloadItem; 65 using content::DownloadItem;
63 using content::DownloadManager; 66 using content::DownloadManager;
64 using content::DownloadPersistentStoreInfo; 67 using content::DownloadPersistentStoreInfo;
65 using content::WebContents; 68 using content::WebContents;
66 69
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // Information passed in to |DownloadFileCheckErrors()|. 249 // Information passed in to |DownloadFileCheckErrors()|.
247 struct DownloadInfo { 250 struct DownloadInfo {
248 const char* url_name; // URL for the download. 251 const char* url_name; // URL for the download.
249 DownloadMethod download_method; // Navigation or Direct. 252 DownloadMethod download_method; // Navigation or Direct.
250 // Download interrupt reason (NONE is OK). 253 // Download interrupt reason (NONE is OK).
251 content::DownloadInterruptReason reason; 254 content::DownloadInterruptReason reason;
252 bool show_download_item; // True if the download item appears on the shelf. 255 bool show_download_item; // True if the download item appears on the shelf.
253 bool should_redirect_to_documents; // True if we save it in "My Documents". 256 bool should_redirect_to_documents; // True if we save it in "My Documents".
254 }; 257 };
255 258
259 struct FileErrorInjectInfo {
260 DownloadInfo download_info;
261 content::TestFileErrorInjector::FileErrorInfo error_info;
262 };
263
256 DownloadTest() { 264 DownloadTest() {
257 EnableDOMAutomation(); 265 EnableDOMAutomation();
258 } 266 }
259 267
260 void SetUpOnMainThread() OVERRIDE { 268 void SetUpOnMainThread() OVERRIDE {
261 BrowserThread::PostTask( 269 BrowserThread::PostTask(
262 BrowserThread::IO, FROM_HERE, 270 BrowserThread::IO, FROM_HERE,
263 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); 271 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
264 } 272 }
265 273
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 // Check the contents. 644 // Check the contents.
637 EXPECT_EQ(value, file_contents); 645 EXPECT_EQ(value, file_contents);
638 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0) 646 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0)
639 return false; 647 return false;
640 648
641 return true; 649 return true;
642 } 650 }
643 651
644 // Attempts to download a file, based on information in |download_info|. 652 // Attempts to download a file, based on information in |download_info|.
645 // If a Select File dialog opens, will automatically choose the default. 653 // If a Select File dialog opens, will automatically choose the default.
646 void DownloadFileCheckErrors(const DownloadInfo& download_info) { 654 void DownloadFilesCheckErrorsSetup() {
647 ASSERT_TRUE(test_server()->Start()); 655 ASSERT_TRUE(test_server()->Start());
648 std::vector<DownloadItem*> download_items; 656 std::vector<DownloadItem*> download_items;
649 GetDownloads(browser(), &download_items); 657 GetDownloads(browser(), &download_items);
650 ASSERT_TRUE(download_items.empty()); 658 ASSERT_TRUE(download_items.empty());
651 659
652 NullSelectFile(browser()); 660 NullSelectFile(browser());
661 }
662
663 void DownloadFilesCheckErrorsLoopBody(const DownloadInfo& download_info,
664 size_t i) {
665 std::stringstream s;
666 s << " " << __FUNCTION__ << "()"
667 << " index = " << i
668 << " url = '" << download_info.url_name << "'"
669 << " method = "
670 << ((download_info.download_method == DOWNLOAD_DIRECT) ?
671 "DOWNLOAD_DIRECT" : "DOWNLOAD_NAVIGATE")
672 << " show_item = " << download_info.show_download_item
673 << " reason = "
674 << InterruptReasonDebugString(download_info.reason);
675
676 std::vector<DownloadItem*> download_items;
677 GetDownloads(browser(), &download_items);
678 size_t downloads_expected = download_items.size();
653 679
654 std::string server_path = "files/downloads/"; 680 std::string server_path = "files/downloads/";
655 server_path += download_info.url_name; 681 server_path += download_info.url_name;
656 GURL url = test_server()->GetURL(server_path); 682 GURL url = test_server()->GetURL(server_path);
657 ASSERT_TRUE(url.is_valid()); 683 ASSERT_TRUE(url.is_valid()) << s.str();
658
659 NullSelectFile(browser()); // Needed for read-only tests.
660 684
661 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); 685 DownloadManager* download_manager = DownloadManagerForBrowser(browser());
686 WebContents* web_contents = browser()->GetSelectedWebContents();
687 ASSERT_TRUE(web_contents) << s.str();
688
662 scoped_ptr<DownloadTestObserver> observer( 689 scoped_ptr<DownloadTestObserver> observer(
663 new DownloadTestObserverTerminal( 690 new DownloadTestObserverTerminal(
664 download_manager, 691 download_manager,
665 1, 692 1,
666 false, // Don't bail on select file. 693 false, // Don't bail on select file.
667 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 694 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
668 695
669 if (download_info.download_method == DOWNLOAD_DIRECT) { 696 if (download_info.download_method == DOWNLOAD_DIRECT) {
670 // Go directly to download. 697 // Go directly to download. Don't wait for navigation.
671 WebContents* web_contents = browser()->GetSelectedWebContents();
672 ASSERT_TRUE(web_contents);
673 content::DownloadSaveInfo save_info; 698 content::DownloadSaveInfo save_info;
699 // NOTE: |prompt_for_save_location| may change during the download.
674 save_info.prompt_for_save_location = false; 700 save_info.prompt_for_save_location = false;
675 701
676 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( 702 scoped_refptr<DownloadTestItemCreationObserver> creation_observer(
677 new DownloadTestItemCreationObserver); 703 new DownloadTestItemCreationObserver);
678 704
679 DownloadManagerForBrowser(browser())->DownloadUrl( 705 DownloadManagerForBrowser(browser())->DownloadUrl(
680 url, GURL(""), "", false, -1, save_info, web_contents, 706 url, GURL(""), "", false, -1, save_info, web_contents,
681 creation_observer->callback()); 707 creation_observer->callback());
682 708
683 // Wait until the item is created, or we have determined that it 709 // Wait until the item is created, or we have determined that it
(...skipping 11 matching lines...) Expand all
695 EXPECT_EQ(invalid_id, creation_observer->download_id().local()); 721 EXPECT_EQ(invalid_id, creation_observer->download_id().local());
696 } 722 }
697 } else { 723 } else {
698 // Navigate to URL normally, wait until done. 724 // Navigate to URL normally, wait until done.
699 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), 725 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
700 url, 726 url,
701 1); 727 1);
702 } 728 }
703 729
704 if (download_info.show_download_item) { 730 if (download_info.show_download_item) {
731 downloads_expected++;
705 observer->WaitForFinished(); 732 observer->WaitForFinished();
706 DownloadItem::DownloadState final_state = 733 DownloadItem::DownloadState final_state =
707 (download_info.reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) ? 734 (download_info.reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) ?
708 DownloadItem::COMPLETE : 735 DownloadItem::COMPLETE :
709 DownloadItem::INTERRUPTED; 736 DownloadItem::INTERRUPTED;
710 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(final_state)); 737 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(final_state));
711 } 738 }
712 739
713 // Validate that the correct file was downloaded. 740 // Wait till the |DownloadFile|s are destroyed.
741 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
742 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::UI);
743
744 // Validate that the correct files were downloaded.
714 download_items.clear(); 745 download_items.clear();
715 GetDownloads(browser(), &download_items); 746 GetDownloads(browser(), &download_items);
716 size_t item_count = download_info.show_download_item ? 1 : 0; 747 ASSERT_EQ(downloads_expected, download_items.size()) << s.str();
717 ASSERT_EQ(item_count, download_items.size());
718 748
719 if (download_info.show_download_item) { 749 if (download_info.show_download_item) {
750 // Find the last download item.
720 DownloadItem* item = download_items[0]; 751 DownloadItem* item = download_items[0];
721 ASSERT_EQ(url, item->GetOriginalUrl()); 752 for (size_t d = 1; d < downloads_expected; ++d) {
753 if (download_items[d]->GetStartTime() > item->GetStartTime())
754 item = download_items[d];
755 }
722 756
723 ASSERT_EQ(download_info.reason, item->GetLastReason()); 757 ASSERT_EQ(url, item->GetOriginalUrl()) << s.str();
758
759 ASSERT_EQ(download_info.reason, item->GetLastReason()) << s.str();
724 760
725 if (item->GetState() == content::DownloadItem::COMPLETE) { 761 if (item->GetState() == content::DownloadItem::COMPLETE) {
726 // Clean up the file, in case it ended up in the My Documents folder. 762 // Clean up the file, in case it ended up in the My Documents folder.
727 FilePath destination_folder = GetDownloadDirectory(browser()); 763 FilePath destination_folder = GetDownloadDirectory(browser());
728 FilePath my_downloaded_file = item->GetTargetFilePath(); 764 FilePath my_downloaded_file = item->GetTargetFilePath();
729 EXPECT_TRUE(file_util::PathExists(my_downloaded_file)); 765 EXPECT_TRUE(file_util::PathExists(my_downloaded_file));
730 EXPECT_TRUE(file_util::Delete(my_downloaded_file, false)); 766 EXPECT_TRUE(file_util::Delete(my_downloaded_file, false));
731 767
732 EXPECT_EQ(download_info.should_redirect_to_documents ? 768 EXPECT_EQ(download_info.should_redirect_to_documents ?
733 std::string::npos : 769 std::string::npos :
734 0u, 770 0u,
735 my_downloaded_file.value().find(destination_folder.value())); 771 my_downloaded_file.value().find(destination_folder.value()));
736 if (download_info.should_redirect_to_documents) { 772 if (download_info.should_redirect_to_documents) {
737 // If it's not where we asked it to be, it should be in the 773 // If it's not where we asked it to be, it should be in the
738 // My Documents folder. 774 // My Documents folder.
739 FilePath my_docs_folder; 775 FilePath my_docs_folder;
740 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DOCUMENTS, 776 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DOCUMENTS,
741 &my_docs_folder)); 777 &my_docs_folder));
742 EXPECT_EQ(0u, 778 EXPECT_EQ(0u,
743 my_downloaded_file.value().find(my_docs_folder.value())); 779 my_downloaded_file.value().find(my_docs_folder.value()));
744 } 780 }
745 } 781 }
746 } 782 }
747 } 783 }
748 784
785 // Attempts to download a set of files, based on information in the
786 // |download_info| array. |count| is the number of files.
787 // If a Select File dialog appears, it will choose the default and return
788 // immediately.
789 void DownloadFilesCheckErrors(size_t count, DownloadInfo* download_info) {
790 DownloadFilesCheckErrorsSetup();
791
792 for (size_t i = 0; i < count; ++i) {
793 DownloadFilesCheckErrorsLoopBody(download_info[i], i);
794 }
795 }
796
797 void DownloadInsertFilesErrorCheckErrorsLoopBody(
798 scoped_refptr<content::TestFileErrorInjector> injector,
799 const FileErrorInjectInfo& info,
800 size_t i) {
801 std::stringstream s;
802 s << " " << __FUNCTION__ << "()"
803 << " index = " << i
804 << " url = " << info.error_info.url
805 << " operation code = " <<
806 content::TestFileErrorInjector::DebugString(
807 info.error_info.code)
808 << " instance = " << info.error_info.operation_instance
809 << " error = " << net::ErrorToString(
810 info.error_info.net_error);
811
812 injector->ClearErrors();
813 injector->AddError(info.error_info);
814
815 injector->InjectErrors();
816
817 DownloadFilesCheckErrorsLoopBody(info.download_info, i);
818
819 size_t expected_successes = info.download_info.show_download_item ? 1u : 0u;
820 EXPECT_EQ(expected_successes, injector->TotalFileCount()) << s.str();
821 EXPECT_EQ(0u, injector->CurrentFileCount()) << s.str();
822
823 if (info.download_info.show_download_item)
824 EXPECT_TRUE(injector->HadFile(GURL(info.error_info.url))) << s.str();
825 }
826
827 void DownloadInsertFilesErrorCheckErrors(size_t count,
828 FileErrorInjectInfo* info) {
829 DownloadFilesCheckErrorsSetup();
830
831 // Set up file failures.
832 scoped_refptr<content::TestFileErrorInjector> injector(
833 content::TestFileErrorInjector::Create());
834
835 for (size_t i = 0; i < count; ++i) {
836 // Set up the full URL, for download file tracking.
837 std::string server_path = "files/downloads/";
838 server_path += info[i].download_info.url_name;
839 GURL url = test_server()->GetURL(server_path);
840 info[i].error_info.url = url.spec();
841
842 DownloadInsertFilesErrorCheckErrorsLoopBody(injector, info[i], i);
843 }
844 }
845
749 // Attempts to download a file to a read-only folder, based on information 846 // Attempts to download a file to a read-only folder, based on information
750 // in |download_info|. 847 // in |download_info|.
751 void DownloadFileToReadonlyFolder(const DownloadInfo& download_info) { 848 void DownloadFilesToReadonlyFolder(size_t count,
849 DownloadInfo* download_info) {
752 ASSERT_TRUE(InitialSetup(false)); // Creates temporary download folder. 850 ASSERT_TRUE(InitialSetup(false)); // Creates temporary download folder.
753 851
852 DownloadFilesCheckErrorsSetup();
853
754 // Make the test folder unwritable. 854 // Make the test folder unwritable.
755 FilePath destination_folder = GetDownloadDirectory(browser()); 855 FilePath destination_folder = GetDownloadDirectory(browser());
756 DVLOG(1) << " " << __FUNCTION__ << "()" 856 DVLOG(1) << " " << __FUNCTION__ << "()"
757 << " folder = '" << destination_folder.value() << "'"; 857 << " folder = '" << destination_folder.value() << "'";
758 file_util::PermissionRestorer permission_restorer(destination_folder); 858 file_util::PermissionRestorer permission_restorer(destination_folder);
759 EXPECT_TRUE(file_util::MakeFileUnwritable(destination_folder)); 859 EXPECT_TRUE(file_util::MakeFileUnwritable(destination_folder));
760 860
761 DownloadFileCheckErrors(download_info); 861 for (size_t i = 0; i < count; ++i) {
862 DownloadFilesCheckErrorsLoopBody(download_info[i], i);
863 }
762 } 864 }
763 865
764 bool EnsureNoPendingDownloads() { 866 bool EnsureNoPendingDownloads() {
765 bool result = true; 867 bool result = true;
766 BrowserThread::PostTask( 868 BrowserThread::PostTask(
767 BrowserThread::IO, FROM_HERE, 869 BrowserThread::IO, FROM_HERE,
768 base::Bind(&EnsureNoPendingDownloadJobsOnIO, &result)); 870 base::Bind(&EnsureNoPendingDownloadJobsOnIO, &result));
769 MessageLoop::current()->Run(); 871 MessageLoop::current()->Run();
770 return result && DownloadManager::EnsureNoPendingDownloadsForTesting(); 872 return result && DownloadManager::EnsureNoPendingDownloadsForTesting();
771 } 873 }
(...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 2166
2065 // Validate that the correct file was downloaded via the context menu. 2167 // Validate that the correct file was downloaded via the context menu.
2066 download_items.clear(); 2168 download_items.clear();
2067 GetDownloads(browser(), &download_items); 2169 GetDownloads(browser(), &download_items);
2068 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); 2170 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen());
2069 ASSERT_EQ(2u, download_items.size()); 2171 ASSERT_EQ(2u, download_items.size());
2070 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); 2172 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl());
2071 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); 2173 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl());
2072 } 2174 }
2073 2175
2074 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadNavigate) { 2176 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsServer) {
2075 DownloadInfo download_info = { 2177 DownloadInfo download_info[] = {
2076 "a_zip_file.zip", 2178 { // Normal navigated download.
2077 DOWNLOAD_NAVIGATE, 2179 "a_zip_file.zip",
2078 content::DOWNLOAD_INTERRUPT_REASON_NONE, 2180 DOWNLOAD_NAVIGATE,
2079 true, 2181 content::DOWNLOAD_INTERRUPT_REASON_NONE,
2080 false 2182 true,
2183 false
2184 },
2185 { // Normal direct download.
2186 "a_zip_file.zip",
2187 DOWNLOAD_DIRECT,
2188 content::DOWNLOAD_INTERRUPT_REASON_NONE,
2189 true,
2190 false
2191 },
2192 { // Direct download with 404 error.
2193 "there_IS_no_spoon.zip",
2194 DOWNLOAD_DIRECT,
2195 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2196 true,
2197 false
2198 },
2199 { // Navigated download with 404 error.
2200 "there_IS_no_spoon.zip",
2201 DOWNLOAD_NAVIGATE,
2202 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2203 false,
2204 false
2205 },
2206 { // Direct download with 400 error.
2207 "zip_file_not_found.zip",
2208 DOWNLOAD_DIRECT,
2209 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2210 true,
2211 false
2212 },
2213 { // Navigated download with 400 error.
2214 "zip_file_not_found.zip",
2215 DOWNLOAD_NAVIGATE,
2216 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2217 false,
2218 false
2219 }
2081 }; 2220 };
2082 2221
2083 // Do initial setup. 2222 // Do initial setup.
2084 ASSERT_TRUE(InitialSetup(false)); 2223 ASSERT_TRUE(InitialSetup(false));
2085 DownloadFileCheckErrors(download_info); 2224
2086 } 2225 DownloadFilesCheckErrors(ARRAYSIZE_UNSAFE(download_info), download_info);
2087 2226 }
2088 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDirect) { 2227
2089 DownloadInfo download_info = { 2228 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsFile) {
2090 "a_zip_file.zip", 2229 FileErrorInjectInfo error_info[] = {
2091 DOWNLOAD_DIRECT, 2230 { // Navigated download with injected "Disk full" error in Initialize().
2092 content::DOWNLOAD_INTERRUPT_REASON_NONE, 2231 { "a_zip_file.zip",
2093 true, 2232 DOWNLOAD_NAVIGATE,
2094 false 2233 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2234 1
2235 },
2236 {
2237 "",
2238 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2239 0,
2240 net::ERR_FILE_NO_SPACE
2241 }
2242 },
2243 { // Direct download with injected "Disk full" error in Initialize().
2244 { "a_zip_file.zip",
2245 DOWNLOAD_DIRECT,
2246 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2247 1
2248 },
2249 {
2250 "",
2251 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2252 0,
2253 net::ERR_FILE_NO_SPACE
2254 }
2255 },
2256 { // Navigated download with injected "Disk full" error in Write().
2257 { "a_zip_file.zip",
2258 DOWNLOAD_NAVIGATE,
2259 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2260 1
2261 },
2262 {
2263 "",
2264 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2265 0,
2266 net::ERR_FILE_NO_SPACE
2267 }
2268 },
2269 { // Direct download with injected "Disk full" error in Write().
2270 { "a_zip_file.zip",
2271 DOWNLOAD_DIRECT,
2272 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2273 1
2274 },
2275 {
2276 "",
2277 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2278 0,
2279 net::ERR_FILE_NO_SPACE
2280 }
2281 },
2282 { // Navigated download with injected "Failed" error in Initialize().
2283 { "a_zip_file.zip",
2284 DOWNLOAD_NAVIGATE,
2285 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2286 1
2287 },
2288 {
2289 "",
2290 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2291 0,
2292 net::ERR_FAILED
2293 }
2294 },
2295 { // Direct download with injected "Failed" error in Initialize().
2296 { "a_zip_file.zip",
2297 DOWNLOAD_DIRECT,
2298 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2299 1
2300 },
2301 {
2302 "",
2303 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2304 0,
2305 net::ERR_FAILED
2306 }
2307 },
2308 { // Navigated download with injected "Failed" error in Write().
2309 { "a_zip_file.zip",
2310 DOWNLOAD_NAVIGATE,
2311 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2312 1
2313 },
2314 {
2315 "",
2316 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2317 0,
2318 net::ERR_FAILED
2319 }
2320 },
2321 { // Direct download with injected "Failed" error in Write().
2322 { "a_zip_file.zip",
2323 DOWNLOAD_DIRECT,
2324 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2325 1
2326 },
2327 {
2328 "",
2329 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2330 0,
2331 net::ERR_FAILED
2332 }
2333 },
2334 { // Navigated download with injected "Name too long" error in
2335 // Initialize().
2336 { "a_zip_file.zip",
2337 DOWNLOAD_NAVIGATE,
2338 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
2339 1
2340 },
2341 {
2342 "",
2343 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2344 0,
2345 net::ERR_FILE_PATH_TOO_LONG
2346 }
2347 },
2348 { // Direct download with injected "Name too long" error in Initialize().
2349 { "a_zip_file.zip",
2350 DOWNLOAD_DIRECT,
2351 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
2352 1
2353 },
2354 {
2355 "",
2356 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2357 0,
2358 net::ERR_FILE_PATH_TOO_LONG
2359 }
2360 },
2361 { // Navigated download with injected "Name too long" error in Write().
2362 { "a_zip_file.zip",
2363 DOWNLOAD_NAVIGATE,
2364 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2365 1
2366 },
2367 {
2368 "",
2369 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2370 0,
2371 net::ERR_INVALID_HANDLE
2372 }
2373 },
2374 { // Direct download with injected "Name too long" error in Write().
2375 { "a_zip_file.zip",
2376 DOWNLOAD_DIRECT,
2377 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2378 1
2379 },
2380 {
2381 "",
2382 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2383 0,
2384 net::ERR_INVALID_HANDLE
2385 }
2386 },
2387 { // Direct download with injected "Disk full" error in 2nd Write().
2388 { "06bESSE21Evolution.ppt",
2389 DOWNLOAD_DIRECT,
2390 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2391 1
2392 },
2393 {
2394 "",
2395 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2396 1,
2397 net::ERR_FILE_NO_SPACE
2398 }
2399 }
2095 }; 2400 };
2096 2401
2097 // Do initial setup. 2402 DownloadInsertFilesErrorCheckErrors(ARRAYSIZE_UNSAFE(error_info), error_info);
2098 ASSERT_TRUE(InitialSetup(false)); 2403 }
2099 DownloadFileCheckErrors(download_info); 2404
2100 } 2405 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorReadonlyFolder) {
2101 2406 DownloadInfo download_info[] = {
2102 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError404Direct) { 2407 {
2103 DownloadInfo download_info = { 2408 "a_zip_file.zip",
2104 "there_IS_no_spoon.zip", 2409 DOWNLOAD_DIRECT,
2105 DOWNLOAD_DIRECT, 2410 // This passes because we switch to the My Documents folder.
2106 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, 2411 content::DOWNLOAD_INTERRUPT_REASON_NONE,
2107 true, 2412 true,
2108 false 2413 true
2414 },
2415 {
2416 "a_zip_file.zip",
2417 DOWNLOAD_NAVIGATE,
2418 // This passes because we switch to the My Documents folder.
2419 content::DOWNLOAD_INTERRUPT_REASON_NONE,
2420 true,
2421 true
2422 }
2109 }; 2423 };
2110 2424
2111 // Do initial setup. 2425 DownloadFilesToReadonlyFolder(ARRAYSIZE_UNSAFE(download_info), download_info);
2112 ASSERT_TRUE(InitialSetup(false)); 2426 }
2113 DownloadFileCheckErrors(download_info);
2114 }
2115
2116 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError404Navigate) {
2117 DownloadInfo download_info = {
2118 "there_IS_no_spoon.zip",
2119 DOWNLOAD_NAVIGATE,
2120 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2121 false,
2122 false
2123 };
2124
2125 // Do initial setup.
2126 ASSERT_TRUE(InitialSetup(false));
2127 DownloadFileCheckErrors(download_info);
2128 }
2129
2130 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError400Direct) {
2131 DownloadInfo download_info = {
2132 "zip_file_not_found.zip",
2133 DOWNLOAD_DIRECT,
2134 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2135 true,
2136 false
2137 };
2138
2139 // Do initial setup.
2140 ASSERT_TRUE(InitialSetup(false));
2141 DownloadFileCheckErrors(download_info);
2142 }
2143
2144 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError400Navigate) {
2145 DownloadInfo download_info = {
2146 "zip_file_not_found.zip",
2147 DOWNLOAD_NAVIGATE,
2148 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2149 false,
2150 false
2151 };
2152
2153 // Do initial setup.
2154 ASSERT_TRUE(InitialSetup(false));
2155 DownloadFileCheckErrors(download_info);
2156 }
2157
2158 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorReadonlyFolderDirect) {
2159 DownloadInfo download_info = {
2160 "a_zip_file.zip",
2161 DOWNLOAD_DIRECT,
2162 // This passes because we switch to the My Documents folder.
2163 content::DOWNLOAD_INTERRUPT_REASON_NONE,
2164 true,
2165 true
2166 };
2167
2168 DownloadFileToReadonlyFolder(download_info);
2169 }
2170
2171 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorReadonlyFolderNavigate) {
2172 DownloadInfo download_info = {
2173 "a_zip_file.zip",
2174 DOWNLOAD_NAVIGATE,
2175 // This passes because we switch to the My Documents folder.
2176 content::DOWNLOAD_INTERRUPT_REASON_NONE,
2177 true,
2178 true
2179 };
2180
2181 DownloadFileToReadonlyFolder(download_info);
2182 }
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