Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: net/quic/quic_stream_factory_test.cc

Issue 186293002: Disable QUIC port selection when the server is going away. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comments Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_stream_factory.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/base/test_data_directory.h" 9 #include "net/base/test_data_directory.h"
10 #include "net/cert/cert_verifier.h" 10 #include "net/cert/cert_verifier.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 host_port_proxy_pair_(HostPortPair(kDefaultServerHostName, 84 host_port_proxy_pair_(HostPortPair(kDefaultServerHostName,
85 kDefaultServerPort), 85 kDefaultServerPort),
86 ProxyServer::Direct()), 86 ProxyServer::Direct()),
87 is_https_(false), 87 is_https_(false),
88 cert_verifier_(CertVerifier::CreateDefault()) { 88 cert_verifier_(CertVerifier::CreateDefault()) {
89 factory_.set_require_confirmation(false); 89 factory_.set_require_confirmation(false);
90 } 90 }
91 91
92 92
93 int GetSourcePortForNewSession(const HostPortProxyPair& destination) { 93 int GetSourcePortForNewSession(const HostPortProxyPair& destination) {
94 return GetSourcePortForNewSessionInner(destination, false);
95 }
96
97 int GetSourcePortForNewSessionAndGoAway(
98 const HostPortProxyPair& destination) {
99 return GetSourcePortForNewSessionInner(destination, true);
100 }
101
102 int GetSourcePortForNewSessionInner(const HostPortProxyPair& destination,
103 bool goaway_received) {
94 // Should only be called if there is no active session for this destination. 104 // Should only be called if there is no active session for this destination.
95 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(destination, 105 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(destination,
96 net_log_).get()); 106 net_log_).get());
97 size_t socket_count = socket_factory_.udp_client_sockets().size(); 107 size_t socket_count = socket_factory_.udp_client_sockets().size();
98 108
99 MockRead reads[] = { 109 MockRead reads[] = {
100 MockRead(ASYNC, OK, 0) // EOF 110 MockRead(ASYNC, OK, 0) // EOF
101 }; 111 };
102 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); 112 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
103 socket_data.StopAfter(1); 113 socket_data.StopAfter(1);
(...skipping 18 matching lines...) Expand all
122 132
123 if (socket_count + 1 != socket_factory_.udp_client_sockets().size()) { 133 if (socket_count + 1 != socket_factory_.udp_client_sockets().size()) {
124 EXPECT_TRUE(false); 134 EXPECT_TRUE(false);
125 return 0; 135 return 0;
126 } 136 }
127 137
128 IPEndPoint endpoint; 138 IPEndPoint endpoint;
129 socket_factory_. 139 socket_factory_.
130 udp_client_sockets()[socket_count]->GetLocalAddress(&endpoint); 140 udp_client_sockets()[socket_count]->GetLocalAddress(&endpoint);
131 int port = endpoint.port(); 141 int port = endpoint.port();
142 if (goaway_received) {
143 QuicGoAwayFrame goaway(QUIC_NO_ERROR, 1, "");
144 session->OnGoAway(goaway);
145 }
132 146
133 factory_.OnSessionClosed(session); 147 factory_.OnSessionClosed(session);
134 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(destination, 148 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(destination,
135 net_log_).get()); 149 net_log_).get());
136 EXPECT_TRUE(socket_data.at_read_eof()); 150 EXPECT_TRUE(socket_data.at_read_eof());
137 EXPECT_TRUE(socket_data.at_write_eof()); 151 EXPECT_TRUE(socket_data.at_write_eof());
138 return port; 152 return port;
139 } 153 }
140 154
141 scoped_ptr<QuicEncryptedPacket> ConstructRstPacket() { 155 scoped_ptr<QuicEncryptedPacket> ConstructRstPacket() {
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 EXPECT_NE(kDefaultServerHostName, other_server_name); 683 EXPECT_NE(kDefaultServerHostName, other_server_name);
670 HostPortPair host_port_pair2(other_server_name, kDefaultServerPort); 684 HostPortPair host_port_pair2(other_server_name, kDefaultServerPort);
671 HostPortProxyPair host_port_proxy_pair2(host_port_pair2, 685 HostPortProxyPair host_port_proxy_pair2(host_port_pair2,
672 host_port_proxy_pair_.second); 686 host_port_proxy_pair_.second);
673 687
674 int original_port = GetSourcePortForNewSession(host_port_proxy_pair_); 688 int original_port = GetSourcePortForNewSession(host_port_proxy_pair_);
675 EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_proxy_pair2)); 689 EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_proxy_pair2));
676 EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_proxy_pair_)); 690 EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_proxy_pair_));
677 } 691 }
678 692
693 TEST_P(QuicStreamFactoryTest, GoAwayDisablesConsistentEphemeralPort) {
694 // Get a session to the host using the port suggester.
695 int original_port =
696 GetSourcePortForNewSessionAndGoAway(host_port_proxy_pair_);
697 // Verify that the port is different after the goaway.
698 EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_proxy_pair_));
699 // Since the previous session did not goaway we should see the original port.
700 EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_proxy_pair_));
701 }
702
679 TEST_P(QuicStreamFactoryTest, CloseAllSessions) { 703 TEST_P(QuicStreamFactoryTest, CloseAllSessions) {
680 MockRead reads[] = { 704 MockRead reads[] = {
681 MockRead(ASYNC, 0, 0) // EOF 705 MockRead(ASYNC, 0, 0) // EOF
682 }; 706 };
683 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); 707 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
684 std::vector<MockWrite> writes; 708 std::vector<MockWrite> writes;
685 if (GetParam() > QUIC_VERSION_13) 709 if (GetParam() > QUIC_VERSION_13)
686 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); 710 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
687 DeterministicSocketData socket_data(reads, arraysize(reads), 711 DeterministicSocketData socket_data(reads, arraysize(reads),
688 writes.empty() ? NULL : &writes[0], 712 writes.empty() ? NULL : &writes[0],
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 QuicCryptoClientConfig::CachedState* cached2 = 1037 QuicCryptoClientConfig::CachedState* cached2 =
1014 crypto_config2->LookupOrCreate(host_port_proxy_pair2.first.host()); 1038 crypto_config2->LookupOrCreate(host_port_proxy_pair2.first.host());
1015 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); 1039 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token());
1016 EXPECT_TRUE(cached2->source_address_token().empty()); 1040 EXPECT_TRUE(cached2->source_address_token().empty());
1017 EXPECT_FALSE(cached2->proof_valid()); 1041 EXPECT_FALSE(cached2->proof_valid());
1018 } 1042 }
1019 } 1043 }
1020 1044
1021 } // namespace test 1045 } // namespace test
1022 } // namespace net 1046 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_stream_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698