Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(774)

Side by Side Diff: content/browser/download/download_manager_impl_unittest.cc

Issue 2593183002: [downloads] Remove DownloadManager::RemoveAllDownloads. (Closed)
Patch Set: Fix SavePageBrowsertest Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/browser/download/download_manager_impl.h" 5 #include "content/browser/download/download_manager_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 // Confirm that the callback was called with the right values in this case. 697 // Confirm that the callback was called with the right values in this case.
698 callback_called_ = false; 698 callback_called_ = false;
699 DetermineDownloadTarget(&item); 699 DetermineDownloadTarget(&item);
700 EXPECT_TRUE(callback_called_); 700 EXPECT_TRUE(callback_called_);
701 EXPECT_EQ(path, target_path_); 701 EXPECT_EQ(path, target_path_);
702 EXPECT_EQ(DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_disposition_); 702 EXPECT_EQ(DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_disposition_);
703 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, danger_type_); 703 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, danger_type_);
704 EXPECT_EQ(path, intermediate_path_); 704 EXPECT_EQ(path, intermediate_path_);
705 } 705 }
706 706
707 // Confirm the DownloadManagerImpl::RemoveAllDownloads() functionality
708 TEST_F(DownloadManagerTest, RemoveAllDownloads) {
709 base::Time now(base::Time::Now());
710 for (uint32_t i = 0; i < 4; ++i) {
711 MockDownloadItemImpl& item(AddItemToManager());
712 EXPECT_EQ(i, item.GetId());
713 EXPECT_CALL(item, GetStartTime())
714 .WillRepeatedly(Return(now));
715 }
716
717 // Specify states for each.
718 EXPECT_CALL(GetMockDownloadItem(0), GetState())
719 .WillRepeatedly(Return(DownloadItem::COMPLETE));
720 EXPECT_CALL(GetMockDownloadItem(1), GetState())
721 .WillRepeatedly(Return(DownloadItem::CANCELLED));
722 EXPECT_CALL(GetMockDownloadItem(2), GetState())
723 .WillRepeatedly(Return(DownloadItem::INTERRUPTED));
724 EXPECT_CALL(GetMockDownloadItem(3), GetState())
725 .WillRepeatedly(Return(DownloadItem::IN_PROGRESS));
726
727 // Expectations for whether or not they'll actually be removed.
728 EXPECT_CALL(GetMockDownloadItem(0), Remove())
729 .WillOnce(Return());
730 EXPECT_CALL(GetMockDownloadItem(1), Remove())
731 .WillOnce(Return());
732 EXPECT_CALL(GetMockDownloadItem(2), Remove())
733 .WillOnce(Return());
734 EXPECT_CALL(GetMockDownloadItem(3), Remove())
735 .Times(0);
736
737 download_manager_->RemoveAllDownloads();
738 // Because we're mocking the download item, the Remove call doesn't
739 // result in them being removed from the DownloadManager list.
740 }
741
742 TEST_F(DownloadManagerTest, GetDownloadByGuid) { 707 TEST_F(DownloadManagerTest, GetDownloadByGuid) {
743 for (uint32_t i = 0; i < 4; ++i) 708 for (uint32_t i = 0; i < 4; ++i)
744 AddItemToManager(); 709 AddItemToManager();
745 710
746 MockDownloadItemImpl& item = GetMockDownloadItem(0); 711 MockDownloadItemImpl& item = GetMockDownloadItem(0);
747 DownloadItem* result = download_manager_->GetDownloadByGuid(item.GetGuid()); 712 DownloadItem* result = download_manager_->GetDownloadByGuid(item.GetGuid());
748 ASSERT_TRUE(result); 713 ASSERT_TRUE(result);
749 ASSERT_EQ(static_cast<DownloadItem*>(&item), result); 714 ASSERT_EQ(static_cast<DownloadItem*>(&item), result);
750 715
751 ASSERT_FALSE(download_manager_->GetDownloadByGuid("")); 716 ASSERT_FALSE(download_manager_->GetDownloadByGuid(""));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0); 752 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0);
788 753
789 base::Callback<bool(const GURL&)> url_filter = 754 base::Callback<bool(const GURL&)> url_filter =
790 GetSingleURLFilter(download_urls_[0]); 755 GetSingleURLFilter(download_urls_[0]);
791 int remove_count = download_manager_->RemoveDownloadsByURLAndTime( 756 int remove_count = download_manager_->RemoveDownloadsByURLAndTime(
792 url_filter, base::Time(), base::Time::Max()); 757 url_filter, base::Time(), base::Time::Max());
793 EXPECT_EQ(remove_count, 1); 758 EXPECT_EQ(remove_count, 1);
794 } 759 }
795 760
796 } // namespace content 761 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_manager_impl.cc ('k') | content/browser/download/download_stats.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698