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/spdy/spdy_proxy_client_socket.h" | 5 #include "net/spdy/spdy_proxy_client_socket.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
11 #include "net/base/net_log.h" | 11 #include "net/base/net_log.h" |
12 #include "net/base/net_log_unittest.h" | 12 #include "net/base/net_log_unittest.h" |
13 #include "net/base/mock_host_resolver.h" | 13 #include "net/base/mock_host_resolver.h" |
14 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
15 #include "net/base/winsock_init.h" | 15 #include "net/base/winsock_init.h" |
16 #include "net/http/http_response_info.h" | 16 #include "net/http/http_response_info.h" |
17 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
18 #include "net/socket/client_socket_factory.h" | 18 #include "net/socket/client_socket_factory.h" |
19 #include "net/socket/tcp_client_socket.h" | 19 #include "net/socket/tcp_client_socket.h" |
20 #include "net/socket/socket_test_util.h" | 20 #include "net/socket/socket_test_util.h" |
21 #include "net/spdy/spdy_http_utils.h" | 21 #include "net/spdy/spdy_http_utils.h" |
22 #include "net/spdy/spdy_protocol.h" | 22 #include "net/spdy/spdy_protocol.h" |
23 #include "net/spdy/spdy_session_pool.h" | 23 #include "net/spdy/spdy_session_pool.h" |
24 #include "net/spdy/spdy_test_util.h" | 24 #include "net/spdy/spdy_test_util_spdy3.h" |
25 #include "testing/platform_test.h" | 25 #include "testing/platform_test.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
27 | 27 |
| 28 using namespace net::test_spdy3; |
| 29 |
28 //----------------------------------------------------------------------------- | 30 //----------------------------------------------------------------------------- |
29 | 31 |
30 namespace { | 32 namespace { |
31 | 33 |
32 static const char kUrl[] = "https://www.google.com/"; | 34 static const char kUrl[] = "https://www.google.com/"; |
33 static const char kOriginHost[] = "www.google.com"; | 35 static const char kOriginHost[] = "www.google.com"; |
34 static const int kOriginPort = 443; | 36 static const int kOriginPort = 443; |
35 static const char kOriginHostPort[] = "www.google.com:443"; | 37 static const char kOriginHostPort[] = "www.google.com:443"; |
36 static const char kProxyUrl[] = "https://myproxy:6121/"; | 38 static const char kProxyUrl[] = "https://myproxy:6121/"; |
37 static const char kProxyHost[] = "myproxy"; | 39 static const char kProxyHost[] = "myproxy"; |
(...skipping 10 matching lines...) Expand all Loading... |
48 static const int kLen3 = 4; | 50 static const int kLen3 = 4; |
49 static const char kMsg33[] = "bye!bye!"; | 51 static const char kMsg33[] = "bye!bye!"; |
50 static const int kLen33 = kLen3 + kLen3; | 52 static const int kLen33 = kLen3 + kLen3; |
51 static const char kMsg333[] = "bye!bye!bye!"; | 53 static const char kMsg333[] = "bye!bye!bye!"; |
52 static const int kLen333 = kLen3 + kLen3 + kLen3; | 54 static const int kLen333 = kLen3 + kLen3 + kLen3; |
53 | 55 |
54 } // anonymous namespace | 56 } // anonymous namespace |
55 | 57 |
56 namespace net { | 58 namespace net { |
57 | 59 |
58 class SpdyProxyClientSocketTest : public PlatformTest { | 60 class SpdyProxyClientSocketSpdy3Test : public PlatformTest { |
59 public: | 61 public: |
60 SpdyProxyClientSocketTest(); | 62 SpdyProxyClientSocketSpdy3Test(); |
61 | 63 |
62 virtual void TearDown(); | 64 virtual void TearDown(); |
63 | 65 |
64 protected: | 66 protected: |
65 void Initialize(MockRead* reads, size_t reads_count, MockWrite* writes, | 67 void Initialize(MockRead* reads, size_t reads_count, MockWrite* writes, |
66 size_t writes_count); | 68 size_t writes_count); |
67 spdy::SpdyFrame* ConstructConnectRequestFrame(); | 69 spdy::SpdyFrame* ConstructConnectRequestFrame(); |
68 spdy::SpdyFrame* ConstructConnectAuthRequestFrame(); | 70 spdy::SpdyFrame* ConstructConnectAuthRequestFrame(); |
69 spdy::SpdyFrame* ConstructConnectReplyFrame(); | 71 spdy::SpdyFrame* ConstructConnectReplyFrame(); |
70 spdy::SpdyFrame* ConstructConnectAuthReplyFrame(); | 72 spdy::SpdyFrame* ConstructConnectAuthReplyFrame(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 spdy::SpdyFramer framer_; | 117 spdy::SpdyFramer framer_; |
116 | 118 |
117 std::string user_agent_; | 119 std::string user_agent_; |
118 GURL url_; | 120 GURL url_; |
119 HostPortPair proxy_host_port_; | 121 HostPortPair proxy_host_port_; |
120 HostPortPair endpoint_host_port_pair_; | 122 HostPortPair endpoint_host_port_pair_; |
121 ProxyServer proxy_; | 123 ProxyServer proxy_; |
122 HostPortProxyPair endpoint_host_port_proxy_pair_; | 124 HostPortProxyPair endpoint_host_port_proxy_pair_; |
123 scoped_refptr<TransportSocketParams> transport_params_; | 125 scoped_refptr<TransportSocketParams> transport_params_; |
124 | 126 |
125 DISALLOW_COPY_AND_ASSIGN(SpdyProxyClientSocketTest); | 127 DISALLOW_COPY_AND_ASSIGN(SpdyProxyClientSocketSpdy3Test); |
126 }; | 128 }; |
127 | 129 |
128 SpdyProxyClientSocketTest::SpdyProxyClientSocketTest() | 130 SpdyProxyClientSocketSpdy3Test::SpdyProxyClientSocketSpdy3Test() |
129 : sock_(NULL), | 131 : sock_(NULL), |
130 data_(NULL), | 132 data_(NULL), |
131 session_(NULL), | 133 session_(NULL), |
132 read_buf_(NULL), | 134 read_buf_(NULL), |
133 session_deps_(), | 135 session_deps_(), |
134 connect_data_(SYNCHRONOUS, OK), | 136 connect_data_(SYNCHRONOUS, OK), |
135 spdy_session_(NULL), | 137 spdy_session_(NULL), |
136 spdy_stream_(NULL), | 138 spdy_stream_(NULL), |
137 framer_(), | 139 framer_(), |
138 user_agent_(kUserAgent), | 140 user_agent_(kUserAgent), |
139 url_(kUrl), | 141 url_(kUrl), |
140 proxy_host_port_(kProxyHost, kProxyPort), | 142 proxy_host_port_(kProxyHost, kProxyPort), |
141 endpoint_host_port_pair_(kOriginHost, kOriginPort), | 143 endpoint_host_port_pair_(kOriginHost, kOriginPort), |
142 proxy_(ProxyServer::SCHEME_HTTPS, proxy_host_port_), | 144 proxy_(ProxyServer::SCHEME_HTTPS, proxy_host_port_), |
143 endpoint_host_port_proxy_pair_(endpoint_host_port_pair_, proxy_), | 145 endpoint_host_port_proxy_pair_(endpoint_host_port_pair_, proxy_), |
144 transport_params_(new TransportSocketParams(proxy_host_port_, | 146 transport_params_(new TransportSocketParams(proxy_host_port_, |
145 LOWEST, | 147 LOWEST, |
146 false, | 148 false, |
147 false)) { | 149 false)) { |
148 } | 150 } |
149 | 151 |
150 void SpdyProxyClientSocketTest::TearDown() { | 152 void SpdyProxyClientSocketSpdy3Test::TearDown() { |
151 sock_.reset(NULL); | 153 sock_.reset(NULL); |
152 if (session_ != NULL) | 154 if (session_ != NULL) |
153 session_->spdy_session_pool()->CloseAllSessions(); | 155 session_->spdy_session_pool()->CloseAllSessions(); |
154 | 156 |
155 spdy::SpdyFramer::set_enable_compression_default(true); | 157 spdy::SpdyFramer::set_enable_compression_default(true); |
156 // Empty the current queue. | 158 // Empty the current queue. |
157 MessageLoop::current()->RunAllPending(); | 159 MessageLoop::current()->RunAllPending(); |
158 PlatformTest::TearDown(); | 160 PlatformTest::TearDown(); |
159 } | 161 } |
160 | 162 |
161 void SpdyProxyClientSocketTest::Initialize(MockRead* reads, | 163 void SpdyProxyClientSocketSpdy3Test::Initialize(MockRead* reads, |
162 size_t reads_count, | 164 size_t reads_count, |
163 MockWrite* writes, | 165 MockWrite* writes, |
164 size_t writes_count) { | 166 size_t writes_count) { |
165 data_ = new DeterministicSocketData(reads, reads_count, writes, writes_count); | 167 data_ = new DeterministicSocketData(reads, reads_count, writes, writes_count); |
166 data_->set_connect_data(connect_data_); | 168 data_->set_connect_data(connect_data_); |
167 data_->SetStop(2); | 169 data_->SetStop(2); |
168 | 170 |
169 session_deps_.deterministic_socket_factory->AddSocketDataProvider( | 171 session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
170 data_.get()); | 172 data_.get()); |
171 session_deps_.host_resolver->set_synchronous_mode(true); | 173 session_deps_.host_resolver->set_synchronous_mode(true); |
(...skipping 24 matching lines...) Expand all Loading... |
196 CompletionCallback())); | 198 CompletionCallback())); |
197 | 199 |
198 // Create the SpdyProxyClientSocket | 200 // Create the SpdyProxyClientSocket |
199 sock_.reset( | 201 sock_.reset( |
200 new SpdyProxyClientSocket(spdy_stream_, user_agent_, | 202 new SpdyProxyClientSocket(spdy_stream_, user_agent_, |
201 endpoint_host_port_pair_, url_, | 203 endpoint_host_port_pair_, url_, |
202 proxy_host_port_, session_->http_auth_cache(), | 204 proxy_host_port_, session_->http_auth_cache(), |
203 session_->http_auth_handler_factory())); | 205 session_->http_auth_handler_factory())); |
204 } | 206 } |
205 | 207 |
206 scoped_refptr<IOBufferWithSize> SpdyProxyClientSocketTest::CreateBuffer( | 208 scoped_refptr<IOBufferWithSize> SpdyProxyClientSocketSpdy3Test::CreateBuffer( |
207 const char* data, int size) { | 209 const char* data, int size) { |
208 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(size)); | 210 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(size)); |
209 memcpy(buf->data(), data, size); | 211 memcpy(buf->data(), data, size); |
210 return buf; | 212 return buf; |
211 } | 213 } |
212 | 214 |
213 void SpdyProxyClientSocketTest::AssertConnectSucceeds() { | 215 void SpdyProxyClientSocketSpdy3Test::AssertConnectSucceeds() { |
214 ASSERT_EQ(ERR_IO_PENDING, sock_->Connect(read_callback_.callback())); | 216 ASSERT_EQ(ERR_IO_PENDING, sock_->Connect(read_callback_.callback())); |
215 data_->Run(); | 217 data_->Run(); |
216 ASSERT_EQ(OK, read_callback_.WaitForResult()); | 218 ASSERT_EQ(OK, read_callback_.WaitForResult()); |
217 } | 219 } |
218 | 220 |
219 void SpdyProxyClientSocketTest::AssertConnectFails(int result) { | 221 void SpdyProxyClientSocketSpdy3Test::AssertConnectFails(int result) { |
220 ASSERT_EQ(ERR_IO_PENDING, sock_->Connect(read_callback_.callback())); | 222 ASSERT_EQ(ERR_IO_PENDING, sock_->Connect(read_callback_.callback())); |
221 data_->Run(); | 223 data_->Run(); |
222 ASSERT_EQ(result, read_callback_.WaitForResult()); | 224 ASSERT_EQ(result, read_callback_.WaitForResult()); |
223 } | 225 } |
224 | 226 |
225 void SpdyProxyClientSocketTest::AssertConnectionEstablished() { | 227 void SpdyProxyClientSocketSpdy3Test::AssertConnectionEstablished() { |
226 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); | 228 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); |
227 ASSERT_TRUE(response != NULL); | 229 ASSERT_TRUE(response != NULL); |
228 ASSERT_EQ(200, response->headers->response_code()); | 230 ASSERT_EQ(200, response->headers->response_code()); |
229 ASSERT_EQ("Connection Established", response->headers->GetStatusText()); | 231 ASSERT_EQ("Connection Established", response->headers->GetStatusText()); |
230 } | 232 } |
231 | 233 |
232 void SpdyProxyClientSocketTest::AssertSyncReadEquals(const char* data, | 234 void SpdyProxyClientSocketSpdy3Test::AssertSyncReadEquals(const char* data, |
233 int len) { | 235 int len) { |
234 scoped_refptr<IOBuffer> buf(new IOBuffer(len)); | 236 scoped_refptr<IOBuffer> buf(new IOBuffer(len)); |
235 ASSERT_EQ(len, sock_->Read(buf, len, CompletionCallback())); | 237 ASSERT_EQ(len, sock_->Read(buf, len, CompletionCallback())); |
236 ASSERT_EQ(std::string(data, len), std::string(buf->data(), len)); | 238 ASSERT_EQ(std::string(data, len), std::string(buf->data(), len)); |
237 ASSERT_TRUE(sock_->IsConnected()); | 239 ASSERT_TRUE(sock_->IsConnected()); |
238 } | 240 } |
239 | 241 |
240 void SpdyProxyClientSocketTest::AssertAsyncReadEquals(const char* data, | 242 void SpdyProxyClientSocketSpdy3Test::AssertAsyncReadEquals(const char* data, |
241 int len) { | 243 int len) { |
242 data_->StopAfter(1); | 244 data_->StopAfter(1); |
243 // Issue the read, which will be completed asynchronously | 245 // Issue the read, which will be completed asynchronously |
244 scoped_refptr<IOBuffer> buf(new IOBuffer(len)); | 246 scoped_refptr<IOBuffer> buf(new IOBuffer(len)); |
245 ASSERT_EQ(ERR_IO_PENDING, sock_->Read(buf, len, read_callback_.callback())); | 247 ASSERT_EQ(ERR_IO_PENDING, sock_->Read(buf, len, read_callback_.callback())); |
246 EXPECT_TRUE(sock_->IsConnected()); | 248 EXPECT_TRUE(sock_->IsConnected()); |
247 data_->Run(); | 249 data_->Run(); |
248 | 250 |
249 EXPECT_TRUE(sock_->IsConnected()); | 251 EXPECT_TRUE(sock_->IsConnected()); |
250 | 252 |
251 // Now the read will return | 253 // Now the read will return |
252 EXPECT_EQ(len, read_callback_.WaitForResult()); | 254 EXPECT_EQ(len, read_callback_.WaitForResult()); |
253 ASSERT_EQ(std::string(data, len), std::string(buf->data(), len)); | 255 ASSERT_EQ(std::string(data, len), std::string(buf->data(), len)); |
254 } | 256 } |
255 | 257 |
256 void SpdyProxyClientSocketTest::AssertReadStarts(const char* data, int len) { | 258 void SpdyProxyClientSocketSpdy3Test::AssertReadStarts(const char* data, |
| 259 int len) { |
257 data_->StopAfter(1); | 260 data_->StopAfter(1); |
258 // Issue the read, which will be completed asynchronously | 261 // Issue the read, which will be completed asynchronously |
259 read_buf_ = new IOBuffer(len); | 262 read_buf_ = new IOBuffer(len); |
260 ASSERT_EQ(ERR_IO_PENDING, | 263 ASSERT_EQ(ERR_IO_PENDING, |
261 sock_->Read(read_buf_, len, read_callback_.callback())); | 264 sock_->Read(read_buf_, len, read_callback_.callback())); |
262 EXPECT_TRUE(sock_->IsConnected()); | 265 EXPECT_TRUE(sock_->IsConnected()); |
263 } | 266 } |
264 | 267 |
265 void SpdyProxyClientSocketTest::AssertReadReturns(const char* data, int len) { | 268 void SpdyProxyClientSocketSpdy3Test::AssertReadReturns(const char* data, |
| 269 int len) { |
266 EXPECT_TRUE(sock_->IsConnected()); | 270 EXPECT_TRUE(sock_->IsConnected()); |
267 | 271 |
268 // Now the read will return | 272 // Now the read will return |
269 EXPECT_EQ(len, read_callback_.WaitForResult()); | 273 EXPECT_EQ(len, read_callback_.WaitForResult()); |
270 ASSERT_EQ(std::string(data, len), std::string(read_buf_->data(), len)); | 274 ASSERT_EQ(std::string(data, len), std::string(read_buf_->data(), len)); |
271 } | 275 } |
272 | 276 |
273 void SpdyProxyClientSocketTest::AssertAsyncWriteSucceeds(const char* data, | 277 void SpdyProxyClientSocketSpdy3Test::AssertAsyncWriteSucceeds(const char* data, |
274 int len) { | 278 int len) { |
275 AssertWriteReturns(data, len, ERR_IO_PENDING); | 279 AssertWriteReturns(data, len, ERR_IO_PENDING); |
276 data_->RunFor(1); | 280 data_->RunFor(1); |
277 AssertWriteLength(len); | 281 AssertWriteLength(len); |
278 } | 282 } |
279 | 283 |
280 void SpdyProxyClientSocketTest::AssertWriteReturns(const char* data, int len, | 284 void SpdyProxyClientSocketSpdy3Test::AssertWriteReturns(const char* data, |
281 int rv) { | 285 int len, |
| 286 int rv) { |
282 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(data, len)); | 287 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(data, len)); |
283 EXPECT_EQ(rv, sock_->Write(buf, buf->size(), write_callback_.callback())); | 288 EXPECT_EQ(rv, sock_->Write(buf, buf->size(), write_callback_.callback())); |
284 } | 289 } |
285 | 290 |
286 void SpdyProxyClientSocketTest::AssertWriteLength(int len) { | 291 void SpdyProxyClientSocketSpdy3Test::AssertWriteLength(int len) { |
287 EXPECT_EQ(len, write_callback_.WaitForResult()); | 292 EXPECT_EQ(len, write_callback_.WaitForResult()); |
288 } | 293 } |
289 | 294 |
290 void SpdyProxyClientSocketTest::AssertAsyncWriteWithReadsSucceeds( | 295 void SpdyProxyClientSocketSpdy3Test::AssertAsyncWriteWithReadsSucceeds( |
291 const char* data, int len, int num_reads) { | 296 const char* data, int len, int num_reads) { |
292 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(data, len)); | 297 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(data, len)); |
293 | 298 |
294 EXPECT_EQ(ERR_IO_PENDING, sock_->Write(buf, buf->size(), | 299 EXPECT_EQ(ERR_IO_PENDING, sock_->Write(buf, buf->size(), |
295 write_callback_.callback())); | 300 write_callback_.callback())); |
296 | 301 |
297 for (int i = 0; i < num_reads; i++) { | 302 for (int i = 0; i < num_reads; i++) { |
298 Run(1); | 303 Run(1); |
299 AssertSyncReadEquals(kMsg2, kLen2); | 304 AssertSyncReadEquals(kMsg2, kLen2); |
300 } | 305 } |
301 | 306 |
302 write_callback_.WaitForResult(); | 307 write_callback_.WaitForResult(); |
303 } | 308 } |
304 | 309 |
305 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. | 310 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. |
306 spdy::SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectRequestFrame() { | 311 spdy::SpdyFrame* |
| 312 SpdyProxyClientSocketSpdy3Test::ConstructConnectRequestFrame() { |
307 const SpdyHeaderInfo kSynStartHeader = { | 313 const SpdyHeaderInfo kSynStartHeader = { |
308 spdy::SYN_STREAM, | 314 spdy::SYN_STREAM, |
309 kStreamId, | 315 kStreamId, |
310 0, | 316 0, |
311 net::ConvertRequestPriorityToSpdyPriority(LOWEST), | 317 net::ConvertRequestPriorityToSpdyPriority(LOWEST), |
312 spdy::CONTROL_FLAG_NONE, | 318 spdy::CONTROL_FLAG_NONE, |
313 false, | 319 false, |
314 spdy::INVALID, | 320 spdy::INVALID, |
315 NULL, | 321 NULL, |
316 0, | 322 0, |
317 spdy::DATA_FLAG_NONE | 323 spdy::DATA_FLAG_NONE |
318 }; | 324 }; |
319 const char* const kConnectHeaders[] = { | 325 const char* const kConnectHeaders[] = { |
320 "method", "CONNECT", | 326 "method", "CONNECT", |
321 "url", kOriginHostPort, | 327 "url", kOriginHostPort, |
322 "host", kOriginHost, | 328 "host", kOriginHost, |
323 "user-agent", kUserAgent, | 329 "user-agent", kUserAgent, |
324 "version", "HTTP/1.1", | 330 "version", "HTTP/1.1", |
325 }; | 331 }; |
326 return ConstructSpdyPacket( | 332 return ConstructSpdyPacket( |
327 kSynStartHeader, NULL, 0, kConnectHeaders, arraysize(kConnectHeaders)/2); | 333 kSynStartHeader, NULL, 0, kConnectHeaders, arraysize(kConnectHeaders)/2); |
328 } | 334 } |
329 | 335 |
330 // Constructs a SPDY SYN_STREAM frame for a CONNECT request which includes | 336 // Constructs a SPDY SYN_STREAM frame for a CONNECT request which includes |
331 // Proxy-Authorization headers. | 337 // Proxy-Authorization headers. |
332 spdy::SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthRequestFrame() { | 338 spdy::SpdyFrame* |
| 339 SpdyProxyClientSocketSpdy3Test::ConstructConnectAuthRequestFrame() { |
333 const SpdyHeaderInfo kSynStartHeader = { | 340 const SpdyHeaderInfo kSynStartHeader = { |
334 spdy::SYN_STREAM, | 341 spdy::SYN_STREAM, |
335 kStreamId, | 342 kStreamId, |
336 0, | 343 0, |
337 net::ConvertRequestPriorityToSpdyPriority(LOWEST), | 344 net::ConvertRequestPriorityToSpdyPriority(LOWEST), |
338 spdy::CONTROL_FLAG_NONE, | 345 spdy::CONTROL_FLAG_NONE, |
339 false, | 346 false, |
340 spdy::INVALID, | 347 spdy::INVALID, |
341 NULL, | 348 NULL, |
342 0, | 349 0, |
343 spdy::DATA_FLAG_NONE | 350 spdy::DATA_FLAG_NONE |
344 }; | 351 }; |
345 const char* const kConnectHeaders[] = { | 352 const char* const kConnectHeaders[] = { |
346 "method", "CONNECT", | 353 "method", "CONNECT", |
347 "url", kOriginHostPort, | 354 "url", kOriginHostPort, |
348 "host", kOriginHost, | 355 "host", kOriginHost, |
349 "user-agent", kUserAgent, | 356 "user-agent", kUserAgent, |
350 "version", "HTTP/1.1", | 357 "version", "HTTP/1.1", |
351 "proxy-authorization", "Basic Zm9vOmJhcg==", | 358 "proxy-authorization", "Basic Zm9vOmJhcg==", |
352 }; | 359 }; |
353 return ConstructSpdyPacket( | 360 return ConstructSpdyPacket( |
354 kSynStartHeader, NULL, 0, kConnectHeaders, arraysize(kConnectHeaders)/2); | 361 kSynStartHeader, NULL, 0, kConnectHeaders, arraysize(kConnectHeaders)/2); |
355 } | 362 } |
356 | 363 |
357 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT. | 364 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT. |
358 spdy::SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectReplyFrame() { | 365 spdy::SpdyFrame* SpdyProxyClientSocketSpdy3Test::ConstructConnectReplyFrame() { |
359 const char* const kStandardReplyHeaders[] = { | 366 const char* const kStandardReplyHeaders[] = { |
360 "status", "200 Connection Established", | 367 "status", "200 Connection Established", |
361 "version", "HTTP/1.1" | 368 "version", "HTTP/1.1" |
362 }; | 369 }; |
363 return ConstructSpdyControlFrame(NULL, | 370 return ConstructSpdyControlFrame(NULL, |
364 0, | 371 0, |
365 false, | 372 false, |
366 kStreamId, | 373 kStreamId, |
367 LOWEST, | 374 LOWEST, |
368 spdy::SYN_REPLY, | 375 spdy::SYN_REPLY, |
369 spdy::CONTROL_FLAG_NONE, | 376 spdy::CONTROL_FLAG_NONE, |
370 kStandardReplyHeaders, | 377 kStandardReplyHeaders, |
371 arraysize(kStandardReplyHeaders)); | 378 arraysize(kStandardReplyHeaders)); |
372 } | 379 } |
373 | 380 |
374 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT. | 381 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT. |
375 spdy::SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthReplyFrame() { | 382 spdy::SpdyFrame* |
| 383 SpdyProxyClientSocketSpdy3Test::ConstructConnectAuthReplyFrame() { |
376 const char* const kStandardReplyHeaders[] = { | 384 const char* const kStandardReplyHeaders[] = { |
377 "status", "407 Proxy Authentication Required", | 385 "status", "407 Proxy Authentication Required", |
378 "version", "HTTP/1.1", | 386 "version", "HTTP/1.1", |
379 "proxy-authenticate", "Basic realm=\"MyRealm1\"", | 387 "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
380 }; | 388 }; |
381 | 389 |
382 return ConstructSpdyControlFrame(NULL, | 390 return ConstructSpdyControlFrame(NULL, |
383 0, | 391 0, |
384 false, | 392 false, |
385 kStreamId, | 393 kStreamId, |
386 LOWEST, | 394 LOWEST, |
387 spdy::SYN_REPLY, | 395 spdy::SYN_REPLY, |
388 spdy::CONTROL_FLAG_NONE, | 396 spdy::CONTROL_FLAG_NONE, |
389 kStandardReplyHeaders, | 397 kStandardReplyHeaders, |
390 arraysize(kStandardReplyHeaders)); | 398 arraysize(kStandardReplyHeaders)); |
391 } | 399 } |
392 | 400 |
393 // Constructs a SPDY SYN_REPLY frame with an HTTP 500 error. | 401 // Constructs a SPDY SYN_REPLY frame with an HTTP 500 error. |
394 spdy::SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectErrorReplyFrame() { | 402 spdy::SpdyFrame* |
| 403 SpdyProxyClientSocketSpdy3Test::ConstructConnectErrorReplyFrame() { |
395 const char* const kStandardReplyHeaders[] = { | 404 const char* const kStandardReplyHeaders[] = { |
396 "status", "500 Internal Server Error", | 405 "status", "500 Internal Server Error", |
397 "version", "HTTP/1.1", | 406 "version", "HTTP/1.1", |
398 }; | 407 }; |
399 | 408 |
400 return ConstructSpdyControlFrame(NULL, | 409 return ConstructSpdyControlFrame(NULL, |
401 0, | 410 0, |
402 false, | 411 false, |
403 kStreamId, | 412 kStreamId, |
404 LOWEST, | 413 LOWEST, |
405 spdy::SYN_REPLY, | 414 spdy::SYN_REPLY, |
406 spdy::CONTROL_FLAG_NONE, | 415 spdy::CONTROL_FLAG_NONE, |
407 kStandardReplyHeaders, | 416 kStandardReplyHeaders, |
408 arraysize(kStandardReplyHeaders)); | 417 arraysize(kStandardReplyHeaders)); |
409 } | 418 } |
410 | 419 |
411 spdy::SpdyFrame* SpdyProxyClientSocketTest::ConstructBodyFrame(const char* data, | 420 spdy::SpdyFrame* SpdyProxyClientSocketSpdy3Test::ConstructBodyFrame( |
412 int length) { | 421 const char* data, |
| 422 int length) { |
413 return framer_.CreateDataFrame(kStreamId, data, length, spdy::DATA_FLAG_NONE); | 423 return framer_.CreateDataFrame(kStreamId, data, length, spdy::DATA_FLAG_NONE); |
414 } | 424 } |
415 | 425 |
416 // ----------- Connect | 426 // ----------- Connect |
417 | 427 |
418 TEST_F(SpdyProxyClientSocketTest, ConnectSendsCorrectRequest) { | 428 TEST_F(SpdyProxyClientSocketSpdy3Test, ConnectSendsCorrectRequest) { |
419 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 429 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
420 MockWrite writes[] = { | 430 MockWrite writes[] = { |
421 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 431 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
422 }; | 432 }; |
423 | 433 |
424 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 434 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
425 MockRead reads[] = { | 435 MockRead reads[] = { |
426 CreateMockRead(*resp, 1, ASYNC), | 436 CreateMockRead(*resp, 1, ASYNC), |
427 MockRead(ASYNC, 0, 3), // EOF | 437 MockRead(ASYNC, 0, 3), // EOF |
428 }; | 438 }; |
429 | 439 |
430 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 440 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
431 | 441 |
432 ASSERT_FALSE(sock_->IsConnected()); | 442 ASSERT_FALSE(sock_->IsConnected()); |
433 | 443 |
434 AssertConnectSucceeds(); | 444 AssertConnectSucceeds(); |
435 | 445 |
436 AssertConnectionEstablished(); | 446 AssertConnectionEstablished(); |
437 } | 447 } |
438 | 448 |
439 TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthRequested) { | 449 TEST_F(SpdyProxyClientSocketSpdy3Test, ConnectWithAuthRequested) { |
440 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 450 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
441 MockWrite writes[] = { | 451 MockWrite writes[] = { |
442 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 452 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
443 }; | 453 }; |
444 | 454 |
445 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectAuthReplyFrame()); | 455 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectAuthReplyFrame()); |
446 MockRead reads[] = { | 456 MockRead reads[] = { |
447 CreateMockRead(*resp, 1, ASYNC), | 457 CreateMockRead(*resp, 1, ASYNC), |
448 MockRead(ASYNC, 0, 3), // EOF | 458 MockRead(ASYNC, 0, 3), // EOF |
449 }; | 459 }; |
450 | 460 |
451 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 461 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
452 | 462 |
453 AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); | 463 AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); |
454 | 464 |
455 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); | 465 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); |
456 ASSERT_TRUE(response != NULL); | 466 ASSERT_TRUE(response != NULL); |
457 ASSERT_EQ(407, response->headers->response_code()); | 467 ASSERT_EQ(407, response->headers->response_code()); |
458 ASSERT_EQ("Proxy Authentication Required", | 468 ASSERT_EQ("Proxy Authentication Required", |
459 response->headers->GetStatusText()); | 469 response->headers->GetStatusText()); |
460 } | 470 } |
461 | 471 |
462 TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthCredentials) { | 472 TEST_F(SpdyProxyClientSocketSpdy3Test, ConnectWithAuthCredentials) { |
463 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectAuthRequestFrame()); | 473 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectAuthRequestFrame()); |
464 MockWrite writes[] = { | 474 MockWrite writes[] = { |
465 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 475 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
466 }; | 476 }; |
467 | 477 |
468 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 478 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
469 MockRead reads[] = { | 479 MockRead reads[] = { |
470 CreateMockRead(*resp, 1, ASYNC), | 480 CreateMockRead(*resp, 1, ASYNC), |
471 MockRead(ASYNC, 0, 3), // EOF | 481 MockRead(ASYNC, 0, 3), // EOF |
472 }; | 482 }; |
473 | 483 |
474 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 484 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
475 AddAuthToCache(); | 485 AddAuthToCache(); |
476 | 486 |
477 AssertConnectSucceeds(); | 487 AssertConnectSucceeds(); |
478 | 488 |
479 AssertConnectionEstablished(); | 489 AssertConnectionEstablished(); |
480 } | 490 } |
481 | 491 |
482 TEST_F(SpdyProxyClientSocketTest, ConnectFails) { | 492 TEST_F(SpdyProxyClientSocketSpdy3Test, ConnectFails) { |
483 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 493 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
484 MockWrite writes[] = { | 494 MockWrite writes[] = { |
485 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 495 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
486 }; | 496 }; |
487 | 497 |
488 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 498 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
489 MockRead reads[] = { | 499 MockRead reads[] = { |
490 MockRead(ASYNC, 0, 1), // EOF | 500 MockRead(ASYNC, 0, 1), // EOF |
491 }; | 501 }; |
492 | 502 |
493 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 503 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
494 | 504 |
495 ASSERT_FALSE(sock_->IsConnected()); | 505 ASSERT_FALSE(sock_->IsConnected()); |
496 | 506 |
497 AssertConnectFails(ERR_CONNECTION_CLOSED); | 507 AssertConnectFails(ERR_CONNECTION_CLOSED); |
498 | 508 |
499 ASSERT_FALSE(sock_->IsConnected()); | 509 ASSERT_FALSE(sock_->IsConnected()); |
500 } | 510 } |
501 | 511 |
502 // ----------- WasEverUsed | 512 // ----------- WasEverUsed |
503 | 513 |
504 TEST_F(SpdyProxyClientSocketTest, WasEverUsedReturnsCorrectValues) { | 514 TEST_F(SpdyProxyClientSocketSpdy3Test, WasEverUsedReturnsCorrectValues) { |
505 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 515 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
506 MockWrite writes[] = { | 516 MockWrite writes[] = { |
507 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 517 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
508 }; | 518 }; |
509 | 519 |
510 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 520 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
511 MockRead reads[] = { | 521 MockRead reads[] = { |
512 CreateMockRead(*resp, 1, ASYNC), | 522 CreateMockRead(*resp, 1, ASYNC), |
513 MockRead(ASYNC, 0, 2), // EOF | 523 MockRead(ASYNC, 0, 2), // EOF |
514 }; | 524 }; |
515 | 525 |
516 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 526 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
517 | 527 |
518 EXPECT_FALSE(sock_->WasEverUsed()); | 528 EXPECT_FALSE(sock_->WasEverUsed()); |
519 AssertConnectSucceeds(); | 529 AssertConnectSucceeds(); |
520 EXPECT_TRUE(sock_->WasEverUsed()); | 530 EXPECT_TRUE(sock_->WasEverUsed()); |
521 sock_->Disconnect(); | 531 sock_->Disconnect(); |
522 EXPECT_TRUE(sock_->WasEverUsed()); | 532 EXPECT_TRUE(sock_->WasEverUsed()); |
523 } | 533 } |
524 | 534 |
525 // ----------- GetPeerAddress | 535 // ----------- GetPeerAddress |
526 | 536 |
527 TEST_F(SpdyProxyClientSocketTest, GetPeerAddressReturnsCorrectValues) { | 537 TEST_F(SpdyProxyClientSocketSpdy3Test, GetPeerAddressReturnsCorrectValues) { |
528 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 538 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
529 MockWrite writes[] = { | 539 MockWrite writes[] = { |
530 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 540 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
531 }; | 541 }; |
532 | 542 |
533 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 543 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
534 MockRead reads[] = { | 544 MockRead reads[] = { |
535 CreateMockRead(*resp, 1, ASYNC), | 545 CreateMockRead(*resp, 1, ASYNC), |
536 MockRead(ASYNC, 0, 2), // EOF | 546 MockRead(ASYNC, 0, 2), // EOF |
537 }; | 547 }; |
(...skipping 12 matching lines...) Expand all Loading... |
550 EXPECT_FALSE(sock_->IsConnected()); | 560 EXPECT_FALSE(sock_->IsConnected()); |
551 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, sock_->GetPeerAddress(&addr)); | 561 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, sock_->GetPeerAddress(&addr)); |
552 | 562 |
553 sock_->Disconnect(); | 563 sock_->Disconnect(); |
554 | 564 |
555 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, sock_->GetPeerAddress(&addr)); | 565 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, sock_->GetPeerAddress(&addr)); |
556 } | 566 } |
557 | 567 |
558 // ----------- Write | 568 // ----------- Write |
559 | 569 |
560 TEST_F(SpdyProxyClientSocketTest, WriteSendsDataInDataFrame) { | 570 TEST_F(SpdyProxyClientSocketSpdy3Test, WriteSendsDataInDataFrame) { |
561 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 571 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
562 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 572 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
563 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 573 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
564 MockWrite writes[] = { | 574 MockWrite writes[] = { |
565 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 575 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
566 CreateMockWrite(*msg1, 2, SYNCHRONOUS), | 576 CreateMockWrite(*msg1, 2, SYNCHRONOUS), |
567 CreateMockWrite(*msg2, 3, SYNCHRONOUS), | 577 CreateMockWrite(*msg2, 3, SYNCHRONOUS), |
568 }; | 578 }; |
569 | 579 |
570 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 580 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
571 MockRead reads[] = { | 581 MockRead reads[] = { |
572 CreateMockRead(*resp, 1, ASYNC), | 582 CreateMockRead(*resp, 1, ASYNC), |
573 MockRead(ASYNC, 0, 4), // EOF | 583 MockRead(ASYNC, 0, 4), // EOF |
574 }; | 584 }; |
575 | 585 |
576 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 586 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
577 | 587 |
578 AssertConnectSucceeds(); | 588 AssertConnectSucceeds(); |
579 | 589 |
580 AssertAsyncWriteSucceeds(kMsg1, kLen1); | 590 AssertAsyncWriteSucceeds(kMsg1, kLen1); |
581 AssertAsyncWriteSucceeds(kMsg2, kLen2); | 591 AssertAsyncWriteSucceeds(kMsg2, kLen2); |
582 } | 592 } |
583 | 593 |
584 TEST_F(SpdyProxyClientSocketTest, WriteSplitsLargeDataIntoMultipleFrames) { | 594 TEST_F(SpdyProxyClientSocketSpdy3Test, WriteSplitsLargeDataIntoMultipleFrames) { |
585 std::string chunk_data(kMaxSpdyFrameChunkSize, 'x'); | 595 std::string chunk_data(kMaxSpdyFrameChunkSize, 'x'); |
586 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 596 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
587 scoped_ptr<spdy::SpdyFrame> chunk(ConstructBodyFrame(chunk_data.data(), | 597 scoped_ptr<spdy::SpdyFrame> chunk(ConstructBodyFrame(chunk_data.data(), |
588 chunk_data.length())); | 598 chunk_data.length())); |
589 MockWrite writes[] = { | 599 MockWrite writes[] = { |
590 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 600 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
591 CreateMockWrite(*chunk, 2, SYNCHRONOUS), | 601 CreateMockWrite(*chunk, 2, SYNCHRONOUS), |
592 CreateMockWrite(*chunk, 3, SYNCHRONOUS), | 602 CreateMockWrite(*chunk, 3, SYNCHRONOUS), |
593 CreateMockWrite(*chunk, 4, SYNCHRONOUS) | 603 CreateMockWrite(*chunk, 4, SYNCHRONOUS) |
594 }; | 604 }; |
(...skipping 14 matching lines...) Expand all Loading... |
609 | 619 |
610 EXPECT_EQ(ERR_IO_PENDING, sock_->Write(buf, buf->size(), | 620 EXPECT_EQ(ERR_IO_PENDING, sock_->Write(buf, buf->size(), |
611 write_callback_.callback())); | 621 write_callback_.callback())); |
612 data_->RunFor(3); | 622 data_->RunFor(3); |
613 | 623 |
614 EXPECT_EQ(buf->size(), write_callback_.WaitForResult()); | 624 EXPECT_EQ(buf->size(), write_callback_.WaitForResult()); |
615 } | 625 } |
616 | 626 |
617 // ----------- Read | 627 // ----------- Read |
618 | 628 |
619 TEST_F(SpdyProxyClientSocketTest, ReadReadsDataInDataFrame) { | 629 TEST_F(SpdyProxyClientSocketSpdy3Test, ReadReadsDataInDataFrame) { |
620 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 630 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
621 MockWrite writes[] = { | 631 MockWrite writes[] = { |
622 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 632 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
623 }; | 633 }; |
624 | 634 |
625 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 635 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
626 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 636 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
627 MockRead reads[] = { | 637 MockRead reads[] = { |
628 CreateMockRead(*resp, 1, ASYNC), | 638 CreateMockRead(*resp, 1, ASYNC), |
629 CreateMockRead(*msg1, 2, ASYNC), | 639 CreateMockRead(*msg1, 2, ASYNC), |
630 MockRead(ASYNC, 0, 3), // EOF | 640 MockRead(ASYNC, 0, 3), // EOF |
631 }; | 641 }; |
632 | 642 |
633 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 643 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
634 | 644 |
635 AssertConnectSucceeds(); | 645 AssertConnectSucceeds(); |
636 | 646 |
637 Run(1); // SpdySession consumes the next read and sends it to | 647 Run(1); // SpdySession consumes the next read and sends it to |
638 // sock_ to be buffered. | 648 // sock_ to be buffered. |
639 AssertSyncReadEquals(kMsg1, kLen1); | 649 AssertSyncReadEquals(kMsg1, kLen1); |
640 } | 650 } |
641 | 651 |
642 TEST_F(SpdyProxyClientSocketTest, ReadDataFromBufferedFrames) { | 652 TEST_F(SpdyProxyClientSocketSpdy3Test, ReadDataFromBufferedFrames) { |
643 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 653 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
644 MockWrite writes[] = { | 654 MockWrite writes[] = { |
645 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 655 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
646 }; | 656 }; |
647 | 657 |
648 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 658 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
649 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 659 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
650 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 660 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
651 MockRead reads[] = { | 661 MockRead reads[] = { |
652 CreateMockRead(*resp, 1, ASYNC), | 662 CreateMockRead(*resp, 1, ASYNC), |
653 CreateMockRead(*msg1, 2, ASYNC), | 663 CreateMockRead(*msg1, 2, ASYNC), |
654 CreateMockRead(*msg2, 3, ASYNC), | 664 CreateMockRead(*msg2, 3, ASYNC), |
655 MockRead(ASYNC, 0, 4), // EOF | 665 MockRead(ASYNC, 0, 4), // EOF |
656 }; | 666 }; |
657 | 667 |
658 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 668 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
659 | 669 |
660 AssertConnectSucceeds(); | 670 AssertConnectSucceeds(); |
661 | 671 |
662 Run(1); // SpdySession consumes the next read and sends it to | 672 Run(1); // SpdySession consumes the next read and sends it to |
663 // sock_ to be buffered. | 673 // sock_ to be buffered. |
664 AssertSyncReadEquals(kMsg1, kLen1); | 674 AssertSyncReadEquals(kMsg1, kLen1); |
665 Run(1); // SpdySession consumes the next read and sends it to | 675 Run(1); // SpdySession consumes the next read and sends it to |
666 // sock_ to be buffered. | 676 // sock_ to be buffered. |
667 AssertSyncReadEquals(kMsg2, kLen2); | 677 AssertSyncReadEquals(kMsg2, kLen2); |
668 } | 678 } |
669 | 679 |
670 TEST_F(SpdyProxyClientSocketTest, ReadDataMultipleBufferedFrames) { | 680 TEST_F(SpdyProxyClientSocketSpdy3Test, ReadDataMultipleBufferedFrames) { |
671 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 681 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
672 MockWrite writes[] = { | 682 MockWrite writes[] = { |
673 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 683 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
674 }; | 684 }; |
675 | 685 |
676 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 686 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
677 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 687 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
678 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 688 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
679 MockRead reads[] = { | 689 MockRead reads[] = { |
680 CreateMockRead(*resp, 1, ASYNC), | 690 CreateMockRead(*resp, 1, ASYNC), |
681 CreateMockRead(*msg1, 2, ASYNC), | 691 CreateMockRead(*msg1, 2, ASYNC), |
682 CreateMockRead(*msg2, 3, ASYNC), | 692 CreateMockRead(*msg2, 3, ASYNC), |
683 MockRead(ASYNC, 0, 4), // EOF | 693 MockRead(ASYNC, 0, 4), // EOF |
684 }; | 694 }; |
685 | 695 |
686 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 696 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
687 | 697 |
688 AssertConnectSucceeds(); | 698 AssertConnectSucceeds(); |
689 | 699 |
690 Run(2); // SpdySession consumes the next two reads and sends then to | 700 Run(2); // SpdySession consumes the next two reads and sends then to |
691 // sock_ to be buffered. | 701 // sock_ to be buffered. |
692 AssertSyncReadEquals(kMsg1, kLen1); | 702 AssertSyncReadEquals(kMsg1, kLen1); |
693 AssertSyncReadEquals(kMsg2, kLen2); | 703 AssertSyncReadEquals(kMsg2, kLen2); |
694 } | 704 } |
695 | 705 |
696 TEST_F(SpdyProxyClientSocketTest, LargeReadWillMergeDataFromDifferentFrames) { | 706 TEST_F(SpdyProxyClientSocketSpdy3Test, |
| 707 LargeReadWillMergeDataFromDifferentFrames) { |
697 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 708 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
698 MockWrite writes[] = { | 709 MockWrite writes[] = { |
699 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 710 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
700 }; | 711 }; |
701 | 712 |
702 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 713 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
703 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 714 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
704 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); | 715 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); |
705 MockRead reads[] = { | 716 MockRead reads[] = { |
706 CreateMockRead(*resp, 1, ASYNC), | 717 CreateMockRead(*resp, 1, ASYNC), |
707 CreateMockRead(*msg3, 2, ASYNC), | 718 CreateMockRead(*msg3, 2, ASYNC), |
708 CreateMockRead(*msg3, 3, ASYNC), | 719 CreateMockRead(*msg3, 3, ASYNC), |
709 MockRead(ASYNC, 0, 4), // EOF | 720 MockRead(ASYNC, 0, 4), // EOF |
710 }; | 721 }; |
711 | 722 |
712 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 723 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
713 | 724 |
714 AssertConnectSucceeds(); | 725 AssertConnectSucceeds(); |
715 | 726 |
716 Run(2); // SpdySession consumes the next two reads and sends then to | 727 Run(2); // SpdySession consumes the next two reads and sends then to |
717 // sock_ to be buffered. | 728 // sock_ to be buffered. |
718 // The payload from two data frames, each with kMsg3 will be combined | 729 // The payload from two data frames, each with kMsg3 will be combined |
719 // together into a single read(). | 730 // together into a single read(). |
720 AssertSyncReadEquals(kMsg33, kLen33); | 731 AssertSyncReadEquals(kMsg33, kLen33); |
721 } | 732 } |
722 | 733 |
723 TEST_F(SpdyProxyClientSocketTest, MultipleShortReadsThenMoreRead) { | 734 TEST_F(SpdyProxyClientSocketSpdy3Test, MultipleShortReadsThenMoreRead) { |
724 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 735 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
725 MockWrite writes[] = { | 736 MockWrite writes[] = { |
726 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 737 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
727 }; | 738 }; |
728 | 739 |
729 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 740 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
730 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 741 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
731 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); | 742 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); |
732 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 743 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
733 MockRead reads[] = { | 744 MockRead reads[] = { |
(...skipping 11 matching lines...) Expand all Loading... |
745 | 756 |
746 Run(4); // SpdySession consumes the next four reads and sends then to | 757 Run(4); // SpdySession consumes the next four reads and sends then to |
747 // sock_ to be buffered. | 758 // sock_ to be buffered. |
748 AssertSyncReadEquals(kMsg1, kLen1); | 759 AssertSyncReadEquals(kMsg1, kLen1); |
749 // The payload from two data frames, each with kMsg3 will be combined | 760 // The payload from two data frames, each with kMsg3 will be combined |
750 // together into a single read(). | 761 // together into a single read(). |
751 AssertSyncReadEquals(kMsg33, kLen33); | 762 AssertSyncReadEquals(kMsg33, kLen33); |
752 AssertSyncReadEquals(kMsg2, kLen2); | 763 AssertSyncReadEquals(kMsg2, kLen2); |
753 } | 764 } |
754 | 765 |
755 TEST_F(SpdyProxyClientSocketTest, ReadWillSplitDataFromLargeFrame) { | 766 TEST_F(SpdyProxyClientSocketSpdy3Test, ReadWillSplitDataFromLargeFrame) { |
756 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 767 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
757 MockWrite writes[] = { | 768 MockWrite writes[] = { |
758 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 769 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
759 }; | 770 }; |
760 | 771 |
761 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 772 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
762 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 773 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
763 scoped_ptr<spdy::SpdyFrame> msg33(ConstructBodyFrame(kMsg33, kLen33)); | 774 scoped_ptr<spdy::SpdyFrame> msg33(ConstructBodyFrame(kMsg33, kLen33)); |
764 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 775 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
765 MockRead reads[] = { | 776 MockRead reads[] = { |
766 CreateMockRead(*resp, 1, ASYNC), | 777 CreateMockRead(*resp, 1, ASYNC), |
767 CreateMockRead(*msg1, 2, ASYNC), | 778 CreateMockRead(*msg1, 2, ASYNC), |
768 CreateMockRead(*msg33, 3, ASYNC), | 779 CreateMockRead(*msg33, 3, ASYNC), |
769 MockRead(ASYNC, 0, 4), // EOF | 780 MockRead(ASYNC, 0, 4), // EOF |
770 }; | 781 }; |
771 | 782 |
772 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 783 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
773 | 784 |
774 AssertConnectSucceeds(); | 785 AssertConnectSucceeds(); |
775 | 786 |
776 Run(2); // SpdySession consumes the next two reads and sends then to | 787 Run(2); // SpdySession consumes the next two reads and sends then to |
777 // sock_ to be buffered. | 788 // sock_ to be buffered. |
778 AssertSyncReadEquals(kMsg1, kLen1); | 789 AssertSyncReadEquals(kMsg1, kLen1); |
779 // The payload from the single large data frame will be read across | 790 // The payload from the single large data frame will be read across |
780 // two different reads. | 791 // two different reads. |
781 AssertSyncReadEquals(kMsg3, kLen3); | 792 AssertSyncReadEquals(kMsg3, kLen3); |
782 AssertSyncReadEquals(kMsg3, kLen3); | 793 AssertSyncReadEquals(kMsg3, kLen3); |
783 } | 794 } |
784 | 795 |
785 TEST_F(SpdyProxyClientSocketTest, MultipleReadsFromSameLargeFrame) { | 796 TEST_F(SpdyProxyClientSocketSpdy3Test, MultipleReadsFromSameLargeFrame) { |
786 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 797 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
787 MockWrite writes[] = { | 798 MockWrite writes[] = { |
788 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 799 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
789 }; | 800 }; |
790 | 801 |
791 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 802 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
792 scoped_ptr<spdy::SpdyFrame> msg333(ConstructBodyFrame(kMsg333, kLen333)); | 803 scoped_ptr<spdy::SpdyFrame> msg333(ConstructBodyFrame(kMsg333, kLen333)); |
793 MockRead reads[] = { | 804 MockRead reads[] = { |
794 CreateMockRead(*resp, 1, ASYNC), | 805 CreateMockRead(*resp, 1, ASYNC), |
795 CreateMockRead(*msg333, 2, ASYNC), | 806 CreateMockRead(*msg333, 2, ASYNC), |
(...skipping 10 matching lines...) Expand all Loading... |
806 // two different reads. | 817 // two different reads. |
807 AssertSyncReadEquals(kMsg33, kLen33); | 818 AssertSyncReadEquals(kMsg33, kLen33); |
808 | 819 |
809 // Now attempt to do a read of more data than remains buffered | 820 // Now attempt to do a read of more data than remains buffered |
810 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen33)); | 821 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen33)); |
811 ASSERT_EQ(kLen3, sock_->Read(buf, kLen33, read_callback_.callback())); | 822 ASSERT_EQ(kLen3, sock_->Read(buf, kLen33, read_callback_.callback())); |
812 ASSERT_EQ(std::string(kMsg3, kLen3), std::string(buf->data(), kLen3)); | 823 ASSERT_EQ(std::string(kMsg3, kLen3), std::string(buf->data(), kLen3)); |
813 ASSERT_TRUE(sock_->IsConnected()); | 824 ASSERT_TRUE(sock_->IsConnected()); |
814 } | 825 } |
815 | 826 |
816 TEST_F(SpdyProxyClientSocketTest, ReadAuthResponseBody) { | 827 TEST_F(SpdyProxyClientSocketSpdy3Test, ReadAuthResponseBody) { |
817 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 828 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
818 MockWrite writes[] = { | 829 MockWrite writes[] = { |
819 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 830 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
820 }; | 831 }; |
821 | 832 |
822 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectAuthReplyFrame()); | 833 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectAuthReplyFrame()); |
823 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 834 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
824 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 835 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
825 MockRead reads[] = { | 836 MockRead reads[] = { |
826 CreateMockRead(*resp, 1, ASYNC), | 837 CreateMockRead(*resp, 1, ASYNC), |
827 CreateMockRead(*msg1, 2, ASYNC), | 838 CreateMockRead(*msg1, 2, ASYNC), |
828 CreateMockRead(*msg2, 3, ASYNC), | 839 CreateMockRead(*msg2, 3, ASYNC), |
829 MockRead(ASYNC, 0, 4), // EOF | 840 MockRead(ASYNC, 0, 4), // EOF |
830 }; | 841 }; |
831 | 842 |
832 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 843 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
833 | 844 |
834 AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); | 845 AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); |
835 | 846 |
836 Run(2); // SpdySession consumes the next two reads and sends then to | 847 Run(2); // SpdySession consumes the next two reads and sends then to |
837 // sock_ to be buffered. | 848 // sock_ to be buffered. |
838 AssertSyncReadEquals(kMsg1, kLen1); | 849 AssertSyncReadEquals(kMsg1, kLen1); |
839 AssertSyncReadEquals(kMsg2, kLen2); | 850 AssertSyncReadEquals(kMsg2, kLen2); |
840 } | 851 } |
841 | 852 |
842 TEST_F(SpdyProxyClientSocketTest, ReadErrorResponseBody) { | 853 TEST_F(SpdyProxyClientSocketSpdy3Test, ReadErrorResponseBody) { |
843 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 854 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
844 MockWrite writes[] = { | 855 MockWrite writes[] = { |
845 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 856 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
846 }; | 857 }; |
847 | 858 |
848 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectErrorReplyFrame()); | 859 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectErrorReplyFrame()); |
849 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 860 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
850 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 861 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
851 MockRead reads[] = { | 862 MockRead reads[] = { |
852 CreateMockRead(*resp, 1, ASYNC), | 863 CreateMockRead(*resp, 1, ASYNC), |
(...skipping 10 matching lines...) Expand all Loading... |
863 // sock_ to be buffered. | 874 // sock_ to be buffered. |
864 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, | 875 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, |
865 sock_->Read(NULL, 1, CompletionCallback())); | 876 sock_->Read(NULL, 1, CompletionCallback())); |
866 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1 + kLen2)); | 877 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1 + kLen2)); |
867 scoped_ptr<HttpStream> stream(sock_->CreateConnectResponseStream()); | 878 scoped_ptr<HttpStream> stream(sock_->CreateConnectResponseStream()); |
868 stream->ReadResponseBody(buf, kLen1 + kLen2, read_callback_.callback()); | 879 stream->ReadResponseBody(buf, kLen1 + kLen2, read_callback_.callback()); |
869 } | 880 } |
870 | 881 |
871 // ----------- Reads and Writes | 882 // ----------- Reads and Writes |
872 | 883 |
873 TEST_F(SpdyProxyClientSocketTest, AsyncReadAroundWrite) { | 884 TEST_F(SpdyProxyClientSocketSpdy3Test, AsyncReadAroundWrite) { |
874 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 885 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
875 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 886 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
876 MockWrite writes[] = { | 887 MockWrite writes[] = { |
877 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 888 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
878 CreateMockWrite(*msg2, 3, SYNCHRONOUS), | 889 CreateMockWrite(*msg2, 3, SYNCHRONOUS), |
879 }; | 890 }; |
880 | 891 |
881 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 892 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
882 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 893 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
883 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); | 894 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); |
(...skipping 15 matching lines...) Expand all Loading... |
899 // Read should block until after the write succeeds | 910 // Read should block until after the write succeeds |
900 | 911 |
901 AssertAsyncWriteSucceeds(kMsg2, kLen2); // Runs 1 step | 912 AssertAsyncWriteSucceeds(kMsg2, kLen2); // Runs 1 step |
902 | 913 |
903 ASSERT_FALSE(read_callback_.have_result()); | 914 ASSERT_FALSE(read_callback_.have_result()); |
904 Run(1); | 915 Run(1); |
905 // Now the read will return | 916 // Now the read will return |
906 AssertReadReturns(kMsg3, kLen3); | 917 AssertReadReturns(kMsg3, kLen3); |
907 } | 918 } |
908 | 919 |
909 TEST_F(SpdyProxyClientSocketTest, AsyncWriteAroundReads) { | 920 TEST_F(SpdyProxyClientSocketSpdy3Test, AsyncWriteAroundReads) { |
910 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 921 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
911 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 922 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
912 MockWrite writes[] = { | 923 MockWrite writes[] = { |
913 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 924 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
914 CreateMockWrite(*msg2, 4, ASYNC), | 925 CreateMockWrite(*msg2, 4, ASYNC), |
915 }; | 926 }; |
916 | 927 |
917 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 928 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
918 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 929 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
919 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); | 930 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); |
(...skipping 18 matching lines...) Expand all Loading... |
938 ASSERT_FALSE(write_callback_.have_result()); | 949 ASSERT_FALSE(write_callback_.have_result()); |
939 | 950 |
940 // Now the write will complete | 951 // Now the write will complete |
941 Run(1); | 952 Run(1); |
942 AssertWriteLength(kLen2); | 953 AssertWriteLength(kLen2); |
943 } | 954 } |
944 | 955 |
945 // ----------- Reading/Writing on Closed socket | 956 // ----------- Reading/Writing on Closed socket |
946 | 957 |
947 // Reading from an already closed socket should return 0 | 958 // Reading from an already closed socket should return 0 |
948 TEST_F(SpdyProxyClientSocketTest, ReadOnClosedSocketReturnsZero) { | 959 TEST_F(SpdyProxyClientSocketSpdy3Test, ReadOnClosedSocketReturnsZero) { |
949 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 960 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
950 MockWrite writes[] = { | 961 MockWrite writes[] = { |
951 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 962 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
952 }; | 963 }; |
953 | 964 |
954 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 965 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
955 MockRead reads[] = { | 966 MockRead reads[] = { |
956 CreateMockRead(*resp, 1, ASYNC), | 967 CreateMockRead(*resp, 1, ASYNC), |
957 MockRead(ASYNC, 0, 2), // EOF | 968 MockRead(ASYNC, 0, 2), // EOF |
958 }; | 969 }; |
959 | 970 |
960 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 971 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
961 | 972 |
962 AssertConnectSucceeds(); | 973 AssertConnectSucceeds(); |
963 | 974 |
964 Run(1); | 975 Run(1); |
965 | 976 |
966 ASSERT_FALSE(sock_->IsConnected()); | 977 ASSERT_FALSE(sock_->IsConnected()); |
967 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); | 978 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); |
968 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); | 979 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); |
969 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); | 980 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); |
970 ASSERT_FALSE(sock_->IsConnectedAndIdle()); | 981 ASSERT_FALSE(sock_->IsConnectedAndIdle()); |
971 } | 982 } |
972 | 983 |
973 // Read pending when socket is closed should return 0 | 984 // Read pending when socket is closed should return 0 |
974 TEST_F(SpdyProxyClientSocketTest, PendingReadOnCloseReturnsZero) { | 985 TEST_F(SpdyProxyClientSocketSpdy3Test, PendingReadOnCloseReturnsZero) { |
975 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 986 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
976 MockWrite writes[] = { | 987 MockWrite writes[] = { |
977 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 988 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
978 }; | 989 }; |
979 | 990 |
980 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 991 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
981 MockRead reads[] = { | 992 MockRead reads[] = { |
982 CreateMockRead(*resp, 1, ASYNC), | 993 CreateMockRead(*resp, 1, ASYNC), |
983 MockRead(ASYNC, 0, 2), // EOF | 994 MockRead(ASYNC, 0, 2), // EOF |
984 }; | 995 }; |
985 | 996 |
986 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 997 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
987 | 998 |
988 AssertConnectSucceeds(); | 999 AssertConnectSucceeds(); |
989 | 1000 |
990 AssertReadStarts(kMsg1, kLen1); | 1001 AssertReadStarts(kMsg1, kLen1); |
991 | 1002 |
992 Run(1); | 1003 Run(1); |
993 | 1004 |
994 ASSERT_EQ(0, read_callback_.WaitForResult()); | 1005 ASSERT_EQ(0, read_callback_.WaitForResult()); |
995 } | 1006 } |
996 | 1007 |
997 // Reading from a disconnected socket is an error | 1008 // Reading from a disconnected socket is an error |
998 TEST_F(SpdyProxyClientSocketTest, ReadOnDisconnectSocketReturnsNotConnected) { | 1009 TEST_F(SpdyProxyClientSocketSpdy3Test, |
| 1010 ReadOnDisconnectSocketReturnsNotConnected) { |
999 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1011 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1000 MockWrite writes[] = { | 1012 MockWrite writes[] = { |
1001 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1013 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1002 }; | 1014 }; |
1003 | 1015 |
1004 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1016 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1005 MockRead reads[] = { | 1017 MockRead reads[] = { |
1006 CreateMockRead(*resp, 1, ASYNC), | 1018 CreateMockRead(*resp, 1, ASYNC), |
1007 MockRead(ASYNC, 0, 2), // EOF | 1019 MockRead(ASYNC, 0, 2), // EOF |
1008 }; | 1020 }; |
1009 | 1021 |
1010 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1022 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
1011 | 1023 |
1012 AssertConnectSucceeds(); | 1024 AssertConnectSucceeds(); |
1013 | 1025 |
1014 sock_->Disconnect(); | 1026 sock_->Disconnect(); |
1015 | 1027 |
1016 ASSERT_EQ(ERR_SOCKET_NOT_CONNECTED, | 1028 ASSERT_EQ(ERR_SOCKET_NOT_CONNECTED, |
1017 sock_->Read(NULL, 1, CompletionCallback())); | 1029 sock_->Read(NULL, 1, CompletionCallback())); |
1018 } | 1030 } |
1019 | 1031 |
1020 // Reading buffered data from an already closed socket should return | 1032 // Reading buffered data from an already closed socket should return |
1021 // buffered data, then 0. | 1033 // buffered data, then 0. |
1022 TEST_F(SpdyProxyClientSocketTest, ReadOnClosedSocketReturnsBufferedData) { | 1034 TEST_F(SpdyProxyClientSocketSpdy3Test, ReadOnClosedSocketReturnsBufferedData) { |
1023 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1035 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1024 MockWrite writes[] = { | 1036 MockWrite writes[] = { |
1025 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1037 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1026 }; | 1038 }; |
1027 | 1039 |
1028 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1040 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1029 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 1041 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
1030 MockRead reads[] = { | 1042 MockRead reads[] = { |
1031 CreateMockRead(*resp, 1, ASYNC), | 1043 CreateMockRead(*resp, 1, ASYNC), |
1032 CreateMockRead(*msg1, 2, ASYNC), | 1044 CreateMockRead(*msg1, 2, ASYNC), |
(...skipping 12 matching lines...) Expand all Loading... |
1045 ASSERT_EQ(std::string(kMsg1, kLen1), std::string(buf->data(), kLen1)); | 1057 ASSERT_EQ(std::string(kMsg1, kLen1), std::string(buf->data(), kLen1)); |
1046 | 1058 |
1047 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); | 1059 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); |
1048 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); | 1060 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); |
1049 sock_->Disconnect(); | 1061 sock_->Disconnect(); |
1050 ASSERT_EQ(ERR_SOCKET_NOT_CONNECTED, | 1062 ASSERT_EQ(ERR_SOCKET_NOT_CONNECTED, |
1051 sock_->Read(NULL, 1, CompletionCallback())); | 1063 sock_->Read(NULL, 1, CompletionCallback())); |
1052 } | 1064 } |
1053 | 1065 |
1054 // Calling Write() on a closed socket is an error | 1066 // Calling Write() on a closed socket is an error |
1055 TEST_F(SpdyProxyClientSocketTest, WriteOnClosedStream) { | 1067 TEST_F(SpdyProxyClientSocketSpdy3Test, WriteOnClosedStream) { |
1056 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1068 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1057 MockWrite writes[] = { | 1069 MockWrite writes[] = { |
1058 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1070 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1059 }; | 1071 }; |
1060 | 1072 |
1061 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1073 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1062 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 1074 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
1063 MockRead reads[] = { | 1075 MockRead reads[] = { |
1064 CreateMockRead(*resp, 1, ASYNC), | 1076 CreateMockRead(*resp, 1, ASYNC), |
1065 MockRead(ASYNC, 0, 2), // EOF | 1077 MockRead(ASYNC, 0, 2), // EOF |
1066 }; | 1078 }; |
1067 | 1079 |
1068 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1080 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
1069 | 1081 |
1070 AssertConnectSucceeds(); | 1082 AssertConnectSucceeds(); |
1071 | 1083 |
1072 Run(1); // Read EOF which will close the stream | 1084 Run(1); // Read EOF which will close the stream |
1073 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); | 1085 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); |
1074 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, | 1086 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, |
1075 sock_->Write(buf, buf->size(), CompletionCallback())); | 1087 sock_->Write(buf, buf->size(), CompletionCallback())); |
1076 } | 1088 } |
1077 | 1089 |
1078 // Calling Write() on a disconnected socket is an error | 1090 // Calling Write() on a disconnected socket is an error |
1079 TEST_F(SpdyProxyClientSocketTest, WriteOnDisconnectedSocket) { | 1091 TEST_F(SpdyProxyClientSocketSpdy3Test, WriteOnDisconnectedSocket) { |
1080 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1092 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1081 MockWrite writes[] = { | 1093 MockWrite writes[] = { |
1082 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1094 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1083 }; | 1095 }; |
1084 | 1096 |
1085 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1097 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1086 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 1098 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
1087 MockRead reads[] = { | 1099 MockRead reads[] = { |
1088 CreateMockRead(*resp, 1, ASYNC), | 1100 CreateMockRead(*resp, 1, ASYNC), |
1089 MockRead(ASYNC, 0, 2), // EOF | 1101 MockRead(ASYNC, 0, 2), // EOF |
1090 }; | 1102 }; |
1091 | 1103 |
1092 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1104 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
1093 | 1105 |
1094 AssertConnectSucceeds(); | 1106 AssertConnectSucceeds(); |
1095 | 1107 |
1096 sock_->Disconnect(); | 1108 sock_->Disconnect(); |
1097 | 1109 |
1098 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); | 1110 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); |
1099 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, | 1111 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, |
1100 sock_->Write(buf, buf->size(), CompletionCallback())); | 1112 sock_->Write(buf, buf->size(), CompletionCallback())); |
1101 } | 1113 } |
1102 | 1114 |
1103 // If the socket is closed with a pending Write(), the callback | 1115 // If the socket is closed with a pending Write(), the callback |
1104 // should be called with ERR_CONNECTION_CLOSED. | 1116 // should be called with ERR_CONNECTION_CLOSED. |
1105 TEST_F(SpdyProxyClientSocketTest, WritePendingOnClose) { | 1117 TEST_F(SpdyProxyClientSocketSpdy3Test, WritePendingOnClose) { |
1106 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1118 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1107 MockWrite writes[] = { | 1119 MockWrite writes[] = { |
1108 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1120 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1109 MockWrite(ASYNC, ERR_IO_PENDING, 2), | 1121 MockWrite(ASYNC, ERR_IO_PENDING, 2), |
1110 }; | 1122 }; |
1111 | 1123 |
1112 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1124 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1113 MockRead reads[] = { | 1125 MockRead reads[] = { |
1114 CreateMockRead(*resp, 1, ASYNC), | 1126 CreateMockRead(*resp, 1, ASYNC), |
1115 MockRead(ASYNC, 0, 3), // EOF | 1127 MockRead(ASYNC, 0, 3), // EOF |
1116 }; | 1128 }; |
1117 | 1129 |
1118 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1130 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
1119 | 1131 |
1120 AssertConnectSucceeds(); | 1132 AssertConnectSucceeds(); |
1121 | 1133 |
1122 EXPECT_TRUE(sock_->IsConnected()); | 1134 EXPECT_TRUE(sock_->IsConnected()); |
1123 | 1135 |
1124 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); | 1136 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); |
1125 EXPECT_EQ(ERR_IO_PENDING, | 1137 EXPECT_EQ(ERR_IO_PENDING, |
1126 sock_->Write(buf, buf->size(), write_callback_.callback())); | 1138 sock_->Write(buf, buf->size(), write_callback_.callback())); |
1127 | 1139 |
1128 Run(1); | 1140 Run(1); |
1129 | 1141 |
1130 EXPECT_EQ(ERR_CONNECTION_CLOSED, write_callback_.WaitForResult()); | 1142 EXPECT_EQ(ERR_CONNECTION_CLOSED, write_callback_.WaitForResult()); |
1131 } | 1143 } |
1132 | 1144 |
1133 // If the socket is Disconnected with a pending Write(), the callback | 1145 // If the socket is Disconnected with a pending Write(), the callback |
1134 // should not be called. | 1146 // should not be called. |
1135 TEST_F(SpdyProxyClientSocketTest, DisconnectWithWritePending) { | 1147 TEST_F(SpdyProxyClientSocketSpdy3Test, DisconnectWithWritePending) { |
1136 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1148 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1137 MockWrite writes[] = { | 1149 MockWrite writes[] = { |
1138 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1150 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1139 MockWrite(SYNCHRONOUS, 0, 2), // EOF | 1151 MockWrite(SYNCHRONOUS, 0, 2), // EOF |
1140 }; | 1152 }; |
1141 | 1153 |
1142 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1154 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1143 MockRead reads[] = { | 1155 MockRead reads[] = { |
1144 CreateMockRead(*resp, 1, ASYNC), | 1156 CreateMockRead(*resp, 1, ASYNC), |
1145 MockRead(ASYNC, 0, 3), // EOF | 1157 MockRead(ASYNC, 0, 3), // EOF |
(...skipping 10 matching lines...) Expand all Loading... |
1156 sock_->Write(buf, buf->size(), write_callback_.callback())); | 1168 sock_->Write(buf, buf->size(), write_callback_.callback())); |
1157 | 1169 |
1158 sock_->Disconnect(); | 1170 sock_->Disconnect(); |
1159 | 1171 |
1160 EXPECT_FALSE(sock_->IsConnected()); | 1172 EXPECT_FALSE(sock_->IsConnected()); |
1161 EXPECT_FALSE(write_callback_.have_result()); | 1173 EXPECT_FALSE(write_callback_.have_result()); |
1162 } | 1174 } |
1163 | 1175 |
1164 // If the socket is Disconnected with a pending Read(), the callback | 1176 // If the socket is Disconnected with a pending Read(), the callback |
1165 // should not be called. | 1177 // should not be called. |
1166 TEST_F(SpdyProxyClientSocketTest, DisconnectWithReadPending) { | 1178 TEST_F(SpdyProxyClientSocketSpdy3Test, DisconnectWithReadPending) { |
1167 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1179 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1168 MockWrite writes[] = { | 1180 MockWrite writes[] = { |
1169 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1181 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1170 }; | 1182 }; |
1171 | 1183 |
1172 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1184 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1173 MockRead reads[] = { | 1185 MockRead reads[] = { |
1174 CreateMockRead(*resp, 1, ASYNC), | 1186 CreateMockRead(*resp, 1, ASYNC), |
1175 MockRead(ASYNC, 0, 2), // EOF | 1187 MockRead(ASYNC, 0, 2), // EOF |
1176 }; | 1188 }; |
1177 | 1189 |
1178 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1190 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
1179 | 1191 |
1180 AssertConnectSucceeds(); | 1192 AssertConnectSucceeds(); |
1181 | 1193 |
1182 EXPECT_TRUE(sock_->IsConnected()); | 1194 EXPECT_TRUE(sock_->IsConnected()); |
1183 | 1195 |
1184 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1)); | 1196 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1)); |
1185 ASSERT_EQ(ERR_IO_PENDING, | 1197 ASSERT_EQ(ERR_IO_PENDING, |
1186 sock_->Read(buf, kLen1, read_callback_.callback())); | 1198 sock_->Read(buf, kLen1, read_callback_.callback())); |
1187 | 1199 |
1188 sock_->Disconnect(); | 1200 sock_->Disconnect(); |
1189 | 1201 |
1190 EXPECT_FALSE(sock_->IsConnected()); | 1202 EXPECT_FALSE(sock_->IsConnected()); |
1191 EXPECT_FALSE(read_callback_.have_result()); | 1203 EXPECT_FALSE(read_callback_.have_result()); |
1192 } | 1204 } |
1193 | 1205 |
1194 // If the socket is Reset when both a read and write are pending, | 1206 // If the socket is Reset when both a read and write are pending, |
1195 // both should be called back. | 1207 // both should be called back. |
1196 TEST_F(SpdyProxyClientSocketTest, RstWithReadAndWritePending) { | 1208 TEST_F(SpdyProxyClientSocketSpdy3Test, RstWithReadAndWritePending) { |
1197 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1209 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1198 MockWrite writes[] = { | 1210 MockWrite writes[] = { |
1199 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1211 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1200 MockWrite(ASYNC, ERR_IO_PENDING, 2), | 1212 MockWrite(ASYNC, ERR_IO_PENDING, 2), |
1201 }; | 1213 }; |
1202 | 1214 |
1203 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1215 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1204 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL)); | 1216 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL)); |
1205 MockRead reads[] = { | 1217 MockRead reads[] = { |
1206 CreateMockRead(*resp, 1, ASYNC), | 1218 CreateMockRead(*resp, 1, ASYNC), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 | 1265 |
1254 scoped_ptr<SpdyProxyClientSocket>* sock_; | 1266 scoped_ptr<SpdyProxyClientSocket>* sock_; |
1255 CompletionCallback callback_; | 1267 CompletionCallback callback_; |
1256 | 1268 |
1257 DISALLOW_COPY_AND_ASSIGN(DeleteSockCallback); | 1269 DISALLOW_COPY_AND_ASSIGN(DeleteSockCallback); |
1258 }; | 1270 }; |
1259 | 1271 |
1260 // If the socket is Reset when both a read and write are pending, and the | 1272 // If the socket is Reset when both a read and write are pending, and the |
1261 // read callback causes the socket to be deleted, the write callback should | 1273 // read callback causes the socket to be deleted, the write callback should |
1262 // not be called. | 1274 // not be called. |
1263 TEST_F(SpdyProxyClientSocketTest, RstWithReadAndWritePendingDelete) { | 1275 TEST_F(SpdyProxyClientSocketSpdy3Test, RstWithReadAndWritePendingDelete) { |
1264 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1276 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1265 MockWrite writes[] = { | 1277 MockWrite writes[] = { |
1266 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1278 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1267 MockWrite(ASYNC, ERR_IO_PENDING, 2), | 1279 MockWrite(ASYNC, ERR_IO_PENDING, 2), |
1268 }; | 1280 }; |
1269 | 1281 |
1270 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1282 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1271 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL)); | 1283 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL)); |
1272 MockRead reads[] = { | 1284 MockRead reads[] = { |
1273 CreateMockRead(*resp, 1, ASYNC), | 1285 CreateMockRead(*resp, 1, ASYNC), |
(...skipping 17 matching lines...) Expand all Loading... |
1291 write_callback_.callback())); | 1303 write_callback_.callback())); |
1292 | 1304 |
1293 Run(2); | 1305 Run(2); |
1294 | 1306 |
1295 EXPECT_FALSE(sock_.get()); | 1307 EXPECT_FALSE(sock_.get()); |
1296 EXPECT_TRUE(read_callback.have_result()); | 1308 EXPECT_TRUE(read_callback.have_result()); |
1297 EXPECT_FALSE(write_callback_.have_result()); | 1309 EXPECT_FALSE(write_callback_.have_result()); |
1298 } | 1310 } |
1299 | 1311 |
1300 } // namespace net | 1312 } // namespace net |
OLD | NEW |