| 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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 | 564 |
| 565 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); | 565 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); |
| 566 }; | 566 }; |
| 567 | 567 |
| 568 // Confirm the appropriate invocations occur when you start a download. | 568 // Confirm the appropriate invocations occur when you start a download. |
| 569 TEST_F(DownloadManagerTest, StartDownload) { | 569 TEST_F(DownloadManagerTest, StartDownload) { |
| 570 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); | 570 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); |
| 571 scoped_ptr<content::ByteStreamReader> stream; | 571 scoped_ptr<content::ByteStreamReader> stream; |
| 572 int32 local_id(5); // Random value | 572 int32 local_id(5); // Random value |
| 573 | 573 |
| 574 EXPECT_FALSE(download_manager_->GetActiveDownloadItem(local_id)); | 574 EXPECT_FALSE(download_manager_->GetDownload(local_id)); |
| 575 | 575 |
| 576 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | 576 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 577 .WillOnce(Return()); | 577 .WillOnce(Return()); |
| 578 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId()) | 578 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId()) |
| 579 .WillOnce(Return(content::DownloadId(this, local_id))); | 579 .WillOnce(Return(content::DownloadId(this, local_id))); |
| 580 EXPECT_CALL(GetMockDownloadManagerDelegate(), GenerateFileHash()) | 580 EXPECT_CALL(GetMockDownloadManagerDelegate(), GenerateFileHash()) |
| 581 .WillOnce(Return(true)); | 581 .WillOnce(Return(true)); |
| 582 EXPECT_CALL(GetMockDownloadFileManager(), MockCreateDownloadFile( | 582 EXPECT_CALL(GetMockDownloadFileManager(), MockCreateDownloadFile( |
| 583 info.get(), static_cast<content::ByteStreamReader*>(NULL), | 583 info.get(), static_cast<content::ByteStreamReader*>(NULL), |
| 584 download_manager_.get(), true, _, _)); | 584 download_manager_.get(), true, _, _)); |
| 585 | 585 |
| 586 download_manager_->StartDownload(info.Pass(), stream.Pass()); | 586 download_manager_->StartDownload(info.Pass(), stream.Pass()); |
| 587 EXPECT_TRUE(download_manager_->GetActiveDownloadItem(local_id)); | 587 EXPECT_TRUE(download_manager_->GetDownload(local_id)); |
| 588 } | 588 } |
| 589 | 589 |
| 590 // Do the results of an OnDownloadInterrupted get passed through properly | 590 // Do the results of an OnDownloadInterrupted get passed through properly |
| 591 // to the DownloadItem? | 591 // to the DownloadItem? |
| 592 TEST_F(DownloadManagerTest, OnDownloadInterrupted) { | 592 TEST_F(DownloadManagerTest, OnDownloadInterrupted) { |
| 593 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | 593 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 594 .WillOnce(Return()); | 594 .WillOnce(Return()); |
| 595 // Put a mock we have a handle to on the download manager. | 595 // Put a mock we have a handle to on the download manager. |
| 596 MockDownloadItemImpl& item(AddItemToManager()); | 596 MockDownloadItemImpl& item(AddItemToManager()); |
| 597 int download_id = item.GetId(); | 597 int download_id = item.GetId(); |
| 598 | 598 |
| 599 content::DownloadInterruptReason reason( | 599 content::DownloadInterruptReason reason( |
| 600 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); | 600 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); |
| 601 | 601 |
| 602 EXPECT_CALL(item, Interrupt(reason)); | 602 EXPECT_CALL(item, Interrupt(reason)); |
| 603 download_manager_->OnDownloadInterrupted(download_id, reason); | 603 download_manager_->OnDownloadInterrupted(download_id, reason); |
| 604 EXPECT_EQ(&item, download_manager_->GetActiveDownloadItem(download_id)); | 604 EXPECT_EQ(&item, download_manager_->GetDownload(download_id)); |
| 605 } | 605 } |
| 606 | |
| 607 // Does DownloadStopped remove Download from appropriate queues? | |
| 608 // This test tests non-persisted downloads. | |
| 609 TEST_F(DownloadManagerTest, OnDownloadStopped_NonPersisted) { | |
| 610 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | |
| 611 .WillOnce(Return()); | |
| 612 // Put a mock we have a handle to on the download manager. | |
| 613 MockDownloadItemImpl& item(AddItemToManager()); | |
| 614 | |
| 615 EXPECT_CALL(item, IsPersisted()) | |
| 616 .WillRepeatedly(Return(false)); | |
| 617 EXPECT_CALL(item, GetState()) | |
| 618 .WillRepeatedly(Return(DownloadItem::CANCELLED)); | |
| 619 EXPECT_CALL(item, GetDbHandle()) | |
| 620 .WillRepeatedly(Return(DownloadItem::kUninitializedHandle)); | |
| 621 | |
| 622 EXPECT_CALL(item, OffThreadCancel()); | |
| 623 DownloadStopped(&item); | |
| 624 // TODO(rdsmith): Confirm that the download item is no longer on the | |
| 625 // active list by calling download_manager_->GetActiveDownloadItem(id). | |
| 626 // Currently, the item is left on the active list for rendez-vous with | |
| 627 // the history system :-{. | |
| 628 } | |
| 629 | |
| 630 // Does DownloadStopped remove Download from appropriate queues? | |
| 631 // This test tests persisted downloads. | |
| 632 TEST_F(DownloadManagerTest, OnDownloadStopped_Persisted) { | |
| 633 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | |
| 634 .WillOnce(Return()); | |
| 635 // Put a mock we have a handle to on the download manager. | |
| 636 MockDownloadItemImpl& item(AddItemToManager()); | |
| 637 int download_id = item.GetId(); | |
| 638 int64 db_handle = 0x7; | |
| 639 EXPECT_CALL(GetMockObserver(), ModelChanged(download_manager_.get())) | |
| 640 .WillOnce(Return()); | |
| 641 AddItemToHistory(item, db_handle); | |
| 642 | |
| 643 EXPECT_CALL(item, IsPersisted()) | |
| 644 .WillRepeatedly(Return(true)); | |
| 645 EXPECT_CALL(GetMockDownloadManagerDelegate(), | |
| 646 UpdateItemInPersistentStore(&item)); | |
| 647 EXPECT_CALL(item, GetState()) | |
| 648 .WillRepeatedly(Return(DownloadItem::CANCELLED)); | |
| 649 EXPECT_CALL(item, GetDbHandle()) | |
| 650 .WillRepeatedly(Return(db_handle)); | |
| 651 | |
| 652 EXPECT_CALL(item, OffThreadCancel()); | |
| 653 DownloadStopped(&item); | |
| 654 EXPECT_EQ(NULL, download_manager_->GetActiveDownloadItem(download_id)); | |
| 655 } | |
| OLD | NEW |