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 <vector> |
| 8 |
7 #include "base/file_util.h" | 9 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
9 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
10 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
11 #include "chrome/browser/safe_browsing/download_feedback.h" | 13 #include "chrome/browser/safe_browsing/download_feedback.h" |
12 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/test/mock_download_item.h" | 15 #include "content/public/test/mock_download_item.h" |
14 #include "content/public/test/test_browser_thread_bundle.h" | 16 #include "content/public/test/test_browser_thread_bundle.h" |
15 #include "net/url_request/url_request_test_util.h" | 17 #include "net/url_request/url_request_test_util.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 return upload_file_path; | 158 return upload_file_path; |
157 } | 159 } |
158 | 160 |
159 FakeDownloadFeedback* feedback(size_t n) const { | 161 FakeDownloadFeedback* feedback(size_t n) const { |
160 return download_feedback_factory_.feedback(n); | 162 return download_feedback_factory_.feedback(n); |
161 } | 163 } |
162 | 164 |
163 size_t num_feedbacks() const { | 165 size_t num_feedbacks() const { |
164 return download_feedback_factory_.num_feedbacks(); | 166 return download_feedback_factory_.num_feedbacks(); |
165 } | 167 } |
| 168 |
166 protected: | 169 protected: |
167 base::ScopedTempDir temp_dir_; | 170 base::ScopedTempDir temp_dir_; |
168 content::TestBrowserThreadBundle thread_bundle_; | 171 content::TestBrowserThreadBundle thread_bundle_; |
169 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | 172 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
170 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 173 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
171 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; | 174 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; |
172 FakeDownloadFeedbackFactory download_feedback_factory_; | 175 FakeDownloadFeedbackFactory download_feedback_factory_; |
173 | |
174 }; | 176 }; |
175 | 177 |
176 TEST_F(DownloadFeedbackServiceTest, MaybeStorePingsForDownload) { | 178 TEST_F(DownloadFeedbackServiceTest, MaybeStorePingsForDownload) { |
177 const int64 ok_size = DownloadFeedback::kMaxUploadSize; | 179 const int64 ok_size = DownloadFeedback::kMaxUploadSize; |
178 const int64 bad_size = DownloadFeedback::kMaxUploadSize + 1; | 180 const int64 bad_size = DownloadFeedback::kMaxUploadSize + 1; |
179 | 181 |
180 EXPECT_FALSE(WillStorePings(DownloadProtectionService::SAFE, ok_size)); | 182 EXPECT_FALSE(WillStorePings(DownloadProtectionService::SAFE, ok_size)); |
181 EXPECT_FALSE(WillStorePings(DownloadProtectionService::DANGEROUS, ok_size)); | 183 EXPECT_FALSE(WillStorePings(DownloadProtectionService::DANGEROUS, ok_size)); |
182 EXPECT_TRUE(WillStorePings(DownloadProtectionService::UNCOMMON, ok_size)); | 184 EXPECT_TRUE(WillStorePings(DownloadProtectionService::UNCOMMON, ok_size)); |
183 EXPECT_TRUE( | 185 EXPECT_TRUE( |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 // was deleted. | 366 // was deleted. |
365 EXPECT_FALSE(base::PathExists(file_path[2])); | 367 EXPECT_FALSE(base::PathExists(file_path[2])); |
366 | 368 |
367 // These files should still exist since the FakeDownloadFeedback does not | 369 // These files should still exist since the FakeDownloadFeedback does not |
368 // delete them. | 370 // delete them. |
369 EXPECT_TRUE(base::PathExists(file_path[0])); | 371 EXPECT_TRUE(base::PathExists(file_path[0])); |
370 EXPECT_TRUE(base::PathExists(file_path[1])); | 372 EXPECT_TRUE(base::PathExists(file_path[1])); |
371 } | 373 } |
372 | 374 |
373 } // namespace safe_browsing | 375 } // namespace safe_browsing |
OLD | NEW |