In quic, include minplaintextpacketsize when deterine whether removing soft limit for crypto frames. protected by enabled gfe2_reloadable_flag_quic_fix_min_crypto_frame_size.

PiperOrigin-RevId: 317743102
Change-Id: I43d56a2b3daea603cac4d2746f58426610875b0f
diff --git a/quic/core/quic_connection_test.cc b/quic/core/quic_connection_test.cc
index affd89f..d0f38a5 100644
--- a/quic/core/quic_connection_test.cc
+++ b/quic/core/quic_connection_test.cc
@@ -11345,6 +11345,44 @@
   }
 }
 
+// Regresstion test for b/156232673.
+TEST_P(QuicConnectionTest, CoalescePacketOfLowerEncryptionLevel) {
+  if (!connection_.version().CanSendCoalescedPackets()) {
+    return;
+  }
+  if (GetQuicReloadableFlag(quic_fix_min_crypto_frame_size)) {
+    EXPECT_CALL(visitor_, OnHandshakePacketSent()).Times(1);
+  } else {
+    EXPECT_CALL(visitor_, OnHandshakePacketSent()).Times(0);
+  }
+  {
+    QuicConnection::ScopedPacketFlusher flusher(&connection_);
+    use_tagging_decrypter();
+    connection_.SetEncrypter(ENCRYPTION_HANDSHAKE,
+                             std::make_unique<TaggingEncrypter>(0x01));
+    connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE,
+                             std::make_unique<TaggingEncrypter>(0x02));
+    connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
+    SendStreamDataToPeer(2, string(1286, 'a'), 0, NO_FIN, nullptr);
+    connection_.SetDefaultEncryptionLevel(ENCRYPTION_HANDSHAKE);
+    // Try to coalesce a HANDSHAKE packet after 1-RTT packet.
+    if (GetQuicReloadableFlag(quic_fix_min_crypto_frame_size)) {
+      // Verify soft max packet length gets resumed and handshake packet gets
+      // successfully sent.
+      connection_.SendCryptoDataWithString("a", 0, ENCRYPTION_HANDSHAKE);
+    } else {
+      // Problematic: creator thinks there is space to consume 1-byte, however,
+      // extra paddings make the serialization fail because of
+      // MinPlaintextPacketSize.
+      EXPECT_CALL(visitor_,
+                  OnConnectionClosed(_, ConnectionCloseSource::FROM_SELF));
+      EXPECT_QUIC_BUG(
+          connection_.SendCryptoDataWithString("a", 0, ENCRYPTION_HANDSHAKE),
+          "AppendPaddingFrame of 3 failed");
+    }
+  }
+}
+
 }  // namespace
 }  // namespace test
 }  // namespace quic