OLD | NEW |
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 <stdint.h> |
| 6 |
5 #include <sstream> | 7 #include <sstream> |
6 | 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
10 #include "base/feature_list.h" | 12 #include "base/feature_list.h" |
11 #include "base/files/file.h" | 13 #include "base/files/file.h" |
12 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
14 #include "base/files/scoped_temp_dir.h" | 16 #include "base/files/scoped_temp_dir.h" |
| 17 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
16 #include "base/path_service.h" | 19 #include "base/path_service.h" |
17 #include "base/prefs/pref_service.h" | 20 #include "base/prefs/pref_service.h" |
18 #include "base/stl_util.h" | 21 #include "base/stl_util.h" |
19 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_split.h" | 23 #include "base/strings/string_split.h" |
21 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
22 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
23 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
24 #include "base/sys_info.h" | 27 #include "base/sys_info.h" |
25 #include "base/test/test_file_util.h" | 28 #include "base/test/test_file_util.h" |
| 29 #include "build/build_config.h" |
26 #include "chrome/app/chrome_command_ids.h" | 30 #include "chrome/app/chrome_command_ids.h" |
27 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
28 #include "chrome/browser/chrome_notification_types.h" | 32 #include "chrome/browser/chrome_notification_types.h" |
29 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 33 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
30 #include "chrome/browser/download/download_browsertest.h" | 34 #include "chrome/browser/download/download_browsertest.h" |
31 #include "chrome/browser/download/download_crx_util.h" | 35 #include "chrome/browser/download/download_crx_util.h" |
32 #include "chrome/browser/download/download_history.h" | 36 #include "chrome/browser/download/download_history.h" |
33 #include "chrome/browser/download/download_item_model.h" | 37 #include "chrome/browser/download/download_item_model.h" |
34 #include "chrome/browser/download/download_prefs.h" | 38 #include "chrome/browser/download/download_prefs.h" |
35 #include "chrome/browser/download/download_request_limiter.h" | 39 #include "chrome/browser/download/download_request_limiter.h" |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 EXPECT_TRUE(origin_file_exists) << origin_file.value(); | 636 EXPECT_TRUE(origin_file_exists) << origin_file.value(); |
633 if (!origin_file_exists) | 637 if (!origin_file_exists) |
634 return false; | 638 return false; |
635 | 639 |
636 // Confirm the downloaded data file exists. | 640 // Confirm the downloaded data file exists. |
637 bool downloaded_file_exists = base::PathExists(downloaded_file); | 641 bool downloaded_file_exists = base::PathExists(downloaded_file); |
638 EXPECT_TRUE(downloaded_file_exists) << downloaded_file.value(); | 642 EXPECT_TRUE(downloaded_file_exists) << downloaded_file.value(); |
639 if (!downloaded_file_exists) | 643 if (!downloaded_file_exists) |
640 return false; | 644 return false; |
641 | 645 |
642 int64 origin_file_size = 0; | 646 int64_t origin_file_size = 0; |
643 EXPECT_TRUE(base::GetFileSize(origin_file, &origin_file_size)); | 647 EXPECT_TRUE(base::GetFileSize(origin_file, &origin_file_size)); |
644 std::string original_file_contents; | 648 std::string original_file_contents; |
645 EXPECT_TRUE(base::ReadFileToString(origin_file, &original_file_contents)); | 649 EXPECT_TRUE(base::ReadFileToString(origin_file, &original_file_contents)); |
646 EXPECT_TRUE( | 650 EXPECT_TRUE( |
647 VerifyFile(downloaded_file, original_file_contents, origin_file_size)); | 651 VerifyFile(downloaded_file, original_file_contents, origin_file_size)); |
648 | 652 |
649 // Delete the downloaded copy of the file. | 653 // Delete the downloaded copy of the file. |
650 bool downloaded_file_deleted = base::DieFileDie(downloaded_file, false); | 654 bool downloaded_file_deleted = base::DieFileDie(downloaded_file, false); |
651 EXPECT_TRUE(downloaded_file_deleted); | 655 EXPECT_TRUE(downloaded_file_deleted); |
652 return downloaded_file_deleted; | 656 return downloaded_file_deleted; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 } | 785 } |
782 | 786 |
783 bool DidShowFileChooser() { | 787 bool DidShowFileChooser() { |
784 return file_activity_observer_->TestAndResetDidShowFileChooser(); | 788 return file_activity_observer_->TestAndResetDidShowFileChooser(); |
785 } | 789 } |
786 | 790 |
787 // Checks that |path| is has |file_size| bytes, and matches the |value| | 791 // Checks that |path| is has |file_size| bytes, and matches the |value| |
788 // string. | 792 // string. |
789 bool VerifyFile(const base::FilePath& path, | 793 bool VerifyFile(const base::FilePath& path, |
790 const std::string& value, | 794 const std::string& value, |
791 const int64 file_size) { | 795 const int64_t file_size) { |
792 std::string file_contents; | 796 std::string file_contents; |
793 | 797 |
794 bool read = base::ReadFileToString(path, &file_contents); | 798 bool read = base::ReadFileToString(path, &file_contents); |
795 EXPECT_TRUE(read) << "Failed reading file: " << path.value() << std::endl; | 799 EXPECT_TRUE(read) << "Failed reading file: " << path.value() << std::endl; |
796 if (!read) | 800 if (!read) |
797 return false; // Couldn't read the file. | 801 return false; // Couldn't read the file. |
798 | 802 |
799 // Note: we don't handle really large files (more than size_t can hold) | 803 // Note: we don't handle really large files (more than size_t can hold) |
800 // so we will fail in that case. | 804 // so we will fail in that case. |
801 size_t expected_size = static_cast<size_t>(file_size); | 805 size_t expected_size = static_cast<size_t>(file_size); |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 // bug; this next test tests that filename deduplication happens independently | 1360 // bug; this next test tests that filename deduplication happens independently |
1357 // of DownloadManager/CDMD. | 1361 // of DownloadManager/CDMD. |
1358 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_IncognitoRegular) { | 1362 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_IncognitoRegular) { |
1359 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("downloads/a_zip_file.zip"); | 1363 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("downloads/a_zip_file.zip"); |
1360 | 1364 |
1361 // Read the origin file now so that we can compare the downloaded files to it | 1365 // Read the origin file now so that we can compare the downloaded files to it |
1362 // later. | 1366 // later. |
1363 base::FilePath origin(OriginFile(base::FilePath(FILE_PATH_LITERAL( | 1367 base::FilePath origin(OriginFile(base::FilePath(FILE_PATH_LITERAL( |
1364 "downloads/a_zip_file.zip")))); | 1368 "downloads/a_zip_file.zip")))); |
1365 ASSERT_TRUE(base::PathExists(origin)); | 1369 ASSERT_TRUE(base::PathExists(origin)); |
1366 int64 origin_file_size = 0; | 1370 int64_t origin_file_size = 0; |
1367 EXPECT_TRUE(base::GetFileSize(origin, &origin_file_size)); | 1371 EXPECT_TRUE(base::GetFileSize(origin, &origin_file_size)); |
1368 std::string original_contents; | 1372 std::string original_contents; |
1369 EXPECT_TRUE(base::ReadFileToString(origin, &original_contents)); | 1373 EXPECT_TRUE(base::ReadFileToString(origin, &original_contents)); |
1370 | 1374 |
1371 std::vector<DownloadItem*> download_items; | 1375 std::vector<DownloadItem*> download_items; |
1372 GetDownloads(browser(), &download_items); | 1376 GetDownloads(browser(), &download_items); |
1373 ASSERT_TRUE(download_items.empty()); | 1377 ASSERT_TRUE(download_items.empty()); |
1374 | 1378 |
1375 // Download a file in the on-record browser and check that it was downloaded | 1379 // Download a file in the on-record browser and check that it was downloaded |
1376 // correctly. | 1380 // correctly. |
(...skipping 1600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2977 #define MAYBE_DownloadTest_PercentComplete DISABLED_DownloadTest_PercentComplete | 2981 #define MAYBE_DownloadTest_PercentComplete DISABLED_DownloadTest_PercentComplete |
2978 #else | 2982 #else |
2979 #define MAYBE_DownloadTest_PercentComplete DownloadTest_PercentComplete | 2983 #define MAYBE_DownloadTest_PercentComplete DownloadTest_PercentComplete |
2980 #endif | 2984 #endif |
2981 IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_DownloadTest_PercentComplete) { | 2985 IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_DownloadTest_PercentComplete) { |
2982 // Write a huge file. | 2986 // Write a huge file. |
2983 base::FilePath file_path(DestinationFile( | 2987 base::FilePath file_path(DestinationFile( |
2984 browser(), base::FilePath(FILE_PATH_LITERAL("DownloadTest_BigZip.zip")))); | 2988 browser(), base::FilePath(FILE_PATH_LITERAL("DownloadTest_BigZip.zip")))); |
2985 base::File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_WRITE); | 2989 base::File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_WRITE); |
2986 ASSERT_TRUE(file.IsValid()); | 2990 ASSERT_TRUE(file.IsValid()); |
2987 int64 size = 1 << 25; | 2991 int64_t size = 1 << 25; |
2988 EXPECT_EQ(1, file.Write(size, "a", 1)); | 2992 EXPECT_EQ(1, file.Write(size, "a", 1)); |
2989 file.Close(); | 2993 file.Close(); |
2990 | 2994 |
2991 #if defined(OS_POSIX) | 2995 #if defined(OS_POSIX) |
2992 // Make it readable by chronos on chromeos | 2996 // Make it readable by chronos on chromeos |
2993 base::SetPosixFilePermissions(file_path, 0755); | 2997 base::SetPosixFilePermissions(file_path, 0755); |
2994 #endif | 2998 #endif |
2995 | 2999 |
2996 // Ensure that we have enough disk space. | 3000 // Ensure that we have enough disk space. |
2997 int64 free_space = base::SysInfo::AmountOfFreeDiskSpace( | 3001 int64_t free_space = |
2998 GetDownloadDirectory(browser())); | 3002 base::SysInfo::AmountOfFreeDiskSpace(GetDownloadDirectory(browser())); |
2999 ASSERT_LE(size, free_space) << "Not enough disk space to download. Got " | 3003 ASSERT_LE(size, free_space) << "Not enough disk space to download. Got " |
3000 << free_space; | 3004 << free_space; |
3001 GURL file_url(net::FilePathToFileURL(file_path)); | 3005 GURL file_url(net::FilePathToFileURL(file_path)); |
3002 scoped_ptr<content::DownloadTestObserver> progress_waiter( | 3006 scoped_ptr<content::DownloadTestObserver> progress_waiter( |
3003 CreateInProgressWaiter(browser(), 1)); | 3007 CreateInProgressWaiter(browser(), 1)); |
3004 | 3008 |
3005 // Start downloading a file, wait for it to be created. | 3009 // Start downloading a file, wait for it to be created. |
3006 ui_test_utils::NavigateToURLWithDisposition( | 3010 ui_test_utils::NavigateToURLWithDisposition( |
3007 browser(), file_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | 3011 browser(), file_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); |
3008 progress_waiter->WaitForFinished(); | 3012 progress_waiter->WaitForFinished(); |
3009 EXPECT_EQ(1u, progress_waiter->NumDownloadsSeenInState( | 3013 EXPECT_EQ(1u, progress_waiter->NumDownloadsSeenInState( |
3010 DownloadItem::IN_PROGRESS)); | 3014 DownloadItem::IN_PROGRESS)); |
3011 std::vector<DownloadItem*> download_items; | 3015 std::vector<DownloadItem*> download_items; |
3012 GetDownloads(browser(), &download_items); | 3016 GetDownloads(browser(), &download_items); |
3013 ASSERT_EQ(1UL, download_items.size()); | 3017 ASSERT_EQ(1UL, download_items.size()); |
3014 | 3018 |
3015 // Wait for the download to complete, checking along the way that the | 3019 // Wait for the download to complete, checking along the way that the |
3016 // PercentComplete() never regresses. | 3020 // PercentComplete() never regresses. |
3017 PercentWaiter waiter(download_items[0]); | 3021 PercentWaiter waiter(download_items[0]); |
3018 EXPECT_TRUE(waiter.WaitForFinished()); | 3022 EXPECT_TRUE(waiter.WaitForFinished()); |
3019 EXPECT_EQ(DownloadItem::COMPLETE, download_items[0]->GetState()); | 3023 EXPECT_EQ(DownloadItem::COMPLETE, download_items[0]->GetState()); |
3020 ASSERT_EQ(100, download_items[0]->PercentComplete()); | 3024 ASSERT_EQ(100, download_items[0]->PercentComplete()); |
3021 | 3025 |
3022 // Check that the file downloaded correctly. | 3026 // Check that the file downloaded correctly. |
3023 ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath())); | 3027 ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath())); |
3024 int64 downloaded_size = 0; | 3028 int64_t downloaded_size = 0; |
3025 ASSERT_TRUE(base::GetFileSize( | 3029 ASSERT_TRUE(base::GetFileSize( |
3026 download_items[0]->GetTargetFilePath(), &downloaded_size)); | 3030 download_items[0]->GetTargetFilePath(), &downloaded_size)); |
3027 ASSERT_EQ(size + 1, downloaded_size); | 3031 ASSERT_EQ(size + 1, downloaded_size); |
3028 ASSERT_TRUE(base::DieFileDie(file_path, false)); | 3032 ASSERT_TRUE(base::DieFileDie(file_path, false)); |
3029 ASSERT_TRUE(base::DieFileDie(download_items[0]->GetTargetFilePath(), false)); | 3033 ASSERT_TRUE(base::DieFileDie(download_items[0]->GetTargetFilePath(), false)); |
3030 } | 3034 } |
3031 | 3035 |
3032 // A download that is interrupted due to a file error should be able to be | 3036 // A download that is interrupted due to a file error should be able to be |
3033 // resumed. | 3037 // resumed. |
3034 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_NoPrompt) { | 3038 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_NoPrompt) { |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3633 | 3637 |
3634 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( | 3638 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( |
3635 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 3639 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
3636 ui_test_utils::NavigateToURL(browser(), extension_url); | 3640 ui_test_utils::NavigateToURL(browser(), extension_url); |
3637 | 3641 |
3638 observer->WaitForFinished(); | 3642 observer->WaitForFinished(); |
3639 | 3643 |
3640 // Download shelf should close. | 3644 // Download shelf should close. |
3641 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3645 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
3642 } | 3646 } |
OLD | NEW |