xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/http2/adapter/test_frame_sequence.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 #ifndef QUICHE_HTTP2_ADAPTER_TEST_FRAME_SEQUENCE_H_
2 #define QUICHE_HTTP2_ADAPTER_TEST_FRAME_SEQUENCE_H_
3 
4 #include <cstdint>
5 #include <memory>
6 #include <string>
7 #include <vector>
8 
9 #include "quiche/http2/adapter/http2_protocol.h"
10 #include "quiche/common/platform/api/quiche_export.h"
11 #include "quiche/spdy/core/http2_header_block.h"
12 #include "quiche/spdy/core/spdy_protocol.h"
13 
14 namespace http2 {
15 namespace adapter {
16 namespace test {
17 
18 std::vector<Header> QUICHE_NO_EXPORT ToHeaders(
19     absl::Span<const std::pair<absl::string_view, absl::string_view>> headers);
20 
21 class QUICHE_NO_EXPORT TestFrameSequence {
22  public:
23   TestFrameSequence() = default;
24 
25   TestFrameSequence(TestFrameSequence&& other) = default;
26   TestFrameSequence& operator=(TestFrameSequence&& other) = default;
27 
28   TestFrameSequence& ClientPreface(
29       absl::Span<const Http2Setting> settings = {});
30   TestFrameSequence& ServerPreface(
31       absl::Span<const Http2Setting> settings = {});
32   TestFrameSequence& Data(Http2StreamId stream_id, absl::string_view payload,
33                           bool fin = false,
34                           std::optional<int> padding_length = std::nullopt);
35   TestFrameSequence& RstStream(Http2StreamId stream_id, Http2ErrorCode error);
36   TestFrameSequence& Settings(absl::Span<const Http2Setting> settings);
37   TestFrameSequence& SettingsAck();
38   TestFrameSequence& PushPromise(Http2StreamId stream_id,
39                                  Http2StreamId promised_stream_id,
40                                  absl::Span<const Header> headers);
41   TestFrameSequence& Ping(Http2PingId id);
42   TestFrameSequence& PingAck(Http2PingId id);
43   TestFrameSequence& GoAway(Http2StreamId last_good_stream_id,
44                             Http2ErrorCode error,
45                             absl::string_view payload = "");
46   TestFrameSequence& Headers(
47       Http2StreamId stream_id,
48       absl::Span<const std::pair<absl::string_view, absl::string_view>> headers,
49       bool fin = false, bool add_continuation = false);
50   TestFrameSequence& Headers(Http2StreamId stream_id,
51                              spdy::Http2HeaderBlock block, bool fin = false,
52                              bool add_continuation = false);
53   TestFrameSequence& Headers(Http2StreamId stream_id,
54                              absl::Span<const Header> headers, bool fin = false,
55                              bool add_continuation = false);
56   TestFrameSequence& WindowUpdate(Http2StreamId stream_id, int32_t delta);
57   TestFrameSequence& Priority(Http2StreamId stream_id,
58                               Http2StreamId parent_stream_id, int weight,
59                               bool exclusive);
60   TestFrameSequence& Metadata(Http2StreamId stream_id,
61                               absl::string_view payload,
62                               bool multiple_frames = false);
63 
64   std::string Serialize();
65 
66  private:
67   std::string preface_;
68   std::vector<std::unique_ptr<spdy::SpdyFrameIR>> frames_;
69 };
70 
71 }  // namespace test
72 }  // namespace adapter
73 }  // namespace http2
74 
75 #endif  // QUICHE_HTTP2_ADAPTER_TEST_FRAME_SEQUENCE_H_
76