src/net/quic/quic_network_transaction_unittest.cc
// Verify that if a QUIC connection RTOs, the QuicHttpStream will
// return QUIC_PROTOCOL_ERROR.
Verify that if a QUIC connection RTOs, the QuicHttpStream will
return QUIC_PROTOCOL_ERROR.
Verify that if a QUIC connection RTOs the QuicHttpStream will return QUIC_PROTOCOL_ERROR .
TEST_P(QuicNetworkTransactionTest, TooManyRtosAfterHandshakeConfirmed) {
  if (version_.handshake_protocol == quic::PROTOCOL_TLS1_3) {
    return;
  }
  context_.params()->retry_without_alt_svc_on_quic_errors = false;
  context_.params()->connection_options.push_back(quic::k5RTO);
  MockQuicData quic_data(version_);
  spdy::SpdyPriority priority =
      ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY);
  client_maker_->set_save_packet_frames(true);
  client_maker_->SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT);
  int packet_number = 1;
  if (VersionUsesHttp3(version_.transport_version)) {
    quic_data.AddWrite(
        SYNCHRONOUS, client_maker_->MakeInitialSettingsPacket(packet_number++));
  }
  quic_data.AddWrite(
      SYNCHRONOUS,
      client_maker_->MakeRequestHeadersPacket(
          packet_number++, GetNthClientInitiatedBidirectionalStreamId(0), true,
          true, priority, GetRequestHeaders("GET", "https", "/"), 0, nullptr));
  client_maker_->SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE);
  if (VersionUsesHttp3(version_.transport_version)) {
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(1, 3, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(2, 4, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(1, 5, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(2, 6, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(1, 7, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(2, 8, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(1, 9, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(2, 10, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(1, 11, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(2, 12, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeConnectionClosePacket(
                           13, true, quic::QUIC_TOO_MANY_RTOS,
                           "5 consecutive retransmission timeouts"));
  } else {
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(1, 2, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(1, 3, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(1, 4, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(1, 5, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(1, 6, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeRetransmissionPacket(1, 7, true));
    quic_data.AddWrite(SYNCHRONOUS,
                       client_maker_->MakeConnectionClosePacket(
                           8, true, quic::QUIC_TOO_MANY_RTOS,
                           "5 consecutive retransmission timeouts"));
  }
  quic_data.AddRead(ASYNC, OK);
  quic_data.AddSocketDataToFactory(&socket_factory_);
  host_resolver_.set_synchronous_mode(true);
  host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1",
                                           "");
  CreateSession();
  QuicStreamFactoryPeer::SetAlarmFactory(
      session_->quic_stream_factory(),
      std::make_unique<QuicChromiumAlarmFactory>(quic_task_runner_.get(),
                                                 context_.clock()));
  AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
  HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get());
  TestCompletionCallback callback;
  int rv = trans.Start(&request_, callback.callback(), net_log_.bound());
  EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
  base::RunLoop().RunUntilIdle();
  crypto_client_stream_factory_.last_stream()
      ->NotifySessionOneRttKeyAvailable();
  quic_task_runner_->RunUntilIdle();
  ExpectQuicAlternateProtocolMapping();
  ASSERT_TRUE(quic_data.AllWriteDataConsumed());
  EXPECT_THAT(callback.WaitForResult(), IsError(ERR_QUIC_PROTOCOL_ERROR));
}
TEST_P ( QuicNetworkTransactionTest , TooManyRtosAfterHandshakeConfirmed ) { if ( version_ . handshake_protocol == quic :: PROTOCOL_TLS1_3 ) { return ; } context_ . params ( ) -> retry_without_alt_svc_on_quic_errors = false ; context_ . params ( ) -> connection_options . push_back ( quic :: k5RTO ) ; MockQuicData quic_data ( version_ ) ; spdy :: SpdyPriority priority = ConvertRequestPriorityToQuicPriority ( DEFAULT_PRIORITY ) ; client_maker_ -> set_save_packet_frames ( true ) ; client_maker_ -> SetEncryptionLevel ( quic :: ENCRYPTION_ZERO_RTT ) ; int packet_number = 1 ; if ( VersionUsesHttp3 ( version_ . transport_version ) ) { quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeInitialSettingsPacket ( packet_number ++ ) ) ; } quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRequestHeadersPacket ( packet_number ++ , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , true , true , priority , GetRequestHeaders ( " " , " " , " " ) , 0 , nullptr ) ) ; client_maker_ -> SetEncryptionLevel ( quic :: ENCRYPTION_FORWARD_SECURE ) ; if ( VersionUsesHttp3 ( version_ . transport_version ) ) { quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 1 , 3 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 2 , 4 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 1 , 5 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 2 , 6 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 1 , 7 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 2 , 8 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 1 , 9 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 2 , 10 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 1 , 11 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 2 , 12 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeConnectionClosePacket ( 13 , true , quic :: QUIC_TOO_MANY_RTOS , " " ) ) ; } else { quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 1 , 2 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 1 , 3 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 1 , 4 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 1 , 5 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 1 , 6 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeRetransmissionPacket ( 1 , 7 , true ) ) ; quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakeConnectionClosePacket ( 8 , true , quic :: QUIC_TOO_MANY_RTOS , " " ) ) ; } quic_data . AddRead ( ASYNC , OK ) ; quic_data . AddSocketDataToFactory ( & socket_factory_ ) ; host_resolver_ . set_synchronous_mode ( true ) ; host_resolver_ . rules ( ) -> AddIPLiteralRule ( " " , " " , " " ) ; CreateSession ( ) ; QuicStreamFactoryPeer :: SetAlarmFactory ( session_ -> quic_stream_factory ( ) , std :: make_unique < QuicChromiumAlarmFactory > ( quic_task_runner_ . get ( ) , context_ . clock ( ) ) ) ; AddQuicAlternateProtocolMapping ( MockCryptoClientStream :: ZERO_RTT ) ; HttpNetworkTransaction trans ( DEFAULT_PRIORITY , session_ . get ( ) ) ; TestCompletionCallback callback ; int rv = trans . Start ( & request_ , callback . callback ( ) , net_log_ . bound ( ) ) ; EXPECT_THAT ( rv , IsError ( ERR_IO_PENDING ) ) ; base :: RunLoop ( ) . RunUntilIdle ( ) ; crypto_client_stream_factory_ . last_stream ( ) -> NotifySessionOneRttKeyAvailable ( ) ; quic_task_runner_ -> RunUntilIdle ( ) ; ExpectQuicAlternateProtocolMapping ( ) ; ASSERT_TRUE ( quic_data . AllWriteDataConsumed ( ) ) ; EXPECT_THAT ( callback . WaitForResult ( ) , IsError ( ERR_QUIC_PROTOCOL_ERROR ) ) ; }
Verify that if a QUIC connection RTOs, the QuicHttpStream will
return QUIC_PROTOCOL_ERROR.
Verify that if a QUIC connection RTOs the QuicHttpStream will return QUIC_PROTOCOL_ERROR .
// QUIC with TLS1.3 handshake doesn't support 0-rtt. // The request will initially go out over QUIC. // TLP 1 // TLP 2 // RTO 1 // RTO 2 // RTO 3 // RTO 4 // RTO 5 // TLP 1 // TLP 2 // RTO 1 // RTO 2 // RTO 3 // RTO 4 // RTO 5 // In order for a new QUIC session to be established via alternate-protocol // without racing an HTTP connection, we need the host resolution to happen // synchronously.  Of course, even though QUIC *could* perform a 0-RTT // connection to the the server, in this test we require confirmation // before encrypting so the HTTP job will still start. // Use a TestTaskRunner to avoid waiting in real time for timeouts. // Pump the message loop to get the request started. // Explicitly confirm the handshake. // Run the QUIC session to completion.