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

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: Created 5 years, 5 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..65c88263af6ab5e91005561e6158eef5d50f3816 100644
--- a/content/browser/download/download_manager_impl_unittest.cc
+++ b/content/browser/download/download_manager_impl_unittest.cc
@@ -59,6 +59,10 @@ class ByteStreamReader;
namespace {
+const GURL origin1("http://www.origin1.com");
+const GURL origin2("http://www.origin2.com");
+const GURL origin3("http://www.origin3.com");
+
// Matches a DownloadCreateInfo* that points to the same object as |info| and
// has a |default_download_directory| that matches |download_directory|.
MATCHER_P2(DownloadCreateInfoWithDefaultPath, info, download_directory, "") {
@@ -694,4 +698,85 @@ TEST_F(DownloadManagerTest, RemoveAllDownloads) {
// result in them being removed from the DownloadManager list.
}
+// Confirm that downloads without origin restrictions are removed.
+TEST_F(DownloadManagerTest, RemoveUnrestrictedOriginDownloads) {
+ base::Time now(base::Time::Now());
+ for (uint32 i = 0; i < 3; ++i) {
+ MockDownloadItemImpl& item(AddItemToManager());
+ EXPECT_CALL(item, GetStartTime())
+ .WillRepeatedly(Return(now));
+ EXPECT_CALL(item, GetState())
+ .WillRepeatedly(Return(DownloadItem::COMPLETE));
+ EXPECT_CALL(item, Remove());
+ }
+
+ EXPECT_CALL(GetMockDownloadItem(0), GetURL())
+ .WillRepeatedly(ReturnRef(origin1));
+ EXPECT_CALL(GetMockDownloadItem(1), GetURL())
+ .WillRepeatedly(ReturnRef(origin2));
+ EXPECT_CALL(GetMockDownloadItem(2), GetURL())
+ .WillRepeatedly(ReturnRef(origin3));
+
+ int remove_count = download_manager_->RemoveDownloadsBetween(
+ std::set<GURL>(), base::Time(), base::Time::Max());
+ EXPECT_EQ(remove_count, 3);
+}
+
+// Confirm that downloads from matching restricted origins are removed.
+TEST_F(DownloadManagerTest, RemoveRestrictedMatchingOriginDownloads) {
+ base::Time now(base::Time::Now());
+ for (uint32 i = 0; i < 3; ++i) {
+ MockDownloadItemImpl& item(AddItemToManager());
+ EXPECT_CALL(item, GetStartTime())
+ .WillRepeatedly(Return(now));
+ EXPECT_CALL(item, GetState())
+ .WillRepeatedly(Return(DownloadItem::COMPLETE));
+ }
+
+ EXPECT_CALL(GetMockDownloadItem(0), GetURL())
+ .WillRepeatedly(ReturnRef(origin1));
+ EXPECT_CALL(GetMockDownloadItem(0), Remove());
+
+ EXPECT_CALL(GetMockDownloadItem(1), GetURL())
+ .WillRepeatedly(ReturnRef(origin2));
+ EXPECT_CALL(GetMockDownloadItem(1), Remove());
+
+ EXPECT_CALL(GetMockDownloadItem(2), GetURL())
+ .WillRepeatedly(ReturnRef(origin3));
+ EXPECT_CALL(GetMockDownloadItem(2), Remove())
+ .Times(0);
+
+ std::set<GURL> restricted_urls;
+ restricted_urls.insert(origin1);
+ restricted_urls.insert(origin2);
+ int remove_count = download_manager_->RemoveDownloadsBetween(
+ restricted_urls, base::Time(), base::Time::Max());
+ EXPECT_EQ(remove_count, 2);
+}
+
+// Confirm that downloads from non-matching restricted origins are not removed.
+TEST_F(DownloadManagerTest, RemoveRestrictedNonMatchingOriginDownloads) {
+ 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(item, Remove())
+ .Times(0);
+ }
+
+ EXPECT_CALL(GetMockDownloadItem(0), GetURL())
+ .WillRepeatedly(ReturnRef(origin1));
+ EXPECT_CALL(GetMockDownloadItem(1), GetURL())
+ .WillRepeatedly(ReturnRef(origin2));
+
+ std::set<GURL> restricted_urls;
+ restricted_urls.insert(origin3);
+ int remove_count = download_manager_->RemoveDownloadsBetween(
+ restricted_urls, base::Time(), base::Time::Max());
+ EXPECT_EQ(remove_count, 0);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698