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 11279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11290 EXPECT_EQ(ERR_IO_PENDING, | 11290 EXPECT_EQ(ERR_IO_PENDING, |
11291 trans2.Start(&request2, callback2.callback(), BoundNetLog())); | 11291 trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
11292 MessageLoop::current()->RunUntilIdle(); | 11292 MessageLoop::current()->RunUntilIdle(); |
11293 data2->RunFor(3); | 11293 data2->RunFor(3); |
11294 | 11294 |
11295 ASSERT_TRUE(callback2.have_result()); | 11295 ASSERT_TRUE(callback2.have_result()); |
11296 EXPECT_EQ(OK, callback2.WaitForResult()); | 11296 EXPECT_EQ(OK, callback2.WaitForResult()); |
11297 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); | 11297 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
11298 } | 11298 } |
11299 | 11299 |
| 11300 // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 11301 // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 11302 // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 11303 // SpdySession) do work. http://crbug.com/224701 |
| 11304 TEST_F(HttpNetworkTransactionSpdy2Test, ErrorSocketNotConnected) { |
| 11305 const std::string https_url = "https://www.google.com/"; |
| 11306 |
| 11307 MockRead reads1[] = { |
| 11308 MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 11309 }; |
| 11310 |
| 11311 scoped_ptr<DeterministicSocketData> data1( |
| 11312 new DeterministicSocketData(reads1, arraysize(reads1), NULL, 0)); |
| 11313 data1->SetStop(1); |
| 11314 |
| 11315 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(https_url.c_str(), |
| 11316 false, 1, MEDIUM)); |
| 11317 MockWrite writes2[] = { |
| 11318 CreateMockWrite(*req2, 0), |
| 11319 }; |
| 11320 |
| 11321 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11322 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(1, true)); |
| 11323 MockRead reads2[] = { |
| 11324 CreateMockRead(*resp2, 1), |
| 11325 CreateMockRead(*body2, 2), |
| 11326 MockRead(ASYNC, OK, 3) // EOF |
| 11327 }; |
| 11328 |
| 11329 scoped_ptr<DeterministicSocketData> data2( |
| 11330 new DeterministicSocketData(reads2, arraysize(reads2), |
| 11331 writes2, arraysize(writes2))); |
| 11332 |
| 11333 SpdySessionDependencies session_deps; |
| 11334 SSLSocketDataProvider ssl1(ASYNC, OK); |
| 11335 ssl1.SetNextProto(kProtoSPDY2); |
| 11336 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11337 session_deps.deterministic_socket_factory->AddSocketDataProvider(data1.get()); |
| 11338 |
| 11339 SSLSocketDataProvider ssl2(ASYNC, OK); |
| 11340 ssl2.SetNextProto(kProtoSPDY2); |
| 11341 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11342 session_deps.deterministic_socket_factory->AddSocketDataProvider(data2.get()); |
| 11343 |
| 11344 scoped_refptr<HttpNetworkSession> session( |
| 11345 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps)); |
| 11346 |
| 11347 // Start the first transaction to set up the SpdySession and verify that |
| 11348 // connection was closed. |
| 11349 HttpRequestInfo request1; |
| 11350 request1.method = "GET"; |
| 11351 request1.url = GURL(https_url); |
| 11352 request1.load_flags = 0; |
| 11353 HttpNetworkTransaction trans1(MEDIUM, session); |
| 11354 TestCompletionCallback callback1; |
| 11355 EXPECT_EQ(ERR_IO_PENDING, |
| 11356 trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 11357 MessageLoop::current()->RunUntilIdle(); |
| 11358 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 11359 |
| 11360 // Now, start the second request and make sure it succeeds. |
| 11361 HttpRequestInfo request2; |
| 11362 request2.method = "GET"; |
| 11363 request2.url = GURL(https_url); |
| 11364 request2.load_flags = 0; |
| 11365 HttpNetworkTransaction trans2(MEDIUM, session); |
| 11366 TestCompletionCallback callback2; |
| 11367 EXPECT_EQ(ERR_IO_PENDING, |
| 11368 trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
| 11369 MessageLoop::current()->RunUntilIdle(); |
| 11370 data2->RunFor(3); |
| 11371 |
| 11372 ASSERT_TRUE(callback2.have_result()); |
| 11373 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11374 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11375 } |
| 11376 |
11300 } // namespace net | 11377 } // namespace net |
OLD | NEW |