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/quic/quic_session.h" | 5 #include "net/quic/quic_session.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 QuicDataStream* GetIncomingReliableStream(QuicStreamId stream_id) { | 116 QuicDataStream* GetIncomingReliableStream(QuicStreamId stream_id) { |
117 return QuicSession::GetIncomingReliableStream(stream_id); | 117 return QuicSession::GetIncomingReliableStream(stream_id); |
118 } | 118 } |
119 | 119 |
120 TestCryptoStream crypto_stream_; | 120 TestCryptoStream crypto_stream_; |
121 }; | 121 }; |
122 | 122 |
123 class QuicSessionTest : public ::testing::Test { | 123 class QuicSessionTest : public ::testing::Test { |
124 protected: | 124 protected: |
125 QuicSessionTest() | 125 QuicSessionTest() |
126 : guid_(1), | 126 : connection_(new MockConnection(false)), |
127 connection_(new MockConnection(guid_, IPEndPoint(), false)), | |
128 session_(connection_, true) { | 127 session_(connection_, true) { |
129 headers_[":host"] = "www.google.com"; | 128 headers_[":host"] = "www.google.com"; |
130 headers_[":path"] = "/index.hml"; | 129 headers_[":path"] = "/index.hml"; |
131 headers_[":scheme"] = "http"; | 130 headers_[":scheme"] = "http"; |
132 headers_["cookie"] = | 131 headers_["cookie"] = |
133 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; " | 132 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; " |
134 "__utmc=160408618; " | 133 "__utmc=160408618; " |
135 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX" | 134 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX" |
136 "hoALMsy6HOdDad2Sz0flUByv7etmo3mLMidGrBoljqO9hSVA40SLqpG_iuKKSHX" | 135 "hoALMsy6HOdDad2Sz0flUByv7etmo3mLMidGrBoljqO9hSVA40SLqpG_iuKKSHX" |
137 "RW3Np4bq0F0SDGDNsW0DSmTS9ufMRrlpARJDS7qAI6M3bghqJp4eABKZiRqebHT" | 136 "RW3Np4bq0F0SDGDNsW0DSmTS9ufMRrlpARJDS7qAI6M3bghqJp4eABKZiRqebHT" |
(...skipping 25 matching lines...) Expand all Loading... |
163 EXPECT_TRUE(session_.IsClosedStream(i)) << " stream id: " << i; | 162 EXPECT_TRUE(session_.IsClosedStream(i)) << " stream id: " << i; |
164 } | 163 } |
165 } | 164 } |
166 } | 165 } |
167 | 166 |
168 void CloseStream(QuicStreamId id) { | 167 void CloseStream(QuicStreamId id) { |
169 session_.CloseStream(id); | 168 session_.CloseStream(id); |
170 closed_streams_.insert(id); | 169 closed_streams_.insert(id); |
171 } | 170 } |
172 | 171 |
173 QuicGuid guid_; | |
174 MockConnection* connection_; | 172 MockConnection* connection_; |
175 TestSession session_; | 173 TestSession session_; |
176 set<QuicStreamId> closed_streams_; | 174 set<QuicStreamId> closed_streams_; |
177 SpdyHeaderBlock headers_; | 175 SpdyHeaderBlock headers_; |
178 }; | 176 }; |
179 | 177 |
180 TEST_F(QuicSessionTest, PeerAddress) { | 178 TEST_F(QuicSessionTest, PeerAddress) { |
181 EXPECT_EQ(IPEndPoint(), session_.peer_address()); | 179 EXPECT_EQ(IPEndPoint(Loopback4(), kTestPort), session_.peer_address()); |
182 } | 180 } |
183 | 181 |
184 TEST_F(QuicSessionTest, IsCryptoHandshakeConfirmed) { | 182 TEST_F(QuicSessionTest, IsCryptoHandshakeConfirmed) { |
185 EXPECT_FALSE(session_.IsCryptoHandshakeConfirmed()); | 183 EXPECT_FALSE(session_.IsCryptoHandshakeConfirmed()); |
186 CryptoHandshakeMessage message; | 184 CryptoHandshakeMessage message; |
187 session_.crypto_stream_.OnHandshakeMessage(message); | 185 session_.crypto_stream_.OnHandshakeMessage(message); |
188 EXPECT_TRUE(session_.IsCryptoHandshakeConfirmed()); | 186 EXPECT_TRUE(session_.IsCryptoHandshakeConfirmed()); |
189 } | 187 } |
190 | 188 |
191 TEST_F(QuicSessionTest, IsClosedStreamDefault) { | 189 TEST_F(QuicSessionTest, IsClosedStreamDefault) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 EXPECT_EQ(kDefaultInitialTimeoutSecs, | 386 EXPECT_EQ(kDefaultInitialTimeoutSecs, |
389 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); | 387 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); |
390 CryptoHandshakeMessage msg; | 388 CryptoHandshakeMessage msg; |
391 session_.crypto_stream_.OnHandshakeMessage(msg); | 389 session_.crypto_stream_.OnHandshakeMessage(msg); |
392 EXPECT_EQ(kDefaultTimeoutSecs, | 390 EXPECT_EQ(kDefaultTimeoutSecs, |
393 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); | 391 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); |
394 } | 392 } |
395 | 393 |
396 TEST_F(QuicSessionTest, ZombieStream) { | 394 TEST_F(QuicSessionTest, ZombieStream) { |
397 StrictMock<MockConnection>* connection = | 395 StrictMock<MockConnection>* connection = |
398 new StrictMock<MockConnection>(guid_, IPEndPoint(), false); | 396 new StrictMock<MockConnection>(false); |
399 TestSession session(connection, /*is_server=*/ false); | 397 TestSession session(connection, /*is_server=*/ false); |
400 | 398 |
401 TestStream* stream3 = session.CreateOutgoingDataStream(); | 399 TestStream* stream3 = session.CreateOutgoingDataStream(); |
402 EXPECT_EQ(3u, stream3->id()); | 400 EXPECT_EQ(3u, stream3->id()); |
403 TestStream* stream5 = session.CreateOutgoingDataStream(); | 401 TestStream* stream5 = session.CreateOutgoingDataStream(); |
404 EXPECT_EQ(5u, stream5->id()); | 402 EXPECT_EQ(5u, stream5->id()); |
405 EXPECT_EQ(2u, session.GetNumOpenStreams()); | 403 EXPECT_EQ(2u, session.GetNumOpenStreams()); |
406 | 404 |
407 // Reset the stream, but since the headers have not been decompressed | 405 // Reset the stream, but since the headers have not been decompressed |
408 // it will become a zombie and will continue to process data | 406 // it will become a zombie and will continue to process data |
(...skipping 19 matching lines...) Expand all Loading... |
428 EXPECT_FALSE(stream3->headers_decompressed()); | 426 EXPECT_FALSE(stream3->headers_decompressed()); |
429 | 427 |
430 session.OnStreamFrames(frames); | 428 session.OnStreamFrames(frames); |
431 EXPECT_EQ(1u, session.GetNumOpenStreams()); | 429 EXPECT_EQ(1u, session.GetNumOpenStreams()); |
432 | 430 |
433 EXPECT_TRUE(connection->connected()); | 431 EXPECT_TRUE(connection->connected()); |
434 } | 432 } |
435 | 433 |
436 TEST_F(QuicSessionTest, ZombieStreamConnectionClose) { | 434 TEST_F(QuicSessionTest, ZombieStreamConnectionClose) { |
437 StrictMock<MockConnection>* connection = | 435 StrictMock<MockConnection>* connection = |
438 new StrictMock<MockConnection>(guid_, IPEndPoint(), false); | 436 new StrictMock<MockConnection>(false); |
439 TestSession session(connection, /*is_server=*/ false); | 437 TestSession session(connection, /*is_server=*/ false); |
440 | 438 |
441 TestStream* stream3 = session.CreateOutgoingDataStream(); | 439 TestStream* stream3 = session.CreateOutgoingDataStream(); |
442 EXPECT_EQ(3u, stream3->id()); | 440 EXPECT_EQ(3u, stream3->id()); |
443 TestStream* stream5 = session.CreateOutgoingDataStream(); | 441 TestStream* stream5 = session.CreateOutgoingDataStream(); |
444 EXPECT_EQ(5u, stream5->id()); | 442 EXPECT_EQ(5u, stream5->id()); |
445 EXPECT_EQ(2u, session.GetNumOpenStreams()); | 443 EXPECT_EQ(2u, session.GetNumOpenStreams()); |
446 | 444 |
447 stream3->CloseWriteSide(); | 445 stream3->CloseWriteSide(); |
448 // Reset the stream, but since the headers have not been decompressed | 446 // Reset the stream, but since the headers have not been decompressed |
(...skipping 23 matching lines...) Expand all Loading... |
472 QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED)); | 470 QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED)); |
473 | 471 |
474 QuicRstStreamFrame rst1(3, QUIC_STREAM_NO_ERROR); | 472 QuicRstStreamFrame rst1(3, QUIC_STREAM_NO_ERROR); |
475 session_.OnRstStream(rst1); | 473 session_.OnRstStream(rst1); |
476 EXPECT_EQ(0u, session_.GetNumOpenStreams()); | 474 EXPECT_EQ(0u, session_.GetNumOpenStreams()); |
477 } | 475 } |
478 | 476 |
479 } // namespace | 477 } // namespace |
480 } // namespace test | 478 } // namespace test |
481 } // namespace net | 479 } // namespace net |
OLD | NEW |