Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: net/url_request/certificate_report_sender_unittest.cc

Issue 1847563004: Add error callback to net::CertificateReportSender (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "net/url_request/certificate_report_sender.h" 5 #include "net/url_request/certificate_report_sender.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/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 29 matching lines...) Expand all
40 ASSERT_EQ(1u, upload->GetElementReaders()->size()); 40 ASSERT_EQ(1u, upload->GetElementReaders()->size());
41 41
42 const UploadBytesElementReader* reader = 42 const UploadBytesElementReader* reader =
43 (*upload->GetElementReaders())[0]->AsBytesReader(); 43 (*upload->GetElementReaders())[0]->AsBytesReader();
44 ASSERT_TRUE(reader); 44 ASSERT_TRUE(reader);
45 std::string upload_data(reader->bytes(), reader->length()); 45 std::string upload_data(reader->bytes(), reader->length());
46 46
47 EXPECT_EQ(1u, expect_reports->erase(upload_data)); 47 EXPECT_EQ(1u, expect_reports->erase(upload_data));
48 } 48 }
49 49
50 // Provides an error callback for report sending. If the callback is
51 // called, it sets |called| to true.
52 void ErrorCallback(bool* called, URLRequest* request) {
53 EXPECT_FALSE(request->status().is_success());
54 *called = true;
55 }
56
50 // A network delegate that lets tests check that a certificate report 57 // A network delegate that lets tests check that a certificate report
51 // was sent. It counts the number of requests and lets tests register a 58 // was sent. It counts the number of requests and lets tests register a
52 // callback to run when the request is destroyed. It also checks that 59 // callback to run when the request is destroyed. It also checks that
53 // the uploaded data is as expected. 60 // the uploaded data is as expected.
54 class TestCertificateReportSenderNetworkDelegate : public NetworkDelegateImpl { 61 class TestCertificateReportSenderNetworkDelegate : public NetworkDelegateImpl {
55 public: 62 public:
56 TestCertificateReportSenderNetworkDelegate() 63 TestCertificateReportSenderNetworkDelegate()
57 : url_request_destroyed_callback_(base::Bind(&base::DoNothing)), 64 : url_request_destroyed_callback_(base::Bind(&base::DoNothing)),
58 all_url_requests_destroyed_callback_(base::Bind(&base::DoNothing)), 65 all_url_requests_destroyed_callback_(base::Bind(&base::DoNothing)),
59 num_requests_(0), 66 num_requests_(0),
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 238
232 // Test that a request that returns an error gets cleaned up. 239 // Test that a request that returns an error gets cleaned up.
233 TEST_F(CertificateReportSenderTest, ErroredRequestGetsDeleted) { 240 TEST_F(CertificateReportSenderTest, ErroredRequestGetsDeleted) {
234 GURL url = URLRequestFailedJob::GetMockHttpsUrl(ERR_FAILED); 241 GURL url = URLRequestFailedJob::GetMockHttpsUrl(ERR_FAILED);
235 CertificateReportSender reporter( 242 CertificateReportSender reporter(
236 context(), CertificateReportSender::DO_NOT_SEND_COOKIES); 243 context(), CertificateReportSender::DO_NOT_SEND_COOKIES);
237 // SendReport will block until the URLRequest is destroyed. 244 // SendReport will block until the URLRequest is destroyed.
238 SendReport(&reporter, kDummyReport, url, 0); 245 SendReport(&reporter, kDummyReport, url, 0);
239 } 246 }
240 247
248 // Test that the error callback, if provided, gets called when a request
249 // returns an error.
250 TEST_F(CertificateReportSenderTest, ErroredRequestCallsCallback) {
251 bool error_callback_called = false;
252 GURL url = URLRequestFailedJob::GetMockHttpsUrl(ERR_FAILED);
253 CertificateReportSender reporter(
254 context(), CertificateReportSender::DO_NOT_SEND_COOKIES,
255 base::Bind(ErrorCallback, &error_callback_called));
256 // SendReport will block until the URLRequest is destroyed.
257 SendReport(&reporter, kDummyReport, url, 0);
258 EXPECT_TRUE(error_callback_called);
259 }
260
261 // Test that the error callback does not get called when a request
262 // does not return an error.
263 TEST_F(CertificateReportSenderTest, SuccessfulRequestDoesNotCallErrorCallback) {
264 bool error_callback_called = false;
265 GURL url = URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1);
266 CertificateReportSender reporter(
267 context(), CertificateReportSender::DO_NOT_SEND_COOKIES,
268 base::Bind(ErrorCallback, &error_callback_called));
269 SendReport(&reporter, kDummyReport, url, 0);
270 EXPECT_FALSE(error_callback_called);
271 }
272
241 // Test that cookies are sent or not sent according to the error 273 // Test that cookies are sent or not sent according to the error
242 // reporter's cookies preference. 274 // reporter's cookies preference.
243 275
244 TEST_F(CertificateReportSenderTest, SendCookiesPreference) { 276 TEST_F(CertificateReportSenderTest, SendCookiesPreference) {
245 GURL url = URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); 277 GURL url = URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1);
246 CertificateReportSender reporter(context(), 278 CertificateReportSender reporter(context(),
247 CertificateReportSender::SEND_COOKIES); 279 CertificateReportSender::SEND_COOKIES);
248 280
249 network_delegate_.set_expect_cookies(true); 281 network_delegate_.set_expect_cookies(true);
250 SendReport(&reporter, kDummyReport, url, 0); 282 SendReport(&reporter, kDummyReport, url, 0);
251 } 283 }
252 284
253 TEST_F(CertificateReportSenderTest, DoNotSendCookiesPreference) { 285 TEST_F(CertificateReportSenderTest, DoNotSendCookiesPreference) {
254 GURL url = URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); 286 GURL url = URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1);
255 CertificateReportSender reporter( 287 CertificateReportSender reporter(
256 context(), CertificateReportSender::DO_NOT_SEND_COOKIES); 288 context(), CertificateReportSender::DO_NOT_SEND_COOKIES);
257 289
258 network_delegate_.set_expect_cookies(false); 290 network_delegate_.set_expect_cookies(false);
259 SendReport(&reporter, kDummyReport, url, 0); 291 SendReport(&reporter, kDummyReport, url, 0);
260 } 292 }
261 293
262 } // namespace 294 } // namespace
263 } // namespace net 295 } // namespace net
OLDNEW
« net/url_request/certificate_report_sender.cc ('K') | « net/url_request/certificate_report_sender.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698