OLD | NEW |
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 "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" | 5 #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 }; | 114 }; |
115 | 115 |
116 // For the first version of the feature, sending reports is "fire and forget". | 116 // For the first version of the feature, sending reports is "fire and forget". |
117 // Therefore, we test only that the Reporter tried to send a request at all. | 117 // Therefore, we test only that the Reporter tried to send a request at all. |
118 // In the future, when we have more sophisticated (i.e., any) error handling | 118 // In the future, when we have more sophisticated (i.e., any) error handling |
119 // and re-tries, we will need more sopisticated tests as well. | 119 // and re-tries, we will need more sopisticated tests as well. |
120 // | 120 // |
121 // This class doesn't do anything now, but in near future versions it will. | 121 // This class doesn't do anything now, but in near future versions it will. |
122 class MockURLRequest : public net::URLRequest { | 122 class MockURLRequest : public net::URLRequest { |
123 public: | 123 public: |
124 MockURLRequest() : net::URLRequest(GURL(""), NULL), passed_(false) { | 124 MockURLRequest(net::URLRequestContext* context) |
| 125 : net::URLRequest(GURL(""), NULL, context), |
| 126 passed_(false) { |
125 } | 127 } |
126 | 128 |
127 private: | 129 private: |
128 bool passed_; | 130 bool passed_; |
129 }; | 131 }; |
130 | 132 |
131 // A ChromeFraudulentCertificateReporter that uses a MockURLRequest, but is | 133 // A ChromeFraudulentCertificateReporter that uses a MockURLRequest, but is |
132 // otherwise normal: reports are constructed and sent in the usual way. | 134 // otherwise normal: reports are constructed and sent in the usual way. |
133 class MockReporter : public ChromeFraudulentCertificateReporter { | 135 class MockReporter : public ChromeFraudulentCertificateReporter { |
134 public: | 136 public: |
135 explicit MockReporter(net::URLRequestContext* request_context) | 137 explicit MockReporter(net::URLRequestContext* request_context) |
136 : ChromeFraudulentCertificateReporter(request_context) {} | 138 : ChromeFraudulentCertificateReporter(request_context) {} |
137 | 139 |
138 virtual net::URLRequest* CreateURLRequest() OVERRIDE { | 140 virtual net::URLRequest* CreateURLRequest( |
139 return new MockURLRequest(); | 141 net::URLRequestContext* context) OVERRIDE { |
| 142 return new MockURLRequest(context); |
140 } | 143 } |
141 | 144 |
142 virtual void SendReport( | 145 virtual void SendReport( |
143 const std::string& hostname, | 146 const std::string& hostname, |
144 const net::SSLInfo& ssl_info, | 147 const net::SSLInfo& ssl_info, |
145 bool sni_available) { | 148 bool sni_available) { |
146 DCHECK(!hostname.empty()); | 149 DCHECK(!hostname.empty()); |
147 DCHECK(ssl_info.is_valid()); | 150 DCHECK(ssl_info.is_valid()); |
148 ChromeFraudulentCertificateReporter::SendReport(hostname, ssl_info, | 151 ChromeFraudulentCertificateReporter::SendReport(hostname, ssl_info, |
149 sni_available); | 152 sni_available); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } | 197 } |
195 | 198 |
196 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { | 199 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { |
197 MessageLoop loop(MessageLoop::TYPE_IO); | 200 MessageLoop loop(MessageLoop::TYPE_IO); |
198 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); | 201 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); |
199 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); | 202 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); |
200 loop.RunAllPending(); | 203 loop.RunAllPending(); |
201 } | 204 } |
202 | 205 |
203 } // namespace chrome_browser_net | 206 } // namespace chrome_browser_net |
OLD | NEW |