Chromium Code Reviews| 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/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 MOCK_METHOD1(StealDangerousDownload, void(const AcquireFileCallback&)); | 102 MOCK_METHOD1(StealDangerousDownload, void(const AcquireFileCallback&)); |
| 103 MOCK_METHOD3(UpdateProgress, void(int64, int64, const std::string&)); | 103 MOCK_METHOD3(UpdateProgress, void(int64, int64, const std::string&)); |
| 104 MOCK_METHOD1(Cancel, void(bool)); | 104 MOCK_METHOD1(Cancel, void(bool)); |
| 105 MOCK_METHOD0(MarkAsComplete, void()); | 105 MOCK_METHOD0(MarkAsComplete, void()); |
| 106 MOCK_METHOD1(OnAllDataSaved, void(const std::string&)); | 106 MOCK_METHOD1(OnAllDataSaved, void(const std::string&)); |
| 107 MOCK_METHOD0(OnDownloadedFileRemoved, void()); | 107 MOCK_METHOD0(OnDownloadedFileRemoved, void()); |
| 108 virtual void Start( | 108 virtual void Start( |
| 109 scoped_ptr<DownloadFile> download_file, | 109 scoped_ptr<DownloadFile> download_file, |
| 110 scoped_ptr<DownloadRequestHandleInterface> req_handle) OVERRIDE { | 110 scoped_ptr<DownloadRequestHandleInterface> req_handle) OVERRIDE { |
| 111 MockStart(download_file.get(), req_handle.get()); | 111 MockStart(download_file.get(), req_handle.get()); |
| 112 last_file_.swap(download_file); | |
| 112 } | 113 } |
| 113 | 114 |
| 114 MOCK_METHOD2(MockStart, void(DownloadFile*, DownloadRequestHandleInterface*)); | 115 MOCK_METHOD2(MockStart, void(DownloadFile*, DownloadRequestHandleInterface*)); |
| 115 | 116 |
| 116 MOCK_METHOD0(Remove, void()); | 117 MOCK_METHOD0(Remove, void()); |
| 117 MOCK_CONST_METHOD1(TimeRemaining, bool(base::TimeDelta*)); | 118 MOCK_CONST_METHOD1(TimeRemaining, bool(base::TimeDelta*)); |
| 118 MOCK_CONST_METHOD0(CurrentSpeed, int64()); | 119 MOCK_CONST_METHOD0(CurrentSpeed, int64()); |
| 119 MOCK_CONST_METHOD0(PercentComplete, int()); | 120 MOCK_CONST_METHOD0(PercentComplete, int()); |
| 120 MOCK_CONST_METHOD0(AllDataSaved, bool()); | 121 MOCK_CONST_METHOD0(AllDataSaved, bool()); |
| 121 MOCK_CONST_METHOD1(MatchesQuery, bool(const string16& query)); | 122 MOCK_CONST_METHOD1(MatchesQuery, bool(const string16& query)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 MOCK_CONST_METHOD0(GetLastReason, DownloadInterruptReason()); | 164 MOCK_CONST_METHOD0(GetLastReason, DownloadInterruptReason()); |
| 164 MOCK_CONST_METHOD0(GetBrowserContext, BrowserContext*()); | 165 MOCK_CONST_METHOD0(GetBrowserContext, BrowserContext*()); |
| 165 MOCK_CONST_METHOD0(GetWebContents, WebContents*()); | 166 MOCK_CONST_METHOD0(GetWebContents, WebContents*()); |
| 166 MOCK_CONST_METHOD0(GetFileNameToReportUser, base::FilePath()); | 167 MOCK_CONST_METHOD0(GetFileNameToReportUser, base::FilePath()); |
| 167 MOCK_METHOD1(SetDisplayName, void(const base::FilePath&)); | 168 MOCK_METHOD1(SetDisplayName, void(const base::FilePath&)); |
| 168 MOCK_METHOD0(NotifyRemoved, void()); | 169 MOCK_METHOD0(NotifyRemoved, void()); |
| 169 // May be called when vlog is on. | 170 // May be called when vlog is on. |
| 170 virtual std::string DebugString(bool verbose) const OVERRIDE { | 171 virtual std::string DebugString(bool verbose) const OVERRIDE { |
| 171 return std::string(); | 172 return std::string(); |
| 172 } | 173 } |
| 174 | |
| 175 private: | |
| 176 scoped_ptr<DownloadFile> last_file_; | |
| 173 }; | 177 }; |
| 174 | 178 |
| 175 class MockDownloadManagerDelegate : public DownloadManagerDelegate { | 179 class MockDownloadManagerDelegate : public DownloadManagerDelegate { |
| 176 public: | 180 public: |
| 177 MockDownloadManagerDelegate(); | 181 MockDownloadManagerDelegate(); |
| 178 virtual ~MockDownloadManagerDelegate(); | 182 virtual ~MockDownloadManagerDelegate(); |
| 179 | 183 |
| 180 MOCK_METHOD0(Shutdown, void()); | 184 MOCK_METHOD0(Shutdown, void()); |
| 181 MOCK_METHOD1(GetNextId, void(const DownloadIdCallback&)); | 185 MOCK_METHOD1(GetNextId, void(const DownloadIdCallback&)); |
| 182 MOCK_METHOD2(DetermineDownloadTarget, | 186 MOCK_METHOD2(DetermineDownloadTarget, |
| 183 bool(DownloadItem* item, | 187 bool(DownloadItem* item, |
| 184 const DownloadTargetCallback&)); | 188 const DownloadTargetCallback&)); |
| 185 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const base::FilePath&)); | 189 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const base::FilePath&)); |
| 186 MOCK_METHOD2(ShouldCompleteDownload, | 190 MOCK_METHOD2(ShouldCompleteDownload, |
| 187 bool(DownloadItem*, const base::Closure&)); | 191 bool(DownloadItem*, const base::Closure&)); |
| 188 MOCK_METHOD2(ShouldOpenDownload, | 192 MOCK_METHOD2(ShouldOpenDownload, |
| 189 bool(DownloadItem*, const DownloadOpenDelayedCallback&)); | 193 bool(DownloadItem*, const DownloadOpenDelayedCallback&)); |
| 190 MOCK_METHOD0(GenerateFileHash, bool()); | 194 MOCK_METHOD0(GenerateFileHash, bool()); |
| 191 MOCK_METHOD4(GetSaveDir, void(BrowserContext*, | 195 MOCK_METHOD4(GetSaveDir, void(BrowserContext*, |
| 192 base::FilePath*, base::FilePath*, bool*)); | 196 base::FilePath*, base::FilePath*, bool*)); |
| 193 MOCK_METHOD5(ChooseSavePath, void( | 197 MOCK_METHOD5(ChooseSavePath, void( |
| 194 WebContents*, const base::FilePath&, const base::FilePath::StringType&, | 198 WebContents*, const base::FilePath&, const base::FilePath::StringType&, |
| 195 bool, const SavePackagePathPickedCallback&)); | 199 bool, const SavePackagePathPickedCallback&)); |
| 200 | |
| 201 virtual std::string ApplicationClientIdForFileScanning() const { | |
|
asanka
2013/08/08 21:16:01
Use a mock and set expectations so this is consist
Greg Billock
2013/08/08 23:55:46
Done.
| |
| 202 return std::string("client-id"); | |
| 203 } | |
| 196 }; | 204 }; |
| 197 | 205 |
| 198 MockDownloadManagerDelegate::MockDownloadManagerDelegate() {} | 206 MockDownloadManagerDelegate::MockDownloadManagerDelegate() {} |
| 199 | 207 |
| 200 MockDownloadManagerDelegate::~MockDownloadManagerDelegate() {} | 208 MockDownloadManagerDelegate::~MockDownloadManagerDelegate() {} |
| 201 | 209 |
| 202 class MockDownloadItemFactory | 210 class MockDownloadItemFactory |
| 203 : public DownloadItemFactory, | 211 : public DownloadItemFactory, |
| 204 public base::SupportsWeakPtr<MockDownloadItemFactory> { | 212 public base::SupportsWeakPtr<MockDownloadItemFactory> { |
| 205 public: | 213 public: |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 | 375 |
| 368 virtual DownloadFile* CreateFile( | 376 virtual DownloadFile* CreateFile( |
| 369 scoped_ptr<DownloadSaveInfo> save_info, | 377 scoped_ptr<DownloadSaveInfo> save_info, |
| 370 const base::FilePath& default_download_directory, | 378 const base::FilePath& default_download_directory, |
| 371 const GURL& url, | 379 const GURL& url, |
| 372 const GURL& referrer_url, | 380 const GURL& referrer_url, |
| 373 bool calculate_hash, | 381 bool calculate_hash, |
| 374 scoped_ptr<ByteStreamReader> stream, | 382 scoped_ptr<ByteStreamReader> stream, |
| 375 const net::BoundNetLog& bound_net_log, | 383 const net::BoundNetLog& bound_net_log, |
| 376 base::WeakPtr<DownloadDestinationObserver> observer) { | 384 base::WeakPtr<DownloadDestinationObserver> observer) { |
| 377 return MockCreateFile(*save_info.get(), default_download_directory, url, | 385 MockCreateFile(*save_info.get(), default_download_directory, url, |
| 378 referrer_url, calculate_hash, | 386 referrer_url, calculate_hash, |
| 379 stream.get(), bound_net_log, observer); | 387 stream.get(), bound_net_log, observer); |
| 388 mock_file_ = new MockDownloadFile(); | |
| 389 return mock_file_; | |
| 380 } | 390 } |
| 391 | |
| 392 MockDownloadFile* GetCreatedDownloadFile() { | |
| 393 return mock_file_; | |
| 394 } | |
| 395 | |
| 396 private: | |
| 397 MockDownloadFile* mock_file_; | |
| 381 }; | 398 }; |
| 382 | 399 |
| 383 class MockBrowserContext : public BrowserContext { | 400 class MockBrowserContext : public BrowserContext { |
| 384 public: | 401 public: |
| 385 MockBrowserContext() {} | 402 MockBrowserContext() {} |
| 386 ~MockBrowserContext() {} | 403 ~MockBrowserContext() {} |
| 387 | 404 |
| 388 MOCK_CONST_METHOD0(GetPath, base::FilePath()); | 405 MOCK_CONST_METHOD0(GetPath, base::FilePath()); |
| 389 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); | 406 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); |
| 390 MOCK_METHOD0(GetRequestContext, net::URLRequestContextGetter*()); | 407 MOCK_METHOD0(GetRequestContext, net::URLRequestContextGetter*()); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 .WillOnce(Return()); | 599 .WillOnce(Return()); |
| 583 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId(_)) | 600 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId(_)) |
| 584 .WillOnce(RunCallback<0>(local_id)); | 601 .WillOnce(RunCallback<0>(local_id)); |
| 585 | 602 |
| 586 // Doing nothing will set the default download directory to null. | 603 // Doing nothing will set the default download directory to null. |
| 587 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetSaveDir(_, _, _, _)); | 604 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetSaveDir(_, _, _, _)); |
| 588 EXPECT_CALL(GetMockDownloadManagerDelegate(), GenerateFileHash()) | 605 EXPECT_CALL(GetMockDownloadManagerDelegate(), GenerateFileHash()) |
| 589 .WillOnce(Return(true)); | 606 .WillOnce(Return(true)); |
| 590 EXPECT_CALL(*mock_download_file_factory_.get(), | 607 EXPECT_CALL(*mock_download_file_factory_.get(), |
| 591 MockCreateFile(Ref(*info->save_info.get()), _, _, _, true, | 608 MockCreateFile(Ref(*info->save_info.get()), _, _, _, true, |
| 592 stream.get(), _, _)); | 609 stream.get(), _, _)); |
|
asanka
2013/08/08 21:16:01
Create a MockDownloadFile here, set its expectatio
Greg Billock
2013/08/08 23:55:46
Done, but as an aside I think these tests would be
| |
| 593 | 610 |
| 594 download_manager_->StartDownload( | 611 download_manager_->StartDownload( |
| 595 info.Pass(), stream.Pass(), DownloadUrlParameters::OnStartedCallback()); | 612 info.Pass(), stream.Pass(), DownloadUrlParameters::OnStartedCallback()); |
| 596 EXPECT_TRUE(download_manager_->GetDownload(local_id)); | 613 EXPECT_TRUE(NULL != download_manager_->GetDownload(local_id)); |
|
asanka
2013/08/08 21:16:01
Is this change necessary?
Greg Billock
2013/08/08 23:55:46
I'll put it back.
| |
| 614 | |
| 615 // Make sure the client app GUID was set in the DownloadItem. | |
| 616 MockDownloadFile* mock_file = | |
| 617 mock_download_file_factory_->GetCreatedDownloadFile(); | |
| 618 EXPECT_EQ("client-id", mock_file->client_guid()); | |
| 597 } | 619 } |
| 598 | 620 |
| 599 // Confirm that calling DetermineDownloadTarget behaves properly if the delegate | 621 // Confirm that calling DetermineDownloadTarget behaves properly if the delegate |
| 600 // blocks starting. | 622 // blocks starting. |
| 601 TEST_F(DownloadManagerTest, DetermineDownloadTarget_True) { | 623 TEST_F(DownloadManagerTest, DetermineDownloadTarget_True) { |
| 602 // Put a mock we have a handle to on the download manager. | 624 // Put a mock we have a handle to on the download manager. |
| 603 MockDownloadItemImpl& item(AddItemToManager()); | 625 MockDownloadItemImpl& item(AddItemToManager()); |
| 604 EXPECT_CALL(item, GetState()) | 626 EXPECT_CALL(item, GetState()) |
| 605 .WillRepeatedly(Return(DownloadItem::IN_PROGRESS)); | 627 .WillRepeatedly(Return(DownloadItem::IN_PROGRESS)); |
| 606 | 628 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 .WillOnce(Return()); | 684 .WillOnce(Return()); |
| 663 EXPECT_CALL(GetMockDownloadItem(3), Remove()) | 685 EXPECT_CALL(GetMockDownloadItem(3), Remove()) |
| 664 .Times(0); | 686 .Times(0); |
| 665 | 687 |
| 666 download_manager_->RemoveAllDownloads(); | 688 download_manager_->RemoveAllDownloads(); |
| 667 // Because we're mocking the download item, the Remove call doesn't | 689 // Because we're mocking the download item, the Remove call doesn't |
| 668 // result in them being removed from the DownloadManager list. | 690 // result in them being removed from the DownloadManager list. |
| 669 } | 691 } |
| 670 | 692 |
| 671 } // namespace content | 693 } // namespace content |
| OLD | NEW |