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

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

Issue 180723003: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unintialized memory error Created 6 years, 10 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
« no previous file with comments | « net/tools/quic/quic_server_session_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_spdy_server_stream.h" 5 #include "net/tools/quic/quic_spdy_server_stream.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_piece.h" 8 #include "base/strings/string_piece.h"
9 #include "net/quic/quic_connection.h" 9 #include "net/quic/quic_connection.h"
10 #include "net/quic/quic_protocol.h" 10 #include "net/quic/quic_protocol.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 body_("hello world") { 87 body_("hello world") {
88 BalsaHeaders request_headers; 88 BalsaHeaders request_headers;
89 request_headers.SetRequestFirstlineFromStringPieces( 89 request_headers.SetRequestFirstlineFromStringPieces(
90 "POST", "https://www.google.com/", "HTTP/1.1"); 90 "POST", "https://www.google.com/", "HTTP/1.1");
91 request_headers.ReplaceOrAppendHeader("content-length", "11"); 91 request_headers.ReplaceOrAppendHeader("content-length", "11");
92 92
93 headers_string_ = SpdyUtils::SerializeRequestHeaders(request_headers); 93 headers_string_ = SpdyUtils::SerializeRequestHeaders(request_headers);
94 stream_.reset(new QuicSpdyServerStreamPeer(3, &session_)); 94 stream_.reset(new QuicSpdyServerStreamPeer(3, &session_));
95 } 95 }
96 96
97 QuicConsumedData ValidateHeaders(const struct iovec* iov) { 97 QuicConsumedData ValidateHeaders(const IOVector& data) {
98 const iovec* iov = data.iovec();
98 StringPiece headers = 99 StringPiece headers =
99 StringPiece(static_cast<const char*>(iov[0].iov_base), iov[0].iov_len); 100 StringPiece(static_cast<const char*>(iov[0].iov_base), iov[0].iov_len);
100 headers_string_ = SpdyUtils::SerializeResponseHeaders( 101 headers_string_ = SpdyUtils::SerializeResponseHeaders(
101 response_headers_); 102 response_headers_);
102 QuicSpdyDecompressor decompressor; 103 QuicSpdyDecompressor decompressor;
103 TestDecompressorVisitor visitor; 104 TestDecompressorVisitor visitor;
104 105
105 // First the header id, then the compressed data. 106 // First the header id, then the compressed data.
106 EXPECT_EQ(1, headers[0]); 107 EXPECT_EQ(1, headers[0]);
107 EXPECT_EQ(0, headers[1]); 108 EXPECT_EQ(0, headers[1]);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 EpollServer eps_; 162 EpollServer eps_;
162 StrictMock<MockConnection>* connection_; 163 StrictMock<MockConnection>* connection_;
163 StrictMock<MockSession> session_; 164 StrictMock<MockSession> session_;
164 scoped_ptr<QuicSpdyServerStreamPeer> stream_; 165 scoped_ptr<QuicSpdyServerStreamPeer> stream_;
165 string headers_string_; 166 string headers_string_;
166 string body_; 167 string body_;
167 }; 168 };
168 169
169 QuicConsumedData ConsumeAllData( 170 QuicConsumedData ConsumeAllData(
170 QuicStreamId id, 171 QuicStreamId id,
171 const struct iovec* iov, 172 const IOVector& data,
172 int iov_count,
173 QuicStreamOffset offset, 173 QuicStreamOffset offset,
174 bool fin, 174 bool fin,
175 QuicAckNotifier::DelegateInterface* /*ack_notifier_delegate*/) { 175 QuicAckNotifier::DelegateInterface* /*ack_notifier_delegate*/) {
176 ssize_t consumed_length = 0; 176 return QuicConsumedData(data.TotalBufferSize(), fin);
177 for (int i = 0; i < iov_count; ++i) {
178 consumed_length += iov[i].iov_len;
179 }
180 return QuicConsumedData(consumed_length, fin);
181 } 177 }
182 178
183 INSTANTIATE_TEST_CASE_P(Tests, QuicSpdyServerStreamTest, 179 INSTANTIATE_TEST_CASE_P(Tests, QuicSpdyServerStreamTest,
184 ::testing::ValuesIn(QuicSupportedVersions())); 180 ::testing::ValuesIn(QuicSupportedVersions()));
185 181
186 TEST_P(QuicSpdyServerStreamTest, TestFraming) { 182 TEST_P(QuicSpdyServerStreamTest, TestFraming) {
187 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)).Times(AnyNumber()). 183 EXPECT_CALL(session_, WritevData(_, _, _, _, _)).Times(AnyNumber()).
188 WillRepeatedly(Invoke(ConsumeAllData)); 184 WillRepeatedly(Invoke(ConsumeAllData));
189 185
190 EXPECT_EQ(headers_string_.size(), stream_->ProcessData( 186 EXPECT_EQ(headers_string_.size(), stream_->ProcessData(
191 headers_string_.c_str(), headers_string_.size())); 187 headers_string_.c_str(), headers_string_.size()));
192 EXPECT_EQ(body_.size(), stream_->ProcessData(body_.c_str(), body_.size())); 188 EXPECT_EQ(body_.size(), stream_->ProcessData(body_.c_str(), body_.size()));
193 EXPECT_EQ(11u, StreamHeaders().content_length()); 189 EXPECT_EQ(11u, StreamHeaders().content_length());
194 EXPECT_EQ("https://www.google.com/", StreamHeaders().request_uri()); 190 EXPECT_EQ("https://www.google.com/", StreamHeaders().request_uri());
195 EXPECT_EQ("POST", StreamHeaders().request_method()); 191 EXPECT_EQ("POST", StreamHeaders().request_method());
196 EXPECT_EQ(body_, StreamBody()); 192 EXPECT_EQ(body_, StreamBody());
197 } 193 }
198 194
199 TEST_P(QuicSpdyServerStreamTest, TestFramingOnePacket) { 195 TEST_P(QuicSpdyServerStreamTest, TestFramingOnePacket) {
200 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)).Times(AnyNumber()). 196 EXPECT_CALL(session_, WritevData(_, _, _, _, _)).Times(AnyNumber()).
201 WillRepeatedly(Invoke(ConsumeAllData)); 197 WillRepeatedly(Invoke(ConsumeAllData));
202 198
203 string message = headers_string_ + body_; 199 string message = headers_string_ + body_;
204 200
205 EXPECT_EQ(message.size(), stream_->ProcessData( 201 EXPECT_EQ(message.size(), stream_->ProcessData(
206 message.c_str(), message.size())); 202 message.c_str(), message.size()));
207 EXPECT_EQ(11u, StreamHeaders().content_length()); 203 EXPECT_EQ(11u, StreamHeaders().content_length());
208 EXPECT_EQ("https://www.google.com/", StreamHeaders().request_uri()); 204 EXPECT_EQ("https://www.google.com/", StreamHeaders().request_uri());
209 EXPECT_EQ("POST", StreamHeaders().request_method()); 205 EXPECT_EQ("POST", StreamHeaders().request_method());
210 EXPECT_EQ(body_, StreamBody()); 206 EXPECT_EQ(body_, StreamBody());
211 } 207 }
212 208
213 TEST_P(QuicSpdyServerStreamTest, TestFramingExtraData) { 209 TEST_P(QuicSpdyServerStreamTest, TestFramingExtraData) {
214 string large_body = "hello world!!!!!!"; 210 string large_body = "hello world!!!!!!";
215 211
216 // We'll automatically write out an error (headers + body) 212 // We'll automatically write out an error (headers + body)
217 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)).Times(AnyNumber()). 213 EXPECT_CALL(session_, WritevData(_, _, _, _, _)).Times(AnyNumber()).
218 WillRepeatedly(Invoke(ConsumeAllData)); 214 WillRepeatedly(Invoke(ConsumeAllData));
219 215
220 EXPECT_EQ(headers_string_.size(), stream_->ProcessData( 216 EXPECT_EQ(headers_string_.size(), stream_->ProcessData(
221 headers_string_.c_str(), headers_string_.size())); 217 headers_string_.c_str(), headers_string_.size()));
222 // Content length is still 11. This will register as an error and we won't 218 // Content length is still 11. This will register as an error and we won't
223 // accept the bytes. 219 // accept the bytes.
224 stream_->ProcessData(large_body.c_str(), large_body.size()); 220 stream_->ProcessData(large_body.c_str(), large_body.size());
225 EXPECT_EQ(11u, StreamHeaders().content_length()); 221 EXPECT_EQ(11u, StreamHeaders().content_length());
226 EXPECT_EQ("https://www.google.com/", StreamHeaders().request_uri()); 222 EXPECT_EQ("https://www.google.com/", StreamHeaders().request_uri());
227 EXPECT_EQ("POST", StreamHeaders().request_method()); 223 EXPECT_EQ("POST", StreamHeaders().request_method());
228 } 224 }
229 225
230 TEST_P(QuicSpdyServerStreamTest, TestSendResponse) { 226 TEST_P(QuicSpdyServerStreamTest, TestSendResponse) {
231 BalsaHeaders* request_headers = stream_->mutable_headers(); 227 BalsaHeaders* request_headers = stream_->mutable_headers();
232 request_headers->SetRequestFirstlineFromStringPieces( 228 request_headers->SetRequestFirstlineFromStringPieces(
233 "GET", 229 "GET",
234 "https://www.google.com/foo", 230 "https://www.google.com/foo",
235 "HTTP/1.1"); 231 "HTTP/1.1");
236 232
237 response_headers_.SetResponseFirstlineFromStringPieces( 233 response_headers_.SetResponseFirstlineFromStringPieces(
238 "HTTP/1.1", "200", "OK"); 234 "HTTP/1.1", "200", "OK");
239 response_headers_.ReplaceOrAppendHeader("content-length", "3"); 235 response_headers_.ReplaceOrAppendHeader("content-length", "3");
240 236
241 InSequence s; 237 InSequence s;
242 if (GetParam() > QUIC_VERSION_12) { 238 if (GetParam() > QUIC_VERSION_12) {
243 EXPECT_CALL(session_, 239 EXPECT_CALL(session_,
244 WritevData(kHeadersStreamId, _, _, 0, false, NULL)); 240 WritevData(kHeadersStreamId, _, 0, false, NULL));
245 } else { 241 } else {
246 EXPECT_CALL(session_, WritevData(_, _, 1, _, _, _)).Times(1) 242 EXPECT_CALL(session_, WritevData(_, _, _, _, _)).Times(1)
247 .WillOnce(WithArgs<1>(Invoke( 243 .WillOnce(WithArgs<1>(Invoke(
248 this, &QuicSpdyServerStreamTest::ValidateHeaders))); 244 this, &QuicSpdyServerStreamTest::ValidateHeaders)));
249 } 245 }
250 246
251 EXPECT_CALL(session_, WritevData(_, _, 1, _, _, _)).Times(1). 247 EXPECT_CALL(session_, WritevData(_, _, _, _, _)).Times(1).
252 WillOnce(Return(QuicConsumedData(3, true))); 248 WillOnce(Return(QuicConsumedData(3, true)));
253 249
254 QuicSpdyServerStreamPeer::SendResponse(stream_.get()); 250 QuicSpdyServerStreamPeer::SendResponse(stream_.get());
255 EXPECT_TRUE(stream_->read_side_closed()); 251 EXPECT_TRUE(stream_->read_side_closed());
256 EXPECT_TRUE(stream_->write_side_closed()); 252 EXPECT_TRUE(stream_->write_side_closed());
257 } 253 }
258 254
259 TEST_P(QuicSpdyServerStreamTest, TestSendErrorResponse) { 255 TEST_P(QuicSpdyServerStreamTest, TestSendErrorResponse) {
260 response_headers_.SetResponseFirstlineFromStringPieces( 256 response_headers_.SetResponseFirstlineFromStringPieces(
261 "HTTP/1.1", "500", "Server Error"); 257 "HTTP/1.1", "500", "Server Error");
262 response_headers_.ReplaceOrAppendHeader("content-length", "3"); 258 response_headers_.ReplaceOrAppendHeader("content-length", "3");
263 259
264 InSequence s; 260 InSequence s;
265 if (GetParam() > QUIC_VERSION_12) { 261 if (GetParam() > QUIC_VERSION_12) {
266 EXPECT_CALL(session_, WritevData(kHeadersStreamId, _, _, 0, false, NULL)); 262 EXPECT_CALL(session_,
263 WritevData(kHeadersStreamId, _, 0, false, NULL));
267 } else { 264 } else {
268 EXPECT_CALL(session_, WritevData(_, _, 1, _, _, _)).Times(1) 265 EXPECT_CALL(session_, WritevData(_, _, _, _, _)).Times(1)
269 .WillOnce(WithArgs<1>(Invoke( 266 .WillOnce(WithArgs<1>(Invoke(
270 this, &QuicSpdyServerStreamTest::ValidateHeaders))); 267 this, &QuicSpdyServerStreamTest::ValidateHeaders)));
271 } 268 }
272 269
273 EXPECT_CALL(session_, WritevData(_, _, 1, _, _, _)).Times(1). 270 EXPECT_CALL(session_, WritevData(_, _, _, _, _)).Times(1).
274 WillOnce(Return(QuicConsumedData(3, true))); 271 WillOnce(Return(QuicConsumedData(3, true)));
275 272
276 QuicSpdyServerStreamPeer::SendErrorResponse(stream_.get()); 273 QuicSpdyServerStreamPeer::SendErrorResponse(stream_.get());
277 EXPECT_TRUE(stream_->read_side_closed()); 274 EXPECT_TRUE(stream_->read_side_closed());
278 EXPECT_TRUE(stream_->write_side_closed()); 275 EXPECT_TRUE(stream_->write_side_closed());
279 } 276 }
280 277
281 TEST_P(QuicSpdyServerStreamTest, InvalidHeadersWithFin) { 278 TEST_P(QuicSpdyServerStreamTest, InvalidHeadersWithFin) {
282 char arr[] = { 279 char arr[] = {
283 0x05, 0x00, 0x00, 0x00, // .... 280 0x05, 0x00, 0x00, 0x00, // ....
(...skipping 24 matching lines...) Expand all
308 StringPiece data(arr + start, arraysize(arr) - start); 305 StringPiece data(arr + start, arraysize(arr) - start);
309 QuicStreamFrame frame(stream_->id(), true, 0, MakeIOVector(data)); 306 QuicStreamFrame frame(stream_->id(), true, 0, MakeIOVector(data));
310 // Verify that we don't crash when we get a invalid headers in stream frame. 307 // Verify that we don't crash when we get a invalid headers in stream frame.
311 stream_->OnStreamFrame(frame); 308 stream_->OnStreamFrame(frame);
312 } 309 }
313 310
314 } // namespace 311 } // namespace
315 } // namespace test 312 } // namespace test
316 } // namespace tools 313 } // namespace tools
317 } // namespace net 314 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_server_session_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698