| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 MOCK_CONST_METHOD0(GetPersistentStoreInfo, | 150 MOCK_CONST_METHOD0(GetPersistentStoreInfo, |
| 151 content::DownloadPersistentStoreInfo()); | 151 content::DownloadPersistentStoreInfo()); |
| 152 MOCK_CONST_METHOD0(GetBrowserContext, content::BrowserContext*()); | 152 MOCK_CONST_METHOD0(GetBrowserContext, content::BrowserContext*()); |
| 153 MOCK_CONST_METHOD0(GetWebContents, content::WebContents*()); | 153 MOCK_CONST_METHOD0(GetWebContents, content::WebContents*()); |
| 154 MOCK_CONST_METHOD0(GetFileNameToReportUser, FilePath()); | 154 MOCK_CONST_METHOD0(GetFileNameToReportUser, FilePath()); |
| 155 MOCK_METHOD1(SetDisplayName, void(const FilePath&)); | 155 MOCK_METHOD1(SetDisplayName, void(const FilePath&)); |
| 156 MOCK_CONST_METHOD0(GetUserVerifiedFilePath, FilePath()); | 156 MOCK_CONST_METHOD0(GetUserVerifiedFilePath, FilePath()); |
| 157 MOCK_METHOD0(OffThreadCancel, void()); | 157 MOCK_METHOD0(OffThreadCancel, void()); |
| 158 MOCK_CONST_METHOD1(DebugString, std::string(bool)); | 158 MOCK_CONST_METHOD1(DebugString, std::string(bool)); |
| 159 MOCK_METHOD0(MockDownloadOpenForTesting, void()); | 159 MOCK_METHOD0(MockDownloadOpenForTesting, void()); |
| 160 MOCK_METHOD1(GetExternalData, ExternalData*(const void*)); | |
| 161 MOCK_CONST_METHOD1(GetExternalData, const ExternalData*(const void*)); | |
| 162 MOCK_METHOD2(SetExternalData, void(const void*, ExternalData*)); | |
| 163 }; | 160 }; |
| 164 | 161 |
| 165 class MockDownloadManagerDelegate : public content::DownloadManagerDelegate { | 162 class MockDownloadManagerDelegate : public content::DownloadManagerDelegate { |
| 166 public: | 163 public: |
| 167 MockDownloadManagerDelegate(); | 164 MockDownloadManagerDelegate(); |
| 168 virtual ~MockDownloadManagerDelegate(); | 165 virtual ~MockDownloadManagerDelegate(); |
| 169 | 166 |
| 170 MOCK_METHOD0(Shutdown, void()); | 167 MOCK_METHOD0(Shutdown, void()); |
| 171 MOCK_METHOD0(GetNextId, content::DownloadId()); | 168 MOCK_METHOD0(GetNextId, content::DownloadId()); |
| 172 MOCK_METHOD2(DetermineDownloadTarget, | 169 MOCK_METHOD2(DetermineDownloadTarget, |
| 173 bool(DownloadItem* item, | 170 bool(DownloadItem* item, |
| 174 const content::DownloadTargetCallback&)); | 171 const content::DownloadTargetCallback&)); |
| 175 MOCK_METHOD0(GetAlternativeWebContentsToNotifyForDownload, WebContents*()); | 172 MOCK_METHOD0(GetAlternativeWebContentsToNotifyForDownload, WebContents*()); |
| 176 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const FilePath&)); | 173 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const FilePath&)); |
| 177 MOCK_METHOD2(ShouldCompleteDownload, bool( | 174 MOCK_METHOD2(ShouldCompleteDownload, bool( |
| 178 DownloadItem*, const base::Closure&)); | 175 DownloadItem*, const base::Closure&)); |
| 179 MOCK_METHOD1(ShouldOpenDownload, bool(DownloadItem*)); | 176 MOCK_METHOD1(ShouldOpenDownload, bool(DownloadItem*)); |
| 180 MOCK_METHOD0(GenerateFileHash, bool()); | 177 MOCK_METHOD0(GenerateFileHash, bool()); |
| 181 MOCK_METHOD1(AddItemToPersistentStore, void(DownloadItem*)); | |
| 182 MOCK_METHOD1(UpdateItemInPersistentStore, void(DownloadItem*)); | |
| 183 MOCK_METHOD2(UpdatePathForItemInPersistentStore, | |
| 184 void(DownloadItem*, const FilePath&)); | |
| 185 MOCK_METHOD1(RemoveItemFromPersistentStore, void(DownloadItem*)); | |
| 186 MOCK_METHOD2(RemoveItemsFromPersistentStoreBetween, void( | |
| 187 base::Time remove_begin, base::Time remove_end)); | |
| 188 MOCK_METHOD4(GetSaveDir, void(WebContents*, FilePath*, FilePath*, bool*)); | 178 MOCK_METHOD4(GetSaveDir, void(WebContents*, FilePath*, FilePath*, bool*)); |
| 189 MOCK_METHOD5(ChooseSavePath, void( | 179 MOCK_METHOD5(ChooseSavePath, void( |
| 190 WebContents*, const FilePath&, const FilePath::StringType&, | 180 WebContents*, const FilePath&, const FilePath::StringType&, |
| 191 bool, const content::SavePackagePathPickedCallback&)); | 181 bool, const content::SavePackagePathPickedCallback&)); |
| 192 }; | 182 }; |
| 193 | 183 |
| 194 MockDownloadManagerDelegate::MockDownloadManagerDelegate() {} | 184 MockDownloadManagerDelegate::MockDownloadManagerDelegate() {} |
| 195 | 185 |
| 196 MockDownloadManagerDelegate::~MockDownloadManagerDelegate() {} | 186 MockDownloadManagerDelegate::~MockDownloadManagerDelegate() {} |
| 197 | 187 |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 | 624 |
| 635 // Does DownloadStopped remove Download from appropriate queues? | 625 // Does DownloadStopped remove Download from appropriate queues? |
| 636 // This test tests persisted downloads. | 626 // This test tests persisted downloads. |
| 637 TEST_F(DownloadManagerTest, OnDownloadStopped_Persisted) { | 627 TEST_F(DownloadManagerTest, OnDownloadStopped_Persisted) { |
| 638 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | 628 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 639 .WillOnce(Return()); | 629 .WillOnce(Return()); |
| 640 // Put a mock we have a handle to on the download manager. | 630 // Put a mock we have a handle to on the download manager. |
| 641 MockDownloadItemImpl& item(AddItemToManager()); | 631 MockDownloadItemImpl& item(AddItemToManager()); |
| 642 int download_id = item.GetId(); | 632 int download_id = item.GetId(); |
| 643 int64 db_handle = 0x7; | 633 int64 db_handle = 0x7; |
| 644 EXPECT_CALL(item, GetExternalData(_)) | |
| 645 .WillOnce(Return(static_cast<DownloadItem::ExternalData*>(NULL))); | |
| 646 EXPECT_CALL(GetMockObserver(), ModelChanged(download_manager_.get())) | 634 EXPECT_CALL(GetMockObserver(), ModelChanged(download_manager_.get())) |
| 647 .WillOnce(Return()); | 635 .WillOnce(Return()); |
| 648 AddItemToHistory(item, db_handle); | 636 AddItemToHistory(item, db_handle); |
| 649 | 637 |
| 650 EXPECT_CALL(item, IsPersisted()) | 638 EXPECT_CALL(item, IsPersisted()) |
| 651 .WillRepeatedly(Return(true)); | 639 .WillRepeatedly(Return(true)); |
| 652 EXPECT_CALL(GetMockDownloadManagerDelegate(), | |
| 653 UpdateItemInPersistentStore(&item)); | |
| 654 EXPECT_CALL(item, GetState()) | 640 EXPECT_CALL(item, GetState()) |
| 655 .WillRepeatedly(Return(DownloadItem::CANCELLED)); | 641 .WillRepeatedly(Return(DownloadItem::CANCELLED)); |
| 656 EXPECT_CALL(item, GetDbHandle()) | 642 EXPECT_CALL(item, GetDbHandle()) |
| 657 .WillRepeatedly(Return(db_handle)); | 643 .WillRepeatedly(Return(db_handle)); |
| 658 | 644 |
| 659 EXPECT_CALL(item, OffThreadCancel()); | 645 EXPECT_CALL(item, OffThreadCancel()); |
| 660 DownloadStopped(&item); | 646 DownloadStopped(&item); |
| 661 EXPECT_EQ(NULL, download_manager_->GetActiveDownloadItem(download_id)); | 647 EXPECT_EQ(NULL, download_manager_->GetActiveDownloadItem(download_id)); |
| 662 } | 648 } |
| OLD | NEW |