Index: content/browser/download/download_manager_impl_unittest.cc |
diff --git a/content/browser/download/download_manager_impl_unittest.cc b/content/browser/download/download_manager_impl_unittest.cc |
index 52adff4010e44aef4d21566bd76fedc0cca3dec8..3a233fed543859a148a8ac722e15a428bd297de5 100644 |
--- a/content/browser/download/download_manager_impl_unittest.cc |
+++ b/content/browser/download/download_manager_impl_unittest.cc |
@@ -37,6 +37,7 @@ |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gmock_mutant.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "url/origin.h" |
using ::testing::AllOf; |
using ::testing::DoAll; |
@@ -445,12 +446,17 @@ class DownloadManagerTest : public testing::Test { |
public: |
static const char* kTestData; |
static const size_t kTestDataLen; |
+ std::vector<GURL> download_urls; |
DownloadManagerTest() |
: callback_called_(false), |
ui_thread_(BrowserThread::UI, &message_loop_), |
file_thread_(BrowserThread::FILE, &message_loop_), |
next_download_id_(0) { |
+ download_urls.push_back(GURL("http://www.url1.com")); |
+ download_urls.push_back(GURL("http://www.url2.com")); |
+ download_urls.push_back(GURL("http://www.url3.com")); |
+ download_urls.push_back(GURL("http://www.url4.com")); |
} |
// We tear down everything in TearDown(). |
@@ -521,6 +527,8 @@ class DownloadManagerTest : public testing::Test { |
// in the factory. |
scoped_ptr<DownloadRequestHandleInterface> req_handle; |
item.Start(scoped_ptr<DownloadFile>(), req_handle.Pass()); |
+ DCHECK(id < download_urls.size()); |
+ EXPECT_CALL(item, GetURL()).WillRepeatedly(ReturnRef(download_urls[id])); |
return item; |
} |
@@ -694,4 +702,23 @@ TEST_F(DownloadManagerTest, RemoveAllDownloads) { |
// result in them being removed from the DownloadManager list. |
} |
+// Confirm that only downloads with same origin are removed. |
+TEST_F(DownloadManagerTest, RemoveSameOriginDownloads) { |
+ base::Time now(base::Time::Now()); |
+ for (uint32 i = 0; i < 2; ++i) { |
+ MockDownloadItemImpl& item(AddItemToManager()); |
+ EXPECT_CALL(item, GetStartTime()).WillRepeatedly(Return(now)); |
+ EXPECT_CALL(item, GetState()) |
+ .WillRepeatedly(Return(DownloadItem::COMPLETE)); |
+ } |
+ |
+ EXPECT_CALL(GetMockDownloadItem(0), Remove()); |
Randy Smith (Not in Mondays)
2015/08/05 16:02:04
Do you need a ::testing::Mock::VerifyAndClearExpec
Timo Reimann
2015/08/05 20:07:46
I notice that none of the other (similar looking)
|
+ EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0); |
+ |
+ url::Origin origin_to_clear(download_urls[0]); |
+ int remove_count = download_manager_->RemoveDownloadsByOriginAndTime( |
+ origin_to_clear, base::Time(), base::Time::Max()); |
+ EXPECT_EQ(remove_count, 1); |
+} |
+ |
} // namespace content |