| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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/http2/hpack/decoder/hpack_entry_type_decoder.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/bind_helpers.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "net/http2/hpack/tools/hpack_block_builder.h" | |
| 13 #include "net/http2/tools/failure.h" | |
| 14 #include "net/http2/tools/random_decoder_test.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 | |
| 17 using ::testing::AssertionFailure; | |
| 18 using ::testing::AssertionResult; | |
| 19 using ::testing::AssertionSuccess; | |
| 20 | |
| 21 namespace net { | |
| 22 namespace test { | |
| 23 namespace { | |
| 24 const bool kReturnNonZeroOnFirst = true; | |
| 25 | |
| 26 class HpackEntryTypeDecoderTest : public RandomDecoderTest { | |
| 27 public: | |
| 28 AssertionResult ValidatorForDynamicTableSizeUpdate(uint32_t size) { | |
| 29 VERIFY_EQ(HpackEntryType::kDynamicTableSizeUpdate, decoder_.entry_type()); | |
| 30 VERIFY_EQ(size, decoder_.varint()); | |
| 31 return AssertionSuccess(); | |
| 32 } | |
| 33 | |
| 34 AssertionResult ValidatorForHeaderWithIndex(const HpackEntryType entry_type, | |
| 35 uint32_t index) { | |
| 36 VERIFY_EQ(entry_type, decoder_.entry_type()); | |
| 37 VERIFY_EQ(index, decoder_.varint()); | |
| 38 return AssertionSuccess(); | |
| 39 } | |
| 40 | |
| 41 protected: | |
| 42 DecodeStatus StartDecoding(DecodeBuffer* b) override { | |
| 43 CHECK_LT(0u, b->Remaining()); | |
| 44 return decoder_.Start(b); | |
| 45 } | |
| 46 | |
| 47 DecodeStatus ResumeDecoding(DecodeBuffer* b) override { | |
| 48 return decoder_.Resume(b); | |
| 49 } | |
| 50 | |
| 51 HpackEntryTypeDecoder decoder_; | |
| 52 }; | |
| 53 | |
| 54 TEST_F(HpackEntryTypeDecoderTest, DynamicTableSizeUpdate) { | |
| 55 for (uint32_t size = 0; size < 1000 * 1000; size += 256) { | |
| 56 HpackBlockBuilder bb; | |
| 57 bb.AppendDynamicTableSizeUpdate(size); | |
| 58 DecodeBuffer db(bb.buffer()); | |
| 59 NoArgValidator validator = base::Bind( | |
| 60 &HpackEntryTypeDecoderTest::ValidatorForDynamicTableSizeUpdate, | |
| 61 base::Unretained(this), size); | |
| 62 EXPECT_TRUE(DecodeAndValidateSeveralWays(&db, kReturnNonZeroOnFirst, | |
| 63 ValidateDoneAndEmpty(validator))) | |
| 64 << "\nentry_type=kDynamicTableSizeUpdate, size=" << size; | |
| 65 // Run the validator again to make sure that DecodeAndValidateSeveralWays | |
| 66 // did the right thing. | |
| 67 EXPECT_TRUE(validator.Run()); | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 TEST_F(HpackEntryTypeDecoderTest, HeaderWithIndex) { | |
| 72 std::vector<HpackEntryType> entry_types = { | |
| 73 HpackEntryType::kIndexedHeader, HpackEntryType::kIndexedLiteralHeader, | |
| 74 HpackEntryType::kUnindexedLiteralHeader, | |
| 75 HpackEntryType::kNeverIndexedLiteralHeader, | |
| 76 }; | |
| 77 for (const HpackEntryType entry_type : entry_types) { | |
| 78 const uint32_t first = entry_type == HpackEntryType::kIndexedHeader ? 1 : 0; | |
| 79 for (uint32_t index = first; index < 1000; ++index) { | |
| 80 HpackBlockBuilder bb; | |
| 81 bb.AppendEntryTypeAndVarint(entry_type, index); | |
| 82 DecodeBuffer db(bb.buffer()); | |
| 83 NoArgValidator validator = | |
| 84 base::Bind(&HpackEntryTypeDecoderTest::ValidatorForHeaderWithIndex, | |
| 85 base::Unretained(this), entry_type, index); | |
| 86 EXPECT_TRUE(DecodeAndValidateSeveralWays(&db, kReturnNonZeroOnFirst, | |
| 87 ValidateDoneAndEmpty(validator))) | |
| 88 << "\nentry_type=" << entry_type << ", index=" << index; | |
| 89 // Run the validator again to make sure that DecodeAndValidateSeveralWays | |
| 90 // did the right thing. | |
| 91 EXPECT_TRUE(validator.Run()); | |
| 92 } | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 } // namespace | |
| 97 } // namespace test | |
| 98 } // namespace net | |
| OLD | NEW |