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/decoder/payload_decoders/continuation_payload_decoder.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include <string> | |
10 #include <type_traits> | |
11 | |
12 #include "base/logging.h" | |
13 #include "net/http2/decoder/frame_parts.h" | |
14 #include "net/http2/decoder/frame_parts_collector.h" | |
15 #include "net/http2/decoder/http2_frame_decoder_listener.h" | |
16 #include "net/http2/decoder/payload_decoders/payload_decoder_base_test_util.h" | |
17 #include "net/http2/http2_constants.h" | |
18 #include "net/http2/http2_structures.h" | |
19 #include "net/http2/tools/random_decoder_test.h" | |
20 #include "testing/gtest/include/gtest/gtest.h" | |
21 | |
22 using std::string; | |
23 | |
24 namespace net { | |
25 namespace test { | |
26 | |
27 // Provides friend access to an instance of the payload decoder, and also | |
28 // provides info to aid in testing. | |
29 class ContinuationPayloadDecoderPeer { | |
30 public: | |
31 static constexpr Http2FrameType FrameType() { | |
32 return Http2FrameType::CONTINUATION; | |
33 } | |
34 | |
35 // Returns the mask of flags that affect the decoding of the payload (i.e. | |
36 // flags that that indicate the presence of certain fields or padding). | |
37 static constexpr uint8_t FlagsAffectingPayloadDecoding() { return 0; } | |
38 | |
39 static void Randomize(ContinuationPayloadDecoder* p, RandomBase* rng) { | |
40 // ContinuationPayloadDecoder has no fields, | |
41 // so there is nothing to randomize. | |
42 static_assert(std::is_empty<ContinuationPayloadDecoder>::value, | |
43 "Need to randomize fields of ContinuationPayloadDecoder"); | |
44 } | |
45 }; | |
46 | |
47 namespace { | |
48 | |
49 struct Listener : public FramePartsCollector { | |
50 void OnContinuationStart(const Http2FrameHeader& header) override { | |
51 VLOG(1) << "OnContinuationStart: " << header; | |
52 StartFrame(header)->OnContinuationStart(header); | |
53 } | |
54 | |
55 void OnHpackFragment(const char* data, size_t len) override { | |
56 VLOG(1) << "OnHpackFragment: len=" << len; | |
57 CurrentFrame()->OnHpackFragment(data, len); | |
58 } | |
59 | |
60 void OnContinuationEnd() override { | |
61 VLOG(1) << "OnContinuationEnd"; | |
62 EndFrame()->OnContinuationEnd(); | |
63 } | |
64 }; | |
65 | |
66 class ContinuationPayloadDecoderTest | |
67 : public AbstractPayloadDecoderTest<ContinuationPayloadDecoder, | |
68 ContinuationPayloadDecoderPeer, | |
69 Listener>, | |
70 public ::testing::WithParamInterface<uint32_t> { | |
71 protected: | |
72 ContinuationPayloadDecoderTest() : length_(GetParam()) { | |
73 VLOG(1) << "################ length_=" << length_ << " ################"; | |
74 } | |
75 | |
76 const uint32_t length_; | |
77 }; | |
78 | |
79 INSTANTIATE_TEST_CASE_P(VariousLengths, | |
80 ContinuationPayloadDecoderTest, | |
81 ::testing::Values(0, 1, 2, 3, 4, 5, 6)); | |
82 | |
83 TEST_P(ContinuationPayloadDecoderTest, ValidLength) { | |
84 string hpack_payload = Random().RandString(length_); | |
85 Http2FrameHeader frame_header(length_, Http2FrameType::CONTINUATION, | |
86 RandFlags(), RandStreamId()); | |
87 set_frame_header(frame_header); | |
88 FrameParts expected(frame_header, hpack_payload); | |
89 EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(hpack_payload, expected)); | |
90 } | |
91 | |
92 } // namespace | |
93 } // namespace test | |
94 } // namespace net | |
OLD | NEW |