Avoid using QuicSession::CloseStream() in tests.

This is part of the effort to deprecate QuicSession::CloseStream()

Test only change. not protected.

PiperOrigin-RevId: 319107364
Change-Id: I57bf6509c4768b4170a37caad324c536465ba7f1
diff --git a/quic/core/http/quic_spdy_client_session_test.cc b/quic/core/http/quic_spdy_client_session_test.cc
index 21e5d96..535ecf5 100644
--- a/quic/core/http/quic_spdy_client_session_test.cc
+++ b/quic/core/http/quic_spdy_client_session_test.cc
@@ -288,7 +288,7 @@
 
   // Close the stream, but without having received a FIN or a RST_STREAM
   // or MAX_STREAMS (V99) and check that a new one can not be created.
-  session_->CloseStream(stream->id());
+  session_->ResetStream(stream->id(), QUIC_STREAM_CANCELLED, 0);
   EXPECT_EQ(1u, QuicSessionPeer::GetNumOpenDynamicStreams(session_.get()));
 
   stream = session_->CreateOutgoingBidirectionalStream();
@@ -304,7 +304,7 @@
   EXPECT_EQ(nullptr, session_->CreateOutgoingBidirectionalStream());
 
   // Close the stream and receive an RST frame to remove the unfinished stream
-  session_->CloseStream(stream->id());
+  session_->ResetStream(stream->id(), QUIC_STREAM_CANCELLED, 0);
   session_->OnRstStream(QuicRstStreamFrame(kInvalidControlFrameId, stream->id(),
                                            QUIC_RST_ACKNOWLEDGEMENT, 0));
   // Check that a new one can be created.
diff --git a/quic/core/http/quic_spdy_session_test.cc b/quic/core/http/quic_spdy_session_test.cc
index b2bcaa3..febbe40 100644
--- a/quic/core/http/quic_spdy_session_test.cc
+++ b/quic/core/http/quic_spdy_session_test.cc
@@ -406,7 +406,12 @@
           .WillRepeatedly(Invoke(&ClearControlFrame));
     }
     EXPECT_CALL(*connection_, OnStreamReset(id, _));
-    session_.CloseStream(id);
+
+    // QPACK streams might write data upon stream reset. Let the test session
+    // handle the data.
+    session_.set_writev_consumes_all_data(true);
+
+    session_.ResetStream(id, QUIC_STREAM_CANCELLED, 0);
     closed_streams_.insert(id);
   }
 
@@ -1721,21 +1726,7 @@
   for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += kNextId) {
     QuicStreamFrame data1(i, false, 0, quiche::QuicheStringPiece("HT"));
     session_.OnStreamFrame(data1);
-    // EXPECT_EQ(1u, session_.GetNumOpenStreams());
-    if (!VersionHasIetfQuicFrames(transport_version())) {
-      EXPECT_CALL(*connection_, SendControlFrame(_))
-          .WillOnce(Invoke(&ClearControlFrame));
-    } else {
-      // V99 has two frames, RST_STREAM and STOP_SENDING
-      EXPECT_CALL(*connection_, SendControlFrame(_))
-          .Times(2)
-          .WillRepeatedly(Invoke(&ClearControlFrame));
-    }
-    // Close the stream only if not version 99. If we are version 99
-    // then closing the stream opens up the available stream id space,
-    // so we never bump into the limit.
-    EXPECT_CALL(*connection_, OnStreamReset(i, _));
-    session_.CloseStream(i);
+    CloseStream(i);
   }
   // Try and open a stream that exceeds the limit.
   if (!VersionHasIetfQuicFrames(transport_version())) {
@@ -2082,9 +2073,7 @@
   QuicStreamPeer::SetStreamBytesWritten(3, stream2);
   EXPECT_TRUE(stream2->IsWaitingForAcks());
 
-  EXPECT_CALL(*connection_, SendControlFrame(_));
-  EXPECT_CALL(*connection_, OnStreamReset(stream2->id(), _));
-  session_.CloseStream(stream2->id());
+  CloseStream(stream2->id());
   EXPECT_FALSE(QuicContainsKey(session_.zombie_streams(), stream2->id()));
   ASSERT_EQ(1u, session_.closed_streams()->size());
   EXPECT_EQ(stream2->id(), session_.closed_streams()->front()->id());
diff --git a/quic/core/quic_session_test.cc b/quic/core/quic_session_test.cc
index 12a4830..aa937a6 100644
--- a/quic/core/quic_session_test.cc
+++ b/quic/core/quic_session_test.cc
@@ -439,9 +439,12 @@
       if (QuicUtils::GetStreamType(
               id, session_.perspective(), session_.IsIncomingStream(id),
               connection_->version()) == READ_UNIDIRECTIONAL) {
-        // Verify reset is not sent for READ_UNIDIRECTIONAL streams.
-        EXPECT_CALL(*connection_, SendControlFrame(_)).Times(0);
-        EXPECT_CALL(*connection_, OnStreamReset(_, _)).Times(0);
+        // Verify STOP_SENDING but no RESET_STREAM is sent for
+        // READ_UNIDIRECTIONAL streams.
+        EXPECT_CALL(*connection_, SendControlFrame(_))
+            .Times(1)
+            .WillOnce(Invoke(&ClearControlFrame));
+        EXPECT_CALL(*connection_, OnStreamReset(id, _)).Times(1);
       } else if (QuicUtils::GetStreamType(
                      id, session_.perspective(), session_.IsIncomingStream(id),
                      connection_->version()) == WRITE_UNIDIRECTIONAL) {
@@ -464,7 +467,7 @@
           .WillOnce(Invoke(&ClearControlFrame));
       EXPECT_CALL(*connection_, OnStreamReset(id, _));
     }
-    session_.CloseStream(id);
+    session_.ResetStream(id, QUIC_STREAM_CANCELLED, 0);
     closed_streams_.insert(id);
   }
 
