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