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 "quiche/http2/decoder/payload_decoders/continuation_payload_decoder.h"
6
7 #include <stddef.h>
8
9 #include <string>
10 #include <type_traits>
11
12 #include "quiche/http2/decoder/http2_frame_decoder_listener.h"
13 #include "quiche/http2/http2_constants.h"
14 #include "quiche/http2/http2_structures.h"
15 #include "quiche/http2/test_tools/frame_parts.h"
16 #include "quiche/http2/test_tools/frame_parts_collector.h"
17 #include "quiche/http2/test_tools/payload_decoder_base_test_util.h"
18 #include "quiche/http2/test_tools/random_decoder_test_base.h"
19 #include "quiche/common/platform/api/quiche_logging.h"
20 #include "quiche/common/platform/api/quiche_test.h"
21
22 namespace http2 {
23 namespace test {
24
25 // Provides friend access to an instance of the payload decoder, and also
26 // provides info to aid in testing.
27 class ContinuationPayloadDecoderPeer {
28 public:
FrameType()29 static constexpr Http2FrameType FrameType() {
30 return Http2FrameType::CONTINUATION;
31 }
32
33 // Returns the mask of flags that affect the decoding of the payload (i.e.
34 // flags that that indicate the presence of certain fields or padding).
FlagsAffectingPayloadDecoding()35 static constexpr uint8_t FlagsAffectingPayloadDecoding() { return 0; }
36 };
37
38 namespace {
39
40 struct Listener : public FramePartsCollector {
OnContinuationStarthttp2::test::__anon7ec9f8160111::Listener41 void OnContinuationStart(const Http2FrameHeader& header) override {
42 QUICHE_VLOG(1) << "OnContinuationStart: " << header;
43 StartFrame(header)->OnContinuationStart(header);
44 }
45
OnHpackFragmenthttp2::test::__anon7ec9f8160111::Listener46 void OnHpackFragment(const char* data, size_t len) override {
47 QUICHE_VLOG(1) << "OnHpackFragment: len=" << len;
48 CurrentFrame()->OnHpackFragment(data, len);
49 }
50
OnContinuationEndhttp2::test::__anon7ec9f8160111::Listener51 void OnContinuationEnd() override {
52 QUICHE_VLOG(1) << "OnContinuationEnd";
53 EndFrame()->OnContinuationEnd();
54 }
55 };
56
57 class ContinuationPayloadDecoderTest
58 : public AbstractPayloadDecoderTest<
59 ContinuationPayloadDecoder, ContinuationPayloadDecoderPeer, Listener>,
60 public ::testing::WithParamInterface<uint32_t> {
61 protected:
ContinuationPayloadDecoderTest()62 ContinuationPayloadDecoderTest() : length_(GetParam()) {
63 QUICHE_VLOG(1) << "################ length_=" << length_
64 << " ################";
65 }
66
67 const uint32_t length_;
68 };
69
70 INSTANTIATE_TEST_SUITE_P(VariousLengths, ContinuationPayloadDecoderTest,
71 ::testing::Values(0, 1, 2, 3, 4, 5, 6));
72
TEST_P(ContinuationPayloadDecoderTest,ValidLength)73 TEST_P(ContinuationPayloadDecoderTest, ValidLength) {
74 std::string hpack_payload = Random().RandString(length_);
75 Http2FrameHeader frame_header(length_, Http2FrameType::CONTINUATION,
76 RandFlags(), RandStreamId());
77 set_frame_header(frame_header);
78 FrameParts expected(frame_header, hpack_payload);
79 EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(hpack_payload, expected));
80 }
81
82 } // namespace
83 } // namespace test
84 } // namespace http2
85