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

Unified Diff: chrome/browser/safe_browsing/download_feedback_service_unittest.cc

Issue 2696973002: Allow Safe Browsing backend to select downloads to upload. (Closed)
Patch Set: Switch histogram to use enum, per isherman Created 3 years, 10 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: chrome/browser/safe_browsing/download_feedback_service_unittest.cc
diff --git a/chrome/browser/safe_browsing/download_feedback_service_unittest.cc b/chrome/browser/safe_browsing/download_feedback_service_unittest.cc
index c4cdd8247865841e5211ef6bab8b47b39b0f6b6b..9779a0d5c59b643db58cc09d89ac9372b33642c0 100644
--- a/chrome/browser/safe_browsing/download_feedback_service_unittest.cc
+++ b/chrome/browser/safe_browsing/download_feedback_service_unittest.cc
@@ -113,12 +113,14 @@ class FakeDownloadFeedbackFactory : public DownloadFeedbackFactory {
};
bool WillStorePings(DownloadProtectionService::DownloadCheckResult result,
+ bool upload_requested,
int64_t size) {
content::MockDownloadItem item;
EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(size));
EXPECT_FALSE(DownloadFeedbackService::IsEnabledForDownload(item));
- DownloadFeedbackService::MaybeStorePingsForDownload(result, &item, "a", "b");
+ DownloadFeedbackService::MaybeStorePingsForDownload(result, upload_requested,
+ &item, "a", "b");
return DownloadFeedbackService::IsEnabledForDownload(item);
}
@@ -172,21 +174,42 @@ TEST_F(DownloadFeedbackServiceTest, MaybeStorePingsForDownload) {
const int64_t ok_size = DownloadFeedback::kMaxUploadSize;
const int64_t bad_size = DownloadFeedback::kMaxUploadSize + 1;
- EXPECT_FALSE(WillStorePings(DownloadProtectionService::SAFE, ok_size));
- EXPECT_FALSE(WillStorePings(DownloadProtectionService::DANGEROUS, ok_size));
- EXPECT_TRUE(WillStorePings(DownloadProtectionService::UNCOMMON, ok_size));
- EXPECT_TRUE(
- WillStorePings(DownloadProtectionService::DANGEROUS_HOST, ok_size));
- EXPECT_TRUE(
- WillStorePings(DownloadProtectionService::POTENTIALLY_UNWANTED, ok_size));
-
- EXPECT_FALSE(WillStorePings(DownloadProtectionService::SAFE, bad_size));
- EXPECT_FALSE(WillStorePings(DownloadProtectionService::DANGEROUS, bad_size));
- EXPECT_FALSE(WillStorePings(DownloadProtectionService::UNCOMMON, bad_size));
- EXPECT_FALSE(
- WillStorePings(DownloadProtectionService::DANGEROUS_HOST, bad_size));
- EXPECT_FALSE(WillStorePings(DownloadProtectionService::POTENTIALLY_UNWANTED,
- bad_size));
+ std::vector<bool> upload_requests = {false, true};
+ for (bool upload_requested : upload_requests) {
+ // SAFE will never upload
+ EXPECT_FALSE(WillStorePings(DownloadProtectionService::SAFE,
+ upload_requested, ok_size));
+ // Others will upload if requested.
+ EXPECT_EQ(upload_requested,
+ WillStorePings(DownloadProtectionService::UNKNOWN,
+ upload_requested, ok_size));
+ EXPECT_EQ(upload_requested,
+ WillStorePings(DownloadProtectionService::DANGEROUS,
+ upload_requested, ok_size));
+ EXPECT_EQ(upload_requested,
+ WillStorePings(DownloadProtectionService::UNCOMMON,
+ upload_requested, ok_size));
+ EXPECT_EQ(upload_requested,
+ WillStorePings(DownloadProtectionService::DANGEROUS_HOST,
+ upload_requested, ok_size));
+ EXPECT_EQ(upload_requested,
+ WillStorePings(DownloadProtectionService::POTENTIALLY_UNWANTED,
+ upload_requested, ok_size));
+
+ // Bad sizes never upload
+ EXPECT_FALSE(WillStorePings(DownloadProtectionService::SAFE,
+ upload_requested, bad_size));
+ EXPECT_FALSE(WillStorePings(DownloadProtectionService::UNKNOWN,
+ upload_requested, bad_size));
+ EXPECT_FALSE(WillStorePings(DownloadProtectionService::DANGEROUS,
+ upload_requested, bad_size));
+ EXPECT_FALSE(WillStorePings(DownloadProtectionService::UNCOMMON,
+ upload_requested, bad_size));
+ EXPECT_FALSE(WillStorePings(DownloadProtectionService::DANGEROUS_HOST,
+ upload_requested, bad_size));
+ EXPECT_FALSE(WillStorePings(DownloadProtectionService::POTENTIALLY_UNWANTED,
+ upload_requested, bad_size));
+ }
}
TEST_F(DownloadFeedbackServiceTest, SingleFeedbackCompleteAndDiscardDownload) {
@@ -206,8 +229,9 @@ TEST_F(DownloadFeedbackServiceTest, SingleFeedbackCompleteAndDiscardDownload) {
DownloadFeedbackService service(request_context_getter_.get(),
file_task_runner_.get());
- service.MaybeStorePingsForDownload(
- DownloadProtectionService::UNCOMMON, &item, ping_request, ping_response);
+ service.MaybeStorePingsForDownload(DownloadProtectionService::UNCOMMON,
+ true /* upload_requested */, &item,
+ ping_request, ping_response);
ASSERT_TRUE(DownloadFeedbackService::IsEnabledForDownload(item));
service.BeginFeedbackForDownload(&item, DownloadCommands::DISCARD);
ASSERT_FALSE(download_discarded_callback.is_null());
@@ -247,7 +271,8 @@ TEST_F(DownloadFeedbackServiceTest, SingleFeedbackCompleteAndKeepDownload) {
DownloadFeedbackService service(request_context_getter_.get(),
file_task_runner_.get());
- service.MaybeStorePingsForDownload(DownloadProtectionService::UNCOMMON, &item,
+ service.MaybeStorePingsForDownload(DownloadProtectionService::UNCOMMON,
+ true /* upload_requested */, &item,
ping_request, ping_response);
ASSERT_TRUE(DownloadFeedbackService::IsEnabledForDownload(item));
service.BeginFeedbackForDownload(&item, DownloadCommands::KEEP);
@@ -286,8 +311,8 @@ TEST_F(DownloadFeedbackServiceTest, MultiplePendingFeedbackComplete) {
EXPECT_CALL(item[i], StealDangerousDownload(true, _))
.WillOnce(SaveArg<1>(&download_discarded_callback[i]));
DownloadFeedbackService::MaybeStorePingsForDownload(
- DownloadProtectionService::UNCOMMON, &item[i], ping_request,
- ping_response);
+ DownloadProtectionService::UNCOMMON, true /* upload_requested */,
+ &item[i], ping_request, ping_response);
ASSERT_TRUE(DownloadFeedbackService::IsEnabledForDownload(item[i]));
}
@@ -355,8 +380,8 @@ TEST_F(DownloadFeedbackServiceTest, MultiFeedbackWithIncomplete) {
EXPECT_CALL(item[i], StealDangerousDownload(true, _))
.WillOnce(SaveArg<1>(&download_discarded_callback[i]));
DownloadFeedbackService::MaybeStorePingsForDownload(
- DownloadProtectionService::UNCOMMON, &item[i], ping_request,
- ping_response);
+ DownloadProtectionService::UNCOMMON, true /* upload_requested */,
+ &item[i], ping_request, ping_response);
ASSERT_TRUE(DownloadFeedbackService::IsEnabledForDownload(item[i]));
}
« no previous file with comments | « chrome/browser/safe_browsing/download_feedback_service.cc ('k') | chrome/browser/safe_browsing/download_protection_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698