@@ -1861,21 +1864,7 @@
        i += QuicUtils::StreamIdDelta(connection_->transport_version())) {
     QuicStreamFrame data1(i, false, 0, quiche::QuicheStringPiece("HT"));
     session_.OnStreamFrame(data1);
-    // EXPECT_EQ(1u, session_.GetNumOpenStreams());
-    if (VersionHasIetfQuicFrames(transport_version())) {
-      // Expect two control frames, RST STREAM and STOP SENDING
-      EXPECT_CALL(*connection_, SendControlFrame(_))
-          .Times(2)
-          .WillRepeatedly(Invoke(&ClearControlFrame));
-    } else {
-      // Expect one control frame, just RST STREAM
-      EXPECT_CALL(*connection_, SendControlFrame(_))
-          .WillOnce(Invoke(&ClearControlFrame));
-    }
-    // Close stream. Should not make new streams available since
-    // the stream is not finished.
-    EXPECT_CALL(*connection_, OnStreamReset(i, _));
-    session_.CloseStream(i);
+    CloseStream(i);
   }
 
   if (VersionHasIetfQuicFrames(transport_version())) {
@@ -2218,9 +2207,7 @@
   QuicStreamPeer::SetStreamBytesWritten(3, stream2);
   EXPECT_TRUE(stream2->IsWaitingForAcks());
 
-  EXPECT_CALL(*connection_, SendControlFrame(_));
-  EXPECT_CALL(*connection_, OnStreamReset(stream2->id(), _));
-  session_.CloseStream(stream2->id());
+  CloseStream(stream2->id());
   EXPECT_FALSE(QuicContainsKey(session_.zombie_streams(), stream2->id()));
   ASSERT_EQ(1u, session_.closed_streams()->size());
   EXPECT_EQ(stream2->id(), session_.closed_streams()->front()->id());
@@ -2471,7 +2458,7 @@
   // Retransmit stream data causes connection close. Stream has not sent fin
   // yet, so an RST is sent.
   EXPECT_CALL(*stream, OnCanWrite()).WillOnce(Invoke([this, stream]() {
-    session_.CloseStream(stream->id());
+    session_.ResetStream(stream->id(), QUIC_STREAM_CANCELLED, 0);
   }));
   if (VersionHasIetfQuicFrames(transport_version())) {
     // Once for the RST_STREAM, once for the STOP_SENDING
@@ -2578,9 +2565,7 @@
   TestStream* stream2 = session_.CreateOutgoingBidirectionalStream();
   EXPECT_FALSE(stream2->IsWaitingForAcks());
 
-  EXPECT_CALL(*connection_, SendControlFrame(_));
-  EXPECT_CALL(*connection_, OnStreamReset(stream2->id(), _));
-  session_.CloseStream(stream2->id());
+  CloseStream(stream2->id());
   EXPECT_FALSE(QuicContainsKey(session_.zombie_streams(), stream2->id()));
   EXPECT_EQ(1u, session_.closed_streams()->size());
   EXPECT_TRUE(
@@ -2847,10 +2832,7 @@
 
   TestStream* stream = session_.CreateOutgoingBidirectionalStream();
   QuicStreamId stream_id = stream->id();
-  // Expect these as side effect of closing the stream.
-  EXPECT_CALL(*connection_, SendControlFrame(_));
-  EXPECT_CALL(*connection_, OnStreamReset(_, _));
-  session_.CloseStream(stream_id);
+  CloseStream(stream_id);
   QuicStopSendingFrame frame(1, stream_id, 123);
   EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0);
   session_.OnStopSendingFrame(frame);
diff --git a/quic/core/quic_stream_test.cc b/quic/core/quic_stream_test.cc
index 356a77d..a991a52 100644
--- a/quic/core/quic_stream_test.cc
+++ b/quic/core/quic_stream_test.cc
@@ -130,7 +130,7 @@
       StreamSendingState /*state*/,
       TransmissionType /*type*/,
       quiche::QuicheOptional<EncryptionLevel> /*level*/) {
-    session_->CloseStream(id);
+    session_->ResetStream(id, QUIC_STREAM_CANCELLED, 0);
     return QuicConsumedData(1, false);
   }