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 #include "net/quic/quic_connection.h" | |
7 | 6 |
8 #include <set> | 7 #include <set> |
9 | 8 |
10 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
11 #include "net/quic/crypto/crypto_handshake.h" | 10 #include "net/quic/crypto/crypto_handshake.h" |
| 11 #include "net/quic/quic_connection.h" |
| 12 #include "net/quic/quic_protocol.h" |
| 13 #include "net/quic/test_tools/quic_connection_peer.h" |
12 #include "net/quic/test_tools/quic_test_utils.h" | 14 #include "net/quic/test_tools/quic_test_utils.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 | 17 |
16 using base::hash_map; | 18 using base::hash_map; |
17 using std::set; | 19 using std::set; |
18 using testing::_; | 20 using testing::_; |
19 using testing::InSequence; | 21 using testing::InSequence; |
20 | 22 |
21 namespace net { | 23 namespace net { |
22 namespace test { | 24 namespace test { |
23 namespace { | 25 namespace { |
24 | 26 |
25 class TestCryptoStream : public QuicCryptoStream { | 27 class TestCryptoStream : public QuicCryptoStream { |
26 public: | 28 public: |
27 explicit TestCryptoStream(QuicSession* session) | 29 explicit TestCryptoStream(QuicSession* session) |
28 : QuicCryptoStream(session) { | 30 : QuicCryptoStream(session) { |
29 } | 31 } |
30 | 32 |
31 virtual void OnHandshakeMessage( | 33 virtual void OnHandshakeMessage( |
32 const CryptoHandshakeMessage& message) OVERRIDE { | 34 const CryptoHandshakeMessage& message) OVERRIDE { |
33 encryption_established_ = true; | 35 encryption_established_ = true; |
34 handshake_confirmed_ = true; | 36 handshake_confirmed_ = true; |
| 37 CryptoHandshakeMessage msg; |
| 38 string error_details; |
| 39 session()->config()->ToHandshakeMessage(&msg); |
| 40 const QuicErrorCode error = session()->config()->ProcessClientHello( |
| 41 msg, &error_details); |
| 42 EXPECT_EQ(QUIC_NO_ERROR, error); |
35 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED); | 43 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED); |
36 } | 44 } |
37 }; | 45 }; |
38 | 46 |
39 class TestStream : public ReliableQuicStream { | 47 class TestStream : public ReliableQuicStream { |
40 public: | 48 public: |
41 TestStream(QuicStreamId id, QuicSession* session) | 49 TestStream(QuicStreamId id, QuicSession* session) |
42 : ReliableQuicStream(id, session) { | 50 : ReliableQuicStream(id, session) { |
43 } | 51 } |
44 | 52 |
45 virtual uint32 ProcessData(const char* data, uint32 data_len) { | 53 virtual uint32 ProcessData(const char* data, uint32 data_len) { |
46 return data_len; | 54 return data_len; |
47 } | 55 } |
48 | 56 |
49 MOCK_METHOD0(OnCanWrite, void()); | 57 MOCK_METHOD0(OnCanWrite, void()); |
50 }; | 58 }; |
51 | 59 |
52 class TestSession : public QuicSession { | 60 class TestSession : public QuicSession { |
53 public: | 61 public: |
54 TestSession(QuicConnection* connection, bool is_server) | 62 TestSession(QuicConnection* connection, bool is_server) |
55 : QuicSession(connection, is_server), | 63 : QuicSession(connection, QuicConfig(), is_server), |
56 crypto_stream_(this) { | 64 crypto_stream_(this) { |
| 65 config()->SetDefaults(); |
57 } | 66 } |
58 | 67 |
59 virtual QuicCryptoStream* GetCryptoStream() OVERRIDE { | 68 virtual QuicCryptoStream* GetCryptoStream() OVERRIDE { |
60 return &crypto_stream_; | 69 return &crypto_stream_; |
61 } | 70 } |
62 | 71 |
63 virtual TestStream* CreateOutgoingReliableStream() OVERRIDE { | 72 virtual TestStream* CreateOutgoingReliableStream() OVERRIDE { |
64 TestStream* stream = new TestStream(GetNextStreamId(), this); | 73 TestStream* stream = new TestStream(GetNextStreamId(), this); |
65 ActivateStream(stream); | 74 ActivateStream(stream); |
66 return stream; | 75 return stream; |
(...skipping 10 matching lines...) Expand all Loading... |
77 ReliableQuicStream* GetIncomingReliableStream(QuicStreamId stream_id) { | 86 ReliableQuicStream* GetIncomingReliableStream(QuicStreamId stream_id) { |
78 return QuicSession::GetIncomingReliableStream(stream_id); | 87 return QuicSession::GetIncomingReliableStream(stream_id); |
79 } | 88 } |
80 | 89 |
81 // Helper method for gmock | 90 // Helper method for gmock |
82 void MarkTwoWriteBlocked() { | 91 void MarkTwoWriteBlocked() { |
83 this->MarkWriteBlocked(2); | 92 this->MarkWriteBlocked(2); |
84 } | 93 } |
85 | 94 |
86 TestCryptoStream crypto_stream_; | 95 TestCryptoStream crypto_stream_; |
| 96 QuicConfig config_; |
87 }; | 97 }; |
88 | 98 |
89 class QuicSessionTest : public ::testing::Test { | 99 class QuicSessionTest : public ::testing::Test { |
90 protected: | 100 protected: |
91 QuicSessionTest() | 101 QuicSessionTest() |
92 : guid_(1), | 102 : guid_(1), |
93 connection_(new MockConnection(guid_, IPEndPoint(), false)), | 103 connection_(new MockConnection(guid_, IPEndPoint(), false)), |
94 session_(connection_, true) { | 104 session_(connection_, true) { |
95 } | 105 } |
96 | 106 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 CloseStream(9); | 169 CloseStream(9); |
160 CheckClosedStreams(); | 170 CheckClosedStreams(); |
161 } | 171 } |
162 | 172 |
163 TEST_F(QuicSessionTest, StreamIdTooLarge) { | 173 TEST_F(QuicSessionTest, StreamIdTooLarge) { |
164 session_.GetIncomingReliableStream(3); | 174 session_.GetIncomingReliableStream(3); |
165 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID)); | 175 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID)); |
166 session_.GetIncomingReliableStream(105); | 176 session_.GetIncomingReliableStream(105); |
167 } | 177 } |
168 | 178 |
| 179 TEST_F(QuicSessionTest, DecompressionError) { |
| 180 ReliableQuicStream* stream = session_.GetIncomingReliableStream(3); |
| 181 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_DECOMPRESSION_FAILURE)); |
| 182 const char data[] = |
| 183 "\1\0\0\0" // headers id |
| 184 "\0\0\0\4" // length |
| 185 "abcd"; // invalid compressed data |
| 186 stream->ProcessRawData(data, arraysize(data)); |
| 187 } |
| 188 |
169 TEST_F(QuicSessionTest, OnCanWrite) { | 189 TEST_F(QuicSessionTest, OnCanWrite) { |
170 TestStream* stream2 = session_.CreateOutgoingReliableStream(); | 190 TestStream* stream2 = session_.CreateOutgoingReliableStream(); |
171 TestStream* stream4 = session_.CreateOutgoingReliableStream(); | 191 TestStream* stream4 = session_.CreateOutgoingReliableStream(); |
172 TestStream* stream6 = session_.CreateOutgoingReliableStream(); | 192 TestStream* stream6 = session_.CreateOutgoingReliableStream(); |
173 | 193 |
174 session_.MarkWriteBlocked(2); | 194 session_.MarkWriteBlocked(2); |
175 session_.MarkWriteBlocked(6); | 195 session_.MarkWriteBlocked(6); |
176 session_.MarkWriteBlocked(4); | 196 session_.MarkWriteBlocked(4); |
177 | 197 |
178 InSequence s; | 198 InSequence s; |
(...skipping 27 matching lines...) Expand all Loading... |
206 // result in a RST being sent. | 226 // result in a RST being sent. |
207 EXPECT_CALL(*connection_, | 227 EXPECT_CALL(*connection_, |
208 SendGoAway(QUIC_PEER_GOING_AWAY, 0u, "Going Away.")); | 228 SendGoAway(QUIC_PEER_GOING_AWAY, 0u, "Going Away.")); |
209 session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away."); | 229 session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away."); |
210 EXPECT_TRUE(session_.goaway_sent()); | 230 EXPECT_TRUE(session_.goaway_sent()); |
211 | 231 |
212 EXPECT_CALL(*connection_, SendRstStream(3u, QUIC_STREAM_PEER_GOING_AWAY)); | 232 EXPECT_CALL(*connection_, SendRstStream(3u, QUIC_STREAM_PEER_GOING_AWAY)); |
213 EXPECT_FALSE(session_.GetIncomingReliableStream(3u)); | 233 EXPECT_FALSE(session_.GetIncomingReliableStream(3u)); |
214 } | 234 } |
215 | 235 |
| 236 TEST_F(QuicSessionTest, IncreasedTimeoutAfterCryptoHandshake) { |
| 237 EXPECT_EQ(kDefaultInitialTimeoutSecs, |
| 238 QuicConnectionPeer::GetTimeout(connection_).ToSeconds()); |
| 239 CryptoHandshakeMessage msg; |
| 240 session_.crypto_stream_.OnHandshakeMessage(msg); |
| 241 EXPECT_EQ(kDefaultTimeoutSecs, |
| 242 QuicConnectionPeer::GetTimeout(connection_).ToSeconds()); |
| 243 } |
| 244 |
216 } // namespace | 245 } // namespace |
217 } // namespace test | 246 } // namespace test |
218 } // namespace net | 247 } // namespace net |
OLD | NEW |