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 "content/browser/download/download_manager_impl.h" | 5 #include "content/browser/download/download_manager_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 std::vector<GURL>(), | 86 std::vector<GURL>(), |
87 GURL(), | 87 GURL(), |
88 "application/octet-stream", | 88 "application/octet-stream", |
89 "application/octet-stream", | 89 "application/octet-stream", |
90 base::Time(), | 90 base::Time(), |
91 base::Time(), | 91 base::Time(), |
92 std::string(), | 92 std::string(), |
93 std::string(), | 93 std::string(), |
94 0, | 94 0, |
95 0, | 95 0, |
| 96 std::string(), |
96 DownloadItem::COMPLETE, | 97 DownloadItem::COMPLETE, |
97 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 98 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
98 DOWNLOAD_INTERRUPT_REASON_NONE, | 99 DOWNLOAD_INTERRUPT_REASON_NONE, |
99 false, | 100 false, |
100 net::BoundNetLog()) {} | 101 net::BoundNetLog()) {} |
101 virtual ~MockDownloadItemImpl() {} | 102 virtual ~MockDownloadItemImpl() {} |
102 | 103 |
103 MOCK_METHOD4(OnDownloadTargetDetermined, | 104 MOCK_METHOD4(OnDownloadTargetDetermined, |
104 void(const base::FilePath&, TargetDisposition, | 105 void(const base::FilePath&, TargetDisposition, |
105 DownloadDangerType, const base::FilePath&)); | 106 DownloadDangerType, const base::FilePath&)); |
106 MOCK_METHOD1(AddObserver, void(DownloadItem::Observer*)); | 107 MOCK_METHOD1(AddObserver, void(DownloadItem::Observer*)); |
107 MOCK_METHOD1(RemoveObserver, void(DownloadItem::Observer*)); | 108 MOCK_METHOD1(RemoveObserver, void(DownloadItem::Observer*)); |
108 MOCK_METHOD0(UpdateObservers, void()); | 109 MOCK_METHOD0(UpdateObservers, void()); |
109 MOCK_METHOD0(CanShowInFolder, bool()); | 110 MOCK_METHOD0(CanShowInFolder, bool()); |
110 MOCK_METHOD0(CanOpenDownload, bool()); | 111 MOCK_METHOD0(CanOpenDownload, bool()); |
111 MOCK_METHOD0(ShouldOpenFileBasedOnExtension, bool()); | 112 MOCK_METHOD0(ShouldOpenFileBasedOnExtension, bool()); |
112 MOCK_METHOD0(OpenDownload, void()); | 113 MOCK_METHOD0(OpenDownload, void()); |
113 MOCK_METHOD0(ShowDownloadInShell, void()); | 114 MOCK_METHOD0(ShowDownloadInShell, void()); |
114 MOCK_METHOD0(ValidateDangerousDownload, void()); | 115 MOCK_METHOD0(ValidateDangerousDownload, void()); |
115 MOCK_METHOD1(StealDangerousDownload, void(const AcquireFileCallback&)); | 116 MOCK_METHOD1(StealDangerousDownload, void(const AcquireFileCallback&)); |
116 MOCK_METHOD3(UpdateProgress, void(int64_t, int64_t, const std::string&)); | 117 MOCK_METHOD3(UpdateProgress, void(int64_t, int64_t, const std::string&)); |
117 MOCK_METHOD1(Cancel, void(bool)); | 118 MOCK_METHOD1(Cancel, void(bool)); |
118 MOCK_METHOD0(MarkAsComplete, void()); | 119 MOCK_METHOD0(MarkAsComplete, void()); |
119 MOCK_METHOD1(OnAllDataSaved, void(const std::string&)); | 120 void OnAllDataSaved(int64_t, scoped_ptr<crypto::SecureHash>) override { |
| 121 NOTREACHED(); |
| 122 } |
120 MOCK_METHOD0(OnDownloadedFileRemoved, void()); | 123 MOCK_METHOD0(OnDownloadedFileRemoved, void()); |
121 void Start(scoped_ptr<DownloadFile> download_file, | 124 void Start(scoped_ptr<DownloadFile> download_file, |
122 scoped_ptr<DownloadRequestHandleInterface> req_handle, | 125 scoped_ptr<DownloadRequestHandleInterface> req_handle, |
123 const DownloadCreateInfo& create_info) override { | 126 const DownloadCreateInfo& create_info) override { |
124 MockStart(download_file.get(), req_handle.get()); | 127 MockStart(download_file.get(), req_handle.get()); |
125 } | 128 } |
126 | 129 |
127 MOCK_METHOD2(MockStart, void(DownloadFile*, DownloadRequestHandleInterface*)); | 130 MOCK_METHOD2(MockStart, void(DownloadFile*, DownloadRequestHandleInterface*)); |
128 | 131 |
129 MOCK_METHOD0(Remove, void()); | 132 MOCK_METHOD0(Remove, void()); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 MOCK_METHOD0(Shutdown, void()); | 199 MOCK_METHOD0(Shutdown, void()); |
197 MOCK_METHOD1(GetNextId, void(const DownloadIdCallback&)); | 200 MOCK_METHOD1(GetNextId, void(const DownloadIdCallback&)); |
198 MOCK_METHOD2(DetermineDownloadTarget, | 201 MOCK_METHOD2(DetermineDownloadTarget, |
199 bool(DownloadItem* item, | 202 bool(DownloadItem* item, |
200 const DownloadTargetCallback&)); | 203 const DownloadTargetCallback&)); |
201 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const base::FilePath&)); | 204 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const base::FilePath&)); |
202 MOCK_METHOD2(ShouldCompleteDownload, | 205 MOCK_METHOD2(ShouldCompleteDownload, |
203 bool(DownloadItem*, const base::Closure&)); | 206 bool(DownloadItem*, const base::Closure&)); |
204 MOCK_METHOD2(ShouldOpenDownload, | 207 MOCK_METHOD2(ShouldOpenDownload, |
205 bool(DownloadItem*, const DownloadOpenDelayedCallback&)); | 208 bool(DownloadItem*, const DownloadOpenDelayedCallback&)); |
206 MOCK_METHOD0(GenerateFileHash, bool()); | |
207 MOCK_METHOD4(GetSaveDir, void(BrowserContext*, | 209 MOCK_METHOD4(GetSaveDir, void(BrowserContext*, |
208 base::FilePath*, base::FilePath*, bool*)); | 210 base::FilePath*, base::FilePath*, bool*)); |
209 MOCK_METHOD5(ChooseSavePath, void( | 211 MOCK_METHOD5(ChooseSavePath, void( |
210 WebContents*, const base::FilePath&, const base::FilePath::StringType&, | 212 WebContents*, const base::FilePath&, const base::FilePath::StringType&, |
211 bool, const SavePackagePathPickedCallback&)); | 213 bool, const SavePackagePathPickedCallback&)); |
212 MOCK_CONST_METHOD0(ApplicationClientIdForFileScanning, std::string()); | 214 MOCK_CONST_METHOD0(ApplicationClientIdForFileScanning, std::string()); |
213 }; | 215 }; |
214 | 216 |
215 MockDownloadManagerDelegate::MockDownloadManagerDelegate() {} | 217 MockDownloadManagerDelegate::MockDownloadManagerDelegate() {} |
216 | 218 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 const std::vector<GURL>& url_chain, | 250 const std::vector<GURL>& url_chain, |
249 const GURL& referrer_url, | 251 const GURL& referrer_url, |
250 const std::string& mime_type, | 252 const std::string& mime_type, |
251 const std::string& original_mime_type, | 253 const std::string& original_mime_type, |
252 const base::Time& start_time, | 254 const base::Time& start_time, |
253 const base::Time& end_time, | 255 const base::Time& end_time, |
254 const std::string& etag, | 256 const std::string& etag, |
255 const std::string& last_modofied, | 257 const std::string& last_modofied, |
256 int64_t received_bytes, | 258 int64_t received_bytes, |
257 int64_t total_bytes, | 259 int64_t total_bytes, |
| 260 const std::string& hash, |
258 DownloadItem::DownloadState state, | 261 DownloadItem::DownloadState state, |
259 DownloadDangerType danger_type, | 262 DownloadDangerType danger_type, |
260 DownloadInterruptReason interrupt_reason, | 263 DownloadInterruptReason interrupt_reason, |
261 bool opened, | 264 bool opened, |
262 const net::BoundNetLog& bound_net_log) override; | 265 const net::BoundNetLog& bound_net_log) override; |
263 DownloadItemImpl* CreateActiveItem( | 266 DownloadItemImpl* CreateActiveItem( |
264 DownloadItemImplDelegate* delegate, | 267 DownloadItemImplDelegate* delegate, |
265 uint32_t download_id, | 268 uint32_t download_id, |
266 const DownloadCreateInfo& info, | 269 const DownloadCreateInfo& info, |
267 const net::BoundNetLog& bound_net_log) override; | 270 const net::BoundNetLog& bound_net_log) override; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 const std::vector<GURL>& url_chain, | 319 const std::vector<GURL>& url_chain, |
317 const GURL& referrer_url, | 320 const GURL& referrer_url, |
318 const std::string& mime_type, | 321 const std::string& mime_type, |
319 const std::string& original_mime_type, | 322 const std::string& original_mime_type, |
320 const base::Time& start_time, | 323 const base::Time& start_time, |
321 const base::Time& end_time, | 324 const base::Time& end_time, |
322 const std::string& etag, | 325 const std::string& etag, |
323 const std::string& last_modified, | 326 const std::string& last_modified, |
324 int64_t received_bytes, | 327 int64_t received_bytes, |
325 int64_t total_bytes, | 328 int64_t total_bytes, |
| 329 const std::string& hash, |
326 DownloadItem::DownloadState state, | 330 DownloadItem::DownloadState state, |
327 DownloadDangerType danger_type, | 331 DownloadDangerType danger_type, |
328 DownloadInterruptReason interrupt_reason, | 332 DownloadInterruptReason interrupt_reason, |
329 bool opened, | 333 bool opened, |
330 const net::BoundNetLog& bound_net_log) { | 334 const net::BoundNetLog& bound_net_log) { |
331 DCHECK(items_.find(download_id) == items_.end()); | 335 DCHECK(items_.find(download_id) == items_.end()); |
332 MockDownloadItemImpl* result = | 336 MockDownloadItemImpl* result = |
333 new StrictMock<MockDownloadItemImpl>(&item_delegate_); | 337 new StrictMock<MockDownloadItemImpl>(&item_delegate_); |
334 EXPECT_CALL(*result, GetId()) | 338 EXPECT_CALL(*result, GetId()) |
335 .WillRepeatedly(Return(download_id)); | 339 .WillRepeatedly(Return(download_id)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 } | 385 } |
382 | 386 |
383 class MockDownloadFileFactory | 387 class MockDownloadFileFactory |
384 : public DownloadFileFactory, | 388 : public DownloadFileFactory, |
385 public base::SupportsWeakPtr<MockDownloadFileFactory> { | 389 public base::SupportsWeakPtr<MockDownloadFileFactory> { |
386 public: | 390 public: |
387 MockDownloadFileFactory() {} | 391 MockDownloadFileFactory() {} |
388 virtual ~MockDownloadFileFactory() {} | 392 virtual ~MockDownloadFileFactory() {} |
389 | 393 |
390 // Overridden method from DownloadFileFactory | 394 // Overridden method from DownloadFileFactory |
391 MOCK_METHOD3(MockCreateFile, | 395 MOCK_METHOD2(MockCreateFile, |
392 MockDownloadFile*(const DownloadSaveInfo&, | 396 MockDownloadFile*(const DownloadSaveInfo&, ByteStreamReader*)); |
393 bool, | |
394 ByteStreamReader*)); | |
395 | 397 |
396 virtual DownloadFile* CreateFile( | 398 virtual DownloadFile* CreateFile( |
397 const DownloadSaveInfo& save_info, | 399 scoped_ptr<DownloadSaveInfo> save_info, |
398 const base::FilePath& default_download_directory, | 400 const base::FilePath& default_download_directory, |
399 const GURL& url, | |
400 const GURL& referrer_url, | |
401 bool calculate_hash, | |
402 base::File file_stream, | |
403 scoped_ptr<ByteStreamReader> byte_stream, | 401 scoped_ptr<ByteStreamReader> byte_stream, |
404 const net::BoundNetLog& bound_net_log, | 402 const net::BoundNetLog& bound_net_log, |
405 base::WeakPtr<DownloadDestinationObserver> observer) { | 403 base::WeakPtr<DownloadDestinationObserver> observer) override { |
406 return MockCreateFile(save_info, calculate_hash, byte_stream.get()); | 404 return MockCreateFile(*save_info, byte_stream.get()); |
407 } | 405 } |
408 }; | 406 }; |
409 | 407 |
410 class MockBrowserContext : public BrowserContext { | 408 class MockBrowserContext : public BrowserContext { |
411 public: | 409 public: |
412 MockBrowserContext() { | 410 MockBrowserContext() { |
413 content::BrowserContext::Initialize(this, base::FilePath()); | 411 content::BrowserContext::Initialize(this, base::FilePath()); |
414 } | 412 } |
415 ~MockBrowserContext() {} | 413 ~MockBrowserContext() {} |
416 | 414 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 625 |
628 EXPECT_FALSE(download_manager_->GetDownload(local_id)); | 626 EXPECT_FALSE(download_manager_->GetDownload(local_id)); |
629 | 627 |
630 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | 628 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
631 .WillOnce(Return()); | 629 .WillOnce(Return()); |
632 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId(_)) | 630 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId(_)) |
633 .WillOnce(RunCallback<0>(local_id)); | 631 .WillOnce(RunCallback<0>(local_id)); |
634 | 632 |
635 // Doing nothing will set the default download directory to null. | 633 // Doing nothing will set the default download directory to null. |
636 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetSaveDir(_, _, _, _)); | 634 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetSaveDir(_, _, _, _)); |
637 EXPECT_CALL(GetMockDownloadManagerDelegate(), GenerateFileHash()) | |
638 .WillOnce(Return(true)); | |
639 EXPECT_CALL(GetMockDownloadManagerDelegate(), | 635 EXPECT_CALL(GetMockDownloadManagerDelegate(), |
640 ApplicationClientIdForFileScanning()) | 636 ApplicationClientIdForFileScanning()) |
641 .WillRepeatedly(Return("client-id")); | 637 .WillRepeatedly(Return("client-id")); |
642 MockDownloadFile* mock_file = new MockDownloadFile; | 638 MockDownloadFile* mock_file = new MockDownloadFile; |
643 EXPECT_CALL(*mock_file, SetClientGuid("client-id")); | |
644 EXPECT_CALL(*mock_download_file_factory_.get(), | 639 EXPECT_CALL(*mock_download_file_factory_.get(), |
645 MockCreateFile(Ref(*info->save_info.get()), true, stream.get())) | 640 MockCreateFile(Ref(*info->save_info.get()), stream.get())) |
646 .WillOnce(Return(mock_file)); | 641 .WillOnce(Return(mock_file)); |
647 | 642 |
648 download_manager_->StartDownload(std::move(info), std::move(stream), | 643 download_manager_->StartDownload(std::move(info), std::move(stream), |
649 DownloadUrlParameters::OnStartedCallback()); | 644 DownloadUrlParameters::OnStartedCallback()); |
650 EXPECT_TRUE(download_manager_->GetDownload(local_id)); | 645 EXPECT_TRUE(download_manager_->GetDownload(local_id)); |
651 } | 646 } |
652 | 647 |
653 // Confirm that calling DetermineDownloadTarget behaves properly if the delegate | 648 // Confirm that calling DetermineDownloadTarget behaves properly if the delegate |
654 // blocks starting. | 649 // blocks starting. |
655 TEST_F(DownloadManagerTest, DetermineDownloadTarget_True) { | 650 TEST_F(DownloadManagerTest, DetermineDownloadTarget_True) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 std::vector<GURL>(), | 737 std::vector<GURL>(), |
743 GURL("http://example.com/a"), | 738 GURL("http://example.com/a"), |
744 "application/octet-stream", | 739 "application/octet-stream", |
745 "application/octet-stream", | 740 "application/octet-stream", |
746 base::Time::Now(), | 741 base::Time::Now(), |
747 base::Time::Now(), | 742 base::Time::Now(), |
748 std::string(), | 743 std::string(), |
749 std::string(), | 744 std::string(), |
750 10, | 745 10, |
751 10, | 746 10, |
| 747 std::string(), |
752 DownloadItem::INTERRUPTED, | 748 DownloadItem::INTERRUPTED, |
753 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 749 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
754 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | 750 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, |
755 false); | 751 false); |
756 ASSERT_TRUE(persisted_item); | 752 ASSERT_TRUE(persisted_item); |
757 | 753 |
758 ASSERT_EQ(persisted_item, download_manager_->GetDownloadByGuid(kGuid)); | 754 ASSERT_EQ(persisted_item, download_manager_->GetDownloadByGuid(kGuid)); |
759 } | 755 } |
760 | 756 |
761 namespace { | 757 namespace { |
(...skipping 18 matching lines...) Expand all Loading... |
780 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0); | 776 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0); |
781 | 777 |
782 base::Callback<bool(const GURL&)> url_filter = | 778 base::Callback<bool(const GURL&)> url_filter = |
783 GetSingleURLFilter(download_urls_[0]); | 779 GetSingleURLFilter(download_urls_[0]); |
784 int remove_count = download_manager_->RemoveDownloadsByURLAndTime( | 780 int remove_count = download_manager_->RemoveDownloadsByURLAndTime( |
785 url_filter, base::Time(), base::Time::Max()); | 781 url_filter, base::Time(), base::Time::Max()); |
786 EXPECT_EQ(remove_count, 1); | 782 EXPECT_EQ(remove_count, 1); |
787 } | 783 } |
788 | 784 |
789 } // namespace content | 785 } // namespace content |
OLD | NEW |