src/net/quic/quic_network_transaction_unittest.cc
// Performs an HTTP/2 request over QUIC proxy tunnel.
Performs an HTTP/2 request over QUIC proxy tunnel.
Performs an HTTP / 2 request over QUIC proxy tunnel .
TEST_P(QuicNetworkTransactionTest, QuicProxyConnectSpdyServer) {
  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")));
  SpdyTestUtil spdy_util;
  spdy::SpdySerializedFrame get_frame =
      spdy_util.ConstructSpdyGet("https://mail.example.org/", 1, LOWEST);
  std::string header = ConstructDataHeader(get_frame.size());
  if (!version_.HasIetfQuicFrames()) {
    mock_quic_data.AddWrite(
        SYNCHRONOUS,
        ConstructClientAckAndDataPacket(
            packet_num++, false, GetNthClientInitiatedBidirectionalStreamId(0),
            1, 1, 1, false,
            quiche::QuicheStringPiece(get_frame.data(), get_frame.size())));
  } else {
    mock_quic_data.AddWrite(
        SYNCHRONOUS,
        ConstructClientAckAndDataPacket(
            packet_num++, false, GetNthClientInitiatedBidirectionalStreamId(0),
            1, 1, 1, false,
            {header + std::string(get_frame.data(), get_frame.size())}));
  }
  spdy::SpdySerializedFrame resp_frame =
      spdy_util.ConstructSpdyGetReply(nullptr, 0, 1);
  std::string header2 = ConstructDataHeader(resp_frame.size());
  mock_quic_data.AddRead(
      ASYNC, ConstructServerDataPacket(
                 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false,
                 header2 + std::string(resp_frame.data(), resp_frame.size())));
  spdy::SpdySerializedFrame data_frame =
      spdy_util.ConstructSpdyDataFrame(1, "0123456789", true);
  std::string header3 = ConstructDataHeader(resp_frame.size());
  mock_quic_data.AddRead(
      SYNCHRONOUS,
      ConstructServerDataPacket(
          3, GetNthClientInitiatedBidirectionalStreamId(0), false, false,
          header3 + std::string(data_frame.data(), data_frame.size())));
  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_);
  SSLSocketDataProvider ssl_data(ASYNC, OK);
  ssl_data.next_proto = kProtoHTTP2;
  socket_factory_.AddSSLSocketDataProvider(&ssl_data);
  CreateSession();
  request_.url = GURL("https://mail.example.org/");
  HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get());
  RunTransaction(&trans);
  CheckWasSpdyResponse(&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 , QuicProxyConnectSpdyServer ) { 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 ( " " ) ) ) ; SpdyTestUtil spdy_util ; spdy :: SpdySerializedFrame get_frame = spdy_util . ConstructSpdyGet ( " " , 1 , LOWEST ) ; std :: string header = ConstructDataHeader ( get_frame . size ( ) ) ; if ( ! version_ . HasIetfQuicFrames ( ) ) { mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientAckAndDataPacket ( packet_num ++ , false , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , 1 , 1 , 1 , false , quiche :: QuicheStringPiece ( get_frame . data ( ) , get_frame . size ( ) ) ) ) ; } else { mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientAckAndDataPacket ( packet_num ++ , false , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , 1 , 1 , 1 , false , { header + std :: string ( get_frame . data ( ) , get_frame . size ( ) ) } ) ) ; } spdy :: SpdySerializedFrame resp_frame = spdy_util . ConstructSpdyGetReply ( nullptr , 0 , 1 ) ; std :: string header2 = ConstructDataHeader ( resp_frame . size ( ) ) ; mock_quic_data . AddRead ( ASYNC , ConstructServerDataPacket ( 2 , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , false , false , header2 + std :: string ( resp_frame . data ( ) , resp_frame . size ( ) ) ) ) ; spdy :: SpdySerializedFrame data_frame = spdy_util . ConstructSpdyDataFrame ( 1 , " " , true ) ; std :: string header3 = ConstructDataHeader ( resp_frame . size ( ) ) ; mock_quic_data . AddRead ( SYNCHRONOUS , ConstructServerDataPacket ( 3 , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , false , false , header3 + std :: string ( data_frame . data ( ) , data_frame . size ( ) ) ) ) ; 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_ ) ; SSLSocketDataProvider ssl_data ( ASYNC , OK ) ; ssl_data . next_proto = kProtoHTTP2 ; socket_factory_ . AddSSLSocketDataProvider ( & ssl_data ) ; CreateSession ( ) ; request_ . url = GURL ( " " ) ; HttpNetworkTransaction trans ( DEFAULT_PRIORITY , session_ . get ( ) ) ; RunTransaction ( & trans ) ; CheckWasSpdyResponse ( & 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 HTTP/2 request over QUIC proxy tunnel.
Performs an HTTP / 2 request over QUIC proxy tunnel .
// No more data to read // Causes MockSSLClientSocket to disconproxyconnecthttpnect, which causes the // underlying QUIC proxy socket to disconnect.