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

Unified Diff: content/browser/download/download_manager_impl_unittest.cc

Issue 1251243003: Support restricting browsing data removal for downloads by origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Add separate method to remove downloads by origin. Created 5 years, 4 months 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698