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

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

Issue 11363222: Persist download interrupt reason, both target and current paths, and url_chain. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated Ben's comments. Created 8 years 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_history_unittest.cc
diff --git a/chrome/browser/download/download_history_unittest.cc b/chrome/browser/download/download_history_unittest.cc
index 9d3a5fb85cc149d5c412b45b2ab67d58b86f3114..1b0cc7784a18c7f8481d0bbbb97881b90ccea34e 100644
--- a/chrome/browser/download/download_history_unittest.cc
+++ b/chrome/browser/download/download_history_unittest.cc
@@ -29,8 +29,14 @@ namespace {
void CheckInfoEqual(const history::DownloadRow& left,
const history::DownloadRow& right) {
- EXPECT_EQ(left.path.value(), right.path.value());
- EXPECT_EQ(left.url.spec(), right.url.spec());
+ EXPECT_EQ(left.current_path.value(), right.current_path.value());
+ EXPECT_EQ(left.target_path.value(), right.target_path.value());
+ EXPECT_EQ(left.url_chain.size(), right.url_chain.size());
+ for (unsigned int i = 0;
+ i < left.url_chain.size() && i < right.url_chain.size();
+ ++i) {
+ EXPECT_EQ(left.url_chain[i].spec(), right.url_chain[i].spec());
+ }
EXPECT_EQ(left.referrer_url.spec(), right.referrer_url.spec());
EXPECT_EQ(left.start_time.ToTimeT(), right.start_time.ToTimeT());
EXPECT_EQ(left.end_time.ToTimeT(), right.end_time.ToTimeT());
@@ -234,15 +240,16 @@ class DownloadHistoryTest : public testing::Test {
EXPECT_CALL(manager(), RemoveObserver(_));
download_created_index_ = 0;
for (size_t index = 0; index < infos->size(); ++index) {
- EXPECT_CALL(manager(), CreateDownloadItem(
- infos->at(index).path,
- infos->at(index).url,
+ EXPECT_CALL(manager(), MockCreateDownloadItem(
+ infos->at(index).target_path,
+ infos->at(index).url_chain,
infos->at(index).referrer_url,
infos->at(index).start_time,
infos->at(index).end_time,
infos->at(index).received_bytes,
infos->at(index).total_bytes,
infos->at(index).state,
+ infos->at(index).interrupt_reason,
infos->at(index).opened))
.WillOnce(DoAll(
InvokeWithoutArgs(
@@ -317,16 +324,21 @@ class DownloadHistoryTest : public testing::Test {
history_->ExpectDownloadsRemoved(handles);
}
+ // Caller is responsibile for making sure reference arguments lifetime is
+ // greater than the lifetime of the NiceMockDownloadItem() created by this
+ // routine.
void InitItem(
int32 id,
- const FilePath& path,
- const GURL& url,
+ const FilePath& current_path,
+ const FilePath& target_path,
+ const std::vector<GURL>& url_chain,
const GURL& referrer,
const base::Time& start_time,
const base::Time& end_time,
int64 received_bytes,
int64 total_bytes,
content::DownloadItem::DownloadState state,
+ content::DownloadInterruptReason interrupt_reason,
int64 db_handle,
bool opened,
history::DownloadRow* info) {
@@ -335,20 +347,28 @@ class DownloadHistoryTest : public testing::Test {
NiceMockDownloadItem* mock_item = new NiceMockDownloadItem();
items_.push_back(mock_item);
- info->path = path;
- info->url = url;
+ info->current_path = current_path;
+ info->target_path = target_path;
+ info->url_chain = url_chain;
info->referrer_url = referrer;
info->start_time = start_time;
info->end_time = end_time;
info->received_bytes = received_bytes;
info->total_bytes = total_bytes;
info->state = state;
+ info->interrupt_reason = interrupt_reason;
info->db_handle = db_handle;
info->opened = opened;
EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id));
- EXPECT_CALL(item(index), GetFullPath()).WillRepeatedly(ReturnRef(path));
- EXPECT_CALL(item(index), GetURL()).WillRepeatedly(ReturnRef(url));
+ EXPECT_CALL(item(index),
+ GetFullPath()).WillRepeatedly(ReturnRef(current_path));
+ EXPECT_CALL(item(index),
+ GetTargetFilePath()).WillRepeatedly(ReturnRef(target_path));
+ DCHECK_LE(1u, url_chain.size());
+ EXPECT_CALL(item(index), GetURL()).WillRepeatedly(ReturnRef(url_chain[0]));
+ EXPECT_CALL(item(index),
+ GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
EXPECT_CALL(item(index), GetMimeType()).WillRepeatedly(Return(
"application/octet-stream"));
EXPECT_CALL(item(index), GetReferrerUrl()).WillRepeatedly(ReturnRef(
@@ -402,15 +422,19 @@ TEST_F(DownloadHistoryTest, DownloadHistoryTest_Load) {
FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf"));
GURL url("http://example.com/bar.pdf");
GURL referrer("http://example.com/referrer.html");
+ std::vector<GURL> url_chain;
+ url_chain.push_back(url);
InitItem(base::RandInt(0, 1 << 20),
path,
- url,
+ path,
+ url_chain,
referrer,
(base::Time::Now() - base::TimeDelta::FromMinutes(10)),
(base::Time::Now() - base::TimeDelta::FromMinutes(1)),
100,
100,
content::DownloadItem::COMPLETE,
+ content::DOWNLOAD_INTERRUPT_REASON_NONE,
base::RandInt(0, 1 << 20),
false,
&info);
@@ -447,15 +471,19 @@ TEST_F(DownloadHistoryTest, DownloadHistoryTest_Create) {
FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf"));
GURL url("http://example.com/bar.pdf");
GURL referrer("http://example.com/referrer.html");
+ std::vector<GURL> url_chain;
+ url_chain.push_back(url);
InitItem(base::RandInt(0, 1 << 20),
path,
- url,
+ path,
+ url_chain,
referrer,
(base::Time::Now() - base::TimeDelta::FromMinutes(10)),
(base::Time::Now() - base::TimeDelta::FromMinutes(1)),
100,
100,
content::DownloadItem::COMPLETE,
+ content::DOWNLOAD_INTERRUPT_REASON_NONE,
-1,
false,
&info);
@@ -494,15 +522,19 @@ TEST_F(DownloadHistoryTest, DownloadHistoryTest_Temporary) {
FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf"));
GURL url("http://example.com/bar.pdf");
GURL referrer("http://example.com/referrer.html");
+ std::vector<GURL> url_chain;
+ url_chain.push_back(url);
InitItem(base::RandInt(0, 1 << 20),
path,
- url,
+ path,
+ url_chain,
referrer,
(base::Time::Now() - base::TimeDelta::FromMinutes(10)),
(base::Time::Now() - base::TimeDelta::FromMinutes(1)),
100,
100,
content::DownloadItem::COMPLETE,
+ content::DOWNLOAD_INTERRUPT_REASON_NONE,
-1,
false,
&info);
@@ -555,15 +587,19 @@ TEST_F(DownloadHistoryTest,
FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf"));
GURL url("http://example.com/bar.pdf");
GURL referrer("http://example.com/referrer.html");
+ std::vector<GURL> url_chain;
+ url_chain.push_back(url);
InitItem(base::RandInt(0, 1 << 20),
path,
- url,
+ path,
+ url_chain,
referrer,
(base::Time::Now() - base::TimeDelta::FromMinutes(10)),
(base::Time::Now() - base::TimeDelta::FromMinutes(1)),
100,
100,
content::DownloadItem::COMPLETE,
+ content::DOWNLOAD_INTERRUPT_REASON_NONE,
-1,
false,
&info);
@@ -606,30 +642,38 @@ TEST_F(DownloadHistoryTest, DownloadHistoryTest_Multiple) {
FilePath path0(FILE_PATH_LITERAL("/foo/bar.pdf"));
GURL url0("http://example.com/bar.pdf");
GURL referrer0("http://example.com/referrer.html");
+ std::vector<GURL> url0_chain;
+ url0_chain.push_back(url0);
InitItem(base::RandInt(0, 1 << 10),
path0,
- url0,
+ path0,
+ url0_chain,
referrer0,
(base::Time::Now() - base::TimeDelta::FromMinutes(11)),
(base::Time::Now() - base::TimeDelta::FromMinutes(2)),
100,
100,
content::DownloadItem::COMPLETE,
+ content::DOWNLOAD_INTERRUPT_REASON_NONE,
base::RandInt(0, 1 << 10),
false,
&info0);
FilePath path1(FILE_PATH_LITERAL("/foo/qux.pdf"));
GURL url1("http://example.com/qux.pdf");
GURL referrer1("http://example.com/referrer.html");
+ std::vector<GURL> url1_chain;
+ url1_chain.push_back(url0);
InitItem(item(0).GetId() + base::RandInt(1, 1 << 10),
path1,
- url1,
+ path1,
+ url1_chain,
referrer1,
(base::Time::Now() - base::TimeDelta::FromMinutes(10)),
(base::Time::Now() - base::TimeDelta::FromMinutes(1)),
200,
200,
content::DownloadItem::COMPLETE,
+ content::DOWNLOAD_INTERRUPT_REASON_NONE,
info0.db_handle + base::RandInt(1, 1 << 10),
false,
&info1);
@@ -664,15 +708,19 @@ TEST_F(DownloadHistoryTest, DownloadHistoryTest_CreateFailed) {
FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf"));
GURL url("http://example.com/bar.pdf");
GURL referrer("http://example.com/referrer.html");
+ std::vector<GURL> url_chain;
+ url_chain.push_back(url);
InitItem(base::RandInt(0, 1 << 20),
path,
- url,
+ path,
+ url_chain,
referrer,
(base::Time::Now() - base::TimeDelta::FromMinutes(10)),
(base::Time::Now() - base::TimeDelta::FromMinutes(1)),
100,
100,
content::DownloadItem::COMPLETE,
+ content::DOWNLOAD_INTERRUPT_REASON_NONE,
-1,
false,
&info);
@@ -702,15 +750,19 @@ TEST_F(DownloadHistoryTest,
FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf"));
GURL url("http://example.com/bar.pdf");
GURL referrer("http://example.com/referrer.html");
+ std::vector<GURL> url_chain;
+ url_chain.push_back(url);
InitItem(base::RandInt(0, 1 << 20),
path,
- url,
+ path,
+ url_chain,
referrer,
(base::Time::Now() - base::TimeDelta::FromMinutes(10)),
(base::Time::Now() - base::TimeDelta::FromMinutes(1)),
100,
100,
content::DownloadItem::COMPLETE,
+ content::DOWNLOAD_INTERRUPT_REASON_NONE,
-1,
false,
&info);

Powered by Google App Engine
This is Rietveld 408576698