src/net/quic/quic_network_transaction_unittest.cc
// Performs an HTTPS/1.1 request over QUIC proxy tunnel.
Performs an HTTPS/1.1 request over QUIC proxy tunnel.
Performs an HTTPS / 1 . 1 request over QUIC proxy tunnel .
TEST_P(QuicNetworkTransactionTest, QuicProxyConnectHttpsServer) {
  session_params_.enable_quic = true;
  session_params_.enable_quic_proxies_for_https_urls = true;
  proxy_resolution_service_ =
      ConfiguredProxyResolutionService::CreateFixedFromPacResult(
          "QUIC proxy.example.org:70", TRAFFIC_ANNOTATION_FOR_TESTS);
  MockQuicData mock_quic_data(version_);
  int packet_num = 1;
  if (VersionUsesHttp3(version_.transport_version)) {
    mock_quic_data.AddWrite(SYNCHRONOUS,
                            ConstructInitialSettingsPacket(packet_num++));
    mock_quic_data.AddWrite(
        SYNCHRONOUS, client_maker_->MakePriorityPacket(
                         packet_num++, true,
                         GetNthClientInitiatedBidirectionalStreamId(0), 0,
                         ConvertRequestPriorityToQuicPriority(
                             HttpProxyConnectJob::kH2QuicTunnelPriority)));
  }
  mock_quic_data.AddWrite(
      SYNCHRONOUS,
      ConstructClientRequestHeadersPacket(
          packet_num++, GetNthClientInitiatedBidirectionalStreamId(0), true,
          false,
          VersionUsesHttp3(version_.transport_version)
              ? MEDIUM
              : HttpProxyConnectJob::kH2QuicTunnelPriority,
          ConnectRequestHeaders("mail.example.org:443"), 0));
  mock_quic_data.AddRead(
      ASYNC, ConstructServerResponseHeadersPacket(
                 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false,
                 GetResponseHeaders("200 OK")));
  const char get_request[] =
      "GET / HTTP/1.1\r\n"
      "Host: mail.example.org\r\n"
      "Connection: keep-alive\r\n\r\n";
  std::string header = ConstructDataHeader(strlen(get_request));
  if (!version_.HasIetfQuicFrames()) {
    mock_quic_data.AddWrite(
        SYNCHRONOUS,
        ConstructClientAckAndDataPacket(
            packet_num++, false, GetNthClientInitiatedBidirectionalStreamId(0),
            1, 1, 1, false, quiche::QuicheStringPiece(get_request)));
  } else {
    mock_quic_data.AddWrite(
        SYNCHRONOUS,
        ConstructClientAckAndDataPacket(
            packet_num++, false, GetNthClientInitiatedBidirectionalStreamId(0),
            1, 1, 1, false, {header + std::string(get_request)}));
  }
  const char get_response[] =
      "HTTP/1.1 200 OK\r\n"
      "Content-Length: 10\r\n\r\n";
  std::string header2 = ConstructDataHeader(strlen(get_response));
  mock_quic_data.AddRead(
      ASYNC, ConstructServerDataPacket(
                 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false,
                 header2 + std::string(get_response)));
  std::string header3 = ConstructDataHeader(10);
  mock_quic_data.AddRead(
      SYNCHRONOUS, ConstructServerDataPacket(
                       3, GetNthClientInitiatedBidirectionalStreamId(0), false,
                       false, header3 + std::string("0123456789")));
  mock_quic_data.AddWrite(SYNCHRONOUS,
                          ConstructClientAckPacket(packet_num++, 3, 2, 1));
  mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING);  
  if (VersionUsesHttp3(version_.transport_version)) {
    mock_quic_data.AddWrite(
        SYNCHRONOUS, ConstructClientDataPacket(
                         packet_num++, GetQpackDecoderStreamId(), true, false,
                         StreamCancellationQpackDecoderInstruction(0)));
  }
  mock_quic_data.AddWrite(
      SYNCHRONOUS,
      ConstructClientRstPacket(packet_num++,
                               GetNthClientInitiatedBidirectionalStreamId(0),
                               quic::QUIC_STREAM_CANCELLED));
  mock_quic_data.AddSocketDataToFactory(&socket_factory_);
  socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
  CreateSession();
  request_.url = GURL("https://mail.example.org/");
  AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE);
  HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get());
  RunTransaction(&trans);
  CheckWasHttpResponse(&trans);
  CheckResponsePort(&trans, 70);
  CheckResponseData(&trans, "0123456789");
  EXPECT_TRUE(trans.GetResponseInfo()->proxy_server.is_quic());
  NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
  base::RunLoop().RunUntilIdle();
  EXPECT_TRUE(mock_quic_data.AllReadDataConsumed());
  EXPECT_TRUE(mock_quic_data.AllWriteDataConsumed());
}
TEST_P ( QuicNetworkTransactionTest , QuicProxyConnectHttpsServer ) { session_params_ . enable_quic = true ; session_params_ . enable_quic_proxies_for_https_urls = true ; proxy_resolution_service_ = ConfiguredProxyResolutionService :: CreateFixedFromPacResult ( " " , TRAFFIC_ANNOTATION_FOR_TESTS ) ; MockQuicData mock_quic_data ( version_ ) ; int packet_num = 1 ; if ( VersionUsesHttp3 ( version_ . transport_version ) ) { mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructInitialSettingsPacket ( packet_num ++ ) ) ; mock_quic_data . AddWrite ( SYNCHRONOUS , client_maker_ -> MakePriorityPacket ( packet_num ++ , true , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , 0 , ConvertRequestPriorityToQuicPriority ( HttpProxyConnectJob :: kH2QuicTunnelPriority ) ) ) ; } mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientRequestHeadersPacket ( packet_num ++ , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , true , false , VersionUsesHttp3 ( version_ . transport_version ) ? MEDIUM : HttpProxyConnectJob :: kH2QuicTunnelPriority , ConnectRequestHeaders ( " " ) , 0 ) ) ; mock_quic_data . AddRead ( ASYNC , ConstructServerResponseHeadersPacket ( 1 , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , false , false , GetResponseHeaders ( " " ) ) ) ; const char get_request [ ] = " \r \n " " \r \n " " \r \n \r \n " ; std :: string header = ConstructDataHeader ( strlen ( get_request ) ) ; if ( ! version_ . HasIetfQuicFrames ( ) ) { mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientAckAndDataPacket ( packet_num ++ , false , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , 1 , 1 , 1 , false , quiche :: QuicheStringPiece ( get_request ) ) ) ; } else { mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientAckAndDataPacket ( packet_num ++ , false , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , 1 , 1 , 1 , false , { header + std :: string ( get_request ) } ) ) ; } const char get_response [ ] = " \r \n " " \r \n \r \n " ; std :: string header2 = ConstructDataHeader ( strlen ( get_response ) ) ; mock_quic_data . AddRead ( ASYNC , ConstructServerDataPacket ( 2 , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , false , false , header2 + std :: string ( get_response ) ) ) ; std :: string header3 = ConstructDataHeader ( 10 ) ; mock_quic_data . AddRead ( SYNCHRONOUS , ConstructServerDataPacket ( 3 , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , false , false , header3 + std :: string ( " " ) ) ) ; mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientAckPacket ( packet_num ++ , 3 , 2 , 1 ) ) ; mock_quic_data . AddRead ( SYNCHRONOUS , ERR_IO_PENDING ) ; if ( VersionUsesHttp3 ( version_ . transport_version ) ) { mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientDataPacket ( packet_num ++ , GetQpackDecoderStreamId ( ) , true , false , StreamCancellationQpackDecoderInstruction ( 0 ) ) ) ; } mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientRstPacket ( packet_num ++ , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , quic :: QUIC_STREAM_CANCELLED ) ) ; mock_quic_data . AddSocketDataToFactory ( & socket_factory_ ) ; socket_factory_ . AddSSLSocketDataProvider ( & ssl_data_ ) ; CreateSession ( ) ; request_ . url = GURL ( " " ) ; AddQuicAlternateProtocolMapping ( MockCryptoClientStream :: CONFIRM_HANDSHAKE ) ; HttpNetworkTransaction trans ( DEFAULT_PRIORITY , session_ . get ( ) ) ; RunTransaction ( & trans ) ; CheckWasHttpResponse ( & trans ) ; CheckResponsePort ( & trans , 70 ) ; CheckResponseData ( & trans , " " ) ; EXPECT_TRUE ( trans . GetResponseInfo ( ) -> proxy_server . is_quic ( ) ) ; NetworkChangeNotifier :: NotifyObserversOfIPAddressChangeForTests ( ) ; base :: RunLoop ( ) . RunUntilIdle ( ) ; EXPECT_TRUE ( mock_quic_data . AllReadDataConsumed ( ) ) ; EXPECT_TRUE ( mock_quic_data . AllWriteDataConsumed ( ) ) ; }
Performs an HTTPS/1.1 request over QUIC proxy tunnel.
Performs an HTTPS / 1 . 1 request over QUIC proxy tunnel .
// No more data to read // Causes MockSSLClientSocket to disconnect, which causes the underlying QUIC // proxy socket to disconnect.