| Index: content/browser/download/download_file_manager_unittest.cc
|
| diff --git a/content/browser/download/download_file_manager_unittest.cc b/content/browser/download/download_file_manager_unittest.cc
|
| index 15eab3afcf963f84e82c567ef59d35f65e24ecaa..e363102fe5e926ebb528724f95b7493b54a54732 100644
|
| --- a/content/browser/download/download_file_manager_unittest.cc
|
| +++ b/content/browser/download/download_file_manager_unittest.cc
|
| @@ -10,7 +10,6 @@
|
| #include "base/scoped_temp_dir.h"
|
| #include "base/string_number_conversions.h"
|
| #include "content/browser/browser_thread_impl.h"
|
| -#include "content/browser/download/download_buffer.h"
|
| #include "content/browser/download/download_create_info.h"
|
| #include "content/browser/download/download_interrupt_reasons_impl.h"
|
| #include "content/browser/download/download_request_handle.h"
|
| @@ -127,8 +126,7 @@ class DownloadFileManagerTest : public testing::Test {
|
| // calling Release() on |download_manager_| won't ever result in its
|
| // destructor being called and we get a leak.
|
| DownloadFileManagerTest()
|
| - : download_buffer_(new content::DownloadBuffer()),
|
| - ui_thread_(BrowserThread::UI, &loop_),
|
| + : ui_thread_(BrowserThread::UI, &loop_),
|
| file_thread_(BrowserThread::FILE, &loop_) {
|
| }
|
|
|
| @@ -196,88 +194,6 @@ class DownloadFileManagerTest : public testing::Test {
|
| ClearExpectations(id);
|
| }
|
|
|
| - // Creates a new |net::IOBuffer| of size |length| with |data|, and attaches
|
| - // it to the download buffer.
|
| - bool UpdateBuffer(const char* data, size_t length) {
|
| - // We are passing ownership of this buffer to the download file manager.
|
| - // NOTE: we are padding io_buffer with one extra character so that the
|
| - // mock testing framework can treat it as a NULL-delimited string.
|
| - net::IOBuffer* io_buffer = new net::IOBuffer(length + 1);
|
| - // We need |AddRef()| because we do a |Release()| in |UpdateDownload()|.
|
| - io_buffer->AddRef();
|
| - memcpy(io_buffer->data(), data, length);
|
| - io_buffer->data()[length] = 0;
|
| -
|
| - download_buffer_->AddData(io_buffer, length);
|
| -
|
| - return true;
|
| - }
|
| -
|
| - // Updates the download file.
|
| - // |id| is the download ID of the download file.
|
| - // |data| is the buffer containing the data.
|
| - // |length| is the length of the data buffer.
|
| - // |error_to_insert| is the error to simulate. For no error, use net::OK.
|
| - void UpdateDownload(const DownloadId& id,
|
| - const char* data,
|
| - size_t length,
|
| - net::Error error_to_insert) {
|
| - // Expected call sequence:
|
| - // Create DownloadBuffer
|
| - // UpdateDownload
|
| - // GetDownloadFile
|
| - // DownloadFile::AppendDataToFile
|
| - //
|
| - // On error:
|
| - // DownloadFile::GetDownloadManager
|
| - // DownloadFile::BytesSoFar
|
| - // CancelDownload
|
| - // Process one message in the message loop
|
| - // DownloadManager::OnDownloadInterrupted
|
| - EXPECT_TRUE(UpdateBuffer(data, length));
|
| - MockDownloadFile* file = download_file_factory_->GetExistingFile(id);
|
| - ASSERT_TRUE(file != NULL);
|
| - byte_count_[id] += length;
|
| -
|
| - // Make sure our comparison string is NULL-terminated.
|
| - char* expected_data = new char[length + 1];
|
| - memcpy(expected_data, data, length);
|
| - expected_data[length] = 0;
|
| -
|
| - EXPECT_CALL(*file, AppendDataToFile(StrEq(expected_data), length))
|
| - .Times(1)
|
| - .WillOnce(Return(error_to_insert));
|
| -
|
| - if (error_to_insert != net::OK) {
|
| - EXPECT_CALL(*file, GetDownloadManager())
|
| - .Times(AtLeast(1));
|
| - EXPECT_CALL(*file, BytesSoFar())
|
| - .Times(AtLeast(1))
|
| - .WillRepeatedly(Return(byte_count_[id]));
|
| - EXPECT_CALL(*file, GetHashState())
|
| - .Times(AtLeast(1));
|
| - EXPECT_CALL(*file, Cancel());
|
| - }
|
| -
|
| - download_file_manager_->UpdateDownload(id, download_buffer_.get());
|
| -
|
| - if (error_to_insert != net::OK) {
|
| - EXPECT_CALL(*download_manager_,
|
| - OnDownloadInterrupted(
|
| - id.local(),
|
| - byte_count_[id],
|
| - "",
|
| - content::ConvertNetErrorToInterruptReason(
|
| - error_to_insert, content::DOWNLOAD_INTERRUPT_FROM_DISK)));
|
| -
|
| - ProcessAllPendingMessages();
|
| - ++error_count_[id];
|
| - }
|
| -
|
| - ClearExpectations(id);
|
| - delete [] expected_data;
|
| - }
|
| -
|
| // Renames the download file.
|
| // |id| is the download ID of the download file.
|
| // |new_path| is the new file path.
|
| @@ -395,8 +311,6 @@ class DownloadFileManagerTest : public testing::Test {
|
| .Times(AtLeast(1))
|
| .WillRepeatedly(Return(byte_count_[id]));
|
|
|
| - download_file_manager_->OnResponseCompleted(id, reason, security_string);
|
| -
|
| if (reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) {
|
| EXPECT_CALL(*download_manager_,
|
| OnResponseCompleted(id.local(), byte_count_[id], ""))
|
| @@ -442,7 +356,6 @@ class DownloadFileManagerTest : public testing::Test {
|
| scoped_ptr<MockDownloadRequestHandle> request_handle_;
|
| MockDownloadFileFactory* download_file_factory_;
|
| scoped_refptr<DownloadFileManager> download_file_manager_;
|
| - scoped_refptr<content::DownloadBuffer> download_buffer_;
|
|
|
| // Per-download statistics.
|
| std::map<DownloadId, int64> byte_count_;
|
| @@ -487,10 +400,6 @@ TEST_F(DownloadFileManagerTest, CancelBeforeFinished) {
|
|
|
| StartDownload(info, dummy_id);
|
|
|
| - UpdateDownload(dummy_id, kTestData1, strlen(kTestData1), net::OK);
|
| - UpdateDownload(dummy_id, kTestData2, strlen(kTestData2), net::OK);
|
| - UpdateDownload(dummy_id, kTestData3, strlen(kTestData3), net::OK);
|
| -
|
| CleanUp(dummy_id);
|
| }
|
|
|
| @@ -501,9 +410,6 @@ TEST_F(DownloadFileManagerTest, DownloadWithError) {
|
|
|
| StartDownload(info, dummy_id);
|
|
|
| - UpdateDownload(dummy_id, kTestData1, strlen(kTestData1), net::OK);
|
| - UpdateDownload(dummy_id, kTestData2, strlen(kTestData2),
|
| - net::ERR_FILE_NO_SPACE);
|
| }
|
|
|
| TEST_F(DownloadFileManagerTest, CompleteDownload) {
|
| @@ -513,10 +419,6 @@ TEST_F(DownloadFileManagerTest, CompleteDownload) {
|
|
|
| StartDownload(info, dummy_id);
|
|
|
| - UpdateDownload(dummy_id, kTestData1, strlen(kTestData1), net::OK);
|
| - UpdateDownload(dummy_id, kTestData2, strlen(kTestData2), net::OK);
|
| - UpdateDownload(dummy_id, kTestData3, strlen(kTestData3), net::OK);
|
| -
|
| OnResponseCompleted(dummy_id, content::DOWNLOAD_INTERRUPT_REASON_NONE, "");
|
|
|
| CleanUp(dummy_id);
|
| @@ -529,10 +431,6 @@ TEST_F(DownloadFileManagerTest, CompleteDownloadWithError) {
|
|
|
| StartDownload(info, dummy_id);
|
|
|
| - UpdateDownload(dummy_id, kTestData1, strlen(kTestData1), net::OK);
|
| - UpdateDownload(dummy_id, kTestData2, strlen(kTestData2), net::OK);
|
| - UpdateDownload(dummy_id, kTestData3, strlen(kTestData3), net::OK);
|
| -
|
| OnResponseCompleted(dummy_id,
|
| content::DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED,
|
| "");
|
| @@ -549,11 +447,8 @@ TEST_F(DownloadFileManagerTest, RenameInProgress) {
|
|
|
| StartDownload(info, dummy_id);
|
|
|
| - UpdateDownload(dummy_id, kTestData1, strlen(kTestData1), net::OK);
|
| - UpdateDownload(dummy_id, kTestData2, strlen(kTestData2), net::OK);
|
| FilePath foo(download_dir.path().Append(FILE_PATH_LITERAL("foo.txt")));
|
| RenameFile(dummy_id, foo, foo, net::OK, IN_PROGRESS, OVERWRITE);
|
| - UpdateDownload(dummy_id, kTestData3, strlen(kTestData3), net::OK);
|
|
|
| OnResponseCompleted(dummy_id, content::DOWNLOAD_INTERRUPT_REASON_NONE, "");
|
|
|
| @@ -569,8 +464,6 @@ TEST_F(DownloadFileManagerTest, RenameInProgressWithError) {
|
|
|
| StartDownload(info, dummy_id);
|
|
|
| - UpdateDownload(dummy_id, kTestData1, strlen(kTestData1), net::OK);
|
| - UpdateDownload(dummy_id, kTestData2, strlen(kTestData2), net::OK);
|
| FilePath foo(download_dir.path().Append(FILE_PATH_LITERAL("foo.txt")));
|
| RenameFile(dummy_id, foo, foo, net::ERR_FILE_PATH_TOO_LONG,
|
| IN_PROGRESS, OVERWRITE);
|
| @@ -587,10 +480,6 @@ TEST_F(DownloadFileManagerTest, RenameCompleting) {
|
|
|
| StartDownload(info, dummy_id);
|
|
|
| - UpdateDownload(dummy_id, kTestData1, strlen(kTestData1), net::OK);
|
| - UpdateDownload(dummy_id, kTestData2, strlen(kTestData2), net::OK);
|
| - UpdateDownload(dummy_id, kTestData3, strlen(kTestData3), net::OK);
|
| -
|
| OnResponseCompleted(dummy_id, content::DOWNLOAD_INTERRUPT_REASON_NONE, "");
|
|
|
| FilePath foo(download_dir.path().Append(FILE_PATH_LITERAL("foo.txt")));
|
| @@ -608,10 +497,6 @@ TEST_F(DownloadFileManagerTest, RenameCompletingWithUniquification) {
|
|
|
| StartDownload(info, dummy_id);
|
|
|
| - UpdateDownload(dummy_id, kTestData1, strlen(kTestData1), net::OK);
|
| - UpdateDownload(dummy_id, kTestData2, strlen(kTestData2), net::OK);
|
| - UpdateDownload(dummy_id, kTestData3, strlen(kTestData3), net::OK);
|
| -
|
| OnResponseCompleted(dummy_id, content::DOWNLOAD_INTERRUPT_REASON_NONE, "");
|
|
|
| FilePath foo(download_dir.path().Append(FILE_PATH_LITERAL("foo.txt")));
|
| @@ -634,10 +519,6 @@ TEST_F(DownloadFileManagerTest, RenameCompletingWithError) {
|
|
|
| StartDownload(info, dummy_id);
|
|
|
| - UpdateDownload(dummy_id, kTestData1, strlen(kTestData1), net::OK);
|
| - UpdateDownload(dummy_id, kTestData2, strlen(kTestData2), net::OK);
|
| - UpdateDownload(dummy_id, kTestData3, strlen(kTestData3), net::OK);
|
| -
|
| OnResponseCompleted(dummy_id, content::DOWNLOAD_INTERRUPT_REASON_NONE, "");
|
|
|
| FilePath foo(download_dir.path().Append(FILE_PATH_LITERAL("foo.txt")));
|
| @@ -656,12 +537,9 @@ TEST_F(DownloadFileManagerTest, RenameTwice) {
|
|
|
| StartDownload(info, dummy_id);
|
|
|
| - UpdateDownload(dummy_id, kTestData1, strlen(kTestData1), net::OK);
|
| - UpdateDownload(dummy_id, kTestData2, strlen(kTestData2), net::OK);
|
| FilePath crfoo(download_dir.path().Append(
|
| FILE_PATH_LITERAL("foo.txt.crdownload")));
|
| RenameFile(dummy_id, crfoo, crfoo, net::OK, IN_PROGRESS, OVERWRITE);
|
| - UpdateDownload(dummy_id, kTestData3, strlen(kTestData3), net::OK);
|
|
|
| OnResponseCompleted(dummy_id, content::DOWNLOAD_INTERRUPT_REASON_NONE, "");
|
|
|
| @@ -682,13 +560,9 @@ TEST_F(DownloadFileManagerTest, TwoDownloads) {
|
|
|
| StartDownload(info, dummy_id);
|
|
|
| - UpdateDownload(dummy_id, kTestData1, strlen(kTestData1), net::OK);
|
|
|
| StartDownload(info2, dummy_id2);
|
|
|
| - UpdateDownload(dummy_id, kTestData2, strlen(kTestData2), net::OK);
|
| -
|
| - UpdateDownload(dummy_id2, kTestData4, strlen(kTestData4), net::OK);
|
| FilePath crbar(download_dir.path().Append(
|
| FILE_PATH_LITERAL("bar.txt.crdownload")));
|
| RenameFile(dummy_id2, crbar, crbar, net::OK, IN_PROGRESS, OVERWRITE);
|
| @@ -697,11 +571,6 @@ TEST_F(DownloadFileManagerTest, TwoDownloads) {
|
| FILE_PATH_LITERAL("foo.txt.crdownload")));
|
| RenameFile(dummy_id, crfoo, crfoo, net::OK, IN_PROGRESS, OVERWRITE);
|
|
|
| - UpdateDownload(dummy_id, kTestData3, strlen(kTestData3), net::OK);
|
| -
|
| - UpdateDownload(dummy_id2, kTestData5, strlen(kTestData5), net::OK);
|
| - UpdateDownload(dummy_id2, kTestData6, strlen(kTestData6), net::OK);
|
| -
|
| OnResponseCompleted(dummy_id2, content::DOWNLOAD_INTERRUPT_REASON_NONE, "");
|
|
|
| OnResponseCompleted(dummy_id, content::DOWNLOAD_INTERRUPT_REASON_NONE, "");
|
|
|