| 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 <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 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 | 672 |
| 673 // Confirm the downloaded data file exists. | 673 // Confirm the downloaded data file exists. |
| 674 bool downloaded_file_exists = base::PathExists(downloaded_file); | 674 bool downloaded_file_exists = base::PathExists(downloaded_file); |
| 675 EXPECT_TRUE(downloaded_file_exists) << downloaded_file.value(); | 675 EXPECT_TRUE(downloaded_file_exists) << downloaded_file.value(); |
| 676 if (!downloaded_file_exists) | 676 if (!downloaded_file_exists) |
| 677 return false; | 677 return false; |
| 678 | 678 |
| 679 int64 origin_file_size = 0; | 679 int64 origin_file_size = 0; |
| 680 EXPECT_TRUE(file_util::GetFileSize(origin_file, &origin_file_size)); | 680 EXPECT_TRUE(file_util::GetFileSize(origin_file, &origin_file_size)); |
| 681 std::string original_file_contents; | 681 std::string original_file_contents; |
| 682 EXPECT_TRUE( | 682 EXPECT_TRUE(base::ReadFileToString(origin_file, &original_file_contents)); |
| 683 file_util::ReadFileToString(origin_file, &original_file_contents)); | |
| 684 EXPECT_TRUE( | 683 EXPECT_TRUE( |
| 685 VerifyFile(downloaded_file, original_file_contents, origin_file_size)); | 684 VerifyFile(downloaded_file, original_file_contents, origin_file_size)); |
| 686 | 685 |
| 687 // Delete the downloaded copy of the file. | 686 // Delete the downloaded copy of the file. |
| 688 bool downloaded_file_deleted = | 687 bool downloaded_file_deleted = |
| 689 file_util::DieFileDie(downloaded_file, false); | 688 file_util::DieFileDie(downloaded_file, false); |
| 690 EXPECT_TRUE(downloaded_file_deleted); | 689 EXPECT_TRUE(downloaded_file_deleted); |
| 691 return downloaded_file_deleted; | 690 return downloaded_file_deleted; |
| 692 } | 691 } |
| 693 | 692 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 return file_activity_observer_->TestAndResetDidShowFileChooser(); | 823 return file_activity_observer_->TestAndResetDidShowFileChooser(); |
| 825 } | 824 } |
| 826 | 825 |
| 827 // Checks that |path| is has |file_size| bytes, and matches the |value| | 826 // Checks that |path| is has |file_size| bytes, and matches the |value| |
| 828 // string. | 827 // string. |
| 829 bool VerifyFile(const base::FilePath& path, | 828 bool VerifyFile(const base::FilePath& path, |
| 830 const std::string& value, | 829 const std::string& value, |
| 831 const int64 file_size) { | 830 const int64 file_size) { |
| 832 std::string file_contents; | 831 std::string file_contents; |
| 833 | 832 |
| 834 bool read = file_util::ReadFileToString(path, &file_contents); | 833 bool read = base::ReadFileToString(path, &file_contents); |
| 835 EXPECT_TRUE(read) << "Failed reading file: " << path.value() << std::endl; | 834 EXPECT_TRUE(read) << "Failed reading file: " << path.value() << std::endl; |
| 836 if (!read) | 835 if (!read) |
| 837 return false; // Couldn't read the file. | 836 return false; // Couldn't read the file. |
| 838 | 837 |
| 839 // Note: we don't handle really large files (more than size_t can hold) | 838 // Note: we don't handle really large files (more than size_t can hold) |
| 840 // so we will fail in that case. | 839 // so we will fail in that case. |
| 841 size_t expected_size = static_cast<size_t>(file_size); | 840 size_t expected_size = static_cast<size_t>(file_size); |
| 842 | 841 |
| 843 // Check the size. | 842 // Check the size. |
| 844 EXPECT_EQ(expected_size, file_contents.size()); | 843 EXPECT_EQ(expected_size, file_contents.size()); |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 GURL url(test_server()->GetURL("files/downloads/a_zip_file.zip")); | 1467 GURL url(test_server()->GetURL("files/downloads/a_zip_file.zip")); |
| 1469 | 1468 |
| 1470 // Read the origin file now so that we can compare the downloaded files to it | 1469 // Read the origin file now so that we can compare the downloaded files to it |
| 1471 // later. | 1470 // later. |
| 1472 base::FilePath origin(OriginFile(base::FilePath(FILE_PATH_LITERAL( | 1471 base::FilePath origin(OriginFile(base::FilePath(FILE_PATH_LITERAL( |
| 1473 "downloads/a_zip_file.zip")))); | 1472 "downloads/a_zip_file.zip")))); |
| 1474 ASSERT_TRUE(base::PathExists(origin)); | 1473 ASSERT_TRUE(base::PathExists(origin)); |
| 1475 int64 origin_file_size = 0; | 1474 int64 origin_file_size = 0; |
| 1476 EXPECT_TRUE(file_util::GetFileSize(origin, &origin_file_size)); | 1475 EXPECT_TRUE(file_util::GetFileSize(origin, &origin_file_size)); |
| 1477 std::string original_contents; | 1476 std::string original_contents; |
| 1478 EXPECT_TRUE(file_util::ReadFileToString(origin, &original_contents)); | 1477 EXPECT_TRUE(base::ReadFileToString(origin, &original_contents)); |
| 1479 | 1478 |
| 1480 std::vector<DownloadItem*> download_items; | 1479 std::vector<DownloadItem*> download_items; |
| 1481 GetDownloads(browser(), &download_items); | 1480 GetDownloads(browser(), &download_items); |
| 1482 ASSERT_TRUE(download_items.empty()); | 1481 ASSERT_TRUE(download_items.empty()); |
| 1483 | 1482 |
| 1484 // Download a file in the on-record browser and check that it was downloaded | 1483 // Download a file in the on-record browser and check that it was downloaded |
| 1485 // correctly. | 1484 // correctly. |
| 1486 DownloadAndWaitWithDisposition(browser(), | 1485 DownloadAndWaitWithDisposition(browser(), |
| 1487 url, | 1486 url, |
| 1488 CURRENT_TAB, | 1487 CURRENT_TAB, |
| (...skipping 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2839 } | 2838 } |
| 2840 | 2839 |
| 2841 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_Renaming) { | 2840 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_Renaming) { |
| 2842 ASSERT_TRUE(test_server()->Start()); | 2841 ASSERT_TRUE(test_server()->Start()); |
| 2843 GURL url(test_server()->GetURL("files/downloads/a_zip_file.zip")); | 2842 GURL url(test_server()->GetURL("files/downloads/a_zip_file.zip")); |
| 2844 content::DownloadManager* manager = DownloadManagerForBrowser(browser()); | 2843 content::DownloadManager* manager = DownloadManagerForBrowser(browser()); |
| 2845 base::FilePath origin_file(OriginFile(base::FilePath(FILE_PATH_LITERAL( | 2844 base::FilePath origin_file(OriginFile(base::FilePath(FILE_PATH_LITERAL( |
| 2846 "downloads/a_zip_file.zip")))); | 2845 "downloads/a_zip_file.zip")))); |
| 2847 ASSERT_TRUE(base::PathExists(origin_file)); | 2846 ASSERT_TRUE(base::PathExists(origin_file)); |
| 2848 std::string origin_contents; | 2847 std::string origin_contents; |
| 2849 ASSERT_TRUE(file_util::ReadFileToString(origin_file, &origin_contents)); | 2848 ASSERT_TRUE(base::ReadFileToString(origin_file, &origin_contents)); |
| 2850 | 2849 |
| 2851 // Download the same url several times and expect that all downloaded files | 2850 // Download the same url several times and expect that all downloaded files |
| 2852 // after the zero-th contain a deduplication counter. | 2851 // after the zero-th contain a deduplication counter. |
| 2853 for (int index = 0; index < 5; ++index) { | 2852 for (int index = 0; index < 5; ++index) { |
| 2854 DownloadAndWait(browser(), url); | 2853 DownloadAndWait(browser(), url); |
| 2855 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 2854 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 2856 content::DownloadItem* item = manager->GetDownload( | 2855 content::DownloadItem* item = manager->GetDownload( |
| 2857 content::DownloadItem::kInvalidId + 1 + index); | 2856 content::DownloadItem::kInvalidId + 1 + index); |
| 2858 ASSERT_TRUE(item); | 2857 ASSERT_TRUE(item); |
| 2859 ASSERT_EQ(DownloadItem::COMPLETE, item->GetState()); | 2858 ASSERT_EQ(DownloadItem::COMPLETE, item->GetState()); |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3246 | 3245 |
| 3247 // No errors this time. The download should complete successfully. | 3246 // No errors this time. The download should complete successfully. |
| 3248 EXPECT_FALSE(completion_observer->IsFinished()); | 3247 EXPECT_FALSE(completion_observer->IsFinished()); |
| 3249 completion_observer->StartObserving(); | 3248 completion_observer->StartObserving(); |
| 3250 download->Resume(); | 3249 download->Resume(); |
| 3251 completion_observer->WaitForFinished(); | 3250 completion_observer->WaitForFinished(); |
| 3252 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); | 3251 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); |
| 3253 | 3252 |
| 3254 EXPECT_FALSE(DidShowFileChooser()); | 3253 EXPECT_FALSE(DidShowFileChooser()); |
| 3255 } | 3254 } |
| OLD | NEW |