| 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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 << " " << actual_address.port(); | 500 << " " << actual_address.port(); |
| 501 DVLOG(1) << "Expected address: " << expected_address.address().ToString() | 501 DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 502 << " " << expected_address.port(); | 502 << " " << expected_address.port(); |
| 503 | 503 |
| 504 stream.reset(); | 504 stream.reset(); |
| 505 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); | 505 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 506 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); | 506 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 507 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); | 507 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 508 } | 508 } |
| 509 | 509 |
| 510 // Helper methods for tests of connection migration on write error. |
| 511 void MigrateSessionOnWriteErrorNonMigratableStream(IoMode mode); |
| 512 void MigrateSessionOnWriteErrorMigrationDisabled(IoMode mode); |
| 513 void MigrateSessionOnWriteError(IoMode mode); |
| 514 void MigrateSessionOnWriteErrorNoNewNetwork(IoMode mode); |
| 515 void MigrateSessionOnMultipleWriteErrors(IoMode mode1, IoMode mode2); |
| 516 void MigrateSessionOnWriteErrorWithNotificationQueued(bool disconnected); |
| 517 |
| 510 MockHostResolver host_resolver_; | 518 MockHostResolver host_resolver_; |
| 511 scoped_refptr<SSLConfigService> ssl_config_service_; | 519 scoped_refptr<SSLConfigService> ssl_config_service_; |
| 512 MockClientSocketFactory socket_factory_; | 520 MockClientSocketFactory socket_factory_; |
| 513 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 521 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
| 514 MockRandom random_generator_; | 522 MockRandom random_generator_; |
| 515 MockClock* clock_; // Owned by |factory_| once created. | 523 MockClock* clock_; // Owned by |factory_| once created. |
| 516 scoped_refptr<TestTaskRunner> runner_; | 524 scoped_refptr<TestTaskRunner> runner_; |
| 517 QuicVersion version_; | 525 QuicVersion version_; |
| 518 QuicTestPacketMaker client_maker_; | 526 QuicTestPacketMaker client_maker_; |
| 519 QuicTestPacketMaker server_maker_; | 527 QuicTestPacketMaker server_maker_; |
| (...skipping 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2405 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | 2413 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2406 EXPECT_TRUE(HasActiveSession(host_port_pair_)); | 2414 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2407 EXPECT_EQ(1u, session->GetNumActiveStreams()); | 2415 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2408 | 2416 |
| 2409 stream.reset(); | 2417 stream.reset(); |
| 2410 | 2418 |
| 2411 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 2419 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2412 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 2420 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2413 } | 2421 } |
| 2414 | 2422 |
| 2415 TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteError) { | 2423 TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorSynchronous) { |
| 2424 MigrateSessionOnWriteError(SYNCHRONOUS); |
| 2425 } |
| 2426 |
| 2427 TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorAsync) { |
| 2428 MigrateSessionOnWriteError(ASYNC); |
| 2429 } |
| 2430 |
| 2431 void QuicStreamFactoryTestBase::MigrateSessionOnWriteError(IoMode mode) { |
| 2416 InitializeConnectionMigrationTest( | 2432 InitializeConnectionMigrationTest( |
| 2417 {kDefaultNetworkForTests, kNewNetworkForTests}); | 2433 {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2418 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 2434 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2419 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 2435 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2420 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 2436 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2421 | 2437 |
| 2422 MockQuicData socket_data; | 2438 MockQuicData socket_data; |
| 2423 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); | 2439 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2424 socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); | 2440 socket_data.AddWrite(mode, ERR_ADDRESS_UNREACHABLE); |
| 2425 socket_data.AddSocketDataToFactory(&socket_factory_); | 2441 socket_data.AddSocketDataToFactory(&socket_factory_); |
| 2426 | 2442 |
| 2427 // Create request and QuicHttpStream. | 2443 // Create request and QuicHttpStream. |
| 2428 QuicStreamRequest request(factory_.get()); | 2444 QuicStreamRequest request(factory_.get()); |
| 2429 EXPECT_EQ(ERR_IO_PENDING, | 2445 EXPECT_EQ(ERR_IO_PENDING, |
| 2430 request.Request(host_port_pair_, privacy_mode_, | 2446 request.Request(host_port_pair_, privacy_mode_, |
| 2431 /*cert_verify_flags=*/0, url_, "GET", net_log_, | 2447 /*cert_verify_flags=*/0, url_, "GET", net_log_, |
| 2432 callback_.callback())); | 2448 callback_.callback())); |
| 2433 EXPECT_EQ(OK, callback_.WaitForResult()); | 2449 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 2434 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); | 2450 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2459 2, false, kClientDataStreamId1, QUIC_STREAM_CANCELLED, 1, 1, 1, true)); | 2475 2, false, kClientDataStreamId1, QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 2460 socket_data1.AddSocketDataToFactory(&socket_factory_); | 2476 socket_data1.AddSocketDataToFactory(&socket_factory_); |
| 2461 | 2477 |
| 2462 // Send GET request on stream. This should cause a write error, which triggers | 2478 // Send GET request on stream. This should cause a write error, which triggers |
| 2463 // a connection migration attempt. | 2479 // a connection migration attempt. |
| 2464 HttpResponseInfo response; | 2480 HttpResponseInfo response; |
| 2465 HttpRequestHeaders request_headers; | 2481 HttpRequestHeaders request_headers; |
| 2466 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, | 2482 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2467 callback_.callback())); | 2483 callback_.callback())); |
| 2468 | 2484 |
| 2469 // Run the message loop so that data queued in the new socket is read by the | 2485 // Run the message loop so that the migration attempt is executed and |
| 2470 // packet reader. | 2486 // data queued in the new socket is read by the packet reader. |
| 2471 base::RunLoop().RunUntilIdle(); | 2487 base::RunLoop().RunUntilIdle(); |
| 2472 | 2488 |
| 2473 // The session should now be marked as going away. Ensure that | 2489 // The session should now be marked as going away. Ensure that |
| 2474 // while it is still alive, it is no longer active. | 2490 // while it is still alive, it is no longer active. |
| 2475 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | 2491 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2476 EXPECT_FALSE(HasActiveSession(host_port_pair_)); | 2492 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2477 EXPECT_EQ(1u, session->GetNumActiveStreams()); | 2493 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2478 | 2494 |
| 2479 // Verify that response headers on the migrated socket were delivered to the | 2495 // Verify that response headers on the migrated socket were delivered to the |
| 2480 // stream. | 2496 // stream. |
| 2481 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); | 2497 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 2482 EXPECT_EQ(200, response.headers->response_code()); | 2498 EXPECT_EQ(200, response.headers->response_code()); |
| 2483 | 2499 |
| 2484 stream.reset(); | 2500 stream.reset(); |
| 2485 | 2501 |
| 2486 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 2502 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2487 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 2503 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2488 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); | 2504 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 2489 EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); | 2505 EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 2490 } | 2506 } |
| 2491 | 2507 |
| 2492 TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorNoNewNetwork) { | 2508 TEST_P(QuicStreamFactoryTest, |
| 2509 MigrateSessionOnWriteErrorNoNewNetworkSynchronous) { |
| 2510 MigrateSessionOnWriteErrorNoNewNetwork(SYNCHRONOUS); |
| 2511 } |
| 2512 |
| 2513 TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorNoNewNetworkAsync) { |
| 2514 MigrateSessionOnWriteErrorNoNewNetwork(ASYNC); |
| 2515 } |
| 2516 |
| 2517 void QuicStreamFactoryTestBase::MigrateSessionOnWriteErrorNoNewNetwork( |
| 2518 IoMode mode) { |
| 2493 InitializeConnectionMigrationTest({kDefaultNetworkForTests}); | 2519 InitializeConnectionMigrationTest({kDefaultNetworkForTests}); |
| 2494 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 2520 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2495 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 2521 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2496 | 2522 |
| 2497 MockQuicData socket_data; | 2523 MockQuicData socket_data; |
| 2498 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); | 2524 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2499 socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); | 2525 socket_data.AddWrite(mode, ERR_ADDRESS_UNREACHABLE); |
| 2500 socket_data.AddSocketDataToFactory(&socket_factory_); | 2526 socket_data.AddSocketDataToFactory(&socket_factory_); |
| 2501 | 2527 |
| 2502 // Create request and QuicHttpStream. | 2528 // Create request and QuicHttpStream. |
| 2503 QuicStreamRequest request(factory_.get()); | 2529 QuicStreamRequest request(factory_.get()); |
| 2504 EXPECT_EQ(ERR_IO_PENDING, | 2530 EXPECT_EQ(ERR_IO_PENDING, |
| 2505 request.Request(host_port_pair_, privacy_mode_, | 2531 request.Request(host_port_pair_, privacy_mode_, |
| 2506 /*cert_verify_flags=*/0, url_, "GET", net_log_, | 2532 /*cert_verify_flags=*/0, url_, "GET", net_log_, |
| 2507 callback_.callback())); | 2533 callback_.callback())); |
| 2508 EXPECT_EQ(OK, callback_.WaitForResult()); | 2534 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 2509 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); | 2535 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); |
| 2510 EXPECT_TRUE(stream.get()); | 2536 EXPECT_TRUE(stream.get()); |
| 2511 | 2537 |
| 2512 // Cause QUIC stream to be created. | 2538 // Cause QUIC stream to be created. |
| 2513 HttpRequestInfo request_info; | 2539 HttpRequestInfo request_info; |
| 2514 request_info.method = "GET"; | 2540 request_info.method = "GET"; |
| 2515 request_info.url = GURL("https://www.example.org/"); | 2541 request_info.url = GURL("https://www.example.org/"); |
| 2516 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, | 2542 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 2517 net_log_, CompletionCallback())); | 2543 net_log_, CompletionCallback())); |
| 2518 | 2544 |
| 2519 // Ensure that session is alive and active. | 2545 // Ensure that session is alive and active. |
| 2520 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); | 2546 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2521 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | 2547 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2522 EXPECT_TRUE(HasActiveSession(host_port_pair_)); | 2548 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2523 | 2549 |
| 2524 // Send GET request on stream. This should cause a write error, which triggers | 2550 // Send GET request on stream. This should cause a write error, which triggers |
| 2525 // a connection migration attempt. | 2551 // a connection migration attempt. |
| 2526 HttpResponseInfo response; | 2552 HttpResponseInfo response; |
| 2527 HttpRequestHeaders request_headers; | 2553 HttpRequestHeaders request_headers; |
| 2528 EXPECT_EQ( | 2554 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2529 ERR_QUIC_PROTOCOL_ERROR, | 2555 callback_.callback())); |
| 2530 stream->SendRequest(request_headers, &response, callback_.callback())); | 2556 // Run message loop to execute migration attempt. |
| 2531 | 2557 base::RunLoop().RunUntilIdle(); |
| 2532 // Migration fails, and session is marked as going away. | 2558 // Migration fails, and session is closed and deleted. |
| 2559 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2533 EXPECT_FALSE(HasActiveSession(host_port_pair_)); | 2560 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2534 | 2561 |
| 2535 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 2562 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2536 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 2563 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2537 } | 2564 } |
| 2538 | 2565 |
| 2539 TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorNonMigratableStream) { | 2566 TEST_P(QuicStreamFactoryTest, |
| 2567 MigrateSessionOnWriteErrorNonMigratableStreamSynchronous) { |
| 2568 MigrateSessionOnWriteErrorNonMigratableStream(SYNCHRONOUS); |
| 2569 } |
| 2570 |
| 2571 TEST_P(QuicStreamFactoryTest, |
| 2572 MigrateSessionOnWriteErrorNonMigratableStreamAsync) { |
| 2573 MigrateSessionOnWriteErrorNonMigratableStream(ASYNC); |
| 2574 } |
| 2575 |
| 2576 void QuicStreamFactoryTestBase::MigrateSessionOnWriteErrorNonMigratableStream( |
| 2577 IoMode mode) { |
| 2578 DVLOG(1) << "Mode: " << ((mode == SYNCHRONOUS) ? "SYNCHRONOUS" : "ASYNC"); |
| 2540 InitializeConnectionMigrationTest( | 2579 InitializeConnectionMigrationTest( |
| 2541 {kDefaultNetworkForTests, kNewNetworkForTests}); | 2580 {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2542 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 2581 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2543 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 2582 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2544 | 2583 |
| 2545 MockQuicData socket_data; | 2584 MockQuicData socket_data; |
| 2546 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); | 2585 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2547 socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); | 2586 socket_data.AddWrite(mode, ERR_ADDRESS_UNREACHABLE); |
| 2548 socket_data.AddSocketDataToFactory(&socket_factory_); | 2587 socket_data.AddSocketDataToFactory(&socket_factory_); |
| 2549 | 2588 |
| 2550 // Create request and QuicHttpStream. | 2589 // Create request and QuicHttpStream. |
| 2551 QuicStreamRequest request(factory_.get()); | 2590 QuicStreamRequest request(factory_.get()); |
| 2552 EXPECT_EQ(ERR_IO_PENDING, | 2591 EXPECT_EQ(ERR_IO_PENDING, |
| 2553 request.Request(host_port_pair_, privacy_mode_, | 2592 request.Request(host_port_pair_, privacy_mode_, |
| 2554 /*cert_verify_flags=*/0, url_, "GET", net_log_, | 2593 /*cert_verify_flags=*/0, url_, "GET", net_log_, |
| 2555 callback_.callback())); | 2594 callback_.callback())); |
| 2556 EXPECT_EQ(OK, callback_.WaitForResult()); | 2595 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 2557 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); | 2596 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); |
| 2558 EXPECT_TRUE(stream.get()); | 2597 EXPECT_TRUE(stream.get()); |
| 2559 | 2598 |
| 2560 // Cause QUIC stream to be created, but marked as non-migratable. | 2599 // Cause QUIC stream to be created, but marked as non-migratable. |
| 2561 HttpRequestInfo request_info; | 2600 HttpRequestInfo request_info; |
| 2562 request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION; | 2601 request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION; |
| 2563 request_info.method = "GET"; | 2602 request_info.method = "GET"; |
| 2564 request_info.url = GURL("https://www.example.org/"); | 2603 request_info.url = GURL("https://www.example.org/"); |
| 2565 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, | 2604 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 2566 net_log_, CompletionCallback())); | 2605 net_log_, CompletionCallback())); |
| 2567 | 2606 |
| 2568 // Ensure that session is alive and active. | 2607 // Ensure that session is alive and active. |
| 2569 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); | 2608 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2570 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | 2609 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2571 EXPECT_TRUE(HasActiveSession(host_port_pair_)); | 2610 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2572 | 2611 |
| 2573 // Send GET request on stream. This should cause a write error, which triggers | 2612 // Send GET request on stream. This should cause a write error, which triggers |
| 2574 // a connection migration attempt. | 2613 // a connection migration attempt. |
| 2575 HttpResponseInfo response; | 2614 HttpResponseInfo response; |
| 2576 HttpRequestHeaders request_headers; | 2615 HttpRequestHeaders request_headers; |
| 2577 EXPECT_EQ( | 2616 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2578 ERR_QUIC_PROTOCOL_ERROR, | 2617 callback_.callback())); |
| 2579 stream->SendRequest(request_headers, &response, callback_.callback())); | |
| 2580 | 2618 |
| 2581 // Migration fails, and session is marked as going away. | 2619 // Run message loop to execute migration attempt. |
| 2620 base::RunLoop().RunUntilIdle(); |
| 2621 |
| 2622 // Migration fails, and session is closed and deleted. |
| 2623 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2582 EXPECT_FALSE(HasActiveSession(host_port_pair_)); | 2624 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2583 | 2625 |
| 2584 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 2626 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2585 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 2627 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2586 } | 2628 } |
| 2587 | 2629 |
| 2588 TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorMigrationDisabled) { | 2630 TEST_P(QuicStreamFactoryTest, |
| 2631 MigrateSessionOnWriteErrorMigrationDisabledSynchronous) { |
| 2632 MigrateSessionOnWriteErrorMigrationDisabled(SYNCHRONOUS); |
| 2633 } |
| 2634 |
| 2635 TEST_P(QuicStreamFactoryTest, |
| 2636 MigrateSessionOnWriteErrorMigrationDisabledAsync) { |
| 2637 MigrateSessionOnWriteErrorMigrationDisabled(ASYNC); |
| 2638 } |
| 2639 |
| 2640 void QuicStreamFactoryTestBase::MigrateSessionOnWriteErrorMigrationDisabled( |
| 2641 IoMode mode) { |
| 2589 InitializeConnectionMigrationTest( | 2642 InitializeConnectionMigrationTest( |
| 2590 {kDefaultNetworkForTests, kNewNetworkForTests}); | 2643 {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2591 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 2644 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2592 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 2645 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2593 | 2646 |
| 2594 MockQuicData socket_data; | 2647 MockQuicData socket_data; |
| 2595 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); | 2648 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2596 socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); | 2649 socket_data.AddWrite(mode, ERR_ADDRESS_UNREACHABLE); |
| 2597 socket_data.AddSocketDataToFactory(&socket_factory_); | 2650 socket_data.AddSocketDataToFactory(&socket_factory_); |
| 2598 | 2651 |
| 2599 // Create request and QuicHttpStream. | 2652 // Create request and QuicHttpStream. |
| 2600 QuicStreamRequest request(factory_.get()); | 2653 QuicStreamRequest request(factory_.get()); |
| 2601 EXPECT_EQ(ERR_IO_PENDING, | 2654 EXPECT_EQ(ERR_IO_PENDING, |
| 2602 request.Request(host_port_pair_, privacy_mode_, | 2655 request.Request(host_port_pair_, privacy_mode_, |
| 2603 /*cert_verify_flags=*/0, url_, "GET", net_log_, | 2656 /*cert_verify_flags=*/0, url_, "GET", net_log_, |
| 2604 callback_.callback())); | 2657 callback_.callback())); |
| 2605 EXPECT_EQ(OK, callback_.WaitForResult()); | 2658 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 2606 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); | 2659 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2619 EXPECT_TRUE(HasActiveSession(host_port_pair_)); | 2672 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2620 | 2673 |
| 2621 // Set session config to have connection migration disabled. | 2674 // Set session config to have connection migration disabled. |
| 2622 QuicConfigPeer::SetReceivedDisableConnectionMigration(session->config()); | 2675 QuicConfigPeer::SetReceivedDisableConnectionMigration(session->config()); |
| 2623 EXPECT_TRUE(session->config()->DisableConnectionMigration()); | 2676 EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 2624 | 2677 |
| 2625 // Send GET request on stream. This should cause a write error, which triggers | 2678 // Send GET request on stream. This should cause a write error, which triggers |
| 2626 // a connection migration attempt. | 2679 // a connection migration attempt. |
| 2627 HttpResponseInfo response; | 2680 HttpResponseInfo response; |
| 2628 HttpRequestHeaders request_headers; | 2681 HttpRequestHeaders request_headers; |
| 2629 EXPECT_EQ( | 2682 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2630 ERR_QUIC_PROTOCOL_ERROR, | 2683 callback_.callback())); |
| 2631 stream->SendRequest(request_headers, &response, callback_.callback())); | 2684 // Run message loop to execute migration attempt. |
| 2632 | 2685 base::RunLoop().RunUntilIdle(); |
| 2633 // Migration fails, and session is marked as going away. | 2686 // Migration fails, and session is closed and deleted. |
| 2687 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2634 EXPECT_FALSE(HasActiveSession(host_port_pair_)); | 2688 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2635 | |
| 2636 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 2689 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2637 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 2690 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2638 } | 2691 } |
| 2639 | 2692 |
| 2693 TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncSync) { |
| 2694 MigrateSessionOnMultipleWriteErrors(SYNCHRONOUS, SYNCHRONOUS); |
| 2695 } |
| 2696 |
| 2697 TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncAsync) { |
| 2698 MigrateSessionOnMultipleWriteErrors(SYNCHRONOUS, ASYNC); |
| 2699 } |
| 2700 |
| 2701 TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncSync) { |
| 2702 MigrateSessionOnMultipleWriteErrors(ASYNC, SYNCHRONOUS); |
| 2703 } |
| 2704 |
| 2705 TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncAsync) { |
| 2706 MigrateSessionOnMultipleWriteErrors(ASYNC, ASYNC); |
| 2707 } |
| 2708 |
| 2709 void QuicStreamFactoryTestBase::MigrateSessionOnMultipleWriteErrors( |
| 2710 IoMode mode1, |
| 2711 IoMode mode2) { |
| 2712 const int kMaxReadersPerQuicSession = 5; |
| 2713 InitializeConnectionMigrationTest( |
| 2714 {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2715 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2716 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2717 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2718 |
| 2719 // Set up kMaxReadersPerQuicSession socket data providers, since migration |
| 2720 // will |
| 2721 // cause kMaxReadersPerQuicSession write failures as the session hops |
| 2722 // repeatedly |
| 2723 // between the two networks. |
| 2724 MockQuicData socket_data[kMaxReadersPerQuicSession + 1]; |
| 2725 for (int i = 0; i <= kMaxReadersPerQuicSession; ++i) { |
| 2726 // The last socket is created but never used. |
| 2727 if (i < kMaxReadersPerQuicSession) { |
| 2728 socket_data[i].AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2729 socket_data[i].AddWrite((i % 2 == 0) ? mode1 : mode2, ERR_FAILED); |
| 2730 } |
| 2731 socket_data[i].AddSocketDataToFactory(&socket_factory_); |
| 2732 } |
| 2733 |
| 2734 // Create request and QuicHttpStream. |
| 2735 QuicStreamRequest request(factory_.get()); |
| 2736 EXPECT_EQ(ERR_IO_PENDING, |
| 2737 request.Request(host_port_pair_, privacy_mode_, |
| 2738 /*cert_verify_flags=*/0, url_, "GET", net_log_, |
| 2739 callback_.callback())); |
| 2740 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 2741 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); |
| 2742 EXPECT_TRUE(stream.get()); |
| 2743 |
| 2744 // Cause QUIC stream to be created. |
| 2745 HttpRequestInfo request_info; |
| 2746 request_info.method = "GET"; |
| 2747 request_info.url = GURL("https://www.example.org/"); |
| 2748 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 2749 net_log_, CompletionCallback())); |
| 2750 |
| 2751 // Ensure that session is alive and active. |
| 2752 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2753 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2754 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2755 |
| 2756 // Send GET request on stream. This should cause a write error, which triggers |
| 2757 // a connection migration attempt. |
| 2758 HttpResponseInfo response; |
| 2759 HttpRequestHeaders request_headers; |
| 2760 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2761 callback_.callback())); |
| 2762 |
| 2763 // Run the message loop so that data queued in the new socket is read by the |
| 2764 // packet reader. |
| 2765 base::RunLoop().RunUntilIdle(); |
| 2766 |
| 2767 // The connection should be closed because of a write error after migration. |
| 2768 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2769 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2770 |
| 2771 // EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 2772 // EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, |
| 2773 // stream->ReadResponseHeaders(callback_.callback())); |
| 2774 |
| 2775 stream.reset(); |
| 2776 for (int i = 0; i <= kMaxReadersPerQuicSession; ++i) { |
| 2777 DLOG(INFO) << "Socket number: " << i; |
| 2778 EXPECT_TRUE(socket_data[i].AllReadDataConsumed()); |
| 2779 EXPECT_TRUE(socket_data[i].AllWriteDataConsumed()); |
| 2780 } |
| 2781 } |
| 2782 |
| 2783 TEST_P(QuicStreamFactoryTest, |
| 2784 MigrateSessionOnWriteErrorWithNetworkDisconnected) { |
| 2785 MigrateSessionOnWriteErrorWithNotificationQueued(/*disconnected=*/true); |
| 2786 } |
| 2787 |
| 2788 TEST_P(QuicStreamFactoryTest, |
| 2789 MigrateSessionOnWriteErrorWithNetworkMadeDefault) { |
| 2790 MigrateSessionOnWriteErrorWithNotificationQueued(/*disconnected=*/false); |
| 2791 } |
| 2792 |
| 2793 void QuicStreamFactoryTestBase:: |
| 2794 MigrateSessionOnWriteErrorWithNotificationQueued(bool disconnected) { |
| 2795 InitializeConnectionMigrationTest( |
| 2796 {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2797 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2798 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2799 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2800 |
| 2801 MockQuicData socket_data; |
| 2802 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2803 socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 2804 socket_data.AddSocketDataToFactory(&socket_factory_); |
| 2805 |
| 2806 // Create request and QuicHttpStream. |
| 2807 QuicStreamRequest request(factory_.get()); |
| 2808 EXPECT_EQ(ERR_IO_PENDING, |
| 2809 request.Request(host_port_pair_, privacy_mode_, |
| 2810 /*cert_verify_flags=*/0, url_, "GET", net_log_, |
| 2811 callback_.callback())); |
| 2812 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 2813 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); |
| 2814 EXPECT_TRUE(stream.get()); |
| 2815 |
| 2816 // Cause QUIC stream to be created. |
| 2817 HttpRequestInfo request_info; |
| 2818 request_info.method = "GET"; |
| 2819 request_info.url = GURL("https://www.example.org/"); |
| 2820 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 2821 net_log_, CompletionCallback())); |
| 2822 |
| 2823 // Ensure that session is alive and active. |
| 2824 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2825 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2826 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2827 |
| 2828 // Set up second socket data provider that is used after |
| 2829 // migration. The request is rewritten to this new socket, and the |
| 2830 // response to the request is read on this new socket. |
| 2831 MockQuicData socket_data1; |
| 2832 socket_data1.AddWrite( |
| 2833 ConstructGetRequestPacket(1, kClientDataStreamId1, true, true)); |
| 2834 socket_data1.AddRead( |
| 2835 ConstructOkResponsePacket(1, kClientDataStreamId1, false, false)); |
| 2836 socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2837 socket_data1.AddWrite(client_maker_.MakeAckAndRstPacket( |
| 2838 2, false, kClientDataStreamId1, QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 2839 socket_data1.AddSocketDataToFactory(&socket_factory_); |
| 2840 |
| 2841 // First queue a network change notification in the message loop. |
| 2842 if (disconnected) { |
| 2843 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2844 ->QueueNetworkDisconnected(kDefaultNetworkForTests); |
| 2845 } else { |
| 2846 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2847 ->QueueNetworkMadeDefault(kNewNetworkForTests); |
| 2848 } |
| 2849 // Send GET request on stream. This should cause a write error, |
| 2850 // which triggers a connection migration attempt. This will queue a |
| 2851 // migration attempt behind the notification in the message loop. |
| 2852 HttpResponseInfo response; |
| 2853 HttpRequestHeaders request_headers; |
| 2854 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2855 callback_.callback())); |
| 2856 |
| 2857 base::RunLoop().RunUntilIdle(); |
| 2858 // The session should now be marked as going away. Ensure that |
| 2859 // while it is still alive, it is no longer active. |
| 2860 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2861 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2862 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2863 |
| 2864 // Verify that response headers on the migrated socket were delivered to the |
| 2865 // stream. |
| 2866 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 2867 EXPECT_EQ(200, response.headers->response_code()); |
| 2868 |
| 2869 stream.reset(); |
| 2870 |
| 2871 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2872 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2873 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 2874 EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 2875 } |
| 2876 |
| 2640 TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyToBadSocket) { | 2877 TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyToBadSocket) { |
| 2641 // This simulates the case where we attempt to migrate to a new | 2878 // This simulates the case where we attempt to migrate to a new |
| 2642 // socket but the socket is unusable, such as an ipv4/ipv6 mismatch. | 2879 // socket but the socket is unusable, such as an ipv4/ipv6 mismatch. |
| 2643 InitializeConnectionMigrationTest( | 2880 InitializeConnectionMigrationTest( |
| 2644 {kDefaultNetworkForTests, kNewNetworkForTests}); | 2881 {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2645 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 2882 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2646 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 2883 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2647 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 2884 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2648 | 2885 |
| 2649 MockQuicData socket_data; | 2886 MockQuicData socket_data; |
| (...skipping 2485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5135 // Clear all cached states. | 5372 // Clear all cached states. |
| 5136 factory_->ClearCachedStatesInCryptoConfig( | 5373 factory_->ClearCachedStatesInCryptoConfig( |
| 5137 base::Callback<bool(const GURL&)>()); | 5374 base::Callback<bool(const GURL&)>()); |
| 5138 EXPECT_TRUE(test_cases[0].state->certs().empty()); | 5375 EXPECT_TRUE(test_cases[0].state->certs().empty()); |
| 5139 EXPECT_TRUE(test_cases[1].state->certs().empty()); | 5376 EXPECT_TRUE(test_cases[1].state->certs().empty()); |
| 5140 EXPECT_TRUE(test_cases[2].state->certs().empty()); | 5377 EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 5141 } | 5378 } |
| 5142 | 5379 |
| 5143 } // namespace test | 5380 } // namespace test |
| 5144 } // namespace net | 5381 } // namespace net |
| OLD | NEW |