Index: net/http2/http2_constants_test_util.cc |
diff --git a/net/http2/http2_constants_test_util.cc b/net/http2/http2_constants_test_util.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2f4be401138055696a91d3770a664ca4ef4aa44a |
--- /dev/null |
+++ b/net/http2/http2_constants_test_util.cc |
@@ -0,0 +1,142 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "net/http2/http2_constants_test_util.h" |
+ |
+namespace net { |
+namespace test { |
+ |
+std::vector<Http2FrameType> AllHttp2FrameTypes() { |
+ // clang-format off |
+ return { |
+ Http2FrameType::DATA, |
+ Http2FrameType::HEADERS, |
+ Http2FrameType::PRIORITY, |
+ Http2FrameType::RST_STREAM, |
+ Http2FrameType::SETTINGS, |
+ Http2FrameType::PUSH_PROMISE, |
+ Http2FrameType::PING, |
+ Http2FrameType::GOAWAY, |
+ Http2FrameType::WINDOW_UPDATE, |
+ Http2FrameType::CONTINUATION, |
+ Http2FrameType::ALTSVC, |
+ }; |
+ // clang-format on |
+} |
+ |
+std::vector<Http2FrameFlag> AllHttp2FrameFlagsForFrameType( |
+ Http2FrameType type) { |
+ // clang-format off |
+ switch (type) { |
+ case Http2FrameType::DATA: |
+ return { |
+ Http2FrameFlag::FLAG_END_STREAM, |
+ Http2FrameFlag::FLAG_PADDED, |
+ }; |
+ case Http2FrameType::HEADERS: |
+ return { |
+ Http2FrameFlag::FLAG_END_STREAM, |
+ Http2FrameFlag::FLAG_END_HEADERS, |
+ Http2FrameFlag::FLAG_PADDED, |
+ Http2FrameFlag::FLAG_PRIORITY, |
+ }; |
+ case Http2FrameType::SETTINGS: |
+ return { |
+ Http2FrameFlag::FLAG_ACK, |
+ }; |
+ case Http2FrameType::PUSH_PROMISE: |
+ return { |
+ Http2FrameFlag::FLAG_END_HEADERS, |
+ Http2FrameFlag::FLAG_PADDED, |
+ }; |
+ case Http2FrameType::PING: |
+ return { |
+ Http2FrameFlag::FLAG_ACK, |
+ }; |
+ case Http2FrameType::CONTINUATION: |
+ return { |
+ Http2FrameFlag::FLAG_END_HEADERS, |
+ }; |
+ default: |
+ return std::vector<Http2FrameFlag>{}; |
+ } |
+ // clang-format on |
+} |
+ |
+std::vector<Http2ErrorCode> AllHttp2ErrorCodes() { |
+ // clang-format off |
+ return { |
+ Http2ErrorCode::HTTP2_NO_ERROR, |
+ Http2ErrorCode::PROTOCOL_ERROR, |
+ Http2ErrorCode::INTERNAL_ERROR, |
+ Http2ErrorCode::FLOW_CONTROL_ERROR, |
+ Http2ErrorCode::SETTINGS_TIMEOUT, |
+ Http2ErrorCode::STREAM_CLOSED, |
+ Http2ErrorCode::FRAME_SIZE_ERROR, |
+ Http2ErrorCode::REFUSED_STREAM, |
+ Http2ErrorCode::CANCEL, |
+ Http2ErrorCode::COMPRESSION_ERROR, |
+ Http2ErrorCode::CONNECT_ERROR, |
+ Http2ErrorCode::ENHANCE_YOUR_CALM, |
+ Http2ErrorCode::INADEQUATE_SECURITY, |
+ Http2ErrorCode::HTTP_1_1_REQUIRED, |
+ }; |
+ // clang-format on |
+} |
+ |
+std::vector<Http2SettingsParameter> AllHttp2SettingsParameters() { |
+ // clang-format off |
+ return { |
+ Http2SettingsParameter::HEADER_TABLE_SIZE, |
+ Http2SettingsParameter::ENABLE_PUSH, |
+ Http2SettingsParameter::MAX_CONCURRENT_STREAMS, |
+ Http2SettingsParameter::INITIAL_WINDOW_SIZE, |
+ Http2SettingsParameter::MAX_FRAME_SIZE, |
+ Http2SettingsParameter::MAX_HEADER_LIST_SIZE, |
+ }; |
+ // clang-format on |
+} |
+ |
+// Returns a mask of flags supported for the specified frame type. Returns |
+// zero for unknown frame types. |
+uint8_t KnownFlagsMaskForFrameType(Http2FrameType type) { |
+ switch (type) { |
+ case Http2FrameType::DATA: |
+ return Http2FrameFlag::FLAG_END_STREAM | Http2FrameFlag::FLAG_PADDED; |
+ case Http2FrameType::HEADERS: |
+ return Http2FrameFlag::FLAG_END_STREAM | |
+ Http2FrameFlag::FLAG_END_HEADERS | Http2FrameFlag::FLAG_PADDED | |
+ Http2FrameFlag::FLAG_PRIORITY; |
+ case Http2FrameType::PRIORITY: |
+ return 0x00; |
+ case Http2FrameType::RST_STREAM: |
+ return 0x00; |
+ case Http2FrameType::SETTINGS: |
+ return Http2FrameFlag::FLAG_ACK; |
+ case Http2FrameType::PUSH_PROMISE: |
+ return Http2FrameFlag::FLAG_END_HEADERS | Http2FrameFlag::FLAG_PADDED; |
+ case Http2FrameType::PING: |
+ return Http2FrameFlag::FLAG_ACK; |
+ case Http2FrameType::GOAWAY: |
+ return 0x00; |
+ case Http2FrameType::WINDOW_UPDATE: |
+ return 0x00; |
+ case Http2FrameType::CONTINUATION: |
+ return Http2FrameFlag::FLAG_END_HEADERS; |
+ case Http2FrameType::ALTSVC: |
+ return 0x00; |
+ default: |
+ return 0x00; |
+ } |
+} |
+ |
+uint8_t InvalidFlagMaskForFrameType(Http2FrameType type) { |
+ if (IsSupportedHttp2FrameType(type)) { |
+ return ~KnownFlagsMaskForFrameType(type); |
+ } |
+ return 0x00; |
+} |
+ |
+} // namespace test |
+} // namespace net |