Adds support for METADATA frames to TestFrameSequence.

This will make it easier to test metadata handling behavior in adapter unit tests.

PiperOrigin-RevId: 381314900
diff --git a/http2/adapter/http2_protocol.h b/http2/adapter/http2_protocol.h
index 7cefa29..efe4048 100644
--- a/http2/adapter/http2_protocol.h
+++ b/http2/adapter/http2_protocol.h
@@ -125,6 +125,9 @@
   kServer,
 };
 
+const uint8_t kMetadataFrameType = 0x4d;
+const uint8_t kMetadataEndFlag = 0x04;
+
 }  // namespace adapter
 }  // namespace http2
 
diff --git a/http2/adapter/test_frame_sequence.cc b/http2/adapter/test_frame_sequence.cc
index 7be368e..a64f915 100644
--- a/http2/adapter/test_frame_sequence.cc
+++ b/http2/adapter/test_frame_sequence.cc
@@ -2,6 +2,7 @@
 
 #include "http2/adapter/http2_util.h"
 #include "http2/adapter/oghttp2_util.h"
+#include "spdy/core/hpack/hpack_encoder.h"
 #include "spdy/core/spdy_framer.h"
 
 namespace http2 {
@@ -124,6 +125,21 @@
   return *this;
 }
 
+TestFrameSequence& TestFrameSequence::Metadata(Http2StreamId stream_id,
+                                               absl::string_view payload) {
+  // Encode the payload using a header block.
+  spdy::SpdyHeaderBlock block;
+  block["example-payload"] = payload;
+  spdy::HpackEncoder encoder;
+  encoder.DisableCompression();
+  std::string encoded_payload;
+  encoder.EncodeHeaderSet(block, &encoded_payload);
+  frames_.push_back(absl::make_unique<spdy::SpdyUnknownIR>(
+      stream_id, kMetadataFrameType, kMetadataEndFlag,
+      std::move(encoded_payload)));
+  return *this;
+}
+
 std::string TestFrameSequence::Serialize() {
   std::string result;
   if (!preface_.empty()) {
diff --git a/http2/adapter/test_frame_sequence.h b/http2/adapter/test_frame_sequence.h
index cc5e8b5..7a65f67 100644
--- a/http2/adapter/test_frame_sequence.h
+++ b/http2/adapter/test_frame_sequence.h
@@ -48,6 +48,8 @@
                               Http2StreamId parent_stream_id,
                               int weight,
                               bool exclusive);
+  TestFrameSequence& Metadata(Http2StreamId stream_id,
+                              absl::string_view payload);
 
   std::string Serialize();