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

Unified Diff: content/browser/download/download_manager_impl_unittest.cc

Issue 10074001: Initial implementation of the ByteStream refactor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/download/download_manager_impl_unittest.cc
diff --git a/content/browser/download/download_manager_impl_unittest.cc b/content/browser/download/download_manager_impl_unittest.cc
index abafb1406cb0bf2f8aef695e84efa26c03c74443..838d065817faf97a74a204f5fb2014f393cfccd6 100644
--- a/content/browser/download/download_manager_impl_unittest.cc
+++ b/content/browser/download/download_manager_impl_unittest.cc
@@ -15,7 +15,6 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "build/build_config.h"
-#include "content/browser/download/download_buffer.h"
#include "content/browser/download/download_create_info.h"
#include "content/browser/download/download_file_impl.h"
#include "content/browser/download/download_file_manager.h"
@@ -217,8 +216,7 @@ class DownloadManagerTest : public testing::Test {
download_manager_(new DownloadManagerImpl(
download_manager_delegate_.get(), NULL)),
ui_thread_(BrowserThread::UI, &message_loop_),
- file_thread_(BrowserThread::FILE, &message_loop_),
- download_buffer_(new content::DownloadBuffer) {
+ file_thread_(BrowserThread::FILE, &message_loop_) {
download_manager_->Init(browser_context.get());
download_manager_delegate_->set_download_manager(download_manager_);
}
@@ -257,23 +255,6 @@ class DownloadManagerTest : public testing::Test {
download_manager_->ContinueDownloadWithPath(download, path);
}
- void UpdateData(int32 id, const char* data, size_t length) {
- // We are passing ownership of this buffer to the download file manager.
- net::IOBuffer* io_buffer = new net::IOBuffer(length);
- // We need |AddRef()| because we do a |Release()| in |UpdateDownload()|.
- io_buffer->AddRef();
- memcpy(io_buffer->data(), data, length);
-
- download_buffer_->AddData(io_buffer, length);
-
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&DownloadFileManager::UpdateDownload, file_manager_.get(),
- DownloadId(kValidIdDomain, id), download_buffer_));
-
- message_loop_.RunAllPending();
- }
-
void OnDownloadInterrupted(int32 download_id, int64 size,
const std::string& hash_state,
content::DownloadInterruptReason reason) {
@@ -294,7 +275,6 @@ class DownloadManagerTest : public testing::Test {
MessageLoopForUI message_loop_;
content::TestBrowserThread ui_thread_;
content::TestBrowserThread file_thread_;
- scoped_refptr<content::DownloadBuffer> download_buffer_;
DownloadFileManager* file_manager() {
if (!file_manager_) {
@@ -999,6 +979,14 @@ TEST_F(DownloadManagerTest, DownloadInterruptTest) {
EXPECT_EQ(download->GetTotalBytes(), static_cast<int64>(kTestDataLen));
}
+void WriteCopyToPipe(scoped_refptr<content::ByteStream> pipe,
+ const char *source,
+ size_t len) {
+ scoped_refptr<net::IOBuffer> copy(new net::IOBuffer(len));
+ memcpy(copy.get()->data(), source, len);
+ pipe->AddData(copy, len);
+}
+
// Test the behavior of DownloadFileManager and DownloadManager in the event
// of a file error while writing the download to disk.
TEST_F(DownloadManagerTest, MAYBE_DownloadFileErrorTest) {
@@ -1023,14 +1011,14 @@ TEST_F(DownloadManagerTest, MAYBE_DownloadFileErrorTest) {
info->total_bytes = static_cast<int64>(kTestDataLen * 3);
info->save_info.file_path = path;
info->save_info.file_stream.reset(stream);
+ scoped_refptr<content::ByteStream> data_pipe(new content::ByteStream);
+ info->pipe = data_pipe;
// Create a download file that we can insert errors into.
- DownloadFileWithErrors* download_file(new DownloadFileWithErrors(
+ scoped_ptr<DownloadFileWithErrors> download_file(new DownloadFileWithErrors(
info.get(), download_manager_, false));
download_file->Initialize();
- AddDownloadToFileManager(local_id, download_file);
- // |download_file| is owned by DownloadFileManager.
download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle());
DownloadItem* download = GetActiveDownloadItem(0);
@@ -1040,7 +1028,7 @@ TEST_F(DownloadManagerTest, MAYBE_DownloadFileErrorTest) {
scoped_ptr<ItemObserver> observer(new ItemObserver(download));
// Add some data before finalizing the file name.
- UpdateData(local_id, kTestData, kTestDataLen);
+ WriteCopyToPipe(data_pipe, kTestData, kTestDataLen);
// Finalize the file name.
ContinueDownloadWithPath(download, path);
@@ -1048,11 +1036,11 @@ TEST_F(DownloadManagerTest, MAYBE_DownloadFileErrorTest) {
EXPECT_TRUE(GetActiveDownloadItem(0) != NULL);
// Add more data.
- UpdateData(local_id, kTestData, kTestDataLen);
+ WriteCopyToPipe(data_pipe, kTestData, kTestDataLen);
// Add more data, but an error occurs.
download_file->set_forced_error(net::ERR_FAILED);
- UpdateData(local_id, kTestData, kTestDataLen);
+ WriteCopyToPipe(data_pipe, kTestData, kTestDataLen);
// Check the state. The download should have been interrupted.
EXPECT_TRUE(GetActiveDownloadItem(0) == NULL);

Powered by Google App Engine
This is Rietveld 408576698