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

Side by Side Diff: net/http2/decoder/frame_parts.h

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
« no previous file with comments | « net/http2/decoder/frame_decoder_state_test_util.cc ('k') | net/http2/decoder/frame_parts.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef NET_HTTP2_DECODER_FRAME_PARTS_H_
6 #define NET_HTTP2_DECODER_FRAME_PARTS_H_
7
8 // FrameParts implements Http2FrameDecoderListener, recording the callbacks
9 // during the decoding of a single frame. It is also used for comparing the
10 // info that a test expects to be recorded during the decoding of a frame
11 // with the actual recorded value (i.e. by providing a comparator).
12
13 // TODO(jamessynge): Convert FrameParts to a class, hide the members, add
14 // getters/setters.
15
16 #include <stddef.h>
17
18 #include <string>
19 #include <vector>
20
21 #include "base/logging.h"
22 #include "base/optional.h"
23 #include "base/strings/string_piece.h"
24 #include "net/http2/decoder/http2_frame_decoder_listener.h"
25 #include "net/http2/http2_constants.h"
26 #include "net/http2/http2_structures.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28
29 namespace net {
30 namespace test {
31
32 struct FrameParts;
33
34 std::ostream& operator<<(std::ostream& out, const FrameParts& v);
35
36 struct FrameParts : public Http2FrameDecoderListener {
37 // The first callback for every type of frame includes the frame header; this
38 // is the only constructor used during decoding of a frame.
39 explicit FrameParts(const Http2FrameHeader& header);
40
41 // For use in tests where the expected frame has a variable size payload.
42 FrameParts(const Http2FrameHeader& header, base::StringPiece payload);
43
44 // For use in tests where the expected frame has a variable size payload
45 // and may be padded.
46 FrameParts(const Http2FrameHeader& header,
47 base::StringPiece payload,
48 size_t total_pad_length);
49
50 FrameParts(const FrameParts& other);
51
52 ~FrameParts() override;
53
54 // Returns AssertionSuccess() if they're equal, else AssertionFailure()
55 // with info about the difference.
56 ::testing::AssertionResult VerifyEquals(const FrameParts& other) const;
57
58 // Format this FrameParts object.
59 void OutputTo(std::ostream& out) const;
60
61 // Set the total padding length (0 to 256).
62 void SetTotalPadLength(size_t total_pad_length);
63
64 // Set the origin and value expected in an ALTSVC frame.
65 void SetAltSvcExpected(base::StringPiece origin, base::StringPiece value);
66
67 // Http2FrameDecoderListener methods:
68 bool OnFrameHeader(const Http2FrameHeader& header) override;
69 void OnDataStart(const Http2FrameHeader& header) override;
70 void OnDataPayload(const char* data, size_t len) override;
71 void OnDataEnd() override;
72 void OnHeadersStart(const Http2FrameHeader& header) override;
73 void OnHeadersPriority(const Http2PriorityFields& priority) override;
74 void OnHpackFragment(const char* data, size_t len) override;
75 void OnHeadersEnd() override;
76 void OnPriorityFrame(const Http2FrameHeader& header,
77 const Http2PriorityFields& priority) override;
78 void OnContinuationStart(const Http2FrameHeader& header) override;
79 void OnContinuationEnd() override;
80 void OnPadLength(size_t trailing_length) override;
81 void OnPadding(const char* pad, size_t skipped_length) override;
82 void OnRstStream(const Http2FrameHeader& header,
83 Http2ErrorCode error_code) override;
84 void OnSettingsStart(const Http2FrameHeader& header) override;
85 void OnSetting(const Http2SettingFields& setting_fields) override;
86 void OnSettingsEnd() override;
87 void OnSettingsAck(const Http2FrameHeader& header) override;
88 void OnPushPromiseStart(const Http2FrameHeader& header,
89 const Http2PushPromiseFields& promise,
90 size_t total_padding_length) override;
91 void OnPushPromiseEnd() override;
92 void OnPing(const Http2FrameHeader& header,
93 const Http2PingFields& ping) override;
94 void OnPingAck(const Http2FrameHeader& header,
95 const Http2PingFields& ping) override;
96 void OnGoAwayStart(const Http2FrameHeader& header,
97 const Http2GoAwayFields& goaway) override;
98 void OnGoAwayOpaqueData(const char* data, size_t len) override;
99 void OnGoAwayEnd() override;
100 void OnWindowUpdate(const Http2FrameHeader& header,
101 uint32_t increment) override;
102 void OnAltSvcStart(const Http2FrameHeader& header,
103 size_t origin_length,
104 size_t value_length) override;
105 void OnAltSvcOriginData(const char* data, size_t len) override;
106 void OnAltSvcValueData(const char* data, size_t len) override;
107 void OnAltSvcEnd() override;
108 void OnUnknownStart(const Http2FrameHeader& header) override;
109 void OnUnknownPayload(const char* data, size_t len) override;
110 void OnUnknownEnd() override;
111 void OnPaddingTooLong(const Http2FrameHeader& header,
112 size_t missing_length) override;
113 void OnFrameSizeError(const Http2FrameHeader& header) override;
114
115 // The fields are public for access by tests.
116
117 const Http2FrameHeader frame_header;
118
119 std::string payload;
120 std::string padding;
121 std::string altsvc_origin;
122 std::string altsvc_value;
123
124 base::Optional<Http2PriorityFields> opt_priority;
125 base::Optional<Http2ErrorCode> opt_rst_stream_error_code;
126 base::Optional<Http2PushPromiseFields> opt_push_promise;
127 base::Optional<Http2PingFields> opt_ping;
128 base::Optional<Http2GoAwayFields> opt_goaway;
129
130 base::Optional<int> opt_pad_length;
131 base::Optional<int> opt_payload_length;
132 base::Optional<int> opt_missing_length;
133 base::Optional<int> opt_altsvc_origin_length;
134 base::Optional<int> opt_altsvc_value_length;
135
136 base::Optional<size_t> opt_window_update_increment;
137
138 bool has_frame_size_error = false;
139
140 std::vector<Http2SettingFields> settings;
141
142 // These booleans are not checked by CompareCollectedFrames.
143 bool got_start_callback = false;
144 bool got_end_callback = false;
145
146 private:
147 // ASSERT during an On* method that we're handling a frame of type
148 // expected_frame_type, and have not already received other On* methods
149 // (i.e. got_start_callback is false).
150 ::testing::AssertionResult StartFrameOfType(
151 const Http2FrameHeader& header,
152 Http2FrameType expected_frame_type);
153
154 // ASSERT that StartFrameOfType has already been called with
155 // expected_frame_type (i.e. got_start_callback has been called), and that
156 // EndFrameOfType has not yet been called (i.e. got_end_callback is false).
157 ::testing::AssertionResult InFrameOfType(Http2FrameType expected_frame_type);
158
159 // ASSERT that we're InFrameOfType, and then sets got_end_callback=true.
160 ::testing::AssertionResult EndFrameOfType(Http2FrameType expected_frame_type);
161
162 // ASSERT that we're in the middle of processing a frame that is padded.
163 ::testing::AssertionResult InPaddedFrame();
164
165 // Append source to target. If opt_length is not nullptr, then verifies that
166 // the optional has a value (i.e. that the necessary On*Start method has been
167 // called), and that target is not longer than opt_length->value().
168 ::testing::AssertionResult AppendString(base::StringPiece source,
169 std::string* target,
170 base::Optional<int>* opt_length);
171 };
172
173 } // namespace test
174 } // namespace net
175
176 #endif // NET_HTTP2_DECODER_FRAME_PARTS_H_
OLDNEW
« no previous file with comments | « net/http2/decoder/frame_decoder_state_test_util.cc ('k') | net/http2/decoder/frame_parts.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698