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/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 MOCK_METHOD2(MockStart, void(DownloadFile*, DownloadRequestHandleInterface*)); | 109 MOCK_METHOD2(MockStart, void(DownloadFile*, DownloadRequestHandleInterface*)); |
110 | 110 |
111 MOCK_METHOD0(Remove, void()); | 111 MOCK_METHOD0(Remove, void()); |
112 MOCK_CONST_METHOD1(TimeRemaining, bool(base::TimeDelta*)); | 112 MOCK_CONST_METHOD1(TimeRemaining, bool(base::TimeDelta*)); |
113 MOCK_CONST_METHOD0(CurrentSpeed, int64()); | 113 MOCK_CONST_METHOD0(CurrentSpeed, int64()); |
114 MOCK_CONST_METHOD0(PercentComplete, int()); | 114 MOCK_CONST_METHOD0(PercentComplete, int()); |
115 MOCK_CONST_METHOD0(AllDataSaved, bool()); | 115 MOCK_CONST_METHOD0(AllDataSaved, bool()); |
116 MOCK_CONST_METHOD1(MatchesQuery, bool(const string16& query)); | 116 MOCK_CONST_METHOD1(MatchesQuery, bool(const string16& query)); |
117 MOCK_CONST_METHOD0(IsDone, bool()); | 117 MOCK_CONST_METHOD0(IsDone, bool()); |
118 MOCK_CONST_METHOD0(IsInProgress, bool()); | |
119 MOCK_CONST_METHOD0(IsCancelled, bool()); | |
120 MOCK_CONST_METHOD0(IsInterrupted, bool()); | |
121 MOCK_CONST_METHOD0(IsComplete, bool()); | |
122 MOCK_CONST_METHOD0(GetFullPath, const base::FilePath&()); | 118 MOCK_CONST_METHOD0(GetFullPath, const base::FilePath&()); |
123 MOCK_CONST_METHOD0(GetTargetFilePath, const base::FilePath&()); | 119 MOCK_CONST_METHOD0(GetTargetFilePath, const base::FilePath&()); |
124 MOCK_CONST_METHOD0(GetTargetDisposition, TargetDisposition()); | 120 MOCK_CONST_METHOD0(GetTargetDisposition, TargetDisposition()); |
125 MOCK_METHOD1(OnContentCheckCompleted, void(DownloadDangerType)); | 121 MOCK_METHOD1(OnContentCheckCompleted, void(DownloadDangerType)); |
126 MOCK_CONST_METHOD0(GetState, DownloadState()); | 122 MOCK_CONST_METHOD0(GetState, DownloadState()); |
127 MOCK_CONST_METHOD0(GetUrlChain, const std::vector<GURL>&()); | 123 MOCK_CONST_METHOD0(GetUrlChain, const std::vector<GURL>&()); |
128 MOCK_METHOD1(SetTotalBytes, void(int64)); | 124 MOCK_METHOD1(SetTotalBytes, void(int64)); |
129 MOCK_CONST_METHOD0(GetURL, const GURL&()); | 125 MOCK_CONST_METHOD0(GetURL, const GURL&()); |
130 MOCK_CONST_METHOD0(GetOriginalUrl, const GURL&()); | 126 MOCK_CONST_METHOD0(GetOriginalUrl, const GURL&()); |
131 MOCK_CONST_METHOD0(GetReferrerUrl, const GURL&()); | 127 MOCK_CONST_METHOD0(GetReferrerUrl, const GURL&()); |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 | 596 |
601 download_manager_->StartDownload(info.Pass(), stream.Pass()); | 597 download_manager_->StartDownload(info.Pass(), stream.Pass()); |
602 EXPECT_TRUE(download_manager_->GetDownload(local_id)); | 598 EXPECT_TRUE(download_manager_->GetDownload(local_id)); |
603 } | 599 } |
604 | 600 |
605 // Confirm that calling DetermineDownloadTarget behaves properly if the delegate | 601 // Confirm that calling DetermineDownloadTarget behaves properly if the delegate |
606 // blocks starting. | 602 // blocks starting. |
607 TEST_F(DownloadManagerTest, DetermineDownloadTarget_True) { | 603 TEST_F(DownloadManagerTest, DetermineDownloadTarget_True) { |
608 // Put a mock we have a handle to on the download manager. | 604 // Put a mock we have a handle to on the download manager. |
609 MockDownloadItemImpl& item(AddItemToManager()); | 605 MockDownloadItemImpl& item(AddItemToManager()); |
610 EXPECT_CALL(item, IsInProgress()) | 606 EXPECT_CALL(item, GetState()) |
611 .WillRepeatedly(Return(true)); | 607 .WillRepeatedly(Return(DownloadItem::IN_PROGRESS)); |
612 | 608 |
613 EXPECT_CALL(GetMockDownloadManagerDelegate(), | 609 EXPECT_CALL(GetMockDownloadManagerDelegate(), |
614 DetermineDownloadTarget(&item, _)) | 610 DetermineDownloadTarget(&item, _)) |
615 .WillOnce(Return(true)); | 611 .WillOnce(Return(true)); |
616 DetermineDownloadTarget(&item); | 612 DetermineDownloadTarget(&item); |
617 } | 613 } |
618 | 614 |
619 // Confirm that calling DetermineDownloadTarget behaves properly if the delegate | 615 // Confirm that calling DetermineDownloadTarget behaves properly if the delegate |
620 // allows starting. This also tests OnDownloadTargetDetermined. | 616 // allows starting. This also tests OnDownloadTargetDetermined. |
621 TEST_F(DownloadManagerTest, DetermineDownloadTarget_False) { | 617 TEST_F(DownloadManagerTest, DetermineDownloadTarget_False) { |
(...skipping 18 matching lines...) Expand all Loading... |
640 } | 636 } |
641 | 637 |
642 // Confirm the DownloadManagerImpl::RemoveAllDownloads() functionality | 638 // Confirm the DownloadManagerImpl::RemoveAllDownloads() functionality |
643 TEST_F(DownloadManagerTest, RemoveAllDownloads) { | 639 TEST_F(DownloadManagerTest, RemoveAllDownloads) { |
644 base::Time now(base::Time::Now()); | 640 base::Time now(base::Time::Now()); |
645 for (int i = 0; i < 4; ++i) { | 641 for (int i = 0; i < 4; ++i) { |
646 MockDownloadItemImpl& item(AddItemToManager()); | 642 MockDownloadItemImpl& item(AddItemToManager()); |
647 EXPECT_EQ(i, item.GetId()); | 643 EXPECT_EQ(i, item.GetId()); |
648 EXPECT_CALL(item, GetStartTime()) | 644 EXPECT_CALL(item, GetStartTime()) |
649 .WillRepeatedly(Return(now)); | 645 .WillRepeatedly(Return(now)); |
650 | |
651 // Default returns; overridden for each item below. | |
652 EXPECT_CALL(GetMockDownloadItem(i), IsComplete()) | |
653 .WillRepeatedly(Return(false)); | |
654 EXPECT_CALL(GetMockDownloadItem(i), IsCancelled()) | |
655 .WillRepeatedly(Return(false)); | |
656 EXPECT_CALL(GetMockDownloadItem(i), IsInterrupted()) | |
657 .WillRepeatedly(Return(false)); | |
658 EXPECT_CALL(GetMockDownloadItem(i), IsInProgress()) | |
659 .WillRepeatedly(Return(false)); | |
660 } | 646 } |
661 | 647 |
662 // Specify states for each. | 648 // Specify states for each. |
663 EXPECT_CALL(GetMockDownloadItem(0), IsComplete()) | 649 EXPECT_CALL(GetMockDownloadItem(0), GetState()) |
664 .WillRepeatedly(Return(true)); | 650 .WillRepeatedly(Return(DownloadItem::COMPLETE)); |
665 EXPECT_CALL(GetMockDownloadItem(1), IsCancelled()) | 651 EXPECT_CALL(GetMockDownloadItem(1), GetState()) |
666 .WillRepeatedly(Return(true)); | 652 .WillRepeatedly(Return(DownloadItem::CANCELLED)); |
667 EXPECT_CALL(GetMockDownloadItem(2), IsInterrupted()) | 653 EXPECT_CALL(GetMockDownloadItem(2), GetState()) |
668 .WillRepeatedly(Return(true)); | 654 .WillRepeatedly(Return(DownloadItem::INTERRUPTED)); |
669 EXPECT_CALL(GetMockDownloadItem(3), IsInProgress()) | 655 EXPECT_CALL(GetMockDownloadItem(3), GetState()) |
670 .WillRepeatedly(Return(true)); | 656 .WillRepeatedly(Return(DownloadItem::IN_PROGRESS)); |
671 | 657 |
672 // Expectations for whether or not they'll actually be removed. | 658 // Expectations for whether or not they'll actually be removed. |
673 EXPECT_CALL(GetMockDownloadItem(0), Remove()) | 659 EXPECT_CALL(GetMockDownloadItem(0), Remove()) |
674 .WillOnce(Return()); | 660 .WillOnce(Return()); |
675 EXPECT_CALL(GetMockDownloadItem(1), Remove()) | 661 EXPECT_CALL(GetMockDownloadItem(1), Remove()) |
676 .WillOnce(Return()); | 662 .WillOnce(Return()); |
677 EXPECT_CALL(GetMockDownloadItem(2), Remove()) | 663 EXPECT_CALL(GetMockDownloadItem(2), Remove()) |
678 .WillOnce(Return()); | 664 .WillOnce(Return()); |
679 EXPECT_CALL(GetMockDownloadItem(3), Remove()) | 665 EXPECT_CALL(GetMockDownloadItem(3), Remove()) |
680 .Times(0); | 666 .Times(0); |
681 | 667 |
682 download_manager_->RemoveAllDownloads(); | 668 download_manager_->RemoveAllDownloads(); |
683 // Because we're mocking the download item, the Remove call doesn't | 669 // Because we're mocking the download item, the Remove call doesn't |
684 // result in them being removed from the DownloadManager list. | 670 // result in them being removed from the DownloadManager list. |
685 } | 671 } |
686 | 672 |
687 } // namespace content | 673 } // namespace content |
OLD | NEW |