Chromium Code Reviews| 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/chromium/quic_stream_factory.h" | 5 #include "net/quic/chromium/quic_stream_factory.h" |
| 6 | 6 |
| 7 #include <ostream> | 7 #include <ostream> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 3318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3329 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get())); | 3329 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get())); |
| 3330 | 3330 |
| 3331 // Verify that QUIC stays disabled after a TCP job succeeds. | 3331 // Verify that QUIC stays disabled after a TCP job succeeds. |
| 3332 factory_->OnTcpJobCompleted(/*succeeded=*/false); | 3332 factory_->OnTcpJobCompleted(/*succeeded=*/false); |
| 3333 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get())); | 3333 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get())); |
| 3334 | 3334 |
| 3335 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 3335 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3336 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 3336 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3337 } | 3337 } |
| 3338 | 3338 |
| 3339 TEST_P(QuicStreamFactoryTest, | |
| 3340 DisableQuicWhenTimeoutsWithOpenStreamsExponentialBackoff) { | |
| 3341 disable_disk_cache_ = true; | |
| 3342 disable_quic_on_timeout_with_open_streams_ = true; | |
| 3343 Initialize(); | |
| 3344 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | |
| 3345 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | |
|
ianswett
2016/09/14 20:10:14
Any reason you're adding the ProofVerifyDetails tw
| |
| 3346 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | |
| 3347 QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); | |
| 3348 | |
| 3349 EXPECT_FALSE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get())); | |
| 3350 | |
| 3351 MockQuicData socket_data; | |
| 3352 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); | |
| 3353 socket_data.AddSocketDataToFactory(&socket_factory_); | |
| 3354 | |
| 3355 MockQuicData socket_data2; | |
| 3356 socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); | |
| 3357 socket_data2.AddSocketDataToFactory(&socket_factory_); | |
| 3358 | |
| 3359 crypto_client_stream_factory_.set_handshake_mode( | |
| 3360 MockCryptoClientStream::CONFIRM_HANDSHAKE); | |
| 3361 host_resolver_.set_synchronous_mode(true); | |
| 3362 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), | |
| 3363 "192.168.0.1", ""); | |
| 3364 | |
| 3365 // Test first timeouts with open streams will disable QUIC. | |
| 3366 QuicStreamRequest request(factory_.get()); | |
| 3367 EXPECT_EQ(OK, request.Request(host_port_pair_, privacy_mode_, | |
| 3368 /*cert_verify_flags=*/0, url_, "GET", net_log_, | |
| 3369 callback_.callback())); | |
| 3370 | |
| 3371 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); | |
| 3372 | |
| 3373 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); | |
| 3374 EXPECT_TRUE(stream.get()); | |
| 3375 HttpRequestInfo request_info; | |
| 3376 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, | |
| 3377 net_log_, CompletionCallback())); | |
| 3378 | |
| 3379 DVLOG(1) | |
| 3380 << "Created 1st session and initialized a stream. Now trigger timeout." | |
| 3381 << "Will disable QUIC."; | |
| 3382 session->connection()->CloseConnection(QUIC_NETWORK_IDLE_TIMEOUT, "test", | |
| 3383 ConnectionCloseBehavior::SILENT_CLOSE); | |
| 3384 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get())); | |
| 3385 | |
| 3386 ASSERT_EQ(1u, runner_->GetPostedTasks().size()); | |
| 3387 ASSERT_EQ(clock_->NowInTicks() + base::TimeDelta::FromMinutes(5), | |
| 3388 runner_->GetPostedTasks()[0].GetTimeToRun()); | |
| 3389 runner_->RunNextTask(); | |
| 3390 | |
| 3391 // Need to spin the loop now to ensure that | |
| 3392 // QuicStreamFactory::OnSessionClosed() runs. | |
| 3393 base::RunLoop run_loop; | |
| 3394 run_loop.RunUntilIdle(); | |
| 3395 | |
| 3396 EXPECT_FALSE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get())); | |
| 3397 | |
| 3398 ASSERT_TRUE(runner_->GetPostedTasks().empty()); | |
| 3399 | |
| 3400 // Create a new session which will cause a task to be posted to | |
| 3401 // clear the exponential backoff. | |
| 3402 QuicStreamRequest request2(factory_.get()); | |
| 3403 EXPECT_EQ(OK, request2.Request(host_port_pair_, privacy_mode_, | |
| 3404 /*cert_verify_flags=*/0, url_, "GET", net_log_, | |
| 3405 callback_.callback())); | |
| 3406 QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); | |
| 3407 std::unique_ptr<QuicHttpStream> stream2 = request2.CreateStream(); | |
| 3408 EXPECT_TRUE(stream2.get()); | |
| 3409 HttpRequestInfo request_info2; | |
| 3410 EXPECT_EQ(OK, stream2->InitializeStream(&request_info2, DEFAULT_PRIORITY, | |
| 3411 net_log_, CompletionCallback())); | |
| 3412 | |
| 3413 // Check that the clear task has been posted. | |
| 3414 ASSERT_EQ(1u, runner_->GetPostedTasks().size()); | |
| 3415 ASSERT_EQ(clock_->NowInTicks() + base::TimeDelta::FromMinutes(5), | |
| 3416 runner_->GetPostedTasks()[0].GetTimeToRun()); | |
| 3417 | |
| 3418 session2->connection()->CloseConnection( | |
| 3419 QUIC_NETWORK_IDLE_TIMEOUT, "test", ConnectionCloseBehavior::SILENT_CLOSE); | |
| 3420 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get())); | |
| 3421 | |
| 3422 ASSERT_EQ(2u, runner_->GetPostedTasks().size()); | |
| 3423 ASSERT_EQ(clock_->NowInTicks() + base::TimeDelta::FromMinutes(10), | |
| 3424 runner_->GetPostedTasks()[1].GetTimeToRun()); | |
| 3425 runner_->RunNextTask(); | |
| 3426 | |
| 3427 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get())); | |
| 3428 | |
| 3429 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
| 3430 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
| 3431 } | |
| 3432 | |
| 3433 TEST_P(QuicStreamFactoryTest, | |
| 3434 DisableQuicWhenTimeoutsWithOpenStreamsExponentialBackoffReset) { | |
| 3435 disable_disk_cache_ = true; | |
| 3436 disable_quic_on_timeout_with_open_streams_ = true; | |
| 3437 Initialize(); | |
| 3438 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | |
| 3439 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | |
| 3440 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | |
| 3441 QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); | |
| 3442 | |
| 3443 EXPECT_FALSE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get())); | |
| 3444 | |
| 3445 MockQuicData socket_data; | |
| 3446 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); | |
| 3447 socket_data.AddSocketDataToFactory(&socket_factory_); | |
| 3448 | |
| 3449 MockQuicData socket_data2; | |
| 3450 socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); | |
| 3451 socket_data2.AddSocketDataToFactory(&socket_factory_); | |
| 3452 | |
| 3453 crypto_client_stream_factory_.set_handshake_mode( | |
| 3454 MockCryptoClientStream::CONFIRM_HANDSHAKE); | |
| 3455 host_resolver_.set_synchronous_mode(true); | |
| 3456 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), | |
| 3457 "192.168.0.1", ""); | |
| 3458 | |
| 3459 // Test first timeouts with open streams will disable QUIC. | |
| 3460 QuicStreamRequest request(factory_.get()); | |
| 3461 EXPECT_EQ(OK, request.Request(host_port_pair_, privacy_mode_, | |
| 3462 /*cert_verify_flags=*/0, url_, "GET", net_log_, | |
| 3463 callback_.callback())); | |
| 3464 | |
| 3465 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); | |
| 3466 | |
| 3467 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); | |
| 3468 EXPECT_TRUE(stream.get()); | |
| 3469 HttpRequestInfo request_info; | |
| 3470 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, | |
| 3471 net_log_, CompletionCallback())); | |
| 3472 | |
| 3473 DVLOG(1) | |
| 3474 << "Created 1st session and initialized a stream. Now trigger timeout." | |
| 3475 << "Will disable QUIC."; | |
| 3476 session->connection()->CloseConnection(QUIC_NETWORK_IDLE_TIMEOUT, "test", | |
| 3477 ConnectionCloseBehavior::SILENT_CLOSE); | |
| 3478 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get())); | |
| 3479 | |
| 3480 ASSERT_EQ(1u, runner_->GetPostedTasks().size()); | |
| 3481 ASSERT_EQ(clock_->NowInTicks() + base::TimeDelta::FromMinutes(5), | |
| 3482 runner_->GetPostedTasks()[0].GetTimeToRun()); | |
| 3483 runner_->RunNextTask(); | |
| 3484 | |
| 3485 // Need to spin the loop now to ensure that | |
| 3486 // QuicStreamFactory::OnSessionClosed() runs. | |
| 3487 base::RunLoop run_loop; | |
| 3488 run_loop.RunUntilIdle(); | |
| 3489 | |
| 3490 EXPECT_FALSE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get())); | |
| 3491 | |
| 3492 ASSERT_TRUE(runner_->GetPostedTasks().empty()); | |
| 3493 | |
| 3494 // Create a new session which will cause a task to be posted to | |
| 3495 // clear the exponential backoff. | |
| 3496 QuicStreamRequest request2(factory_.get()); | |
| 3497 EXPECT_EQ(OK, request2.Request(host_port_pair_, privacy_mode_, | |
| 3498 /*cert_verify_flags=*/0, url_, "GET", net_log_, | |
| 3499 callback_.callback())); | |
| 3500 QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); | |
| 3501 std::unique_ptr<QuicHttpStream> stream2 = request2.CreateStream(); | |
| 3502 EXPECT_TRUE(stream2.get()); | |
| 3503 HttpRequestInfo request_info2; | |
| 3504 EXPECT_EQ(OK, stream2->InitializeStream(&request_info2, DEFAULT_PRIORITY, | |
| 3505 net_log_, CompletionCallback())); | |
| 3506 | |
| 3507 // Run the clear task and verify that the next disabling is | |
| 3508 // back to the default timeout. | |
| 3509 runner_->RunNextTask(); | |
| 3510 | |
| 3511 // QUIC should still be enabled. | |
| 3512 EXPECT_FALSE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get())); | |
| 3513 | |
| 3514 session2->connection()->CloseConnection( | |
| 3515 QUIC_NETWORK_IDLE_TIMEOUT, "test", ConnectionCloseBehavior::SILENT_CLOSE); | |
| 3516 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get())); | |
| 3517 | |
| 3518 ASSERT_EQ(1u, runner_->GetPostedTasks().size()); | |
| 3519 ASSERT_EQ(clock_->NowInTicks() + base::TimeDelta::FromMinutes(5), | |
| 3520 runner_->GetPostedTasks()[0].GetTimeToRun()); | |
| 3521 runner_->RunNextTask(); | |
| 3522 | |
| 3523 EXPECT_FALSE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get())); | |
| 3524 | |
| 3525 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
| 3526 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
| 3527 } | |
| 3528 | |
| 3339 TEST_P(QuicStreamFactoryTest, EnableDelayTcpRace) { | 3529 TEST_P(QuicStreamFactoryTest, EnableDelayTcpRace) { |
| 3340 Initialize(); | 3530 Initialize(); |
| 3341 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 3531 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3342 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 3532 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3343 bool delay_tcp_race = QuicStreamFactoryPeer::GetDelayTcpRace(factory_.get()); | 3533 bool delay_tcp_race = QuicStreamFactoryPeer::GetDelayTcpRace(factory_.get()); |
| 3344 QuicStreamFactoryPeer::SetDelayTcpRace(factory_.get(), false); | 3534 QuicStreamFactoryPeer::SetDelayTcpRace(factory_.get(), false); |
| 3345 MockQuicData socket_data; | 3535 MockQuicData socket_data; |
| 3346 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); | 3536 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3347 socket_data.AddSocketDataToFactory(&socket_factory_); | 3537 socket_data.AddSocketDataToFactory(&socket_factory_); |
| 3348 | 3538 |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4208 // Clear all cached states. | 4398 // Clear all cached states. |
| 4209 factory_->ClearCachedStatesInCryptoConfig( | 4399 factory_->ClearCachedStatesInCryptoConfig( |
| 4210 base::Callback<bool(const GURL&)>()); | 4400 base::Callback<bool(const GURL&)>()); |
| 4211 EXPECT_TRUE(test_cases[0].state->certs().empty()); | 4401 EXPECT_TRUE(test_cases[0].state->certs().empty()); |
| 4212 EXPECT_TRUE(test_cases[1].state->certs().empty()); | 4402 EXPECT_TRUE(test_cases[1].state->certs().empty()); |
| 4213 EXPECT_TRUE(test_cases[2].state->certs().empty()); | 4403 EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 4214 } | 4404 } |
| 4215 | 4405 |
| 4216 } // namespace test | 4406 } // namespace test |
| 4217 } // namespace net | 4407 } // namespace net |
| OLD | NEW |