| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // has a |default_download_directory| that matches |download_directory|. | 61 // has a |default_download_directory| that matches |download_directory|. |
| 62 MATCHER_P2(DownloadCreateInfoWithDefaultPath, info, download_directory, "") { | 62 MATCHER_P2(DownloadCreateInfoWithDefaultPath, info, download_directory, "") { |
| 63 return arg == info && | 63 return arg == info && |
| 64 arg->default_download_directory == download_directory; | 64 arg->default_download_directory == download_directory; |
| 65 } | 65 } |
| 66 | 66 |
| 67 class MockDownloadItemImpl : public DownloadItemImpl { | 67 class MockDownloadItemImpl : public DownloadItemImpl { |
| 68 public: | 68 public: |
| 69 // Use history constructor for minimal base object. | 69 // Use history constructor for minimal base object. |
| 70 MockDownloadItemImpl(DownloadItemImplDelegate* delegate) | 70 MockDownloadItemImpl(DownloadItemImplDelegate* delegate) |
| 71 : DownloadItemImpl(delegate, content::DownloadId(), | 71 : DownloadItemImpl( |
| 72 content::DownloadPersistentStoreInfo(), | 72 delegate, |
| 73 net::BoundNetLog()) {} | 73 content::DownloadId(), |
| 74 FilePath(), |
| 75 GURL(), |
| 76 GURL(), |
| 77 base::Time(), |
| 78 base::Time(), |
| 79 0, |
| 80 0, |
| 81 DownloadItem::IN_PROGRESS, |
| 82 false, |
| 83 net::BoundNetLog()) {} |
| 74 virtual ~MockDownloadItemImpl() {} | 84 virtual ~MockDownloadItemImpl() {} |
| 75 | 85 |
| 76 MOCK_METHOD4(OnDownloadTargetDetermined, | 86 MOCK_METHOD4(OnDownloadTargetDetermined, |
| 77 void(const FilePath&, TargetDisposition, | 87 void(const FilePath&, TargetDisposition, |
| 78 content::DownloadDangerType, const FilePath&)); | 88 content::DownloadDangerType, const FilePath&)); |
| 79 MOCK_METHOD1(AddObserver, void(content::DownloadItem::Observer*)); | 89 MOCK_METHOD1(AddObserver, void(content::DownloadItem::Observer*)); |
| 80 MOCK_METHOD1(RemoveObserver, void(content::DownloadItem::Observer*)); | 90 MOCK_METHOD1(RemoveObserver, void(content::DownloadItem::Observer*)); |
| 81 MOCK_METHOD0(UpdateObservers, void()); | 91 MOCK_METHOD0(UpdateObservers, void()); |
| 82 MOCK_METHOD0(CanShowInFolder, bool()); | 92 MOCK_METHOD0(CanShowInFolder, bool()); |
| 83 MOCK_METHOD0(CanOpenDownload, bool()); | 93 MOCK_METHOD0(CanOpenDownload, bool()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 MOCK_CONST_METHOD0(GetReferrerCharset, std::string()); | 134 MOCK_CONST_METHOD0(GetReferrerCharset, std::string()); |
| 125 MOCK_CONST_METHOD0(GetRemoteAddress, std::string()); | 135 MOCK_CONST_METHOD0(GetRemoteAddress, std::string()); |
| 126 MOCK_CONST_METHOD0(GetTotalBytes, int64()); | 136 MOCK_CONST_METHOD0(GetTotalBytes, int64()); |
| 127 MOCK_CONST_METHOD0(GetReceivedBytes, int64()); | 137 MOCK_CONST_METHOD0(GetReceivedBytes, int64()); |
| 128 MOCK_CONST_METHOD0(GetHashState, const std::string&()); | 138 MOCK_CONST_METHOD0(GetHashState, const std::string&()); |
| 129 MOCK_CONST_METHOD0(GetHash, const std::string&()); | 139 MOCK_CONST_METHOD0(GetHash, const std::string&()); |
| 130 MOCK_CONST_METHOD0(GetId, int32()); | 140 MOCK_CONST_METHOD0(GetId, int32()); |
| 131 MOCK_CONST_METHOD0(GetGlobalId, content::DownloadId()); | 141 MOCK_CONST_METHOD0(GetGlobalId, content::DownloadId()); |
| 132 MOCK_CONST_METHOD0(GetStartTime, base::Time()); | 142 MOCK_CONST_METHOD0(GetStartTime, base::Time()); |
| 133 MOCK_CONST_METHOD0(GetEndTime, base::Time()); | 143 MOCK_CONST_METHOD0(GetEndTime, base::Time()); |
| 134 MOCK_METHOD0(SetIsPersisted, void()); | |
| 135 MOCK_CONST_METHOD0(IsPersisted, bool()); | |
| 136 MOCK_METHOD1(SetDbHandle, void(int64)); | |
| 137 MOCK_CONST_METHOD0(GetDbHandle, int64()); | |
| 138 MOCK_METHOD0(GetDownloadManager, content::DownloadManager*()); | 144 MOCK_METHOD0(GetDownloadManager, content::DownloadManager*()); |
| 139 MOCK_CONST_METHOD0(IsPaused, bool()); | 145 MOCK_CONST_METHOD0(IsPaused, bool()); |
| 140 MOCK_CONST_METHOD0(GetOpenWhenComplete, bool()); | 146 MOCK_CONST_METHOD0(GetOpenWhenComplete, bool()); |
| 141 MOCK_METHOD1(SetOpenWhenComplete, void(bool)); | 147 MOCK_METHOD1(SetOpenWhenComplete, void(bool)); |
| 142 MOCK_CONST_METHOD0(GetFileExternallyRemoved, bool()); | 148 MOCK_CONST_METHOD0(GetFileExternallyRemoved, bool()); |
| 143 MOCK_CONST_METHOD0(GetSafetyState, SafetyState()); | 149 MOCK_CONST_METHOD0(GetSafetyState, SafetyState()); |
| 144 MOCK_CONST_METHOD0(GetDangerType, content::DownloadDangerType()); | 150 MOCK_CONST_METHOD0(GetDangerType, content::DownloadDangerType()); |
| 145 MOCK_CONST_METHOD0(IsDangerous, bool()); | 151 MOCK_CONST_METHOD0(IsDangerous, bool()); |
| 146 MOCK_METHOD0(GetAutoOpened, bool()); | 152 MOCK_METHOD0(GetAutoOpened, bool()); |
| 147 MOCK_CONST_METHOD0(GetForcedFilePath, const FilePath&()); | 153 MOCK_CONST_METHOD0(GetForcedFilePath, const FilePath&()); |
| 148 MOCK_CONST_METHOD0(HasUserGesture, bool()); | 154 MOCK_CONST_METHOD0(HasUserGesture, bool()); |
| 149 MOCK_CONST_METHOD0(GetTransitionType, content::PageTransition()); | 155 MOCK_CONST_METHOD0(GetTransitionType, content::PageTransition()); |
| 150 MOCK_CONST_METHOD0(IsTemporary, bool()); | 156 MOCK_CONST_METHOD0(IsTemporary, bool()); |
| 151 MOCK_METHOD1(SetIsTemporary, void(bool)); | 157 MOCK_METHOD1(SetIsTemporary, void(bool)); |
| 152 MOCK_METHOD1(SetOpened, void(bool)); | 158 MOCK_METHOD1(SetOpened, void(bool)); |
| 153 MOCK_CONST_METHOD0(GetOpened, bool()); | 159 MOCK_CONST_METHOD0(GetOpened, bool()); |
| 154 MOCK_CONST_METHOD0(GetLastModifiedTime, const std::string&()); | 160 MOCK_CONST_METHOD0(GetLastModifiedTime, const std::string&()); |
| 155 MOCK_CONST_METHOD0(GetETag, const std::string&()); | 161 MOCK_CONST_METHOD0(GetETag, const std::string&()); |
| 156 MOCK_CONST_METHOD0(GetLastReason, DownloadInterruptReason()); | 162 MOCK_CONST_METHOD0(GetLastReason, DownloadInterruptReason()); |
| 157 MOCK_CONST_METHOD0(GetPersistentStoreInfo, | |
| 158 content::DownloadPersistentStoreInfo()); | |
| 159 MOCK_CONST_METHOD0(GetBrowserContext, content::BrowserContext*()); | 163 MOCK_CONST_METHOD0(GetBrowserContext, content::BrowserContext*()); |
| 160 MOCK_CONST_METHOD0(GetWebContents, content::WebContents*()); | 164 MOCK_CONST_METHOD0(GetWebContents, content::WebContents*()); |
| 161 MOCK_CONST_METHOD0(GetFileNameToReportUser, FilePath()); | 165 MOCK_CONST_METHOD0(GetFileNameToReportUser, FilePath()); |
| 162 MOCK_METHOD1(SetDisplayName, void(const FilePath&)); | 166 MOCK_METHOD1(SetDisplayName, void(const FilePath&)); |
| 163 MOCK_CONST_METHOD0(GetUserVerifiedFilePath, FilePath()); | 167 MOCK_CONST_METHOD0(GetUserVerifiedFilePath, FilePath()); |
| 164 MOCK_METHOD0(OffThreadCancel, void()); | 168 MOCK_METHOD0(OffThreadCancel, void()); |
| 165 MOCK_CONST_METHOD1(DebugString, std::string(bool)); | 169 MOCK_CONST_METHOD1(DebugString, std::string(bool)); |
| 166 MOCK_METHOD0(MockDownloadOpenForTesting, void()); | 170 MOCK_METHOD0(MockDownloadOpenForTesting, void()); |
| 167 }; | 171 }; |
| 168 | 172 |
| 169 class MockDownloadManagerDelegate : public content::DownloadManagerDelegate { | 173 class MockDownloadManagerDelegate : public content::DownloadManagerDelegate { |
| 170 public: | 174 public: |
| 171 MockDownloadManagerDelegate(); | 175 MockDownloadManagerDelegate(); |
| 172 virtual ~MockDownloadManagerDelegate(); | 176 virtual ~MockDownloadManagerDelegate(); |
| 173 | 177 |
| 174 MOCK_METHOD0(Shutdown, void()); | 178 MOCK_METHOD0(Shutdown, void()); |
| 175 MOCK_METHOD0(GetNextId, content::DownloadId()); | 179 MOCK_METHOD0(GetNextId, content::DownloadId()); |
| 176 MOCK_METHOD2(DetermineDownloadTarget, | 180 MOCK_METHOD2(DetermineDownloadTarget, |
| 177 bool(DownloadItem* item, | 181 bool(DownloadItem* item, |
| 178 const content::DownloadTargetCallback&)); | 182 const content::DownloadTargetCallback&)); |
| 179 MOCK_METHOD0(GetAlternativeWebContentsToNotifyForDownload, WebContents*()); | 183 MOCK_METHOD0(GetAlternativeWebContentsToNotifyForDownload, WebContents*()); |
| 180 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const FilePath&)); | 184 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const FilePath&)); |
| 181 MOCK_METHOD2(ShouldCompleteDownload, bool( | 185 MOCK_METHOD2(ShouldCompleteDownload, bool( |
| 182 DownloadItem*, const base::Closure&)); | 186 DownloadItem*, const base::Closure&)); |
| 183 MOCK_METHOD1(ShouldOpenDownload, bool(DownloadItem*)); | 187 MOCK_METHOD1(ShouldOpenDownload, bool(DownloadItem*)); |
| 184 MOCK_METHOD0(GenerateFileHash, bool()); | 188 MOCK_METHOD0(GenerateFileHash, bool()); |
| 185 MOCK_METHOD1(AddItemToPersistentStore, void(DownloadItem*)); | |
| 186 MOCK_METHOD1(UpdateItemInPersistentStore, void(DownloadItem*)); | |
| 187 MOCK_METHOD2(UpdatePathForItemInPersistentStore, | |
| 188 void(DownloadItem*, const FilePath&)); | |
| 189 MOCK_METHOD1(RemoveItemFromPersistentStore, void(DownloadItem*)); | |
| 190 MOCK_METHOD2(RemoveItemsFromPersistentStoreBetween, void( | |
| 191 base::Time remove_begin, base::Time remove_end)); | |
| 192 MOCK_METHOD4(GetSaveDir, void(content::BrowserContext*, | 189 MOCK_METHOD4(GetSaveDir, void(content::BrowserContext*, |
| 193 FilePath*, FilePath*, bool*)); | 190 FilePath*, FilePath*, bool*)); |
| 194 MOCK_METHOD5(ChooseSavePath, void( | 191 MOCK_METHOD5(ChooseSavePath, void( |
| 195 WebContents*, const FilePath&, const FilePath::StringType&, | 192 WebContents*, const FilePath&, const FilePath::StringType&, |
| 196 bool, const content::SavePackagePathPickedCallback&)); | 193 bool, const content::SavePackagePathPickedCallback&)); |
| 197 }; | 194 }; |
| 198 | 195 |
| 199 MockDownloadManagerDelegate::MockDownloadManagerDelegate() {} | 196 MockDownloadManagerDelegate::MockDownloadManagerDelegate() {} |
| 200 | 197 |
| 201 MockDownloadManagerDelegate::~MockDownloadManagerDelegate() {} | 198 MockDownloadManagerDelegate::~MockDownloadManagerDelegate() {} |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 MockDownloadItemImpl* PopItem(); | 262 MockDownloadItemImpl* PopItem(); |
| 266 | 263 |
| 267 // Should be called when the item of this id is removed so that | 264 // Should be called when the item of this id is removed so that |
| 268 // we don't keep dangling pointers. | 265 // we don't keep dangling pointers. |
| 269 void RemoveItem(int id); | 266 void RemoveItem(int id); |
| 270 | 267 |
| 271 // Overridden methods from DownloadItemFactory. | 268 // Overridden methods from DownloadItemFactory. |
| 272 virtual DownloadItemImpl* CreatePersistedItem( | 269 virtual DownloadItemImpl* CreatePersistedItem( |
| 273 DownloadItemImplDelegate* delegate, | 270 DownloadItemImplDelegate* delegate, |
| 274 content::DownloadId download_id, | 271 content::DownloadId download_id, |
| 275 const content::DownloadPersistentStoreInfo& info, | 272 const FilePath& path, |
| 273 const GURL& url, |
| 274 const GURL& referrer_url, |
| 275 const base::Time& start_time, |
| 276 const base::Time& end_time, |
| 277 int64 received_bytes, |
| 278 int64 total_bytes, |
| 279 DownloadItem::DownloadState state, |
| 280 bool opened, |
| 276 const net::BoundNetLog& bound_net_log) OVERRIDE; | 281 const net::BoundNetLog& bound_net_log) OVERRIDE; |
| 277 virtual DownloadItemImpl* CreateActiveItem( | 282 virtual DownloadItemImpl* CreateActiveItem( |
| 278 DownloadItemImplDelegate* delegate, | 283 DownloadItemImplDelegate* delegate, |
| 279 const DownloadCreateInfo& info, | 284 const DownloadCreateInfo& info, |
| 280 scoped_ptr<DownloadRequestHandleInterface> request_handle, | 285 scoped_ptr<DownloadRequestHandleInterface> request_handle, |
| 281 const net::BoundNetLog& bound_net_log) OVERRIDE; | 286 const net::BoundNetLog& bound_net_log) OVERRIDE; |
| 282 virtual DownloadItemImpl* CreateSavePageItem( | 287 virtual DownloadItemImpl* CreateSavePageItem( |
| 283 DownloadItemImplDelegate* delegate, | 288 DownloadItemImplDelegate* delegate, |
| 284 const FilePath& path, | 289 const FilePath& path, |
| 285 const GURL& url, | 290 const GURL& url, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 316 } | 321 } |
| 317 | 322 |
| 318 void MockDownloadItemFactory::RemoveItem(int id) { | 323 void MockDownloadItemFactory::RemoveItem(int id) { |
| 319 DCHECK(items_.find(id) != items_.end()); | 324 DCHECK(items_.find(id) != items_.end()); |
| 320 items_.erase(id); | 325 items_.erase(id); |
| 321 } | 326 } |
| 322 | 327 |
| 323 DownloadItemImpl* MockDownloadItemFactory::CreatePersistedItem( | 328 DownloadItemImpl* MockDownloadItemFactory::CreatePersistedItem( |
| 324 DownloadItemImplDelegate* delegate, | 329 DownloadItemImplDelegate* delegate, |
| 325 content::DownloadId download_id, | 330 content::DownloadId download_id, |
| 326 const content::DownloadPersistentStoreInfo& info, | 331 const FilePath& path, |
| 332 const GURL& url, |
| 333 const GURL& referrer_url, |
| 334 const base::Time& start_time, |
| 335 const base::Time& end_time, |
| 336 int64 received_bytes, |
| 337 int64 total_bytes, |
| 338 DownloadItem::DownloadState state, |
| 339 bool opened, |
| 327 const net::BoundNetLog& bound_net_log) { | 340 const net::BoundNetLog& bound_net_log) { |
| 328 int local_id = download_id.local(); | 341 int local_id = download_id.local(); |
| 329 DCHECK(items_.find(local_id) == items_.end()); | 342 DCHECK(items_.find(local_id) == items_.end()); |
| 330 | 343 |
| 331 MockDownloadItemImpl* result = | 344 MockDownloadItemImpl* result = |
| 332 new StrictMock<MockDownloadItemImpl>(&item_delegate_); | 345 new StrictMock<MockDownloadItemImpl>(&item_delegate_); |
| 333 EXPECT_CALL(*result, GetId()) | 346 EXPECT_CALL(*result, GetId()) |
| 334 .WillRepeatedly(Return(local_id)); | 347 .WillRepeatedly(Return(local_id)); |
| 335 items_[local_id] = result; | 348 items_[local_id] = result; |
| 336 | 349 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 | 537 |
| 525 MockDownloadManagerObserver& GetMockObserver() { | 538 MockDownloadManagerObserver& GetMockObserver() { |
| 526 return *observer_; | 539 return *observer_; |
| 527 } | 540 } |
| 528 | 541 |
| 529 // Probe at private internals. | 542 // Probe at private internals. |
| 530 void DownloadStopped(DownloadItemImpl* item) { | 543 void DownloadStopped(DownloadItemImpl* item) { |
| 531 download_manager_->DownloadStopped(item); | 544 download_manager_->DownloadStopped(item); |
| 532 } | 545 } |
| 533 | 546 |
| 534 void AddItemToHistory(MockDownloadItemImpl& item, int64 db_handle) { | |
| 535 // For DCHECK in AddDownloadItemToHistory. Don't want to use | |
| 536 // WillRepeatedly as it may have to return true after this. | |
| 537 if (DCHECK_IS_ON()) | |
| 538 EXPECT_CALL(item, IsPersisted()) | |
| 539 .WillRepeatedly(Return(false)); | |
| 540 | |
| 541 EXPECT_CALL(item, SetDbHandle(db_handle)); | |
| 542 EXPECT_CALL(item, SetIsPersisted()); | |
| 543 EXPECT_CALL(item, GetDbHandle()) | |
| 544 .WillRepeatedly(Return(db_handle)); | |
| 545 | |
| 546 // Null out ShowDownloadInBrowser | |
| 547 EXPECT_CALL(item, GetWebContents()) | |
| 548 .WillOnce(Return(static_cast<WebContents*>(NULL))); | |
| 549 EXPECT_CALL(GetMockDownloadManagerDelegate(), | |
| 550 GetAlternativeWebContentsToNotifyForDownload()) | |
| 551 .WillOnce(Return(static_cast<WebContents*>(NULL))); | |
| 552 | |
| 553 EXPECT_CALL(item, IsInProgress()) | |
| 554 .WillOnce(Return(true)); | |
| 555 | |
| 556 // Null out MaybeCompleteDownload | |
| 557 EXPECT_CALL(item, AllDataSaved()) | |
| 558 .WillOnce(Return(false)); | |
| 559 | |
| 560 download_manager_->OnItemAddedToPersistentStore(item.GetId(), db_handle); | |
| 561 } | |
| 562 | |
| 563 protected: | 547 protected: |
| 564 // Key test variable; we'll keep it available to sub-classes. | 548 // Key test variable; we'll keep it available to sub-classes. |
| 565 scoped_refptr<DownloadManagerImpl> download_manager_; | 549 scoped_refptr<DownloadManagerImpl> download_manager_; |
| 566 | 550 |
| 567 private: | 551 private: |
| 568 MessageLoopForUI message_loop_; | 552 MessageLoopForUI message_loop_; |
| 569 content::TestBrowserThread ui_thread_; | 553 content::TestBrowserThread ui_thread_; |
| 570 content::TestBrowserThread file_thread_; | 554 content::TestBrowserThread file_thread_; |
| 571 base::WeakPtr<MockDownloadItemFactory> mock_download_item_factory_; | 555 base::WeakPtr<MockDownloadItemFactory> mock_download_item_factory_; |
| 572 scoped_ptr<MockDownloadManagerDelegate> mock_download_manager_delegate_; | 556 scoped_ptr<MockDownloadManagerDelegate> mock_download_manager_delegate_; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 | 602 |
| 619 content::DownloadInterruptReason reason( | 603 content::DownloadInterruptReason reason( |
| 620 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); | 604 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); |
| 621 | 605 |
| 622 EXPECT_CALL(item, Interrupt(reason)); | 606 EXPECT_CALL(item, Interrupt(reason)); |
| 623 download_manager_->OnDownloadInterrupted(download_id, reason); | 607 download_manager_->OnDownloadInterrupted(download_id, reason); |
| 624 EXPECT_EQ(&item, download_manager_->GetActiveDownloadItem(download_id)); | 608 EXPECT_EQ(&item, download_manager_->GetActiveDownloadItem(download_id)); |
| 625 } | 609 } |
| 626 | 610 |
| 627 // Does DownloadStopped remove Download from appropriate queues? | 611 // Does DownloadStopped remove Download from appropriate queues? |
| 628 // This test tests non-persisted downloads. | 612 TEST_F(DownloadManagerTest, OnDownloadStopped) { |
| 629 TEST_F(DownloadManagerTest, OnDownloadStopped_NonPersisted) { | |
| 630 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | 613 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 631 .WillOnce(Return()); | 614 .WillOnce(Return()); |
| 632 // Put a mock we have a handle to on the download manager. | 615 // Put a mock we have a handle to on the download manager. |
| 633 MockDownloadItemImpl& item(AddItemToManager()); | 616 MockDownloadItemImpl& item(AddItemToManager()); |
| 634 | 617 |
| 635 EXPECT_CALL(item, IsPersisted()) | |
| 636 .WillRepeatedly(Return(false)); | |
| 637 EXPECT_CALL(item, GetState()) | 618 EXPECT_CALL(item, GetState()) |
| 638 .WillRepeatedly(Return(DownloadItem::CANCELLED)); | 619 .WillRepeatedly(Return(DownloadItem::CANCELLED)); |
| 639 EXPECT_CALL(item, GetDbHandle()) | |
| 640 .WillRepeatedly(Return(DownloadItem::kUninitializedHandle)); | |
| 641 | 620 |
| 642 EXPECT_CALL(item, OffThreadCancel()); | 621 EXPECT_CALL(item, OffThreadCancel()); |
| 643 DownloadStopped(&item); | 622 DownloadStopped(&item); |
| 644 // TODO(rdsmith): Confirm that the download item is no longer on the | 623 // TODO(rdsmith): Confirm that the download item is no longer on the |
| 645 // active list by calling download_manager_->GetActiveDownloadItem(id). | 624 // active list by calling download_manager_->GetActiveDownloadItem(id). |
| 646 // Currently, the item is left on the active list for rendez-vous with | 625 // Currently, the item is left on the active list for rendez-vous with |
| 647 // the history system :-{. | 626 // the history system :-{. |
| 648 } | 627 } |
| 649 | |
| 650 // Does DownloadStopped remove Download from appropriate queues? | |
| 651 // This test tests persisted downloads. | |
| 652 TEST_F(DownloadManagerTest, OnDownloadStopped_Persisted) { | |
| 653 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | |
| 654 .WillOnce(Return()); | |
| 655 // Put a mock we have a handle to on the download manager. | |
| 656 MockDownloadItemImpl& item(AddItemToManager()); | |
| 657 int download_id = item.GetId(); | |
| 658 int64 db_handle = 0x7; | |
| 659 EXPECT_CALL(GetMockObserver(), ModelChanged(download_manager_.get())) | |
| 660 .WillOnce(Return()); | |
| 661 AddItemToHistory(item, db_handle); | |
| 662 | |
| 663 EXPECT_CALL(item, IsPersisted()) | |
| 664 .WillRepeatedly(Return(true)); | |
| 665 EXPECT_CALL(GetMockDownloadManagerDelegate(), | |
| 666 UpdateItemInPersistentStore(&item)); | |
| 667 EXPECT_CALL(item, GetState()) | |
| 668 .WillRepeatedly(Return(DownloadItem::CANCELLED)); | |
| 669 EXPECT_CALL(item, GetDbHandle()) | |
| 670 .WillRepeatedly(Return(db_handle)); | |
| 671 | |
| 672 EXPECT_CALL(item, OffThreadCancel()); | |
| 673 DownloadStopped(&item); | |
| 674 EXPECT_EQ(NULL, download_manager_->GetActiveDownloadItem(download_id)); | |
| 675 } | |
| OLD | NEW |