| 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/hpack_input_stream.h" | 5 #include "net/spdy/hpack_input_stream.h" |
| 6 | 6 |
| 7 #include <bitset> | 7 #include <bitset> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 class HpackInputStreamTest : public ::testing::Test { | 25 class HpackInputStreamTest : public ::testing::Test { |
| 26 virtual void SetUp() { | 26 virtual void SetUp() { |
| 27 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); | 27 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); |
| 28 EXPECT_TRUE(huffman_table.Initialize(&code[0], code.size())); | 28 EXPECT_TRUE(huffman_table.Initialize(&code[0], code.size())); |
| 29 } | 29 } |
| 30 | 30 |
| 31 protected: | 31 protected: |
| 32 HpackHuffmanTable huffman_table; | 32 HpackHuffmanTable huffman_table; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 const char kEncodedFixture[] = "\x33" // Length prefix. | 35 const char kEncodedFixture[] = |
| 36 "\xc5\xad\xb7\x7f\x87\x6f\xc7\xfb\xf7\xfd\xbf\xbe\xbf\xf3\xf7\xf4" | 36 "\x33" // Length prefix. |
| 37 "\xfb\x7e\xbb\xbe\x9f\x5f\x87\xe3\x7f\xef\xed\xfa\xee\xfa\x7c\x3f" | 37 "\xc5\xad\xb7\x7f\x87\x6f\xc7\xfb\xf7\xfd\xbf\xbe\xbf\xf3\xf7\xf4" |
| 38 "\x1d\x5d\x1a\x23\xce\x54\x64\x36\xcd\x49\x4b\xd5\xd1\xcc\x5f\x05" | 38 "\xfb\x7e\xbb\xbe\x9f\x5f\x87\xe3\x7f\xef\xed\xfa\xee\xfa\x7c\x3f" |
| 39 "\x35\x96\x9b"; | 39 "\x1d\x5d\x1a\x23\xce\x54\x64\x36\xcd\x49\x4b\xd5\xd1\xcc\x5f\x05" |
| 40 "\x35\x96\x9b"; |
| 40 | 41 |
| 41 const char kDecodedFixture[] = | 42 const char kDecodedFixture[] = |
| 42 "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1"; | 43 "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1"; |
| 43 | 44 |
| 44 // Utility function to decode an assumed-valid uint32 with an N-bit | 45 // Utility function to decode an assumed-valid uint32 with an N-bit |
| 45 // prefix. | 46 // prefix. |
| 46 uint32 DecodeValidUint32(uint8 N, StringPiece str) { | 47 uint32 DecodeValidUint32(uint8 N, StringPiece str) { |
| 47 EXPECT_GT(N, 0); | 48 EXPECT_GT(N, 0); |
| 48 EXPECT_LE(N, 8); | 49 EXPECT_LE(N, 8); |
| 49 HpackInputStream input_stream(kLiteralBound, str); | 50 HpackInputStream input_stream(kLiteralBound, str); |
| 50 input_stream.SetBitOffsetForTest(8 - N); | 51 input_stream.SetBitOffsetForTest(8 - N); |
| 51 uint32 I; | 52 uint32 I; |
| 52 EXPECT_TRUE(input_stream.DecodeNextUint32ForTest(&I)); | 53 EXPECT_TRUE(input_stream.DecodeNextUint32ForTest(&I)); |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 TEST_F(HpackInputStreamTest, DecodeNextIdentityStringNotEnoughInput) { | 508 TEST_F(HpackInputStreamTest, DecodeNextIdentityStringNotEnoughInput) { |
| 508 // Set the length to be one more than it should be. | 509 // Set the length to be one more than it should be. |
| 509 HpackInputStream input_stream(kLiteralBound, "\x0fstring literal"); | 510 HpackInputStream input_stream(kLiteralBound, "\x0fstring literal"); |
| 510 | 511 |
| 511 EXPECT_TRUE(input_stream.HasMoreData()); | 512 EXPECT_TRUE(input_stream.HasMoreData()); |
| 512 StringPiece string_piece; | 513 StringPiece string_piece; |
| 513 EXPECT_FALSE(input_stream.DecodeNextIdentityString(&string_piece)); | 514 EXPECT_FALSE(input_stream.DecodeNextIdentityString(&string_piece)); |
| 514 } | 515 } |
| 515 | 516 |
| 516 TEST_F(HpackInputStreamTest, DecodeNextHuffmanString) { | 517 TEST_F(HpackInputStreamTest, DecodeNextHuffmanString) { |
| 517 string output, input(kEncodedFixture, arraysize(kEncodedFixture)-1); | 518 string output, input(kEncodedFixture, arraysize(kEncodedFixture) - 1); |
| 518 HpackInputStream input_stream(arraysize(kDecodedFixture)-1, input); | 519 HpackInputStream input_stream(arraysize(kDecodedFixture) - 1, input); |
| 519 | 520 |
| 520 EXPECT_TRUE(input_stream.HasMoreData()); | 521 EXPECT_TRUE(input_stream.HasMoreData()); |
| 521 EXPECT_TRUE(input_stream.DecodeNextHuffmanString(huffman_table, &output)); | 522 EXPECT_TRUE(input_stream.DecodeNextHuffmanString(huffman_table, &output)); |
| 522 EXPECT_EQ(kDecodedFixture, output); | 523 EXPECT_EQ(kDecodedFixture, output); |
| 523 EXPECT_FALSE(input_stream.HasMoreData()); | 524 EXPECT_FALSE(input_stream.HasMoreData()); |
| 524 } | 525 } |
| 525 | 526 |
| 526 TEST_F(HpackInputStreamTest, DecodeNextHuffmanStringSizeLimit) { | 527 TEST_F(HpackInputStreamTest, DecodeNextHuffmanStringSizeLimit) { |
| 527 string output, input(kEncodedFixture, arraysize(kEncodedFixture)-1); | 528 string output, input(kEncodedFixture, arraysize(kEncodedFixture) - 1); |
| 528 // Max string literal is one byte shorter than the decoded fixture. | 529 // Max string literal is one byte shorter than the decoded fixture. |
| 529 HpackInputStream input_stream(arraysize(kDecodedFixture)-2, input); | 530 HpackInputStream input_stream(arraysize(kDecodedFixture) - 2, input); |
| 530 | 531 |
| 531 // Decoded string overflows the max string literal. | 532 // Decoded string overflows the max string literal. |
| 532 EXPECT_TRUE(input_stream.HasMoreData()); | 533 EXPECT_TRUE(input_stream.HasMoreData()); |
| 533 EXPECT_FALSE(input_stream.DecodeNextHuffmanString(huffman_table, &output)); | 534 EXPECT_FALSE(input_stream.DecodeNextHuffmanString(huffman_table, &output)); |
| 534 } | 535 } |
| 535 | 536 |
| 536 TEST_F(HpackInputStreamTest, DecodeNextHuffmanStringNotEnoughInput) { | 537 TEST_F(HpackInputStreamTest, DecodeNextHuffmanStringNotEnoughInput) { |
| 537 string output, input(kEncodedFixture, arraysize(kEncodedFixture)-1); | 538 string output, input(kEncodedFixture, arraysize(kEncodedFixture) - 1); |
| 538 input[0]++; // Input prefix is one byte larger than available input. | 539 input[0]++; // Input prefix is one byte larger than available input. |
| 539 HpackInputStream input_stream(arraysize(kDecodedFixture)-1, input); | 540 HpackInputStream input_stream(arraysize(kDecodedFixture) - 1, input); |
| 540 | 541 |
| 541 // Not enough buffer for declared encoded length. | 542 // Not enough buffer for declared encoded length. |
| 542 EXPECT_TRUE(input_stream.HasMoreData()); | 543 EXPECT_TRUE(input_stream.HasMoreData()); |
| 543 EXPECT_FALSE(input_stream.DecodeNextHuffmanString(huffman_table, &output)); | 544 EXPECT_FALSE(input_stream.DecodeNextHuffmanString(huffman_table, &output)); |
| 544 } | 545 } |
| 545 | 546 |
| 546 TEST_F(HpackInputStreamTest, PeekBitsAndConsume) { | 547 TEST_F(HpackInputStreamTest, PeekBitsAndConsume) { |
| 547 HpackInputStream input_stream(kLiteralBound, "\xad\xab\xad\xab\xad"); | 548 HpackInputStream input_stream(kLiteralBound, "\xad\xab\xad\xab\xad"); |
| 548 | 549 |
| 549 uint32 bits = 0; | 550 uint32 bits = 0; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 | 618 |
| 618 input_stream.ConsumeBits(6); | 619 input_stream.ConsumeBits(6); |
| 619 EXPECT_TRUE(input_stream.HasMoreData()); | 620 EXPECT_TRUE(input_stream.HasMoreData()); |
| 620 input_stream.ConsumeByteRemainder(); | 621 input_stream.ConsumeByteRemainder(); |
| 621 EXPECT_FALSE(input_stream.HasMoreData()); | 622 EXPECT_FALSE(input_stream.HasMoreData()); |
| 622 } | 623 } |
| 623 | 624 |
| 624 } // namespace | 625 } // namespace |
| 625 | 626 |
| 626 } // namespace net | 627 } // namespace net |
| OLD | NEW |