OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/net/certificate_error_reporter.h" | 5 #include "chrome/browser/net/certificate_error_reporter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // Test that CertificateErrorReporter::SendReport creates a URLRequest | 167 // Test that CertificateErrorReporter::SendReport creates a URLRequest |
168 // for the endpoint and sends the expected data. | 168 // for the endpoint and sends the expected data. |
169 TEST_F(CertificateErrorReporterTest, SendReportSendsRequest) { | 169 TEST_F(CertificateErrorReporterTest, SendReportSendsRequest) { |
170 base::RunLoop run_loop; | 170 base::RunLoop run_loop; |
171 network_delegate()->set_url_request_destroyed_callback( | 171 network_delegate()->set_url_request_destroyed_callback( |
172 run_loop.QuitClosure()); | 172 run_loop.QuitClosure()); |
173 | 173 |
174 GURL url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); | 174 GURL url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); |
175 network_delegate()->set_expected_url(url); | 175 network_delegate()->set_expected_url(url); |
176 | 176 |
177 CertificateErrorReporter reporter(context(), url); | 177 scoped_refptr<CertificateErrorReporter> reporter = |
| 178 new CertificateErrorReporter(context(), url); |
178 | 179 |
179 EXPECT_EQ(0, network_delegate()->num_requests()); | 180 EXPECT_EQ(0, network_delegate()->num_requests()); |
180 | 181 |
181 reporter.SendReport(CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION, | 182 reporter->SendReport(CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION, |
182 kHostname, GetTestSSLInfo()); | 183 kHostname, GetTestSSLInfo()); |
183 run_loop.Run(); | 184 run_loop.Run(); |
184 | 185 |
185 EXPECT_EQ(1, network_delegate()->num_requests()); | 186 EXPECT_EQ(1, network_delegate()->num_requests()); |
186 } | 187 } |
187 | 188 |
188 // Test that pending URLRequests get cleaned up when the reporter is | 189 // Test that pending URLRequests get cleaned up when the reporter is |
189 // deleted. | 190 // deleted. |
190 TEST_F(CertificateErrorReporterTest, PendingRequestGetsDeleted) { | 191 TEST_F(CertificateErrorReporterTest, PendingRequestGetsDeleted) { |
191 base::RunLoop run_loop; | 192 base::RunLoop run_loop; |
192 network_delegate()->set_url_request_destroyed_callback( | 193 network_delegate()->set_url_request_destroyed_callback( |
193 run_loop.QuitClosure()); | 194 run_loop.QuitClosure()); |
194 | 195 |
195 GURL url = net::URLRequestMockHTTPJob::GetMockUrlWithFailure( | 196 GURL url = net::URLRequestMockHTTPJob::GetMockUrlWithFailure( |
196 base::FilePath(FILE_PATH_LITERAL("empty.html")), | 197 base::FilePath(FILE_PATH_LITERAL("empty.html")), |
197 net::URLRequestMockHTTPJob::START, net::ERR_IO_PENDING); | 198 net::URLRequestMockHTTPJob::START, net::ERR_IO_PENDING); |
198 network_delegate()->set_expected_url(url); | 199 network_delegate()->set_expected_url(url); |
199 | 200 |
200 EXPECT_EQ(0, network_delegate()->num_requests()); | 201 EXPECT_EQ(0, network_delegate()->num_requests()); |
201 | 202 |
202 scoped_ptr<CertificateErrorReporter> reporter( | 203 scoped_refptr<CertificateErrorReporter> reporter( |
203 new CertificateErrorReporter(context(), url)); | 204 new CertificateErrorReporter(context(), url)); |
204 reporter->SendReport(CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION, | 205 reporter->SendReport(CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION, |
205 kHostname, GetTestSSLInfo()); | 206 kHostname, GetTestSSLInfo()); |
206 reporter.reset(); | 207 reporter = nullptr; |
207 | 208 |
208 run_loop.Run(); | 209 run_loop.Run(); |
209 | 210 |
210 EXPECT_EQ(1, network_delegate()->num_requests()); | 211 EXPECT_EQ(1, network_delegate()->num_requests()); |
211 } | 212 } |
212 | 213 |
213 // Test that a request that returns an error gets cleaned up. | 214 // Test that a request that returns an error gets cleaned up. |
214 TEST_F(CertificateErrorReporterTest, ErroredRequestGetsDeleted) { | 215 TEST_F(CertificateErrorReporterTest, ErroredRequestGetsDeleted) { |
215 base::RunLoop run_loop; | 216 base::RunLoop run_loop; |
216 network_delegate()->set_url_request_destroyed_callback( | 217 network_delegate()->set_url_request_destroyed_callback( |
217 run_loop.QuitClosure()); | 218 run_loop.QuitClosure()); |
218 | 219 |
219 GURL url = net::URLRequestFailedJob::GetMockHttpsUrl(net::ERR_FAILED); | 220 GURL url = net::URLRequestFailedJob::GetMockHttpsUrl(net::ERR_FAILED); |
220 network_delegate()->set_expected_url(url); | 221 network_delegate()->set_expected_url(url); |
221 | 222 |
222 EXPECT_EQ(0, network_delegate()->num_requests()); | 223 EXPECT_EQ(0, network_delegate()->num_requests()); |
223 | 224 |
224 CertificateErrorReporter reporter(context(), url); | 225 scoped_refptr<CertificateErrorReporter> reporter = |
225 reporter.SendReport(CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION, | 226 new CertificateErrorReporter(context(), url); |
226 kHostname, GetTestSSLInfo()); | 227 reporter->SendReport(CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION, |
| 228 kHostname, GetTestSSLInfo()); |
227 run_loop.Run(); | 229 run_loop.Run(); |
228 | 230 |
229 EXPECT_EQ(1, network_delegate()->num_requests()); | 231 EXPECT_EQ(1, network_delegate()->num_requests()); |
230 } | 232 } |
231 | 233 |
232 } // namespace | 234 } // namespace |
OLD | NEW |