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

Unified Diff: chrome/browser/download/download_manager_unittest.cc

Issue 8372073: Merge 8401001 r107836 into branch 912: Fix history importing by delaying DownloadManager creation. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/912/src/
Patch Set: Created 9 years, 1 month 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: chrome/browser/download/download_manager_unittest.cc
===================================================================
--- chrome/browser/download/download_manager_unittest.cc (revision 108294)
+++ chrome/browser/download/download_manager_unittest.cc (working copy)
@@ -26,6 +26,7 @@
#include "content/browser/download/download_create_info.h"
#include "content/browser/download/download_file.h"
#include "content/browser/download/download_file_manager.h"
+#include "content/browser/download/download_id_factory.h"
#include "content/browser/download/download_item.h"
#include "content/browser/download/download_manager.h"
#include "content/browser/download/download_status_updater.h"
@@ -40,6 +41,8 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/text/bytes_formatting.h"
+DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain";
+
class DownloadManagerTest : public testing::Test {
public:
static const char* kTestData;
@@ -49,8 +52,11 @@
: profile_(new TestingProfile()),
download_manager_delegate_(new ChromeDownloadManagerDelegate(
profile_.get())),
+ id_factory_(new DownloadIdFactory(kValidIdDomain)),
download_manager_(new MockDownloadManager(
- download_manager_delegate_, &download_status_updater_)),
+ download_manager_delegate_,
+ id_factory_.get(),
+ &download_status_updater_)),
ui_thread_(BrowserThread::UI, &message_loop_),
file_thread_(BrowserThread::FILE, &message_loop_) {
download_manager_->Init(profile_.get());
@@ -68,7 +74,7 @@
}
void AddDownloadToFileManager(int id, DownloadFile* download_file) {
- file_manager()->downloads_[DownloadId(download_manager_.get(), id)] =
+ file_manager()->downloads_[DownloadId(kValidIdDomain, id)] =
download_file;
}
@@ -102,7 +108,7 @@
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&DownloadFileManager::UpdateDownload, file_manager_.get(),
- DownloadId(download_manager_.get(), id), &download_buffer_));
+ DownloadId(kValidIdDomain, id), &download_buffer_));
message_loop_.RunAllPending();
}
@@ -123,6 +129,7 @@
DownloadStatusUpdater download_status_updater_;
scoped_ptr<TestingProfile> profile_;
scoped_refptr<ChromeDownloadManagerDelegate> download_manager_delegate_;
+ scoped_refptr<DownloadIdFactory> id_factory_;
scoped_refptr<DownloadManager> download_manager_;
scoped_refptr<DownloadFileManager> file_manager_;
MessageLoopForUI message_loop_;
@@ -384,7 +391,7 @@
// responsible for deleting it. In these unit tests, however, we
// don't call the function that deletes it, so we do so ourselves.
scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
- info->download_id = static_cast<int>(i);
+ info->download_id = DownloadId(kValidIdDomain, static_cast<int>(i));
info->prompt_user_for_save_location = kStartDownloadCases[i].save_as;
info->url_chain.push_back(GURL(kStartDownloadCases[i].url));
info->mime_type = kStartDownloadCases[i].mime_type;
@@ -392,9 +399,9 @@
DownloadFile* download_file(
new DownloadFile(info.get(), download_manager_));
- AddDownloadToFileManager(info->download_id, download_file);
+ AddDownloadToFileManager(info->download_id.local(), download_file);
download_file->Initialize(false);
- download_manager_->StartDownload(info->download_id);
+ download_manager_->StartDownload(info->download_id.local());
message_loop_.RunAllPending();
// SelectFileObserver will have recorded any attempt to open the
@@ -416,14 +423,14 @@
// responsible for deleting it. In these unit tests, however, we
// don't call the function that deletes it, so we do so ourselves.
scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
- info->download_id = static_cast<int>(i);
+ info->download_id = DownloadId(kValidIdDomain, static_cast<int>(i));
info->prompt_user_for_save_location = false;
info->url_chain.push_back(GURL());
const FilePath new_path(kDownloadRenameCases[i].suggested_path);
MockDownloadFile* download_file(
new MockDownloadFile(info.get(), download_manager_));
- AddDownloadToFileManager(info->download_id, download_file);
+ AddDownloadToFileManager(info->download_id.local(), download_file);
// |download_file| is owned by DownloadFileManager.
::testing::Mock::AllowLeak(download_file);
@@ -479,7 +486,7 @@
// responsible for deleting it. In these unit tests, however, we
// don't call the function that deletes it, so we do so ourselves.
scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
- info->download_id = static_cast<int>(0);
+ info->download_id = DownloadId(kValidIdDomain, static_cast<int>(0));
info->prompt_user_for_save_location = false;
info->url_chain.push_back(GURL());
info->total_bytes = static_cast<int64>(kTestDataLen);
@@ -488,7 +495,7 @@
MockDownloadFile* download_file(
new MockDownloadFile(info.get(), download_manager_));
- AddDownloadToFileManager(info->download_id, download_file);
+ AddDownloadToFileManager(info->download_id.local(), download_file);
// |download_file| is owned by DownloadFileManager.
::testing::Mock::AllowLeak(download_file);
@@ -570,7 +577,7 @@
// don't call the function that deletes it, so we do so ourselves.
scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
int32 id = 0;
- info->download_id = id;
+ info->download_id = DownloadId(kValidIdDomain, id);
info->prompt_user_for_save_location = false;
info->url_chain.push_back(GURL());
info->total_bytes = static_cast<int64>(kTestDataLen * 3);
@@ -648,7 +655,7 @@
// responsible for deleting it. In these unit tests, however, we
// don't call the function that deletes it, so we do so ourselves.
scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
- info->download_id = static_cast<int>(0);
+ info->download_id = DownloadId(kValidIdDomain, static_cast<int>(0));
info->prompt_user_for_save_location = false;
info->url_chain.push_back(GURL());
const FilePath new_path(FILE_PATH_LITERAL("foo.zip"));
@@ -656,7 +663,7 @@
MockDownloadFile* download_file(
new MockDownloadFile(info.get(), download_manager_));
- AddDownloadToFileManager(info->download_id, download_file);
+ AddDownloadToFileManager(info->download_id.local(), download_file);
// |download_file| is owned by DownloadFileManager.
::testing::Mock::AllowLeak(download_file);
@@ -732,7 +739,7 @@
// responsible for deleting it. In these unit tests, however, we
// don't call the function that deletes it, so we do so ourselves.
scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
- info->download_id = static_cast<int>(0);
+ info->download_id = DownloadId(kValidIdDomain, static_cast<int>(0));
info->prompt_user_for_save_location = true;
info->url_chain.push_back(GURL());
@@ -756,7 +763,7 @@
// This creates the .crdownload version of the file.
download_file->Initialize(false);
// |download_file| is owned by DownloadFileManager.
- AddDownloadToFileManager(info->download_id, download_file);
+ AddDownloadToFileManager(info->download_id.local(), download_file);
ContinueDownloadWithPath(download, new_path);
message_loop_.RunAllPending();
@@ -808,7 +815,7 @@
// responsible for deleting it. In these unit tests, however, we
// don't call the function that deletes it, so we do so ourselves.
scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
- info->download_id = static_cast<int>(0);
+ info->download_id = DownloadId(kValidIdDomain, static_cast<int>(0));
info->prompt_user_for_save_location = true;
info->url_chain.push_back(GURL());
@@ -832,7 +839,7 @@
// This creates the .crdownload version of the file.
download_file->Initialize(false);
// |download_file| is owned by DownloadFileManager.
- AddDownloadToFileManager(info->download_id, download_file);
+ AddDownloadToFileManager(info->download_id.local(), download_file);
ContinueDownloadWithPath(download, new_path);
message_loop_.RunAllPending();
« no previous file with comments | « chrome/browser/download/chrome_download_manager_delegate.cc ('k') | chrome/browser/download/download_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698