| 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.h" | 5 #include "chrome/browser/safe_browsing/download_feedback.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "chrome/browser/safe_browsing/two_phase_uploader.h" | 13 #include "chrome/browser/safe_browsing/two_phase_uploader.h" |
| 14 #include "chrome/common/safe_browsing/csd.pb.h" | 14 #include "chrome/common/safe_browsing/csd.pb.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/test/test_browser_thread_bundle.h" | 16 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 17 #include "net/url_request/url_request_test_util.h" | 18 #include "net/url_request/url_request_test_util.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace safe_browsing { | 21 namespace safe_browsing { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 class FakeUploader : public TwoPhaseUploader { | 25 class FakeUploader : public TwoPhaseUploader { |
| 25 public: | 26 public: |
| 26 FakeUploader(net::URLRequestContextGetter* url_request_context_getter, | 27 FakeUploader(net::URLRequestContextGetter* url_request_context_getter, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 FakeUploaderFactory() : uploader_(nullptr) {} | 69 FakeUploaderFactory() : uploader_(nullptr) {} |
| 69 ~FakeUploaderFactory() override {} | 70 ~FakeUploaderFactory() override {} |
| 70 | 71 |
| 71 std::unique_ptr<TwoPhaseUploader> CreateTwoPhaseUploader( | 72 std::unique_ptr<TwoPhaseUploader> CreateTwoPhaseUploader( |
| 72 net::URLRequestContextGetter* url_request_context_getter, | 73 net::URLRequestContextGetter* url_request_context_getter, |
| 73 base::TaskRunner* file_task_runner, | 74 base::TaskRunner* file_task_runner, |
| 74 const GURL& base_url, | 75 const GURL& base_url, |
| 75 const std::string& metadata, | 76 const std::string& metadata, |
| 76 const base::FilePath& file_path, | 77 const base::FilePath& file_path, |
| 77 const TwoPhaseUploader::ProgressCallback& progress_callback, | 78 const TwoPhaseUploader::ProgressCallback& progress_callback, |
| 78 const TwoPhaseUploader::FinishCallback& finish_callback) override; | 79 const TwoPhaseUploader::FinishCallback& finish_callback, |
| 80 const net::NetworkTrafficAnnotationTag& traffic_annotation) override; |
| 79 | 81 |
| 80 FakeUploader* uploader_; | 82 FakeUploader* uploader_; |
| 81 }; | 83 }; |
| 82 | 84 |
| 83 std::unique_ptr<TwoPhaseUploader> FakeUploaderFactory::CreateTwoPhaseUploader( | 85 std::unique_ptr<TwoPhaseUploader> FakeUploaderFactory::CreateTwoPhaseUploader( |
| 84 net::URLRequestContextGetter* url_request_context_getter, | 86 net::URLRequestContextGetter* url_request_context_getter, |
| 85 base::TaskRunner* file_task_runner, | 87 base::TaskRunner* file_task_runner, |
| 86 const GURL& base_url, | 88 const GURL& base_url, |
| 87 const std::string& metadata, | 89 const std::string& metadata, |
| 88 const base::FilePath& file_path, | 90 const base::FilePath& file_path, |
| 89 const TwoPhaseUploader::ProgressCallback& progress_callback, | 91 const TwoPhaseUploader::ProgressCallback& progress_callback, |
| 90 const TwoPhaseUploader::FinishCallback& finish_callback) { | 92 const TwoPhaseUploader::FinishCallback& finish_callback, |
| 93 const net::NetworkTrafficAnnotationTag& traffic_annotation) { |
| 91 EXPECT_FALSE(uploader_); | 94 EXPECT_FALSE(uploader_); |
| 92 | 95 |
| 93 uploader_ = new FakeUploader(url_request_context_getter, file_task_runner, | 96 uploader_ = new FakeUploader(url_request_context_getter, file_task_runner, |
| 94 base_url, metadata, file_path, progress_callback, | 97 base_url, metadata, file_path, progress_callback, |
| 95 finish_callback); | 98 finish_callback); |
| 96 return base::WrapUnique(uploader_); | 99 return base::WrapUnique(uploader_); |
| 97 } | 100 } |
| 98 | 101 |
| 99 } // namespace | 102 } // namespace |
| 100 | 103 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 EXPECT_TRUE(base::PathExists(upload_file_path_)); | 217 EXPECT_TRUE(base::PathExists(upload_file_path_)); |
| 215 | 218 |
| 216 feedback.reset(); | 219 feedback.reset(); |
| 217 EXPECT_FALSE(feedback_finish_called_); | 220 EXPECT_FALSE(feedback_finish_called_); |
| 218 | 221 |
| 219 base::RunLoop().RunUntilIdle(); | 222 base::RunLoop().RunUntilIdle(); |
| 220 EXPECT_FALSE(base::PathExists(upload_file_path_)); | 223 EXPECT_FALSE(base::PathExists(upload_file_path_)); |
| 221 } | 224 } |
| 222 | 225 |
| 223 } // namespace safe_browsing | 226 } // namespace safe_browsing |
| OLD | NEW |