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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 session->set_hung_interval(base::TimeDelta::FromSeconds(0)); | 320 session->set_hung_interval(base::TimeDelta::FromSeconds(0)); |
321 | 321 |
322 // Send a PING frame. | 322 // Send a PING frame. |
323 session->WritePingFrame(1); | 323 session->WritePingFrame(1); |
324 EXPECT_LT(0, session->pings_in_flight()); | 324 EXPECT_LT(0, session->pings_in_flight()); |
325 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); | 325 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); |
326 EXPECT_TRUE(session->check_ping_status_pending()); | 326 EXPECT_TRUE(session->check_ping_status_pending()); |
327 | 327 |
328 // Assert session is not closed. | 328 // Assert session is not closed. |
329 EXPECT_FALSE(session->IsClosed()); | 329 EXPECT_FALSE(session->IsClosed()); |
330 EXPECT_LT(0u, session->num_active_streams()); | 330 EXPECT_LT(0u, session->num_active_streams() + session->num_created_streams()); |
331 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); | 331 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); |
332 | 332 |
333 // We set last time we have received any data in 1 sec less than now. | 333 // We set last time we have received any data in 1 sec less than now. |
334 // CheckPingStatus will trigger timeout because hung interval is zero. | 334 // CheckPingStatus will trigger timeout because hung interval is zero. |
335 base::TimeTicks now = base::TimeTicks::Now(); | 335 base::TimeTicks now = base::TimeTicks::Now(); |
336 session->last_activity_time_ = now - base::TimeDelta::FromSeconds(1); | 336 session->last_activity_time_ = now - base::TimeDelta::FromSeconds(1); |
337 session->CheckPingStatus(now); | 337 session->CheckPingStatus(now); |
338 | 338 |
339 EXPECT_TRUE(session->IsClosed()); | 339 EXPECT_TRUE(session->IsClosed()); |
340 EXPECT_EQ(0u, session->num_active_streams()); | 340 EXPECT_EQ(0u, session->num_active_streams()); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 spdy_session_pool->CloseIdleSessions(); | 440 spdy_session_pool->CloseIdleSessions(); |
441 EXPECT_TRUE(session1->is_active()); | 441 EXPECT_TRUE(session1->is_active()); |
442 EXPECT_FALSE(session1->IsClosed()); | 442 EXPECT_FALSE(session1->IsClosed()); |
443 EXPECT_TRUE(session2->is_active()); | 443 EXPECT_TRUE(session2->is_active()); |
444 EXPECT_FALSE(session2->IsClosed()); | 444 EXPECT_FALSE(session2->IsClosed()); |
445 EXPECT_TRUE(session3->is_active()); | 445 EXPECT_TRUE(session3->is_active()); |
446 EXPECT_FALSE(session3->IsClosed()); | 446 EXPECT_FALSE(session3->IsClosed()); |
447 | 447 |
448 // Make sessions 1 and 3 inactive, but keep them open. | 448 // Make sessions 1 and 3 inactive, but keep them open. |
449 // Session 2 still open and active | 449 // Session 2 still open and active |
450 session1->CloseStream(spdy_stream1->stream_id(), OK); | 450 session1->CloseCreatedStream(spdy_stream1, OK); |
451 session3->CloseStream(spdy_stream3->stream_id(), OK); | 451 session3->CloseCreatedStream(spdy_stream3, OK); |
452 EXPECT_FALSE(session1->is_active()); | 452 EXPECT_FALSE(session1->is_active()); |
453 EXPECT_FALSE(session1->IsClosed()); | 453 EXPECT_FALSE(session1->IsClosed()); |
454 EXPECT_TRUE(session2->is_active()); | 454 EXPECT_TRUE(session2->is_active()); |
455 EXPECT_FALSE(session2->IsClosed()); | 455 EXPECT_FALSE(session2->IsClosed()); |
456 EXPECT_FALSE(session3->is_active()); | 456 EXPECT_FALSE(session3->is_active()); |
457 EXPECT_FALSE(session3->IsClosed()); | 457 EXPECT_FALSE(session3->IsClosed()); |
458 | 458 |
459 // Should close session 1 and 3, 2 should be left open | 459 // Should close session 1 and 3, 2 should be left open |
460 spdy_session_pool->CloseIdleSessions(); | 460 spdy_session_pool->CloseIdleSessions(); |
461 EXPECT_FALSE(session1->is_active()); | 461 EXPECT_FALSE(session1->is_active()); |
462 EXPECT_TRUE(session1->IsClosed()); | 462 EXPECT_TRUE(session1->IsClosed()); |
463 EXPECT_TRUE(session2->is_active()); | 463 EXPECT_TRUE(session2->is_active()); |
464 EXPECT_FALSE(session2->IsClosed()); | 464 EXPECT_FALSE(session2->IsClosed()); |
465 EXPECT_FALSE(session3->is_active()); | 465 EXPECT_FALSE(session3->is_active()); |
466 EXPECT_TRUE(session3->IsClosed()); | 466 EXPECT_TRUE(session3->IsClosed()); |
467 | 467 |
468 // Should not do anything | 468 // Should not do anything |
469 spdy_session_pool->CloseIdleSessions(); | 469 spdy_session_pool->CloseIdleSessions(); |
470 EXPECT_TRUE(session2->is_active()); | 470 EXPECT_TRUE(session2->is_active()); |
471 EXPECT_FALSE(session2->IsClosed()); | 471 EXPECT_FALSE(session2->IsClosed()); |
472 | 472 |
473 // Make 2 not active | 473 // Make 2 not active |
474 session2->CloseStream(spdy_stream2->stream_id(), OK); | 474 session2->CloseCreatedStream(spdy_stream2, OK); |
475 EXPECT_FALSE(session2->is_active()); | 475 EXPECT_FALSE(session2->is_active()); |
476 EXPECT_FALSE(session2->IsClosed()); | 476 EXPECT_FALSE(session2->IsClosed()); |
477 | 477 |
478 // This should close session 2 | 478 // This should close session 2 |
479 spdy_session_pool->CloseIdleSessions(); | 479 spdy_session_pool->CloseIdleSessions(); |
480 EXPECT_FALSE(session2->is_active()); | 480 EXPECT_FALSE(session2->is_active()); |
481 EXPECT_TRUE(session2->IsClosed()); | 481 EXPECT_TRUE(session2->IsClosed()); |
482 } | 482 } |
483 | 483 |
484 // Start with max concurrent streams set to 1. Request two streams. Receive a | 484 // Start with max concurrent streams set to 1. Request two streams. Receive a |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 SettingsMap new_settings; | 1110 SettingsMap new_settings; |
1111 int32 window_size = 1; | 1111 int32 window_size = 1; |
1112 new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = | 1112 new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
1113 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, window_size); | 1113 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, window_size); |
1114 | 1114 |
1115 // Set up the socket so we read a SETTINGS frame that sets | 1115 // Set up the socket so we read a SETTINGS frame that sets |
1116 // INITIAL_WINDOW_SIZE. | 1116 // INITIAL_WINDOW_SIZE. |
1117 MockConnect connect_data(SYNCHRONOUS, OK); | 1117 MockConnect connect_data(SYNCHRONOUS, OK); |
1118 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(new_settings)); | 1118 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(new_settings)); |
1119 MockRead reads[] = { | 1119 MockRead reads[] = { |
1120 CreateMockRead(*settings_frame), | 1120 CreateMockRead(*settings_frame, 0), |
1121 MockRead(SYNCHRONOUS, 0, 0) // EOF | 1121 MockRead(ASYNC, 0, 2) // EOF |
1122 }; | 1122 }; |
1123 | 1123 |
1124 SpdySessionDependencies session_deps; | 1124 SpdySessionDependencies session_deps; |
| 1125 |
1125 session_deps.host_resolver->set_synchronous_mode(true); | 1126 session_deps.host_resolver->set_synchronous_mode(true); |
1126 | 1127 |
1127 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 1128 scoped_refptr<DeterministicSocketData> data = |
1128 data.set_connect_data(connect_data); | 1129 new DeterministicSocketData(reads, arraysize(reads), NULL, 0); |
1129 session_deps.socket_factory->AddSocketDataProvider(&data); | 1130 data->set_connect_data(connect_data); |
| 1131 session_deps.deterministic_socket_factory->AddSocketDataProvider(data); |
1130 | 1132 |
1131 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 1133 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
1132 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); | 1134 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); |
1133 | 1135 |
1134 scoped_refptr<HttpNetworkSession> http_session( | 1136 scoped_refptr<HttpNetworkSession> http_session( |
1135 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | 1137 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps)); |
1136 | 1138 |
1137 const std::string kTestHost("www.foo.com"); | 1139 const std::string kTestHost("www.foo.com"); |
1138 const int kTestPort = 80; | 1140 const int kTestPort = 80; |
1139 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 1141 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
1140 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); | 1142 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
1141 | 1143 |
1142 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); | 1144 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
1143 | 1145 |
1144 // Create a session. | 1146 // Create a session. |
1145 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | 1147 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
(...skipping 18 matching lines...) Expand all Loading... |
1164 TestCompletionCallback callback1; | 1166 TestCompletionCallback callback1; |
1165 GURL url("http://www.google.com"); | 1167 GURL url("http://www.google.com"); |
1166 EXPECT_EQ(OK, | 1168 EXPECT_EQ(OK, |
1167 session->CreateStream(url, | 1169 session->CreateStream(url, |
1168 MEDIUM, /* priority, not important */ | 1170 MEDIUM, /* priority, not important */ |
1169 &spdy_stream1, | 1171 &spdy_stream1, |
1170 BoundNetLog(), | 1172 BoundNetLog(), |
1171 callback1.callback())); | 1173 callback1.callback())); |
1172 EXPECT_NE(spdy_stream1->send_window_size(), window_size); | 1174 EXPECT_NE(spdy_stream1->send_window_size(), window_size); |
1173 | 1175 |
| 1176 data->RunFor(1); // Process the SETTINGS frame, but not the EOF |
1174 MessageLoop::current()->RunAllPending(); | 1177 MessageLoop::current()->RunAllPending(); |
1175 EXPECT_EQ(session->initial_send_window_size(), window_size); | 1178 EXPECT_EQ(session->initial_send_window_size(), window_size); |
1176 EXPECT_EQ(spdy_stream1->send_window_size(), window_size); | 1179 EXPECT_EQ(spdy_stream1->send_window_size(), window_size); |
1177 | 1180 |
1178 // Release the first one, this will allow the second to be created. | 1181 // Release the first one, this will allow the second to be created. |
1179 spdy_stream1->Cancel(); | 1182 spdy_stream1->Cancel(); |
1180 spdy_stream1 = NULL; | 1183 spdy_stream1 = NULL; |
1181 | 1184 |
1182 scoped_refptr<SpdyStream> spdy_stream2; | 1185 scoped_refptr<SpdyStream> spdy_stream2; |
1183 EXPECT_EQ(OK, | 1186 EXPECT_EQ(OK, |
1184 session->CreateStream(url, | 1187 session->CreateStream(url, |
1185 MEDIUM, /* priority, not important */ | 1188 MEDIUM, /* priority, not important */ |
1186 &spdy_stream2, | 1189 &spdy_stream2, |
1187 BoundNetLog(), | 1190 BoundNetLog(), |
1188 callback1.callback())); | 1191 callback1.callback())); |
1189 | 1192 |
1190 EXPECT_EQ(spdy_stream2->send_window_size(), window_size); | 1193 EXPECT_EQ(spdy_stream2->send_window_size(), window_size); |
1191 spdy_stream2->Cancel(); | 1194 spdy_stream2->Cancel(); |
1192 spdy_stream2 = NULL; | 1195 spdy_stream2 = NULL; |
1193 } | 1196 } |
1194 | 1197 |
1195 TEST_F(SpdySessionSpdy3Test, OutOfOrderSynStreams) { | 1198 TEST_F(SpdySessionSpdy3Test, OutOfOrderSynStreams) { |
1196 // Construct the request. | 1199 // Construct the request. |
1197 MockConnect connect_data(SYNCHRONOUS, OK); | 1200 MockConnect connect_data(SYNCHRONOUS, OK); |
1198 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 1201 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, HIGHEST)); |
1199 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, HIGHEST)); | 1202 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, LOWEST)); |
1200 MockWrite writes[] = { | 1203 MockWrite writes[] = { |
1201 CreateMockWrite(*req1, 2), | 1204 CreateMockWrite(*req1, 2), |
1202 CreateMockWrite(*req2, 1), | 1205 CreateMockWrite(*req2, 1), |
1203 }; | 1206 }; |
1204 | 1207 |
1205 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 3)); | 1208 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 3)); |
1206 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(3, true)); | 1209 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(3, true)); |
1207 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 5)); | 1210 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 5)); |
1208 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(5, true)); | 1211 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(5, true)); |
1209 MockRead reads[] = { | 1212 MockRead reads[] = { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 http_session->GetTransportSocketPool( | 1255 http_session->GetTransportSocketPool( |
1253 HttpNetworkSession::NORMAL_SOCKET_POOL), | 1256 HttpNetworkSession::NORMAL_SOCKET_POOL), |
1254 BoundNetLog())); | 1257 BoundNetLog())); |
1255 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | 1258 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
1256 | 1259 |
1257 scoped_refptr<SpdyStream> spdy_stream1; | 1260 scoped_refptr<SpdyStream> spdy_stream1; |
1258 TestCompletionCallback callback1; | 1261 TestCompletionCallback callback1; |
1259 GURL url1("http://www.google.com"); | 1262 GURL url1("http://www.google.com"); |
1260 EXPECT_EQ(OK, session->CreateStream(url1, LOWEST, &spdy_stream1, | 1263 EXPECT_EQ(OK, session->CreateStream(url1, LOWEST, &spdy_stream1, |
1261 BoundNetLog(), callback1.callback())); | 1264 BoundNetLog(), callback1.callback())); |
1262 EXPECT_EQ(1u, spdy_stream1->stream_id()); | 1265 EXPECT_EQ(0u, spdy_stream1->stream_id()); |
1263 | 1266 |
1264 scoped_refptr<SpdyStream> spdy_stream2; | 1267 scoped_refptr<SpdyStream> spdy_stream2; |
1265 TestCompletionCallback callback2; | 1268 TestCompletionCallback callback2; |
1266 GURL url2("http://www.google.com"); | 1269 GURL url2("http://www.google.com"); |
1267 EXPECT_EQ(OK, session->CreateStream(url2, HIGHEST, &spdy_stream2, | 1270 EXPECT_EQ(OK, session->CreateStream(url2, HIGHEST, &spdy_stream2, |
1268 BoundNetLog(), callback2.callback())); | 1271 BoundNetLog(), callback2.callback())); |
1269 EXPECT_EQ(3u, spdy_stream2->stream_id()); | 1272 EXPECT_EQ(0u, spdy_stream2->stream_id()); |
1270 | 1273 |
1271 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); | 1274 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); |
1272 (*headers)[":method"] = "GET"; | 1275 (*headers)[":method"] = "GET"; |
1273 (*headers)[":scheme"] = url1.scheme(); | 1276 (*headers)[":scheme"] = url1.scheme(); |
1274 (*headers)[":host"] = url1.host(); | 1277 (*headers)[":host"] = url1.host(); |
1275 (*headers)[":path"] = url1.path(); | 1278 (*headers)[":path"] = url1.path(); |
1276 (*headers)[":version"] = "HTTP/1.1"; | 1279 (*headers)[":version"] = "HTTP/1.1"; |
1277 spdy_stream1->set_spdy_headers(headers); | 1280 spdy_stream1->set_spdy_headers(headers); |
1278 EXPECT_TRUE(spdy_stream1->HasUrl()); | 1281 EXPECT_TRUE(spdy_stream1->HasUrl()); |
1279 | 1282 |
1280 spdy_stream2->set_spdy_headers(headers); | 1283 spdy_stream2->set_spdy_headers(headers); |
1281 EXPECT_TRUE(spdy_stream2->HasUrl()); | 1284 EXPECT_TRUE(spdy_stream2->HasUrl()); |
1282 | 1285 |
1283 spdy_stream1->SendRequest(false); | 1286 spdy_stream1->SendRequest(false); |
1284 spdy_stream2->SendRequest(false); | 1287 spdy_stream2->SendRequest(false); |
1285 MessageLoop::current()->RunAllPending(); | 1288 MessageLoop::current()->RunAllPending(); |
1286 | 1289 |
1287 EXPECT_EQ(1u, spdy_stream1->stream_id()); | 1290 EXPECT_EQ(3u, spdy_stream1->stream_id()); |
1288 EXPECT_EQ(3u, spdy_stream2->stream_id()); | 1291 EXPECT_EQ(1u, spdy_stream2->stream_id()); |
1289 | 1292 |
1290 spdy_stream1->Cancel(); | 1293 spdy_stream1->Cancel(); |
1291 spdy_stream1 = NULL; | 1294 spdy_stream1 = NULL; |
1292 | 1295 |
1293 spdy_stream2->Cancel(); | 1296 spdy_stream2->Cancel(); |
1294 spdy_stream2 = NULL; | 1297 spdy_stream2 = NULL; |
1295 } | 1298 } |
1296 | 1299 |
1297 } // namespace net | 1300 } // namespace net |
OLD | NEW |