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::URLRequestContext* context) | 124 explicit MockURLRequest(net::URLRequestContext* context) |
125 : net::URLRequest(GURL(""), NULL, context) { | 125 : net::URLRequest(GURL(""), NULL, context) { |
126 } | 126 } |
127 | 127 |
128 private: | 128 private: |
129 }; | 129 }; |
130 | 130 |
131 // A ChromeFraudulentCertificateReporter that uses a MockURLRequest, but is | 131 // A ChromeFraudulentCertificateReporter that uses a MockURLRequest, but is |
132 // otherwise normal: reports are constructed and sent in the usual way. | 132 // otherwise normal: reports are constructed and sent in the usual way. |
133 class MockReporter : public ChromeFraudulentCertificateReporter { | 133 class MockReporter : public ChromeFraudulentCertificateReporter { |
134 public: | 134 public: |
(...skipping 10 matching lines...) Expand all Loading... |
145 const net::SSLInfo& ssl_info, | 145 const net::SSLInfo& ssl_info, |
146 bool sni_available) { | 146 bool sni_available) { |
147 DCHECK(!hostname.empty()); | 147 DCHECK(!hostname.empty()); |
148 DCHECK(ssl_info.is_valid()); | 148 DCHECK(ssl_info.is_valid()); |
149 ChromeFraudulentCertificateReporter::SendReport(hostname, ssl_info, | 149 ChromeFraudulentCertificateReporter::SendReport(hostname, ssl_info, |
150 sni_available); | 150 sni_available); |
151 } | 151 } |
152 }; | 152 }; |
153 | 153 |
154 static void DoReportIsSent() { | 154 static void DoReportIsSent() { |
155 ChromeURLRequestContext context; | 155 ChromeURLRequestContext context(ChromeURLRequestContext::CONTEXT_TYPE_MAIN, |
| 156 NULL); |
156 SendingTestReporter reporter(&context); | 157 SendingTestReporter reporter(&context); |
157 SSLInfo info = GetGoodSSLInfo(); | 158 SSLInfo info = GetGoodSSLInfo(); |
158 reporter.SendReport("mail.google.com", info, true); | 159 reporter.SendReport("mail.google.com", info, true); |
159 } | 160 } |
160 | 161 |
161 static void DoReportIsNotSent() { | 162 static void DoReportIsNotSent() { |
162 ChromeURLRequestContext context; | 163 ChromeURLRequestContext context(ChromeURLRequestContext::CONTEXT_TYPE_MAIN, |
| 164 NULL); |
163 NotSendingTestReporter reporter(&context); | 165 NotSendingTestReporter reporter(&context); |
164 SSLInfo info = GetBadSSLInfo(); | 166 SSLInfo info = GetBadSSLInfo(); |
165 reporter.SendReport("www.example.com", info, true); | 167 reporter.SendReport("www.example.com", info, true); |
166 } | 168 } |
167 | 169 |
168 static void DoMockReportIsSent() { | 170 static void DoMockReportIsSent() { |
169 ChromeURLRequestContext context; | 171 ChromeURLRequestContext context(ChromeURLRequestContext::CONTEXT_TYPE_MAIN, |
| 172 NULL); |
170 MockReporter reporter(&context); | 173 MockReporter reporter(&context); |
171 SSLInfo info = GetGoodSSLInfo(); | 174 SSLInfo info = GetGoodSSLInfo(); |
172 reporter.SendReport("mail.google.com", info, true); | 175 reporter.SendReport("mail.google.com", info, true); |
173 } | 176 } |
174 | 177 |
175 TEST(ChromeFraudulentCertificateReporterTest, GoodBadInfo) { | 178 TEST(ChromeFraudulentCertificateReporterTest, GoodBadInfo) { |
176 SSLInfo good = GetGoodSSLInfo(); | 179 SSLInfo good = GetGoodSSLInfo(); |
177 EXPECT_TRUE(IsGoodSSLInfo(good)); | 180 EXPECT_TRUE(IsGoodSSLInfo(good)); |
178 | 181 |
179 SSLInfo bad = GetBadSSLInfo(); | 182 SSLInfo bad = GetBadSSLInfo(); |
(...skipping 15 matching lines...) Expand all Loading... |
195 } | 198 } |
196 | 199 |
197 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { | 200 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { |
198 MessageLoop loop(MessageLoop::TYPE_IO); | 201 MessageLoop loop(MessageLoop::TYPE_IO); |
199 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); | 202 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); |
200 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); | 203 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); |
201 loop.RunAllPending(); | 204 loop.RunAllPending(); |
202 } | 205 } |
203 | 206 |
204 } // namespace chrome_browser_net | 207 } // namespace chrome_browser_net |
OLD | NEW |