OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <arpa/inet.h> | 5 #include <arpa/inet.h> |
6 #include <netinet/tcp.h> | 6 #include <netinet/tcp.h> |
7 #include <stdarg.h> | 7 #include <stdarg.h> |
8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "net/socket/tcp_client_socket.h" | 34 #include "net/socket/tcp_client_socket.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
36 #include "testing/platform_test.h" | 36 #include "testing/platform_test.h" |
37 | 37 |
38 namespace net { | 38 namespace net { |
39 | 39 |
40 // TestSSLHostInfo is an SSLHostInfo which stores a single state in memory and | 40 // TestSSLHostInfo is an SSLHostInfo which stores a single state in memory and |
41 // pretends that certificate verification always succeeds. | 41 // pretends that certificate verification always succeeds. |
42 class TestSSLHostInfo : public SSLHostInfo { | 42 class TestSSLHostInfo : public SSLHostInfo { |
43 public: | 43 public: |
44 TestSSLHostInfo() | 44 explicit TestSSLHostInfo(CertVerifier* cert_verifier) |
45 : SSLHostInfo("example.com", kDefaultSSLConfig) { | 45 : SSLHostInfo("example.com", kDefaultSSLConfig, cert_verifier) { |
46 if (!saved_.empty()) | 46 if (!saved_.empty()) |
47 Parse(saved_); | 47 Parse(saved_); |
48 cert_verification_complete_ = true; | 48 cert_verification_complete_ = true; |
49 cert_verification_error_ = OK; | 49 cert_verification_error_ = OK; |
50 } | 50 } |
51 | 51 |
52 virtual void Start() { | 52 virtual void Start() { |
53 } | 53 } |
54 | 54 |
55 virtual int WaitForDataReady(CompletionCallback*) { return OK; } | 55 virtual int WaitForDataReady(CompletionCallback*) { return OK; } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 localhost.push_back(0); | 187 localhost.push_back(0); |
188 localhost.push_back(1); | 188 localhost.push_back(1); |
189 AddressList addr_list(localhost, 443, false); | 189 AddressList addr_list(localhost, 443, false); |
190 TCPClientSocket* transport = new TCPClientSocket( | 190 TCPClientSocket* transport = new TCPClientSocket( |
191 addr_list, &log_, NetLog::Source()); | 191 addr_list, &log_, NetLog::Source()); |
192 | 192 |
193 transport->AdoptSocket(client_); | 193 transport->AdoptSocket(client_); |
194 scoped_ptr<SSLClientSocket> sock( | 194 scoped_ptr<SSLClientSocket> sock( |
195 socket_factory_->CreateSSLClientSocket( | 195 socket_factory_->CreateSSLClientSocket( |
196 transport, HostPortPair("example.com", 443), ssl_config_, | 196 transport, HostPortPair("example.com", 443), ssl_config_, |
197 new TestSSLHostInfo())); | 197 new TestSSLHostInfo(&cert_verifier_), &cert_verifier_)); |
198 | 198 |
199 TestCompletionCallback callback; | 199 TestCompletionCallback callback; |
200 int rv = sock->Connect(&callback); | 200 int rv = sock->Connect(&callback); |
201 if (rv != OK) { | 201 if (rv != OK) { |
202 ASSERT_EQ(ERR_IO_PENDING, rv); | 202 ASSERT_EQ(ERR_IO_PENDING, rv); |
203 EXPECT_FALSE(sock->IsConnected()); | 203 EXPECT_FALSE(sock->IsConnected()); |
204 rv = callback.WaitForResult(); | 204 rv = callback.WaitForResult(); |
205 EXPECT_EQ(OK, rv); | 205 EXPECT_EQ(OK, rv); |
206 } | 206 } |
207 EXPECT_TRUE(sock->IsConnected()); | 207 EXPECT_TRUE(sock->IsConnected()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 log_.GetEntries(&entries); | 258 log_.GetEntries(&entries); |
259 for (CapturingNetLog::EntryList::const_iterator | 259 for (CapturingNetLog::EntryList::const_iterator |
260 i = entries.begin(); i != entries.end(); i++) { | 260 i = entries.begin(); i != entries.end(); i++) { |
261 if (i->type == NetLog::TYPE_SSL_VERIFICATION_MERGED) | 261 if (i->type == NetLog::TYPE_SSL_VERIFICATION_MERGED) |
262 return true; | 262 return true; |
263 } | 263 } |
264 return false; | 264 return false; |
265 } | 265 } |
266 | 266 |
267 base::ProcessHandle child_; | 267 base::ProcessHandle child_; |
| 268 CertVerifier cert_verifier_; |
268 ClientSocketFactory* const socket_factory_; | 269 ClientSocketFactory* const socket_factory_; |
269 struct sockaddr_in remote_; | 270 struct sockaddr_in remote_; |
270 int client_; | 271 int client_; |
271 SSLConfig ssl_config_; | 272 SSLConfig ssl_config_; |
272 CapturingNetLog log_; | 273 CapturingNetLog log_; |
273 SSLClientSocket::NextProtoStatus next_proto_status_; | 274 SSLClientSocket::NextProtoStatus next_proto_status_; |
274 std::string next_proto_; | 275 std::string next_proto_; |
275 }; | 276 }; |
276 | 277 |
277 TEST_F(SSLClientSocketSnapStartTest, Basic) { | 278 TEST_F(SSLClientSocketSnapStartTest, Basic) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 360 |
360 SSLClientSocketNSS::ClearSessionCache(); | 361 SSLClientSocketNSS::ClearSessionCache(); |
361 PerformConnection(); | 362 PerformConnection(); |
362 EXPECT_EQ(SSL_SNAP_START_FULL, SnapStartEventType()); | 363 EXPECT_EQ(SSL_SNAP_START_FULL, SnapStartEventType()); |
363 EXPECT_EQ(SSLClientSocket::kNextProtoNegotiated, next_proto_status_); | 364 EXPECT_EQ(SSLClientSocket::kNextProtoNegotiated, next_proto_status_); |
364 EXPECT_EQ("baz", next_proto_); | 365 EXPECT_EQ("baz", next_proto_); |
365 EXPECT_TRUE(DidMerge()); | 366 EXPECT_TRUE(DidMerge()); |
366 } | 367 } |
367 | 368 |
368 } // namespace net | 369 } // namespace net |
OLD | NEW |