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_spdy2.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_spdy2; |
| 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 SpdyProxyClientSocketSpdy2Test : public PlatformTest { |
59 public: | 61 public: |
60 SpdyProxyClientSocketTest(); | 62 SpdyProxyClientSocketSpdy2Test(); |
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(SpdyProxyClientSocketSpdy2Test); |
126 }; | 128 }; |
127 | 129 |
128 SpdyProxyClientSocketTest::SpdyProxyClientSocketTest() | 130 SpdyProxyClientSocketSpdy2Test::SpdyProxyClientSocketSpdy2Test() |
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 SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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> SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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* SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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 SpdyProxyClientSocketSpdy2Test::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* SpdyProxyClientSocketSpdy2Test::ConstructBodyFrame( |
412 int length) { | 421 const char* data, int length) { |
413 return framer_.CreateDataFrame(kStreamId, data, length, spdy::DATA_FLAG_NONE); | 422 return framer_.CreateDataFrame(kStreamId, data, length, spdy::DATA_FLAG_NONE); |
414 } | 423 } |
415 | 424 |
416 // ----------- Connect | 425 // ----------- Connect |
417 | 426 |
418 TEST_F(SpdyProxyClientSocketTest, ConnectSendsCorrectRequest) { | 427 TEST_F(SpdyProxyClientSocketSpdy2Test, ConnectSendsCorrectRequest) { |
419 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 428 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
420 MockWrite writes[] = { | 429 MockWrite writes[] = { |
421 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 430 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
422 }; | 431 }; |
423 | 432 |
424 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 433 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
425 MockRead reads[] = { | 434 MockRead reads[] = { |
426 CreateMockRead(*resp, 1, ASYNC), | 435 CreateMockRead(*resp, 1, ASYNC), |
427 MockRead(ASYNC, 0, 3), // EOF | 436 MockRead(ASYNC, 0, 3), // EOF |
428 }; | 437 }; |
429 | 438 |
430 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 439 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
431 | 440 |
432 ASSERT_FALSE(sock_->IsConnected()); | 441 ASSERT_FALSE(sock_->IsConnected()); |
433 | 442 |
434 AssertConnectSucceeds(); | 443 AssertConnectSucceeds(); |
435 | 444 |
436 AssertConnectionEstablished(); | 445 AssertConnectionEstablished(); |
437 } | 446 } |
438 | 447 |
439 TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthRequested) { | 448 TEST_F(SpdyProxyClientSocketSpdy2Test, ConnectWithAuthRequested) { |
440 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 449 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
441 MockWrite writes[] = { | 450 MockWrite writes[] = { |
442 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 451 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
443 }; | 452 }; |
444 | 453 |
445 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectAuthReplyFrame()); | 454 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectAuthReplyFrame()); |
446 MockRead reads[] = { | 455 MockRead reads[] = { |
447 CreateMockRead(*resp, 1, ASYNC), | 456 CreateMockRead(*resp, 1, ASYNC), |
448 MockRead(ASYNC, 0, 3), // EOF | 457 MockRead(ASYNC, 0, 3), // EOF |
449 }; | 458 }; |
450 | 459 |
451 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 460 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
452 | 461 |
453 AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); | 462 AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); |
454 | 463 |
455 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); | 464 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); |
456 ASSERT_TRUE(response != NULL); | 465 ASSERT_TRUE(response != NULL); |
457 ASSERT_EQ(407, response->headers->response_code()); | 466 ASSERT_EQ(407, response->headers->response_code()); |
458 ASSERT_EQ("Proxy Authentication Required", | 467 ASSERT_EQ("Proxy Authentication Required", |
459 response->headers->GetStatusText()); | 468 response->headers->GetStatusText()); |
460 } | 469 } |
461 | 470 |
462 TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthCredentials) { | 471 TEST_F(SpdyProxyClientSocketSpdy2Test, ConnectWithAuthCredentials) { |
463 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectAuthRequestFrame()); | 472 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectAuthRequestFrame()); |
464 MockWrite writes[] = { | 473 MockWrite writes[] = { |
465 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 474 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
466 }; | 475 }; |
467 | 476 |
468 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 477 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
469 MockRead reads[] = { | 478 MockRead reads[] = { |
470 CreateMockRead(*resp, 1, ASYNC), | 479 CreateMockRead(*resp, 1, ASYNC), |
471 MockRead(ASYNC, 0, 3), // EOF | 480 MockRead(ASYNC, 0, 3), // EOF |
472 }; | 481 }; |
473 | 482 |
474 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 483 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
475 AddAuthToCache(); | 484 AddAuthToCache(); |
476 | 485 |
477 AssertConnectSucceeds(); | 486 AssertConnectSucceeds(); |
478 | 487 |
479 AssertConnectionEstablished(); | 488 AssertConnectionEstablished(); |
480 } | 489 } |
481 | 490 |
482 TEST_F(SpdyProxyClientSocketTest, ConnectFails) { | 491 TEST_F(SpdyProxyClientSocketSpdy2Test, ConnectFails) { |
483 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 492 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
484 MockWrite writes[] = { | 493 MockWrite writes[] = { |
485 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 494 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
486 }; | 495 }; |
487 | 496 |
488 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 497 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
489 MockRead reads[] = { | 498 MockRead reads[] = { |
490 MockRead(ASYNC, 0, 1), // EOF | 499 MockRead(ASYNC, 0, 1), // EOF |
491 }; | 500 }; |
492 | 501 |
493 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 502 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
494 | 503 |
495 ASSERT_FALSE(sock_->IsConnected()); | 504 ASSERT_FALSE(sock_->IsConnected()); |
496 | 505 |
497 AssertConnectFails(ERR_CONNECTION_CLOSED); | 506 AssertConnectFails(ERR_CONNECTION_CLOSED); |
498 | 507 |
499 ASSERT_FALSE(sock_->IsConnected()); | 508 ASSERT_FALSE(sock_->IsConnected()); |
500 } | 509 } |
501 | 510 |
502 // ----------- WasEverUsed | 511 // ----------- WasEverUsed |
503 | 512 |
504 TEST_F(SpdyProxyClientSocketTest, WasEverUsedReturnsCorrectValues) { | 513 TEST_F(SpdyProxyClientSocketSpdy2Test, WasEverUsedReturnsCorrectValues) { |
505 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 514 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
506 MockWrite writes[] = { | 515 MockWrite writes[] = { |
507 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 516 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
508 }; | 517 }; |
509 | 518 |
510 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 519 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
511 MockRead reads[] = { | 520 MockRead reads[] = { |
512 CreateMockRead(*resp, 1, ASYNC), | 521 CreateMockRead(*resp, 1, ASYNC), |
513 MockRead(ASYNC, 0, 2), // EOF | 522 MockRead(ASYNC, 0, 2), // EOF |
514 }; | 523 }; |
515 | 524 |
516 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 525 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
517 | 526 |
518 EXPECT_FALSE(sock_->WasEverUsed()); | 527 EXPECT_FALSE(sock_->WasEverUsed()); |
519 AssertConnectSucceeds(); | 528 AssertConnectSucceeds(); |
520 EXPECT_TRUE(sock_->WasEverUsed()); | 529 EXPECT_TRUE(sock_->WasEverUsed()); |
521 sock_->Disconnect(); | 530 sock_->Disconnect(); |
522 EXPECT_TRUE(sock_->WasEverUsed()); | 531 EXPECT_TRUE(sock_->WasEverUsed()); |
523 } | 532 } |
524 | 533 |
525 // ----------- GetPeerAddress | 534 // ----------- GetPeerAddress |
526 | 535 |
527 TEST_F(SpdyProxyClientSocketTest, GetPeerAddressReturnsCorrectValues) { | 536 TEST_F(SpdyProxyClientSocketSpdy2Test, GetPeerAddressReturnsCorrectValues) { |
528 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 537 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
529 MockWrite writes[] = { | 538 MockWrite writes[] = { |
530 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 539 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
531 }; | 540 }; |
532 | 541 |
533 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 542 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
534 MockRead reads[] = { | 543 MockRead reads[] = { |
535 CreateMockRead(*resp, 1, ASYNC), | 544 CreateMockRead(*resp, 1, ASYNC), |
536 MockRead(ASYNC, 0, 2), // EOF | 545 MockRead(ASYNC, 0, 2), // EOF |
537 }; | 546 }; |
(...skipping 12 matching lines...) Expand all Loading... |
550 EXPECT_FALSE(sock_->IsConnected()); | 559 EXPECT_FALSE(sock_->IsConnected()); |
551 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, sock_->GetPeerAddress(&addr)); | 560 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, sock_->GetPeerAddress(&addr)); |
552 | 561 |
553 sock_->Disconnect(); | 562 sock_->Disconnect(); |
554 | 563 |
555 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, sock_->GetPeerAddress(&addr)); | 564 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, sock_->GetPeerAddress(&addr)); |
556 } | 565 } |
557 | 566 |
558 // ----------- Write | 567 // ----------- Write |
559 | 568 |
560 TEST_F(SpdyProxyClientSocketTest, WriteSendsDataInDataFrame) { | 569 TEST_F(SpdyProxyClientSocketSpdy2Test, WriteSendsDataInDataFrame) { |
561 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 570 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
562 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 571 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
563 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 572 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
564 MockWrite writes[] = { | 573 MockWrite writes[] = { |
565 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 574 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
566 CreateMockWrite(*msg1, 2, SYNCHRONOUS), | 575 CreateMockWrite(*msg1, 2, SYNCHRONOUS), |
567 CreateMockWrite(*msg2, 3, SYNCHRONOUS), | 576 CreateMockWrite(*msg2, 3, SYNCHRONOUS), |
568 }; | 577 }; |
569 | 578 |
570 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 579 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
571 MockRead reads[] = { | 580 MockRead reads[] = { |
572 CreateMockRead(*resp, 1, ASYNC), | 581 CreateMockRead(*resp, 1, ASYNC), |
573 MockRead(ASYNC, 0, 4), // EOF | 582 MockRead(ASYNC, 0, 4), // EOF |
574 }; | 583 }; |
575 | 584 |
576 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 585 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
577 | 586 |
578 AssertConnectSucceeds(); | 587 AssertConnectSucceeds(); |
579 | 588 |
580 AssertAsyncWriteSucceeds(kMsg1, kLen1); | 589 AssertAsyncWriteSucceeds(kMsg1, kLen1); |
581 AssertAsyncWriteSucceeds(kMsg2, kLen2); | 590 AssertAsyncWriteSucceeds(kMsg2, kLen2); |
582 } | 591 } |
583 | 592 |
584 TEST_F(SpdyProxyClientSocketTest, WriteSplitsLargeDataIntoMultipleFrames) { | 593 TEST_F(SpdyProxyClientSocketSpdy2Test, WriteSplitsLargeDataIntoMultipleFrames) { |
585 std::string chunk_data(kMaxSpdyFrameChunkSize, 'x'); | 594 std::string chunk_data(kMaxSpdyFrameChunkSize, 'x'); |
586 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 595 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
587 scoped_ptr<spdy::SpdyFrame> chunk(ConstructBodyFrame(chunk_data.data(), | 596 scoped_ptr<spdy::SpdyFrame> chunk(ConstructBodyFrame(chunk_data.data(), |
588 chunk_data.length())); | 597 chunk_data.length())); |
589 MockWrite writes[] = { | 598 MockWrite writes[] = { |
590 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 599 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
591 CreateMockWrite(*chunk, 2, SYNCHRONOUS), | 600 CreateMockWrite(*chunk, 2, SYNCHRONOUS), |
592 CreateMockWrite(*chunk, 3, SYNCHRONOUS), | 601 CreateMockWrite(*chunk, 3, SYNCHRONOUS), |
593 CreateMockWrite(*chunk, 4, SYNCHRONOUS) | 602 CreateMockWrite(*chunk, 4, SYNCHRONOUS) |
594 }; | 603 }; |
(...skipping 14 matching lines...) Expand all Loading... |
609 | 618 |
610 EXPECT_EQ(ERR_IO_PENDING, sock_->Write(buf, buf->size(), | 619 EXPECT_EQ(ERR_IO_PENDING, sock_->Write(buf, buf->size(), |
611 write_callback_.callback())); | 620 write_callback_.callback())); |
612 data_->RunFor(3); | 621 data_->RunFor(3); |
613 | 622 |
614 EXPECT_EQ(buf->size(), write_callback_.WaitForResult()); | 623 EXPECT_EQ(buf->size(), write_callback_.WaitForResult()); |
615 } | 624 } |
616 | 625 |
617 // ----------- Read | 626 // ----------- Read |
618 | 627 |
619 TEST_F(SpdyProxyClientSocketTest, ReadReadsDataInDataFrame) { | 628 TEST_F(SpdyProxyClientSocketSpdy2Test, ReadReadsDataInDataFrame) { |
620 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 629 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
621 MockWrite writes[] = { | 630 MockWrite writes[] = { |
622 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 631 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
623 }; | 632 }; |
624 | 633 |
625 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 634 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
626 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 635 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
627 MockRead reads[] = { | 636 MockRead reads[] = { |
628 CreateMockRead(*resp, 1, ASYNC), | 637 CreateMockRead(*resp, 1, ASYNC), |
629 CreateMockRead(*msg1, 2, ASYNC), | 638 CreateMockRead(*msg1, 2, ASYNC), |
630 MockRead(ASYNC, 0, 3), // EOF | 639 MockRead(ASYNC, 0, 3), // EOF |
631 }; | 640 }; |
632 | 641 |
633 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 642 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
634 | 643 |
635 AssertConnectSucceeds(); | 644 AssertConnectSucceeds(); |
636 | 645 |
637 Run(1); // SpdySession consumes the next read and sends it to | 646 Run(1); // SpdySession consumes the next read and sends it to |
638 // sock_ to be buffered. | 647 // sock_ to be buffered. |
639 AssertSyncReadEquals(kMsg1, kLen1); | 648 AssertSyncReadEquals(kMsg1, kLen1); |
640 } | 649 } |
641 | 650 |
642 TEST_F(SpdyProxyClientSocketTest, ReadDataFromBufferedFrames) { | 651 TEST_F(SpdyProxyClientSocketSpdy2Test, ReadDataFromBufferedFrames) { |
643 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 652 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
644 MockWrite writes[] = { | 653 MockWrite writes[] = { |
645 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 654 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
646 }; | 655 }; |
647 | 656 |
648 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 657 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
649 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 658 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
650 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 659 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
651 MockRead reads[] = { | 660 MockRead reads[] = { |
652 CreateMockRead(*resp, 1, ASYNC), | 661 CreateMockRead(*resp, 1, ASYNC), |
653 CreateMockRead(*msg1, 2, ASYNC), | 662 CreateMockRead(*msg1, 2, ASYNC), |
654 CreateMockRead(*msg2, 3, ASYNC), | 663 CreateMockRead(*msg2, 3, ASYNC), |
655 MockRead(ASYNC, 0, 4), // EOF | 664 MockRead(ASYNC, 0, 4), // EOF |
656 }; | 665 }; |
657 | 666 |
658 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 667 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
659 | 668 |
660 AssertConnectSucceeds(); | 669 AssertConnectSucceeds(); |
661 | 670 |
662 Run(1); // SpdySession consumes the next read and sends it to | 671 Run(1); // SpdySession consumes the next read and sends it to |
663 // sock_ to be buffered. | 672 // sock_ to be buffered. |
664 AssertSyncReadEquals(kMsg1, kLen1); | 673 AssertSyncReadEquals(kMsg1, kLen1); |
665 Run(1); // SpdySession consumes the next read and sends it to | 674 Run(1); // SpdySession consumes the next read and sends it to |
666 // sock_ to be buffered. | 675 // sock_ to be buffered. |
667 AssertSyncReadEquals(kMsg2, kLen2); | 676 AssertSyncReadEquals(kMsg2, kLen2); |
668 } | 677 } |
669 | 678 |
670 TEST_F(SpdyProxyClientSocketTest, ReadDataMultipleBufferedFrames) { | 679 TEST_F(SpdyProxyClientSocketSpdy2Test, ReadDataMultipleBufferedFrames) { |
671 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 680 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
672 MockWrite writes[] = { | 681 MockWrite writes[] = { |
673 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 682 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
674 }; | 683 }; |
675 | 684 |
676 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 685 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
677 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 686 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
678 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 687 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
679 MockRead reads[] = { | 688 MockRead reads[] = { |
680 CreateMockRead(*resp, 1, ASYNC), | 689 CreateMockRead(*resp, 1, ASYNC), |
681 CreateMockRead(*msg1, 2, ASYNC), | 690 CreateMockRead(*msg1, 2, ASYNC), |
682 CreateMockRead(*msg2, 3, ASYNC), | 691 CreateMockRead(*msg2, 3, ASYNC), |
683 MockRead(ASYNC, 0, 4), // EOF | 692 MockRead(ASYNC, 0, 4), // EOF |
684 }; | 693 }; |
685 | 694 |
686 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 695 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
687 | 696 |
688 AssertConnectSucceeds(); | 697 AssertConnectSucceeds(); |
689 | 698 |
690 Run(2); // SpdySession consumes the next two reads and sends then to | 699 Run(2); // SpdySession consumes the next two reads and sends then to |
691 // sock_ to be buffered. | 700 // sock_ to be buffered. |
692 AssertSyncReadEquals(kMsg1, kLen1); | 701 AssertSyncReadEquals(kMsg1, kLen1); |
693 AssertSyncReadEquals(kMsg2, kLen2); | 702 AssertSyncReadEquals(kMsg2, kLen2); |
694 } | 703 } |
695 | 704 |
696 TEST_F(SpdyProxyClientSocketTest, LargeReadWillMergeDataFromDifferentFrames) { | 705 TEST_F(SpdyProxyClientSocketSpdy2Test, |
| 706 LargeReadWillMergeDataFromDifferentFrames) { |
697 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 707 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
698 MockWrite writes[] = { | 708 MockWrite writes[] = { |
699 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 709 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
700 }; | 710 }; |
701 | 711 |
702 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 712 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
703 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 713 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
704 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); | 714 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); |
705 MockRead reads[] = { | 715 MockRead reads[] = { |
706 CreateMockRead(*resp, 1, ASYNC), | 716 CreateMockRead(*resp, 1, ASYNC), |
707 CreateMockRead(*msg3, 2, ASYNC), | 717 CreateMockRead(*msg3, 2, ASYNC), |
708 CreateMockRead(*msg3, 3, ASYNC), | 718 CreateMockRead(*msg3, 3, ASYNC), |
709 MockRead(ASYNC, 0, 4), // EOF | 719 MockRead(ASYNC, 0, 4), // EOF |
710 }; | 720 }; |
711 | 721 |
712 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 722 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
713 | 723 |
714 AssertConnectSucceeds(); | 724 AssertConnectSucceeds(); |
715 | 725 |
716 Run(2); // SpdySession consumes the next two reads and sends then to | 726 Run(2); // SpdySession consumes the next two reads and sends then to |
717 // sock_ to be buffered. | 727 // sock_ to be buffered. |
718 // The payload from two data frames, each with kMsg3 will be combined | 728 // The payload from two data frames, each with kMsg3 will be combined |
719 // together into a single read(). | 729 // together into a single read(). |
720 AssertSyncReadEquals(kMsg33, kLen33); | 730 AssertSyncReadEquals(kMsg33, kLen33); |
721 } | 731 } |
722 | 732 |
723 TEST_F(SpdyProxyClientSocketTest, MultipleShortReadsThenMoreRead) { | 733 TEST_F(SpdyProxyClientSocketSpdy2Test, MultipleShortReadsThenMoreRead) { |
724 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 734 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
725 MockWrite writes[] = { | 735 MockWrite writes[] = { |
726 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 736 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
727 }; | 737 }; |
728 | 738 |
729 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 739 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
730 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 740 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
731 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); | 741 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); |
732 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 742 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
733 MockRead reads[] = { | 743 MockRead reads[] = { |
(...skipping 11 matching lines...) Expand all Loading... |
745 | 755 |
746 Run(4); // SpdySession consumes the next four reads and sends then to | 756 Run(4); // SpdySession consumes the next four reads and sends then to |
747 // sock_ to be buffered. | 757 // sock_ to be buffered. |
748 AssertSyncReadEquals(kMsg1, kLen1); | 758 AssertSyncReadEquals(kMsg1, kLen1); |
749 // The payload from two data frames, each with kMsg3 will be combined | 759 // The payload from two data frames, each with kMsg3 will be combined |
750 // together into a single read(). | 760 // together into a single read(). |
751 AssertSyncReadEquals(kMsg33, kLen33); | 761 AssertSyncReadEquals(kMsg33, kLen33); |
752 AssertSyncReadEquals(kMsg2, kLen2); | 762 AssertSyncReadEquals(kMsg2, kLen2); |
753 } | 763 } |
754 | 764 |
755 TEST_F(SpdyProxyClientSocketTest, ReadWillSplitDataFromLargeFrame) { | 765 TEST_F(SpdyProxyClientSocketSpdy2Test, ReadWillSplitDataFromLargeFrame) { |
756 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 766 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
757 MockWrite writes[] = { | 767 MockWrite writes[] = { |
758 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 768 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
759 }; | 769 }; |
760 | 770 |
761 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 771 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
762 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 772 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
763 scoped_ptr<spdy::SpdyFrame> msg33(ConstructBodyFrame(kMsg33, kLen33)); | 773 scoped_ptr<spdy::SpdyFrame> msg33(ConstructBodyFrame(kMsg33, kLen33)); |
764 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 774 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
765 MockRead reads[] = { | 775 MockRead reads[] = { |
766 CreateMockRead(*resp, 1, ASYNC), | 776 CreateMockRead(*resp, 1, ASYNC), |
767 CreateMockRead(*msg1, 2, ASYNC), | 777 CreateMockRead(*msg1, 2, ASYNC), |
768 CreateMockRead(*msg33, 3, ASYNC), | 778 CreateMockRead(*msg33, 3, ASYNC), |
769 MockRead(ASYNC, 0, 4), // EOF | 779 MockRead(ASYNC, 0, 4), // EOF |
770 }; | 780 }; |
771 | 781 |
772 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 782 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
773 | 783 |
774 AssertConnectSucceeds(); | 784 AssertConnectSucceeds(); |
775 | 785 |
776 Run(2); // SpdySession consumes the next two reads and sends then to | 786 Run(2); // SpdySession consumes the next two reads and sends then to |
777 // sock_ to be buffered. | 787 // sock_ to be buffered. |
778 AssertSyncReadEquals(kMsg1, kLen1); | 788 AssertSyncReadEquals(kMsg1, kLen1); |
779 // The payload from the single large data frame will be read across | 789 // The payload from the single large data frame will be read across |
780 // two different reads. | 790 // two different reads. |
781 AssertSyncReadEquals(kMsg3, kLen3); | 791 AssertSyncReadEquals(kMsg3, kLen3); |
782 AssertSyncReadEquals(kMsg3, kLen3); | 792 AssertSyncReadEquals(kMsg3, kLen3); |
783 } | 793 } |
784 | 794 |
785 TEST_F(SpdyProxyClientSocketTest, MultipleReadsFromSameLargeFrame) { | 795 TEST_F(SpdyProxyClientSocketSpdy2Test, MultipleReadsFromSameLargeFrame) { |
786 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 796 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
787 MockWrite writes[] = { | 797 MockWrite writes[] = { |
788 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 798 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
789 }; | 799 }; |
790 | 800 |
791 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 801 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
792 scoped_ptr<spdy::SpdyFrame> msg333(ConstructBodyFrame(kMsg333, kLen333)); | 802 scoped_ptr<spdy::SpdyFrame> msg333(ConstructBodyFrame(kMsg333, kLen333)); |
793 MockRead reads[] = { | 803 MockRead reads[] = { |
794 CreateMockRead(*resp, 1, ASYNC), | 804 CreateMockRead(*resp, 1, ASYNC), |
795 CreateMockRead(*msg333, 2, ASYNC), | 805 CreateMockRead(*msg333, 2, ASYNC), |
(...skipping 10 matching lines...) Expand all Loading... |
806 // two different reads. | 816 // two different reads. |
807 AssertSyncReadEquals(kMsg33, kLen33); | 817 AssertSyncReadEquals(kMsg33, kLen33); |
808 | 818 |
809 // Now attempt to do a read of more data than remains buffered | 819 // Now attempt to do a read of more data than remains buffered |
810 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen33)); | 820 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen33)); |
811 ASSERT_EQ(kLen3, sock_->Read(buf, kLen33, read_callback_.callback())); | 821 ASSERT_EQ(kLen3, sock_->Read(buf, kLen33, read_callback_.callback())); |
812 ASSERT_EQ(std::string(kMsg3, kLen3), std::string(buf->data(), kLen3)); | 822 ASSERT_EQ(std::string(kMsg3, kLen3), std::string(buf->data(), kLen3)); |
813 ASSERT_TRUE(sock_->IsConnected()); | 823 ASSERT_TRUE(sock_->IsConnected()); |
814 } | 824 } |
815 | 825 |
816 TEST_F(SpdyProxyClientSocketTest, ReadAuthResponseBody) { | 826 TEST_F(SpdyProxyClientSocketSpdy2Test, ReadAuthResponseBody) { |
817 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 827 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
818 MockWrite writes[] = { | 828 MockWrite writes[] = { |
819 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 829 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
820 }; | 830 }; |
821 | 831 |
822 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectAuthReplyFrame()); | 832 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectAuthReplyFrame()); |
823 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 833 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
824 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 834 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
825 MockRead reads[] = { | 835 MockRead reads[] = { |
826 CreateMockRead(*resp, 1, ASYNC), | 836 CreateMockRead(*resp, 1, ASYNC), |
827 CreateMockRead(*msg1, 2, ASYNC), | 837 CreateMockRead(*msg1, 2, ASYNC), |
828 CreateMockRead(*msg2, 3, ASYNC), | 838 CreateMockRead(*msg2, 3, ASYNC), |
829 MockRead(ASYNC, 0, 4), // EOF | 839 MockRead(ASYNC, 0, 4), // EOF |
830 }; | 840 }; |
831 | 841 |
832 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 842 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
833 | 843 |
834 AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); | 844 AssertConnectFails(ERR_PROXY_AUTH_REQUESTED); |
835 | 845 |
836 Run(2); // SpdySession consumes the next two reads and sends then to | 846 Run(2); // SpdySession consumes the next two reads and sends then to |
837 // sock_ to be buffered. | 847 // sock_ to be buffered. |
838 AssertSyncReadEquals(kMsg1, kLen1); | 848 AssertSyncReadEquals(kMsg1, kLen1); |
839 AssertSyncReadEquals(kMsg2, kLen2); | 849 AssertSyncReadEquals(kMsg2, kLen2); |
840 } | 850 } |
841 | 851 |
842 TEST_F(SpdyProxyClientSocketTest, ReadErrorResponseBody) { | 852 TEST_F(SpdyProxyClientSocketSpdy2Test, ReadErrorResponseBody) { |
843 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 853 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
844 MockWrite writes[] = { | 854 MockWrite writes[] = { |
845 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 855 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
846 }; | 856 }; |
847 | 857 |
848 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectErrorReplyFrame()); | 858 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectErrorReplyFrame()); |
849 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 859 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
850 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 860 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
851 MockRead reads[] = { | 861 MockRead reads[] = { |
852 CreateMockRead(*resp, 1, ASYNC), | 862 CreateMockRead(*resp, 1, ASYNC), |
(...skipping 10 matching lines...) Expand all Loading... |
863 // sock_ to be buffered. | 873 // sock_ to be buffered. |
864 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, | 874 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, |
865 sock_->Read(NULL, 1, CompletionCallback())); | 875 sock_->Read(NULL, 1, CompletionCallback())); |
866 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1 + kLen2)); | 876 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1 + kLen2)); |
867 scoped_ptr<HttpStream> stream(sock_->CreateConnectResponseStream()); | 877 scoped_ptr<HttpStream> stream(sock_->CreateConnectResponseStream()); |
868 stream->ReadResponseBody(buf, kLen1 + kLen2, read_callback_.callback()); | 878 stream->ReadResponseBody(buf, kLen1 + kLen2, read_callback_.callback()); |
869 } | 879 } |
870 | 880 |
871 // ----------- Reads and Writes | 881 // ----------- Reads and Writes |
872 | 882 |
873 TEST_F(SpdyProxyClientSocketTest, AsyncReadAroundWrite) { | 883 TEST_F(SpdyProxyClientSocketSpdy2Test, AsyncReadAroundWrite) { |
874 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 884 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
875 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 885 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
876 MockWrite writes[] = { | 886 MockWrite writes[] = { |
877 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 887 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
878 CreateMockWrite(*msg2, 3, SYNCHRONOUS), | 888 CreateMockWrite(*msg2, 3, SYNCHRONOUS), |
879 }; | 889 }; |
880 | 890 |
881 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 891 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
882 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 892 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
883 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); | 893 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); |
(...skipping 15 matching lines...) Expand all Loading... |
899 // Read should block until after the write succeeds | 909 // Read should block until after the write succeeds |
900 | 910 |
901 AssertAsyncWriteSucceeds(kMsg2, kLen2); // Runs 1 step | 911 AssertAsyncWriteSucceeds(kMsg2, kLen2); // Runs 1 step |
902 | 912 |
903 ASSERT_FALSE(read_callback_.have_result()); | 913 ASSERT_FALSE(read_callback_.have_result()); |
904 Run(1); | 914 Run(1); |
905 // Now the read will return | 915 // Now the read will return |
906 AssertReadReturns(kMsg3, kLen3); | 916 AssertReadReturns(kMsg3, kLen3); |
907 } | 917 } |
908 | 918 |
909 TEST_F(SpdyProxyClientSocketTest, AsyncWriteAroundReads) { | 919 TEST_F(SpdyProxyClientSocketSpdy2Test, AsyncWriteAroundReads) { |
910 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 920 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
911 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); | 921 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); |
912 MockWrite writes[] = { | 922 MockWrite writes[] = { |
913 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 923 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
914 CreateMockWrite(*msg2, 4, ASYNC), | 924 CreateMockWrite(*msg2, 4, ASYNC), |
915 }; | 925 }; |
916 | 926 |
917 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 927 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
918 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 928 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
919 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); | 929 scoped_ptr<spdy::SpdyFrame> msg3(ConstructBodyFrame(kMsg3, kLen3)); |
(...skipping 18 matching lines...) Expand all Loading... |
938 ASSERT_FALSE(write_callback_.have_result()); | 948 ASSERT_FALSE(write_callback_.have_result()); |
939 | 949 |
940 // Now the write will complete | 950 // Now the write will complete |
941 Run(1); | 951 Run(1); |
942 AssertWriteLength(kLen2); | 952 AssertWriteLength(kLen2); |
943 } | 953 } |
944 | 954 |
945 // ----------- Reading/Writing on Closed socket | 955 // ----------- Reading/Writing on Closed socket |
946 | 956 |
947 // Reading from an already closed socket should return 0 | 957 // Reading from an already closed socket should return 0 |
948 TEST_F(SpdyProxyClientSocketTest, ReadOnClosedSocketReturnsZero) { | 958 TEST_F(SpdyProxyClientSocketSpdy2Test, ReadOnClosedSocketReturnsZero) { |
949 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 959 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
950 MockWrite writes[] = { | 960 MockWrite writes[] = { |
951 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 961 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
952 }; | 962 }; |
953 | 963 |
954 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 964 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
955 MockRead reads[] = { | 965 MockRead reads[] = { |
956 CreateMockRead(*resp, 1, ASYNC), | 966 CreateMockRead(*resp, 1, ASYNC), |
957 MockRead(ASYNC, 0, 2), // EOF | 967 MockRead(ASYNC, 0, 2), // EOF |
958 }; | 968 }; |
959 | 969 |
960 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 970 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
961 | 971 |
962 AssertConnectSucceeds(); | 972 AssertConnectSucceeds(); |
963 | 973 |
964 Run(1); | 974 Run(1); |
965 | 975 |
966 ASSERT_FALSE(sock_->IsConnected()); | 976 ASSERT_FALSE(sock_->IsConnected()); |
967 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); | 977 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); |
968 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); | 978 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); |
969 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); | 979 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); |
970 ASSERT_FALSE(sock_->IsConnectedAndIdle()); | 980 ASSERT_FALSE(sock_->IsConnectedAndIdle()); |
971 } | 981 } |
972 | 982 |
973 // Read pending when socket is closed should return 0 | 983 // Read pending when socket is closed should return 0 |
974 TEST_F(SpdyProxyClientSocketTest, PendingReadOnCloseReturnsZero) { | 984 TEST_F(SpdyProxyClientSocketSpdy2Test, PendingReadOnCloseReturnsZero) { |
975 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 985 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
976 MockWrite writes[] = { | 986 MockWrite writes[] = { |
977 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 987 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
978 }; | 988 }; |
979 | 989 |
980 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 990 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
981 MockRead reads[] = { | 991 MockRead reads[] = { |
982 CreateMockRead(*resp, 1, ASYNC), | 992 CreateMockRead(*resp, 1, ASYNC), |
983 MockRead(ASYNC, 0, 2), // EOF | 993 MockRead(ASYNC, 0, 2), // EOF |
984 }; | 994 }; |
985 | 995 |
986 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 996 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
987 | 997 |
988 AssertConnectSucceeds(); | 998 AssertConnectSucceeds(); |
989 | 999 |
990 AssertReadStarts(kMsg1, kLen1); | 1000 AssertReadStarts(kMsg1, kLen1); |
991 | 1001 |
992 Run(1); | 1002 Run(1); |
993 | 1003 |
994 ASSERT_EQ(0, read_callback_.WaitForResult()); | 1004 ASSERT_EQ(0, read_callback_.WaitForResult()); |
995 } | 1005 } |
996 | 1006 |
997 // Reading from a disconnected socket is an error | 1007 // Reading from a disconnected socket is an error |
998 TEST_F(SpdyProxyClientSocketTest, ReadOnDisconnectSocketReturnsNotConnected) { | 1008 TEST_F(SpdyProxyClientSocketSpdy2Test, |
| 1009 ReadOnDisconnectSocketReturnsNotConnected) { |
999 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1010 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1000 MockWrite writes[] = { | 1011 MockWrite writes[] = { |
1001 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1012 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1002 }; | 1013 }; |
1003 | 1014 |
1004 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1015 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1005 MockRead reads[] = { | 1016 MockRead reads[] = { |
1006 CreateMockRead(*resp, 1, ASYNC), | 1017 CreateMockRead(*resp, 1, ASYNC), |
1007 MockRead(ASYNC, 0, 2), // EOF | 1018 MockRead(ASYNC, 0, 2), // EOF |
1008 }; | 1019 }; |
1009 | 1020 |
1010 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1021 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
1011 | 1022 |
1012 AssertConnectSucceeds(); | 1023 AssertConnectSucceeds(); |
1013 | 1024 |
1014 sock_->Disconnect(); | 1025 sock_->Disconnect(); |
1015 | 1026 |
1016 ASSERT_EQ(ERR_SOCKET_NOT_CONNECTED, | 1027 ASSERT_EQ(ERR_SOCKET_NOT_CONNECTED, |
1017 sock_->Read(NULL, 1, CompletionCallback())); | 1028 sock_->Read(NULL, 1, CompletionCallback())); |
1018 } | 1029 } |
1019 | 1030 |
1020 // Reading buffered data from an already closed socket should return | 1031 // Reading buffered data from an already closed socket should return |
1021 // buffered data, then 0. | 1032 // buffered data, then 0. |
1022 TEST_F(SpdyProxyClientSocketTest, ReadOnClosedSocketReturnsBufferedData) { | 1033 TEST_F(SpdyProxyClientSocketSpdy2Test, ReadOnClosedSocketReturnsBufferedData) { |
1023 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1034 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1024 MockWrite writes[] = { | 1035 MockWrite writes[] = { |
1025 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1036 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1026 }; | 1037 }; |
1027 | 1038 |
1028 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1039 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1029 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 1040 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
1030 MockRead reads[] = { | 1041 MockRead reads[] = { |
1031 CreateMockRead(*resp, 1, ASYNC), | 1042 CreateMockRead(*resp, 1, ASYNC), |
1032 CreateMockRead(*msg1, 2, ASYNC), | 1043 CreateMockRead(*msg1, 2, ASYNC), |
(...skipping 12 matching lines...) Expand all Loading... |
1045 ASSERT_EQ(std::string(kMsg1, kLen1), std::string(buf->data(), kLen1)); | 1056 ASSERT_EQ(std::string(kMsg1, kLen1), std::string(buf->data(), kLen1)); |
1046 | 1057 |
1047 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); | 1058 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); |
1048 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); | 1059 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); |
1049 sock_->Disconnect(); | 1060 sock_->Disconnect(); |
1050 ASSERT_EQ(ERR_SOCKET_NOT_CONNECTED, | 1061 ASSERT_EQ(ERR_SOCKET_NOT_CONNECTED, |
1051 sock_->Read(NULL, 1, CompletionCallback())); | 1062 sock_->Read(NULL, 1, CompletionCallback())); |
1052 } | 1063 } |
1053 | 1064 |
1054 // Calling Write() on a closed socket is an error | 1065 // Calling Write() on a closed socket is an error |
1055 TEST_F(SpdyProxyClientSocketTest, WriteOnClosedStream) { | 1066 TEST_F(SpdyProxyClientSocketSpdy2Test, WriteOnClosedStream) { |
1056 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1067 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1057 MockWrite writes[] = { | 1068 MockWrite writes[] = { |
1058 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1069 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1059 }; | 1070 }; |
1060 | 1071 |
1061 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1072 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1062 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 1073 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
1063 MockRead reads[] = { | 1074 MockRead reads[] = { |
1064 CreateMockRead(*resp, 1, ASYNC), | 1075 CreateMockRead(*resp, 1, ASYNC), |
1065 MockRead(ASYNC, 0, 2), // EOF | 1076 MockRead(ASYNC, 0, 2), // EOF |
1066 }; | 1077 }; |
1067 | 1078 |
1068 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1079 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
1069 | 1080 |
1070 AssertConnectSucceeds(); | 1081 AssertConnectSucceeds(); |
1071 | 1082 |
1072 Run(1); // Read EOF which will close the stream | 1083 Run(1); // Read EOF which will close the stream |
1073 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); | 1084 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); |
1074 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, | 1085 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, |
1075 sock_->Write(buf, buf->size(), CompletionCallback())); | 1086 sock_->Write(buf, buf->size(), CompletionCallback())); |
1076 } | 1087 } |
1077 | 1088 |
1078 // Calling Write() on a disconnected socket is an error | 1089 // Calling Write() on a disconnected socket is an error |
1079 TEST_F(SpdyProxyClientSocketTest, WriteOnDisconnectedSocket) { | 1090 TEST_F(SpdyProxyClientSocketSpdy2Test, WriteOnDisconnectedSocket) { |
1080 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1091 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1081 MockWrite writes[] = { | 1092 MockWrite writes[] = { |
1082 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1093 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1083 }; | 1094 }; |
1084 | 1095 |
1085 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1096 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1086 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); | 1097 scoped_ptr<spdy::SpdyFrame> msg1(ConstructBodyFrame(kMsg1, kLen1)); |
1087 MockRead reads[] = { | 1098 MockRead reads[] = { |
1088 CreateMockRead(*resp, 1, ASYNC), | 1099 CreateMockRead(*resp, 1, ASYNC), |
1089 MockRead(ASYNC, 0, 2), // EOF | 1100 MockRead(ASYNC, 0, 2), // EOF |
1090 }; | 1101 }; |
1091 | 1102 |
1092 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1103 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
1093 | 1104 |
1094 AssertConnectSucceeds(); | 1105 AssertConnectSucceeds(); |
1095 | 1106 |
1096 sock_->Disconnect(); | 1107 sock_->Disconnect(); |
1097 | 1108 |
1098 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); | 1109 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); |
1099 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, | 1110 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, |
1100 sock_->Write(buf, buf->size(), CompletionCallback())); | 1111 sock_->Write(buf, buf->size(), CompletionCallback())); |
1101 } | 1112 } |
1102 | 1113 |
1103 // If the socket is closed with a pending Write(), the callback | 1114 // If the socket is closed with a pending Write(), the callback |
1104 // should be called with ERR_CONNECTION_CLOSED. | 1115 // should be called with ERR_CONNECTION_CLOSED. |
1105 TEST_F(SpdyProxyClientSocketTest, WritePendingOnClose) { | 1116 TEST_F(SpdyProxyClientSocketSpdy2Test, WritePendingOnClose) { |
1106 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1117 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1107 MockWrite writes[] = { | 1118 MockWrite writes[] = { |
1108 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1119 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1109 MockWrite(ASYNC, ERR_IO_PENDING, 2), | 1120 MockWrite(ASYNC, ERR_IO_PENDING, 2), |
1110 }; | 1121 }; |
1111 | 1122 |
1112 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1123 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1113 MockRead reads[] = { | 1124 MockRead reads[] = { |
1114 CreateMockRead(*resp, 1, ASYNC), | 1125 CreateMockRead(*resp, 1, ASYNC), |
1115 MockRead(ASYNC, 0, 3), // EOF | 1126 MockRead(ASYNC, 0, 3), // EOF |
1116 }; | 1127 }; |
1117 | 1128 |
1118 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1129 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
1119 | 1130 |
1120 AssertConnectSucceeds(); | 1131 AssertConnectSucceeds(); |
1121 | 1132 |
1122 EXPECT_TRUE(sock_->IsConnected()); | 1133 EXPECT_TRUE(sock_->IsConnected()); |
1123 | 1134 |
1124 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); | 1135 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); |
1125 EXPECT_EQ(ERR_IO_PENDING, | 1136 EXPECT_EQ(ERR_IO_PENDING, |
1126 sock_->Write(buf, buf->size(), write_callback_.callback())); | 1137 sock_->Write(buf, buf->size(), write_callback_.callback())); |
1127 | 1138 |
1128 Run(1); | 1139 Run(1); |
1129 | 1140 |
1130 EXPECT_EQ(ERR_CONNECTION_CLOSED, write_callback_.WaitForResult()); | 1141 EXPECT_EQ(ERR_CONNECTION_CLOSED, write_callback_.WaitForResult()); |
1131 } | 1142 } |
1132 | 1143 |
1133 // If the socket is Disconnected with a pending Write(), the callback | 1144 // If the socket is Disconnected with a pending Write(), the callback |
1134 // should not be called. | 1145 // should not be called. |
1135 TEST_F(SpdyProxyClientSocketTest, DisconnectWithWritePending) { | 1146 TEST_F(SpdyProxyClientSocketSpdy2Test, DisconnectWithWritePending) { |
1136 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1147 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1137 MockWrite writes[] = { | 1148 MockWrite writes[] = { |
1138 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1149 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1139 MockWrite(SYNCHRONOUS, 0, 2), // EOF | 1150 MockWrite(SYNCHRONOUS, 0, 2), // EOF |
1140 }; | 1151 }; |
1141 | 1152 |
1142 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1153 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1143 MockRead reads[] = { | 1154 MockRead reads[] = { |
1144 CreateMockRead(*resp, 1, ASYNC), | 1155 CreateMockRead(*resp, 1, ASYNC), |
1145 MockRead(ASYNC, 0, 3), // EOF | 1156 MockRead(ASYNC, 0, 3), // EOF |
(...skipping 10 matching lines...) Expand all Loading... |
1156 sock_->Write(buf, buf->size(), write_callback_.callback())); | 1167 sock_->Write(buf, buf->size(), write_callback_.callback())); |
1157 | 1168 |
1158 sock_->Disconnect(); | 1169 sock_->Disconnect(); |
1159 | 1170 |
1160 EXPECT_FALSE(sock_->IsConnected()); | 1171 EXPECT_FALSE(sock_->IsConnected()); |
1161 EXPECT_FALSE(write_callback_.have_result()); | 1172 EXPECT_FALSE(write_callback_.have_result()); |
1162 } | 1173 } |
1163 | 1174 |
1164 // If the socket is Disconnected with a pending Read(), the callback | 1175 // If the socket is Disconnected with a pending Read(), the callback |
1165 // should not be called. | 1176 // should not be called. |
1166 TEST_F(SpdyProxyClientSocketTest, DisconnectWithReadPending) { | 1177 TEST_F(SpdyProxyClientSocketSpdy2Test, DisconnectWithReadPending) { |
1167 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1178 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1168 MockWrite writes[] = { | 1179 MockWrite writes[] = { |
1169 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1180 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1170 }; | 1181 }; |
1171 | 1182 |
1172 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1183 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1173 MockRead reads[] = { | 1184 MockRead reads[] = { |
1174 CreateMockRead(*resp, 1, ASYNC), | 1185 CreateMockRead(*resp, 1, ASYNC), |
1175 MockRead(ASYNC, 0, 2), // EOF | 1186 MockRead(ASYNC, 0, 2), // EOF |
1176 }; | 1187 }; |
1177 | 1188 |
1178 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1189 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
1179 | 1190 |
1180 AssertConnectSucceeds(); | 1191 AssertConnectSucceeds(); |
1181 | 1192 |
1182 EXPECT_TRUE(sock_->IsConnected()); | 1193 EXPECT_TRUE(sock_->IsConnected()); |
1183 | 1194 |
1184 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1)); | 1195 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1)); |
1185 ASSERT_EQ(ERR_IO_PENDING, | 1196 ASSERT_EQ(ERR_IO_PENDING, |
1186 sock_->Read(buf, kLen1, read_callback_.callback())); | 1197 sock_->Read(buf, kLen1, read_callback_.callback())); |
1187 | 1198 |
1188 sock_->Disconnect(); | 1199 sock_->Disconnect(); |
1189 | 1200 |
1190 EXPECT_FALSE(sock_->IsConnected()); | 1201 EXPECT_FALSE(sock_->IsConnected()); |
1191 EXPECT_FALSE(read_callback_.have_result()); | 1202 EXPECT_FALSE(read_callback_.have_result()); |
1192 } | 1203 } |
1193 | 1204 |
1194 // If the socket is Reset when both a read and write are pending, | 1205 // If the socket is Reset when both a read and write are pending, |
1195 // both should be called back. | 1206 // both should be called back. |
1196 TEST_F(SpdyProxyClientSocketTest, RstWithReadAndWritePending) { | 1207 TEST_F(SpdyProxyClientSocketSpdy2Test, RstWithReadAndWritePending) { |
1197 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1208 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1198 MockWrite writes[] = { | 1209 MockWrite writes[] = { |
1199 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1210 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1200 MockWrite(ASYNC, ERR_IO_PENDING, 2), | 1211 MockWrite(ASYNC, ERR_IO_PENDING, 2), |
1201 }; | 1212 }; |
1202 | 1213 |
1203 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1214 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1204 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL)); | 1215 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL)); |
1205 MockRead reads[] = { | 1216 MockRead reads[] = { |
1206 CreateMockRead(*resp, 1, ASYNC), | 1217 CreateMockRead(*resp, 1, ASYNC), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 | 1264 |
1254 scoped_ptr<SpdyProxyClientSocket>* sock_; | 1265 scoped_ptr<SpdyProxyClientSocket>* sock_; |
1255 CompletionCallback callback_; | 1266 CompletionCallback callback_; |
1256 | 1267 |
1257 DISALLOW_COPY_AND_ASSIGN(DeleteSockCallback); | 1268 DISALLOW_COPY_AND_ASSIGN(DeleteSockCallback); |
1258 }; | 1269 }; |
1259 | 1270 |
1260 // If the socket is Reset when both a read and write are pending, and the | 1271 // 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 | 1272 // read callback causes the socket to be deleted, the write callback should |
1262 // not be called. | 1273 // not be called. |
1263 TEST_F(SpdyProxyClientSocketTest, RstWithReadAndWritePendingDelete) { | 1274 TEST_F(SpdyProxyClientSocketSpdy2Test, RstWithReadAndWritePendingDelete) { |
1264 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); | 1275 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); |
1265 MockWrite writes[] = { | 1276 MockWrite writes[] = { |
1266 CreateMockWrite(*conn, 0, SYNCHRONOUS), | 1277 CreateMockWrite(*conn, 0, SYNCHRONOUS), |
1267 MockWrite(ASYNC, ERR_IO_PENDING, 2), | 1278 MockWrite(ASYNC, ERR_IO_PENDING, 2), |
1268 }; | 1279 }; |
1269 | 1280 |
1270 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); | 1281 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); |
1271 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL)); | 1282 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL)); |
1272 MockRead reads[] = { | 1283 MockRead reads[] = { |
1273 CreateMockRead(*resp, 1, ASYNC), | 1284 CreateMockRead(*resp, 1, ASYNC), |
(...skipping 17 matching lines...) Expand all Loading... |
1291 write_callback_.callback())); | 1302 write_callback_.callback())); |
1292 | 1303 |
1293 Run(2); | 1304 Run(2); |
1294 | 1305 |
1295 EXPECT_FALSE(sock_.get()); | 1306 EXPECT_FALSE(sock_.get()); |
1296 EXPECT_TRUE(read_callback.have_result()); | 1307 EXPECT_TRUE(read_callback.have_result()); |
1297 EXPECT_FALSE(write_callback_.have_result()); | 1308 EXPECT_FALSE(write_callback_.have_result()); |
1298 } | 1309 } |
1299 | 1310 |
1300 } // namespace net | 1311 } // namespace net |
OLD | NEW |