| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/tcp_client_socket.h" | 5 #include "net/socket/tcp_client_socket.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "net/base/address_list.h" | 8 #include "net/base/address_list.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" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 int rv = resolver->Resolve(info, &addr, NULL, NULL, BoundNetLog()); | 98 int rv = resolver->Resolve(info, &addr, NULL, NULL, BoundNetLog()); |
| 99 CHECK_EQ(rv, OK); | 99 CHECK_EQ(rv, OK); |
| 100 sock_.reset(new TCPClientSocket(addr, &net_log_, NetLog::Source())); | 100 sock_.reset(new TCPClientSocket(addr, &net_log_, NetLog::Source())); |
| 101 } | 101 } |
| 102 | 102 |
| 103 TEST_F(TCPClientSocketTest, Connect) { | 103 TEST_F(TCPClientSocketTest, Connect) { |
| 104 TestCompletionCallback callback; | 104 TestCompletionCallback callback; |
| 105 EXPECT_FALSE(sock_->IsConnected()); | 105 EXPECT_FALSE(sock_->IsConnected()); |
| 106 | 106 |
| 107 int rv = sock_->Connect(&callback); | 107 int rv = sock_->Connect(&callback); |
| 108 |
| 109 net::CapturingNetLog::EntryList net_log_entries; |
| 110 net_log_.GetEntries(&net_log_entries); |
| 108 EXPECT_TRUE(net::LogContainsBeginEvent( | 111 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 109 net_log_.entries(), 0, net::NetLog::TYPE_SOCKET_ALIVE)); | 112 net_log_entries, 0, net::NetLog::TYPE_SOCKET_ALIVE)); |
| 110 EXPECT_TRUE(net::LogContainsBeginEvent( | 113 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 111 net_log_.entries(), 1, net::NetLog::TYPE_TCP_CONNECT)); | 114 net_log_entries, 1, net::NetLog::TYPE_TCP_CONNECT)); |
| 112 if (rv != OK) { | 115 if (rv != OK) { |
| 113 ASSERT_EQ(rv, ERR_IO_PENDING); | 116 ASSERT_EQ(rv, ERR_IO_PENDING); |
| 114 rv = callback.WaitForResult(); | 117 rv = callback.WaitForResult(); |
| 115 EXPECT_EQ(rv, OK); | 118 EXPECT_EQ(rv, OK); |
| 116 } | 119 } |
| 117 | 120 |
| 118 EXPECT_TRUE(sock_->IsConnected()); | 121 EXPECT_TRUE(sock_->IsConnected()); |
| 122 net_log_.GetEntries(&net_log_entries); |
| 119 EXPECT_TRUE(net::LogContainsEndEvent( | 123 EXPECT_TRUE(net::LogContainsEndEvent( |
| 120 net_log_.entries(), -1, net::NetLog::TYPE_TCP_CONNECT)); | 124 net_log_entries, -1, net::NetLog::TYPE_TCP_CONNECT)); |
| 121 | 125 |
| 122 sock_->Disconnect(); | 126 sock_->Disconnect(); |
| 123 EXPECT_FALSE(sock_->IsConnected()); | 127 EXPECT_FALSE(sock_->IsConnected()); |
| 124 } | 128 } |
| 125 | 129 |
| 126 // TODO(wtc): Add unit tests for IsConnectedAndIdle: | 130 // TODO(wtc): Add unit tests for IsConnectedAndIdle: |
| 127 // - Server closes a connection. | 131 // - Server closes a connection. |
| 128 // - Server sends data unexpectedly. | 132 // - Server sends data unexpectedly. |
| 129 | 133 |
| 130 TEST_F(TCPClientSocketTest, Read) { | 134 TEST_F(TCPClientSocketTest, Read) { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 // Close the server socket, so there will at least be a 0-byte read. | 346 // Close the server socket, so there will at least be a 0-byte read. |
| 343 CloseServerSocket(); | 347 CloseServerSocket(); |
| 344 | 348 |
| 345 rv = callback.WaitForResult(); | 349 rv = callback.WaitForResult(); |
| 346 EXPECT_GE(rv, 0); | 350 EXPECT_GE(rv, 0); |
| 347 } | 351 } |
| 348 | 352 |
| 349 } // namespace | 353 } // namespace |
| 350 | 354 |
| 351 } // namespace net | 355 } // namespace net |
| OLD | NEW |