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/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 public: | 24 public: |
25 FakeUploader(net::URLRequestContextGetter* url_request_context_getter, | 25 FakeUploader(net::URLRequestContextGetter* url_request_context_getter, |
26 base::TaskRunner* file_task_runner, | 26 base::TaskRunner* file_task_runner, |
27 const GURL& base_url, | 27 const GURL& base_url, |
28 const std::string& metadata, | 28 const std::string& metadata, |
29 const base::FilePath& file_path, | 29 const base::FilePath& file_path, |
30 const ProgressCallback& progress_callback, | 30 const ProgressCallback& progress_callback, |
31 const FinishCallback& finish_callback); | 31 const FinishCallback& finish_callback); |
32 virtual ~FakeUploader() {} | 32 virtual ~FakeUploader() {} |
33 | 33 |
34 virtual void Start() OVERRIDE { | 34 virtual void Start() override { |
35 start_called_ = true; | 35 start_called_ = true; |
36 } | 36 } |
37 | 37 |
38 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 38 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
39 scoped_refptr<base::TaskRunner> file_task_runner_; | 39 scoped_refptr<base::TaskRunner> file_task_runner_; |
40 GURL base_url_; | 40 GURL base_url_; |
41 std::string metadata_; | 41 std::string metadata_; |
42 base::FilePath file_path_; | 42 base::FilePath file_path_; |
43 ProgressCallback progress_callback_; | 43 ProgressCallback progress_callback_; |
44 FinishCallback finish_callback_; | 44 FinishCallback finish_callback_; |
(...skipping 24 matching lines...) Expand all Loading... |
69 FakeUploaderFactory() : uploader_(NULL) {} | 69 FakeUploaderFactory() : uploader_(NULL) {} |
70 virtual ~FakeUploaderFactory() {} | 70 virtual ~FakeUploaderFactory() {} |
71 | 71 |
72 virtual TwoPhaseUploader* CreateTwoPhaseUploader( | 72 virtual TwoPhaseUploader* CreateTwoPhaseUploader( |
73 net::URLRequestContextGetter* url_request_context_getter, | 73 net::URLRequestContextGetter* url_request_context_getter, |
74 base::TaskRunner* file_task_runner, | 74 base::TaskRunner* file_task_runner, |
75 const GURL& base_url, | 75 const GURL& base_url, |
76 const std::string& metadata, | 76 const std::string& metadata, |
77 const base::FilePath& file_path, | 77 const base::FilePath& file_path, |
78 const TwoPhaseUploader::ProgressCallback& progress_callback, | 78 const TwoPhaseUploader::ProgressCallback& progress_callback, |
79 const TwoPhaseUploader::FinishCallback& finish_callback) OVERRIDE; | 79 const TwoPhaseUploader::FinishCallback& finish_callback) override; |
80 | 80 |
81 FakeUploader* uploader_; | 81 FakeUploader* uploader_; |
82 }; | 82 }; |
83 | 83 |
84 TwoPhaseUploader* FakeUploaderFactory::CreateTwoPhaseUploader( | 84 TwoPhaseUploader* FakeUploaderFactory::CreateTwoPhaseUploader( |
85 net::URLRequestContextGetter* url_request_context_getter, | 85 net::URLRequestContextGetter* url_request_context_getter, |
86 base::TaskRunner* file_task_runner, | 86 base::TaskRunner* file_task_runner, |
87 const GURL& base_url, | 87 const GURL& base_url, |
88 const std::string& metadata, | 88 const std::string& metadata, |
89 const base::FilePath& file_path, | 89 const base::FilePath& file_path, |
(...skipping 15 matching lines...) Expand all Loading... |
105 : file_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread( | 105 : file_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread( |
106 content::BrowserThread::FILE)), | 106 content::BrowserThread::FILE)), |
107 io_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread( | 107 io_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread( |
108 content::BrowserThread::IO)), | 108 content::BrowserThread::IO)), |
109 url_request_context_getter_( | 109 url_request_context_getter_( |
110 new net::TestURLRequestContextGetter(io_task_runner_)), | 110 new net::TestURLRequestContextGetter(io_task_runner_)), |
111 feedback_finish_called_(false) { | 111 feedback_finish_called_(false) { |
112 EXPECT_NE(io_task_runner_, file_task_runner_); | 112 EXPECT_NE(io_task_runner_, file_task_runner_); |
113 } | 113 } |
114 | 114 |
115 virtual void SetUp() OVERRIDE { | 115 virtual void SetUp() override { |
116 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 116 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
117 upload_file_path_ = temp_dir_.path().AppendASCII("test file"); | 117 upload_file_path_ = temp_dir_.path().AppendASCII("test file"); |
118 upload_file_data_ = "data"; | 118 upload_file_data_ = "data"; |
119 ASSERT_EQ(static_cast<int>(upload_file_data_.size()), | 119 ASSERT_EQ(static_cast<int>(upload_file_data_.size()), |
120 base::WriteFile(upload_file_path_, upload_file_data_.data(), | 120 base::WriteFile(upload_file_path_, upload_file_data_.data(), |
121 upload_file_data_.size())); | 121 upload_file_data_.size())); |
122 TwoPhaseUploader::RegisterFactory(&two_phase_uploader_factory_); | 122 TwoPhaseUploader::RegisterFactory(&two_phase_uploader_factory_); |
123 } | 123 } |
124 | 124 |
125 virtual void TearDown() OVERRIDE { | 125 virtual void TearDown() override { |
126 TwoPhaseUploader::RegisterFactory(NULL); | 126 TwoPhaseUploader::RegisterFactory(NULL); |
127 } | 127 } |
128 | 128 |
129 FakeUploader* uploader() const { | 129 FakeUploader* uploader() const { |
130 return two_phase_uploader_factory_.uploader_; | 130 return two_phase_uploader_factory_.uploader_; |
131 } | 131 } |
132 | 132 |
133 void FinishCallback(DownloadFeedback* feedback) { | 133 void FinishCallback(DownloadFeedback* feedback) { |
134 EXPECT_FALSE(feedback_finish_called_); | 134 EXPECT_FALSE(feedback_finish_called_); |
135 feedback_finish_called_ = true; | 135 feedback_finish_called_ = true; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 EXPECT_TRUE(base::PathExists(upload_file_path_)); | 227 EXPECT_TRUE(base::PathExists(upload_file_path_)); |
228 | 228 |
229 delete feedback; | 229 delete feedback; |
230 EXPECT_FALSE(feedback_finish_called_); | 230 EXPECT_FALSE(feedback_finish_called_); |
231 | 231 |
232 base::RunLoop().RunUntilIdle(); | 232 base::RunLoop().RunUntilIdle(); |
233 EXPECT_FALSE(base::PathExists(upload_file_path_)); | 233 EXPECT_FALSE(base::PathExists(upload_file_path_)); |
234 } | 234 } |
235 | 235 |
236 } // namespace safe_browsing | 236 } // namespace safe_browsing |
OLD | NEW |