| 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/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 class MockDownloadManagerDelegate : public DownloadManagerDelegate { | 174 class MockDownloadManagerDelegate : public DownloadManagerDelegate { |
| 175 public: | 175 public: |
| 176 MockDownloadManagerDelegate(); | 176 MockDownloadManagerDelegate(); |
| 177 virtual ~MockDownloadManagerDelegate(); | 177 virtual ~MockDownloadManagerDelegate(); |
| 178 | 178 |
| 179 MOCK_METHOD0(Shutdown, void()); | 179 MOCK_METHOD0(Shutdown, void()); |
| 180 MOCK_METHOD0(GetNextId, DownloadId()); | 180 MOCK_METHOD0(GetNextId, DownloadId()); |
| 181 MOCK_METHOD2(DetermineDownloadTarget, | 181 MOCK_METHOD2(DetermineDownloadTarget, |
| 182 bool(DownloadItem* item, | 182 bool(DownloadItem* item, |
| 183 const DownloadTargetCallback&)); | 183 const DownloadTargetCallback&)); |
| 184 MOCK_METHOD0(GetAlternativeWebContentsToNotifyForDownload, WebContents*()); | |
| 185 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const base::FilePath&)); | 184 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const base::FilePath&)); |
| 186 MOCK_METHOD2(ShouldCompleteDownload, | 185 MOCK_METHOD2(ShouldCompleteDownload, |
| 187 bool(DownloadItem*, const base::Closure&)); | 186 bool(DownloadItem*, const base::Closure&)); |
| 188 MOCK_METHOD2(ShouldOpenDownload, | 187 MOCK_METHOD2(ShouldOpenDownload, |
| 189 bool(DownloadItem*, const DownloadOpenDelayedCallback&)); | 188 bool(DownloadItem*, const DownloadOpenDelayedCallback&)); |
| 190 MOCK_METHOD0(GenerateFileHash, bool()); | 189 MOCK_METHOD0(GenerateFileHash, bool()); |
| 191 MOCK_METHOD4(GetSaveDir, void(BrowserContext*, | 190 MOCK_METHOD4(GetSaveDir, void(BrowserContext*, |
| 192 base::FilePath*, base::FilePath*, bool*)); | 191 base::FilePath*, base::FilePath*, bool*)); |
| 193 MOCK_METHOD5(ChooseSavePath, void( | 192 MOCK_METHOD5(ChooseSavePath, void( |
| 194 WebContents*, const base::FilePath&, const base::FilePath::StringType&, | 193 WebContents*, const base::FilePath&, const base::FilePath::StringType&, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 virtual DownloadItemImpl* CreateActiveItem( | 240 virtual DownloadItemImpl* CreateActiveItem( |
| 242 DownloadItemImplDelegate* delegate, | 241 DownloadItemImplDelegate* delegate, |
| 243 const DownloadCreateInfo& info, | 242 const DownloadCreateInfo& info, |
| 244 const net::BoundNetLog& bound_net_log) OVERRIDE; | 243 const net::BoundNetLog& bound_net_log) OVERRIDE; |
| 245 virtual DownloadItemImpl* CreateSavePageItem( | 244 virtual DownloadItemImpl* CreateSavePageItem( |
| 246 DownloadItemImplDelegate* delegate, | 245 DownloadItemImplDelegate* delegate, |
| 247 const base::FilePath& path, | 246 const base::FilePath& path, |
| 248 const GURL& url, | 247 const GURL& url, |
| 249 DownloadId download_id, | 248 DownloadId download_id, |
| 250 const std::string& mime_type, | 249 const std::string& mime_type, |
| 250 scoped_ptr<DownloadRequestHandleInterface> request_handle, |
| 251 const net::BoundNetLog& bound_net_log) OVERRIDE; | 251 const net::BoundNetLog& bound_net_log) OVERRIDE; |
| 252 | 252 |
| 253 private: | 253 private: |
| 254 std::map<int32, MockDownloadItemImpl*> items_; | 254 std::map<int32, MockDownloadItemImpl*> items_; |
| 255 DownloadItemImplDelegate item_delegate_; | 255 DownloadItemImplDelegate item_delegate_; |
| 256 | 256 |
| 257 DISALLOW_COPY_AND_ASSIGN(MockDownloadItemFactory); | 257 DISALLOW_COPY_AND_ASSIGN(MockDownloadItemFactory); |
| 258 }; | 258 }; |
| 259 | 259 |
| 260 MockDownloadItemFactory::MockDownloadItemFactory() {} | 260 MockDownloadItemFactory::MockDownloadItemFactory() {} |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 332 |
| 333 return result; | 333 return result; |
| 334 } | 334 } |
| 335 | 335 |
| 336 DownloadItemImpl* MockDownloadItemFactory::CreateSavePageItem( | 336 DownloadItemImpl* MockDownloadItemFactory::CreateSavePageItem( |
| 337 DownloadItemImplDelegate* delegate, | 337 DownloadItemImplDelegate* delegate, |
| 338 const base::FilePath& path, | 338 const base::FilePath& path, |
| 339 const GURL& url, | 339 const GURL& url, |
| 340 DownloadId download_id, | 340 DownloadId download_id, |
| 341 const std::string& mime_type, | 341 const std::string& mime_type, |
| 342 scoped_ptr<DownloadRequestHandleInterface> request_handle, |
| 342 const net::BoundNetLog& bound_net_log) { | 343 const net::BoundNetLog& bound_net_log) { |
| 343 int local_id = download_id.local(); | 344 int local_id = download_id.local(); |
| 344 DCHECK(items_.find(local_id) == items_.end()); | 345 DCHECK(items_.find(local_id) == items_.end()); |
| 345 | 346 |
| 346 MockDownloadItemImpl* result = | 347 MockDownloadItemImpl* result = |
| 347 new StrictMock<MockDownloadItemImpl>(&item_delegate_); | 348 new StrictMock<MockDownloadItemImpl>(&item_delegate_); |
| 348 EXPECT_CALL(*result, GetId()) | 349 EXPECT_CALL(*result, GetId()) |
| 349 .WillRepeatedly(Return(local_id)); | 350 .WillRepeatedly(Return(local_id)); |
| 350 items_[local_id] = result; | 351 items_[local_id] = result; |
| 351 | 352 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 intermediate_path_ = intermediate_path; | 544 intermediate_path_ = intermediate_path; |
| 544 } | 545 } |
| 545 | 546 |
| 546 void DetermineDownloadTarget(DownloadItemImpl* item) { | 547 void DetermineDownloadTarget(DownloadItemImpl* item) { |
| 547 download_manager_->DetermineDownloadTarget( | 548 download_manager_->DetermineDownloadTarget( |
| 548 item, base::Bind( | 549 item, base::Bind( |
| 549 &DownloadManagerTest::DownloadTargetDeterminedCallback, | 550 &DownloadManagerTest::DownloadTargetDeterminedCallback, |
| 550 base::Unretained(this))); | 551 base::Unretained(this))); |
| 551 } | 552 } |
| 552 | 553 |
| 553 void AddItemToHistory(MockDownloadItemImpl& item, int64 db_handle) { | |
| 554 // For DCHECK in AddDownloadItemToHistory. Don't want to use | |
| 555 // WillRepeatedly as it may have to return true after this. | |
| 556 if (DCHECK_IS_ON()) | |
| 557 // Null out ShowDownloadInBrowser | |
| 558 EXPECT_CALL(item, GetWebContents()) | |
| 559 .WillOnce(Return(static_cast<WebContents*>(NULL))); | |
| 560 EXPECT_CALL(GetMockDownloadManagerDelegate(), | |
| 561 GetAlternativeWebContentsToNotifyForDownload()) | |
| 562 .WillOnce(Return(static_cast<WebContents*>(NULL))); | |
| 563 | |
| 564 EXPECT_CALL(item, IsInProgress()) | |
| 565 .WillOnce(Return(true)); | |
| 566 } | |
| 567 | |
| 568 protected: | 554 protected: |
| 569 // Key test variable; we'll keep it available to sub-classes. | 555 // Key test variable; we'll keep it available to sub-classes. |
| 570 scoped_refptr<DownloadManagerImpl> download_manager_; | 556 scoped_refptr<DownloadManagerImpl> download_manager_; |
| 571 base::WeakPtr<MockDownloadFileFactory> mock_download_file_factory_; | 557 base::WeakPtr<MockDownloadFileFactory> mock_download_file_factory_; |
| 572 | 558 |
| 573 // Target detetermined callback. | 559 // Target detetermined callback. |
| 574 bool callback_called_; | 560 bool callback_called_; |
| 575 base::FilePath target_path_; | 561 base::FilePath target_path_; |
| 576 DownloadItem::TargetDisposition target_disposition_; | 562 DownloadItem::TargetDisposition target_disposition_; |
| 577 DownloadDangerType danger_type_; | 563 DownloadDangerType danger_type_; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 callback_called_ = false; | 633 callback_called_ = false; |
| 648 DetermineDownloadTarget(&item); | 634 DetermineDownloadTarget(&item); |
| 649 EXPECT_TRUE(callback_called_); | 635 EXPECT_TRUE(callback_called_); |
| 650 EXPECT_EQ(path, target_path_); | 636 EXPECT_EQ(path, target_path_); |
| 651 EXPECT_EQ(DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_disposition_); | 637 EXPECT_EQ(DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_disposition_); |
| 652 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, danger_type_); | 638 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, danger_type_); |
| 653 EXPECT_EQ(path, intermediate_path_); | 639 EXPECT_EQ(path, intermediate_path_); |
| 654 } | 640 } |
| 655 | 641 |
| 656 } // namespace content | 642 } // namespace content |
| OLD | NEW |