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 0316883af53315d071c2e778266ce085da25f2e0..57394f218f4487d0f139df64f6a6fc2db465261d 100644 |
--- a/chrome/browser/download/download_history_unittest.cc |
+++ b/chrome/browser/download/download_history_unittest.cc |
@@ -198,7 +198,6 @@ class DownloadHistoryTest : public testing::Test { |
manager_(new content::MockDownloadManager()), |
history_(NULL), |
manager_observer_(NULL), |
- item_observer_(NULL), |
download_created_index_(0) {} |
virtual ~DownloadHistoryTest() { |
STLDeleteElements(&items_); |
@@ -220,15 +219,6 @@ class DownloadHistoryTest : public testing::Test { |
return manager_observer_; |
} |
- // Relies on the same object observing all download items. |
- void SetItemObserver( |
- content::DownloadItem::Observer* item_observer) { |
- item_observer_ = item_observer; |
- } |
- content::DownloadItem::Observer* item_observer() { |
- return item_observer_; |
- } |
- |
void ExpectWillQueryDownloads(scoped_ptr<InfoVector> infos) { |
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
CHECK(infos.get()); |
@@ -432,10 +422,6 @@ class DownloadHistoryTest : public testing::Test { |
Return(content::DownloadItem::TARGET_DISPOSITION_OVERWRITE)); |
EXPECT_CALL(manager(), GetDownload(id)) |
.WillRepeatedly(Return(&item(index))); |
- EXPECT_CALL(item(index), AddObserver(_)) |
- .WillOnce(WithArg<0>( |
- Invoke(this, &DownloadHistoryTest::SetItemObserver))); |
- EXPECT_CALL(item(index), RemoveObserver(_)); |
EXPECT_CALL(item(index), IsTemporary()).WillRepeatedly(Return(false)); |
#if !defined(OS_ANDROID) |
new DownloadedByExtension(&item(index), by_extension_id, by_extension_name); |
@@ -457,7 +443,6 @@ class DownloadHistoryTest : public testing::Test { |
FakeHistoryAdapter* history_; |
scoped_ptr<DownloadHistory> download_history_; |
content::DownloadManager::Observer* manager_observer_; |
- content::DownloadItem::Observer* item_observer_; |
size_t download_created_index_; |
DISALLOW_COPY_AND_ASSIGN(DownloadHistoryTest); |
@@ -485,14 +470,14 @@ TEST_F(DownloadHistoryTest, DownloadHistoryTest_Load) { |
// Pretend that something changed on the item. |
EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
info.opened = true; |
ExpectDownloadUpdated(info); |
// Pretend that the user removed the item. |
IdSet ids; |
ids.insert(info.id); |
- item_observer()->OnDownloadRemoved(&item(0)); |
+ item(0).UpdateObserversOnRemoved(); |
ExpectDownloadsRemoved(ids); |
} |
@@ -516,14 +501,14 @@ TEST_F(DownloadHistoryTest, DownloadHistoryTest_Create) { |
// Pretend that something changed on the item. |
EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
info.opened = true; |
ExpectDownloadUpdated(info); |
// Pretend that the user removed the item. |
IdSet ids; |
ids.insert(info.id); |
- item_observer()->OnDownloadRemoved(&item(0)); |
+ item(0).UpdateObserversOnRemoved(); |
ExpectDownloadsRemoved(ids); |
} |
@@ -549,72 +534,72 @@ TEST_F(DownloadHistoryTest, DownloadHistoryTest_Update) { |
// current_path |
EXPECT_CALL(item(0), GetFullPath()).WillRepeatedly(ReturnRefOfCopy(new_path)); |
info.current_path = new_path; |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
ExpectDownloadUpdated(info); |
// target_path |
EXPECT_CALL(item(0), GetTargetFilePath()) |
.WillRepeatedly(ReturnRefOfCopy(new_path)); |
info.target_path = new_path; |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
ExpectDownloadUpdated(info); |
// end_time |
EXPECT_CALL(item(0), GetEndTime()).WillRepeatedly(Return(new_time)); |
info.end_time = new_time; |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
ExpectDownloadUpdated(info); |
// received_bytes |
EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(101)); |
info.received_bytes = 101; |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
ExpectDownloadUpdated(info); |
// total_bytes |
EXPECT_CALL(item(0), GetTotalBytes()).WillRepeatedly(Return(102)); |
info.total_bytes = 102; |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
ExpectDownloadUpdated(info); |
// etag |
EXPECT_CALL(item(0), GetETag()).WillRepeatedly(ReturnRefOfCopy(new_etag)); |
info.etag = new_etag; |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
ExpectDownloadUpdated(info); |
// last_modified |
EXPECT_CALL(item(0), GetLastModifiedTime()) |
.WillRepeatedly(ReturnRefOfCopy(new_last_modifed)); |
info.last_modified = new_last_modifed; |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
ExpectDownloadUpdated(info); |
// state |
EXPECT_CALL(item(0), GetState()) |
.WillRepeatedly(Return(content::DownloadItem::INTERRUPTED)); |
info.state = content::DownloadItem::INTERRUPTED; |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
ExpectDownloadUpdated(info); |
// danger_type |
EXPECT_CALL(item(0), GetDangerType()) |
.WillRepeatedly(Return(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT)); |
info.danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT; |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
ExpectDownloadUpdated(info); |
// interrupt_reason |
EXPECT_CALL(item(0), GetLastReason()) |
.WillRepeatedly(Return(content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED)); |
info.interrupt_reason = content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED; |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
ExpectDownloadUpdated(info); |
// opened |
EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); |
info.opened = true; |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
ExpectDownloadUpdated(info); |
} |
@@ -641,7 +626,7 @@ TEST_F(DownloadHistoryTest, DownloadHistoryTest_Temporary) { |
// Pretend the item was marked temporary. DownloadHistory should remove it |
// from history and start ignoring it. |
EXPECT_CALL(item(0), IsTemporary()).WillRepeatedly(Return(true)); |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
IdSet ids; |
ids.insert(info.id); |
ExpectDownloadsRemoved(ids); |
@@ -649,19 +634,19 @@ TEST_F(DownloadHistoryTest, DownloadHistoryTest_Temporary) { |
// Change something that would make DownloadHistory call UpdateDownload if the |
// item weren't temporary. |
EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(4200)); |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
ExpectNoDownloadUpdated(); |
// Changing a temporary item back to a non-temporary item should make |
// DownloadHistory call CreateDownload. |
EXPECT_CALL(item(0), IsTemporary()).WillRepeatedly(Return(false)); |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
info.received_bytes = 4200; |
ExpectDownloadCreated(info); |
EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(100)); |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
info.received_bytes = 100; |
ExpectDownloadUpdated(info); |
} |
@@ -689,7 +674,7 @@ TEST_F(DownloadHistoryTest, DownloadHistoryTest_RemoveWhileAdding) { |
// Instead of calling RemoveDownloads() immediately, DownloadHistory should |
// add the item's id to removed_while_adding_. Then, ItemAdded should |
// immediately remove the item's record from history. |
- item_observer()->OnDownloadRemoved(&item(0)); |
+ item(0).UpdateObserversOnRemoved(); |
EXPECT_CALL(manager(), GetDownload(item(0).GetId())) |
.WillRepeatedly(Return(static_cast<content::DownloadItem*>(NULL))); |
ExpectNoDownloadsRemoved(); |
@@ -732,8 +717,8 @@ TEST_F(DownloadHistoryTest, DownloadHistoryTest_Multiple) { |
IdSet ids; |
ids.insert(info0.id); |
ids.insert(info1.id); |
- item_observer()->OnDownloadRemoved(&item(0)); |
- item_observer()->OnDownloadRemoved(&item(1)); |
+ item(0).UpdateObserversOnRemoved(); |
+ item(1).UpdateObserversOnRemoved(); |
ExpectDownloadsRemoved(ids); |
} |
@@ -756,7 +741,7 @@ TEST_F(DownloadHistoryTest, DownloadHistoryTest_CreateFailed) { |
EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); |
EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(100)); |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
info.received_bytes = 100; |
ExpectDownloadCreated(info); |
EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
@@ -784,7 +769,7 @@ TEST_F(DownloadHistoryTest, DownloadHistoryTest_UpdateWhileAdding) { |
// Pretend that something changed on the item. |
EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); |
- item_observer()->OnDownloadUpdated(&item(0)); |
+ item(0).UpdateObservers(); |
FinishCreateDownload(); |
EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |