blob: 1b3e4c5ac8b0178c9cc1c86fa4d222547378e957 [file] [log] [blame]
QUICHE teamfd50a402018-12-07 22:54:05 -05001// 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 QUICHE_HTTP2_HTTP2_STRUCTURES_TEST_UTIL_H_
6#define QUICHE_HTTP2_HTTP2_STRUCTURES_TEST_UTIL_H_
7
bnc47904002019-08-16 11:49:48 -07008#include <string>
9
QUICHE teamfd50a402018-12-07 22:54:05 -050010#include "net/third_party/quiche/src/http2/http2_structures.h"
QUICHE teamd72981e2020-02-07 19:44:05 -080011#include "net/third_party/quiche/src/http2/platform/api/http2_test_helpers.h"
QUICHE teamfd50a402018-12-07 22:54:05 -050012#include "net/third_party/quiche/src/http2/test_tools/http2_random.h"
13#include "net/third_party/quiche/src/http2/tools/http2_frame_builder.h"
14
15namespace http2 {
16namespace test {
17
18template <class S>
bnc47904002019-08-16 11:49:48 -070019std::string SerializeStructure(const S& s) {
QUICHE teamfd50a402018-12-07 22:54:05 -050020 Http2FrameBuilder fb;
21 fb.Append(s);
22 EXPECT_EQ(S::EncodedSize(), fb.size());
23 return fb.buffer();
24}
25
26// Randomize the members of out, in a manner that yields encodeable contents
27// (e.g. a "uint24" field has only the low 24 bits set).
28void Randomize(Http2FrameHeader* out, Http2Random* rng);
29void Randomize(Http2PriorityFields* out, Http2Random* rng);
30void Randomize(Http2RstStreamFields* out, Http2Random* rng);
31void Randomize(Http2SettingFields* out, Http2Random* rng);
32void Randomize(Http2PushPromiseFields* out, Http2Random* rng);
33void Randomize(Http2PingFields* out, Http2Random* rng);
34void Randomize(Http2GoAwayFields* out, Http2Random* rng);
35void Randomize(Http2WindowUpdateFields* out, Http2Random* rng);
36void Randomize(Http2AltSvcFields* out, Http2Random* rng);
37
38// Clear bits of header->flags that are known to be invalid for the
39// type. For unknown frame types, no change is made.
40void ScrubFlagsOfHeader(Http2FrameHeader* header);
41
42// Is the frame with this header padded? Only true for known/supported frame
43// types.
44bool FrameIsPadded(const Http2FrameHeader& header);
45
46// Does the frame with this header have Http2PriorityFields?
47bool FrameHasPriority(const Http2FrameHeader& header);
48
49// Does the frame with this header have a variable length payload (including
50// empty) payload (e.g. DATA or HEADERS)? Really a test of the frame type.
51bool FrameCanHavePayload(const Http2FrameHeader& header);
52
53// Does the frame with this header have a variable length HPACK payload
54// (including empty) payload (e.g. HEADERS)? Really a test of the frame type.
55bool FrameCanHaveHpackPayload(const Http2FrameHeader& header);
56
57} // namespace test
58} // namespace http2
59
60#endif // QUICHE_HTTP2_HTTP2_STRUCTURES_TEST_UTIL_H_