| 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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 270 |
| 271 // Overridden methods from DownloadItemFactory. | 271 // Overridden methods from DownloadItemFactory. |
| 272 virtual DownloadItemImpl* CreatePersistedItem( | 272 virtual DownloadItemImpl* CreatePersistedItem( |
| 273 DownloadItemImplDelegate* delegate, | 273 DownloadItemImplDelegate* delegate, |
| 274 content::DownloadId download_id, | 274 content::DownloadId download_id, |
| 275 const content::DownloadPersistentStoreInfo& info, | 275 const content::DownloadPersistentStoreInfo& info, |
| 276 const net::BoundNetLog& bound_net_log) OVERRIDE; | 276 const net::BoundNetLog& bound_net_log) OVERRIDE; |
| 277 virtual DownloadItemImpl* CreateActiveItem( | 277 virtual DownloadItemImpl* CreateActiveItem( |
| 278 DownloadItemImplDelegate* delegate, | 278 DownloadItemImplDelegate* delegate, |
| 279 const DownloadCreateInfo& info, | 279 const DownloadCreateInfo& info, |
| 280 scoped_ptr<DownloadRequestHandleInterface> request_handle, | |
| 281 const net::BoundNetLog& bound_net_log) OVERRIDE; | 280 const net::BoundNetLog& bound_net_log) OVERRIDE; |
| 282 virtual DownloadItemImpl* CreateSavePageItem( | 281 virtual DownloadItemImpl* CreateSavePageItem( |
| 283 DownloadItemImplDelegate* delegate, | 282 DownloadItemImplDelegate* delegate, |
| 284 const FilePath& path, | 283 const FilePath& path, |
| 285 const GURL& url, | 284 const GURL& url, |
| 286 content::DownloadId download_id, | 285 content::DownloadId download_id, |
| 287 const std::string& mime_type, | 286 const std::string& mime_type, |
| 288 const net::BoundNetLog& bound_net_log) OVERRIDE; | 287 const net::BoundNetLog& bound_net_log) OVERRIDE; |
| 289 | 288 |
| 290 private: | 289 private: |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 content::DownloadId download_id, | 324 content::DownloadId download_id, |
| 326 const content::DownloadPersistentStoreInfo& info, | 325 const content::DownloadPersistentStoreInfo& info, |
| 327 const net::BoundNetLog& bound_net_log) { | 326 const net::BoundNetLog& bound_net_log) { |
| 328 int local_id = download_id.local(); | 327 int local_id = download_id.local(); |
| 329 DCHECK(items_.find(local_id) == items_.end()); | 328 DCHECK(items_.find(local_id) == items_.end()); |
| 330 | 329 |
| 331 MockDownloadItemImpl* result = | 330 MockDownloadItemImpl* result = |
| 332 new StrictMock<MockDownloadItemImpl>(&item_delegate_); | 331 new StrictMock<MockDownloadItemImpl>(&item_delegate_); |
| 333 EXPECT_CALL(*result, GetId()) | 332 EXPECT_CALL(*result, GetId()) |
| 334 .WillRepeatedly(Return(local_id)); | 333 .WillRepeatedly(Return(local_id)); |
| 334 EXPECT_CALL(*result, DebugString(true)) |
| 335 .WillRepeatedly(Return(std::string())); |
| 335 items_[local_id] = result; | 336 items_[local_id] = result; |
| 336 | 337 |
| 337 return result; | 338 return result; |
| 338 } | 339 } |
| 339 | 340 |
| 340 DownloadItemImpl* MockDownloadItemFactory::CreateActiveItem( | 341 DownloadItemImpl* MockDownloadItemFactory::CreateActiveItem( |
| 341 DownloadItemImplDelegate* delegate, | 342 DownloadItemImplDelegate* delegate, |
| 342 const DownloadCreateInfo& info, | 343 const DownloadCreateInfo& info, |
| 343 scoped_ptr<DownloadRequestHandleInterface> request_handle, | |
| 344 const net::BoundNetLog& bound_net_log) { | 344 const net::BoundNetLog& bound_net_log) { |
| 345 int local_id = info.download_id.local(); | 345 int local_id = info.download_id.local(); |
| 346 DCHECK(items_.find(local_id) == items_.end()); | 346 DCHECK(items_.find(local_id) == items_.end()); |
| 347 | 347 |
| 348 MockDownloadItemImpl* result = | 348 MockDownloadItemImpl* result = |
| 349 new StrictMock<MockDownloadItemImpl>(&item_delegate_); | 349 new StrictMock<MockDownloadItemImpl>(&item_delegate_); |
| 350 EXPECT_CALL(*result, GetId()) | 350 EXPECT_CALL(*result, GetId()) |
| 351 .WillRepeatedly(Return(local_id)); | 351 .WillRepeatedly(Return(local_id)); |
| 352 EXPECT_CALL(*result, DebugString(true)) |
| 353 .WillRepeatedly(Return(std::string())); |
| 352 items_[local_id] = result; | 354 items_[local_id] = result; |
| 353 | 355 |
| 354 return result; | 356 return result; |
| 355 } | 357 } |
| 356 | 358 |
| 357 DownloadItemImpl* MockDownloadItemFactory::CreateSavePageItem( | 359 DownloadItemImpl* MockDownloadItemFactory::CreateSavePageItem( |
| 358 DownloadItemImplDelegate* delegate, | 360 DownloadItemImplDelegate* delegate, |
| 359 const FilePath& path, | 361 const FilePath& path, |
| 360 const GURL& url, | 362 const GURL& url, |
| 361 content::DownloadId download_id, | 363 content::DownloadId download_id, |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 // Does DownloadStopped remove Download from appropriate queues? | 628 // Does DownloadStopped remove Download from appropriate queues? |
| 627 // This test tests non-persisted downloads. | 629 // This test tests non-persisted downloads. |
| 628 TEST_F(DownloadManagerTest, OnDownloadStopped_NonPersisted) { | 630 TEST_F(DownloadManagerTest, OnDownloadStopped_NonPersisted) { |
| 629 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | 631 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 630 .WillOnce(Return()); | 632 .WillOnce(Return()); |
| 631 // Put a mock we have a handle to on the download manager. | 633 // Put a mock we have a handle to on the download manager. |
| 632 MockDownloadItemImpl& item(AddItemToManager()); | 634 MockDownloadItemImpl& item(AddItemToManager()); |
| 633 | 635 |
| 634 EXPECT_CALL(item, IsPersisted()) | 636 EXPECT_CALL(item, IsPersisted()) |
| 635 .WillRepeatedly(Return(false)); | 637 .WillRepeatedly(Return(false)); |
| 638 EXPECT_CALL(item, IsInterrupted()) |
| 639 .WillRepeatedly(Return(false)); |
| 636 EXPECT_CALL(item, GetState()) | 640 EXPECT_CALL(item, GetState()) |
| 637 .WillRepeatedly(Return(DownloadItem::CANCELLED)); | 641 .WillRepeatedly(Return(DownloadItem::CANCELLED)); |
| 638 EXPECT_CALL(item, GetDbHandle()) | 642 EXPECT_CALL(item, GetDbHandle()) |
| 639 .WillRepeatedly(Return(DownloadItem::kUninitializedHandle)); | 643 .WillRepeatedly(Return(DownloadItem::kUninitializedHandle)); |
| 640 | 644 |
| 641 EXPECT_CALL(item, OffThreadCancel()); | 645 EXPECT_CALL(item, OffThreadCancel()); |
| 642 DownloadStopped(&item); | 646 DownloadStopped(&item); |
| 643 } | 647 } |
| 644 | 648 |
| 645 // Does DownloadStopped remove Download from appropriate queues? | 649 // Does DownloadStopped remove Download from appropriate queues? |
| 646 // This test tests persisted downloads. | 650 // This test tests persisted downloads. |
| 647 TEST_F(DownloadManagerTest, OnDownloadStopped_Persisted) { | 651 TEST_F(DownloadManagerTest, OnDownloadStopped_Persisted) { |
| 648 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | 652 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 649 .WillOnce(Return()); | 653 .WillOnce(Return()); |
| 650 // Put a mock we have a handle to on the download manager. | 654 // Put a mock we have a handle to on the download manager. |
| 651 MockDownloadItemImpl& item(AddItemToManager()); | 655 MockDownloadItemImpl& item(AddItemToManager()); |
| 652 int64 db_handle = 0x7; | 656 int64 db_handle = 0x7; |
| 653 EXPECT_CALL(GetMockObserver(), ModelChanged(download_manager_.get())) | 657 EXPECT_CALL(GetMockObserver(), ModelChanged(download_manager_.get())) |
| 654 .WillOnce(Return()); | 658 .WillOnce(Return()); |
| 655 AddItemToHistory(item, db_handle); | 659 AddItemToHistory(item, db_handle); |
| 656 | 660 |
| 657 EXPECT_CALL(item, IsPersisted()) | 661 EXPECT_CALL(item, IsPersisted()) |
| 658 .WillRepeatedly(Return(true)); | 662 .WillRepeatedly(Return(true)); |
| 663 EXPECT_CALL(item, IsInterrupted()) |
| 664 .WillRepeatedly(Return(false)); |
| 659 EXPECT_CALL(GetMockDownloadManagerDelegate(), | 665 EXPECT_CALL(GetMockDownloadManagerDelegate(), |
| 660 UpdateItemInPersistentStore(&item)); | 666 UpdateItemInPersistentStore(&item)); |
| 661 EXPECT_CALL(item, GetState()) | 667 EXPECT_CALL(item, GetState()) |
| 662 .WillRepeatedly(Return(DownloadItem::CANCELLED)); | 668 .WillRepeatedly(Return(DownloadItem::CANCELLED)); |
| 663 EXPECT_CALL(item, GetDbHandle()) | 669 EXPECT_CALL(item, GetDbHandle()) |
| 664 .WillRepeatedly(Return(db_handle)); | 670 .WillRepeatedly(Return(db_handle)); |
| 665 | 671 |
| 666 EXPECT_CALL(item, OffThreadCancel()); | 672 EXPECT_CALL(item, OffThreadCancel()); |
| 667 DownloadStopped(&item); | 673 DownloadStopped(&item); |
| 668 } | 674 } |
| OLD | NEW |