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

Side by Side Diff: chrome/browser/download/download_browsertest.cc

Issue 148133007: [Downloads] Always call DM::StartDownload() for explicit downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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> 5 #include <sstream>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 class DownloadTest : public InProcessBrowserTest { 419 class DownloadTest : public InProcessBrowserTest {
420 public: 420 public:
421 // Choice of navigation or direct fetch. Used by |DownloadFileCheckErrors()|. 421 // Choice of navigation or direct fetch. Used by |DownloadFileCheckErrors()|.
422 enum DownloadMethod { 422 enum DownloadMethod {
423 DOWNLOAD_NAVIGATE, 423 DOWNLOAD_NAVIGATE,
424 DOWNLOAD_DIRECT 424 DOWNLOAD_DIRECT
425 }; 425 };
426 426
427 // Information passed in to |DownloadFileCheckErrors()|. 427 // Information passed in to |DownloadFileCheckErrors()|.
428 struct DownloadInfo { 428 struct DownloadInfo {
429 const char* url_name; // URL for the download. 429 const char* starting_url; // URL for initiating the download.
430 const char* expected_download_url; // Expected value of DI::GetURL().
430 DownloadMethod download_method; // Navigation or Direct. 431 DownloadMethod download_method; // Navigation or Direct.
431 // Download interrupt reason (NONE is OK). 432 // Download interrupt reason (NONE is OK).
432 content::DownloadInterruptReason reason; 433 content::DownloadInterruptReason reason;
433 bool show_download_item; // True if the download item appears on the shelf. 434 bool show_download_item; // True if the download item appears on the shelf.
434 bool should_redirect_to_documents; // True if we save it in "My Documents". 435 bool should_redirect_to_documents; // True if we save it in "My Documents".
435 }; 436 };
436 437
437 struct FileErrorInjectInfo { 438 struct FileErrorInjectInfo {
438 DownloadInfo download_info; 439 DownloadInfo download_info;
439 content::TestFileErrorInjector::FileErrorInfo error_info; 440 content::TestFileErrorInjector::FileErrorInfo error_info;
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 ASSERT_TRUE(test_server()->Start()); 841 ASSERT_TRUE(test_server()->Start());
841 std::vector<DownloadItem*> download_items; 842 std::vector<DownloadItem*> download_items;
842 GetDownloads(browser(), &download_items); 843 GetDownloads(browser(), &download_items);
843 ASSERT_TRUE(download_items.empty()); 844 ASSERT_TRUE(download_items.empty());
844 845
845 EnableFileChooser(true); 846 EnableFileChooser(true);
846 } 847 }
847 848
848 void DownloadFilesCheckErrorsLoopBody(const DownloadInfo& download_info, 849 void DownloadFilesCheckErrorsLoopBody(const DownloadInfo& download_info,
849 size_t i) { 850 size_t i) {
850 std::stringstream s; 851 SCOPED_TRACE(testing::Message()
851 s << " " << __FUNCTION__ << "()" 852 << " " << __FUNCTION__ << "()"
852 << " index = " << i 853 << " index = " << i << " starting_url = '"
853 << " url = '" << download_info.url_name << "'" 854 << download_info.starting_url << "'"
854 << " method = " 855 << " download_url = '" << download_info.expected_download_url
855 << ((download_info.download_method == DOWNLOAD_DIRECT) ? 856 << "'"
856 "DOWNLOAD_DIRECT" : "DOWNLOAD_NAVIGATE") 857 << " method = "
857 << " show_item = " << download_info.show_download_item 858 << ((download_info.download_method == DOWNLOAD_DIRECT)
858 << " reason = " << DownloadInterruptReasonToString(download_info.reason); 859 ? "DOWNLOAD_DIRECT"
860 : "DOWNLOAD_NAVIGATE") << " show_item = "
861 << download_info.show_download_item << " reason = "
862 << DownloadInterruptReasonToString(download_info.reason));
859 863
860 std::vector<DownloadItem*> download_items; 864 std::vector<DownloadItem*> download_items;
861 GetDownloads(browser(), &download_items); 865 GetDownloads(browser(), &download_items);
862 size_t downloads_expected = download_items.size(); 866 size_t downloads_expected = download_items.size();
863 867
864 std::string server_path = "files/downloads/"; 868 // GURL("http://foo/bar").Resolve("baz") => "http://foo/bar/baz"
865 server_path += download_info.url_name; 869 // GURL("http://foo/bar").Resolve("http://baz") => "http://baz"
866 GURL url = test_server()->GetURL(server_path); 870 // I.e. both starting_url and expected_download_url can either be relative
867 ASSERT_TRUE(url.is_valid()) << s.str(); 871 // to the base test server URL or be an absolute URL.
872 GURL base_url = test_server()->GetURL("files/downloads/");
873 GURL starting_url = base_url.Resolve(download_info.starting_url);
874 GURL download_url = base_url.Resolve(download_info.expected_download_url);
875 ASSERT_TRUE(starting_url.is_valid());
876 ASSERT_TRUE(download_url.is_valid());
868 877
869 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); 878 DownloadManager* download_manager = DownloadManagerForBrowser(browser());
870 WebContents* web_contents = 879 WebContents* web_contents =
871 browser()->tab_strip_model()->GetActiveWebContents(); 880 browser()->tab_strip_model()->GetActiveWebContents();
872 ASSERT_TRUE(web_contents) << s.str(); 881 ASSERT_TRUE(web_contents);
873 882
874 scoped_ptr<content::DownloadTestObserver> observer( 883 scoped_ptr<content::DownloadTestObserver> observer(
875 new content::DownloadTestObserverTerminal( 884 new content::DownloadTestObserverTerminal(
876 download_manager, 885 download_manager,
877 1, 886 1,
878 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 887 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
879 888
880 if (download_info.download_method == DOWNLOAD_DIRECT) { 889 if (download_info.download_method == DOWNLOAD_DIRECT) {
881 // Go directly to download. Don't wait for navigation. 890 // Go directly to download. Don't wait for navigation.
882 scoped_refptr<content::DownloadTestItemCreationObserver> 891 scoped_refptr<content::DownloadTestItemCreationObserver>
883 creation_observer(new content::DownloadTestItemCreationObserver); 892 creation_observer(new content::DownloadTestItemCreationObserver);
884 893
885 scoped_ptr<DownloadUrlParameters> params( 894 scoped_ptr<DownloadUrlParameters> params(
886 DownloadUrlParameters::FromWebContents(web_contents, url)); 895 DownloadUrlParameters::FromWebContents(web_contents, starting_url));
887 params->set_callback(creation_observer->callback()); 896 params->set_callback(creation_observer->callback());
888 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); 897 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass());
889 898
890 // Wait until the item is created, or we have determined that it 899 // Wait until the item is created, or we have determined that it
891 // won't be. 900 // won't be.
892 creation_observer->WaitForDownloadItemCreation(); 901 creation_observer->WaitForDownloadItemCreation();
893 902
894 EXPECT_EQ(download_info.show_download_item, 903 EXPECT_NE(content::DownloadItem::kInvalidId,
895 creation_observer->succeeded()); 904 creation_observer->download_id());
896 if (download_info.show_download_item) {
897 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE,
898 creation_observer->interrupt_reason());
899 EXPECT_NE(content::DownloadItem::kInvalidId,
900 creation_observer->download_id());
901 } else {
902 EXPECT_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE,
903 creation_observer->interrupt_reason());
904 EXPECT_EQ(content::DownloadItem::kInvalidId,
905 creation_observer->download_id());
906 }
907 } else { 905 } else {
908 // Navigate to URL normally, wait until done. 906 // Navigate to URL normally, wait until done.
909 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), 907 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
910 url, 908 browser(), starting_url, 1);
911 1);
912 } 909 }
913 910
914 if (download_info.show_download_item) { 911 if (download_info.show_download_item) {
915 downloads_expected++; 912 downloads_expected++;
916 observer->WaitForFinished(); 913 observer->WaitForFinished();
917 DownloadItem::DownloadState final_state = 914 DownloadItem::DownloadState final_state =
918 (download_info.reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) ? 915 (download_info.reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) ?
919 DownloadItem::COMPLETE : 916 DownloadItem::COMPLETE :
920 DownloadItem::INTERRUPTED; 917 DownloadItem::INTERRUPTED;
921 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(final_state)); 918 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(final_state));
922 } 919 }
923 920
924 // Wait till the |DownloadFile|s are destroyed. 921 // Wait till the |DownloadFile|s are destroyed.
925 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); 922 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
926 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); 923 content::RunAllPendingInMessageLoop(content::BrowserThread::UI);
927 924
928 // Validate that the correct files were downloaded. 925 // Validate that the correct files were downloaded.
929 download_items.clear(); 926 download_items.clear();
930 GetDownloads(browser(), &download_items); 927 GetDownloads(browser(), &download_items);
931 ASSERT_EQ(downloads_expected, download_items.size()) << s.str(); 928 ASSERT_EQ(downloads_expected, download_items.size());
932 929
933 if (download_info.show_download_item) { 930 if (download_info.show_download_item) {
934 // Find the last download item. 931 // Find the last download item.
935 DownloadItem* item = download_items[0]; 932 DownloadItem* item = download_items[0];
936 for (size_t d = 1; d < downloads_expected; ++d) { 933 for (size_t d = 1; d < downloads_expected; ++d) {
937 if (download_items[d]->GetStartTime() > item->GetStartTime()) 934 if (download_items[d]->GetStartTime() > item->GetStartTime())
938 item = download_items[d]; 935 item = download_items[d];
939 } 936 }
940 937
941 ASSERT_EQ(url, item->GetOriginalUrl()) << s.str(); 938 EXPECT_EQ(download_url, item->GetURL());
942 939 EXPECT_EQ(download_info.reason, item->GetLastReason());
943 ASSERT_EQ(download_info.reason, item->GetLastReason()) << s.str();
944 940
945 if (item->GetState() == content::DownloadItem::COMPLETE) { 941 if (item->GetState() == content::DownloadItem::COMPLETE) {
946 // Clean up the file, in case it ended up in the My Documents folder. 942 // Clean up the file, in case it ended up in the My Documents folder.
947 base::FilePath destination_folder = GetDownloadDirectory(browser()); 943 base::FilePath destination_folder = GetDownloadDirectory(browser());
948 base::FilePath my_downloaded_file = item->GetTargetFilePath(); 944 base::FilePath my_downloaded_file = item->GetTargetFilePath();
949 EXPECT_TRUE(base::PathExists(my_downloaded_file)); 945 EXPECT_TRUE(base::PathExists(my_downloaded_file));
950 EXPECT_TRUE(base::DeleteFile(my_downloaded_file, false)); 946 EXPECT_TRUE(base::DeleteFile(my_downloaded_file, false));
951 947
952 EXPECT_EQ(download_info.should_redirect_to_documents ? 948 EXPECT_EQ(download_info.should_redirect_to_documents ?
953 std::string::npos : 949 std::string::npos :
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 DownloadFilesCheckErrorsSetup(); 1008 DownloadFilesCheckErrorsSetup();
1013 1009
1014 // Set up file failures. 1010 // Set up file failures.
1015 scoped_refptr<content::TestFileErrorInjector> injector( 1011 scoped_refptr<content::TestFileErrorInjector> injector(
1016 content::TestFileErrorInjector::Create( 1012 content::TestFileErrorInjector::Create(
1017 DownloadManagerForBrowser(browser()))); 1013 DownloadManagerForBrowser(browser())));
1018 1014
1019 for (size_t i = 0; i < count; ++i) { 1015 for (size_t i = 0; i < count; ++i) {
1020 // Set up the full URL, for download file tracking. 1016 // Set up the full URL, for download file tracking.
1021 std::string server_path = "files/downloads/"; 1017 std::string server_path = "files/downloads/";
1022 server_path += info[i].download_info.url_name; 1018 server_path += info[i].download_info.starting_url;
1023 GURL url = test_server()->GetURL(server_path); 1019 GURL url = test_server()->GetURL(server_path);
1024 info[i].error_info.url = url.spec(); 1020 info[i].error_info.url = url.spec();
1025 1021
1026 DownloadInsertFilesErrorCheckErrorsLoopBody(injector, info[i], i); 1022 DownloadInsertFilesErrorCheckErrorsLoopBody(injector, info[i], i);
1027 } 1023 }
1028 } 1024 }
1029 1025
1030 // Attempts to download a file to a read-only folder, based on information 1026 // Attempts to download a file to a read-only folder, based on information
1031 // in |download_info|. 1027 // in |download_info|.
1032 void DownloadFilesToReadonlyFolder(size_t count, 1028 void DownloadFilesToReadonlyFolder(size_t count,
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 DownloadRequestLimiter::TabDownloadState* tab_download_state = 1258 DownloadRequestLimiter::TabDownloadState* tab_download_state =
1263 g_browser_process->download_request_limiter()->GetDownloadState( 1259 g_browser_process->download_request_limiter()->GetDownloadState(
1264 web_contents, web_contents, true); 1260 web_contents, web_contents, true);
1265 ASSERT_TRUE(tab_download_state); 1261 ASSERT_TRUE(tab_download_state);
1266 tab_download_state->set_download_status( 1262 tab_download_state->set_download_status(
1267 DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED); 1263 DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED);
1268 1264
1269 // Try to start the download via Javascript and wait for the corresponding 1265 // Try to start the download via Javascript and wait for the corresponding
1270 // load stop event. 1266 // load stop event.
1271 content::TestNavigationObserver observer(web_contents); 1267 content::TestNavigationObserver observer(web_contents);
1272 bool download_assempted; 1268 bool download_attempted;
1273 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 1269 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
1274 browser()->tab_strip_model()->GetActiveWebContents(), 1270 browser()->tab_strip_model()->GetActiveWebContents(),
1275 "window.domAutomationController.send(startDownload());", 1271 "window.domAutomationController.send(startDownload());",
1276 &download_assempted)); 1272 &download_attempted));
1277 ASSERT_TRUE(download_assempted); 1273 ASSERT_TRUE(download_attempted);
1278 observer.Wait(); 1274 observer.Wait();
1279 1275
1280 // Check that we did not download the file. 1276 // Check that we did not download the file.
1281 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1277 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1282 base::FilePath file_path(DestinationFile(browser(), file)); 1278 base::FilePath file_path(DestinationFile(browser(), file));
1283 EXPECT_FALSE(base::PathExists(file_path)); 1279 EXPECT_FALSE(base::PathExists(file_path));
1284 1280
1285 // Check state. 1281 // Check state.
1286 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 1282 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1287 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1283 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 EXPECT_TRUE(DidShowFileChooser()); 2406 EXPECT_TRUE(DidShowFileChooser());
2411 ASSERT_EQ(2u, download_items.size()); 2407 ASSERT_EQ(2u, download_items.size());
2412 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); 2408 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl());
2413 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); 2409 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl());
2414 } 2410 }
2415 2411
2416 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsServer) { 2412 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsServer) {
2417 DownloadInfo download_info[] = { 2413 DownloadInfo download_info[] = {
2418 { // Normal navigated download. 2414 { // Normal navigated download.
2419 "a_zip_file.zip", 2415 "a_zip_file.zip",
2416 "a_zip_file.zip",
2420 DOWNLOAD_NAVIGATE, 2417 DOWNLOAD_NAVIGATE,
2421 content::DOWNLOAD_INTERRUPT_REASON_NONE, 2418 content::DOWNLOAD_INTERRUPT_REASON_NONE,
2422 true, 2419 true,
2423 false 2420 false
2424 }, 2421 },
2425 { // Normal direct download. 2422 { // Normal direct download.
2426 "a_zip_file.zip", 2423 "a_zip_file.zip",
2424 "a_zip_file.zip",
2427 DOWNLOAD_DIRECT, 2425 DOWNLOAD_DIRECT,
2428 content::DOWNLOAD_INTERRUPT_REASON_NONE, 2426 content::DOWNLOAD_INTERRUPT_REASON_NONE,
2429 true, 2427 true,
2430 false 2428 false
2431 }, 2429 },
2432 { // Direct download with 404 error. 2430 { // Direct download with 404 error.
2433 "there_IS_no_spoon.zip", 2431 "there_IS_no_spoon.zip",
2432 "there_IS_no_spoon.zip",
2434 DOWNLOAD_DIRECT, 2433 DOWNLOAD_DIRECT,
2435 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, 2434 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2436 true, 2435 true,
2437 false 2436 false
2438 }, 2437 },
2439 { // Navigated download with 404 error. 2438 { // Navigated download with 404 error.
2440 "there_IS_no_spoon.zip", 2439 "there_IS_no_spoon.zip",
2440 "there_IS_no_spoon.zip",
2441 DOWNLOAD_NAVIGATE, 2441 DOWNLOAD_NAVIGATE,
2442 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, 2442 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2443 false, 2443 false,
2444 false 2444 false
2445 }, 2445 },
2446 { // Direct download with 400 error. 2446 { // Direct download with 400 error.
2447 "zip_file_not_found.zip", 2447 "zip_file_not_found.zip",
2448 "zip_file_not_found.zip",
2448 DOWNLOAD_DIRECT, 2449 DOWNLOAD_DIRECT,
2449 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, 2450 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2450 true, 2451 true,
2451 false 2452 false
2452 }, 2453 },
2453 { // Navigated download with 400 error. 2454 { // Navigated download with 400 error.
2454 "zip_file_not_found.zip", 2455 "zip_file_not_found.zip",
2456 "",
2455 DOWNLOAD_NAVIGATE, 2457 DOWNLOAD_NAVIGATE,
2456 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, 2458 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2457 false, 2459 false,
2458 false 2460 false
2461 },
2462 { // Simulates clicking on <a href="http://..." download="">. The name does
2463 // not resolve. But since this is an explicit download, the download
2464 // should appear on the shelf and the error should be indicated.
2465 "download-anchor-attrib-name-not-resolved.html",
2466 "http://doesnotexist/shouldnotberesolved",
2467 DOWNLOAD_NAVIGATE,
2468 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED,
2469 true,
2470 false
2471 },
2472 { // Simulates clicking on <a href="http://..." download=""> where the URL
2473 // leads to a 404 response. This is different from the previous test case
2474 // in that the ResourceLoader issues a OnResponseStarted() callback since
2475 // the headers are successfully received.
2476 "download-anchor-attrib-404.html",
2477 "there_IS_no_spoon.zip",
2478 DOWNLOAD_NAVIGATE,
2479 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2480 true,
2481 false
2482 },
2483 { // Similar to the above, but the resulting response contains a status
2484 // code of 400.
2485 "download-anchor-attrib-400.html",
2486 "zip_file_not_found.zip",
2487 DOWNLOAD_NAVIGATE,
2488 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2489 true,
2490 false
2491 },
2492 { // Direct download of a URL where the hostname doesn't resolve.
2493 "http://doesnotexist/shouldnotdownloadsuccessfully",
2494 "http://doesnotexist/shouldnotdownloadsuccessfully",
2495 DOWNLOAD_DIRECT,
2496 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED,
2497 true,
2498 false
2459 } 2499 }
2460 }; 2500 };
2461 2501
2462 DownloadFilesCheckErrors(ARRAYSIZE_UNSAFE(download_info), download_info); 2502 DownloadFilesCheckErrors(ARRAYSIZE_UNSAFE(download_info), download_info);
2463 } 2503 }
2464 2504
2465 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsFile) { 2505 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsFile) {
2466 FileErrorInjectInfo error_info[] = { 2506 FileErrorInjectInfo error_info[] = {
2467 { // Navigated download with injected "Disk full" error in Initialize(). 2507 { // Navigated download with injected "Disk full" error in Initialize().
2468 { "a_zip_file.zip", 2508 {
2509 "a_zip_file.zip",
2510 "a_zip_file.zip",
2469 DOWNLOAD_NAVIGATE, 2511 DOWNLOAD_NAVIGATE,
2470 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 2512 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2471 1 2513 true,
2514 false
2472 }, 2515 },
2473 { 2516 {
2474 "", 2517 "",
2475 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 2518 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2476 0, 2519 0,
2477 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 2520 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2478 } 2521 }
2479 }, 2522 },
2480 { // Direct download with injected "Disk full" error in Initialize(). 2523 { // Direct download with injected "Disk full" error in Initialize().
2481 { "a_zip_file.zip", 2524 {
2525 "a_zip_file.zip",
2526 "a_zip_file.zip",
2482 DOWNLOAD_DIRECT, 2527 DOWNLOAD_DIRECT,
2483 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 2528 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2484 1 2529 true,
2530 false
2485 }, 2531 },
2486 { 2532 {
2487 "", 2533 "",
2488 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 2534 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2489 0, 2535 0,
2490 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 2536 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2491 } 2537 }
2492 }, 2538 },
2493 { // Navigated download with injected "Disk full" error in Write(). 2539 { // Navigated download with injected "Disk full" error in Write().
2494 { "a_zip_file.zip", 2540 {
2541 "a_zip_file.zip",
2542 "a_zip_file.zip",
2495 DOWNLOAD_NAVIGATE, 2543 DOWNLOAD_NAVIGATE,
2496 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 2544 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2497 1 2545 true,
2546 false
2498 }, 2547 },
2499 { 2548 {
2500 "", 2549 "",
2501 content::TestFileErrorInjector::FILE_OPERATION_WRITE, 2550 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2502 0, 2551 0,
2503 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 2552 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2504 } 2553 }
2505 }, 2554 },
2506 { // Direct download with injected "Disk full" error in Write(). 2555 { // Direct download with injected "Disk full" error in Write().
2507 { "a_zip_file.zip", 2556 {
2557 "a_zip_file.zip",
2558 "a_zip_file.zip",
2508 DOWNLOAD_DIRECT, 2559 DOWNLOAD_DIRECT,
2509 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 2560 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2510 1 2561 true,
2562 false
2511 }, 2563 },
2512 { 2564 {
2513 "", 2565 "",
2514 content::TestFileErrorInjector::FILE_OPERATION_WRITE, 2566 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2515 0, 2567 0,
2516 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 2568 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2517 } 2569 }
2518 }, 2570 },
2519 { // Navigated download with injected "Failed" error in Initialize(). 2571 { // Navigated download with injected "Failed" error in Initialize().
2520 { "a_zip_file.zip", 2572 {
2573 "a_zip_file.zip",
2574 "a_zip_file.zip",
2521 DOWNLOAD_NAVIGATE, 2575 DOWNLOAD_NAVIGATE,
2522 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 2576 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2523 1 2577 true,
2578 false
2524 }, 2579 },
2525 { 2580 {
2526 "", 2581 "",
2527 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 2582 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2528 0, 2583 0,
2529 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 2584 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2530 } 2585 }
2531 }, 2586 },
2532 { // Direct download with injected "Failed" error in Initialize(). 2587 { // Direct download with injected "Failed" error in Initialize().
2533 { "a_zip_file.zip", 2588 {
2589 "a_zip_file.zip",
2590 "a_zip_file.zip",
2534 DOWNLOAD_DIRECT, 2591 DOWNLOAD_DIRECT,
2535 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 2592 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2536 1 2593 true,
2594 false
2537 }, 2595 },
2538 { 2596 {
2539 "", 2597 "",
2540 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 2598 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2541 0, 2599 0,
2542 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 2600 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2543 } 2601 }
2544 }, 2602 },
2545 { // Navigated download with injected "Failed" error in Write(). 2603 { // Navigated download with injected "Failed" error in Write().
2546 { "a_zip_file.zip", 2604 {
2605 "a_zip_file.zip",
2606 "a_zip_file.zip",
2547 DOWNLOAD_NAVIGATE, 2607 DOWNLOAD_NAVIGATE,
2548 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 2608 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2549 1 2609 true,
2610 false
2550 }, 2611 },
2551 { 2612 {
2552 "", 2613 "",
2553 content::TestFileErrorInjector::FILE_OPERATION_WRITE, 2614 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2554 0, 2615 0,
2555 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 2616 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2556 } 2617 }
2557 }, 2618 },
2558 { // Direct download with injected "Failed" error in Write(). 2619 { // Direct download with injected "Failed" error in Write().
2559 { "a_zip_file.zip", 2620 {
2621 "a_zip_file.zip",
2622 "a_zip_file.zip",
2560 DOWNLOAD_DIRECT, 2623 DOWNLOAD_DIRECT,
2561 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 2624 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2562 1 2625 true,
2626 false
2563 }, 2627 },
2564 { 2628 {
2565 "", 2629 "",
2566 content::TestFileErrorInjector::FILE_OPERATION_WRITE, 2630 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2567 0, 2631 0,
2568 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 2632 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2569 } 2633 }
2570 }, 2634 },
2571 { // Navigated download with injected "Name too long" error in 2635 { // Navigated download with injected "Name too long" error in
2572 // Initialize(). 2636 // Initialize().
2573 { "a_zip_file.zip", 2637 {
2638 "a_zip_file.zip",
2639 "a_zip_file.zip",
2574 DOWNLOAD_NAVIGATE, 2640 DOWNLOAD_NAVIGATE,
2575 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, 2641 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
2576 1 2642 true,
2643 false
2577 }, 2644 },
2578 { 2645 {
2579 "", 2646 "",
2580 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 2647 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2581 0, 2648 0,
2582 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, 2649 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
2583 } 2650 }
2584 }, 2651 },
2585 { // Direct download with injected "Name too long" error in Initialize(). 2652 { // Direct download with injected "Name too long" error in Initialize().
2586 { "a_zip_file.zip", 2653 {
2654 "a_zip_file.zip",
2655 "a_zip_file.zip",
2587 DOWNLOAD_DIRECT, 2656 DOWNLOAD_DIRECT,
2588 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, 2657 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
2589 1 2658 true,
2659 false
2590 }, 2660 },
2591 { 2661 {
2592 "", 2662 "",
2593 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 2663 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
2594 0, 2664 0,
2595 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, 2665 content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
2596 } 2666 }
2597 }, 2667 },
2598 { // Navigated download with injected "Name too long" error in Write(). 2668 { // Navigated download with injected "Name too long" error in Write().
2599 { "a_zip_file.zip", 2669 {
2670 "a_zip_file.zip",
2671 "a_zip_file.zip",
2600 DOWNLOAD_NAVIGATE, 2672 DOWNLOAD_NAVIGATE,
2601 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 2673 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2602 1 2674 true,
2675 false
2603 }, 2676 },
2604 { 2677 {
2605 "", 2678 "",
2606 content::TestFileErrorInjector::FILE_OPERATION_WRITE, 2679 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2607 0, 2680 0,
2608 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 2681 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2609 } 2682 }
2610 }, 2683 },
2611 { // Direct download with injected "Name too long" error in Write(). 2684 { // Direct download with injected "Name too long" error in Write().
2612 { "a_zip_file.zip", 2685 {
2686 "a_zip_file.zip",
2687 "a_zip_file.zip",
2613 DOWNLOAD_DIRECT, 2688 DOWNLOAD_DIRECT,
2614 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 2689 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2615 1 2690 true,
2691 false
2616 }, 2692 },
2617 { 2693 {
2618 "", 2694 "",
2619 content::TestFileErrorInjector::FILE_OPERATION_WRITE, 2695 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2620 0, 2696 0,
2621 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 2697 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
2622 } 2698 }
2623 }, 2699 },
2624 { // Direct download with injected "Disk full" error in 2nd Write(). 2700 { // Direct download with injected "Disk full" error in 2nd Write().
2625 { "06bESSE21Evolution.ppt", 2701 {
2702 "06bESSE21Evolution.ppt",
2703 "06bESSE21Evolution.ppt",
2626 DOWNLOAD_DIRECT, 2704 DOWNLOAD_DIRECT,
2627 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 2705 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2628 1 2706 true,
2707 false
2629 }, 2708 },
2630 { 2709 {
2631 "", 2710 "",
2632 content::TestFileErrorInjector::FILE_OPERATION_WRITE, 2711 content::TestFileErrorInjector::FILE_OPERATION_WRITE,
2633 1, 2712 1,
2634 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 2713 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
2635 } 2714 }
2636 } 2715 }
2637 }; 2716 };
2638 2717
2639 DownloadInsertFilesErrorCheckErrors(ARRAYSIZE_UNSAFE(error_info), error_info); 2718 DownloadInsertFilesErrorCheckErrors(ARRAYSIZE_UNSAFE(error_info), error_info);
2640 } 2719 }
2641 2720
2642 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorReadonlyFolder) { 2721 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorReadonlyFolder) {
2643 DownloadInfo download_info[] = { 2722 DownloadInfo download_info[] = {
2644 { 2723 {
2645 "a_zip_file.zip", 2724 "a_zip_file.zip",
2725 "a_zip_file.zip",
2646 DOWNLOAD_DIRECT, 2726 DOWNLOAD_DIRECT,
2647 // This passes because we switch to the My Documents folder. 2727 // This passes because we switch to the My Documents folder.
2648 content::DOWNLOAD_INTERRUPT_REASON_NONE, 2728 content::DOWNLOAD_INTERRUPT_REASON_NONE,
2649 true, 2729 true,
2650 true 2730 true
2651 }, 2731 },
2652 { 2732 {
2653 "a_zip_file.zip", 2733 "a_zip_file.zip",
2734 "a_zip_file.zip",
2654 DOWNLOAD_NAVIGATE, 2735 DOWNLOAD_NAVIGATE,
2655 // This passes because we switch to the My Documents folder. 2736 // This passes because we switch to the My Documents folder.
2656 content::DOWNLOAD_INTERRUPT_REASON_NONE, 2737 content::DOWNLOAD_INTERRUPT_REASON_NONE,
2657 true, 2738 true,
2658 true 2739 true
2659 } 2740 }
2660 }; 2741 };
2661 2742
2662 DownloadFilesToReadonlyFolder(ARRAYSIZE_UNSAFE(download_info), download_info); 2743 DownloadFilesToReadonlyFolder(ARRAYSIZE_UNSAFE(download_info), download_info);
2663 } 2744 }
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
3225 3306
3226 // No errors this time. The download should complete successfully. 3307 // No errors this time. The download should complete successfully.
3227 EXPECT_FALSE(completion_observer->IsFinished()); 3308 EXPECT_FALSE(completion_observer->IsFinished());
3228 completion_observer->StartObserving(); 3309 completion_observer->StartObserving();
3229 download->Resume(); 3310 download->Resume();
3230 completion_observer->WaitForFinished(); 3311 completion_observer->WaitForFinished();
3231 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); 3312 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState());
3232 3313
3233 EXPECT_FALSE(DidShowFileChooser()); 3314 EXPECT_FALSE(DidShowFileChooser());
3234 } 3315 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_target_determiner.cc » ('j') | content/browser/download/download_item_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698