| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/spdy/spdy_headers_block_parser.h" | 5 #include "net/spdy/spdy_headers_block_parser.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 class SpdyHeadersBlockParserTest : | 33 class SpdyHeadersBlockParserTest : |
| 34 public ::testing::TestWithParam<SpdyMajorVersion> { | 34 public ::testing::TestWithParam<SpdyMajorVersion> { |
| 35 public: | 35 public: |
| 36 virtual ~SpdyHeadersBlockParserTest() {} | 36 virtual ~SpdyHeadersBlockParserTest() {} |
| 37 | 37 |
| 38 protected: | 38 protected: |
| 39 void SetUp() override { | 39 void SetUp() override { |
| 40 // Create a parser using the mock handler. | 40 // Create a parser using the mock handler. |
| 41 spdy_version_ = GetParam(); | 41 spdy_version_ = GetParam(); |
| 42 |
| 42 parser_.reset(new SpdyHeadersBlockParser(spdy_version_, &handler_)); | 43 parser_.reset(new SpdyHeadersBlockParser(spdy_version_, &handler_)); |
| 43 length_field_size_ = | 44 length_field_size_ = |
| 44 SpdyHeadersBlockParser::LengthFieldSizeForVersion(spdy_version_); | 45 SpdyHeadersBlockParser::LengthFieldSizeForVersion(spdy_version_); |
| 45 } | 46 } |
| 46 | 47 |
| 47 // Create a header block with a specified number of headers. | 48 // Create a header block with a specified number of headers. |
| 48 string CreateHeaders(uint32_t num_headers, bool insert_nulls) { | 49 string CreateHeaders(uint32_t num_headers, bool insert_nulls) { |
| 49 string headers; | 50 string headers; |
| 50 | 51 |
| 51 // First, write the number of headers in the header block. | 52 // First, write the number of headers in the header block. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 TEST_P(SpdyHeadersBlockParserTest, LargeBlocksDiscardedTest) { | 218 TEST_P(SpdyHeadersBlockParserTest, LargeBlocksDiscardedTest) { |
| 218 // Header block with too many headers. | 219 // Header block with too many headers. |
| 219 { | 220 { |
| 220 string headers = EncodeLength( | 221 string headers = EncodeLength( |
| 221 parser_->MaxNumberOfHeadersForVersion(spdy_version_) + 1); | 222 parser_->MaxNumberOfHeadersForVersion(spdy_version_) + 1); |
| 222 EXPECT_FALSE(parser_-> | 223 EXPECT_FALSE(parser_-> |
| 223 HandleControlFrameHeadersData(1, headers.c_str(), headers.length())); | 224 HandleControlFrameHeadersData(1, headers.c_str(), headers.length())); |
| 224 EXPECT_EQ(SpdyHeadersBlockParser::HEADER_BLOCK_TOO_LARGE, | 225 EXPECT_EQ(SpdyHeadersBlockParser::HEADER_BLOCK_TOO_LARGE, |
| 225 parser_->get_error()); | 226 parser_->get_error()); |
| 226 } | 227 } |
| 227 parser_->Reset(); | 228 parser_.reset(new SpdyHeadersBlockParser(spdy_version_, &handler_)); |
| 228 // Header block with one header, which has a too-long key. | 229 // Header block with one header, which has a too-long key. |
| 229 { | 230 { |
| 230 EXPECT_CALL(handler_, OnHeaderBlock(1, 1)).Times(1); | 231 EXPECT_CALL(handler_, OnHeaderBlock(1, 1)).Times(1); |
| 231 | 232 |
| 232 string headers = EncodeLength(1) + EncodeLength( | 233 string headers = EncodeLength(1) + EncodeLength( |
| 233 SpdyHeadersBlockParser::kMaximumFieldLength + 1); | 234 SpdyHeadersBlockParser::kMaximumFieldLength + 1); |
| 234 EXPECT_FALSE(parser_-> | 235 EXPECT_FALSE(parser_-> |
| 235 HandleControlFrameHeadersData(1, headers.c_str(), headers.length())); | 236 HandleControlFrameHeadersData(1, headers.c_str(), headers.length())); |
| 236 EXPECT_EQ(SpdyHeadersBlockParser::HEADER_FIELD_TOO_LARGE, | 237 EXPECT_EQ(SpdyHeadersBlockParser::HEADER_FIELD_TOO_LARGE, |
| 237 parser_->get_error()); | 238 parser_->get_error()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 248 string expect_value = kBaseValue + IntToString(0); | 249 string expect_value = kBaseValue + IntToString(0); |
| 249 EXPECT_CALL(handler_, OnHeader(1, StringPiece(expect_key), | 250 EXPECT_CALL(handler_, OnHeader(1, StringPiece(expect_key), |
| 250 StringPiece(expect_value))).Times(1); | 251 StringPiece(expect_value))).Times(1); |
| 251 | 252 |
| 252 EXPECT_FALSE(parser_-> | 253 EXPECT_FALSE(parser_-> |
| 253 HandleControlFrameHeadersData(1, headers.c_str(), headers.length())); | 254 HandleControlFrameHeadersData(1, headers.c_str(), headers.length())); |
| 254 EXPECT_EQ(SpdyHeadersBlockParser::TOO_MUCH_DATA, parser_->get_error()); | 255 EXPECT_EQ(SpdyHeadersBlockParser::TOO_MUCH_DATA, parser_->get_error()); |
| 255 } | 256 } |
| 256 | 257 |
| 257 } // namespace net | 258 } // namespace net |
| OLD | NEW |