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()); | 118 MOCK_CONST_METHOD0(IsCancelled, bool()); |
benjhayden
2013/06/13 19:01:45
Also remove IsCancelled, IsInterrupted, IsComplete
| |
120 MOCK_CONST_METHOD0(IsInterrupted, bool()); | 119 MOCK_CONST_METHOD0(IsInterrupted, bool()); |
121 MOCK_CONST_METHOD0(IsComplete, bool()); | 120 MOCK_CONST_METHOD0(IsComplete, bool()); |
122 MOCK_CONST_METHOD0(GetFullPath, const base::FilePath&()); | 121 MOCK_CONST_METHOD0(GetFullPath, const base::FilePath&()); |
123 MOCK_CONST_METHOD0(GetTargetFilePath, const base::FilePath&()); | 122 MOCK_CONST_METHOD0(GetTargetFilePath, const base::FilePath&()); |
124 MOCK_CONST_METHOD0(GetTargetDisposition, TargetDisposition()); | 123 MOCK_CONST_METHOD0(GetTargetDisposition, TargetDisposition()); |
125 MOCK_METHOD1(OnContentCheckCompleted, void(DownloadDangerType)); | 124 MOCK_METHOD1(OnContentCheckCompleted, void(DownloadDangerType)); |
126 MOCK_CONST_METHOD0(GetState, DownloadState()); | 125 MOCK_CONST_METHOD0(GetState, DownloadState()); |
127 MOCK_CONST_METHOD0(GetUrlChain, const std::vector<GURL>&()); | 126 MOCK_CONST_METHOD0(GetUrlChain, const std::vector<GURL>&()); |
128 MOCK_METHOD1(SetTotalBytes, void(int64)); | 127 MOCK_METHOD1(SetTotalBytes, void(int64)); |
129 MOCK_CONST_METHOD0(GetURL, const GURL&()); | 128 MOCK_CONST_METHOD0(GetURL, const GURL&()); |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
600 | 599 |
601 download_manager_->StartDownload(info.Pass(), stream.Pass()); | 600 download_manager_->StartDownload(info.Pass(), stream.Pass()); |
602 EXPECT_TRUE(download_manager_->GetDownload(local_id)); | 601 EXPECT_TRUE(download_manager_->GetDownload(local_id)); |
603 } | 602 } |
604 | 603 |
605 // Confirm that calling DetermineDownloadTarget behaves properly if the delegate | 604 // Confirm that calling DetermineDownloadTarget behaves properly if the delegate |
606 // blocks starting. | 605 // blocks starting. |
607 TEST_F(DownloadManagerTest, DetermineDownloadTarget_True) { | 606 TEST_F(DownloadManagerTest, DetermineDownloadTarget_True) { |
608 // Put a mock we have a handle to on the download manager. | 607 // Put a mock we have a handle to on the download manager. |
609 MockDownloadItemImpl& item(AddItemToManager()); | 608 MockDownloadItemImpl& item(AddItemToManager()); |
610 EXPECT_CALL(item, IsInProgress()) | 609 EXPECT_CALL(item, GetState()) |
611 .WillRepeatedly(Return(true)); | 610 .WillRepeatedly(Return(DownloadItem::IN_PROGRESS)); |
612 | 611 |
613 EXPECT_CALL(GetMockDownloadManagerDelegate(), | 612 EXPECT_CALL(GetMockDownloadManagerDelegate(), |
614 DetermineDownloadTarget(&item, _)) | 613 DetermineDownloadTarget(&item, _)) |
615 .WillOnce(Return(true)); | 614 .WillOnce(Return(true)); |
616 DetermineDownloadTarget(&item); | 615 DetermineDownloadTarget(&item); |
617 } | 616 } |
618 | 617 |
619 // Confirm that calling DetermineDownloadTarget behaves properly if the delegate | 618 // Confirm that calling DetermineDownloadTarget behaves properly if the delegate |
620 // allows starting. This also tests OnDownloadTargetDetermined. | 619 // allows starting. This also tests OnDownloadTargetDetermined. |
621 TEST_F(DownloadManagerTest, DetermineDownloadTarget_False) { | 620 TEST_F(DownloadManagerTest, DetermineDownloadTarget_False) { |
(...skipping 18 matching lines...) Expand all Loading... | |
640 } | 639 } |
641 | 640 |
642 // Confirm the DownloadManagerImpl::RemoveAllDownloads() functionality | 641 // Confirm the DownloadManagerImpl::RemoveAllDownloads() functionality |
643 TEST_F(DownloadManagerTest, RemoveAllDownloads) { | 642 TEST_F(DownloadManagerTest, RemoveAllDownloads) { |
644 base::Time now(base::Time::Now()); | 643 base::Time now(base::Time::Now()); |
645 for (int i = 0; i < 4; ++i) { | 644 for (int i = 0; i < 4; ++i) { |
646 MockDownloadItemImpl& item(AddItemToManager()); | 645 MockDownloadItemImpl& item(AddItemToManager()); |
647 EXPECT_EQ(i, item.GetId()); | 646 EXPECT_EQ(i, item.GetId()); |
648 EXPECT_CALL(item, GetStartTime()) | 647 EXPECT_CALL(item, GetStartTime()) |
649 .WillRepeatedly(Return(now)); | 648 .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 } | 649 } |
661 | 650 |
662 // Specify states for each. | 651 // Specify states for each. |
663 EXPECT_CALL(GetMockDownloadItem(0), IsComplete()) | 652 EXPECT_CALL(GetMockDownloadItem(0), GetState()) |
664 .WillRepeatedly(Return(true)); | 653 .WillRepeatedly(Return(DownloadItem::COMPLETE)); |
665 EXPECT_CALL(GetMockDownloadItem(1), IsCancelled()) | 654 EXPECT_CALL(GetMockDownloadItem(1), GetState()) |
666 .WillRepeatedly(Return(true)); | 655 .WillRepeatedly(Return(DownloadItem::CANCELLED)); |
667 EXPECT_CALL(GetMockDownloadItem(2), IsInterrupted()) | 656 EXPECT_CALL(GetMockDownloadItem(2), GetState()) |
668 .WillRepeatedly(Return(true)); | 657 .WillRepeatedly(Return(DownloadItem::INTERRUPTED)); |
669 EXPECT_CALL(GetMockDownloadItem(3), IsInProgress()) | 658 EXPECT_CALL(GetMockDownloadItem(3), GetState()) |
670 .WillRepeatedly(Return(true)); | 659 .WillRepeatedly(Return(DownloadItem::IN_PROGRESS)); |
671 | 660 |
672 // Expectations for whether or not they'll actually be removed. | 661 // Expectations for whether or not they'll actually be removed. |
673 EXPECT_CALL(GetMockDownloadItem(0), Remove()) | 662 EXPECT_CALL(GetMockDownloadItem(0), Remove()) |
674 .WillOnce(Return()); | 663 .WillOnce(Return()); |
675 EXPECT_CALL(GetMockDownloadItem(1), Remove()) | 664 EXPECT_CALL(GetMockDownloadItem(1), Remove()) |
676 .WillOnce(Return()); | 665 .WillOnce(Return()); |
677 EXPECT_CALL(GetMockDownloadItem(2), Remove()) | 666 EXPECT_CALL(GetMockDownloadItem(2), Remove()) |
678 .WillOnce(Return()); | 667 .WillOnce(Return()); |
679 EXPECT_CALL(GetMockDownloadItem(3), Remove()) | 668 EXPECT_CALL(GetMockDownloadItem(3), Remove()) |
680 .Times(0); | 669 .Times(0); |
681 | 670 |
682 download_manager_->RemoveAllDownloads(); | 671 download_manager_->RemoveAllDownloads(); |
683 // Because we're mocking the download item, the Remove call doesn't | 672 // Because we're mocking the download item, the Remove call doesn't |
684 // result in them being removed from the DownloadManager list. | 673 // result in them being removed from the DownloadManager list. |
685 } | 674 } |
686 | 675 |
687 } // namespace content | 676 } // namespace content |
OLD | NEW |