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 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 SettingsMap new_settings; | 1186 SettingsMap new_settings; |
1187 int32 window_size = 1; | 1187 int32 window_size = 1; |
1188 new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = | 1188 new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
1189 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, window_size); | 1189 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, window_size); |
1190 | 1190 |
1191 // Set up the socket so we read a SETTINGS frame that sets | 1191 // Set up the socket so we read a SETTINGS frame that sets |
1192 // INITIAL_WINDOW_SIZE. | 1192 // INITIAL_WINDOW_SIZE. |
1193 MockConnect connect_data(SYNCHRONOUS, OK); | 1193 MockConnect connect_data(SYNCHRONOUS, OK); |
1194 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(new_settings)); | 1194 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(new_settings)); |
1195 MockRead reads[] = { | 1195 MockRead reads[] = { |
1196 CreateMockRead(*settings_frame), | 1196 CreateMockRead(*settings_frame, 0), |
1197 MockRead(SYNCHRONOUS, 0, 0) // EOF | 1197 MockRead(ASYNC, 0, 2) // EOF |
1198 }; | 1198 }; |
1199 | 1199 |
1200 SpdySessionDependencies session_deps; | 1200 SpdySessionDependencies session_deps; |
| 1201 |
1201 session_deps.host_resolver->set_synchronous_mode(true); | 1202 session_deps.host_resolver->set_synchronous_mode(true); |
1202 | 1203 |
1203 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 1204 scoped_refptr<DeterministicSocketData> data = |
1204 data.set_connect_data(connect_data); | 1205 new DeterministicSocketData(reads, arraysize(reads), NULL, 0); |
1205 session_deps.socket_factory->AddSocketDataProvider(&data); | 1206 data->set_connect_data(connect_data); |
| 1207 session_deps.deterministic_socket_factory->AddSocketDataProvider(data); |
1206 | 1208 |
1207 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 1209 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
1208 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); | 1210 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); |
1209 | 1211 |
1210 scoped_refptr<HttpNetworkSession> http_session( | 1212 scoped_refptr<HttpNetworkSession> http_session( |
1211 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | 1213 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps)); |
1212 | 1214 |
1213 const std::string kTestHost("www.foo.com"); | 1215 const std::string kTestHost("www.foo.com"); |
1214 const int kTestPort = 80; | 1216 const int kTestPort = 80; |
1215 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 1217 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
1216 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); | 1218 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
1217 | 1219 |
1218 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); | 1220 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
1219 | 1221 |
1220 // Create a session. | 1222 // Create a session. |
1221 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | 1223 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
(...skipping 19 matching lines...) Expand all Loading... |
1241 TestCompletionCallback callback1; | 1243 TestCompletionCallback callback1; |
1242 GURL url("http://www.google.com"); | 1244 GURL url("http://www.google.com"); |
1243 EXPECT_EQ(OK, | 1245 EXPECT_EQ(OK, |
1244 session->CreateStream(url, | 1246 session->CreateStream(url, |
1245 MEDIUM, /* priority, not important */ | 1247 MEDIUM, /* priority, not important */ |
1246 &spdy_stream1, | 1248 &spdy_stream1, |
1247 BoundNetLog(), | 1249 BoundNetLog(), |
1248 callback1.callback())); | 1250 callback1.callback())); |
1249 EXPECT_NE(spdy_stream1->send_window_size(), window_size); | 1251 EXPECT_NE(spdy_stream1->send_window_size(), window_size); |
1250 | 1252 |
| 1253 data->RunFor(1); // Process the SETTINGS frame, but not the EOF |
1251 MessageLoop::current()->RunAllPending(); | 1254 MessageLoop::current()->RunAllPending(); |
1252 EXPECT_EQ(session->initial_send_window_size(), window_size); | 1255 EXPECT_EQ(session->initial_send_window_size(), window_size); |
1253 EXPECT_EQ(spdy_stream1->send_window_size(), window_size); | 1256 EXPECT_EQ(spdy_stream1->send_window_size(), window_size); |
1254 | 1257 |
1255 // Release the first one, this will allow the second to be created. | 1258 // Release the first one, this will allow the second to be created. |
1256 spdy_stream1->Cancel(); | 1259 spdy_stream1->Cancel(); |
1257 spdy_stream1 = NULL; | 1260 spdy_stream1 = NULL; |
1258 | 1261 |
1259 scoped_refptr<SpdyStream> spdy_stream2; | 1262 scoped_refptr<SpdyStream> spdy_stream2; |
1260 EXPECT_EQ(OK, | 1263 EXPECT_EQ(OK, |
1261 session->CreateStream(url, | 1264 session->CreateStream(url, |
1262 MEDIUM, /* priority, not important */ | 1265 MEDIUM, /* priority, not important */ |
1263 &spdy_stream2, | 1266 &spdy_stream2, |
1264 BoundNetLog(), | 1267 BoundNetLog(), |
1265 callback1.callback())); | 1268 callback1.callback())); |
1266 | 1269 |
1267 EXPECT_EQ(spdy_stream2->send_window_size(), window_size); | 1270 EXPECT_EQ(spdy_stream2->send_window_size(), window_size); |
1268 spdy_stream2->Cancel(); | 1271 spdy_stream2->Cancel(); |
1269 spdy_stream2 = NULL; | 1272 spdy_stream2 = NULL; |
1270 } | 1273 } |
1271 | 1274 |
1272 TEST_F(SpdySessionSpdy3Test, OutOfOrderSynStreams) { | 1275 TEST_F(SpdySessionSpdy3Test, OutOfOrderSynStreams) { |
1273 // Construct the request. | 1276 // Construct the request. |
1274 MockConnect connect_data(SYNCHRONOUS, OK); | 1277 MockConnect connect_data(SYNCHRONOUS, OK); |
1275 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 1278 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, HIGHEST)); |
1276 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, HIGHEST)); | 1279 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, LOWEST)); |
1277 MockWrite writes[] = { | 1280 MockWrite writes[] = { |
1278 CreateMockWrite(*req1, 2), | 1281 CreateMockWrite(*req1, 2), |
1279 CreateMockWrite(*req2, 1), | 1282 CreateMockWrite(*req2, 1), |
1280 }; | 1283 }; |
1281 | 1284 |
1282 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 3)); | 1285 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 3)); |
1283 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(3, true)); | 1286 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(3, true)); |
1284 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 5)); | 1287 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 5)); |
1285 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(5, true)); | 1288 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(5, true)); |
1286 MockRead reads[] = { | 1289 MockRead reads[] = { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 http_session->GetTransportSocketPool( | 1333 http_session->GetTransportSocketPool( |
1331 HttpNetworkSession::NORMAL_SOCKET_POOL), | 1334 HttpNetworkSession::NORMAL_SOCKET_POOL), |
1332 BoundNetLog())); | 1335 BoundNetLog())); |
1333 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | 1336 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
1334 | 1337 |
1335 scoped_refptr<SpdyStream> spdy_stream1; | 1338 scoped_refptr<SpdyStream> spdy_stream1; |
1336 TestCompletionCallback callback1; | 1339 TestCompletionCallback callback1; |
1337 GURL url1("http://www.google.com"); | 1340 GURL url1("http://www.google.com"); |
1338 EXPECT_EQ(OK, session->CreateStream(url1, LOWEST, &spdy_stream1, | 1341 EXPECT_EQ(OK, session->CreateStream(url1, LOWEST, &spdy_stream1, |
1339 BoundNetLog(), callback1.callback())); | 1342 BoundNetLog(), callback1.callback())); |
1340 EXPECT_EQ(1u, spdy_stream1->stream_id()); | 1343 EXPECT_EQ(0u, spdy_stream1->stream_id()); |
1341 | 1344 |
1342 scoped_refptr<SpdyStream> spdy_stream2; | 1345 scoped_refptr<SpdyStream> spdy_stream2; |
1343 TestCompletionCallback callback2; | 1346 TestCompletionCallback callback2; |
1344 GURL url2("http://www.google.com"); | 1347 GURL url2("http://www.google.com"); |
1345 EXPECT_EQ(OK, session->CreateStream(url2, HIGHEST, &spdy_stream2, | 1348 EXPECT_EQ(OK, session->CreateStream(url2, HIGHEST, &spdy_stream2, |
1346 BoundNetLog(), callback2.callback())); | 1349 BoundNetLog(), callback2.callback())); |
1347 EXPECT_EQ(3u, spdy_stream2->stream_id()); | 1350 EXPECT_EQ(0u, spdy_stream2->stream_id()); |
1348 | 1351 |
1349 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); | 1352 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); |
1350 (*headers)[":method"] = "GET"; | 1353 (*headers)[":method"] = "GET"; |
1351 (*headers)[":scheme"] = url1.scheme(); | 1354 (*headers)[":scheme"] = url1.scheme(); |
1352 (*headers)[":host"] = url1.host(); | 1355 (*headers)[":host"] = url1.host(); |
1353 (*headers)[":path"] = url1.path(); | 1356 (*headers)[":path"] = url1.path(); |
1354 (*headers)[":version"] = "HTTP/1.1"; | 1357 (*headers)[":version"] = "HTTP/1.1"; |
1355 spdy_stream1->set_spdy_headers(headers); | 1358 spdy_stream1->set_spdy_headers(headers); |
1356 EXPECT_TRUE(spdy_stream1->HasUrl()); | 1359 EXPECT_TRUE(spdy_stream1->HasUrl()); |
1357 | 1360 |
1358 spdy_stream2->set_spdy_headers(headers); | 1361 spdy_stream2->set_spdy_headers(headers); |
1359 EXPECT_TRUE(spdy_stream2->HasUrl()); | 1362 EXPECT_TRUE(spdy_stream2->HasUrl()); |
1360 | 1363 |
1361 spdy_stream1->SendRequest(false); | 1364 spdy_stream1->SendRequest(false); |
1362 spdy_stream2->SendRequest(false); | 1365 spdy_stream2->SendRequest(false); |
1363 MessageLoop::current()->RunAllPending(); | 1366 MessageLoop::current()->RunAllPending(); |
1364 | 1367 |
1365 EXPECT_EQ(1u, spdy_stream1->stream_id()); | 1368 EXPECT_EQ(3u, spdy_stream1->stream_id()); |
1366 EXPECT_EQ(3u, spdy_stream2->stream_id()); | 1369 EXPECT_EQ(1u, spdy_stream2->stream_id()); |
1367 | 1370 |
1368 spdy_stream1->Cancel(); | 1371 spdy_stream1->Cancel(); |
1369 spdy_stream1 = NULL; | 1372 spdy_stream1 = NULL; |
1370 | 1373 |
1371 spdy_stream2->Cancel(); | 1374 spdy_stream2->Cancel(); |
1372 spdy_stream2 = NULL; | 1375 spdy_stream2 = NULL; |
1373 } | 1376 } |
1374 | 1377 |
1375 } // namespace net | 1378 } // namespace net |
OLD | NEW |