Use IETF application error codes for STOP_SENDING frames.

Add ietf_error_code member to QuicStopSendingFrame, and use
IetfResetStreamErrorCodeToRstStreamErrorCode() and
RstStreamErrorCodeToIetfResetStreamErrorCode() to convert to and from
QuicRstStreamErrorCode.  This closely mirrors behavior of QuicRstStreamFrame.

This is the reland of cl/330521460 with
EndToEndTests/EndToEndTest.ClientRstStats fixed.  See b/168041589 for flakiness
caused by original CL.  Locally verified that 100 runs pass both with and
without FLAGS_gfe2_reloadable_flag_quic_stop_sending_uses_ietf_error_code.

Protected by FLAGS_quic_reloadable_flag_quic_stop_sending_uses_application_error_code.

PiperOrigin-RevId: 331000553
Change-Id: Ie5ac10b4e75fe98858d1e79bd07c108525452caa
diff --git a/quic/core/quic_framer_test.cc b/quic/core/quic_framer_test.cc
index b67eaf3..46cfe61 100644
--- a/quic/core/quic_framer_test.cc
+++ b/quic/core/quic_framer_test.cc
@@ -10977,7 +10977,14 @@
       PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID));
 
   EXPECT_EQ(kStreamId, visitor_.stop_sending_frame_.stream_id);
-  EXPECT_EQ(0x7654, visitor_.stop_sending_frame_.error_code);
+  if (GetQuicReloadableFlag(quic_stop_sending_uses_ietf_error_code)) {
+    EXPECT_EQ(QUIC_STREAM_UNKNOWN_APPLICATION_ERROR_CODE,
+              visitor_.stop_sending_frame_.error_code);
+  } else {
+    EXPECT_EQ(0x7654, visitor_.stop_sending_frame_.error_code);
+  }
+  EXPECT_EQ(static_cast<uint64_t>(0x7654),
+            visitor_.stop_sending_frame_.ietf_error_code);
 
   CheckFramingBoundaries(packet99, QUIC_INVALID_STOP_SENDING_FRAME_DATA);
 }
@@ -10996,7 +11003,9 @@
 
   QuicStopSendingFrame frame;
   frame.stream_id = kStreamId;
-  frame.error_code = static_cast<QuicRstStreamErrorCode>(0xffff);
+  frame.error_code = QUIC_STREAM_ENCODER_STREAM_ERROR;
+  frame.ietf_error_code =
+      static_cast<uint64_t>(QuicHttpQpackErrorCode::ENCODER_STREAM_ERROR);
   QuicFrames frames = {QuicFrame(&frame)};
 
   // clang-format off
@@ -11013,7 +11022,7 @@
     // Stream ID
     kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04,
     // Application error code
-    kVarInt62FourBytes + 0x00, 0x00, 0xff, 0xff
+    kVarInt62TwoBytes + 0x02, 0x01,
   };
   // clang-format on