OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/socket/ssl_client_socket.h" | 5 #include "net/socket/ssl_client_socket.h" |
6 | 6 |
7 #include "net/base/address_list.h" | 7 #include "net/base/address_list.h" |
8 #include "net/base/cert_verifier.h" | 8 #include "net/base/cert_verifier.h" |
9 #include "net/base/host_resolver.h" | 9 #include "net/base/host_resolver.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
11 #include "net/base/net_log.h" | 11 #include "net/base/net_log.h" |
12 #include "net/base/net_log_unittest.h" | 12 #include "net/base/net_log_unittest.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
14 #include "net/base/ssl_config_service.h" | 14 #include "net/base/ssl_config_service.h" |
15 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
16 #include "net/socket/client_socket_factory.h" | 16 #include "net/socket/client_socket_factory.h" |
17 #include "net/socket/client_socket_handle.h" | |
17 #include "net/socket/socket_test_util.h" | 18 #include "net/socket/socket_test_util.h" |
18 #include "net/socket/tcp_client_socket.h" | 19 #include "net/socket/tcp_client_socket.h" |
19 #include "net/test/test_server.h" | 20 #include "net/test/test_server.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "testing/platform_test.h" | 22 #include "testing/platform_test.h" |
22 | 23 |
23 //----------------------------------------------------------------------------- | 24 //----------------------------------------------------------------------------- |
24 | 25 |
25 const net::SSLConfig kDefaultSSLConfig; | 26 const net::SSLConfig kDefaultSSLConfig; |
26 | 27 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 // they'll give up waiting for application data and send the Finished after a | 59 // they'll give up waiting for application data and send the Finished after a |
59 // timeout. This means that an SSL connect end event may appear as a socket | 60 // timeout. This means that an SSL connect end event may appear as a socket |
60 // write. | 61 // write. |
61 static bool LogContainsSSLConnectEndEvent( | 62 static bool LogContainsSSLConnectEndEvent( |
62 const net::CapturingNetLog::EntryList& log, int i) { | 63 const net::CapturingNetLog::EntryList& log, int i) { |
63 return net::LogContainsEndEvent(log, i, net::NetLog::TYPE_SSL_CONNECT) || | 64 return net::LogContainsEndEvent(log, i, net::NetLog::TYPE_SSL_CONNECT) || |
64 net::LogContainsEvent(log, i, net::NetLog::TYPE_SOCKET_BYTES_SENT, | 65 net::LogContainsEvent(log, i, net::NetLog::TYPE_SOCKET_BYTES_SENT, |
65 net::NetLog::PHASE_NONE); | 66 net::NetLog::PHASE_NONE); |
66 }; | 67 }; |
67 | 68 |
69 TEST_F(SSLClientSocketTest, ClientSocketHandleNotFromPool) { | |
70 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); | |
71 ASSERT_TRUE(test_server.Start()); | |
72 | |
73 net::AddressList addr; | |
74 ASSERT_TRUE(test_server.GetAddressList(&addr)); | |
75 | |
76 TestCompletionCallback callback; | |
77 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | |
78 net::StreamSocket* transport = new net::TCPClientSocket( | |
79 addr, &log, net::NetLog::Source()); | |
80 int rv = transport->Connect(&callback); | |
81 if (rv == net::ERR_IO_PENDING) | |
82 rv = callback.WaitForResult(); | |
83 EXPECT_EQ(net::OK, rv); | |
84 | |
85 scoped_ptr<net::ClientSocketHandle> socket_handle( | |
86 new net::ClientSocketHandle()); | |
87 socket_handle->set_socket(transport); | |
88 | |
89 // When creating a SSLClientSocket, it is allowed to pass in a | |
90 // ClientSocketHandle that is not obtained from a client socket pool. | |
91 // Here we verify that such a simple ClientSocketHandle, not associated with | |
92 // any client socket pool, can be destroyed safely. | |
wtc
2011/08/15 19:35:12
Please move this comment before this unit test, at
yzshen1
2011/08/15 23:09:32
Done. Thanks!
| |
93 } | |
94 | |
68 TEST_F(SSLClientSocketTest, Connect) { | 95 TEST_F(SSLClientSocketTest, Connect) { |
69 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); | 96 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); |
70 ASSERT_TRUE(test_server.Start()); | 97 ASSERT_TRUE(test_server.Start()); |
71 | 98 |
72 net::AddressList addr; | 99 net::AddressList addr; |
73 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 100 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
74 | 101 |
75 TestCompletionCallback callback; | 102 TestCompletionCallback callback; |
76 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 103 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
77 net::StreamSocket* transport = new net::TCPClientSocket( | 104 net::StreamSocket* transport = new net::TCPClientSocket( |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 // to being an error such as a certificate name mismatch, which is | 725 // to being an error such as a certificate name mismatch, which is |
699 // client-only, the exact index of the SSL connect end depends on how | 726 // client-only, the exact index of the SSL connect end depends on how |
700 // quickly the test server closes the underlying socket. If the test server | 727 // quickly the test server closes the underlying socket. If the test server |
701 // closes before the IO message loop pumps messages, there may be a 0-byte | 728 // closes before the IO message loop pumps messages, there may be a 0-byte |
702 // Read event in the NetLog due to TCPClientSocket picking up the EOF. As a | 729 // Read event in the NetLog due to TCPClientSocket picking up the EOF. As a |
703 // result, the SSL connect end event will be the second-to-last entry, | 730 // result, the SSL connect end event will be the second-to-last entry, |
704 // rather than the last entry. | 731 // rather than the last entry. |
705 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1) || | 732 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1) || |
706 LogContainsSSLConnectEndEvent(entries, -2)); | 733 LogContainsSSLConnectEndEvent(entries, -2)); |
707 } | 734 } |
OLD | NEW |