Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Side by Side Diff: net/socket/ssl_client_socket_unittest.cc

Issue 149511: Refactorings surrounding HostResolver:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Merge in socks5_client_socket_unittest.cc Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/socket/socks_client_socket_unittest.cc ('k') | net/socket/ssl_test_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/host_resolver.h" 8 #include "net/base/host_resolver.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "net/base/ssl_config_service.h" 11 #include "net/base/ssl_config_service.h"
12 #include "net/base/test_completion_callback.h" 12 #include "net/base/test_completion_callback.h"
13 #include "net/socket/client_socket_factory.h" 13 #include "net/socket/client_socket_factory.h"
14 #include "net/socket/ssl_test_util.h" 14 #include "net/socket/ssl_test_util.h"
15 #include "net/socket/tcp_client_socket.h" 15 #include "net/socket/tcp_client_socket.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/platform_test.h" 17 #include "testing/platform_test.h"
18 18
19 //----------------------------------------------------------------------------- 19 //-----------------------------------------------------------------------------
20 20
21 const net::SSLConfig kDefaultSSLConfig; 21 const net::SSLConfig kDefaultSSLConfig;
22 22
23 class SSLClientSocketTest : public PlatformTest { 23 class SSLClientSocketTest : public PlatformTest {
24 public: 24 public:
25 SSLClientSocketTest() 25 SSLClientSocketTest()
26 : socket_factory_(net::ClientSocketFactory::GetDefaultFactory()) { 26 : resolver_(net::CreateSystemHostResolver()),
27 socket_factory_(net::ClientSocketFactory::GetDefaultFactory()) {
27 } 28 }
28 29
29 void StartOKServer() { 30 void StartOKServer() {
30 bool success = server_.Start(net::TestServerLauncher::ProtoHTTP, 31 bool success = server_.Start(net::TestServerLauncher::ProtoHTTP,
31 server_.kHostName, server_.kOKHTTPSPort, 32 server_.kHostName, server_.kOKHTTPSPort,
32 FilePath(), server_.GetOKCertPath(), std::wstring()); 33 FilePath(), server_.GetOKCertPath(), std::wstring());
33 ASSERT_TRUE(success); 34 ASSERT_TRUE(success);
34 } 35 }
35 36
36 void StartMismatchedServer() { 37 void StartMismatchedServer() {
37 bool success = server_.Start(net::TestServerLauncher::ProtoHTTP, 38 bool success = server_.Start(net::TestServerLauncher::ProtoHTTP,
38 server_.kMismatchedHostName, server_.kOKHTTPSPort, 39 server_.kMismatchedHostName, server_.kOKHTTPSPort,
39 FilePath(), server_.GetOKCertPath(), std::wstring()); 40 FilePath(), server_.GetOKCertPath(), std::wstring());
40 ASSERT_TRUE(success); 41 ASSERT_TRUE(success);
41 } 42 }
42 43
43 void StartExpiredServer() { 44 void StartExpiredServer() {
44 bool success = server_.Start(net::TestServerLauncher::ProtoHTTP, 45 bool success = server_.Start(net::TestServerLauncher::ProtoHTTP,
45 server_.kHostName, server_.kBadHTTPSPort, 46 server_.kHostName, server_.kBadHTTPSPort,
46 FilePath(), server_.GetExpiredCertPath(), std::wstring()); 47 FilePath(), server_.GetExpiredCertPath(), std::wstring());
47 ASSERT_TRUE(success); 48 ASSERT_TRUE(success);
48 } 49 }
49 50
50 protected: 51 protected:
52 scoped_refptr<net::HostResolver> resolver_;
51 net::ClientSocketFactory* socket_factory_; 53 net::ClientSocketFactory* socket_factory_;
52 net::TestServerLauncher server_; 54 net::TestServerLauncher server_;
53 }; 55 };
54 56
55 //----------------------------------------------------------------------------- 57 //-----------------------------------------------------------------------------
56 58
57 #if defined(OS_MACOSX) 59 #if defined(OS_MACOSX)
58 // Status 6/19/09: 60 // Status 6/19/09:
59 // 61 //
60 // If these tests are enabled on OSX, we choke at the point 62 // If these tests are enabled on OSX, we choke at the point
(...skipping 18 matching lines...) Expand all
79 #define MAYBE_ConnectMismatched ConnectMismatched 81 #define MAYBE_ConnectMismatched ConnectMismatched
80 #define MAYBE_Read Read 82 #define MAYBE_Read Read
81 #define MAYBE_Read_SmallChunks Read_SmallChunks 83 #define MAYBE_Read_SmallChunks Read_SmallChunks
82 #define MAYBE_Read_Interrupted Read_Interrupted 84 #define MAYBE_Read_Interrupted Read_Interrupted
83 #endif 85 #endif
84 86
85 TEST_F(SSLClientSocketTest, MAYBE_Connect) { 87 TEST_F(SSLClientSocketTest, MAYBE_Connect) {
86 StartOKServer(); 88 StartOKServer();
87 89
88 net::AddressList addr; 90 net::AddressList addr;
89 scoped_refptr<net::HostResolver> resolver(new net::HostResolver);
90 TestCompletionCallback callback; 91 TestCompletionCallback callback;
91 92
92 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); 93 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort);
93 int rv = resolver->Resolve(info, &addr, NULL, NULL); 94 int rv = resolver_->Resolve(info, &addr, NULL, NULL);
94 EXPECT_EQ(net::OK, rv); 95 EXPECT_EQ(net::OK, rv);
95 96
96 net::ClientSocket *transport = new net::TCPClientSocket(addr); 97 net::ClientSocket *transport = new net::TCPClientSocket(addr);
97 rv = transport->Connect(&callback); 98 rv = transport->Connect(&callback);
98 if (rv == net::ERR_IO_PENDING) 99 if (rv == net::ERR_IO_PENDING)
99 rv = callback.WaitForResult(); 100 rv = callback.WaitForResult();
100 EXPECT_EQ(net::OK, rv); 101 EXPECT_EQ(net::OK, rv);
101 102
102 scoped_ptr<net::SSLClientSocket> sock( 103 scoped_ptr<net::SSLClientSocket> sock(
103 socket_factory_->CreateSSLClientSocket(transport, 104 socket_factory_->CreateSSLClientSocket(transport,
(...skipping 13 matching lines...) Expand all
117 EXPECT_TRUE(sock->IsConnected()); 118 EXPECT_TRUE(sock->IsConnected());
118 119
119 sock->Disconnect(); 120 sock->Disconnect();
120 EXPECT_FALSE(sock->IsConnected()); 121 EXPECT_FALSE(sock->IsConnected());
121 } 122 }
122 123
123 TEST_F(SSLClientSocketTest, MAYBE_ConnectExpired) { 124 TEST_F(SSLClientSocketTest, MAYBE_ConnectExpired) {
124 StartExpiredServer(); 125 StartExpiredServer();
125 126
126 net::AddressList addr; 127 net::AddressList addr;
127 scoped_refptr<net::HostResolver> resolver(new net::HostResolver);
128 TestCompletionCallback callback; 128 TestCompletionCallback callback;
129 129
130 net::HostResolver::RequestInfo info(server_.kHostName, server_.kBadHTTPSPort); 130 net::HostResolver::RequestInfo info(server_.kHostName, server_.kBadHTTPSPort);
131 int rv = resolver->Resolve(info, &addr, NULL, NULL); 131 int rv = resolver_->Resolve(info, &addr, NULL, NULL);
132 EXPECT_EQ(net::OK, rv); 132 EXPECT_EQ(net::OK, rv);
133 133
134 net::ClientSocket *transport = new net::TCPClientSocket(addr); 134 net::ClientSocket *transport = new net::TCPClientSocket(addr);
135 rv = transport->Connect(&callback); 135 rv = transport->Connect(&callback);
136 if (rv == net::ERR_IO_PENDING) 136 if (rv == net::ERR_IO_PENDING)
137 rv = callback.WaitForResult(); 137 rv = callback.WaitForResult();
138 EXPECT_EQ(net::OK, rv); 138 EXPECT_EQ(net::OK, rv);
139 139
140 scoped_ptr<net::SSLClientSocket> sock( 140 scoped_ptr<net::SSLClientSocket> sock(
141 socket_factory_->CreateSSLClientSocket(transport, 141 socket_factory_->CreateSSLClientSocket(transport,
(...skipping 12 matching lines...) Expand all
154 154
155 // We cannot test sock->IsConnected(), as the NSS implementation disconnects 155 // We cannot test sock->IsConnected(), as the NSS implementation disconnects
156 // the socket when it encounters an error, whereas other implementations 156 // the socket when it encounters an error, whereas other implementations
157 // leave it connected. 157 // leave it connected.
158 } 158 }
159 159
160 TEST_F(SSLClientSocketTest, MAYBE_ConnectMismatched) { 160 TEST_F(SSLClientSocketTest, MAYBE_ConnectMismatched) {
161 StartMismatchedServer(); 161 StartMismatchedServer();
162 162
163 net::AddressList addr; 163 net::AddressList addr;
164 scoped_refptr<net::HostResolver> resolver(new net::HostResolver);
165 TestCompletionCallback callback; 164 TestCompletionCallback callback;
166 165
167 net::HostResolver::RequestInfo info(server_.kMismatchedHostName, 166 net::HostResolver::RequestInfo info(server_.kMismatchedHostName,
168 server_.kOKHTTPSPort); 167 server_.kOKHTTPSPort);
169 int rv = resolver->Resolve(info, &addr, NULL, NULL); 168 int rv = resolver_->Resolve(info, &addr, NULL, NULL);
170 EXPECT_EQ(net::OK, rv); 169 EXPECT_EQ(net::OK, rv);
171 170
172 net::ClientSocket *transport = new net::TCPClientSocket(addr); 171 net::ClientSocket *transport = new net::TCPClientSocket(addr);
173 rv = transport->Connect(&callback); 172 rv = transport->Connect(&callback);
174 if (rv == net::ERR_IO_PENDING) 173 if (rv == net::ERR_IO_PENDING)
175 rv = callback.WaitForResult(); 174 rv = callback.WaitForResult();
176 EXPECT_EQ(net::OK, rv); 175 EXPECT_EQ(net::OK, rv);
177 176
178 scoped_ptr<net::SSLClientSocket> sock( 177 scoped_ptr<net::SSLClientSocket> sock(
179 socket_factory_->CreateSSLClientSocket(transport, 178 socket_factory_->CreateSSLClientSocket(transport,
(...skipping 17 matching lines...) Expand all
197 196
198 // TODO(wtc): Add unit tests for IsConnectedAndIdle: 197 // TODO(wtc): Add unit tests for IsConnectedAndIdle:
199 // - Server closes an SSL connection (with a close_notify alert message). 198 // - Server closes an SSL connection (with a close_notify alert message).
200 // - Server closes the underlying TCP connection directly. 199 // - Server closes the underlying TCP connection directly.
201 // - Server sends data unexpectedly. 200 // - Server sends data unexpectedly.
202 201
203 TEST_F(SSLClientSocketTest, MAYBE_Read) { 202 TEST_F(SSLClientSocketTest, MAYBE_Read) {
204 StartOKServer(); 203 StartOKServer();
205 204
206 net::AddressList addr; 205 net::AddressList addr;
207 scoped_refptr<net::HostResolver> resolver(new net::HostResolver);
208 TestCompletionCallback callback; 206 TestCompletionCallback callback;
209 207
210 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); 208 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort);
211 int rv = resolver->Resolve(info, &addr, &callback, NULL); 209 int rv = resolver_->Resolve(info, &addr, &callback, NULL);
212 EXPECT_EQ(net::ERR_IO_PENDING, rv); 210 EXPECT_EQ(net::ERR_IO_PENDING, rv);
213 211
214 rv = callback.WaitForResult(); 212 rv = callback.WaitForResult();
215 EXPECT_EQ(net::OK, rv); 213 EXPECT_EQ(net::OK, rv);
216 214
217 net::ClientSocket *transport = new net::TCPClientSocket(addr); 215 net::ClientSocket *transport = new net::TCPClientSocket(addr);
218 rv = transport->Connect(&callback); 216 rv = transport->Connect(&callback);
219 if (rv == net::ERR_IO_PENDING) 217 if (rv == net::ERR_IO_PENDING)
220 rv = callback.WaitForResult(); 218 rv = callback.WaitForResult();
221 EXPECT_EQ(net::OK, rv); 219 EXPECT_EQ(net::OK, rv);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 EXPECT_GE(rv, 0); 256 EXPECT_GE(rv, 0);
259 if (rv <= 0) 257 if (rv <= 0)
260 break; 258 break;
261 } 259 }
262 } 260 }
263 261
264 TEST_F(SSLClientSocketTest, MAYBE_Read_SmallChunks) { 262 TEST_F(SSLClientSocketTest, MAYBE_Read_SmallChunks) {
265 StartOKServer(); 263 StartOKServer();
266 264
267 net::AddressList addr; 265 net::AddressList addr;
268 scoped_refptr<net::HostResolver> resolver(new net::HostResolver);
269 TestCompletionCallback callback; 266 TestCompletionCallback callback;
270 267
271 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); 268 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort);
272 int rv = resolver->Resolve(info, &addr, NULL, NULL); 269 int rv = resolver_->Resolve(info, &addr, NULL, NULL);
273 EXPECT_EQ(net::OK, rv); 270 EXPECT_EQ(net::OK, rv);
274 271
275 net::ClientSocket *transport = new net::TCPClientSocket(addr); 272 net::ClientSocket *transport = new net::TCPClientSocket(addr);
276 rv = transport->Connect(&callback); 273 rv = transport->Connect(&callback);
277 if (rv == net::ERR_IO_PENDING) 274 if (rv == net::ERR_IO_PENDING)
278 rv = callback.WaitForResult(); 275 rv = callback.WaitForResult();
279 EXPECT_EQ(net::OK, rv); 276 EXPECT_EQ(net::OK, rv);
280 277
281 scoped_ptr<net::SSLClientSocket> sock( 278 scoped_ptr<net::SSLClientSocket> sock(
282 socket_factory_->CreateSSLClientSocket(transport, 279 socket_factory_->CreateSSLClientSocket(transport,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 EXPECT_GE(rv, 0); 311 EXPECT_GE(rv, 0);
315 if (rv <= 0) 312 if (rv <= 0)
316 break; 313 break;
317 } 314 }
318 } 315 }
319 316
320 TEST_F(SSLClientSocketTest, MAYBE_Read_Interrupted) { 317 TEST_F(SSLClientSocketTest, MAYBE_Read_Interrupted) {
321 StartOKServer(); 318 StartOKServer();
322 319
323 net::AddressList addr; 320 net::AddressList addr;
324 scoped_refptr<net::HostResolver> resolver(new net::HostResolver);
325 TestCompletionCallback callback; 321 TestCompletionCallback callback;
326 322
327 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); 323 net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort);
328 int rv = resolver->Resolve(info, &addr, NULL, NULL); 324 int rv = resolver_->Resolve(info, &addr, NULL, NULL);
329 EXPECT_EQ(net::OK, rv); 325 EXPECT_EQ(net::OK, rv);
330 326
331 net::ClientSocket *transport = new net::TCPClientSocket(addr); 327 net::ClientSocket *transport = new net::TCPClientSocket(addr);
332 rv = transport->Connect(&callback); 328 rv = transport->Connect(&callback);
333 if (rv == net::ERR_IO_PENDING) 329 if (rv == net::ERR_IO_PENDING)
334 rv = callback.WaitForResult(); 330 rv = callback.WaitForResult();
335 EXPECT_EQ(net::OK, rv); 331 EXPECT_EQ(net::OK, rv);
336 332
337 scoped_ptr<net::SSLClientSocket> sock( 333 scoped_ptr<net::SSLClientSocket> sock(
338 socket_factory_->CreateSSLClientSocket(transport, 334 socket_factory_->CreateSSLClientSocket(transport,
(...skipping 23 matching lines...) Expand all
362 // Do a partial read and then exit. This test should not crash! 358 // Do a partial read and then exit. This test should not crash!
363 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(512); 359 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(512);
364 rv = sock->Read(buf, 512, &callback); 360 rv = sock->Read(buf, 512, &callback);
365 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); 361 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING);
366 362
367 if (rv == net::ERR_IO_PENDING) 363 if (rv == net::ERR_IO_PENDING)
368 rv = callback.WaitForResult(); 364 rv = callback.WaitForResult();
369 365
370 EXPECT_NE(rv, 0); 366 EXPECT_NE(rv, 0);
371 } 367 }
OLDNEW
« no previous file with comments | « net/socket/socks_client_socket_unittest.cc ('k') | net/socket/ssl_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698