| 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/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 "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const char kServerReply[] = "HTTP/1.1 404 Not Found"; | 27 const char kServerReply[] = "HTTP/1.1 404 Not Found"; |
| 28 | 28 |
| 29 enum ClientSocketTestTypes { | 29 enum ClientSocketTestTypes { |
| 30 TCP, | 30 TCP, |
| 31 SCTP | 31 SCTP |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 } // namespace |
| 35 |
| 34 class TransportClientSocketTest | 36 class TransportClientSocketTest |
| 35 : public ListenSocket::ListenSocketDelegate, | 37 : public StreamListenSocket::Delegate, |
| 36 public ::testing::TestWithParam<ClientSocketTestTypes> { | 38 public ::testing::TestWithParam<ClientSocketTestTypes> { |
| 37 public: | 39 public: |
| 38 TransportClientSocketTest() | 40 TransportClientSocketTest() |
| 39 : listen_port_(0), | 41 : listen_port_(0), |
| 40 net_log_(CapturingNetLog::kUnbounded), | 42 net_log_(CapturingNetLog::kUnbounded), |
| 41 socket_factory_(ClientSocketFactory::GetDefaultFactory()), | 43 socket_factory_(ClientSocketFactory::GetDefaultFactory()), |
| 42 close_server_socket_on_next_send_(false) { | 44 close_server_socket_on_next_send_(false) { |
| 43 } | 45 } |
| 44 | 46 |
| 45 ~TransportClientSocketTest() { | 47 ~TransportClientSocketTest() { |
| 46 } | 48 } |
| 47 | 49 |
| 48 // Implement ListenSocketDelegate methods | 50 // Implement StreamListenSocket::Delegate methods |
| 49 virtual void DidAccept(ListenSocket* server, ListenSocket* connection) { | 51 virtual void DidAccept(StreamListenSocket* server, |
| 52 StreamListenSocket* connection) { |
| 50 connected_sock_ = reinterpret_cast<TCPListenSocket*>(connection); | 53 connected_sock_ = reinterpret_cast<TCPListenSocket*>(connection); |
| 51 } | 54 } |
| 52 virtual void DidRead(ListenSocket*, const char* str, int len) { | 55 virtual void DidRead(StreamListenSocket*, const char* str, int len) { |
| 53 // TODO(dkegel): this might not be long enough to tickle some bugs. | 56 // TODO(dkegel): this might not be long enough to tickle some bugs. |
| 54 connected_sock_->Send(kServerReply, arraysize(kServerReply) - 1, | 57 connected_sock_->Send(kServerReply, arraysize(kServerReply) - 1, |
| 55 false /* Don't append line feed */); | 58 false /* Don't append line feed */); |
| 56 if (close_server_socket_on_next_send_) | 59 if (close_server_socket_on_next_send_) |
| 57 CloseServerSocket(); | 60 CloseServerSocket(); |
| 58 } | 61 } |
| 59 virtual void DidClose(ListenSocket* sock) {} | 62 virtual void DidClose(StreamListenSocket* sock) {} |
| 60 | 63 |
| 61 // Testcase hooks | 64 // Testcase hooks |
| 62 virtual void SetUp(); | 65 virtual void SetUp(); |
| 63 | 66 |
| 64 void CloseServerSocket() { | 67 void CloseServerSocket() { |
| 65 // delete the connected_sock_, which will close it. | 68 // delete the connected_sock_, which will close it. |
| 66 connected_sock_ = NULL; | 69 connected_sock_ = NULL; |
| 67 } | 70 } |
| 68 | 71 |
| 69 void PauseServerReads() { | 72 void PauseServerReads() { |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 EXPECT_GE(rv, 0); | 441 EXPECT_GE(rv, 0); |
| 439 | 442 |
| 440 // It's possible the read is blocked because it's already read all the data. | 443 // It's possible the read is blocked because it's already read all the data. |
| 441 // Close the server socket, so there will at least be a 0-byte read. | 444 // Close the server socket, so there will at least be a 0-byte read. |
| 442 CloseServerSocket(); | 445 CloseServerSocket(); |
| 443 | 446 |
| 444 rv = callback.WaitForResult(); | 447 rv = callback.WaitForResult(); |
| 445 EXPECT_GE(rv, 0); | 448 EXPECT_GE(rv, 0); |
| 446 } | 449 } |
| 447 | 450 |
| 448 } // namespace | |
| 449 | |
| 450 } // namespace net | 451 } // namespace net |
| OLD | NEW |