src/net/quic/quic_network_transaction_unittest.cc
// Pool to existing session with matching destination and matching certificate
// even if origin is different, and even if the alternative service with
// matching destination is not the first one on the list.
Pool to existing session with matching destination and matching certificate
even if origin is different, and even if the alternative service with
matching destination is not the first one on the list.
Pool to existing session with matching destination and matching certificate even if origin is different and even if the alternative service with matching destination is not the first one on the list .
TEST_P(QuicNetworkTransactionTest, PoolByDestination) {
  context_.params()->allow_remote_alt_svc = true;
  GURL origin1 = request_.url;
  GURL origin2("https://www.example.org/");
  ASSERT_NE(origin1.host(), origin2.host());
  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", "https", "/")));
  mock_quic_data.AddRead(
      ASYNC, ConstructServerResponseHeadersPacket(
                 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false,
                 GetResponseHeaders("200 OK")));
  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));
  QuicTestPacketMaker client_maker2(
      version_,
      quic::QuicUtils::CreateRandomConnectionId(context_.random_generator()),
      context_.clock(), origin2.host(), quic::Perspective::IS_CLIENT,
      client_headers_include_h2_stream_dependency_);
  QuicTestPacketMaker server_maker2(
      version_,
      quic::QuicUtils::CreateRandomConnectionId(context_.random_generator()),
      context_.clock(), origin2.host(), quic::Perspective::IS_SERVER, false);
  mock_quic_data.AddWrite(
      SYNCHRONOUS,
      ConstructClientRequestHeadersPacket(
          packet_num++, GetNthClientInitiatedBidirectionalStreamId(1), false,
          true, GetRequestHeaders("GET", "https", "/", &client_maker2),
          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();
  AddHangingNonAlternateProtocolSocketData();
  CreateSession();
  QuicStreamFactoryPeer::SetAlarmFactory(
      session_->quic_stream_factory(),
      std::make_unique<QuicChromiumAlarmFactory>(quic_task_runner_.get(),
                                                 context_.clock()));
  const char destination1[] = "first.example.com";
  const char destination2[] = "second.example.com";
  AlternativeService alternative_service1(kProtoQUIC, destination1, 443);
  base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
  http_server_properties_->SetQuicAlternativeService(
      url::SchemeHostPort(origin1), NetworkIsolationKey(), alternative_service1,
      expiration, supported_versions_);
  AlternativeService alternative_service2(kProtoQUIC, destination2, 443);
  AlternativeServiceInfoVector alternative_services;
  alternative_services.push_back(
      AlternativeServiceInfo::CreateQuicAlternativeServiceInfo(
          alternative_service2, expiration,
          context_.params()->supported_versions));
  alternative_services.push_back(
      AlternativeServiceInfo::CreateQuicAlternativeServiceInfo(
          alternative_service1, expiration,
          context_.params()->supported_versions));
  http_server_properties_->SetAlternativeServices(url::SchemeHostPort(origin2),
                                                  NetworkIsolationKey(),
                                                  alternative_services);
  SendRequestAndExpectQuicResponse("hello!");
  request_.url = origin2;
  SendRequestAndExpectQuicResponse("hello!");
}
TEST_P ( QuicNetworkTransactionTest , PoolByDestination ) { context_ . params ( ) -> allow_remote_alt_svc = true ; GURL origin1 = request_ . url ; GURL origin2 ( " " ) ; ASSERT_NE ( origin1 . host ( ) , origin2 . host ( ) ) ; 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 ( " " , " " , " " ) ) ) ; mock_quic_data . AddRead ( ASYNC , ConstructServerResponseHeadersPacket ( 1 , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , false , false , GetResponseHeaders ( " " ) ) ) ; 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 ) ) ; QuicTestPacketMaker client_maker2 ( version_ , quic :: QuicUtils :: CreateRandomConnectionId ( context_ . random_generator ( ) ) , context_ . clock ( ) , origin2 . host ( ) , quic :: Perspective :: IS_CLIENT , client_headers_include_h2_stream_dependency_ ) ; QuicTestPacketMaker server_maker2 ( version_ , quic :: QuicUtils :: CreateRandomConnectionId ( context_ . random_generator ( ) ) , context_ . clock ( ) , origin2 . host ( ) , quic :: Perspective :: IS_SERVER , false ) ; mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientRequestHeadersPacket ( packet_num ++ , GetNthClientInitiatedBidirectionalStreamId ( 1 ) , false , true , GetRequestHeaders ( " " , " " , " " , & client_maker2 ) , 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 ( ) ; AddHangingNonAlternateProtocolSocketData ( ) ; CreateSession ( ) ; QuicStreamFactoryPeer :: SetAlarmFactory ( session_ -> quic_stream_factory ( ) , std :: make_unique < QuicChromiumAlarmFactory > ( quic_task_runner_ . get ( ) , context_ . clock ( ) ) ) ; const char destination1 [ ] = " " ; const char destination2 [ ] = " " ; AlternativeService alternative_service1 ( kProtoQUIC , destination1 , 443 ) ; base :: Time expiration = base :: Time :: Now ( ) + base :: TimeDelta :: FromDays ( 1 ) ; http_server_properties_ -> SetQuicAlternativeService ( url :: SchemeHostPort ( origin1 ) , NetworkIsolationKey ( ) , alternative_service1 , expiration , supported_versions_ ) ; AlternativeService alternative_service2 ( kProtoQUIC , destination2 , 443 ) ; AlternativeServiceInfoVector alternative_services ; alternative_services . push_back ( AlternativeServiceInfo :: CreateQuicAlternativeServiceInfo ( alternative_service2 , expiration , context_ . params ( ) -> supported_versions ) ) ; alternative_services . push_back ( AlternativeServiceInfo :: CreateQuicAlternativeServiceInfo ( alternative_service1 , expiration , context_ . params ( ) -> supported_versions ) ) ; http_server_properties_ -> SetAlternativeServices ( url :: SchemeHostPort ( origin2 ) , NetworkIsolationKey ( ) , alternative_services ) ; SendRequestAndExpectQuicResponse ( " " ) ; request_ . url = origin2 ; SendRequestAndExpectQuicResponse ( " " ) ; }
Pool to existing session with matching destination and matching certificate
even if origin is different, and even if the alternative service with
matching destination is not the first one on the list.
Pool to existing session with matching destination and matching certificate even if origin is different and even if the alternative service with matching destination is not the first one on the list .
// First request. // Second request. // No more data to read // EOF // Set up alternative service for |origin1|. // Set up multiple alternative service entries for |origin2|, // the first one with a different destination as for |origin1|, // the second one with the same.  The second one should be used, // because the request can be pooled to that one. // First request opens connection to |destination1| // with quic::QuicServerId.host() == origin1.host(). // Second request pools to existing connection with same destination, // because certificate matches, even though quic::QuicServerId is different.