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

Side by Side Diff: net/http2/decoder/payload_decoders/window_update_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/window_update_payload_decoder.h"
6
7 #include <stddef.h>
8
9 #include "base/bind.h"
10 #include "base/logging.h"
11 #include "net/http2/decoder/frame_parts.h"
12 #include "net/http2/decoder/frame_parts_collector.h"
13 #include "net/http2/decoder/http2_frame_decoder_listener.h"
14 #include "net/http2/decoder/payload_decoders/payload_decoder_base_test_util.h"
15 #include "net/http2/http2_constants.h"
16 #include "net/http2/http2_structures_test_util.h"
17 #include "net/http2/tools/http2_frame_builder.h"
18 #include "net/http2/tools/http2_random.h"
19 #include "net/http2/tools/random_decoder_test.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 namespace net {
23 namespace test {
24
25 class WindowUpdatePayloadDecoderPeer {
26 public:
27 static constexpr Http2FrameType FrameType() {
28 return Http2FrameType::WINDOW_UPDATE;
29 }
30
31 // Returns the mask of flags that affect the decoding of the payload (i.e.
32 // flags that that indicate the presence of certain fields or padding).
33 static constexpr uint8_t FlagsAffectingPayloadDecoding() { return 0; }
34
35 static void Randomize(WindowUpdatePayloadDecoder* p, RandomBase* rng) {
36 test::Randomize(&p->window_update_fields_, rng);
37 VLOG(1) << "WindowUpdatePayloadDecoderPeer::Randomize "
38 << "window_update_fields_: " << p->window_update_fields_;
39 }
40 };
41
42 namespace {
43
44 struct Listener : public FramePartsCollector {
45 void OnWindowUpdate(const Http2FrameHeader& header,
46 uint32_t window_size_increment) override {
47 VLOG(1) << "OnWindowUpdate: " << header
48 << "; window_size_increment=" << window_size_increment;
49 EXPECT_EQ(Http2FrameType::WINDOW_UPDATE, header.type);
50 StartAndEndFrame(header)->OnWindowUpdate(header, window_size_increment);
51 }
52
53 void OnFrameSizeError(const Http2FrameHeader& header) override {
54 VLOG(1) << "OnFrameSizeError: " << header;
55 FrameError(header)->OnFrameSizeError(header);
56 }
57 };
58
59 class WindowUpdatePayloadDecoderTest
60 : public AbstractPayloadDecoderTest<WindowUpdatePayloadDecoder,
61 WindowUpdatePayloadDecoderPeer,
62 Listener> {
63 public:
64 static bool ApproveSizeForWrongSize(size_t size) {
65 return size != Http2WindowUpdateFields::EncodedSize();
66 }
67
68 protected:
69 Http2WindowUpdateFields RandWindowUpdateFields() {
70 Http2WindowUpdateFields fields;
71 test::Randomize(&fields, RandomPtr());
72 VLOG(3) << "RandWindowUpdateFields: " << fields;
73 return fields;
74 }
75 };
76
77 // Confirm we get an error if the payload is not the correct size to hold
78 // exactly one Http2WindowUpdateFields.
79 TEST_F(WindowUpdatePayloadDecoderTest, WrongSize) {
80 Http2FrameBuilder fb;
81 fb.Append(RandWindowUpdateFields());
82 fb.Append(RandWindowUpdateFields());
83 fb.Append(RandWindowUpdateFields());
84 EXPECT_TRUE(VerifyDetectsFrameSizeError(
85 0, fb.buffer(),
86 base::Bind(&WindowUpdatePayloadDecoderTest::ApproveSizeForWrongSize)));
87 }
88
89 TEST_F(WindowUpdatePayloadDecoderTest, VariousPayloads) {
90 for (int n = 0; n < 100; ++n) {
91 uint32_t stream_id = n == 0 ? 0 : RandStreamId();
92 Http2WindowUpdateFields fields = RandWindowUpdateFields();
93 Http2FrameBuilder fb;
94 fb.Append(fields);
95 Http2FrameHeader header(fb.size(), Http2FrameType::WINDOW_UPDATE,
96 RandFlags(), stream_id);
97 set_frame_header(header);
98 FrameParts expected(header);
99 expected.opt_window_update_increment = fields.window_size_increment;
100 EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected));
101 }
102 }
103
104 } // namespace
105 } // namespace test
106 } // namespace net
OLDNEW
« no previous file with comments | « net/http2/decoder/payload_decoders/window_update_payload_decoder.cc ('k') | net/http2/hpack/decoder/hpack_block_collector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698