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

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

Issue 2835233002: Fix integration tests in src/chrome and src/extensions so that we can turn on IO thread checks wi... (Closed)
Patch Set: ready for review Created 3 years, 8 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
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 "chrome/browser/download/download_browsertest.h" 5 #include "chrome/browser/download/download_browsertest.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 13 matching lines...) Expand all
24 #include "base/macros.h" 24 #include "base/macros.h"
25 #include "base/memory/ref_counted.h" 25 #include "base/memory/ref_counted.h"
26 #include "base/path_service.h" 26 #include "base/path_service.h"
27 #include "base/strings/string_number_conversions.h" 27 #include "base/strings/string_number_conversions.h"
28 #include "base/strings/string_split.h" 28 #include "base/strings/string_split.h"
29 #include "base/strings/string_util.h" 29 #include "base/strings/string_util.h"
30 #include "base/strings/stringprintf.h" 30 #include "base/strings/stringprintf.h"
31 #include "base/strings/utf_string_conversions.h" 31 #include "base/strings/utf_string_conversions.h"
32 #include "base/sys_info.h" 32 #include "base/sys_info.h"
33 #include "base/test/test_file_util.h" 33 #include "base/test/test_file_util.h"
34 #include "base/threading/thread_restrictions.h"
34 #include "build/build_config.h" 35 #include "build/build_config.h"
35 #include "chrome/app/chrome_command_ids.h" 36 #include "chrome/app/chrome_command_ids.h"
36 #include "chrome/browser/browser_process.h" 37 #include "chrome/browser/browser_process.h"
37 #include "chrome/browser/chrome_notification_types.h" 38 #include "chrome/browser/chrome_notification_types.h"
38 #include "chrome/browser/download/chrome_download_manager_delegate.h" 39 #include "chrome/browser/download/chrome_download_manager_delegate.h"
39 #include "chrome/browser/download/download_commands.h" 40 #include "chrome/browser/download/download_commands.h"
40 #include "chrome/browser/download/download_crx_util.h" 41 #include "chrome/browser/download/download_crx_util.h"
41 #include "chrome/browser/download/download_history.h" 42 #include "chrome/browser/download/download_history.h"
42 #include "chrome/browser/download/download_item_model.h" 43 #include "chrome/browser/download/download_item_model.h"
43 #include "chrome/browser/download/download_prefs.h" 44 #include "chrome/browser/download/download_prefs.h"
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 } 497 }
497 498
498 // Must be called after browser creation. Creates a temporary 499 // Must be called after browser creation. Creates a temporary
499 // directory for downloads that is auto-deleted on destruction. 500 // directory for downloads that is auto-deleted on destruction.
500 // Returning false indicates a failure of the function, and should be asserted 501 // Returning false indicates a failure of the function, and should be asserted
501 // in the caller. 502 // in the caller.
502 bool CreateAndSetDownloadsDirectory(Browser* browser) { 503 bool CreateAndSetDownloadsDirectory(Browser* browser) {
503 if (!browser) 504 if (!browser)
504 return false; 505 return false;
505 506
507 base::ThreadRestrictions::ScopedAllowIO allow_io;
506 if (!downloads_directory_.CreateUniqueTempDir()) 508 if (!downloads_directory_.CreateUniqueTempDir())
507 return false; 509 return false;
508 510
509 browser->profile()->GetPrefs()->SetFilePath( 511 browser->profile()->GetPrefs()->SetFilePath(
510 prefs::kDownloadDefaultDirectory, downloads_directory_.GetPath()); 512 prefs::kDownloadDefaultDirectory, downloads_directory_.GetPath());
511 browser->profile()->GetPrefs()->SetFilePath( 513 browser->profile()->GetPrefs()->SetFilePath(
512 prefs::kSaveFileDefaultDirectory, downloads_directory_.GetPath()); 514 prefs::kSaveFileDefaultDirectory, downloads_directory_.GetPath());
513 515
514 return true; 516 return true;
515 } 517 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 626
625 // Find the origin path (from which the data comes). 627 // Find the origin path (from which the data comes).
626 base::FilePath origin_file(OriginFile(origin_filename)); 628 base::FilePath origin_file(OriginFile(origin_filename));
627 return CheckDownloadFullPaths(browser, downloaded_file, origin_file); 629 return CheckDownloadFullPaths(browser, downloaded_file, origin_file);
628 } 630 }
629 631
630 // A version of CheckDownload that allows complete path specification. 632 // A version of CheckDownload that allows complete path specification.
631 bool CheckDownloadFullPaths(Browser* browser, 633 bool CheckDownloadFullPaths(Browser* browser,
632 const base::FilePath& downloaded_file, 634 const base::FilePath& downloaded_file,
633 const base::FilePath& origin_file) { 635 const base::FilePath& origin_file) {
636 base::ThreadRestrictions::ScopedAllowIO allow_io;
634 bool origin_file_exists = base::PathExists(origin_file); 637 bool origin_file_exists = base::PathExists(origin_file);
635 EXPECT_TRUE(origin_file_exists) << origin_file.value(); 638 EXPECT_TRUE(origin_file_exists) << origin_file.value();
636 if (!origin_file_exists) 639 if (!origin_file_exists)
637 return false; 640 return false;
638 641
639 // Confirm the downloaded data file exists. 642 // Confirm the downloaded data file exists.
640 bool downloaded_file_exists = base::PathExists(downloaded_file); 643 bool downloaded_file_exists = base::PathExists(downloaded_file);
641 EXPECT_TRUE(downloaded_file_exists) << downloaded_file.value(); 644 EXPECT_TRUE(downloaded_file_exists) << downloaded_file.value();
642 if (!downloaded_file_exists) 645 if (!downloaded_file_exists)
643 return false; 646 return false;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 new_item = *iter; 693 new_item = *iter;
691 } 694 }
692 } 695 }
693 return new_item; 696 return new_item;
694 } 697 }
695 698
696 bool RunSizeTest(Browser* browser, 699 bool RunSizeTest(Browser* browser,
697 SizeTestType type, 700 SizeTestType type,
698 const std::string& partial_indication, 701 const std::string& partial_indication,
699 const std::string& total_indication) { 702 const std::string& total_indication) {
703 base::ThreadRestrictions::ScopedAllowIO allow_io;
700 EXPECT_TRUE(type == SIZE_TEST_TYPE_UNKNOWN || type == SIZE_TEST_TYPE_KNOWN); 704 EXPECT_TRUE(type == SIZE_TEST_TYPE_UNKNOWN || type == SIZE_TEST_TYPE_KNOWN);
701 if (type != SIZE_TEST_TYPE_KNOWN && type != SIZE_TEST_TYPE_UNKNOWN) 705 if (type != SIZE_TEST_TYPE_KNOWN && type != SIZE_TEST_TYPE_UNKNOWN)
702 return false; 706 return false;
703 GURL url(type == SIZE_TEST_TYPE_KNOWN ? 707 GURL url(type == SIZE_TEST_TYPE_KNOWN ?
704 net::URLRequestSlowDownloadJob::kKnownSizeUrl : 708 net::URLRequestSlowDownloadJob::kKnownSizeUrl :
705 net::URLRequestSlowDownloadJob::kUnknownSizeUrl); 709 net::URLRequestSlowDownloadJob::kUnknownSizeUrl);
706 710
707 // TODO(ahendrickson) -- |expected_title_in_progress| and 711 // TODO(ahendrickson) -- |expected_title_in_progress| and
708 // |expected_title_finished| need to be checked. 712 // |expected_title_finished| need to be checked.
709 base::FilePath filename; 713 base::FilePath filename;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 return file_activity_observer_->TestAndResetDidShowFileChooser(); 789 return file_activity_observer_->TestAndResetDidShowFileChooser();
786 } 790 }
787 791
788 // Checks that |path| is has |file_size| bytes, and matches the |value| 792 // Checks that |path| is has |file_size| bytes, and matches the |value|
789 // string. 793 // string.
790 bool VerifyFile(const base::FilePath& path, 794 bool VerifyFile(const base::FilePath& path,
791 const std::string& value, 795 const std::string& value,
792 const int64_t file_size) { 796 const int64_t file_size) {
793 std::string file_contents; 797 std::string file_contents;
794 798
799 base::ThreadRestrictions::ScopedAllowIO allow_io;
795 bool read = base::ReadFileToString(path, &file_contents); 800 bool read = base::ReadFileToString(path, &file_contents);
796 EXPECT_TRUE(read) << "Failed reading file: " << path.value() << std::endl; 801 EXPECT_TRUE(read) << "Failed reading file: " << path.value() << std::endl;
797 if (!read) 802 if (!read)
798 return false; // Couldn't read the file. 803 return false; // Couldn't read the file.
799 804
800 // Note: we don't handle really large files (more than size_t can hold) 805 // Note: we don't handle really large files (more than size_t can hold)
801 // so we will fail in that case. 806 // so we will fail in that case.
802 size_t expected_size = static_cast<size_t>(file_size); 807 size_t expected_size = static_cast<size_t>(file_size);
803 808
804 // Check the size. 809 // Check the size.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 for (size_t d = 1; d < downloads_expected; ++d) { 925 for (size_t d = 1; d < downloads_expected; ++d) {
921 if (download_items[d]->GetStartTime() > item->GetStartTime()) 926 if (download_items[d]->GetStartTime() > item->GetStartTime())
922 item = download_items[d]; 927 item = download_items[d];
923 } 928 }
924 929
925 EXPECT_EQ(download_url, item->GetURL()); 930 EXPECT_EQ(download_url, item->GetURL());
926 EXPECT_EQ(download_info.reason, item->GetLastReason()); 931 EXPECT_EQ(download_info.reason, item->GetLastReason());
927 932
928 if (item->GetState() == content::DownloadItem::COMPLETE) { 933 if (item->GetState() == content::DownloadItem::COMPLETE) {
929 // Clean up the file, in case it ended up in the My Documents folder. 934 // Clean up the file, in case it ended up in the My Documents folder.
935 base::ThreadRestrictions::ScopedAllowIO allow_io;
930 base::FilePath destination_folder = GetDownloadDirectory(browser()); 936 base::FilePath destination_folder = GetDownloadDirectory(browser());
931 base::FilePath my_downloaded_file = item->GetTargetFilePath(); 937 base::FilePath my_downloaded_file = item->GetTargetFilePath();
932 EXPECT_TRUE(base::PathExists(my_downloaded_file)); 938 EXPECT_TRUE(base::PathExists(my_downloaded_file));
933 EXPECT_TRUE(base::DeleteFile(my_downloaded_file, false)); 939 EXPECT_TRUE(base::DeleteFile(my_downloaded_file, false));
934 940
935 EXPECT_EQ(download_info.should_redirect_to_documents ? 941 EXPECT_EQ(download_info.should_redirect_to_documents ?
936 std::string::npos : 942 std::string::npos :
937 0u, 943 0u,
938 my_downloaded_file.value().find(destination_folder.value())); 944 my_downloaded_file.value().find(destination_folder.value()));
939 if (download_info.should_redirect_to_documents) { 945 if (download_info.should_redirect_to_documents) {
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); 1199 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path));
1194 1200
1195 // Download the file and wait. We do not expect the Select File dialog. 1201 // Download the file and wait. We do not expect the Select File dialog.
1196 DownloadAndWait(browser(), url); 1202 DownloadAndWait(browser(), url);
1197 1203
1198 // Check state. Special file state must be checked before CheckDownload, 1204 // Check state. Special file state must be checked before CheckDownload,
1199 // as CheckDownload will delete the output file. 1205 // as CheckDownload will delete the output file.
1200 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 1206 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1201 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1207 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1202 base::FilePath downloaded_file(DestinationFile(browser(), file)); 1208 base::FilePath downloaded_file(DestinationFile(browser(), file));
1209 base::ThreadRestrictions::ScopedAllowIO allow_io;
1203 EXPECT_TRUE(content::IsFileQuarantined(downloaded_file, url, GURL())); 1210 EXPECT_TRUE(content::IsFileQuarantined(downloaded_file, url, GURL()));
1204 CheckDownload(browser(), file, file); 1211 CheckDownload(browser(), file, file);
1205 } 1212 }
1206 #endif 1213 #endif
1207 1214
1208 #if defined(OS_WIN) 1215 #if defined(OS_WIN)
1209 // A couple of Windows specific tests to make sure we respect OS specific 1216 // A couple of Windows specific tests to make sure we respect OS specific
1210 // restrictions on Mark-Of-The-Web can be applied. While Chrome doesn't directly 1217 // restrictions on Mark-Of-The-Web can be applied. While Chrome doesn't directly
1211 // apply these policies, Chrome still needs to make sure the correct APIs are 1218 // apply these policies, Chrome still needs to make sure the correct APIs are
1212 // invoked during the download process that result in the expected MOTW 1219 // invoked during the download process that result in the expected MOTW
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 // did not initiate. 1281 // did not initiate.
1275 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { 1282 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) {
1276 base::FilePath file(FILE_PATH_LITERAL("download-test2.html")); 1283 base::FilePath file(FILE_PATH_LITERAL("download-test2.html"));
1277 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test2.html")); 1284 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test2.html"));
1278 base::FilePath file_path(DestinationFile(browser(), file)); 1285 base::FilePath file_path(DestinationFile(browser(), file));
1279 1286
1280 // Open a web page and wait. 1287 // Open a web page and wait.
1281 ui_test_utils::NavigateToURL(browser(), url); 1288 ui_test_utils::NavigateToURL(browser(), url);
1282 1289
1283 // Check that we did not download the web page. 1290 // Check that we did not download the web page.
1291 base::ThreadRestrictions::ScopedAllowIO allow_io;
1284 EXPECT_FALSE(base::PathExists(file_path)); 1292 EXPECT_FALSE(base::PathExists(file_path));
1285 1293
1286 // Check state. 1294 // Check state.
1287 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 1295 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1288 EXPECT_TRUE(VerifyNoDownloads()); 1296 EXPECT_TRUE(VerifyNoDownloads());
1289 } 1297 }
1290 1298
1291 // EmbeddedTestServer::HandleRequestCallback function that returns the relative 1299 // EmbeddedTestServer::HandleRequestCallback function that returns the relative
1292 // URL as the MIME type. 1300 // URL as the MIME type.
1293 // E.g.: 1301 // E.g.:
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 1381 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
1374 browser()->tab_strip_model()->GetActiveWebContents(), 1382 browser()->tab_strip_model()->GetActiveWebContents(),
1375 "window.domAutomationController.send(startDownload());", 1383 "window.domAutomationController.send(startDownload());",
1376 &download_attempted)); 1384 &download_attempted));
1377 ASSERT_TRUE(download_attempted); 1385 ASSERT_TRUE(download_attempted);
1378 observer.Wait(); 1386 observer.Wait();
1379 1387
1380 // Check that we did not download the file. 1388 // Check that we did not download the file.
1381 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1389 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1382 base::FilePath file_path(DestinationFile(browser(), file)); 1390 base::FilePath file_path(DestinationFile(browser(), file));
1391 base::ThreadRestrictions::ScopedAllowIO allow_io;
1383 EXPECT_FALSE(base::PathExists(file_path)); 1392 EXPECT_FALSE(base::PathExists(file_path));
1384 1393
1385 // Check state. 1394 // Check state.
1386 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 1395 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1387 1396
1388 // Verify that there's no pending download. The resource throttle 1397 // Verify that there's no pending download. The resource throttle
1389 // should have deleted it before it created a download item, so it 1398 // should have deleted it before it created a download item, so it
1390 // shouldn't be available as a cancelled download either. 1399 // shouldn't be available as a cancelled download either.
1391 EXPECT_TRUE(VerifyNoDownloads()); 1400 EXPECT_TRUE(VerifyNoDownloads());
1392 } 1401 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 // that the filename is deduplicated. The previous test tests for a specific 1480 // that the filename is deduplicated. The previous test tests for a specific
1472 // bug; this next test tests that filename deduplication happens independently 1481 // bug; this next test tests that filename deduplication happens independently
1473 // of DownloadManager/CDMD. 1482 // of DownloadManager/CDMD.
1474 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_IncognitoRegular) { 1483 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_IncognitoRegular) {
1475 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("downloads/a_zip_file.zip"); 1484 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("downloads/a_zip_file.zip");
1476 1485
1477 // Read the origin file now so that we can compare the downloaded files to it 1486 // Read the origin file now so that we can compare the downloaded files to it
1478 // later. 1487 // later.
1479 base::FilePath origin(OriginFile(base::FilePath(FILE_PATH_LITERAL( 1488 base::FilePath origin(OriginFile(base::FilePath(FILE_PATH_LITERAL(
1480 "downloads/a_zip_file.zip")))); 1489 "downloads/a_zip_file.zip"))));
1490 base::ThreadRestrictions::ScopedAllowIO allow_io;
1481 ASSERT_TRUE(base::PathExists(origin)); 1491 ASSERT_TRUE(base::PathExists(origin));
1482 int64_t origin_file_size = 0; 1492 int64_t origin_file_size = 0;
1483 EXPECT_TRUE(base::GetFileSize(origin, &origin_file_size)); 1493 EXPECT_TRUE(base::GetFileSize(origin, &origin_file_size));
1484 std::string original_contents; 1494 std::string original_contents;
1485 EXPECT_TRUE(base::ReadFileToString(origin, &original_contents)); 1495 EXPECT_TRUE(base::ReadFileToString(origin, &original_contents));
1486 1496
1487 std::vector<DownloadItem*> download_items; 1497 std::vector<DownloadItem*> download_items;
1488 GetDownloads(browser(), &download_items); 1498 GetDownloads(browser(), &download_items);
1489 ASSERT_TRUE(download_items.empty()); 1499 ASSERT_TRUE(download_items.empty());
1490 1500
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1975 std::unique_ptr<content::DownloadTestObserver> observer( 1985 std::unique_ptr<content::DownloadTestObserver> observer(
1976 CreateWaiter(browser(), 1)); 1986 CreateWaiter(browser(), 1));
1977 ui_test_utils::NavigateToURL(browser(), url); 1987 ui_test_utils::NavigateToURL(browser(), url);
1978 observer->WaitForFinished(); 1988 observer->WaitForFinished();
1979 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1989 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1980 CheckDownloadStates(1, DownloadItem::COMPLETE); 1990 CheckDownloadStates(1, DownloadItem::COMPLETE);
1981 1991
1982 // Confirm the downloaded data exists. 1992 // Confirm the downloaded data exists.
1983 base::FilePath downloaded_file = GetDownloadDirectory(browser()); 1993 base::FilePath downloaded_file = GetDownloadDirectory(browser());
1984 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); 1994 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png"));
1995 base::ThreadRestrictions::ScopedAllowIO allow_io;
1985 EXPECT_TRUE(base::PathExists(downloaded_file)); 1996 EXPECT_TRUE(base::PathExists(downloaded_file));
1986 } 1997 }
1987 1998
1988 // Test to make sure auto-open works. 1999 // Test to make sure auto-open works.
1989 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { 2000 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) {
1990 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); 2001 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt"));
1991 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-autoopen.txt")); 2002 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-autoopen.txt"));
1992 2003
1993 ASSERT_TRUE( 2004 ASSERT_TRUE(
1994 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); 2005 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file));
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2197 ASSERT_TRUE(CheckDownload(browser(), file, file)); 2208 ASSERT_TRUE(CheckDownload(browser(), file, file));
2198 } 2209 }
2199 2210
2200 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { 2211 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
2201 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); 2212 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path));
2202 2213
2203 WebContents* web_contents = 2214 WebContents* web_contents =
2204 browser()->tab_strip_model()->GetActiveWebContents(); 2215 browser()->tab_strip_model()->GetActiveWebContents();
2205 ASSERT_TRUE(web_contents); 2216 ASSERT_TRUE(web_contents);
2206 2217
2218 base::ThreadRestrictions::ScopedAllowIO allow_io;
2207 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 2219 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
2208 base::ScopedTempDir other_directory; 2220 base::ScopedTempDir other_directory;
2209 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 2221 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
2210 base::FilePath target_file_full_path = 2222 base::FilePath target_file_full_path =
2211 other_directory.GetPath().Append(file.BaseName()); 2223 other_directory.GetPath().Append(file.BaseName());
2212 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 2224 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1));
2213 std::unique_ptr<DownloadUrlParameters> params( 2225 std::unique_ptr<DownloadUrlParameters> params(
2214 DownloadUrlParameters::CreateForWebContentsMainFrame( 2226 DownloadUrlParameters::CreateForWebContentsMainFrame(
2215 web_contents, url)); 2227 web_contents, url));
2216 params->set_file_path(target_file_full_path); 2228 params->set_file_path(target_file_full_path);
(...skipping 16 matching lines...) Expand all
2233 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); 2245 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent();
2234 } 2246 }
2235 2247
2236 IN_PROC_BROWSER_TEST_F(DownloadTest, TransientDownload) { 2248 IN_PROC_BROWSER_TEST_F(DownloadTest, TransientDownload) {
2237 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); 2249 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path));
2238 2250
2239 WebContents* web_contents = 2251 WebContents* web_contents =
2240 browser()->tab_strip_model()->GetActiveWebContents(); 2252 browser()->tab_strip_model()->GetActiveWebContents();
2241 ASSERT_TRUE(web_contents); 2253 ASSERT_TRUE(web_contents);
2242 2254
2255 base::ThreadRestrictions::ScopedAllowIO allow_io;
2243 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 2256 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
2244 base::ScopedTempDir other_directory; 2257 base::ScopedTempDir other_directory;
2245 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 2258 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
2246 base::FilePath target_file_full_path = 2259 base::FilePath target_file_full_path =
2247 other_directory.GetPath().Append(file.BaseName()); 2260 other_directory.GetPath().Append(file.BaseName());
2248 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 2261 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1));
2249 std::unique_ptr<DownloadUrlParameters> params( 2262 std::unique_ptr<DownloadUrlParameters> params(
2250 DownloadUrlParameters::CreateForWebContentsMainFrame(web_contents, url)); 2263 DownloadUrlParameters::CreateForWebContentsMainFrame(web_contents, url));
2251 params->set_file_path(target_file_full_path); 2264 params->set_file_path(target_file_full_path);
2252 params->set_transient(true); 2265 params->set_transient(true);
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
2924 browser()->tab_strip_model()->GetActiveWebContents()->Close(); 2937 browser()->tab_strip_model()->GetActiveWebContents()->Close();
2925 g_browser_process->notification_ui_manager()->CancelAll(); 2938 g_browser_process->notification_ui_manager()->CancelAll();
2926 } 2939 }
2927 #endif 2940 #endif
2928 2941
2929 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_Renaming) { 2942 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_Renaming) {
2930 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("downloads/a_zip_file.zip"); 2943 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("downloads/a_zip_file.zip");
2931 content::DownloadManager* manager = DownloadManagerForBrowser(browser()); 2944 content::DownloadManager* manager = DownloadManagerForBrowser(browser());
2932 base::FilePath origin_file(OriginFile(base::FilePath(FILE_PATH_LITERAL( 2945 base::FilePath origin_file(OriginFile(base::FilePath(FILE_PATH_LITERAL(
2933 "downloads/a_zip_file.zip")))); 2946 "downloads/a_zip_file.zip"))));
2947 base::ThreadRestrictions::ScopedAllowIO allow_io;
2934 ASSERT_TRUE(base::PathExists(origin_file)); 2948 ASSERT_TRUE(base::PathExists(origin_file));
2935 std::string origin_contents; 2949 std::string origin_contents;
2936 ASSERT_TRUE(base::ReadFileToString(origin_file, &origin_contents)); 2950 ASSERT_TRUE(base::ReadFileToString(origin_file, &origin_contents));
2937 2951
2938 // Download the same url several times and expect that all downloaded files 2952 // Download the same url several times and expect that all downloaded files
2939 // after the zero-th contain a deduplication counter. 2953 // after the zero-th contain a deduplication counter.
2940 for (int index = 0; index < 5; ++index) { 2954 for (int index = 0; index < 5; ++index) {
2941 DownloadAndWait(browser(), url); 2955 DownloadAndWait(browser(), url);
2942 content::DownloadItem* item = manager->GetDownload( 2956 content::DownloadItem* item = manager->GetDownload(
2943 content::DownloadItem::kInvalidId + 1 + index); 2957 content::DownloadItem::kInvalidId + 1 + index);
2944 ASSERT_TRUE(item); 2958 ASSERT_TRUE(item);
2945 ASSERT_EQ(DownloadItem::COMPLETE, item->GetState()); 2959 ASSERT_EQ(DownloadItem::COMPLETE, item->GetState());
2946 base::FilePath target_path(item->GetTargetFilePath()); 2960 base::FilePath target_path(item->GetTargetFilePath());
2947 EXPECT_EQ(std::string("a_zip_file") + 2961 EXPECT_EQ(std::string("a_zip_file") +
2948 (index == 0 ? std::string(".zip") : 2962 (index == 0 ? std::string(".zip") :
2949 base::StringPrintf(" (%d).zip", index)), 2963 base::StringPrintf(" (%d).zip", index)),
2950 target_path.BaseName().AsUTF8Unsafe()); 2964 target_path.BaseName().AsUTF8Unsafe());
2965 base::ThreadRestrictions::ScopedAllowIO allow_io;
2951 ASSERT_TRUE(base::PathExists(target_path)); 2966 ASSERT_TRUE(base::PathExists(target_path));
2952 ASSERT_TRUE(VerifyFile(target_path, origin_contents, 2967 ASSERT_TRUE(VerifyFile(target_path, origin_contents,
2953 origin_contents.size())); 2968 origin_contents.size()));
2954 } 2969 }
2955 } 2970 }
2956 2971
2957 // Test that the entire download pipeline handles unicode correctly. 2972 // Test that the entire download pipeline handles unicode correctly.
2958 // Disabled on Windows due to flaky timeouts: crbug.com/446695 2973 // Disabled on Windows due to flaky timeouts: crbug.com/446695
2959 // Disabled on chromeos due to flaky crash: crbug.com/577332 2974 // Disabled on chromeos due to flaky crash: crbug.com/577332
2960 #if defined(OS_WIN) || defined(OS_CHROMEOS) 2975 #if defined(OS_WIN) || defined(OS_CHROMEOS)
(...skipping 19 matching lines...) Expand all
2980 // korean 2995 // korean
2981 L"\u97d3-\u4e2d \uc815\uc0c1, \ucc9c\uc548\ud568 \uc758\uacac.zip", 2996 L"\u97d3-\u4e2d \uc815\uc0c1, \ucc9c\uc548\ud568 \uc758\uacac.zip",
2982 L"jiho....tiho...miho.zip", 2997 L"jiho....tiho...miho.zip",
2983 L"jiho!@#$tiho$%^&-()_+=miho copy.zip", // special chars 2998 L"jiho!@#$tiho$%^&-()_+=miho copy.zip", // special chars
2984 L"Wohoo-to hoo+I.zip", 2999 L"Wohoo-to hoo+I.zip",
2985 L"Picture 1.zip", 3000 L"Picture 1.zip",
2986 L"This is a very very long english sentence with spaces and , and +.zip", 3001 L"This is a very very long english sentence with spaces and , and +.zip",
2987 }; 3002 };
2988 3003
2989 std::vector<DownloadItem*> download_items; 3004 std::vector<DownloadItem*> download_items;
3005 base::ThreadRestrictions::ScopedAllowIO allow_io;
2990 base::FilePath origin_directory = 3006 base::FilePath origin_directory =
2991 GetDownloadDirectory(browser()).Append(FILE_PATH_LITERAL("origin")); 3007 GetDownloadDirectory(browser()).Append(FILE_PATH_LITERAL("origin"));
2992 ASSERT_TRUE(base::CreateDirectory(origin_directory)); 3008 ASSERT_TRUE(base::CreateDirectory(origin_directory));
2993 3009
2994 for (size_t index = 0; index < arraysize(kCrazyFilenames); ++index) { 3010 for (size_t index = 0; index < arraysize(kCrazyFilenames); ++index) {
2995 SCOPED_TRACE(testing::Message() << "Index " << index); 3011 SCOPED_TRACE(testing::Message() << "Index " << index);
2996 base::string16 crazy16; 3012 base::string16 crazy16;
2997 std::string crazy8; 3013 std::string crazy8;
2998 const wchar_t* crazy_w = kCrazyFilenames[index]; 3014 const wchar_t* crazy_w = kCrazyFilenames[index];
2999 ASSERT_TRUE(base::WideToUTF8(crazy_w, wcslen(crazy_w), &crazy8)); 3015 ASSERT_TRUE(base::WideToUTF8(crazy_w, wcslen(crazy_w), &crazy8));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3077 // Disable on mac: http://crbug.com/238831 3093 // Disable on mac: http://crbug.com/238831
3078 #define MAYBE_DownloadTest_PercentComplete DISABLED_DownloadTest_PercentComplete 3094 #define MAYBE_DownloadTest_PercentComplete DISABLED_DownloadTest_PercentComplete
3079 #else 3095 #else
3080 #define MAYBE_DownloadTest_PercentComplete DownloadTest_PercentComplete 3096 #define MAYBE_DownloadTest_PercentComplete DownloadTest_PercentComplete
3081 #endif 3097 #endif
3082 IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_DownloadTest_PercentComplete) { 3098 IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_DownloadTest_PercentComplete) {
3083 // Write a huge file. 3099 // Write a huge file.
3084 base::FilePath file_path( 3100 base::FilePath file_path(
3085 GetDownloadDirectory(browser()).AppendASCII("source").AppendASCII( 3101 GetDownloadDirectory(browser()).AppendASCII("source").AppendASCII(
3086 "DownloadTest_BigZip.zip")); 3102 "DownloadTest_BigZip.zip"));
3087 ASSERT_TRUE(CreateDirectory(file_path.DirName()));
3088 base::File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_WRITE);
3089 ASSERT_TRUE(file.IsValid());
3090 int64_t size = 1 << 25; 3103 int64_t size = 1 << 25;
3091 EXPECT_EQ(1, file.Write(size, "a", 1)); 3104 {
3092 file.Close(); 3105 base::ThreadRestrictions::ScopedAllowIO allow_io;
3106 ASSERT_TRUE(CreateDirectory(file_path.DirName()));
3107 base::File file(file_path,
3108 base::File::FLAG_CREATE | base::File::FLAG_WRITE);
3109 ASSERT_TRUE(file.IsValid());
3110 EXPECT_EQ(1, file.Write(size, "a", 1));
3111 file.Close();
3093 3112
3094 #if defined(OS_POSIX) 3113 #if defined(OS_POSIX)
3095 // Make it readable by chronos on chromeos 3114 // Make it readable by chronos on chromeos
3096 base::SetPosixFilePermissions(file_path, 0755); 3115 base::SetPosixFilePermissions(file_path, 0755);
3097 #endif 3116 #endif
3098 3117
3099 // Ensure that we have enough disk space. 3118 // Ensure that we have enough disk space.
3100 int64_t free_space = 3119 int64_t free_space =
3101 base::SysInfo::AmountOfFreeDiskSpace(GetDownloadDirectory(browser())); 3120 base::SysInfo::AmountOfFreeDiskSpace(GetDownloadDirectory(browser()));
3102 ASSERT_LE(size, free_space) << "Not enough disk space to download. Got " 3121 ASSERT_LE(size, free_space)
3103 << free_space; 3122 << "Not enough disk space to download. Got " << free_space;
3123 }
3104 GURL file_url(net::FilePathToFileURL(file_path)); 3124 GURL file_url(net::FilePathToFileURL(file_path));
3105 std::unique_ptr<content::DownloadTestObserver> progress_waiter( 3125 std::unique_ptr<content::DownloadTestObserver> progress_waiter(
3106 CreateInProgressWaiter(browser(), 1)); 3126 CreateInProgressWaiter(browser(), 1));
3107 3127
3108 // Start downloading a file, wait for it to be created. 3128 // Start downloading a file, wait for it to be created.
3109 ui_test_utils::NavigateToURLWithDisposition( 3129 ui_test_utils::NavigateToURLWithDisposition(
3110 browser(), file_url, WindowOpenDisposition::CURRENT_TAB, 3130 browser(), file_url, WindowOpenDisposition::CURRENT_TAB,
3111 ui_test_utils::BROWSER_TEST_NONE); 3131 ui_test_utils::BROWSER_TEST_NONE);
3112 progress_waiter->WaitForFinished(); 3132 progress_waiter->WaitForFinished();
3113 EXPECT_EQ(1u, progress_waiter->NumDownloadsSeenInState( 3133 EXPECT_EQ(1u, progress_waiter->NumDownloadsSeenInState(
3114 DownloadItem::IN_PROGRESS)); 3134 DownloadItem::IN_PROGRESS));
3115 std::vector<DownloadItem*> download_items; 3135 std::vector<DownloadItem*> download_items;
3116 GetDownloads(browser(), &download_items); 3136 GetDownloads(browser(), &download_items);
3117 ASSERT_EQ(1UL, download_items.size()); 3137 ASSERT_EQ(1UL, download_items.size());
3118 3138
3119 // Wait for the download to complete, checking along the way that the 3139 // Wait for the download to complete, checking along the way that the
3120 // PercentComplete() never regresses. 3140 // PercentComplete() never regresses.
3121 PercentWaiter waiter(download_items[0]); 3141 PercentWaiter waiter(download_items[0]);
3122 EXPECT_TRUE(waiter.WaitForFinished()); 3142 EXPECT_TRUE(waiter.WaitForFinished());
3123 EXPECT_EQ(DownloadItem::COMPLETE, download_items[0]->GetState()); 3143 EXPECT_EQ(DownloadItem::COMPLETE, download_items[0]->GetState());
3124 ASSERT_EQ(100, download_items[0]->PercentComplete()); 3144 ASSERT_EQ(100, download_items[0]->PercentComplete());
3125 3145
3126 // Check that the file downloaded correctly. 3146 // Check that the file downloaded correctly.
3147 base::ThreadRestrictions::ScopedAllowIO allow_io;
3127 ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath())); 3148 ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath()));
3128 int64_t downloaded_size = 0; 3149 int64_t downloaded_size = 0;
3129 ASSERT_TRUE(base::GetFileSize( 3150 ASSERT_TRUE(base::GetFileSize(
3130 download_items[0]->GetTargetFilePath(), &downloaded_size)); 3151 download_items[0]->GetTargetFilePath(), &downloaded_size));
3131 ASSERT_EQ(size + 1, downloaded_size); 3152 ASSERT_EQ(size + 1, downloaded_size);
3132 ASSERT_TRUE(base::DieFileDie(file_path, false)); 3153 ASSERT_TRUE(base::DieFileDie(file_path, false));
3133 ASSERT_TRUE(base::DieFileDie(download_items[0]->GetTargetFilePath(), false)); 3154 ASSERT_TRUE(base::DieFileDie(download_items[0]->GetTargetFilePath(), false));
3134 } 3155 }
3135 3156
3136 // A download that is interrupted due to a file error should be able to be 3157 // A download that is interrupted due to a file error should be able to be
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
3527 3548
3528 // Begin feedback and check that file is still there. 3549 // Begin feedback and check that file is still there.
3529 download_protection_service->feedback_service()->BeginFeedbackForDownload( 3550 download_protection_service->feedback_service()->BeginFeedbackForDownload(
3530 downloads[0], DownloadCommands::KEEP); 3551 downloads[0], DownloadCommands::KEEP);
3531 completion_observer->WaitForFinished(); 3552 completion_observer->WaitForFinished();
3532 3553
3533 std::vector<DownloadItem*> updated_downloads; 3554 std::vector<DownloadItem*> updated_downloads;
3534 GetDownloads(browser(), &updated_downloads); 3555 GetDownloads(browser(), &updated_downloads);
3535 ASSERT_EQ(std::size_t(1), updated_downloads.size()); 3556 ASSERT_EQ(std::size_t(1), updated_downloads.size());
3536 ASSERT_FALSE(updated_downloads[0]->IsDangerous()); 3557 ASSERT_FALSE(updated_downloads[0]->IsDangerous());
3558 base::ThreadRestrictions::ScopedAllowIO allow_io;
3537 ASSERT_TRUE(PathExists(updated_downloads[0]->GetTargetFilePath())); 3559 ASSERT_TRUE(PathExists(updated_downloads[0]->GetTargetFilePath()));
3538 updated_downloads[0]->Cancel(true); 3560 updated_downloads[0]->Cancel(true);
3539 } 3561 }
3540 3562
3541 IN_PROC_BROWSER_TEST_F(DownloadTestWithFakeSafeBrowsing, 3563 IN_PROC_BROWSER_TEST_F(DownloadTestWithFakeSafeBrowsing,
3542 SendUncommonDownloadReportIfUserProceed) { 3564 SendUncommonDownloadReportIfUserProceed) {
3543 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, 3565 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled,
3544 true); 3566 true);
3545 // Make a dangerous file. 3567 // Make a dangerous file.
3546 GURL download_url( 3568 GURL download_url(
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
3843 browser(), 1, 3865 browser(), 1,
3844 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 3866 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
3845 ui_test_utils::NavigateToURL(browser(), extension_url); 3867 ui_test_utils::NavigateToURL(browser(), extension_url);
3846 3868
3847 observer->WaitForFinished(); 3869 observer->WaitForFinished();
3848 3870
3849 // Download shelf should close. 3871 // Download shelf should close.
3850 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 3872 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3851 } 3873 }
3852 #endif // defined(OS_CHROMEOS) 3874 #endif // defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « chrome/browser/downgrade/user_data_downgrade_browsertest.cc ('k') | chrome/browser/download/save_page_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698