Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(791)

Side by Side Diff: net/spdy/spdy_session_spdy2_unittest.cc

Issue 10448083: Fix out of order SYN_STEAM frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make SpdyFrameProducer a nested class in SpdySession. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 CapturingNetLog::Entry entry = entries[pos]; 1032 CapturingNetLog::Entry entry = entries[pos];
1033 NetLogSpdySessionCloseParameter* request_params = 1033 NetLogSpdySessionCloseParameter* request_params =
1034 static_cast<NetLogSpdySessionCloseParameter*>( 1034 static_cast<NetLogSpdySessionCloseParameter*>(
1035 entry.extra_parameters.get()); 1035 entry.extra_parameters.get());
1036 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status()); 1036 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status());
1037 } 1037 }
1038 1038
1039 TEST_F(SpdySessionSpdy2Test, OutOfOrderSynStreams) { 1039 TEST_F(SpdySessionSpdy2Test, OutOfOrderSynStreams) {
1040 // Construct the request. 1040 // Construct the request.
1041 MockConnect connect_data(SYNCHRONOUS, OK); 1041 MockConnect connect_data(SYNCHRONOUS, OK);
1042 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); 1042 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, HIGHEST));
1043 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, HIGHEST)); 1043 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, LOWEST));
1044 MockWrite writes[] = { 1044 MockWrite writes[] = {
1045 CreateMockWrite(*req1, 2), 1045 CreateMockWrite(*req1, 2),
1046 CreateMockWrite(*req2, 1), 1046 CreateMockWrite(*req2, 1),
1047 }; 1047 };
1048 1048
1049 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); 1049 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1));
1050 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true)); 1050 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true));
1051 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); 1051 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3));
1052 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(3, true)); 1052 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(3, true));
1053 MockRead reads[] = { 1053 MockRead reads[] = {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 http_session->GetTransportSocketPool( 1096 http_session->GetTransportSocketPool(
1097 HttpNetworkSession::NORMAL_SOCKET_POOL), 1097 HttpNetworkSession::NORMAL_SOCKET_POOL),
1098 BoundNetLog())); 1098 BoundNetLog()));
1099 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); 1099 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
1100 1100
1101 scoped_refptr<SpdyStream> spdy_stream1; 1101 scoped_refptr<SpdyStream> spdy_stream1;
1102 TestCompletionCallback callback1; 1102 TestCompletionCallback callback1;
1103 GURL url1("http://www.google.com"); 1103 GURL url1("http://www.google.com");
1104 EXPECT_EQ(OK, session->CreateStream(url1, LOWEST, &spdy_stream1, 1104 EXPECT_EQ(OK, session->CreateStream(url1, LOWEST, &spdy_stream1,
1105 BoundNetLog(), callback1.callback())); 1105 BoundNetLog(), callback1.callback()));
1106 EXPECT_EQ(1u, spdy_stream1->stream_id()); 1106 EXPECT_EQ(0u, spdy_stream1->stream_id());
1107 1107
1108 scoped_refptr<SpdyStream> spdy_stream2; 1108 scoped_refptr<SpdyStream> spdy_stream2;
1109 TestCompletionCallback callback2; 1109 TestCompletionCallback callback2;
1110 GURL url2("http://www.google.com"); 1110 GURL url2("http://www.google.com");
1111 EXPECT_EQ(OK, session->CreateStream(url2, HIGHEST, &spdy_stream2, 1111 EXPECT_EQ(OK, session->CreateStream(url2, HIGHEST, &spdy_stream2,
1112 BoundNetLog(), callback2.callback())); 1112 BoundNetLog(), callback2.callback()));
1113 EXPECT_EQ(3u, spdy_stream2->stream_id()); 1113 EXPECT_EQ(0u, spdy_stream2->stream_id());
1114 1114
1115 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); 1115 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
1116 (*headers)["method"] = "GET"; 1116 (*headers)["method"] = "GET";
1117 (*headers)["scheme"] = url1.scheme(); 1117 (*headers)["scheme"] = url1.scheme();
1118 (*headers)["host"] = url1.host(); 1118 (*headers)["host"] = url1.host();
1119 (*headers)["url"] = url1.path(); 1119 (*headers)["url"] = url1.path();
1120 (*headers)["version"] = "HTTP/1.1"; 1120 (*headers)["version"] = "HTTP/1.1";
1121 spdy_stream1->set_spdy_headers(headers); 1121 spdy_stream1->set_spdy_headers(headers);
1122 EXPECT_TRUE(spdy_stream1->HasUrl()); 1122 EXPECT_TRUE(spdy_stream1->HasUrl());
1123 1123
1124 spdy_stream2->set_spdy_headers(headers); 1124 spdy_stream2->set_spdy_headers(headers);
1125 EXPECT_TRUE(spdy_stream2->HasUrl()); 1125 EXPECT_TRUE(spdy_stream2->HasUrl());
1126 1126
1127 spdy_stream1->SendRequest(false); 1127 spdy_stream1->SendRequest(false);
1128 spdy_stream2->SendRequest(false); 1128 spdy_stream2->SendRequest(false);
1129 MessageLoop::current()->RunAllPending(); 1129 MessageLoop::current()->RunAllPending();
1130 1130
1131 EXPECT_EQ(1u, spdy_stream1->stream_id()); 1131 EXPECT_EQ(3u, spdy_stream1->stream_id());
1132 EXPECT_EQ(3u, spdy_stream2->stream_id()); 1132 EXPECT_EQ(1u, spdy_stream2->stream_id());
1133 1133
1134 spdy_stream1->Cancel(); 1134 spdy_stream1->Cancel();
1135 spdy_stream1 = NULL; 1135 spdy_stream1 = NULL;
1136 1136
1137 spdy_stream2->Cancel(); 1137 spdy_stream2->Cancel();
1138 spdy_stream2 = NULL; 1138 spdy_stream2 = NULL;
1139 } 1139 }
1140 1140
1141 } // namespace net 1141 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698