[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/spdy/spdy_headers_block_parser.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 9 | #include "base/memory/scoped_ptr.h" |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 10 | #include "base/strings/string_number_conversions.h" |
| 11 | #include "base/sys_byteorder.h" |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 12 | #include "net/test/gtest_util.h" |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 13 | #include "testing/gmock/include/gmock/gmock.h" |
| 14 | #include "testing/gtest/include/gtest/gtest.h" |
| 15 | |
| 16 | namespace net { |
| 17 | |
| 18 | using base::IntToString; |
| 19 | using base::StringPiece; |
| 20 | using std::string; |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 21 | |
[email protected] | 976aa18f | 2014-01-29 08:49:07 | [diff] [blame] | 22 | // A mock the handler class to check that we parse out the correct headers |
| 23 | // and call the callback methods when we should. |
| 24 | class MockSpdyHeadersHandler : public SpdyHeadersHandlerInterface { |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 25 | public: |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 26 | MOCK_METHOD1(OnHeaderBlock, void(uint32_t num_of_headers)); |
| 27 | MOCK_METHOD1(OnHeaderBlockEnd, void(size_t bytes)); |
| 28 | MOCK_METHOD2(OnHeader, void(StringPiece key, StringPiece value)); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 29 | }; |
| 30 | |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 31 | class SpdyHeadersBlockParserTest : |
| 32 | public ::testing::TestWithParam<SpdyMajorVersion> { |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 33 | public: |
| 34 | virtual ~SpdyHeadersBlockParserTest() {} |
| 35 | |
| 36 | protected: |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 37 | void SetUp() override { |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 38 | // Create a parser using the mock handler. |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 39 | spdy_version_ = GetParam(); |
bnc | 7701ff6 | 2014-12-18 20:29:53 | [diff] [blame] | 40 | |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 41 | parser_.reset(new SpdyHeadersBlockParser(spdy_version_, &handler_)); |
| 42 | length_field_size_ = |
| 43 | SpdyHeadersBlockParser::LengthFieldSizeForVersion(spdy_version_); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 44 | } |
| 45 | |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 46 | // Create a header block with a specified number of headers. |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 47 | string CreateHeaders(uint32_t num_headers, bool insert_nulls) { |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 48 | string headers; |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 49 | |
| 50 | // First, write the number of headers in the header block. |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 51 | headers += EncodeLength(num_headers); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 52 | |
| 53 | // Second, write the key-value pairs. |
| 54 | for (uint32_t i = 0; i < num_headers; i++) { |
| 55 | // Build the key. |
| 56 | string key; |
| 57 | if (insert_nulls) { |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 58 | key = string(kBaseKey) + string("\0", 1) + IntToString(i); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 59 | } else { |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 60 | key = string(kBaseKey) + IntToString(i); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 61 | } |
| 62 | // Encode the key as SPDY header. |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 63 | headers += EncodeLength(key.length()); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 64 | headers += key; |
| 65 | |
| 66 | // Build the value. |
| 67 | string value; |
| 68 | if (insert_nulls) { |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 69 | value = string(kBaseValue) + string("\0", 1) + IntToString(i); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 70 | } else { |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 71 | value = string(kBaseValue) + IntToString(i); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 72 | } |
| 73 | // Encode the value as SPDY header. |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 74 | headers += EncodeLength(value.length()); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 75 | headers += value; |
| 76 | } |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 77 | return headers; |
| 78 | } |
| 79 | |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 80 | string EncodeLength(uint32_t len) { |
| 81 | char buffer[4]; |
| 82 | if (length_field_size_ == sizeof(uint32_t)) { |
| 83 | uint32_t net_order_len = htonl(len); |
| 84 | memcpy(buffer, &net_order_len, length_field_size_); |
| 85 | } else if (length_field_size_ == sizeof(uint16_t)) { |
| 86 | uint16_t net_order_len = htons(len); |
| 87 | memcpy(buffer, &net_order_len, length_field_size_); |
| 88 | } else { |
| 89 | CHECK(false) << "Invalid length field size"; |
| 90 | } |
| 91 | return string(buffer, length_field_size_); |
| 92 | } |
| 93 | |
| 94 | size_t length_field_size_; |
| 95 | SpdyMajorVersion spdy_version_; |
| 96 | |
| 97 | MockSpdyHeadersHandler handler_; |
| 98 | scoped_ptr<SpdyHeadersBlockParser> parser_; |
| 99 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 100 | static const char *const kBaseKey; |
| 101 | static const char *const kBaseValue; |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 102 | |
| 103 | // Number of headers and header blocks used in the tests. |
| 104 | static const int kNumHeadersInBlock = 10; |
| 105 | static const int kNumHeaderBlocks = 10; |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 106 | }; |
| 107 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 108 | const char *const SpdyHeadersBlockParserTest::kBaseKey = "test_key"; |
| 109 | const char *const SpdyHeadersBlockParserTest::kBaseValue = "test_value"; |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 110 | |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 111 | // All tests are run with 3 different SPDY versions: SPDY/2, SPDY/3, SPDY/4. |
| 112 | INSTANTIATE_TEST_CASE_P(SpdyHeadersBlockParserTests, |
| 113 | SpdyHeadersBlockParserTest, |
| 114 | ::testing::Values(SPDY2, SPDY3, SPDY4)); |
| 115 | |
| 116 | TEST_P(SpdyHeadersBlockParserTest, BasicTest) { |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 117 | // Sanity test, verify that we parse out correctly a block with |
[email protected] | 976aa18f | 2014-01-29 08:49:07 | [diff] [blame] | 118 | // a single key-value pair and that we notify when we start and finish |
| 119 | // handling a headers block. |
bnc | d53c312 | 2015-03-12 02:58:47 | [diff] [blame^] | 120 | EXPECT_EQ(spdy_version_, parser_->spdy_version()); |
| 121 | |
[email protected] | a73a3c1 | 2014-05-18 19:01:54 | [diff] [blame] | 122 | string headers(CreateHeaders(1, false)); |
| 123 | |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 124 | EXPECT_CALL(handler_, OnHeaderBlock(1)).Times(1); |
[email protected] | 976aa18f | 2014-01-29 08:49:07 | [diff] [blame] | 125 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 126 | std::string expect_key = kBaseKey + IntToString(0); |
| 127 | std::string expect_value = kBaseValue + IntToString(0); |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 128 | EXPECT_CALL(handler_, OnHeader(StringPiece(expect_key), |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 129 | StringPiece(expect_value))).Times(1); |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 130 | EXPECT_CALL(handler_, OnHeaderBlockEnd(headers.length())).Times(1); |
[email protected] | 976aa18f | 2014-01-29 08:49:07 | [diff] [blame] | 131 | |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 132 | EXPECT_TRUE(parser_-> |
| 133 | HandleControlFrameHeadersData(1, headers.c_str(), headers.length())); |
bnc | f697c9c | 2015-01-26 16:30:34 | [diff] [blame] | 134 | EXPECT_EQ(SpdyHeadersBlockParser::NO_PARSER_ERROR, parser_->get_error()); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 135 | } |
| 136 | |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 137 | TEST_P(SpdyHeadersBlockParserTest, NullsSupportedTest) { |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 138 | // Sanity test, verify that we parse out correctly a block with |
| 139 | // a single key-value pair when the key and value contain null charecters. |
[email protected] | a73a3c1 | 2014-05-18 19:01:54 | [diff] [blame] | 140 | string headers(CreateHeaders(1, true)); |
| 141 | |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 142 | EXPECT_CALL(handler_, OnHeaderBlock(1)).Times(1); |
[email protected] | 976aa18f | 2014-01-29 08:49:07 | [diff] [blame] | 143 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 144 | std::string expect_key = kBaseKey + string("\0", 1) + IntToString(0); |
| 145 | std::string expect_value = kBaseValue + string("\0", 1) + IntToString(0); |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 146 | EXPECT_CALL(handler_, OnHeader(StringPiece(expect_key), |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 147 | StringPiece(expect_value))).Times(1); |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 148 | EXPECT_CALL(handler_, OnHeaderBlockEnd(headers.length())).Times(1); |
[email protected] | 976aa18f | 2014-01-29 08:49:07 | [diff] [blame] | 149 | |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 150 | EXPECT_TRUE(parser_-> |
| 151 | HandleControlFrameHeadersData(1, headers.c_str(), headers.length())); |
bnc | f697c9c | 2015-01-26 16:30:34 | [diff] [blame] | 152 | EXPECT_EQ(SpdyHeadersBlockParser::NO_PARSER_ERROR, parser_->get_error()); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 153 | } |
| 154 | |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 155 | TEST_P(SpdyHeadersBlockParserTest, MultipleBlocksAndHeadersWithPartialData) { |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 156 | testing::InSequence s; |
| 157 | |
[email protected] | a73a3c1 | 2014-05-18 19:01:54 | [diff] [blame] | 158 | // CreateHeaders is deterministic; we can call it once for the whole test. |
| 159 | string headers(CreateHeaders(kNumHeadersInBlock, false)); |
| 160 | |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 161 | // The mock doesn't retain storage of arguments, so keep them in scope. |
| 162 | std::vector<string> retained_arguments; |
| 163 | for (int i = 0; i < kNumHeadersInBlock; i++) { |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 164 | retained_arguments.push_back(kBaseKey + IntToString(i)); |
| 165 | retained_arguments.push_back(kBaseValue + IntToString(i)); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 166 | } |
| 167 | // For each block we expect to parse out the headers in order. |
| 168 | for (int i = 0; i < kNumHeaderBlocks; i++) { |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 169 | EXPECT_CALL(handler_, OnHeaderBlock(kNumHeadersInBlock)).Times(1); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 170 | for (int j = 0; j < kNumHeadersInBlock; j++) { |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 171 | EXPECT_CALL(handler_, OnHeader( |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 172 | StringPiece(retained_arguments[2 * j]), |
| 173 | StringPiece(retained_arguments[2 * j + 1]))).Times(1); |
| 174 | } |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 175 | EXPECT_CALL(handler_, OnHeaderBlockEnd(headers.length())).Times(1); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 176 | } |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 177 | // Parse the header blocks, feeding the parser one byte at a time. |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 178 | for (int i = 1; i <= kNumHeaderBlocks; i++) { |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 179 | for (string::iterator it = headers.begin(); it != headers.end(); ++it) { |
| 180 | if ((it + 1) == headers.end()) { |
| 181 | // Last byte completes the block. |
| 182 | EXPECT_TRUE(parser_->HandleControlFrameHeadersData(i, &(*it), 1)); |
bnc | f697c9c | 2015-01-26 16:30:34 | [diff] [blame] | 183 | EXPECT_EQ(SpdyHeadersBlockParser::NO_PARSER_ERROR, |
| 184 | parser_->get_error()); |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 185 | } else { |
| 186 | EXPECT_FALSE(parser_->HandleControlFrameHeadersData(i, &(*it), 1)); |
| 187 | EXPECT_EQ(SpdyHeadersBlockParser::NEED_MORE_DATA, parser_->get_error()); |
| 188 | } |
| 189 | } |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 193 | TEST_P(SpdyHeadersBlockParserTest, HandlesEmptyCallsTest) { |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 194 | EXPECT_CALL(handler_, OnHeaderBlock(1)).Times(1); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 195 | |
[email protected] | a73a3c1 | 2014-05-18 19:01:54 | [diff] [blame] | 196 | string headers(CreateHeaders(1, false)); |
| 197 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 198 | string expect_key = kBaseKey + IntToString(0); |
| 199 | string expect_value = kBaseValue + IntToString(0); |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 200 | EXPECT_CALL(handler_, OnHeader(StringPiece(expect_key), |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 201 | StringPiece(expect_value))).Times(1); |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 202 | EXPECT_CALL(handler_, OnHeaderBlockEnd(headers.length())).Times(1); |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 203 | |
| 204 | // Send a header in pieces with intermediate empty calls. |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 205 | for (string::iterator it = headers.begin(); it != headers.end(); ++it) { |
| 206 | if ((it + 1) == headers.end()) { |
| 207 | // Last byte completes the block. |
| 208 | EXPECT_TRUE(parser_->HandleControlFrameHeadersData(1, &(*it), 1)); |
bnc | f697c9c | 2015-01-26 16:30:34 | [diff] [blame] | 209 | EXPECT_EQ(SpdyHeadersBlockParser::NO_PARSER_ERROR, parser_->get_error()); |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 210 | } else { |
| 211 | EXPECT_FALSE(parser_->HandleControlFrameHeadersData(1, &(*it), 1)); |
| 212 | EXPECT_EQ(SpdyHeadersBlockParser::NEED_MORE_DATA, parser_->get_error()); |
| 213 | EXPECT_FALSE(parser_->HandleControlFrameHeadersData(1, NULL, 0)); |
| 214 | } |
| 215 | } |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 216 | } |
| 217 | |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 218 | TEST_P(SpdyHeadersBlockParserTest, LargeBlocksDiscardedTest) { |
| 219 | // Header block with too many headers. |
| 220 | { |
| 221 | string headers = EncodeLength( |
| 222 | parser_->MaxNumberOfHeadersForVersion(spdy_version_) + 1); |
| 223 | EXPECT_FALSE(parser_-> |
| 224 | HandleControlFrameHeadersData(1, headers.c_str(), headers.length())); |
| 225 | EXPECT_EQ(SpdyHeadersBlockParser::HEADER_BLOCK_TOO_LARGE, |
| 226 | parser_->get_error()); |
| 227 | } |
bnc | 7701ff6 | 2014-12-18 20:29:53 | [diff] [blame] | 228 | parser_.reset(new SpdyHeadersBlockParser(spdy_version_, &handler_)); |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 229 | // Header block with one header, which has a too-long key. |
| 230 | { |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 231 | EXPECT_CALL(handler_, OnHeaderBlock(1)).Times(1); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 232 | |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 233 | string headers = EncodeLength(1) + EncodeLength( |
| 234 | SpdyHeadersBlockParser::kMaximumFieldLength + 1); |
| 235 | EXPECT_FALSE(parser_-> |
| 236 | HandleControlFrameHeadersData(1, headers.c_str(), headers.length())); |
| 237 | EXPECT_EQ(SpdyHeadersBlockParser::HEADER_FIELD_TOO_LARGE, |
| 238 | parser_->get_error()); |
| 239 | } |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 240 | } |
| 241 | |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 242 | TEST_P(SpdyHeadersBlockParserTest, ExtraDataTest) { |
[email protected] | a73a3c1 | 2014-05-18 19:01:54 | [diff] [blame] | 243 | string headers = CreateHeaders(1, false) + "foobar"; |
| 244 | |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 245 | EXPECT_CALL(handler_, OnHeaderBlock(1)).Times(1); |
| 246 | EXPECT_CALL(handler_, OnHeaderBlockEnd(headers.length())).Times(1); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 247 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 248 | string expect_key = kBaseKey + IntToString(0); |
| 249 | string expect_value = kBaseValue + IntToString(0); |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 250 | EXPECT_CALL(handler_, OnHeader(StringPiece(expect_key), |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 251 | StringPiece(expect_value))).Times(1); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 252 | |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 253 | EXPECT_FALSE(parser_->HandleControlFrameHeadersData(1, headers.c_str(), |
| 254 | headers.length())); |
[email protected] | fd567fb | 2014-02-27 18:22:42 | [diff] [blame] | 255 | EXPECT_EQ(SpdyHeadersBlockParser::TOO_MUCH_DATA, parser_->get_error()); |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 256 | } |
| 257 | |
bnc | b1178b4 | 2015-01-22 01:20:57 | [diff] [blame] | 258 | TEST_P(SpdyHeadersBlockParserTest, WrongStreamIdTest) { |
| 259 | string headers(CreateHeaders(kNumHeadersInBlock, false)); |
| 260 | EXPECT_FALSE(parser_->HandleControlFrameHeadersData(1, headers.data(), 1)); |
| 261 | EXPECT_EQ(SpdyHeadersBlockParser::NEED_MORE_DATA, parser_->get_error()); |
| 262 | bool result; |
| 263 | EXPECT_DFATAL( |
| 264 | result = parser_->HandleControlFrameHeadersData(2, headers.data() + 1, 1), |
| 265 | "Unexpected stream id: 2 \\(expected 1\\)"); |
| 266 | EXPECT_FALSE(result); |
| 267 | EXPECT_EQ(SpdyHeadersBlockParser::UNEXPECTED_STREAM_ID, parser_->get_error()); |
| 268 | } |
| 269 | |
| 270 | TEST_P(SpdyHeadersBlockParserTest, InvalidStreamIdTest) { |
| 271 | string headers(CreateHeaders(kNumHeadersInBlock, false)); |
| 272 | bool result; |
| 273 | EXPECT_DFATAL( |
| 274 | result = parser_->HandleControlFrameHeadersData(0, headers.data(), 1), |
| 275 | "Expected nonzero stream id, saw: 0"); |
| 276 | EXPECT_FALSE(result); |
| 277 | EXPECT_EQ(SpdyHeadersBlockParser::UNEXPECTED_STREAM_ID, parser_->get_error()); |
| 278 | } |
| 279 | |
[email protected] | 6dc1e75 | 2014-01-24 23:17:00 | [diff] [blame] | 280 | } // namespace net |