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/socks_client_socket.h" | 5 #include "net/socket/socks_client_socket.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "net/base/address_list.h" | 11 #include "net/base/address_list.h" |
12 #include "net/base/test_completion_callback.h" | 12 #include "net/base/test_completion_callback.h" |
13 #include "net/base/winsock_init.h" | 13 #include "net/base/winsock_init.h" |
14 #include "net/dns/host_resolver.h" | 14 #include "net/dns/host_resolver.h" |
15 #include "net/dns/mock_host_resolver.h" | 15 #include "net/dns/mock_host_resolver.h" |
16 #include "net/log/net_log.h" | 16 #include "net/log/net_log.h" |
17 #include "net/log/test_net_log.h" | 17 #include "net/log/test_net_log.h" |
18 #include "net/log/test_net_log_entry.h" | 18 #include "net/log/test_net_log_entry.h" |
19 #include "net/log/test_net_log_util.h" | 19 #include "net/log/test_net_log_util.h" |
20 #include "net/socket/client_socket_factory.h" | 20 #include "net/socket/client_socket_factory.h" |
21 #include "net/socket/socket_test_util.h" | 21 #include "net/socket/socket_test_util.h" |
22 #include "net/socket/tcp_client_socket.h" | 22 #include "net/socket/tcp_client_socket.h" |
| 23 #include "net/test/gtest_util.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "testing/platform_test.h" | 26 #include "testing/platform_test.h" |
25 | 27 |
| 28 using net::test::IsError; |
| 29 using net::test::IsOk; |
| 30 |
26 //----------------------------------------------------------------------------- | 31 //----------------------------------------------------------------------------- |
27 | 32 |
28 namespace net { | 33 namespace net { |
29 | 34 |
30 const char kSOCKSOkRequest[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; | 35 const char kSOCKSOkRequest[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
31 const char kSOCKSOkReply[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; | 36 const char kSOCKSOkReply[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
32 | 37 |
33 class SOCKSClientSocketTest : public PlatformTest { | 38 class SOCKSClientSocketTest : public PlatformTest { |
34 public: | 39 public: |
35 SOCKSClientSocketTest(); | 40 SOCKSClientSocketTest(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 HostResolver* host_resolver, | 78 HostResolver* host_resolver, |
74 const std::string& hostname, | 79 const std::string& hostname, |
75 int port, | 80 int port, |
76 NetLog* net_log) { | 81 NetLog* net_log) { |
77 TestCompletionCallback callback; | 82 TestCompletionCallback callback; |
78 data_.reset(new StaticSocketDataProvider(reads, reads_count, | 83 data_.reset(new StaticSocketDataProvider(reads, reads_count, |
79 writes, writes_count)); | 84 writes, writes_count)); |
80 tcp_sock_ = new MockTCPClientSocket(address_list_, net_log, data_.get()); | 85 tcp_sock_ = new MockTCPClientSocket(address_list_, net_log, data_.get()); |
81 | 86 |
82 int rv = tcp_sock_->Connect(callback.callback()); | 87 int rv = tcp_sock_->Connect(callback.callback()); |
83 EXPECT_EQ(ERR_IO_PENDING, rv); | 88 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
84 rv = callback.WaitForResult(); | 89 rv = callback.WaitForResult(); |
85 EXPECT_EQ(OK, rv); | 90 EXPECT_THAT(rv, IsOk()); |
86 EXPECT_TRUE(tcp_sock_->IsConnected()); | 91 EXPECT_TRUE(tcp_sock_->IsConnected()); |
87 | 92 |
88 std::unique_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 93 std::unique_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
89 // |connection| takes ownership of |tcp_sock_|, but keep a | 94 // |connection| takes ownership of |tcp_sock_|, but keep a |
90 // non-owning pointer to it. | 95 // non-owning pointer to it. |
91 connection->SetSocket(std::unique_ptr<StreamSocket>(tcp_sock_)); | 96 connection->SetSocket(std::unique_ptr<StreamSocket>(tcp_sock_)); |
92 return std::unique_ptr<SOCKSClientSocket>(new SOCKSClientSocket( | 97 return std::unique_ptr<SOCKSClientSocket>(new SOCKSClientSocket( |
93 std::move(connection), | 98 std::move(connection), |
94 HostResolver::RequestInfo(HostPortPair(hostname, port)), DEFAULT_PRIORITY, | 99 HostResolver::RequestInfo(HostPortPair(hostname, port)), DEFAULT_PRIORITY, |
95 host_resolver)); | 100 host_resolver)); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 data_writes, arraysize(data_writes), | 161 data_writes, arraysize(data_writes), |
157 host_resolver_.get(), | 162 host_resolver_.get(), |
158 "localhost", 80, | 163 "localhost", 80, |
159 &log); | 164 &log); |
160 | 165 |
161 // At this state the TCP connection is completed but not the SOCKS handshake. | 166 // At this state the TCP connection is completed but not the SOCKS handshake. |
162 EXPECT_TRUE(tcp_sock_->IsConnected()); | 167 EXPECT_TRUE(tcp_sock_->IsConnected()); |
163 EXPECT_FALSE(user_sock_->IsConnected()); | 168 EXPECT_FALSE(user_sock_->IsConnected()); |
164 | 169 |
165 int rv = user_sock_->Connect(callback_.callback()); | 170 int rv = user_sock_->Connect(callback_.callback()); |
166 EXPECT_EQ(ERR_IO_PENDING, rv); | 171 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
167 | 172 |
168 TestNetLogEntry::List entries; | 173 TestNetLogEntry::List entries; |
169 log.GetEntries(&entries); | 174 log.GetEntries(&entries); |
170 EXPECT_TRUE( | 175 EXPECT_TRUE( |
171 LogContainsBeginEvent(entries, 0, NetLog::TYPE_SOCKS_CONNECT)); | 176 LogContainsBeginEvent(entries, 0, NetLog::TYPE_SOCKS_CONNECT)); |
172 EXPECT_FALSE(user_sock_->IsConnected()); | 177 EXPECT_FALSE(user_sock_->IsConnected()); |
173 | 178 |
174 rv = callback_.WaitForResult(); | 179 rv = callback_.WaitForResult(); |
175 EXPECT_EQ(OK, rv); | 180 EXPECT_THAT(rv, IsOk()); |
176 EXPECT_TRUE(user_sock_->IsConnected()); | 181 EXPECT_TRUE(user_sock_->IsConnected()); |
177 log.GetEntries(&entries); | 182 log.GetEntries(&entries); |
178 EXPECT_TRUE(LogContainsEndEvent( | 183 EXPECT_TRUE(LogContainsEndEvent( |
179 entries, -1, NetLog::TYPE_SOCKS_CONNECT)); | 184 entries, -1, NetLog::TYPE_SOCKS_CONNECT)); |
180 | 185 |
181 scoped_refptr<IOBuffer> buffer(new IOBuffer(payload_write.size())); | 186 scoped_refptr<IOBuffer> buffer(new IOBuffer(payload_write.size())); |
182 memcpy(buffer->data(), payload_write.data(), payload_write.size()); | 187 memcpy(buffer->data(), payload_write.data(), payload_write.size()); |
183 rv = user_sock_->Write( | 188 rv = user_sock_->Write( |
184 buffer.get(), payload_write.size(), callback_.callback()); | 189 buffer.get(), payload_write.size(), callback_.callback()); |
185 EXPECT_EQ(ERR_IO_PENDING, rv); | 190 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
186 rv = callback_.WaitForResult(); | 191 rv = callback_.WaitForResult(); |
187 EXPECT_EQ(static_cast<int>(payload_write.size()), rv); | 192 EXPECT_EQ(static_cast<int>(payload_write.size()), rv); |
188 | 193 |
189 buffer = new IOBuffer(payload_read.size()); | 194 buffer = new IOBuffer(payload_read.size()); |
190 rv = | 195 rv = |
191 user_sock_->Read(buffer.get(), payload_read.size(), callback_.callback()); | 196 user_sock_->Read(buffer.get(), payload_read.size(), callback_.callback()); |
192 EXPECT_EQ(ERR_IO_PENDING, rv); | 197 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
193 rv = callback_.WaitForResult(); | 198 rv = callback_.WaitForResult(); |
194 EXPECT_EQ(static_cast<int>(payload_read.size()), rv); | 199 EXPECT_EQ(static_cast<int>(payload_read.size()), rv); |
195 EXPECT_EQ(payload_read, std::string(buffer->data(), payload_read.size())); | 200 EXPECT_EQ(payload_read, std::string(buffer->data(), payload_read.size())); |
196 | 201 |
197 user_sock_->Disconnect(); | 202 user_sock_->Disconnect(); |
198 EXPECT_FALSE(tcp_sock_->IsConnected()); | 203 EXPECT_FALSE(tcp_sock_->IsConnected()); |
199 EXPECT_FALSE(user_sock_->IsConnected()); | 204 EXPECT_FALSE(user_sock_->IsConnected()); |
200 } | 205 } |
201 | 206 |
202 // List of responses from the socks server and the errors they should | 207 // List of responses from the socks server and the errors they should |
(...skipping 25 matching lines...) Expand all Loading... |
228 arraysize(tests[i].fail_reply)) }; | 233 arraysize(tests[i].fail_reply)) }; |
229 TestNetLog log; | 234 TestNetLog log; |
230 | 235 |
231 user_sock_ = BuildMockSocket(data_reads, arraysize(data_reads), | 236 user_sock_ = BuildMockSocket(data_reads, arraysize(data_reads), |
232 data_writes, arraysize(data_writes), | 237 data_writes, arraysize(data_writes), |
233 host_resolver_.get(), | 238 host_resolver_.get(), |
234 "localhost", 80, | 239 "localhost", 80, |
235 &log); | 240 &log); |
236 | 241 |
237 int rv = user_sock_->Connect(callback_.callback()); | 242 int rv = user_sock_->Connect(callback_.callback()); |
238 EXPECT_EQ(ERR_IO_PENDING, rv); | 243 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
239 | 244 |
240 TestNetLogEntry::List entries; | 245 TestNetLogEntry::List entries; |
241 log.GetEntries(&entries); | 246 log.GetEntries(&entries); |
242 EXPECT_TRUE(LogContainsBeginEvent( | 247 EXPECT_TRUE(LogContainsBeginEvent( |
243 entries, 0, NetLog::TYPE_SOCKS_CONNECT)); | 248 entries, 0, NetLog::TYPE_SOCKS_CONNECT)); |
244 | 249 |
245 rv = callback_.WaitForResult(); | 250 rv = callback_.WaitForResult(); |
246 EXPECT_EQ(tests[i].fail_code, rv); | 251 EXPECT_EQ(tests[i].fail_code, rv); |
247 EXPECT_FALSE(user_sock_->IsConnected()); | 252 EXPECT_FALSE(user_sock_->IsConnected()); |
248 EXPECT_TRUE(tcp_sock_->IsConnected()); | 253 EXPECT_TRUE(tcp_sock_->IsConnected()); |
(...skipping 16 matching lines...) Expand all Loading... |
265 MockRead(ASYNC, kSOCKSPartialReply2, arraysize(kSOCKSPartialReply2)) }; | 270 MockRead(ASYNC, kSOCKSPartialReply2, arraysize(kSOCKSPartialReply2)) }; |
266 TestNetLog log; | 271 TestNetLog log; |
267 | 272 |
268 user_sock_ = BuildMockSocket(data_reads, arraysize(data_reads), | 273 user_sock_ = BuildMockSocket(data_reads, arraysize(data_reads), |
269 data_writes, arraysize(data_writes), | 274 data_writes, arraysize(data_writes), |
270 host_resolver_.get(), | 275 host_resolver_.get(), |
271 "localhost", 80, | 276 "localhost", 80, |
272 &log); | 277 &log); |
273 | 278 |
274 int rv = user_sock_->Connect(callback_.callback()); | 279 int rv = user_sock_->Connect(callback_.callback()); |
275 EXPECT_EQ(ERR_IO_PENDING, rv); | 280 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
276 TestNetLogEntry::List entries; | 281 TestNetLogEntry::List entries; |
277 log.GetEntries(&entries); | 282 log.GetEntries(&entries); |
278 EXPECT_TRUE(LogContainsBeginEvent( | 283 EXPECT_TRUE(LogContainsBeginEvent( |
279 entries, 0, NetLog::TYPE_SOCKS_CONNECT)); | 284 entries, 0, NetLog::TYPE_SOCKS_CONNECT)); |
280 | 285 |
281 rv = callback_.WaitForResult(); | 286 rv = callback_.WaitForResult(); |
282 EXPECT_EQ(OK, rv); | 287 EXPECT_THAT(rv, IsOk()); |
283 EXPECT_TRUE(user_sock_->IsConnected()); | 288 EXPECT_TRUE(user_sock_->IsConnected()); |
284 log.GetEntries(&entries); | 289 log.GetEntries(&entries); |
285 EXPECT_TRUE(LogContainsEndEvent( | 290 EXPECT_TRUE(LogContainsEndEvent( |
286 entries, -1, NetLog::TYPE_SOCKS_CONNECT)); | 291 entries, -1, NetLog::TYPE_SOCKS_CONNECT)); |
287 } | 292 } |
288 | 293 |
289 // Tests scenario when the client sends the handshake request in | 294 // Tests scenario when the client sends the handshake request in |
290 // more than one packet. | 295 // more than one packet. |
291 TEST_F(SOCKSClientSocketTest, PartialClientWrites) { | 296 TEST_F(SOCKSClientSocketTest, PartialClientWrites) { |
292 const char kSOCKSPartialRequest1[] = { 0x04, 0x01 }; | 297 const char kSOCKSPartialRequest1[] = { 0x04, 0x01 }; |
(...skipping 10 matching lines...) Expand all Loading... |
303 MockRead(ASYNC, kSOCKSOkReply, arraysize(kSOCKSOkReply)) }; | 308 MockRead(ASYNC, kSOCKSOkReply, arraysize(kSOCKSOkReply)) }; |
304 TestNetLog log; | 309 TestNetLog log; |
305 | 310 |
306 user_sock_ = BuildMockSocket(data_reads, arraysize(data_reads), | 311 user_sock_ = BuildMockSocket(data_reads, arraysize(data_reads), |
307 data_writes, arraysize(data_writes), | 312 data_writes, arraysize(data_writes), |
308 host_resolver_.get(), | 313 host_resolver_.get(), |
309 "localhost", 80, | 314 "localhost", 80, |
310 &log); | 315 &log); |
311 | 316 |
312 int rv = user_sock_->Connect(callback_.callback()); | 317 int rv = user_sock_->Connect(callback_.callback()); |
313 EXPECT_EQ(ERR_IO_PENDING, rv); | 318 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
314 TestNetLogEntry::List entries; | 319 TestNetLogEntry::List entries; |
315 log.GetEntries(&entries); | 320 log.GetEntries(&entries); |
316 EXPECT_TRUE(LogContainsBeginEvent( | 321 EXPECT_TRUE(LogContainsBeginEvent( |
317 entries, 0, NetLog::TYPE_SOCKS_CONNECT)); | 322 entries, 0, NetLog::TYPE_SOCKS_CONNECT)); |
318 | 323 |
319 rv = callback_.WaitForResult(); | 324 rv = callback_.WaitForResult(); |
320 EXPECT_EQ(OK, rv); | 325 EXPECT_THAT(rv, IsOk()); |
321 EXPECT_TRUE(user_sock_->IsConnected()); | 326 EXPECT_TRUE(user_sock_->IsConnected()); |
322 log.GetEntries(&entries); | 327 log.GetEntries(&entries); |
323 EXPECT_TRUE(LogContainsEndEvent( | 328 EXPECT_TRUE(LogContainsEndEvent( |
324 entries, -1, NetLog::TYPE_SOCKS_CONNECT)); | 329 entries, -1, NetLog::TYPE_SOCKS_CONNECT)); |
325 } | 330 } |
326 | 331 |
327 // Tests the case when the server sends a smaller sized handshake data | 332 // Tests the case when the server sends a smaller sized handshake data |
328 // and closes the connection. | 333 // and closes the connection. |
329 TEST_F(SOCKSClientSocketTest, FailedSocketRead) { | 334 TEST_F(SOCKSClientSocketTest, FailedSocketRead) { |
330 MockWrite data_writes[] = { | 335 MockWrite data_writes[] = { |
331 MockWrite(ASYNC, kSOCKSOkRequest, arraysize(kSOCKSOkRequest)) }; | 336 MockWrite(ASYNC, kSOCKSOkRequest, arraysize(kSOCKSOkRequest)) }; |
332 MockRead data_reads[] = { | 337 MockRead data_reads[] = { |
333 MockRead(ASYNC, kSOCKSOkReply, arraysize(kSOCKSOkReply) - 2), | 338 MockRead(ASYNC, kSOCKSOkReply, arraysize(kSOCKSOkReply) - 2), |
334 // close connection unexpectedly | 339 // close connection unexpectedly |
335 MockRead(SYNCHRONOUS, 0) }; | 340 MockRead(SYNCHRONOUS, 0) }; |
336 TestNetLog log; | 341 TestNetLog log; |
337 | 342 |
338 user_sock_ = BuildMockSocket(data_reads, arraysize(data_reads), | 343 user_sock_ = BuildMockSocket(data_reads, arraysize(data_reads), |
339 data_writes, arraysize(data_writes), | 344 data_writes, arraysize(data_writes), |
340 host_resolver_.get(), | 345 host_resolver_.get(), |
341 "localhost", 80, | 346 "localhost", 80, |
342 &log); | 347 &log); |
343 | 348 |
344 int rv = user_sock_->Connect(callback_.callback()); | 349 int rv = user_sock_->Connect(callback_.callback()); |
345 EXPECT_EQ(ERR_IO_PENDING, rv); | 350 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
346 TestNetLogEntry::List entries; | 351 TestNetLogEntry::List entries; |
347 log.GetEntries(&entries); | 352 log.GetEntries(&entries); |
348 EXPECT_TRUE(LogContainsBeginEvent( | 353 EXPECT_TRUE(LogContainsBeginEvent( |
349 entries, 0, NetLog::TYPE_SOCKS_CONNECT)); | 354 entries, 0, NetLog::TYPE_SOCKS_CONNECT)); |
350 | 355 |
351 rv = callback_.WaitForResult(); | 356 rv = callback_.WaitForResult(); |
352 EXPECT_EQ(ERR_CONNECTION_CLOSED, rv); | 357 EXPECT_THAT(rv, IsError(ERR_CONNECTION_CLOSED)); |
353 EXPECT_FALSE(user_sock_->IsConnected()); | 358 EXPECT_FALSE(user_sock_->IsConnected()); |
354 log.GetEntries(&entries); | 359 log.GetEntries(&entries); |
355 EXPECT_TRUE(LogContainsEndEvent( | 360 EXPECT_TRUE(LogContainsEndEvent( |
356 entries, -1, NetLog::TYPE_SOCKS_CONNECT)); | 361 entries, -1, NetLog::TYPE_SOCKS_CONNECT)); |
357 } | 362 } |
358 | 363 |
359 // Tries to connect to an unknown hostname. Should fail rather than | 364 // Tries to connect to an unknown hostname. Should fail rather than |
360 // falling back to SOCKS4a. | 365 // falling back to SOCKS4a. |
361 TEST_F(SOCKSClientSocketTest, FailedDNS) { | 366 TEST_F(SOCKSClientSocketTest, FailedDNS) { |
362 const char hostname[] = "unresolved.ipv4.address"; | 367 const char hostname[] = "unresolved.ipv4.address"; |
363 | 368 |
364 host_resolver_->rules()->AddSimulatedFailure(hostname); | 369 host_resolver_->rules()->AddSimulatedFailure(hostname); |
365 | 370 |
366 TestNetLog log; | 371 TestNetLog log; |
367 | 372 |
368 user_sock_ = BuildMockSocket(NULL, 0, | 373 user_sock_ = BuildMockSocket(NULL, 0, |
369 NULL, 0, | 374 NULL, 0, |
370 host_resolver_.get(), | 375 host_resolver_.get(), |
371 hostname, 80, | 376 hostname, 80, |
372 &log); | 377 &log); |
373 | 378 |
374 int rv = user_sock_->Connect(callback_.callback()); | 379 int rv = user_sock_->Connect(callback_.callback()); |
375 EXPECT_EQ(ERR_IO_PENDING, rv); | 380 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
376 TestNetLogEntry::List entries; | 381 TestNetLogEntry::List entries; |
377 log.GetEntries(&entries); | 382 log.GetEntries(&entries); |
378 EXPECT_TRUE(LogContainsBeginEvent( | 383 EXPECT_TRUE(LogContainsBeginEvent( |
379 entries, 0, NetLog::TYPE_SOCKS_CONNECT)); | 384 entries, 0, NetLog::TYPE_SOCKS_CONNECT)); |
380 | 385 |
381 rv = callback_.WaitForResult(); | 386 rv = callback_.WaitForResult(); |
382 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); | 387 EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
383 EXPECT_FALSE(user_sock_->IsConnected()); | 388 EXPECT_FALSE(user_sock_->IsConnected()); |
384 log.GetEntries(&entries); | 389 log.GetEntries(&entries); |
385 EXPECT_TRUE(LogContainsEndEvent( | 390 EXPECT_TRUE(LogContainsEndEvent( |
386 entries, -1, NetLog::TYPE_SOCKS_CONNECT)); | 391 entries, -1, NetLog::TYPE_SOCKS_CONNECT)); |
387 } | 392 } |
388 | 393 |
389 // Calls Disconnect() while a host resolve is in progress. The outstanding host | 394 // Calls Disconnect() while a host resolve is in progress. The outstanding host |
390 // resolve should be cancelled. | 395 // resolve should be cancelled. |
391 TEST_F(SOCKSClientSocketTest, DisconnectWhileHostResolveInProgress) { | 396 TEST_F(SOCKSClientSocketTest, DisconnectWhileHostResolveInProgress) { |
392 std::unique_ptr<HangingHostResolverWithCancel> hanging_resolver( | 397 std::unique_ptr<HangingHostResolverWithCancel> hanging_resolver( |
393 new HangingHostResolverWithCancel()); | 398 new HangingHostResolverWithCancel()); |
394 | 399 |
395 // Doesn't matter what the socket data is, we will never use it -- garbage. | 400 // Doesn't matter what the socket data is, we will never use it -- garbage. |
396 MockWrite data_writes[] = { MockWrite(SYNCHRONOUS, "", 0) }; | 401 MockWrite data_writes[] = { MockWrite(SYNCHRONOUS, "", 0) }; |
397 MockRead data_reads[] = { MockRead(SYNCHRONOUS, "", 0) }; | 402 MockRead data_reads[] = { MockRead(SYNCHRONOUS, "", 0) }; |
398 | 403 |
399 user_sock_ = BuildMockSocket(data_reads, arraysize(data_reads), | 404 user_sock_ = BuildMockSocket(data_reads, arraysize(data_reads), |
400 data_writes, arraysize(data_writes), | 405 data_writes, arraysize(data_writes), |
401 hanging_resolver.get(), | 406 hanging_resolver.get(), |
402 "foo", 80, | 407 "foo", 80, |
403 NULL); | 408 NULL); |
404 | 409 |
405 // Start connecting (will get stuck waiting for the host to resolve). | 410 // Start connecting (will get stuck waiting for the host to resolve). |
406 int rv = user_sock_->Connect(callback_.callback()); | 411 int rv = user_sock_->Connect(callback_.callback()); |
407 EXPECT_EQ(ERR_IO_PENDING, rv); | 412 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
408 | 413 |
409 EXPECT_FALSE(user_sock_->IsConnected()); | 414 EXPECT_FALSE(user_sock_->IsConnected()); |
410 EXPECT_FALSE(user_sock_->IsConnectedAndIdle()); | 415 EXPECT_FALSE(user_sock_->IsConnectedAndIdle()); |
411 | 416 |
412 // The host resolver should have received the resolve request. | 417 // The host resolver should have received the resolve request. |
413 EXPECT_TRUE(hanging_resolver->HasOutstandingRequest()); | 418 EXPECT_TRUE(hanging_resolver->HasOutstandingRequest()); |
414 | 419 |
415 // Disconnect the SOCKS socket -- this should cancel the outstanding resolve. | 420 // Disconnect the SOCKS socket -- this should cancel the outstanding resolve. |
416 user_sock_->Disconnect(); | 421 user_sock_->Disconnect(); |
417 | 422 |
(...skipping 29 matching lines...) Expand all Loading... |
447 NULL, 0, | 452 NULL, 0, |
448 host_resolver.get(), | 453 host_resolver.get(), |
449 kHostName, 80, | 454 kHostName, 80, |
450 NULL); | 455 NULL); |
451 | 456 |
452 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, | 457 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
453 callback_.GetResult(user_sock_->Connect(callback_.callback()))); | 458 callback_.GetResult(user_sock_->Connect(callback_.callback()))); |
454 } | 459 } |
455 | 460 |
456 } // namespace net | 461 } // namespace net |
OLD | NEW |