OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "net/base/test_data_directory.h" | 10 #include "net/base/test_data_directory.h" |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 enable_connection_racing_(GetParam().enable_connection_racing), | 219 enable_connection_racing_(GetParam().enable_connection_racing), |
220 enable_non_blocking_io_(true), | 220 enable_non_blocking_io_(true), |
221 disable_disk_cache_(false), | 221 disable_disk_cache_(false), |
222 prefer_aes_(false), | 222 prefer_aes_(false), |
223 max_number_of_lossy_connections_(0), | 223 max_number_of_lossy_connections_(0), |
224 packet_loss_threshold_(1.0f), | 224 packet_loss_threshold_(1.0f), |
225 max_disabled_reasons_(3), | 225 max_disabled_reasons_(3), |
226 threshold_timeouts_with_open_streams_(2), | 226 threshold_timeouts_with_open_streams_(2), |
227 threshold_public_resets_post_handshake_(2), | 227 threshold_public_resets_post_handshake_(2), |
228 receive_buffer_size_(0), | 228 receive_buffer_size_(0), |
| 229 delay_tcp_race_(false), |
229 close_sessions_on_ip_change_(false), | 230 close_sessions_on_ip_change_(false), |
230 disable_quic_on_timeout_with_open_streams_(false), | 231 disable_quic_on_timeout_with_open_streams_(false), |
231 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), | 232 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), |
232 migrate_sessions_on_network_change_(false), | 233 migrate_sessions_on_network_change_(false), |
233 migrate_sessions_early_(false) { | 234 migrate_sessions_early_(false) { |
234 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 235 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
235 } | 236 } |
236 | 237 |
237 void Initialize() { | 238 void Initialize() { |
238 factory_.reset(new QuicStreamFactory( | 239 factory_.reset(new QuicStreamFactory( |
239 &host_resolver_, &socket_factory_, http_server_properties_.GetWeakPtr(), | 240 &host_resolver_, &socket_factory_, http_server_properties_.GetWeakPtr(), |
240 cert_verifier_.get(), nullptr, channel_id_service_.get(), | 241 cert_verifier_.get(), nullptr, channel_id_service_.get(), |
241 &transport_security_state_, cert_transparency_verifier_.get(), | 242 &transport_security_state_, cert_transparency_verifier_.get(), |
242 /*SocketPerformanceWatcherFactory*/ nullptr, | 243 /*SocketPerformanceWatcherFactory*/ nullptr, |
243 &crypto_client_stream_factory_, &random_generator_, clock_, | 244 &crypto_client_stream_factory_, &random_generator_, clock_, |
244 kDefaultMaxPacketSize, std::string(), | 245 kDefaultMaxPacketSize, std::string(), |
245 SupportedVersions(GetParam().version), enable_port_selection_, | 246 SupportedVersions(GetParam().version), enable_port_selection_, |
246 always_require_handshake_confirmation_, disable_connection_pooling_, | 247 always_require_handshake_confirmation_, disable_connection_pooling_, |
247 load_server_info_timeout_srtt_multiplier_, enable_connection_racing_, | 248 load_server_info_timeout_srtt_multiplier_, enable_connection_racing_, |
248 enable_non_blocking_io_, disable_disk_cache_, prefer_aes_, | 249 enable_non_blocking_io_, disable_disk_cache_, prefer_aes_, |
249 max_number_of_lossy_connections_, packet_loss_threshold_, | 250 max_number_of_lossy_connections_, packet_loss_threshold_, |
250 max_disabled_reasons_, threshold_timeouts_with_open_streams_, | 251 max_disabled_reasons_, threshold_timeouts_with_open_streams_, |
251 threshold_public_resets_post_handshake_, receive_buffer_size_, | 252 threshold_public_resets_post_handshake_, receive_buffer_size_, |
252 /*max_server_configs_stored_in_properties*/ 0, | 253 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, |
253 close_sessions_on_ip_change_, | 254 close_sessions_on_ip_change_, |
254 disable_quic_on_timeout_with_open_streams_, | 255 disable_quic_on_timeout_with_open_streams_, |
255 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, | 256 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, |
256 migrate_sessions_early_, QuicTagVector(), | 257 migrate_sessions_early_, QuicTagVector(), |
257 /*enable_token_binding*/ false)); | 258 /*enable_token_binding*/ false)); |
258 factory_->set_require_confirmation(false); | 259 factory_->set_require_confirmation(false); |
259 EXPECT_FALSE(factory_->has_quic_server_info_factory()); | 260 EXPECT_FALSE(factory_->has_quic_server_info_factory()); |
260 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); | 261 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); |
261 EXPECT_TRUE(factory_->has_quic_server_info_factory()); | 262 EXPECT_TRUE(factory_->has_quic_server_info_factory()); |
262 } | 263 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 bool enable_connection_racing_; | 430 bool enable_connection_racing_; |
430 bool enable_non_blocking_io_; | 431 bool enable_non_blocking_io_; |
431 bool disable_disk_cache_; | 432 bool disable_disk_cache_; |
432 bool prefer_aes_; | 433 bool prefer_aes_; |
433 int max_number_of_lossy_connections_; | 434 int max_number_of_lossy_connections_; |
434 double packet_loss_threshold_; | 435 double packet_loss_threshold_; |
435 int max_disabled_reasons_; | 436 int max_disabled_reasons_; |
436 int threshold_timeouts_with_open_streams_; | 437 int threshold_timeouts_with_open_streams_; |
437 int threshold_public_resets_post_handshake_; | 438 int threshold_public_resets_post_handshake_; |
438 int receive_buffer_size_; | 439 int receive_buffer_size_; |
| 440 bool delay_tcp_race_; |
439 bool close_sessions_on_ip_change_; | 441 bool close_sessions_on_ip_change_; |
440 bool disable_quic_on_timeout_with_open_streams_; | 442 bool disable_quic_on_timeout_with_open_streams_; |
441 int idle_connection_timeout_seconds_; | 443 int idle_connection_timeout_seconds_; |
442 bool migrate_sessions_on_network_change_; | 444 bool migrate_sessions_on_network_change_; |
443 bool migrate_sessions_early_; | 445 bool migrate_sessions_early_; |
444 }; | 446 }; |
445 | 447 |
446 INSTANTIATE_TEST_CASE_P(Version, | 448 INSTANTIATE_TEST_CASE_P(Version, |
447 QuicStreamFactoryTest, | 449 QuicStreamFactoryTest, |
448 ::testing::ValuesIn(GetTestParams())); | 450 ::testing::ValuesIn(GetTestParams())); |
(...skipping 3215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3664 EXPECT_TRUE(socket_data3.AllReadDataConsumed()); | 3666 EXPECT_TRUE(socket_data3.AllReadDataConsumed()); |
3665 EXPECT_TRUE(socket_data3.AllWriteDataConsumed()); | 3667 EXPECT_TRUE(socket_data3.AllWriteDataConsumed()); |
3666 EXPECT_TRUE(socket_data4.AllReadDataConsumed()); | 3668 EXPECT_TRUE(socket_data4.AllReadDataConsumed()); |
3667 EXPECT_TRUE(socket_data4.AllWriteDataConsumed()); | 3669 EXPECT_TRUE(socket_data4.AllWriteDataConsumed()); |
3668 } | 3670 } |
3669 | 3671 |
3670 TEST_P(QuicStreamFactoryTest, EnableDelayTcpRace) { | 3672 TEST_P(QuicStreamFactoryTest, EnableDelayTcpRace) { |
3671 Initialize(); | 3673 Initialize(); |
3672 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 3674 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
3673 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 3675 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3676 bool delay_tcp_race = QuicStreamFactoryPeer::GetDelayTcpRace(factory_.get()); |
| 3677 QuicStreamFactoryPeer::SetDelayTcpRace(factory_.get(), false); |
3674 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | 3678 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
3675 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0); | 3679 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0); |
3676 socket_factory_.AddSocketDataProvider(&socket_data); | 3680 socket_factory_.AddSocketDataProvider(&socket_data); |
3677 | 3681 |
3678 ServerNetworkStats stats1; | 3682 ServerNetworkStats stats1; |
3679 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 3683 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
3680 url::SchemeHostPort server("https", kDefaultServerHostName, | 3684 url::SchemeHostPort server("https", kDefaultServerHostName, |
3681 kDefaultServerPort); | 3685 kDefaultServerPort); |
3682 http_server_properties_.SetServerNetworkStats(server, stats1); | 3686 http_server_properties_.SetServerNetworkStats(server, stats1); |
3683 | 3687 |
3684 crypto_client_stream_factory_.set_handshake_mode( | 3688 crypto_client_stream_factory_.set_handshake_mode( |
3685 MockCryptoClientStream::ZERO_RTT); | 3689 MockCryptoClientStream::ZERO_RTT); |
3686 host_resolver_.set_synchronous_mode(true); | 3690 host_resolver_.set_synchronous_mode(true); |
3687 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), | 3691 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), |
3688 "192.168.0.1", ""); | 3692 "192.168.0.1", ""); |
3689 | 3693 |
3690 QuicStreamRequest request(factory_.get()); | 3694 QuicStreamRequest request(factory_.get()); |
3691 EXPECT_EQ(ERR_IO_PENDING, | 3695 EXPECT_EQ(ERR_IO_PENDING, |
3692 request.Request(host_port_pair_, privacy_mode_, | 3696 request.Request(host_port_pair_, privacy_mode_, |
3693 /*cert_verify_flags=*/0, url_, "POST", net_log_, | 3697 /*cert_verify_flags=*/0, url_, "POST", net_log_, |
3694 callback_.callback())); | 3698 callback_.callback())); |
3695 | 3699 |
| 3700 // If we don't delay TCP connection, then time delay should be 0. |
| 3701 EXPECT_FALSE(factory_->delay_tcp_race()); |
| 3702 EXPECT_EQ(base::TimeDelta(), request.GetTimeDelayForWaitingJob()); |
| 3703 |
| 3704 // Enable |delay_tcp_race_| param and verify delay is one RTT and that |
| 3705 // server supports QUIC. |
| 3706 QuicStreamFactoryPeer::SetDelayTcpRace(factory_.get(), true); |
| 3707 EXPECT_TRUE(factory_->delay_tcp_race()); |
3696 EXPECT_EQ(base::TimeDelta::FromMicroseconds(15), | 3708 EXPECT_EQ(base::TimeDelta::FromMicroseconds(15), |
3697 request.GetTimeDelayForWaitingJob()); | 3709 request.GetTimeDelayForWaitingJob()); |
3698 | 3710 |
3699 // Confirm the handshake and verify that the stream is created. | 3711 // Confirm the handshake and verify that the stream is created. |
3700 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( | 3712 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
3701 QuicSession::HANDSHAKE_CONFIRMED); | 3713 QuicSession::HANDSHAKE_CONFIRMED); |
3702 | 3714 |
3703 EXPECT_EQ(OK, callback_.WaitForResult()); | 3715 EXPECT_EQ(OK, callback_.WaitForResult()); |
3704 | 3716 |
3705 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); | 3717 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); |
3706 EXPECT_TRUE(stream.get()); | 3718 EXPECT_TRUE(stream.get()); |
3707 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 3719 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
3708 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 3720 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3721 QuicStreamFactoryPeer::SetDelayTcpRace(factory_.get(), delay_tcp_race); |
3709 } | 3722 } |
3710 | 3723 |
3711 TEST_P(QuicStreamFactoryTest, MaybeInitialize) { | 3724 TEST_P(QuicStreamFactoryTest, MaybeInitialize) { |
3712 idle_connection_timeout_seconds_ = 500; | 3725 idle_connection_timeout_seconds_ = 500; |
3713 Initialize(); | 3726 Initialize(); |
3714 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 3727 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
3715 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 3728 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
3716 const QuicConfig* config = QuicStreamFactoryPeer::GetConfig(factory_.get()); | 3729 const QuicConfig* config = QuicStreamFactoryPeer::GetConfig(factory_.get()); |
3717 EXPECT_EQ(500, config->IdleConnectionStateLifetime().ToSeconds()); | 3730 EXPECT_EQ(500, config->IdleConnectionStateLifetime().ToSeconds()); |
3718 | 3731 |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4082 EXPECT_TRUE(stream2.get()); | 4095 EXPECT_TRUE(stream2.get()); |
4083 | 4096 |
4084 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); | 4097 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
4085 EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); | 4098 EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
4086 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); | 4099 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
4087 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); | 4100 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
4088 } | 4101 } |
4089 | 4102 |
4090 } // namespace test | 4103 } // namespace test |
4091 } // namespace net | 4104 } // namespace net |
OLD | NEW |