OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/safe_browsing/download_feedback_service.h" | 5 #include "chrome/browser/safe_browsing/download_feedback_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 201 |
202 content::DownloadItem::AcquireFileCallback download_discarded_callback; | 202 content::DownloadItem::AcquireFileCallback download_discarded_callback; |
203 | 203 |
204 content::MockDownloadItem item; | 204 content::MockDownloadItem item; |
205 EXPECT_CALL(item, GetDangerType()) | 205 EXPECT_CALL(item, GetDangerType()) |
206 .WillRepeatedly(Return(content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT)); | 206 .WillRepeatedly(Return(content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT)); |
207 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(1000)); | 207 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(1000)); |
208 EXPECT_CALL(item, StealDangerousDownload(_)) | 208 EXPECT_CALL(item, StealDangerousDownload(_)) |
209 .WillOnce(SaveArg<0>(&download_discarded_callback)); | 209 .WillOnce(SaveArg<0>(&download_discarded_callback)); |
210 | 210 |
211 DownloadFeedbackService service(request_context_getter_, file_task_runner_); | 211 DownloadFeedbackService service(request_context_getter_.get(), |
| 212 file_task_runner_.get()); |
212 service.MaybeStorePingsForDownload( | 213 service.MaybeStorePingsForDownload( |
213 DownloadProtectionService::UNCOMMON, &item, ping_request, ping_response); | 214 DownloadProtectionService::UNCOMMON, &item, ping_request, ping_response); |
214 ASSERT_TRUE(DownloadFeedbackService::IsEnabledForDownload(item)); | 215 ASSERT_TRUE(DownloadFeedbackService::IsEnabledForDownload(item)); |
215 service.BeginFeedbackForDownload(&item); | 216 service.BeginFeedbackForDownload(&item); |
216 ASSERT_FALSE(download_discarded_callback.is_null()); | 217 ASSERT_FALSE(download_discarded_callback.is_null()); |
217 EXPECT_EQ(0U, num_feedbacks()); | 218 EXPECT_EQ(0U, num_feedbacks()); |
218 | 219 |
219 download_discarded_callback.Run(file_path); | 220 download_discarded_callback.Run(file_path); |
220 ASSERT_EQ(1U, num_feedbacks()); | 221 ASSERT_EQ(1U, num_feedbacks()); |
221 ASSERT_TRUE(feedback(0)); | 222 ASSERT_TRUE(feedback(0)); |
(...skipping 26 matching lines...) Expand all Loading... |
248 EXPECT_CALL(item[i], GetReceivedBytes()).WillRepeatedly(Return(1000)); | 249 EXPECT_CALL(item[i], GetReceivedBytes()).WillRepeatedly(Return(1000)); |
249 EXPECT_CALL(item[i], StealDangerousDownload(_)) | 250 EXPECT_CALL(item[i], StealDangerousDownload(_)) |
250 .WillOnce(SaveArg<0>(&download_discarded_callback[i])); | 251 .WillOnce(SaveArg<0>(&download_discarded_callback[i])); |
251 DownloadFeedbackService::MaybeStorePingsForDownload( | 252 DownloadFeedbackService::MaybeStorePingsForDownload( |
252 DownloadProtectionService::UNCOMMON, &item[i], ping_request, | 253 DownloadProtectionService::UNCOMMON, &item[i], ping_request, |
253 ping_response); | 254 ping_response); |
254 ASSERT_TRUE(DownloadFeedbackService::IsEnabledForDownload(item[i])); | 255 ASSERT_TRUE(DownloadFeedbackService::IsEnabledForDownload(item[i])); |
255 } | 256 } |
256 | 257 |
257 { | 258 { |
258 DownloadFeedbackService service(request_context_getter_, file_task_runner_); | 259 DownloadFeedbackService service(request_context_getter_.get(), |
| 260 file_task_runner_.get()); |
259 for (size_t i = 0; i < num_downloads; ++i) { | 261 for (size_t i = 0; i < num_downloads; ++i) { |
260 SCOPED_TRACE(i); | 262 SCOPED_TRACE(i); |
261 service.BeginFeedbackForDownload(&item[i]); | 263 service.BeginFeedbackForDownload(&item[i]); |
262 ASSERT_FALSE(download_discarded_callback[i].is_null()); | 264 ASSERT_FALSE(download_discarded_callback[i].is_null()); |
263 } | 265 } |
264 EXPECT_EQ(0U, num_feedbacks()); | 266 EXPECT_EQ(0U, num_feedbacks()); |
265 | 267 |
266 for (size_t i = 0; i < num_downloads; ++i) { | 268 for (size_t i = 0; i < num_downloads; ++i) { |
267 download_discarded_callback[i].Run(file_path[i]); | 269 download_discarded_callback[i].Run(file_path[i]); |
268 } | 270 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 EXPECT_CALL(item[i], GetReceivedBytes()).WillRepeatedly(Return(1000)); | 318 EXPECT_CALL(item[i], GetReceivedBytes()).WillRepeatedly(Return(1000)); |
317 EXPECT_CALL(item[i], StealDangerousDownload(_)) | 319 EXPECT_CALL(item[i], StealDangerousDownload(_)) |
318 .WillOnce(SaveArg<0>(&download_discarded_callback[i])); | 320 .WillOnce(SaveArg<0>(&download_discarded_callback[i])); |
319 DownloadFeedbackService::MaybeStorePingsForDownload( | 321 DownloadFeedbackService::MaybeStorePingsForDownload( |
320 DownloadProtectionService::UNCOMMON, &item[i], ping_request, | 322 DownloadProtectionService::UNCOMMON, &item[i], ping_request, |
321 ping_response); | 323 ping_response); |
322 ASSERT_TRUE(DownloadFeedbackService::IsEnabledForDownload(item[i])); | 324 ASSERT_TRUE(DownloadFeedbackService::IsEnabledForDownload(item[i])); |
323 } | 325 } |
324 | 326 |
325 { | 327 { |
326 DownloadFeedbackService service(request_context_getter_, file_task_runner_); | 328 DownloadFeedbackService service(request_context_getter_.get(), |
| 329 file_task_runner_.get()); |
327 for (size_t i = 0; i < num_downloads; ++i) { | 330 for (size_t i = 0; i < num_downloads; ++i) { |
328 SCOPED_TRACE(i); | 331 SCOPED_TRACE(i); |
329 service.BeginFeedbackForDownload(&item[i]); | 332 service.BeginFeedbackForDownload(&item[i]); |
330 ASSERT_FALSE(download_discarded_callback[i].is_null()); | 333 ASSERT_FALSE(download_discarded_callback[i].is_null()); |
331 } | 334 } |
332 EXPECT_EQ(0U, num_feedbacks()); | 335 EXPECT_EQ(0U, num_feedbacks()); |
333 | 336 |
334 download_discarded_callback[0].Run(file_path[0]); | 337 download_discarded_callback[0].Run(file_path[0]); |
335 ASSERT_EQ(1U, num_feedbacks()); | 338 ASSERT_EQ(1U, num_feedbacks()); |
336 ASSERT_TRUE(feedback(0)); | 339 ASSERT_TRUE(feedback(0)); |
(...skipping 28 matching lines...) Expand all Loading... |
365 // was deleted. | 368 // was deleted. |
366 EXPECT_FALSE(file_util::PathExists(file_path[2])); | 369 EXPECT_FALSE(file_util::PathExists(file_path[2])); |
367 | 370 |
368 // These files should still exist since the FakeDownloadFeedback does not | 371 // These files should still exist since the FakeDownloadFeedback does not |
369 // delete them. | 372 // delete them. |
370 EXPECT_TRUE(file_util::PathExists(file_path[0])); | 373 EXPECT_TRUE(file_util::PathExists(file_path[0])); |
371 EXPECT_TRUE(file_util::PathExists(file_path[1])); | 374 EXPECT_TRUE(file_util::PathExists(file_path[1])); |
372 } | 375 } |
373 | 376 |
374 } // namespace safe_browsing | 377 } // namespace safe_browsing |
OLD | NEW |