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