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

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

Issue 185203003: Killing off QUICv12, including cleaning out all of the code for handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Deleted unused StripUint32 Created 6 years, 9 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_spdy_server_stream.cc ('k') | net/tools/quic/test_tools/quic_test_utils.h » ('j') | 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"
11 #include "net/quic/quic_spdy_compressor.h"
12 #include "net/quic/quic_utils.h" 11 #include "net/quic/quic_utils.h"
13 #include "net/quic/test_tools/quic_test_utils.h" 12 #include "net/quic/test_tools/quic_test_utils.h"
14 #include "net/tools/epoll_server/epoll_server.h" 13 #include "net/tools/epoll_server/epoll_server.h"
15 #include "net/tools/quic/quic_in_memory_cache.h" 14 #include "net/tools/quic/quic_in_memory_cache.h"
16 #include "net/tools/quic/spdy_utils.h" 15 #include "net/tools/quic/spdy_utils.h"
17 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" 16 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h"
18 #include "net/tools/quic/test_tools/quic_test_utils.h" 17 #include "net/tools/quic/test_tools/quic_test_utils.h"
19 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
21 20
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 body_("hello world") { 86 body_("hello world") {
88 BalsaHeaders request_headers; 87 BalsaHeaders request_headers;
89 request_headers.SetRequestFirstlineFromStringPieces( 88 request_headers.SetRequestFirstlineFromStringPieces(
90 "POST", "https://www.google.com/", "HTTP/1.1"); 89 "POST", "https://www.google.com/", "HTTP/1.1");
91 request_headers.ReplaceOrAppendHeader("content-length", "11"); 90 request_headers.ReplaceOrAppendHeader("content-length", "11");
92 91
93 headers_string_ = SpdyUtils::SerializeRequestHeaders(request_headers); 92 headers_string_ = SpdyUtils::SerializeRequestHeaders(request_headers);
94 stream_.reset(new QuicSpdyServerStreamPeer(3, &session_)); 93 stream_.reset(new QuicSpdyServerStreamPeer(3, &session_));
95 } 94 }
96 95
97 QuicConsumedData ValidateHeaders(const IOVector& data) {
98 const iovec* iov = data.iovec();
99 StringPiece headers =
100 StringPiece(static_cast<const char*>(iov[0].iov_base), iov[0].iov_len);
101 headers_string_ = SpdyUtils::SerializeResponseHeaders(
102 response_headers_);
103 QuicSpdyDecompressor decompressor;
104 TestDecompressorVisitor visitor;
105
106 // First the header id, then the compressed data.
107 EXPECT_EQ(1, headers[0]);
108 EXPECT_EQ(0, headers[1]);
109 EXPECT_EQ(0, headers[2]);
110 EXPECT_EQ(0, headers[3]);
111 EXPECT_EQ(static_cast<size_t>(headers.length() - 4),
112 decompressor.DecompressData(headers.substr(4), &visitor));
113
114 EXPECT_EQ(headers_string_, visitor.data());
115
116 return QuicConsumedData(headers.size(), false);
117 }
118
119 static void SetUpTestCase() { 96 static void SetUpTestCase() {
120 QuicInMemoryCachePeer::ResetForTests(); 97 QuicInMemoryCachePeer::ResetForTests();
121 } 98 }
122 99
123 virtual void SetUp() { 100 virtual void SetUp() {
124 QuicInMemoryCache* cache = QuicInMemoryCache::GetInstance(); 101 QuicInMemoryCache* cache = QuicInMemoryCache::GetInstance();
125 102
126 BalsaHeaders request_headers, response_headers; 103 BalsaHeaders request_headers, response_headers;
127 StringPiece body("Yum"); 104 StringPiece body("Yum");
128 request_headers.SetRequestFirstlineFromStringPieces( 105 request_headers.SetRequestFirstlineFromStringPieces(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 request_headers->SetRequestFirstlineFromStringPieces( 205 request_headers->SetRequestFirstlineFromStringPieces(
229 "GET", 206 "GET",
230 "https://www.google.com/foo", 207 "https://www.google.com/foo",
231 "HTTP/1.1"); 208 "HTTP/1.1");
232 209
233 response_headers_.SetResponseFirstlineFromStringPieces( 210 response_headers_.SetResponseFirstlineFromStringPieces(
234 "HTTP/1.1", "200", "OK"); 211 "HTTP/1.1", "200", "OK");
235 response_headers_.ReplaceOrAppendHeader("content-length", "3"); 212 response_headers_.ReplaceOrAppendHeader("content-length", "3");
236 213
237 InSequence s; 214 InSequence s;
238 if (GetParam() > QUIC_VERSION_12) { 215 EXPECT_CALL(session_,
239 EXPECT_CALL(session_, 216 WritevData(kHeadersStreamId, _, 0, false, NULL));
240 WritevData(kHeadersStreamId, _, 0, false, NULL)); 217
241 } else {
242 EXPECT_CALL(session_, WritevData(_, _, _, _, _)).Times(1)
243 .WillOnce(WithArgs<1>(Invoke(
244 this, &QuicSpdyServerStreamTest::ValidateHeaders)));
245 }
246 218
247 EXPECT_CALL(session_, WritevData(_, _, _, _, _)).Times(1). 219 EXPECT_CALL(session_, WritevData(_, _, _, _, _)).Times(1).
248 WillOnce(Return(QuicConsumedData(3, true))); 220 WillOnce(Return(QuicConsumedData(3, true)));
249 221
250 QuicSpdyServerStreamPeer::SendResponse(stream_.get()); 222 QuicSpdyServerStreamPeer::SendResponse(stream_.get());
251 EXPECT_TRUE(stream_->read_side_closed()); 223 EXPECT_TRUE(stream_->read_side_closed());
252 EXPECT_TRUE(stream_->write_side_closed()); 224 EXPECT_TRUE(stream_->write_side_closed());
253 } 225 }
254 226
255 TEST_P(QuicSpdyServerStreamTest, TestSendErrorResponse) { 227 TEST_P(QuicSpdyServerStreamTest, TestSendErrorResponse) {
256 response_headers_.SetResponseFirstlineFromStringPieces( 228 response_headers_.SetResponseFirstlineFromStringPieces(
257 "HTTP/1.1", "500", "Server Error"); 229 "HTTP/1.1", "500", "Server Error");
258 response_headers_.ReplaceOrAppendHeader("content-length", "3"); 230 response_headers_.ReplaceOrAppendHeader("content-length", "3");
259 231
260 InSequence s; 232 InSequence s;
261 if (GetParam() > QUIC_VERSION_12) { 233 EXPECT_CALL(session_,
262 EXPECT_CALL(session_, 234 WritevData(kHeadersStreamId, _, 0, false, NULL));
263 WritevData(kHeadersStreamId, _, 0, false, NULL));
264 } else {
265 EXPECT_CALL(session_, WritevData(_, _, _, _, _)).Times(1)
266 .WillOnce(WithArgs<1>(Invoke(
267 this, &QuicSpdyServerStreamTest::ValidateHeaders)));
268 }
269 235
270 EXPECT_CALL(session_, WritevData(_, _, _, _, _)).Times(1). 236 EXPECT_CALL(session_, WritevData(_, _, _, _, _)).Times(1).
271 WillOnce(Return(QuicConsumedData(3, true))); 237 WillOnce(Return(QuicConsumedData(3, true)));
272 238
273 QuicSpdyServerStreamPeer::SendErrorResponse(stream_.get()); 239 QuicSpdyServerStreamPeer::SendErrorResponse(stream_.get());
274 EXPECT_TRUE(stream_->read_side_closed()); 240 EXPECT_TRUE(stream_->read_side_closed());
275 EXPECT_TRUE(stream_->write_side_closed()); 241 EXPECT_TRUE(stream_->write_side_closed());
276 } 242 }
277 243
278 TEST_P(QuicSpdyServerStreamTest, InvalidHeadersWithFin) { 244 TEST_P(QuicSpdyServerStreamTest, InvalidHeadersWithFin) {
279 char arr[] = { 245 char arr[] = {
280 0x05, 0x00, 0x00, 0x00, // ....
281 0x05, 0x00, 0x00, 0x00, // ....
282 0x3a, 0x68, 0x6f, 0x73, // :hos 246 0x3a, 0x68, 0x6f, 0x73, // :hos
283 0x74, 0x00, 0x00, 0x00, // t... 247 0x74, 0x00, 0x00, 0x00, // t...
284 0x00, 0x00, 0x00, 0x00, // .... 248 0x00, 0x00, 0x00, 0x00, // ....
285 0x07, 0x3a, 0x6d, 0x65, // .:me 249 0x07, 0x3a, 0x6d, 0x65, // .:me
286 0x74, 0x68, 0x6f, 0x64, // thod 250 0x74, 0x68, 0x6f, 0x64, // thod
287 0x00, 0x00, 0x00, 0x03, // .... 251 0x00, 0x00, 0x00, 0x03, // ....
288 0x47, 0x45, 0x54, 0x00, // GET. 252 0x47, 0x45, 0x54, 0x00, // GET.
289 0x00, 0x00, 0x05, 0x3a, // ...: 253 0x00, 0x00, 0x05, 0x3a, // ...:
290 0x70, 0x61, 0x74, 0x68, // path 254 0x70, 0x61, 0x74, 0x68, // path
291 0x00, 0x00, 0x00, 0x04, // .... 255 0x00, 0x00, 0x00, 0x04, // ....
292 0x2f, 0x66, 0x6f, 0x6f, // /foo 256 0x2f, 0x66, 0x6f, 0x6f, // /foo
293 0x00, 0x00, 0x00, 0x07, // .... 257 0x00, 0x00, 0x00, 0x07, // ....
294 0x3a, 0x73, 0x63, 0x68, // :sch 258 0x3a, 0x73, 0x63, 0x68, // :sch
295 0x65, 0x6d, 0x65, 0x00, // eme. 259 0x65, 0x6d, 0x65, 0x00, // eme.
296 0x00, 0x00, 0x00, 0x00, // .... 260 0x00, 0x00, 0x00, 0x00, // ....
297 0x00, 0x00, 0x08, 0x3a, // ...: 261 0x00, 0x00, 0x08, 0x3a, // ...:
298 0x76, 0x65, 0x72, 0x73, // vers 262 0x76, 0x65, 0x72, 0x73, // vers
299 '\x96', 0x6f, 0x6e, 0x00, // <i(69)>on. 263 '\x96', 0x6f, 0x6e, 0x00, // <i(69)>on.
300 0x00, 0x00, 0x08, 0x48, // ...H 264 0x00, 0x00, 0x08, 0x48, // ...H
301 0x54, 0x54, 0x50, 0x2f, // TTP/ 265 0x54, 0x54, 0x50, 0x2f, // TTP/
302 0x31, 0x2e, 0x31, // 1.1 266 0x31, 0x2e, 0x31, // 1.1
303 }; 267 };
304 size_t start = GetParam() > QUIC_VERSION_12 ? 8 : 0; 268 StringPiece data(arr, arraysize(arr));
305 StringPiece data(arr + start, arraysize(arr) - start);
306 QuicStreamFrame frame(stream_->id(), true, 0, MakeIOVector(data)); 269 QuicStreamFrame frame(stream_->id(), true, 0, MakeIOVector(data));
307 // Verify that we don't crash when we get a invalid headers in stream frame. 270 // Verify that we don't crash when we get a invalid headers in stream frame.
308 stream_->OnStreamFrame(frame); 271 stream_->OnStreamFrame(frame);
309 } 272 }
310 273
311 } // namespace 274 } // namespace
312 } // namespace test 275 } // namespace test
313 } // namespace tools 276 } // namespace tools
314 } // namespace net 277 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_spdy_server_stream.cc ('k') | net/tools/quic/test_tools/quic_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698