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 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 // to being an error such as a certificate name mismatch, which is | 699 // 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 | 700 // 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 | 701 // 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 | 702 // 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 | 703 // 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, | 704 // result, the SSL connect end event will be the second-to-last entry, |
704 // rather than the last entry. | 705 // rather than the last entry. |
705 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1) || | 706 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1) || |
706 LogContainsSSLConnectEndEvent(entries, -2)); | 707 LogContainsSSLConnectEndEvent(entries, -2)); |
707 } | 708 } |
709 | |
710 // When creating an SSLClientSocket, it is allowed to pass in a | |
711 // ClientSocketHandle that is not obtained from a client socket pool. | |
712 // Here we verify that such a simple ClientSocketHandle, not associated with any | |
713 // client socket pool, can be destroyed safely. | |
714 TEST_F(SSLClientSocketTest, ClientSocketHandleNotFromPool) { | |
715 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); | |
716 ASSERT_TRUE(test_server.Start()); | |
717 | |
718 net::AddressList addr; | |
719 ASSERT_TRUE(test_server.GetAddressList(&addr)); | |
720 | |
721 TestCompletionCallback callback; | |
722 net::StreamSocket* transport = new net::TCPClientSocket( | |
723 addr, NULL, net::NetLog::Source()); | |
724 int rv = transport->Connect(&callback); | |
725 if (rv == net::ERR_IO_PENDING) | |
726 rv = callback.WaitForResult(); | |
727 EXPECT_EQ(net::OK, rv); | |
728 | |
729 net::ClientSocketHandle* socket_handle = new net::ClientSocketHandle(); | |
730 socket_handle->set_socket(transport); | |
731 | |
732 net::SSLClientSocketContext context; | |
733 context.cert_verifier = cert_verifier_.get(); | |
734 scoped_ptr<net::SSLClientSocket> ssl_socket( | |
735 socket_factory_->CreateSSLClientSocket( | |
736 socket_handle, test_server.host_port_pair(), kDefaultSSLConfig, | |
737 NULL, context)); | |
738 | |
739 EXPECT_FALSE(ssl_socket->IsConnected()); | |
740 rv = ssl_socket->Connect(&callback); | |
741 if (rv == net::ERR_IO_PENDING) | |
742 rv = callback.WaitForResult(); | |
743 } | |
wtc
2011/08/15 23:58:11
Add
EXPECT_EQ(net::OK, rv);
| |
OLD | NEW |