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

Side by Side Diff: net/tools/quic/quic_server_session_test.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/tools/quic/quic_server_session.h" 5 #include "net/tools/quic/quic_server_session.h"
6 6
7 #include "net/quic/crypto/quic_crypto_server_config.h" 7 #include "net/quic/crypto/quic_crypto_server_config.h"
8 #include "net/quic/crypto/quic_random.h" 8 #include "net/quic/crypto/quic_random.h"
9 #include "net/quic/quic_connection.h" 9 #include "net/quic/quic_connection.h"
10 #include "net/quic/quic_utils.h" 10 #include "net/quic/quic_utils.h"
(...skipping 13 matching lines...) Expand all
24 using net::test::SupportedVersions; 24 using net::test::SupportedVersions;
25 using testing::StrictMock; 25 using testing::StrictMock;
26 using testing::_; 26 using testing::_;
27 27
28 namespace net { 28 namespace net {
29 namespace tools { 29 namespace tools {
30 namespace test { 30 namespace test {
31 31
32 class QuicServerSessionPeer { 32 class QuicServerSessionPeer {
33 public: 33 public:
34 static QuicDataStream* GetIncomingDataStream( 34 static QuicDataStream* GetIncomingDataStream(QuicServerSession* s,
35 QuicServerSession* s, QuicStreamId id) { 35 QuicStreamId id) {
36 return s->GetIncomingDataStream(id); 36 return s->GetIncomingDataStream(id);
37 } 37 }
38 static QuicDataStream* GetDataStream(QuicServerSession* s, QuicStreamId id) { 38 static QuicDataStream* GetDataStream(QuicServerSession* s, QuicStreamId id) {
39 return s->GetDataStream(id); 39 return s->GetDataStream(id);
40 } 40 }
41 }; 41 };
42 42
43 namespace { 43 namespace {
44 44
45 class QuicServerSessionTest : public ::testing::TestWithParam<QuicVersion> { 45 class QuicServerSessionTest : public ::testing::TestWithParam<QuicVersion> {
46 protected: 46 protected:
47 QuicServerSessionTest() 47 QuicServerSessionTest()
48 : crypto_config_(QuicCryptoServerConfig::TESTING, 48 : crypto_config_(QuicCryptoServerConfig::TESTING,
49 QuicRandom::GetInstance()) { 49 QuicRandom::GetInstance()) {
50 config_.SetDefaults(); 50 config_.SetDefaults();
51 config_.set_max_streams_per_connection(3, 3); 51 config_.set_max_streams_per_connection(3, 3);
52 52
53 connection_ = 53 connection_ =
54 new StrictMock<MockConnection>(true, SupportedVersions(GetParam())); 54 new StrictMock<MockConnection>(true, SupportedVersions(GetParam()));
55 session_.reset(new QuicServerSession( 55 session_.reset(new QuicServerSession(config_, connection_, &owner_));
56 config_, connection_, &owner_));
57 session_->InitializeSession(crypto_config_); 56 session_->InitializeSession(crypto_config_);
58 visitor_ = QuicConnectionPeer::GetVisitor(connection_); 57 visitor_ = QuicConnectionPeer::GetVisitor(connection_);
59 } 58 }
60 59
61 QuicVersion version() const { return connection_->version(); } 60 QuicVersion version() const { return connection_->version(); }
62 61
63 StrictMock<MockQuicServerSessionVisitor> owner_; 62 StrictMock<MockQuicServerSessionVisitor> owner_;
64 StrictMock<MockConnection>* connection_; 63 StrictMock<MockConnection>* connection_;
65 QuicConfig config_; 64 QuicConfig config_;
66 QuicCryptoServerConfig crypto_config_; 65 QuicCryptoServerConfig crypto_config_;
67 scoped_ptr<QuicServerSession> session_; 66 scoped_ptr<QuicServerSession> session_;
68 QuicConnectionVisitorInterface* visitor_; 67 QuicConnectionVisitorInterface* visitor_;
69 }; 68 };
70 69
71 INSTANTIATE_TEST_CASE_P(Tests, QuicServerSessionTest, 70 INSTANTIATE_TEST_CASE_P(Tests,
71 QuicServerSessionTest,
72 ::testing::ValuesIn(QuicSupportedVersions())); 72 ::testing::ValuesIn(QuicSupportedVersions()));
73 73
74 TEST_P(QuicServerSessionTest, CloseStreamDueToReset) { 74 TEST_P(QuicServerSessionTest, CloseStreamDueToReset) {
75 QuicStreamId stream_id = 5; 75 QuicStreamId stream_id = 5;
76 // Open a stream, then reset it. 76 // Open a stream, then reset it.
77 // Send two bytes of payload to open it. 77 // Send two bytes of payload to open it.
78 QuicStreamFrame data1(stream_id, false, 0, MakeIOVector("HT")); 78 QuicStreamFrame data1(stream_id, false, 0, MakeIOVector("HT"));
79 vector<QuicStreamFrame> frames; 79 vector<QuicStreamFrame> frames;
80 frames.push_back(data1); 80 frames.push_back(data1);
81 session_->OnStreamFrames(frames); 81 session_->OnStreamFrames(frames);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 114
115 // The stream should never be opened, now that the reset is received. 115 // The stream should never be opened, now that the reset is received.
116 EXPECT_EQ(0u, session_->GetNumOpenStreams()); 116 EXPECT_EQ(0u, session_->GetNumOpenStreams());
117 EXPECT_TRUE(connection_->connected()); 117 EXPECT_TRUE(connection_->connected());
118 } 118 }
119 119
120 TEST_P(QuicServerSessionTest, AcceptClosedStream) { 120 TEST_P(QuicServerSessionTest, AcceptClosedStream) {
121 QuicStreamId stream_id = 5; 121 QuicStreamId stream_id = 5;
122 vector<QuicStreamFrame> frames; 122 vector<QuicStreamFrame> frames;
123 // Send (empty) compressed headers followed by two bytes of data. 123 // Send (empty) compressed headers followed by two bytes of data.
124 frames.push_back(QuicStreamFrame(stream_id, false, 0, 124 frames.push_back(
125 MakeIOVector("\1\0\0\0\0\0\0\0HT"))); 125 QuicStreamFrame(stream_id, false, 0, MakeIOVector("\1\0\0\0\0\0\0\0HT")));
126 frames.push_back(QuicStreamFrame(stream_id + 2, false, 0, 126 frames.push_back(QuicStreamFrame(
127 MakeIOVector("\2\0\0\0\0\0\0\0HT"))); 127 stream_id + 2, false, 0, MakeIOVector("\2\0\0\0\0\0\0\0HT")));
128 visitor_->OnStreamFrames(frames); 128 visitor_->OnStreamFrames(frames);
129 EXPECT_EQ(2u, session_->GetNumOpenStreams()); 129 EXPECT_EQ(2u, session_->GetNumOpenStreams());
130 130
131 // Send a reset (and expect the peer to send a RST in response). 131 // Send a reset (and expect the peer to send a RST in response).
132 QuicRstStreamFrame rst(stream_id, QUIC_STREAM_NO_ERROR, 0); 132 QuicRstStreamFrame rst(stream_id, QUIC_STREAM_NO_ERROR, 0);
133 EXPECT_CALL(*connection_, 133 EXPECT_CALL(*connection_,
134 SendRstStream(stream_id, QUIC_RST_FLOW_CONTROL_ACCOUNTING, 0)); 134 SendRstStream(stream_id, QUIC_RST_FLOW_CONTROL_ACCOUNTING, 0));
135 visitor_->OnRstStream(rst); 135 visitor_->OnRstStream(rst);
136 136
137 // If we were tracking, we'd probably want to reject this because it's data 137 // If we were tracking, we'd probably want to reject this because it's data
138 // past the reset point of stream 3. As it's a closed stream we just drop the 138 // past the reset point of stream 3. As it's a closed stream we just drop the
139 // data on the floor, but accept the packet because it has data for stream 5. 139 // data on the floor, but accept the packet because it has data for stream 5.
140 frames.clear(); 140 frames.clear();
141 frames.push_back(QuicStreamFrame(stream_id, false, 2, MakeIOVector("TP"))); 141 frames.push_back(QuicStreamFrame(stream_id, false, 2, MakeIOVector("TP")));
142 frames.push_back(QuicStreamFrame(stream_id + 2, false, 2, 142 frames.push_back(
143 MakeIOVector("TP"))); 143 QuicStreamFrame(stream_id + 2, false, 2, MakeIOVector("TP")));
144 visitor_->OnStreamFrames(frames); 144 visitor_->OnStreamFrames(frames);
145 // The stream should never be opened, now that the reset is received. 145 // The stream should never be opened, now that the reset is received.
146 EXPECT_EQ(1u, session_->GetNumOpenStreams()); 146 EXPECT_EQ(1u, session_->GetNumOpenStreams());
147 EXPECT_TRUE(connection_->connected()); 147 EXPECT_TRUE(connection_->connected());
148 } 148 }
149 149
150 TEST_P(QuicServerSessionTest, MaxNumConnections) { 150 TEST_P(QuicServerSessionTest, MaxNumConnections) {
151 QuicStreamId stream_id = 5; 151 QuicStreamId stream_id = 5;
152 EXPECT_EQ(0u, session_->GetNumOpenStreams()); 152 EXPECT_EQ(0u, session_->GetNumOpenStreams());
153 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDataStream(session_.get(), 153 EXPECT_TRUE(
154 stream_id)); 154 QuicServerSessionPeer::GetIncomingDataStream(session_.get(), stream_id));
155 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDataStream(session_.get(), 155 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDataStream(session_.get(),
156 stream_id + 2)); 156 stream_id + 2));
157 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDataStream(session_.get(), 157 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDataStream(session_.get(),
158 stream_id + 4)); 158 stream_id + 4));
159 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)); 159 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS));
160 EXPECT_FALSE(QuicServerSessionPeer::GetIncomingDataStream(session_.get(), 160 EXPECT_FALSE(QuicServerSessionPeer::GetIncomingDataStream(session_.get(),
161 stream_id + 6)); 161 stream_id + 6));
162 } 162 }
163 163
164 TEST_P(QuicServerSessionTest, MaxNumConnectionsImplicit) { 164 TEST_P(QuicServerSessionTest, MaxNumConnectionsImplicit) {
165 QuicStreamId stream_id = 5; 165 QuicStreamId stream_id = 5;
166 EXPECT_EQ(0u, session_->GetNumOpenStreams()); 166 EXPECT_EQ(0u, session_->GetNumOpenStreams());
167 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDataStream(session_.get(), 167 EXPECT_TRUE(
168 stream_id)); 168 QuicServerSessionPeer::GetIncomingDataStream(session_.get(), stream_id));
169 // Implicitly opens two more streams. 169 // Implicitly opens two more streams.
170 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)); 170 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS));
171 EXPECT_FALSE(QuicServerSessionPeer::GetIncomingDataStream(session_.get(), 171 EXPECT_FALSE(QuicServerSessionPeer::GetIncomingDataStream(session_.get(),
172 stream_id + 6)); 172 stream_id + 6));
173 } 173 }
174 174
175 TEST_P(QuicServerSessionTest, GetEvenIncomingError) { 175 TEST_P(QuicServerSessionTest, GetEvenIncomingError) {
176 // Incoming streams on the server session must be odd. 176 // Incoming streams on the server session must be odd.
177 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID)); 177 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID));
178 EXPECT_EQ(NULL, 178 EXPECT_EQ(NULL,
179 QuicServerSessionPeer::GetIncomingDataStream(session_.get(), 4)); 179 QuicServerSessionPeer::GetIncomingDataStream(session_.get(), 4));
180 } 180 }
181 181
182 } // namespace 182 } // namespace
183 } // namespace test 183 } // namespace test
184 } // namespace tools 184 } // namespace tools
185 } // namespace net 185 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698