src/net/third_party/quiche/src/quic/tools/quic_simple_server_session_test.cc
// Tests that after all resources are promised, a RST frame from client can
// prevent a promised resource to be send out.
Tests that after all resources are promised, a RST frame from client can
prevent a promised resource to be send out.
Tests that after all resources are promised a RST frame from client can prevent a promised resource to be send out .
TEST_P(QuicSimpleServerSessionServerPushTest,
       ResetPromisedStreamToCancelServerPush) {
  if (VersionHasIetfQuicFrames(transport_version())) {
    return;
  }
  MaybeConsumeHeadersStreamData();
  if (VersionUsesHttp3(transport_version())) {
    session_->EnableServerPush();
    session_->OnMaxPushIdFrame(kMaxQuicStreamId);
  }
  size_t num_resources = kMaxStreamsForTest + 2;
  if (VersionHasIetfQuicFrames(transport_version())) {
    EXPECT_CALL(*connection_, SendControlFrame(_))
        .WillOnce(Invoke(&ClearControlFrame));
  }
  QuicByteCount data_frame_header_length = PromisePushResources(num_resources);
  QuicStreamId stream_got_reset;
  if (VersionUsesHttp3(transport_version())) {
    stream_got_reset =
        GetNthServerInitiatedUnidirectionalId(kMaxStreamsForTest + 4);
  } else {
    stream_got_reset =
        GetNthServerInitiatedUnidirectionalId(kMaxStreamsForTest + 1);
  }
  QuicRstStreamFrame rst(kInvalidControlFrameId, stream_got_reset,
                         QUIC_STREAM_CANCELLED, 0);
  EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1);
  EXPECT_CALL(*connection_, SendControlFrame(_))
      .WillOnce(Invoke(&ClearControlFrame));
  EXPECT_CALL(*connection_,
              OnStreamReset(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT));
  session_->OnRstStream(rst);
  QuicStreamId stream_not_reset;
  if (VersionUsesHttp3(transport_version())) {
    stream_not_reset =
        GetNthServerInitiatedUnidirectionalId(kMaxStreamsForTest + 3);
  } else {
    stream_not_reset =
        GetNthServerInitiatedUnidirectionalId(kMaxStreamsForTest);
  }
  InSequence s;
  QuicStreamOffset offset = 0;
  if (VersionUsesHttp3(transport_version())) {
    EXPECT_CALL(*connection_,
                SendStreamData(stream_not_reset, 1, offset, NO_FIN));
    offset++;
    EXPECT_CALL(*connection_,
                SendStreamData(stream_not_reset, kHeadersFrameHeaderLength,
                               offset, NO_FIN));
    offset += kHeadersFrameHeaderLength;
    EXPECT_CALL(*connection_,
                SendStreamData(stream_not_reset, kHeadersFramePayloadLength,
                               offset, NO_FIN));
    offset += kHeadersFramePayloadLength;
    EXPECT_CALL(*connection_,
                SendStreamData(stream_not_reset, data_frame_header_length,
                               offset, NO_FIN));
    offset += data_frame_header_length;
  }
  EXPECT_CALL(*connection_, SendStreamData(stream_not_reset, _, offset, NO_FIN))
      .WillOnce(Return(
          QuicConsumedData(kStreamFlowControlWindowSize - offset, false)));
  EXPECT_CALL(*session_, SendBlocked(stream_not_reset));
  if (VersionHasIetfQuicFrames(transport_version())) {
    session_->OnMaxStreamsFrame(
        QuicMaxStreamsFrame(0, num_resources + 3, true));
  }
  session_->StreamDraining(GetNthServerInitiatedUnidirectionalId(3));
  session_->StreamDraining(GetNthServerInitiatedUnidirectionalId(4));
}
TEST_P ( QuicSimpleServerSessionServerPushTest , ResetPromisedStreamToCancelServerPush ) { if ( VersionHasIetfQuicFrames ( transport_version ( ) ) ) { return ; } MaybeConsumeHeadersStreamData ( ) ; if ( VersionUsesHttp3 ( transport_version ( ) ) ) { session_ -> EnableServerPush ( ) ; session_ -> OnMaxPushIdFrame ( kMaxQuicStreamId ) ; } size_t num_resources = kMaxStreamsForTest + 2 ; if ( VersionHasIetfQuicFrames ( transport_version ( ) ) ) { EXPECT_CALL ( * connection_ , SendControlFrame ( _ ) ) . WillOnce ( Invoke ( & ClearControlFrame ) ) ; } QuicByteCount data_frame_header_length = PromisePushResources ( num_resources ) ; QuicStreamId stream_got_reset ; if ( VersionUsesHttp3 ( transport_version ( ) ) ) { stream_got_reset = GetNthServerInitiatedUnidirectionalId ( kMaxStreamsForTest + 4 ) ; } else { stream_got_reset = GetNthServerInitiatedUnidirectionalId ( kMaxStreamsForTest + 1 ) ; } QuicRstStreamFrame rst ( kInvalidControlFrameId , stream_got_reset , QUIC_STREAM_CANCELLED , 0 ) ; EXPECT_CALL ( owner_ , OnRstStreamReceived ( _ ) ) . Times ( 1 ) ; EXPECT_CALL ( * connection_ , SendControlFrame ( _ ) ) . WillOnce ( Invoke ( & ClearControlFrame ) ) ; EXPECT_CALL ( * connection_ , OnStreamReset ( stream_got_reset , QUIC_RST_ACKNOWLEDGEMENT ) ) ; session_ -> OnRstStream ( rst ) ; QuicStreamId stream_not_reset ; if ( VersionUsesHttp3 ( transport_version ( ) ) ) { stream_not_reset = GetNthServerInitiatedUnidirectionalId ( kMaxStreamsForTest + 3 ) ; } else { stream_not_reset = GetNthServerInitiatedUnidirectionalId ( kMaxStreamsForTest ) ; } InSequence s ; QuicStreamOffset offset = 0 ; if ( VersionUsesHttp3 ( transport_version ( ) ) ) { EXPECT_CALL ( * connection_ , SendStreamData ( stream_not_reset , 1 , offset , NO_FIN ) ) ; offset ++ ; EXPECT_CALL ( * connection_ , SendStreamData ( stream_not_reset , kHeadersFrameHeaderLength , offset , NO_FIN ) ) ; offset += kHeadersFrameHeaderLength ; EXPECT_CALL ( * connection_ , SendStreamData ( stream_not_reset , kHeadersFramePayloadLength , offset , NO_FIN ) ) ; offset += kHeadersFramePayloadLength ; EXPECT_CALL ( * connection_ , SendStreamData ( stream_not_reset , data_frame_header_length , offset , NO_FIN ) ) ; offset += data_frame_header_length ; } EXPECT_CALL ( * connection_ , SendStreamData ( stream_not_reset , _ , offset , NO_FIN ) ) . WillOnce ( Return ( QuicConsumedData ( kStreamFlowControlWindowSize - offset , false ) ) ) ; EXPECT_CALL ( * session_ , SendBlocked ( stream_not_reset ) ) ; if ( VersionHasIetfQuicFrames ( transport_version ( ) ) ) { session_ -> OnMaxStreamsFrame ( QuicMaxStreamsFrame ( 0 , num_resources + 3 , true ) ) ; } session_ -> StreamDraining ( GetNthServerInitiatedUnidirectionalId ( 3 ) ) ; session_ -> StreamDraining ( GetNthServerInitiatedUnidirectionalId ( 4 ) ) ; }
Tests that after all resources are promised, a RST frame from client can
prevent a promised resource to be send out.
Tests that after all resources are promised a RST frame from client can prevent a promised resource to be send out .
// This test is resetting a stream that is not opened yet. IETF QUIC has no // way to handle this. Some similar tests can be added once CANCEL_PUSH is // supported. // Having two extra resources to be send later. One of them will be reset, so // when opened stream become close, only one will become open. // V99 will send out a STREAMS_BLOCKED frame when it tries to exceed the // limit. This will clear the frames so that they do not block the later // rst-stream frame. // Reset the last stream in the queue. It should be marked cancelled. // When the first 2 streams becomes draining, the two queued up stream could // be created. But since one of them was marked cancelled due to RST frame, // only one queued resource will be sent out. // The PromisePushedResources call, above, will have used all available // stream ids.  For version 99, stream ids are not made available until // a MAX_STREAMS frame is received. This emulates the reception of one. // For pre-v-99, the node monitors its own stream usage and makes streams // available as it closes/etc them. /*unidirectional=*/