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

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

Issue 10161005: Add DefaultListenSocket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix build on Windows Created 8 years, 7 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/server/http_server.cc ('k') | net/tools/fetch/http_listen_socket.h » ('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) 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
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 24 matching lines...) Expand all
94 private: 97 private:
95 scoped_refptr<TCPListenSocket> listen_sock_; 98 scoped_refptr<TCPListenSocket> listen_sock_;
96 scoped_refptr<TCPListenSocket> connected_sock_; 99 scoped_refptr<TCPListenSocket> connected_sock_;
97 bool close_server_socket_on_next_send_; 100 bool close_server_socket_on_next_send_;
98 }; 101 };
99 102
100 void TransportClientSocketTest::SetUp() { 103 void TransportClientSocketTest::SetUp() {
101 ::testing::TestWithParam<ClientSocketTestTypes>::SetUp(); 104 ::testing::TestWithParam<ClientSocketTestTypes>::SetUp();
102 105
103 // Find a free port to listen on 106 // Find a free port to listen on
104 TCPListenSocket *sock = NULL; 107 scoped_refptr<TCPListenSocket> sock = NULL;
105 int port; 108 int port;
106 // Range of ports to listen on. Shouldn't need to try many. 109 // Range of ports to listen on. Shouldn't need to try many.
107 const int kMinPort = 10100; 110 const int kMinPort = 10100;
108 const int kMaxPort = 10200; 111 const int kMaxPort = 10200;
109 #if defined(OS_WIN) 112 #if defined(OS_WIN)
110 EnsureWinsockInit(); 113 EnsureWinsockInit();
111 #endif 114 #endif
112 for (port = kMinPort; port < kMaxPort; port++) { 115 for (port = kMinPort; port < kMaxPort; port++) {
113 sock = TCPListenSocket::CreateAndListen("127.0.0.1", port, this); 116 sock = TCPListenSocket::CreateAndListen("127.0.0.1", port, this);
114 if (sock) 117 if (sock.get())
115 break; 118 break;
116 } 119 }
117 ASSERT_TRUE(sock != NULL); 120 ASSERT_TRUE(sock != NULL);
118 listen_sock_ = sock; 121 listen_sock_ = sock;
119 listen_port_ = port; 122 listen_port_ = port;
120 123
121 AddressList addr; 124 AddressList addr;
122 scoped_ptr<HostResolver> resolver( 125 scoped_ptr<HostResolver> resolver(
123 CreateSystemHostResolver(HostResolver::kDefaultParallelism, 126 CreateSystemHostResolver(HostResolver::kDefaultParallelism,
124 HostResolver::kDefaultRetryAttempts, 127 HostResolver::kDefaultRetryAttempts,
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « net/server/http_server.cc ('k') | net/tools/fetch/http_listen_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698