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/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "chrome/browser/net/chrome_url_request_context.h" | 15 #include "chrome/browser/net/chrome_url_request_context.h" |
16 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
| 17 #include "net/base/request_priority.h" |
17 #include "net/base/test_data_directory.h" | 18 #include "net/base/test_data_directory.h" |
18 #include "net/cert/x509_certificate.h" | 19 #include "net/cert/x509_certificate.h" |
19 #include "net/http/transport_security_state.h" | 20 #include "net/http/transport_security_state.h" |
20 #include "net/ssl/ssl_info.h" | 21 #include "net/ssl/ssl_info.h" |
21 #include "net/test/cert_test_util.h" | 22 #include "net/test/cert_test_util.h" |
22 #include "net/url_request/fraudulent_certificate_reporter.h" | 23 #include "net/url_request/fraudulent_certificate_reporter.h" |
23 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 using content::BrowserThread; | 27 using content::BrowserThread; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 117 |
117 // For the first version of the feature, sending reports is "fire and forget". | 118 // For the first version of the feature, sending reports is "fire and forget". |
118 // Therefore, we test only that the Reporter tried to send a request at all. | 119 // Therefore, we test only that the Reporter tried to send a request at all. |
119 // In the future, when we have more sophisticated (i.e., any) error handling | 120 // In the future, when we have more sophisticated (i.e., any) error handling |
120 // and re-tries, we will need more sopisticated tests as well. | 121 // and re-tries, we will need more sopisticated tests as well. |
121 // | 122 // |
122 // This class doesn't do anything now, but in near future versions it will. | 123 // This class doesn't do anything now, but in near future versions it will. |
123 class MockURLRequest : public net::URLRequest { | 124 class MockURLRequest : public net::URLRequest { |
124 public: | 125 public: |
125 explicit MockURLRequest(net::URLRequestContext* context) | 126 explicit MockURLRequest(net::URLRequestContext* context) |
126 : net::URLRequest(GURL(std::string()), NULL, context) {} | 127 : net::URLRequest(GURL(std::string()), |
| 128 net::DEFAULT_PRIORITY, |
| 129 NULL, |
| 130 context) {} |
127 | 131 |
128 private: | 132 private: |
129 }; | 133 }; |
130 | 134 |
131 // A ChromeFraudulentCertificateReporter that uses a MockURLRequest, but is | 135 // A ChromeFraudulentCertificateReporter that uses a MockURLRequest, but is |
132 // otherwise normal: reports are constructed and sent in the usual way. | 136 // otherwise normal: reports are constructed and sent in the usual way. |
133 class MockReporter : public ChromeFraudulentCertificateReporter { | 137 class MockReporter : public ChromeFraudulentCertificateReporter { |
134 public: | 138 public: |
135 explicit MockReporter(net::URLRequestContext* request_context) | 139 explicit MockReporter(net::URLRequestContext* request_context) |
136 : ChromeFraudulentCertificateReporter(request_context) {} | 140 : ChromeFraudulentCertificateReporter(request_context) {} |
137 | 141 |
138 virtual net::URLRequest* CreateURLRequest( | 142 virtual scoped_ptr<net::URLRequest> CreateURLRequest( |
139 net::URLRequestContext* context) OVERRIDE { | 143 net::URLRequestContext* context) OVERRIDE { |
140 return new MockURLRequest(context); | 144 return scoped_ptr<net::URLRequest>(new MockURLRequest(context)); |
141 } | 145 } |
142 | 146 |
143 virtual void SendReport( | 147 virtual void SendReport( |
144 const std::string& hostname, | 148 const std::string& hostname, |
145 const net::SSLInfo& ssl_info, | 149 const net::SSLInfo& ssl_info, |
146 bool sni_available) OVERRIDE { | 150 bool sni_available) OVERRIDE { |
147 DCHECK(!hostname.empty()); | 151 DCHECK(!hostname.empty()); |
148 DCHECK(ssl_info.is_valid()); | 152 DCHECK(ssl_info.is_valid()); |
149 ChromeFraudulentCertificateReporter::SendReport(hostname, ssl_info, | 153 ChromeFraudulentCertificateReporter::SendReport(hostname, ssl_info, |
150 sni_available); | 154 sni_available); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } | 202 } |
199 | 203 |
200 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { | 204 TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { |
201 base::MessageLoop loop(base::MessageLoop::TYPE_IO); | 205 base::MessageLoop loop(base::MessageLoop::TYPE_IO); |
202 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); | 206 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); |
203 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); | 207 loop.PostTask(FROM_HERE, base::Bind(&DoReportIsNotSent)); |
204 loop.RunUntilIdle(); | 208 loop.RunUntilIdle(); |
205 } | 209 } |
206 | 210 |
207 } // namespace chrome_browser_net | 211 } // namespace chrome_browser_net |
OLD | NEW |