src/net/quic/quic_network_transaction_unittest.cc
// Check that an existing QUIC connection to an alternative proxy server is
// used.
Check that an existing QUIC connection to an alternative proxy server is
used.
Check that an existing QUIC connection to an alternative proxy server is used .
TEST_P(QuicNetworkTransactionTest, UseExistingQUICAlternativeProxy) {
  base::HistogramTester histogram_tester;
  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,
      ConstructClientRequestHeadersPacket(
          packet_num++, GetNthClientInitiatedBidirectionalStreamId(0), true,
          true, GetRequestHeaders("GET", "http", "/")));
  std::string alt_svc_list;
  mock_quic_data.AddRead(
      ASYNC, ConstructServerResponseHeadersPacket(
                 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false,
                 GetResponseHeaders("200 OK", alt_svc_list)));
  std::string header = ConstructDataHeader(6);
  mock_quic_data.AddRead(
      ASYNC, ConstructServerDataPacket(
                 2, GetNthClientInitiatedBidirectionalStreamId(0), false, true,
                 header + "hello!"));
  mock_quic_data.AddWrite(SYNCHRONOUS,
                          ConstructClientAckPacket(packet_num++, 2, 1, 1));
  mock_quic_data.AddWrite(
      SYNCHRONOUS,
      ConstructClientRequestHeadersPacket(
          packet_num++, GetNthClientInitiatedBidirectionalStreamId(1), false,
          true, GetRequestHeaders("GET", "http", "/"),
          GetNthClientInitiatedBidirectionalStreamId(0)));
  mock_quic_data.AddRead(
      ASYNC, ConstructServerResponseHeadersPacket(
                 3, GetNthClientInitiatedBidirectionalStreamId(1), false, false,
                 GetResponseHeaders("200 OK")));
  mock_quic_data.AddRead(
      ASYNC, ConstructServerDataPacket(
                 4, GetNthClientInitiatedBidirectionalStreamId(1), false, true,
                 header + "hello!"));
  mock_quic_data.AddWrite(
      SYNCHRONOUS,
      ConstructClientAckAndConnectionClosePacket(packet_num++, 4, 3, 1));
  mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING);  
  mock_quic_data.AddRead(ASYNC, 0);               
  mock_quic_data.AddSocketDataToFactory(&socket_factory_);
  AddHangingNonAlternateProtocolSocketData();
  TestProxyDelegate test_proxy_delegate;
  proxy_resolution_service_ =
      ConfiguredProxyResolutionService::CreateFixedFromPacResult(
          "HTTPS mail.example.org:443", TRAFFIC_ANNOTATION_FOR_TESTS);
  test_proxy_delegate.set_alternative_proxy_server(
      ProxyServer::FromPacString("QUIC mail.example.org:443"));
  proxy_resolution_service_->SetProxyDelegate(&test_proxy_delegate);
  request_.url = GURL("http://mail.example.org/");
  CreateSession();
  QuicStreamFactoryPeer::SetAlarmFactory(
      session_->quic_stream_factory(),
      std::make_unique<QuicChromiumAlarmFactory>(quic_task_runner_.get(),
                                                 context_.clock()));
  SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 443);
  histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage",
                                      1 ,
                                      1);
  SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 443);
  histogram_tester.ExpectTotalCount("Net.QuicAlternativeProxy.Usage", 2);
  histogram_tester.ExpectBucketCount("Net.QuicAlternativeProxy.Usage",
                                     0 ,
                                     1);
}
TEST_P ( QuicNetworkTransactionTest , UseExistingQUICAlternativeProxy ) { base :: HistogramTester histogram_tester ; 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 , ConstructClientRequestHeadersPacket ( packet_num ++ , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , true , true , GetRequestHeaders ( " " , " " , " " ) ) ) ; std :: string alt_svc_list ; mock_quic_data . AddRead ( ASYNC , ConstructServerResponseHeadersPacket ( 1 , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , false , false , GetResponseHeaders ( " " , alt_svc_list ) ) ) ; std :: string header = ConstructDataHeader ( 6 ) ; mock_quic_data . AddRead ( ASYNC , ConstructServerDataPacket ( 2 , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , false , true , header + " " ) ) ; mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientAckPacket ( packet_num ++ , 2 , 1 , 1 ) ) ; mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientRequestHeadersPacket ( packet_num ++ , GetNthClientInitiatedBidirectionalStreamId ( 1 ) , false , true , GetRequestHeaders ( " " , " " , " " ) , GetNthClientInitiatedBidirectionalStreamId ( 0 ) ) ) ; mock_quic_data . AddRead ( ASYNC , ConstructServerResponseHeadersPacket ( 3 , GetNthClientInitiatedBidirectionalStreamId ( 1 ) , false , false , GetResponseHeaders ( " " ) ) ) ; mock_quic_data . AddRead ( ASYNC , ConstructServerDataPacket ( 4 , GetNthClientInitiatedBidirectionalStreamId ( 1 ) , false , true , header + " " ) ) ; mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientAckAndConnectionClosePacket ( packet_num ++ , 4 , 3 , 1 ) ) ; mock_quic_data . AddRead ( ASYNC , ERR_IO_PENDING ) ; mock_quic_data . AddRead ( ASYNC , 0 ) ; mock_quic_data . AddSocketDataToFactory ( & socket_factory_ ) ; AddHangingNonAlternateProtocolSocketData ( ) ; TestProxyDelegate test_proxy_delegate ; proxy_resolution_service_ = ConfiguredProxyResolutionService :: CreateFixedFromPacResult ( " " , TRAFFIC_ANNOTATION_FOR_TESTS ) ; test_proxy_delegate . set_alternative_proxy_server ( ProxyServer :: FromPacString ( " " ) ) ; proxy_resolution_service_ -> SetProxyDelegate ( & test_proxy_delegate ) ; request_ . url = GURL ( " " ) ; CreateSession ( ) ; QuicStreamFactoryPeer :: SetAlarmFactory ( session_ -> quic_stream_factory ( ) , std :: make_unique < QuicChromiumAlarmFactory > ( quic_task_runner_ . get ( ) , context_ . clock ( ) ) ) ; SendRequestAndExpectQuicResponseFromProxyOnPort ( " " , 443 ) ; histogram_tester . ExpectUniqueSample ( " " , 1 , 1 ) ; SendRequestAndExpectQuicResponseFromProxyOnPort ( " " , 443 ) ; histogram_tester . ExpectTotalCount ( " " , 2 ) ; histogram_tester . ExpectBucketCount ( " " , 0 , 1 ) ; }
Check that an existing QUIC connection to an alternative proxy server is
used.
Check that an existing QUIC connection to an alternative proxy server is used .
// First QUIC request data. // Open a session to foo.example.org:443 using the first entry of the // alternative service list. // Second QUIC request data. // Connection pooling, using existing session, no need to include version // as version negotiation has been completed. // No more data to read // EOF /* ALTERNATIVE_PROXY_USAGE_WON_RACE */ /* ALTERNATIVE_PROXY_USAGE_NO_RACE */