| 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_session.h" | 5 #include "net/spdy/spdy_session.h" |
| 6 | 6 |
| 7 #include "net/base/host_cache.h" | 7 #include "net/base/host_cache.h" |
| 8 #include "net/base/ip_endpoint.h" | 8 #include "net/base/ip_endpoint.h" |
| 9 #include "net/base/net_log_unittest.h" | 9 #include "net/base/net_log_unittest.h" |
| 10 #include "net/spdy/spdy_io_buffer.h" | 10 #include "net/spdy/spdy_io_buffer.h" |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 session->set_hung_interval(base::TimeDelta::FromSeconds(0)); | 323 session->set_hung_interval(base::TimeDelta::FromSeconds(0)); |
| 324 | 324 |
| 325 // Send a PING frame. | 325 // Send a PING frame. |
| 326 session->WritePingFrame(1); | 326 session->WritePingFrame(1); |
| 327 EXPECT_LT(0, session->pings_in_flight()); | 327 EXPECT_LT(0, session->pings_in_flight()); |
| 328 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); | 328 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); |
| 329 EXPECT_TRUE(session->check_ping_status_pending()); | 329 EXPECT_TRUE(session->check_ping_status_pending()); |
| 330 | 330 |
| 331 // Assert session is not closed. | 331 // Assert session is not closed. |
| 332 EXPECT_FALSE(session->IsClosed()); | 332 EXPECT_FALSE(session->IsClosed()); |
| 333 EXPECT_LT(0u, session->num_active_streams()); | 333 EXPECT_LT(0u, session->num_active_streams() + session->num_created_streams()); |
| 334 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); | 334 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); |
| 335 | 335 |
| 336 // We set last time we have received any data in 1 sec less than now. | 336 // We set last time we have received any data in 1 sec less than now. |
| 337 // CheckPingStatus will trigger timeout because hung interval is zero. | 337 // CheckPingStatus will trigger timeout because hung interval is zero. |
| 338 base::TimeTicks now = base::TimeTicks::Now(); | 338 base::TimeTicks now = base::TimeTicks::Now(); |
| 339 session->last_activity_time_ = now - base::TimeDelta::FromSeconds(1); | 339 session->last_activity_time_ = now - base::TimeDelta::FromSeconds(1); |
| 340 session->CheckPingStatus(now); | 340 session->CheckPingStatus(now); |
| 341 | 341 |
| 342 EXPECT_TRUE(session->IsClosed()); | 342 EXPECT_TRUE(session->IsClosed()); |
| 343 EXPECT_EQ(0u, session->num_active_streams()); | 343 EXPECT_EQ(0u, session->num_active_streams()); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 spdy_session_pool->CloseIdleSessions(); | 443 spdy_session_pool->CloseIdleSessions(); |
| 444 EXPECT_TRUE(session1->is_active()); | 444 EXPECT_TRUE(session1->is_active()); |
| 445 EXPECT_FALSE(session1->IsClosed()); | 445 EXPECT_FALSE(session1->IsClosed()); |
| 446 EXPECT_TRUE(session2->is_active()); | 446 EXPECT_TRUE(session2->is_active()); |
| 447 EXPECT_FALSE(session2->IsClosed()); | 447 EXPECT_FALSE(session2->IsClosed()); |
| 448 EXPECT_TRUE(session3->is_active()); | 448 EXPECT_TRUE(session3->is_active()); |
| 449 EXPECT_FALSE(session3->IsClosed()); | 449 EXPECT_FALSE(session3->IsClosed()); |
| 450 | 450 |
| 451 // Make sessions 1 and 3 inactive, but keep them open. | 451 // Make sessions 1 and 3 inactive, but keep them open. |
| 452 // Session 2 still open and active | 452 // Session 2 still open and active |
| 453 session1->CloseStream(spdy_stream1->stream_id(), OK); | 453 session1->CloseCreatedStream(spdy_stream1, OK); |
| 454 session3->CloseStream(spdy_stream3->stream_id(), OK); | 454 session3->CloseCreatedStream(spdy_stream3, OK); |
| 455 EXPECT_FALSE(session1->is_active()); | 455 EXPECT_FALSE(session1->is_active()); |
| 456 EXPECT_FALSE(session1->IsClosed()); | 456 EXPECT_FALSE(session1->IsClosed()); |
| 457 EXPECT_TRUE(session2->is_active()); | 457 EXPECT_TRUE(session2->is_active()); |
| 458 EXPECT_FALSE(session2->IsClosed()); | 458 EXPECT_FALSE(session2->IsClosed()); |
| 459 EXPECT_FALSE(session3->is_active()); | 459 EXPECT_FALSE(session3->is_active()); |
| 460 EXPECT_FALSE(session3->IsClosed()); | 460 EXPECT_FALSE(session3->IsClosed()); |
| 461 | 461 |
| 462 // Should close session 1 and 3, 2 should be left open | 462 // Should close session 1 and 3, 2 should be left open |
| 463 spdy_session_pool->CloseIdleSessions(); | 463 spdy_session_pool->CloseIdleSessions(); |
| 464 EXPECT_FALSE(session1->is_active()); | 464 EXPECT_FALSE(session1->is_active()); |
| 465 EXPECT_TRUE(session1->IsClosed()); | 465 EXPECT_TRUE(session1->IsClosed()); |
| 466 EXPECT_TRUE(session2->is_active()); | 466 EXPECT_TRUE(session2->is_active()); |
| 467 EXPECT_FALSE(session2->IsClosed()); | 467 EXPECT_FALSE(session2->IsClosed()); |
| 468 EXPECT_FALSE(session3->is_active()); | 468 EXPECT_FALSE(session3->is_active()); |
| 469 EXPECT_TRUE(session3->IsClosed()); | 469 EXPECT_TRUE(session3->IsClosed()); |
| 470 | 470 |
| 471 // Should not do anything | 471 // Should not do anything |
| 472 spdy_session_pool->CloseIdleSessions(); | 472 spdy_session_pool->CloseIdleSessions(); |
| 473 EXPECT_TRUE(session2->is_active()); | 473 EXPECT_TRUE(session2->is_active()); |
| 474 EXPECT_FALSE(session2->IsClosed()); | 474 EXPECT_FALSE(session2->IsClosed()); |
| 475 | 475 |
| 476 // Make 2 not active | 476 // Make 2 not active |
| 477 session2->CloseStream(spdy_stream2->stream_id(), OK); | 477 session2->CloseCreatedStream(spdy_stream2, OK); |
| 478 EXPECT_FALSE(session2->is_active()); | 478 EXPECT_FALSE(session2->is_active()); |
| 479 EXPECT_FALSE(session2->IsClosed()); | 479 EXPECT_FALSE(session2->IsClosed()); |
| 480 | 480 |
| 481 // This should close session 2 | 481 // This should close session 2 |
| 482 spdy_session_pool->CloseIdleSessions(); | 482 spdy_session_pool->CloseIdleSessions(); |
| 483 EXPECT_FALSE(session2->is_active()); | 483 EXPECT_FALSE(session2->is_active()); |
| 484 EXPECT_TRUE(session2->IsClosed()); | 484 EXPECT_TRUE(session2->IsClosed()); |
| 485 } | 485 } |
| 486 | 486 |
| 487 // Start with max concurrent streams set to 1. Request two streams. Receive a | 487 // Start with max concurrent streams set to 1. Request two streams. Receive a |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 | 1102 |
| 1103 CapturingNetLog::CapturedEntry entry = entries[pos]; | 1103 CapturingNetLog::CapturedEntry entry = entries[pos]; |
| 1104 int error_code = 0; | 1104 int error_code = 0; |
| 1105 ASSERT_TRUE(entry.GetNetErrorCode(&error_code)); | 1105 ASSERT_TRUE(entry.GetNetErrorCode(&error_code)); |
| 1106 EXPECT_EQ(ERR_CONNECTION_CLOSED, error_code); | 1106 EXPECT_EQ(ERR_CONNECTION_CLOSED, error_code); |
| 1107 } | 1107 } |
| 1108 | 1108 |
| 1109 TEST_F(SpdySessionSpdy2Test, OutOfOrderSynStreams) { | 1109 TEST_F(SpdySessionSpdy2Test, OutOfOrderSynStreams) { |
| 1110 // Construct the request. | 1110 // Construct the request. |
| 1111 MockConnect connect_data(SYNCHRONOUS, OK); | 1111 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1112 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 1112 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, HIGHEST)); |
| 1113 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, HIGHEST)); | 1113 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, LOWEST)); |
| 1114 MockWrite writes[] = { | 1114 MockWrite writes[] = { |
| 1115 CreateMockWrite(*req1, 2), | 1115 CreateMockWrite(*req1, 2), |
| 1116 CreateMockWrite(*req2, 1), | 1116 CreateMockWrite(*req2, 1), |
| 1117 }; | 1117 }; |
| 1118 | 1118 |
| 1119 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); | 1119 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1120 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true)); | 1120 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true)); |
| 1121 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); | 1121 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1122 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(3, true)); | 1122 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(3, true)); |
| 1123 MockRead reads[] = { | 1123 MockRead reads[] = { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 http_session->GetTransportSocketPool( | 1167 http_session->GetTransportSocketPool( |
| 1168 HttpNetworkSession::NORMAL_SOCKET_POOL), | 1168 HttpNetworkSession::NORMAL_SOCKET_POOL), |
| 1169 BoundNetLog())); | 1169 BoundNetLog())); |
| 1170 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | 1170 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 1171 | 1171 |
| 1172 scoped_refptr<SpdyStream> spdy_stream1; | 1172 scoped_refptr<SpdyStream> spdy_stream1; |
| 1173 TestCompletionCallback callback1; | 1173 TestCompletionCallback callback1; |
| 1174 GURL url1("http://www.google.com"); | 1174 GURL url1("http://www.google.com"); |
| 1175 EXPECT_EQ(OK, session->CreateStream(url1, LOWEST, &spdy_stream1, | 1175 EXPECT_EQ(OK, session->CreateStream(url1, LOWEST, &spdy_stream1, |
| 1176 BoundNetLog(), callback1.callback())); | 1176 BoundNetLog(), callback1.callback())); |
| 1177 EXPECT_EQ(1u, spdy_stream1->stream_id()); | 1177 EXPECT_EQ(0u, spdy_stream1->stream_id()); |
| 1178 | 1178 |
| 1179 scoped_refptr<SpdyStream> spdy_stream2; | 1179 scoped_refptr<SpdyStream> spdy_stream2; |
| 1180 TestCompletionCallback callback2; | 1180 TestCompletionCallback callback2; |
| 1181 GURL url2("http://www.google.com"); | 1181 GURL url2("http://www.google.com"); |
| 1182 EXPECT_EQ(OK, session->CreateStream(url2, HIGHEST, &spdy_stream2, | 1182 EXPECT_EQ(OK, session->CreateStream(url2, HIGHEST, &spdy_stream2, |
| 1183 BoundNetLog(), callback2.callback())); | 1183 BoundNetLog(), callback2.callback())); |
| 1184 EXPECT_EQ(3u, spdy_stream2->stream_id()); | 1184 EXPECT_EQ(0u, spdy_stream2->stream_id()); |
| 1185 | 1185 |
| 1186 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); | 1186 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); |
| 1187 (*headers)["method"] = "GET"; | 1187 (*headers)["method"] = "GET"; |
| 1188 (*headers)["scheme"] = url1.scheme(); | 1188 (*headers)["scheme"] = url1.scheme(); |
| 1189 (*headers)["host"] = url1.host(); | 1189 (*headers)["host"] = url1.host(); |
| 1190 (*headers)["url"] = url1.path(); | 1190 (*headers)["url"] = url1.path(); |
| 1191 (*headers)["version"] = "HTTP/1.1"; | 1191 (*headers)["version"] = "HTTP/1.1"; |
| 1192 spdy_stream1->set_spdy_headers(headers); | 1192 spdy_stream1->set_spdy_headers(headers); |
| 1193 EXPECT_TRUE(spdy_stream1->HasUrl()); | 1193 EXPECT_TRUE(spdy_stream1->HasUrl()); |
| 1194 | 1194 |
| 1195 spdy_stream2->set_spdy_headers(headers); | 1195 spdy_stream2->set_spdy_headers(headers); |
| 1196 EXPECT_TRUE(spdy_stream2->HasUrl()); | 1196 EXPECT_TRUE(spdy_stream2->HasUrl()); |
| 1197 | 1197 |
| 1198 spdy_stream1->SendRequest(false); | 1198 spdy_stream1->SendRequest(false); |
| 1199 spdy_stream2->SendRequest(false); | 1199 spdy_stream2->SendRequest(false); |
| 1200 MessageLoop::current()->RunAllPending(); | 1200 MessageLoop::current()->RunAllPending(); |
| 1201 | 1201 |
| 1202 EXPECT_EQ(1u, spdy_stream1->stream_id()); | 1202 EXPECT_EQ(3u, spdy_stream1->stream_id()); |
| 1203 EXPECT_EQ(3u, spdy_stream2->stream_id()); | 1203 EXPECT_EQ(1u, spdy_stream2->stream_id()); |
| 1204 | 1204 |
| 1205 spdy_stream1->Cancel(); | 1205 spdy_stream1->Cancel(); |
| 1206 spdy_stream1 = NULL; | 1206 spdy_stream1 = NULL; |
| 1207 | 1207 |
| 1208 spdy_stream2->Cancel(); | 1208 spdy_stream2->Cancel(); |
| 1209 spdy_stream2 = NULL; | 1209 spdy_stream2 = NULL; |
| 1210 } | 1210 } |
| 1211 | 1211 |
| 1212 } // namespace net | 1212 } // namespace net |
| OLD | NEW |