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 <ostream> | 7 #include <ostream> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 2630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2641 ERR_QUIC_PROTOCOL_ERROR, | 2641 ERR_QUIC_PROTOCOL_ERROR, |
2642 stream->SendRequest(request_headers, &response, callback_.callback())); | 2642 stream->SendRequest(request_headers, &response, callback_.callback())); |
2643 | 2643 |
2644 // Migration fails, and session is marked as going away. | 2644 // Migration fails, and session is marked as going away. |
2645 EXPECT_FALSE(HasActiveSession(host_port_pair_)); | 2645 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
2646 | 2646 |
2647 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 2647 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
2648 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 2648 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
2649 } | 2649 } |
2650 | 2650 |
2651 TEST_P(QuicStreamFactoryTest, ServerMigration) { | |
2652 Initialize(); | |
2653 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | |
2654 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | |
2655 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | |
2656 | |
2657 std::unique_ptr<QuicEncryptedPacket> request_packet( | |
2658 ConstructGetRequestPacket(1, kClientDataStreamId1, true, true)); | |
2659 MockWrite writes1[] = {MockWrite(SYNCHRONOUS, request_packet->data(), | |
2660 request_packet->length(), 1)}; | |
2661 MockRead reads1[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
2662 SequencedSocketData socket_data1(reads1, arraysize(reads1), writes1, | |
2663 arraysize(writes1)); | |
2664 socket_factory_.AddSocketDataProvider(&socket_data1); | |
2665 | |
2666 // Create request and QuicHttpStream. | |
2667 QuicStreamRequest request(factory_.get()); | |
2668 EXPECT_EQ(ERR_IO_PENDING, | |
2669 request.Request(host_port_pair_, privacy_mode_, | |
2670 /*cert_verify_flags=*/0, url_, "GET", net_log_, | |
2671 callback_.callback())); | |
2672 EXPECT_EQ(OK, callback_.WaitForResult()); | |
2673 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); | |
2674 EXPECT_TRUE(stream.get()); | |
2675 | |
2676 // Cause QUIC stream to be created. This causes session to be created and | |
2677 // migrate to using a new socket to the server's alternate address. | |
Ryan Hamilton
2016/07/06 19:29:37
I don't think this comment is correct since there
Jana
2016/07/12 22:34:10
Yes, that's right -- leftover text from previous i
| |
2678 HttpRequestInfo request_info; | |
2679 request_info.method = "GET"; | |
2680 request_info.url = GURL("https://www.example.org/"); | |
2681 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, | |
2682 net_log_, CompletionCallback())); | |
2683 | |
2684 // Ensure that session is alive and active. | |
2685 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); | |
2686 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
2687 EXPECT_TRUE(HasActiveSession(host_port_pair_)); | |
2688 | |
2689 // Send GET request on stream. | |
2690 HttpResponseInfo response; | |
2691 HttpRequestHeaders request_headers; | |
2692 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, | |
2693 callback_.callback())); | |
2694 | |
2695 IPEndPoint ip; | |
2696 session->GetDefaultSocket()->GetPeerAddress(&ip); | |
2697 DVLOG(1) << "Socket connected to: " << ip.address().ToString() << " " | |
2698 << ip.port(); | |
2699 | |
2700 // Set up second socket data provider that is used after | |
2701 // migration. The request is rewritten to this new socket, and the | |
2702 // response to the request is read on this new socket. | |
2703 std::unique_ptr<QuicEncryptedPacket> ping( | |
2704 client_maker_.MakePingPacket(2, /*include_version=*/true)); | |
2705 std::unique_ptr<QuicEncryptedPacket> client_rst( | |
2706 client_maker_.MakeAckAndRstPacket(3, false, kClientDataStreamId1, | |
2707 QUIC_STREAM_CANCELLED, 1, 1, 1, true)); | |
2708 MockWrite writes2[] = { | |
2709 MockWrite(SYNCHRONOUS, ping->data(), ping->length(), 0), | |
2710 MockWrite(SYNCHRONOUS, client_rst->data(), client_rst->length(), 3)}; | |
2711 std::unique_ptr<QuicEncryptedPacket> response_headers_packet( | |
2712 ConstructOkResponsePacket(1, kClientDataStreamId1, false, false)); | |
2713 MockRead reads2[] = {MockRead(ASYNC, response_headers_packet->data(), | |
2714 response_headers_packet->length(), 1), | |
2715 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2)}; | |
2716 SequencedSocketData socket_data2(reads2, arraysize(reads2), writes2, | |
2717 arraysize(writes2)); | |
2718 socket_factory_.AddSocketDataProvider(&socket_data2); | |
2719 | |
2720 const uint8_t kTestIpAddress[] = {1, 2, 3, 4}; | |
2721 const uint16_t kTestPort = 123; | |
2722 factory_->MigrateSessionToNewSocket( | |
2723 session, IPEndPoint(IPAddress(kTestIpAddress), kTestPort), | |
2724 NetworkChangeNotifier::kInvalidNetworkHandle, net_log_, nullptr); | |
2725 | |
2726 session->GetDefaultSocket()->GetPeerAddress(&ip); | |
2727 DVLOG(1) << "Socket migrated to: " << ip.address().ToString() << " " | |
2728 << ip.port(); | |
2729 | |
2730 // The session should be alive and active. | |
2731 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
2732 EXPECT_TRUE(HasActiveSession(host_port_pair_)); | |
2733 EXPECT_EQ(1u, session->GetNumActiveStreams()); | |
2734 | |
2735 // Run the message loop so that data queued in the new socket is read by the | |
2736 // packet reader. | |
2737 base::RunLoop().RunUntilIdle(); | |
2738 | |
2739 // Verify that response headers on the migrated socket were delivered to the | |
2740 // stream. | |
2741 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); | |
2742 EXPECT_EQ(200, response.headers->response_code()); | |
2743 | |
2744 stream.reset(); | |
2745 | |
2746 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); | |
2747 EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); | |
2748 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); | |
2749 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); | |
2750 } | |
Ryan Hamilton
2016/07/06 19:29:37
This seems like a test which might be a better fit
Jana
2016/07/12 22:34:10
I think the test would basically end up testing th
| |
2751 | |
2651 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { | 2752 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { |
2652 Initialize(); | 2753 Initialize(); |
2653 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 2754 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
2654 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 2755 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
2655 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 2756 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
2656 | 2757 |
2657 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | 2758 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
2658 std::unique_ptr<QuicEncryptedPacket> rst(ConstructClientRstPacket()); | 2759 std::unique_ptr<QuicEncryptedPacket> rst(ConstructClientRstPacket()); |
2659 vector<MockWrite> writes; | 2760 vector<MockWrite> writes; |
2660 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); | 2761 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
(...skipping 2009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4670 EXPECT_NE(session1, session2); | 4771 EXPECT_NE(session1, session2); |
4671 | 4772 |
4672 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); | 4773 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); |
4673 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); | 4774 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); |
4674 | 4775 |
4675 EXPECT_TRUE(AllDataConsumed()); | 4776 EXPECT_TRUE(AllDataConsumed()); |
4676 } | 4777 } |
4677 | 4778 |
4678 } // namespace test | 4779 } // namespace test |
4679 } // namespace net | 4780 } // namespace net |
OLD | NEW |