| 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 "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 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 EXPECT_CALL(GetMockDownloadItem(2), Remove()) | 700 EXPECT_CALL(GetMockDownloadItem(2), Remove()) |
| 701 .WillOnce(Return()); | 701 .WillOnce(Return()); |
| 702 EXPECT_CALL(GetMockDownloadItem(3), Remove()) | 702 EXPECT_CALL(GetMockDownloadItem(3), Remove()) |
| 703 .Times(0); | 703 .Times(0); |
| 704 | 704 |
| 705 download_manager_->RemoveAllDownloads(); | 705 download_manager_->RemoveAllDownloads(); |
| 706 // Because we're mocking the download item, the Remove call doesn't | 706 // Because we're mocking the download item, the Remove call doesn't |
| 707 // result in them being removed from the DownloadManager list. | 707 // result in them being removed from the DownloadManager list. |
| 708 } | 708 } |
| 709 | 709 |
| 710 // Confirm that only downloads with same origin are removed. | 710 namespace { |
| 711 TEST_F(DownloadManagerTest, RemoveSameOriginDownloads) { | 711 |
| 712 base::Callback<bool(const GURL&)> GetSingleURLFilter(const GURL& url) { |
| 713 return base::Bind(&GURL::operator==, base::Owned(new GURL(url))); |
| 714 } |
| 715 |
| 716 } // namespace |
| 717 |
| 718 // Confirm that only downloads with the specified URL are removed. |
| 719 TEST_F(DownloadManagerTest, RemoveDownloadsByURL) { |
| 712 base::Time now(base::Time::Now()); | 720 base::Time now(base::Time::Now()); |
| 713 for (uint32_t i = 0; i < 2; ++i) { | 721 for (uint32_t i = 0; i < 2; ++i) { |
| 714 MockDownloadItemImpl& item(AddItemToManager()); | 722 MockDownloadItemImpl& item(AddItemToManager()); |
| 715 EXPECT_CALL(item, GetStartTime()).WillRepeatedly(Return(now)); | 723 EXPECT_CALL(item, GetStartTime()).WillRepeatedly(Return(now)); |
| 716 EXPECT_CALL(item, GetState()) | 724 EXPECT_CALL(item, GetState()) |
| 717 .WillRepeatedly(Return(DownloadItem::COMPLETE)); | 725 .WillRepeatedly(Return(DownloadItem::COMPLETE)); |
| 718 } | 726 } |
| 719 | 727 |
| 720 EXPECT_CALL(GetMockDownloadItem(0), Remove()); | 728 EXPECT_CALL(GetMockDownloadItem(0), Remove()); |
| 721 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0); | 729 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0); |
| 722 | 730 |
| 723 url::Origin origin_to_clear(download_urls_[0]); | 731 base::Callback<bool(const GURL&)> url_filter = |
| 724 int remove_count = download_manager_->RemoveDownloadsByOriginAndTime( | 732 GetSingleURLFilter(download_urls_[0]); |
| 725 origin_to_clear, base::Time(), base::Time::Max()); | 733 int remove_count = download_manager_->RemoveDownloadsByURLAndTime( |
| 734 url_filter, base::Time(), base::Time::Max()); |
| 726 EXPECT_EQ(remove_count, 1); | 735 EXPECT_EQ(remove_count, 1); |
| 727 } | 736 } |
| 728 | 737 |
| 729 } // namespace content | 738 } // namespace content |
| OLD | NEW |