| 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> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 const base::FilePath& file_path, | 33 const base::FilePath& file_path, |
| 34 const std::string& ping_request, | 34 const std::string& ping_request, |
| 35 const std::string& ping_response, | 35 const std::string& ping_response, |
| 36 base::Closure deletion_callback) | 36 base::Closure deletion_callback) |
| 37 : ping_request_(ping_request), | 37 : ping_request_(ping_request), |
| 38 ping_response_(ping_response), | 38 ping_response_(ping_response), |
| 39 deletion_callback_(deletion_callback), | 39 deletion_callback_(deletion_callback), |
| 40 start_called_(false) { | 40 start_called_(false) { |
| 41 } | 41 } |
| 42 | 42 |
| 43 virtual ~FakeDownloadFeedback() { | 43 ~FakeDownloadFeedback() override { deletion_callback_.Run(); } |
| 44 deletion_callback_.Run(); | |
| 45 } | |
| 46 | 44 |
| 47 virtual void Start(const base::Closure& finish_callback) override { | 45 void Start(const base::Closure& finish_callback) override { |
| 48 start_called_ = true; | 46 start_called_ = true; |
| 49 finish_callback_ = finish_callback; | 47 finish_callback_ = finish_callback; |
| 50 } | 48 } |
| 51 | 49 |
| 52 virtual const std::string& GetPingRequestForTesting() const override { | 50 const std::string& GetPingRequestForTesting() const override { |
| 53 return ping_request_; | 51 return ping_request_; |
| 54 } | 52 } |
| 55 | 53 |
| 56 virtual const std::string& GetPingResponseForTesting() const override { | 54 const std::string& GetPingResponseForTesting() const override { |
| 57 return ping_response_; | 55 return ping_response_; |
| 58 } | 56 } |
| 59 | 57 |
| 60 base::Closure finish_callback() const { | 58 base::Closure finish_callback() const { |
| 61 return finish_callback_; | 59 return finish_callback_; |
| 62 } | 60 } |
| 63 | 61 |
| 64 bool start_called() const { | 62 bool start_called() const { |
| 65 return start_called_; | 63 return start_called_; |
| 66 } | 64 } |
| 67 | 65 |
| 68 private: | 66 private: |
| 69 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 67 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 70 scoped_refptr<base::TaskRunner> file_task_runner_; | 68 scoped_refptr<base::TaskRunner> file_task_runner_; |
| 71 base::FilePath file_path_; | 69 base::FilePath file_path_; |
| 72 std::string ping_request_; | 70 std::string ping_request_; |
| 73 std::string ping_response_; | 71 std::string ping_response_; |
| 74 | 72 |
| 75 base::Closure finish_callback_; | 73 base::Closure finish_callback_; |
| 76 base::Closure deletion_callback_; | 74 base::Closure deletion_callback_; |
| 77 bool start_called_; | 75 bool start_called_; |
| 78 }; | 76 }; |
| 79 | 77 |
| 80 class FakeDownloadFeedbackFactory : public DownloadFeedbackFactory { | 78 class FakeDownloadFeedbackFactory : public DownloadFeedbackFactory { |
| 81 public: | 79 public: |
| 82 virtual ~FakeDownloadFeedbackFactory() {} | 80 ~FakeDownloadFeedbackFactory() override {} |
| 83 | 81 |
| 84 virtual DownloadFeedback* CreateDownloadFeedback( | 82 DownloadFeedback* CreateDownloadFeedback( |
| 85 net::URLRequestContextGetter* request_context_getter, | 83 net::URLRequestContextGetter* request_context_getter, |
| 86 base::TaskRunner* file_task_runner, | 84 base::TaskRunner* file_task_runner, |
| 87 const base::FilePath& file_path, | 85 const base::FilePath& file_path, |
| 88 const std::string& ping_request, | 86 const std::string& ping_request, |
| 89 const std::string& ping_response) override { | 87 const std::string& ping_response) override { |
| 90 FakeDownloadFeedback* feedback = new FakeDownloadFeedback( | 88 FakeDownloadFeedback* feedback = new FakeDownloadFeedback( |
| 91 request_context_getter, | 89 request_context_getter, |
| 92 file_task_runner, | 90 file_task_runner, |
| 93 file_path, | 91 file_path, |
| 94 ping_request, | 92 ping_request, |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 // was deleted. | 364 // was deleted. |
| 367 EXPECT_FALSE(base::PathExists(file_path[2])); | 365 EXPECT_FALSE(base::PathExists(file_path[2])); |
| 368 | 366 |
| 369 // These files should still exist since the FakeDownloadFeedback does not | 367 // These files should still exist since the FakeDownloadFeedback does not |
| 370 // delete them. | 368 // delete them. |
| 371 EXPECT_TRUE(base::PathExists(file_path[0])); | 369 EXPECT_TRUE(base::PathExists(file_path[0])); |
| 372 EXPECT_TRUE(base::PathExists(file_path[1])); | 370 EXPECT_TRUE(base::PathExists(file_path[1])); |
| 373 } | 371 } |
| 374 | 372 |
| 375 } // namespace safe_browsing | 373 } // namespace safe_browsing |
| OLD | NEW |