Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: net/http2/decoder/payload_decoders/unknown_payload_decoder_test.cc

Issue 2554683003: Revert of Add new HTTP/2 and HPACK decoder in net/http2/. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/unknown_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/http2_random.h"
20 #include "net/http2/tools/random_decoder_test.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22
23 using std::string;
24
25 namespace net {
26 namespace test {
27 namespace {
28 Http2FrameType g_unknown_frame_type;
29 } // namespace
30
31 // Provides friend access to an instance of the payload decoder, and also
32 // provides info to aid in testing.
33 class UnknownPayloadDecoderPeer {
34 public:
35 static Http2FrameType FrameType() { return g_unknown_frame_type; }
36
37 // Returns the mask of flags that affect the decoding of the payload (i.e.
38 // flags that that indicate the presence of certain fields or padding).
39 static constexpr uint8_t FlagsAffectingPayloadDecoding() { return 0; }
40
41 static void Randomize(UnknownPayloadDecoder* p, RandomBase* rng) {
42 // UnknownPayloadDecoder has no fields, so there is nothing to randomize.
43 static_assert(std::is_empty<UnknownPayloadDecoder>::value,
44 "Need to randomize fields of UnknownPayloadDecoder");
45 }
46 };
47
48 namespace {
49
50 struct Listener : public FramePartsCollector {
51 void OnUnknownStart(const Http2FrameHeader& header) override {
52 VLOG(1) << "OnUnknownStart: " << header;
53 StartFrame(header)->OnUnknownStart(header);
54 }
55
56 void OnUnknownPayload(const char* data, size_t len) override {
57 VLOG(1) << "OnUnknownPayload: len=" << len;
58 CurrentFrame()->OnUnknownPayload(data, len);
59 }
60
61 void OnUnknownEnd() override {
62 VLOG(1) << "OnUnknownEnd";
63 EndFrame()->OnUnknownEnd();
64 }
65 };
66
67 constexpr bool SupportedFrameType = false;
68
69 class UnknownPayloadDecoderTest
70 : public AbstractPayloadDecoderTest<UnknownPayloadDecoder,
71 UnknownPayloadDecoderPeer,
72 Listener,
73 SupportedFrameType>,
74 public ::testing::WithParamInterface<uint32_t> {
75 protected:
76 UnknownPayloadDecoderTest() : length_(GetParam()) {
77 VLOG(1) << "################ length_=" << length_ << " ################";
78
79 // Each test case will choose a random frame type that isn't supported.
80 do {
81 g_unknown_frame_type = static_cast<Http2FrameType>(Random().Rand8());
82 } while (IsSupportedHttp2FrameType(g_unknown_frame_type));
83 }
84
85 const uint32_t length_;
86 };
87
88 INSTANTIATE_TEST_CASE_P(VariousLengths,
89 UnknownPayloadDecoderTest,
90 ::testing::Values(0, 1, 2, 3, 255, 256));
91
92 TEST_P(UnknownPayloadDecoderTest, ValidLength) {
93 string unknown_payload = Random().RandString(length_);
94 Http2FrameHeader frame_header(length_, g_unknown_frame_type, Random().Rand8(),
95 RandStreamId());
96 set_frame_header(frame_header);
97 FrameParts expected(frame_header, unknown_payload);
98 EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(unknown_payload, expected));
99 // TODO(jamessynge): Check here (and in other such tests) that the fast
100 // and slow decode counts are both non-zero. Perhaps also add some kind of
101 // test for the listener having been called. That could simply be a test
102 // that there is a single collected FrameParts instance, and that it matches
103 // expected.
104 }
105
106 } // namespace
107 } // namespace test
108 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698