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

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: Remove unneeded DCHECK; Initialize and clear download URLs along test fixture life cycle. 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
« no previous file with comments | « content/browser/download/download_manager_impl.cc ('k') | content/public/browser/browser_context.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d4f923370b6afffbcd57d66548f1891b277ad8ae 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;
@@ -483,6 +484,10 @@ class DownloadManagerTest : public testing::Test {
observer_.reset(new MockDownloadManagerObserver());
download_manager_->AddObserver(observer_.get());
download_manager_->SetDelegate(mock_download_manager_delegate_.get());
+ 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"));
}
void TearDown() override {
@@ -502,6 +507,7 @@ class DownloadManagerTest : public testing::Test {
message_loop_.RunUntilIdle();
mock_download_manager_delegate_.reset();
mock_browser_context_.reset();
+ download_urls_.clear();
}
// Returns download id.
@@ -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;
}
@@ -576,6 +584,8 @@ class DownloadManagerTest : public testing::Test {
DownloadDangerType danger_type_;
base::FilePath intermediate_path_;
+ std::vector<GURL> download_urls_;
+
private:
base::MessageLoopForUI message_loop_;
TestBrowserThread ui_thread_;
@@ -694,4 +704,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());
+ 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
« no previous file with comments | « content/browser/download/download_manager_impl.cc ('k') | content/public/browser/browser_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698