| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 MOCK_METHOD0(ShouldOpenFileBasedOnExtension, bool()); | 91 MOCK_METHOD0(ShouldOpenFileBasedOnExtension, bool()); |
| 92 MOCK_METHOD0(OpenDownload, void()); | 92 MOCK_METHOD0(OpenDownload, void()); |
| 93 MOCK_METHOD0(ShowDownloadInShell, void()); | 93 MOCK_METHOD0(ShowDownloadInShell, void()); |
| 94 MOCK_METHOD0(DangerousDownloadValidated, void()); | 94 MOCK_METHOD0(DangerousDownloadValidated, void()); |
| 95 MOCK_METHOD3(UpdateProgress, void(int64, int64, const std::string&)); | 95 MOCK_METHOD3(UpdateProgress, void(int64, int64, const std::string&)); |
| 96 MOCK_METHOD1(Cancel, void(bool)); | 96 MOCK_METHOD1(Cancel, void(bool)); |
| 97 MOCK_METHOD0(MarkAsComplete, void()); | 97 MOCK_METHOD0(MarkAsComplete, void()); |
| 98 MOCK_METHOD1(OnAllDataSaved, void(const std::string&)); | 98 MOCK_METHOD1(OnAllDataSaved, void(const std::string&)); |
| 99 MOCK_METHOD0(OnDownloadedFileRemoved, void()); | 99 MOCK_METHOD0(OnDownloadedFileRemoved, void()); |
| 100 virtual void Start( | 100 virtual void Start( |
| 101 scoped_ptr<DownloadFile> download_file) OVERRIDE { | 101 scoped_ptr<DownloadFile> download_file, |
| 102 MockStart(download_file.get()); | 102 scoped_ptr<DownloadRequestHandleInterface> req_handle) OVERRIDE { |
| 103 MockStart(download_file.get(), req_handle.get()); |
| 103 } | 104 } |
| 104 | 105 |
| 105 MOCK_METHOD1(MockStart, void(DownloadFile*)); | 106 MOCK_METHOD2(MockStart, void(DownloadFile*, DownloadRequestHandleInterface*)); |
| 106 | 107 |
| 107 MOCK_METHOD1(Delete, void(DeleteReason)); | 108 MOCK_METHOD1(Delete, void(DeleteReason)); |
| 108 MOCK_METHOD0(Remove, void()); | 109 MOCK_METHOD0(Remove, void()); |
| 109 MOCK_CONST_METHOD1(TimeRemaining, bool(base::TimeDelta*)); | 110 MOCK_CONST_METHOD1(TimeRemaining, bool(base::TimeDelta*)); |
| 110 MOCK_CONST_METHOD0(CurrentSpeed, int64()); | 111 MOCK_CONST_METHOD0(CurrentSpeed, int64()); |
| 111 MOCK_CONST_METHOD0(PercentComplete, int()); | 112 MOCK_CONST_METHOD0(PercentComplete, int()); |
| 112 MOCK_CONST_METHOD0(AllDataSaved, bool()); | 113 MOCK_CONST_METHOD0(AllDataSaved, bool()); |
| 113 MOCK_CONST_METHOD1(MatchesQuery, bool(const string16& query)); | 114 MOCK_CONST_METHOD1(MatchesQuery, bool(const string16& query)); |
| 114 MOCK_CONST_METHOD0(IsPartialDownload, bool()); | 115 MOCK_CONST_METHOD0(IsPartialDownload, bool()); |
| 115 MOCK_CONST_METHOD0(IsInProgress, bool()); | 116 MOCK_CONST_METHOD0(IsInProgress, bool()); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 const base::Time& start_time, | 230 const base::Time& start_time, |
| 230 const base::Time& end_time, | 231 const base::Time& end_time, |
| 231 int64 received_bytes, | 232 int64 received_bytes, |
| 232 int64 total_bytes, | 233 int64 total_bytes, |
| 233 DownloadItem::DownloadState state, | 234 DownloadItem::DownloadState state, |
| 234 bool opened, | 235 bool opened, |
| 235 const net::BoundNetLog& bound_net_log) OVERRIDE; | 236 const net::BoundNetLog& bound_net_log) OVERRIDE; |
| 236 virtual DownloadItemImpl* CreateActiveItem( | 237 virtual DownloadItemImpl* CreateActiveItem( |
| 237 DownloadItemImplDelegate* delegate, | 238 DownloadItemImplDelegate* delegate, |
| 238 const DownloadCreateInfo& info, | 239 const DownloadCreateInfo& info, |
| 239 scoped_ptr<DownloadRequestHandleInterface> request_handle, | |
| 240 const net::BoundNetLog& bound_net_log) OVERRIDE; | 240 const net::BoundNetLog& bound_net_log) OVERRIDE; |
| 241 virtual DownloadItemImpl* CreateSavePageItem( | 241 virtual DownloadItemImpl* CreateSavePageItem( |
| 242 DownloadItemImplDelegate* delegate, | 242 DownloadItemImplDelegate* delegate, |
| 243 const FilePath& path, | 243 const FilePath& path, |
| 244 const GURL& url, | 244 const GURL& url, |
| 245 DownloadId download_id, | 245 DownloadId download_id, |
| 246 const std::string& mime_type, | 246 const std::string& mime_type, |
| 247 const net::BoundNetLog& bound_net_log) OVERRIDE; | 247 const net::BoundNetLog& bound_net_log) OVERRIDE; |
| 248 | 248 |
| 249 private: | 249 private: |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 EXPECT_CALL(*result, GetId()) | 300 EXPECT_CALL(*result, GetId()) |
| 301 .WillRepeatedly(Return(local_id)); | 301 .WillRepeatedly(Return(local_id)); |
| 302 items_[local_id] = result; | 302 items_[local_id] = result; |
| 303 | 303 |
| 304 return result; | 304 return result; |
| 305 } | 305 } |
| 306 | 306 |
| 307 DownloadItemImpl* MockDownloadItemFactory::CreateActiveItem( | 307 DownloadItemImpl* MockDownloadItemFactory::CreateActiveItem( |
| 308 DownloadItemImplDelegate* delegate, | 308 DownloadItemImplDelegate* delegate, |
| 309 const DownloadCreateInfo& info, | 309 const DownloadCreateInfo& info, |
| 310 scoped_ptr<DownloadRequestHandleInterface> request_handle, | |
| 311 const net::BoundNetLog& bound_net_log) { | 310 const net::BoundNetLog& bound_net_log) { |
| 312 int local_id = info.download_id.local(); | 311 int local_id = info.download_id.local(); |
| 313 DCHECK(items_.find(local_id) == items_.end()); | 312 DCHECK(items_.find(local_id) == items_.end()); |
| 314 | 313 |
| 315 MockDownloadItemImpl* result = | 314 MockDownloadItemImpl* result = |
| 316 new StrictMock<MockDownloadItemImpl>(&item_delegate_); | 315 new StrictMock<MockDownloadItemImpl>(&item_delegate_); |
| 317 EXPECT_CALL(*result, GetId()) | 316 EXPECT_CALL(*result, GetId()) |
| 318 .WillRepeatedly(Return(local_id)); | 317 .WillRepeatedly(Return(local_id)); |
| 319 EXPECT_CALL(*result, GetGlobalId()) | 318 EXPECT_CALL(*result, GetGlobalId()) |
| 320 .WillRepeatedly(Return(DownloadId(delegate, local_id))); | 319 .WillRepeatedly(Return(DownloadId(delegate, local_id))); |
| 321 items_[local_id] = result; | 320 items_[local_id] = result; |
| 322 | 321 |
| 323 // Active items are created and then immediately are called to start | 322 // Active items are created and then immediately are called to start |
| 324 // the download. | 323 // the download. |
| 325 EXPECT_CALL(*result, MockStart(_)); | 324 EXPECT_CALL(*result, MockStart(_, _)); |
| 326 | 325 |
| 327 return result; | 326 return result; |
| 328 } | 327 } |
| 329 | 328 |
| 330 DownloadItemImpl* MockDownloadItemFactory::CreateSavePageItem( | 329 DownloadItemImpl* MockDownloadItemFactory::CreateSavePageItem( |
| 331 DownloadItemImplDelegate* delegate, | 330 DownloadItemImplDelegate* delegate, |
| 332 const FilePath& path, | 331 const FilePath& path, |
| 333 const GURL& url, | 332 const GURL& url, |
| 334 DownloadId download_id, | 333 DownloadId download_id, |
| 335 const std::string& mime_type, | 334 const std::string& mime_type, |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 DownloadCreateInfo info; | 487 DownloadCreateInfo info; |
| 489 | 488 |
| 490 static const char* kDownloadIdDomain = "Test download id domain"; | 489 static const char* kDownloadIdDomain = "Test download id domain"; |
| 491 | 490 |
| 492 // Args are ignored except for download id, so everything else can be | 491 // Args are ignored except for download id, so everything else can be |
| 493 // null. | 492 // null. |
| 494 int id = next_download_id_; | 493 int id = next_download_id_; |
| 495 ++next_download_id_; | 494 ++next_download_id_; |
| 496 info.download_id = DownloadId(kDownloadIdDomain, id); | 495 info.download_id = DownloadId(kDownloadIdDomain, id); |
| 497 info.request_handle = DownloadRequestHandle(); | 496 info.request_handle = DownloadRequestHandle(); |
| 498 download_manager_->CreateDownloadItem(&info, net::BoundNetLog()); | 497 download_manager_->GetOrCreateDownloadItem(&info); |
| 499 | 498 |
| 500 DCHECK(mock_download_item_factory_->GetItem(id)); | 499 DCHECK(mock_download_item_factory_->GetItem(id)); |
| 501 MockDownloadItemImpl& item(*mock_download_item_factory_->GetItem(id)); | 500 MockDownloadItemImpl& item(*mock_download_item_factory_->GetItem(id)); |
| 502 // Satisfy expectation. If the item is created in StartDownload(), | 501 // Satisfy expectation. If the item is created in StartDownload(), |
| 503 // we call Start on it immediately, so we need to set that expectation | 502 // we call Start on it immediately, so we need to set that expectation |
| 504 // in the factory. | 503 // in the factory. |
| 505 item.Start(scoped_ptr<DownloadFile>()); | 504 scoped_ptr<DownloadRequestHandleInterface> req_handle; |
| 505 item.Start(scoped_ptr<DownloadFile>(), req_handle.Pass()); |
| 506 | 506 |
| 507 return item; | 507 return item; |
| 508 } | 508 } |
| 509 | 509 |
| 510 MockDownloadItemImpl& GetMockDownloadItem(int id) { | 510 MockDownloadItemImpl& GetMockDownloadItem(int id) { |
| 511 MockDownloadItemImpl* itemp = mock_download_item_factory_->GetItem(id); | 511 MockDownloadItemImpl* itemp = mock_download_item_factory_->GetItem(id); |
| 512 | 512 |
| 513 DCHECK(itemp); | 513 DCHECK(itemp); |
| 514 return *itemp; | 514 return *itemp; |
| 515 } | 515 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 callback_called_ = false; | 643 callback_called_ = false; |
| 644 DetermineDownloadTarget(&item); | 644 DetermineDownloadTarget(&item); |
| 645 EXPECT_TRUE(callback_called_); | 645 EXPECT_TRUE(callback_called_); |
| 646 EXPECT_EQ(path, target_path_); | 646 EXPECT_EQ(path, target_path_); |
| 647 EXPECT_EQ(DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_disposition_); | 647 EXPECT_EQ(DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_disposition_); |
| 648 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, danger_type_); | 648 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, danger_type_); |
| 649 EXPECT_EQ(path, intermediate_path_); | 649 EXPECT_EQ(path, intermediate_path_); |
| 650 } | 650 } |
| 651 | 651 |
| 652 } // namespace content | 652 } // namespace content |
| OLD | NEW |