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/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 11218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11229 EXPECT_EQ(ERR_IO_PENDING, | 11229 EXPECT_EQ(ERR_IO_PENDING, |
11230 trans2.Start(&request2, callback2.callback(), BoundNetLog())); | 11230 trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
11231 MessageLoop::current()->RunUntilIdle(); | 11231 MessageLoop::current()->RunUntilIdle(); |
11232 data2->RunFor(3); | 11232 data2->RunFor(3); |
11233 | 11233 |
11234 ASSERT_TRUE(callback2.have_result()); | 11234 ASSERT_TRUE(callback2.have_result()); |
11235 EXPECT_EQ(OK, callback2.WaitForResult()); | 11235 EXPECT_EQ(OK, callback2.WaitForResult()); |
11236 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); | 11236 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
11237 } | 11237 } |
11238 | 11238 |
| 11239 // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 11240 // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 11241 // session. Verify that new url's from the same HttpNetworkSession do work. |
| 11242 // http://crbug.com/224701 |
| 11243 TEST_F(HttpNetworkTransactionSpdy3Test, ErrorSocketNotConnected) { |
| 11244 const std::string https_url = "https://www.google.com/"; |
| 11245 |
| 11246 MockRead reads1[] = { |
| 11247 MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 11248 }; |
| 11249 |
| 11250 scoped_ptr<DeterministicSocketData> data1( |
| 11251 new DeterministicSocketData(reads1, arraysize(reads1), NULL, 0)); |
| 11252 data1->SetStop(1); |
| 11253 |
| 11254 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(https_url.c_str(), |
| 11255 false, 1, MEDIUM)); |
| 11256 MockWrite writes2[] = { |
| 11257 CreateMockWrite(*req2, 0), |
| 11258 }; |
| 11259 |
| 11260 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11261 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(1, true)); |
| 11262 MockRead reads2[] = { |
| 11263 CreateMockRead(*resp2, 1), |
| 11264 CreateMockRead(*body2, 2), |
| 11265 MockRead(ASYNC, OK, 3) // EOF |
| 11266 }; |
| 11267 |
| 11268 scoped_ptr<DeterministicSocketData> data2( |
| 11269 new DeterministicSocketData(reads2, arraysize(reads2), |
| 11270 writes2, arraysize(writes2))); |
| 11271 |
| 11272 SpdySessionDependencies session_deps; |
| 11273 SSLSocketDataProvider ssl1(ASYNC, OK); |
| 11274 ssl1.SetNextProto(kProtoSPDY3); |
| 11275 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11276 session_deps.deterministic_socket_factory->AddSocketDataProvider(data1.get()); |
| 11277 |
| 11278 SSLSocketDataProvider ssl2(ASYNC, OK); |
| 11279 ssl2.SetNextProto(kProtoSPDY3); |
| 11280 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11281 session_deps.deterministic_socket_factory->AddSocketDataProvider(data2.get()); |
| 11282 |
| 11283 scoped_refptr<HttpNetworkSession> session( |
| 11284 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps)); |
| 11285 |
| 11286 // Start the first transaction to set up the SpdySession and verify that |
| 11287 // connection was closed. |
| 11288 HttpRequestInfo request1; |
| 11289 request1.method = "GET"; |
| 11290 request1.url = GURL(https_url); |
| 11291 request1.load_flags = 0; |
| 11292 HttpNetworkTransaction trans1(MEDIUM, session); |
| 11293 TestCompletionCallback callback1; |
| 11294 EXPECT_EQ(ERR_IO_PENDING, |
| 11295 trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 11296 MessageLoop::current()->RunUntilIdle(); |
| 11297 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 11298 |
| 11299 // Now, start the second request and make sure it succeeds. |
| 11300 HttpRequestInfo request2; |
| 11301 request2.method = "GET"; |
| 11302 request2.url = GURL(https_url); |
| 11303 request2.load_flags = 0; |
| 11304 HttpNetworkTransaction trans2(MEDIUM, session); |
| 11305 TestCompletionCallback callback2; |
| 11306 EXPECT_EQ(ERR_IO_PENDING, |
| 11307 trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
| 11308 MessageLoop::current()->RunUntilIdle(); |
| 11309 data2->RunFor(3); |
| 11310 |
| 11311 ASSERT_TRUE(callback2.have_result()); |
| 11312 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11313 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11314 } |
| 11315 |
11239 } // namespace net | 11316 } // namespace net |
OLD | NEW |