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

Side by Side Diff: net/http/transport_security_state_unittest.cc

Issue 2648713002: Add response code to the success callback of ReportSender (Closed)
Patch Set: Created 3 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/http/transport_security_state.h" 5 #include "net/http/transport_security_state.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 }; 82 };
83 83
84 // A mock ReportSenderInterface that just remembers the latest report 84 // A mock ReportSenderInterface that just remembers the latest report
85 // URI and report to be sent. 85 // URI and report to be sent.
86 class MockCertificateReportSender 86 class MockCertificateReportSender
87 : public TransportSecurityState::ReportSenderInterface { 87 : public TransportSecurityState::ReportSenderInterface {
88 public: 88 public:
89 MockCertificateReportSender() {} 89 MockCertificateReportSender() {}
90 ~MockCertificateReportSender() override {} 90 ~MockCertificateReportSender() override {}
91 91
92 void Send( 92 void Send(const GURL& report_uri,
93 const GURL& report_uri, 93 base::StringPiece content_type,
94 base::StringPiece content_type, 94 base::StringPiece report,
95 base::StringPiece report, 95 const base::Callback<void(int)>& success_callback,
96 const base::Callback<void()>& success_callback, 96 const base::Callback<void(const GURL&, int, int)>& error_callback)
97 const base::Callback<void(const GURL&, int)>& error_callback) override { 97 override {
98 latest_report_uri_ = report_uri; 98 latest_report_uri_ = report_uri;
99 report.CopyToString(&latest_report_); 99 report.CopyToString(&latest_report_);
100 content_type.CopyToString(&latest_content_type_); 100 content_type.CopyToString(&latest_content_type_);
101 } 101 }
102 102
103 void Clear() { 103 void Clear() {
104 latest_report_uri_ = GURL(); 104 latest_report_uri_ = GURL();
105 latest_report_ = std::string(); 105 latest_report_ = std::string();
106 latest_content_type_ = std::string(); 106 latest_content_type_ = std::string();
107 } 107 }
(...skipping 11 matching lines...) Expand all
119 // A mock ReportSenderInterface that simulates a net error on every report sent. 119 // A mock ReportSenderInterface that simulates a net error on every report sent.
120 class MockFailingCertificateReportSender 120 class MockFailingCertificateReportSender
121 : public TransportSecurityState::ReportSenderInterface { 121 : public TransportSecurityState::ReportSenderInterface {
122 public: 122 public:
123 MockFailingCertificateReportSender() : net_error_(ERR_CONNECTION_FAILED) {} 123 MockFailingCertificateReportSender() : net_error_(ERR_CONNECTION_FAILED) {}
124 ~MockFailingCertificateReportSender() override {} 124 ~MockFailingCertificateReportSender() override {}
125 125
126 int net_error() { return net_error_; } 126 int net_error() { return net_error_; }
127 127
128 // TransportSecurityState::ReportSenderInterface: 128 // TransportSecurityState::ReportSenderInterface:
129 void Send( 129 void Send(const GURL& report_uri,
130 const GURL& report_uri, 130 base::StringPiece content_type,
131 base::StringPiece content_type, 131 base::StringPiece report,
132 base::StringPiece report, 132 const base::Callback<void(int)>& success_callback,
133 const base::Callback<void()>& success_callback, 133 const base::Callback<void(const GURL&, int, int)>& error_callback)
134 const base::Callback<void(const GURL&, int)>& error_callback) override { 134 override {
135 ASSERT_FALSE(error_callback.is_null()); 135 ASSERT_FALSE(error_callback.is_null());
136 error_callback.Run(report_uri, net_error_); 136 error_callback.Run(report_uri, net_error_, 0);
137 } 137 }
138 138
139 private: 139 private:
140 const int net_error_; 140 const int net_error_;
141 }; 141 };
142 142
143 // A mock ExpectCTReporter that remembers the latest violation that was 143 // A mock ExpectCTReporter that remembers the latest violation that was
144 // reported and the number of violations reported. 144 // reported and the number of violations reported.
145 class MockExpectCTReporter : public TransportSecurityState::ExpectCTReporter { 145 class MockExpectCTReporter : public TransportSecurityState::ExpectCTReporter {
146 public: 146 public:
(...skipping 2162 matching lines...) Expand 10 before | Expand all | Expand 10 after
2309 base::FieldTrialList::CreateFieldTrial("EnforceCTForProblematicRoots", 2309 base::FieldTrialList::CreateFieldTrial("EnforceCTForProblematicRoots",
2310 "disabled"); 2310 "disabled");
2311 2311
2312 EXPECT_FALSE( 2312 EXPECT_FALSE(
2313 state.ShouldRequireCT("www.example.com", before_cert.get(), hashes)); 2313 state.ShouldRequireCT("www.example.com", before_cert.get(), hashes));
2314 EXPECT_FALSE( 2314 EXPECT_FALSE(
2315 state.ShouldRequireCT("www.example.com", after_cert.get(), hashes)); 2315 state.ShouldRequireCT("www.example.com", after_cert.get(), hashes));
2316 } 2316 }
2317 2317
2318 } // namespace net 2318 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698