Have framer store frame type currently being processed

This CL has QuicFramer save the frame type for the frame that it currently
is extracting from the packet and processing. This is done so that the
IETF QUIC Transport Connection Close can get the type of frame that
precipitated the close. If the frame-type was not saved like this then
it would need to be passed around in the call stack -- one more parameter
threaded throughout many calls in QUIC.

This done only when IETF Framing (version 99) is enabled.

Tests in quic_framer_test.cc have been modified to check that the right
frame type has been saved (done in all of the On...Frame upcalls, so that
the testing is fairly complete). Also checks that the saved type is 0
when not processing a frame (eg, when doing header processing) OR when not
doing IETF QUIC Framing.

gfe-relnote: N/A is only for Version 99/IETF QUIC Framing.
PiperOrigin-RevId: 265888094
Change-Id: If068d49c9f72b4e3c0e8eb3e7ab7460abde85f8a
diff --git a/quic/core/quic_connection_test.cc b/quic/core/quic_connection_test.cc
index dbf3860..9f8127d 100644
--- a/quic/core/quic_connection_test.cc
+++ b/quic/core/quic_connection_test.cc
@@ -1466,8 +1466,7 @@
         // Maps to a transport close
         qccf.close_type = IETF_QUIC_TRANSPORT_CONNECTION_CLOSE;
         qccf.transport_error_code = mapping.transport_error_code_;
-        // TODO(fkastenholz) need to change "0" to get the frame type currently
-        // being processed so that it can be inserted into the frame.
+        // Frame type is not important for the tests that invoke this method.
         qccf.transport_close_frame_type = 0;
       } else {
         // Maps to an application close.
@@ -9131,6 +9130,32 @@
   }
 }
 
+TEST_P(QuicConnectionTest, ConnectionCloseFrameType) {
+  if (!VersionHasIetfQuicFrames(version().transport_version)) {
+    // Test relevent only for IETF QUIC.
+    return;
+  }
+  const QuicErrorCode kQuicErrorCode = IETF_QUIC_PROTOCOL_VIOLATION;
+  // Use the (unknown) frame type of 9999 to avoid triggering any logic
+  // which might be associated with the processing of a known frame type.
+  const uint64_t kTransportCloseFrameType = 9999u;
+  QuicFramerPeer::set_current_received_frame_type(
+      QuicConnectionPeer::GetFramer(&connection_), kTransportCloseFrameType);
+  // Do a transport connection close
+  EXPECT_CALL(visitor_, OnConnectionClosed(_, _));
+  connection_.CloseConnection(
+      kQuicErrorCode, "Some random error message",
+      ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET);
+  const std::vector<QuicConnectionCloseFrame>& connection_close_frames =
+      writer_->connection_close_frames();
+  ASSERT_EQ(1u, connection_close_frames.size());
+  EXPECT_EQ(IETF_QUIC_TRANSPORT_CONNECTION_CLOSE,
+            connection_close_frames[0].close_type);
+  EXPECT_EQ(kQuicErrorCode, connection_close_frames[0].extracted_error_code);
+  EXPECT_EQ(kTransportCloseFrameType,
+            connection_close_frames[0].transport_close_frame_type);
+}
+
 }  // namespace
 }  // namespace test
 }  // namespace quic