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 "net/socket/ssl_client_socket.h" | 5 #include "net/socket/ssl_client_socket.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "net/base/address_list.h" | 9 #include "net/base/address_list.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 2040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2051 EXPECT_TRUE(sock->IsConnected()); | 2051 EXPECT_TRUE(sock->IsConnected()); |
2052 log.GetEntries(&entries); | 2052 log.GetEntries(&entries); |
2053 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1)); | 2053 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1)); |
2054 | 2054 |
2055 EXPECT_FALSE(sock->signed_cert_timestamps_received_); | 2055 EXPECT_FALSE(sock->signed_cert_timestamps_received_); |
2056 | 2056 |
2057 sock->Disconnect(); | 2057 sock->Disconnect(); |
2058 EXPECT_FALSE(sock->IsConnected()); | 2058 EXPECT_FALSE(sock->IsConnected()); |
2059 } | 2059 } |
2060 | 2060 |
2061 // Tests that IsConnectedAndIdle and WasEverUsed behave as expected. | |
2062 TEST_F(SSLClientSocketTest, ReuseStates) { | |
2063 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, | |
2064 SpawnedTestServer::kLocalhost, | |
2065 base::FilePath()); | |
2066 ASSERT_TRUE(test_server.Start()); | |
2067 | |
2068 AddressList addr; | |
2069 ASSERT_TRUE(test_server.GetAddressList(&addr)); | |
2070 | |
2071 TestCompletionCallback callback; | |
2072 scoped_ptr<StreamSocket> transport( | |
2073 new TCPClientSocket(addr, NULL, NetLog::Source())); | |
2074 int rv = transport->Connect(callback.callback()); | |
2075 if (rv == ERR_IO_PENDING) | |
2076 rv = callback.WaitForResult(); | |
2077 EXPECT_EQ(OK, rv); | |
2078 | |
2079 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | |
2080 transport.Pass(), test_server.host_port_pair(), kDefaultSSLConfig)); | |
2081 | |
2082 rv = sock->Connect(callback.callback()); | |
2083 if (rv == ERR_IO_PENDING) | |
2084 rv = callback.WaitForResult(); | |
2085 EXPECT_EQ(OK, rv); | |
2086 | |
2087 // The socket was just connected. It should be idle because it is speaking | |
2088 // HTTP. Although the transport has been used for the handshake, WasEverUsed() | |
2089 // returns false. | |
2090 EXPECT_TRUE(sock->IsConnected()); | |
2091 EXPECT_TRUE(sock->IsConnectedAndIdle()); | |
2092 EXPECT_FALSE(sock->WasEverUsed()); | |
2093 | |
2094 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | |
mmenke
2014/03/18 15:16:55
nit kRequestText?
davidben
2014/03/25 19:50:18
Done. (That was from copy-and-paste actually.)
| |
2095 scoped_refptr<IOBuffer> request_buffer( | |
2096 new IOBuffer(arraysize(request_text) - 1)); | |
mmenke
2014/03/18 15:16:55
Suggest you have const with the value of "arraysiz
davidben
2014/03/25 19:50:18
Done.
| |
2097 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); | |
2098 | |
2099 rv = sock->Write( | |
2100 request_buffer.get(), arraysize(request_text) - 1, callback.callback()); | |
2101 EXPECT_TRUE(rv >= 0 || rv == ERR_IO_PENDING); | |
2102 | |
2103 if (rv == ERR_IO_PENDING) | |
2104 rv = callback.WaitForResult(); | |
2105 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); | |
2106 | |
2107 // The socket has now been used. | |
2108 EXPECT_TRUE(sock->WasEverUsed()); | |
2109 | |
2110 // TODO(davidben): Read one byte to ensure the test server has responded and | |
2111 // then assert IsConnectedAndIdle is false. This currently doesn't work | |
2112 // because neither SSLClientSocketNSS nor SSLClientSocketOpenSSL check their | |
2113 // SSL implementation's internal buffers. Either call PR_Available and | |
mmenke
2014/03/18 15:16:55
I'm assuming this means the "Idle" part wouldn't w
davidben
2014/03/25 19:50:18
Yeah, IsConnectedAndIdle() will still be true beca
| |
2114 // SSL_pending, although the former isn't actually implemented or perhaps | |
2115 // attempt to read one byte extra. | |
2116 } | |
2117 | |
2061 } // namespace net | 2118 } // namespace net |
OLD | NEW |