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

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

Issue 451383002: Plumbing for TCP FastOpen for SSL sockets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tests now working as intended. Created 6 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/transport_client_socket_pool_test_util.h" 5 #include "net/socket/transport_client_socket_pool_test_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 16 matching lines...) Expand all
27 CHECK(ParseIPLiteralToNumber(ip, &number)); 27 CHECK(ParseIPLiteralToNumber(ip, &number));
28 return number; 28 return number;
29 } 29 }
30 30
31 // A StreamSocket which connects synchronously and successfully. 31 // A StreamSocket which connects synchronously and successfully.
32 class MockConnectClientSocket : public StreamSocket { 32 class MockConnectClientSocket : public StreamSocket {
33 public: 33 public:
34 MockConnectClientSocket(const AddressList& addrlist, net::NetLog* net_log) 34 MockConnectClientSocket(const AddressList& addrlist, net::NetLog* net_log)
35 : connected_(false), 35 : connected_(false),
36 addrlist_(addrlist), 36 addrlist_(addrlist),
37 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) {} 37 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)),
38 use_tcp_fastopen_(false) {}
38 39
39 // StreamSocket implementation. 40 // StreamSocket implementation.
40 virtual int Connect(const CompletionCallback& callback) OVERRIDE { 41 virtual int Connect(const CompletionCallback& callback) OVERRIDE {
41 connected_ = true; 42 connected_ = true;
42 return OK; 43 return OK;
43 } 44 }
44 virtual void Disconnect() OVERRIDE { connected_ = false; } 45 virtual void Disconnect() OVERRIDE { connected_ = false; }
45 virtual bool IsConnected() const OVERRIDE { return connected_; } 46 virtual bool IsConnected() const OVERRIDE { return connected_; }
46 virtual bool IsConnectedAndIdle() const OVERRIDE { return connected_; } 47 virtual bool IsConnectedAndIdle() const OVERRIDE { return connected_; }
47 48
48 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE { 49 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE {
49 *address = addrlist_.front(); 50 *address = addrlist_.front();
50 return OK; 51 return OK;
51 } 52 }
52 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE { 53 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE {
53 if (!connected_) 54 if (!connected_)
54 return ERR_SOCKET_NOT_CONNECTED; 55 return ERR_SOCKET_NOT_CONNECTED;
55 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4) 56 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4)
56 SetIPv4Address(address); 57 SetIPv4Address(address);
57 else 58 else
58 SetIPv6Address(address); 59 SetIPv6Address(address);
59 return OK; 60 return OK;
60 } 61 }
61 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; } 62 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; }
62 63
63 virtual void SetSubresourceSpeculation() OVERRIDE {} 64 virtual void SetSubresourceSpeculation() OVERRIDE {}
64 virtual void SetOmniboxSpeculation() OVERRIDE {} 65 virtual void SetOmniboxSpeculation() OVERRIDE {}
65 virtual bool WasEverUsed() const OVERRIDE { return false; } 66 virtual bool WasEverUsed() const OVERRIDE { return false; }
66 virtual bool UsingTCPFastOpen() const OVERRIDE { return false; } 67 virtual void EnableTCPFastOpen() OVERRIDE { use_tcp_fastopen_ = true; }
68 virtual bool UsingTCPFastOpen() const OVERRIDE { return use_tcp_fastopen_; }
67 virtual bool WasNpnNegotiated() const OVERRIDE { return false; } 69 virtual bool WasNpnNegotiated() const OVERRIDE { return false; }
68 virtual NextProto GetNegotiatedProtocol() const OVERRIDE { 70 virtual NextProto GetNegotiatedProtocol() const OVERRIDE {
69 return kProtoUnknown; 71 return kProtoUnknown;
70 } 72 }
71 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; } 73 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; }
72 74
73 // Socket implementation. 75 // Socket implementation.
74 virtual int Read(IOBuffer* buf, 76 virtual int Read(IOBuffer* buf,
75 int buf_len, 77 int buf_len,
76 const CompletionCallback& callback) OVERRIDE { 78 const CompletionCallback& callback) OVERRIDE {
77 return ERR_FAILED; 79 return ERR_FAILED;
78 } 80 }
79 virtual int Write(IOBuffer* buf, 81 virtual int Write(IOBuffer* buf,
80 int buf_len, 82 int buf_len,
81 const CompletionCallback& callback) OVERRIDE { 83 const CompletionCallback& callback) OVERRIDE {
82 return ERR_FAILED; 84 return ERR_FAILED;
83 } 85 }
84 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { return OK; } 86 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { return OK; }
85 virtual int SetSendBufferSize(int32 size) OVERRIDE { return OK; } 87 virtual int SetSendBufferSize(int32 size) OVERRIDE { return OK; }
86 88
87 private: 89 private:
88 bool connected_; 90 bool connected_;
89 const AddressList addrlist_; 91 const AddressList addrlist_;
90 BoundNetLog net_log_; 92 BoundNetLog net_log_;
93 bool use_tcp_fastopen_;
91 94
92 DISALLOW_COPY_AND_ASSIGN(MockConnectClientSocket); 95 DISALLOW_COPY_AND_ASSIGN(MockConnectClientSocket);
93 }; 96 };
94 97
95 class MockFailingClientSocket : public StreamSocket { 98 class MockFailingClientSocket : public StreamSocket {
96 public: 99 public:
97 MockFailingClientSocket(const AddressList& addrlist, net::NetLog* net_log) 100 MockFailingClientSocket(const AddressList& addrlist, net::NetLog* net_log)
98 : addrlist_(addrlist), 101 : addrlist_(addrlist),
99 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) {} 102 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)),
103 use_tcp_fastopen_(false) {}
100 104
101 // StreamSocket implementation. 105 // StreamSocket implementation.
102 virtual int Connect(const CompletionCallback& callback) OVERRIDE { 106 virtual int Connect(const CompletionCallback& callback) OVERRIDE {
103 return ERR_CONNECTION_FAILED; 107 return ERR_CONNECTION_FAILED;
104 } 108 }
105 109
106 virtual void Disconnect() OVERRIDE {} 110 virtual void Disconnect() OVERRIDE {}
107 111
108 virtual bool IsConnected() const OVERRIDE { return false; } 112 virtual bool IsConnected() const OVERRIDE { return false; }
109 virtual bool IsConnectedAndIdle() const OVERRIDE { return false; } 113 virtual bool IsConnectedAndIdle() const OVERRIDE { return false; }
110 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE { 114 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE {
111 return ERR_UNEXPECTED; 115 return ERR_UNEXPECTED;
112 } 116 }
113 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE { 117 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE {
114 return ERR_UNEXPECTED; 118 return ERR_UNEXPECTED;
115 } 119 }
116 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; } 120 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; }
117 121
118 virtual void SetSubresourceSpeculation() OVERRIDE {} 122 virtual void SetSubresourceSpeculation() OVERRIDE {}
119 virtual void SetOmniboxSpeculation() OVERRIDE {} 123 virtual void SetOmniboxSpeculation() OVERRIDE {}
120 virtual bool WasEverUsed() const OVERRIDE { return false; } 124 virtual bool WasEverUsed() const OVERRIDE { return false; }
121 virtual bool UsingTCPFastOpen() const OVERRIDE { return false; } 125 virtual void EnableTCPFastOpen() OVERRIDE { use_tcp_fastopen_ = true; }
126 virtual bool UsingTCPFastOpen() const OVERRIDE { return use_tcp_fastopen_; }
122 virtual bool WasNpnNegotiated() const OVERRIDE { return false; } 127 virtual bool WasNpnNegotiated() const OVERRIDE { return false; }
123 virtual NextProto GetNegotiatedProtocol() const OVERRIDE { 128 virtual NextProto GetNegotiatedProtocol() const OVERRIDE {
124 return kProtoUnknown; 129 return kProtoUnknown;
125 } 130 }
126 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; } 131 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; }
127 132
128 // Socket implementation. 133 // Socket implementation.
129 virtual int Read(IOBuffer* buf, 134 virtual int Read(IOBuffer* buf,
130 int buf_len, 135 int buf_len,
131 const CompletionCallback& callback) OVERRIDE { 136 const CompletionCallback& callback) OVERRIDE {
132 return ERR_FAILED; 137 return ERR_FAILED;
133 } 138 }
134 139
135 virtual int Write(IOBuffer* buf, 140 virtual int Write(IOBuffer* buf,
136 int buf_len, 141 int buf_len,
137 const CompletionCallback& callback) OVERRIDE { 142 const CompletionCallback& callback) OVERRIDE {
138 return ERR_FAILED; 143 return ERR_FAILED;
139 } 144 }
140 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { return OK; } 145 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { return OK; }
141 virtual int SetSendBufferSize(int32 size) OVERRIDE { return OK; } 146 virtual int SetSendBufferSize(int32 size) OVERRIDE { return OK; }
142 147
143 private: 148 private:
144 const AddressList addrlist_; 149 const AddressList addrlist_;
145 BoundNetLog net_log_; 150 BoundNetLog net_log_;
151 bool use_tcp_fastopen_;
146 152
147 DISALLOW_COPY_AND_ASSIGN(MockFailingClientSocket); 153 DISALLOW_COPY_AND_ASSIGN(MockFailingClientSocket);
148 }; 154 };
149 155
150 class MockTriggerableClientSocket : public StreamSocket { 156 class MockTriggerableClientSocket : public StreamSocket {
151 public: 157 public:
152 // |should_connect| indicates whether the socket should successfully complete 158 // |should_connect| indicates whether the socket should successfully complete
153 // or fail. 159 // or fail.
154 MockTriggerableClientSocket(const AddressList& addrlist, 160 MockTriggerableClientSocket(const AddressList& addrlist,
155 bool should_connect, 161 bool should_connect,
156 net::NetLog* net_log) 162 net::NetLog* net_log)
157 : should_connect_(should_connect), 163 : should_connect_(should_connect),
158 is_connected_(false), 164 is_connected_(false),
159 addrlist_(addrlist), 165 addrlist_(addrlist),
160 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)), 166 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)),
167 use_tcp_fastopen_(false),
161 weak_factory_(this) {} 168 weak_factory_(this) {}
162 169
163 // Call this method to get a closure which will trigger the connect callback 170 // Call this method to get a closure which will trigger the connect callback
164 // when called. The closure can be called even after the socket is deleted; it 171 // when called. The closure can be called even after the socket is deleted; it
165 // will safely do nothing. 172 // will safely do nothing.
166 base::Closure GetConnectCallback() { 173 base::Closure GetConnectCallback() {
167 return base::Bind(&MockTriggerableClientSocket::DoCallback, 174 return base::Bind(&MockTriggerableClientSocket::DoCallback,
168 weak_factory_.GetWeakPtr()); 175 weak_factory_.GetWeakPtr());
169 } 176 }
170 177
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 SetIPv4Address(address); 228 SetIPv4Address(address);
222 else 229 else
223 SetIPv6Address(address); 230 SetIPv6Address(address);
224 return OK; 231 return OK;
225 } 232 }
226 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; } 233 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; }
227 234
228 virtual void SetSubresourceSpeculation() OVERRIDE {} 235 virtual void SetSubresourceSpeculation() OVERRIDE {}
229 virtual void SetOmniboxSpeculation() OVERRIDE {} 236 virtual void SetOmniboxSpeculation() OVERRIDE {}
230 virtual bool WasEverUsed() const OVERRIDE { return false; } 237 virtual bool WasEverUsed() const OVERRIDE { return false; }
231 virtual bool UsingTCPFastOpen() const OVERRIDE { return false; } 238 virtual void EnableTCPFastOpen() OVERRIDE { use_tcp_fastopen_ = true; }
239 virtual bool UsingTCPFastOpen() const OVERRIDE { return use_tcp_fastopen_; }
232 virtual bool WasNpnNegotiated() const OVERRIDE { return false; } 240 virtual bool WasNpnNegotiated() const OVERRIDE { return false; }
233 virtual NextProto GetNegotiatedProtocol() const OVERRIDE { 241 virtual NextProto GetNegotiatedProtocol() const OVERRIDE {
234 return kProtoUnknown; 242 return kProtoUnknown;
235 } 243 }
236 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; } 244 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; }
237 245
238 // Socket implementation. 246 // Socket implementation.
239 virtual int Read(IOBuffer* buf, 247 virtual int Read(IOBuffer* buf,
240 int buf_len, 248 int buf_len,
241 const CompletionCallback& callback) OVERRIDE { 249 const CompletionCallback& callback) OVERRIDE {
(...skipping 12 matching lines...) Expand all
254 void DoCallback() { 262 void DoCallback() {
255 is_connected_ = should_connect_; 263 is_connected_ = should_connect_;
256 callback_.Run(is_connected_ ? OK : ERR_CONNECTION_FAILED); 264 callback_.Run(is_connected_ ? OK : ERR_CONNECTION_FAILED);
257 } 265 }
258 266
259 bool should_connect_; 267 bool should_connect_;
260 bool is_connected_; 268 bool is_connected_;
261 const AddressList addrlist_; 269 const AddressList addrlist_;
262 BoundNetLog net_log_; 270 BoundNetLog net_log_;
263 CompletionCallback callback_; 271 CompletionCallback callback_;
272 bool use_tcp_fastopen_;
264 273
265 base::WeakPtrFactory<MockTriggerableClientSocket> weak_factory_; 274 base::WeakPtrFactory<MockTriggerableClientSocket> weak_factory_;
266 275
267 DISALLOW_COPY_AND_ASSIGN(MockTriggerableClientSocket); 276 DISALLOW_COPY_AND_ASSIGN(MockTriggerableClientSocket);
268 }; 277 };
269 278
270 } // namespace 279 } // namespace
271 280
272 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) { 281 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) {
273 LoadTimingInfo load_timing_info; 282 LoadTimingInfo load_timing_info;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 run_loop_quit_closure_ = run_loop.QuitClosure(); 421 run_loop_quit_closure_ = run_loop.QuitClosure();
413 run_loop.Run(); 422 run_loop.Run();
414 run_loop_quit_closure_.Reset(); 423 run_loop_quit_closure_.Reset();
415 } 424 }
416 base::Closure trigger = triggerable_sockets_.front(); 425 base::Closure trigger = triggerable_sockets_.front();
417 triggerable_sockets_.pop(); 426 triggerable_sockets_.pop();
418 return trigger; 427 return trigger;
419 } 428 }
420 429
421 } // namespace net 430 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698