QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 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 QUICHE_HTTP2_HTTP2_STRUCTURES_TEST_UTIL_H_ |
| 6 | #define QUICHE_HTTP2_HTTP2_STRUCTURES_TEST_UTIL_H_ |
| 7 | |
bnc | 4790400 | 2019-08-16 11:49:48 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 10 | #include "net/third_party/quiche/src/http2/http2_structures.h" |
QUICHE team | d72981e | 2020-02-07 19:44:05 -0800 | [diff] [blame] | 11 | #include "net/third_party/quiche/src/http2/platform/api/http2_test_helpers.h" |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 12 | #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 | |
| 15 | namespace http2 { |
| 16 | namespace test { |
| 17 | |
| 18 | template <class S> |
bnc | 4790400 | 2019-08-16 11:49:48 -0700 | [diff] [blame] | 19 | std::string SerializeStructure(const S& s) { |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 20 | 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). |
| 28 | void Randomize(Http2FrameHeader* out, Http2Random* rng); |
| 29 | void Randomize(Http2PriorityFields* out, Http2Random* rng); |
| 30 | void Randomize(Http2RstStreamFields* out, Http2Random* rng); |
| 31 | void Randomize(Http2SettingFields* out, Http2Random* rng); |
| 32 | void Randomize(Http2PushPromiseFields* out, Http2Random* rng); |
| 33 | void Randomize(Http2PingFields* out, Http2Random* rng); |
| 34 | void Randomize(Http2GoAwayFields* out, Http2Random* rng); |
| 35 | void Randomize(Http2WindowUpdateFields* out, Http2Random* rng); |
| 36 | void 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. |
| 40 | void ScrubFlagsOfHeader(Http2FrameHeader* header); |
| 41 | |
| 42 | // Is the frame with this header padded? Only true for known/supported frame |
| 43 | // types. |
| 44 | bool FrameIsPadded(const Http2FrameHeader& header); |
| 45 | |
| 46 | // Does the frame with this header have Http2PriorityFields? |
| 47 | bool 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. |
| 51 | bool 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. |
| 55 | bool FrameCanHaveHpackPayload(const Http2FrameHeader& header); |
| 56 | |
| 57 | } // namespace test |
| 58 | } // namespace http2 |
| 59 | |
| 60 | #endif // QUICHE_HTTP2_HTTP2_STRUCTURES_TEST_UTIL_H_ |