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

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

Issue 190063008: Include the scheme in the key for QUIC the session map. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: net-internals 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 23 matching lines...) Expand all
34 34
35 namespace { 35 namespace {
36 const char kDefaultServerHostName[] = "www.google.com"; 36 const char kDefaultServerHostName[] = "www.google.com";
37 const int kDefaultServerPort = 443; 37 const int kDefaultServerPort = 443;
38 } // namespace anonymous 38 } // namespace anonymous
39 39
40 class QuicStreamFactoryPeer { 40 class QuicStreamFactoryPeer {
41 public: 41 public:
42 static QuicCryptoClientConfig* GetOrCreateCryptoConfig( 42 static QuicCryptoClientConfig* GetOrCreateCryptoConfig(
43 QuicStreamFactory* factory, 43 QuicStreamFactory* factory,
44 const HostPortProxyPair& host_port_proxy_pair) { 44 const HostPortProxyPair& host_port_proxy_pair,
45 return factory->GetOrCreateCryptoConfig(host_port_proxy_pair); 45 bool is_https) {
46 QuicStreamFactory::SessionKey session_key(host_port_proxy_pair, is_https);
47 return factory->GetOrCreateCryptoConfig(session_key);
46 } 48 }
47 49
48 static bool HasActiveSession(QuicStreamFactory* factory, 50 static bool HasActiveSession(QuicStreamFactory* factory,
49 const HostPortProxyPair& host_port_proxy_pair) { 51 const HostPortProxyPair& host_port_proxy_pair,
50 return factory->HasActiveSession(host_port_proxy_pair); 52 bool is_https) {
53 QuicStreamFactory::SessionKey session_key(host_port_proxy_pair, is_https);
54 return factory->HasActiveSession(session_key);
51 } 55 }
52 56
53 static QuicClientSession* GetActiveSession( 57 static QuicClientSession* GetActiveSession(
54 QuicStreamFactory* factory, 58 QuicStreamFactory* factory,
55 const HostPortProxyPair& host_port_proxy_pair) { 59 const HostPortProxyPair& host_port_proxy_pair,
56 DCHECK(factory->HasActiveSession(host_port_proxy_pair)); 60 bool is_https) {
57 return factory->active_sessions_[host_port_proxy_pair]; 61 QuicStreamFactory::SessionKey session_key(host_port_proxy_pair, is_https);
62 DCHECK(factory->HasActiveSession(session_key));
63 return factory->active_sessions_[session_key];
64 }
65
66 static scoped_ptr<QuicHttpStream> CreateIfSessionExists(
67 QuicStreamFactory* factory,
68 const HostPortProxyPair& host_port_proxy_pair,
69 bool is_https,
70 const BoundNetLog& net_log) {
71 QuicStreamFactory::SessionKey session_key(host_port_proxy_pair, is_https);
72 return factory->CreateIfSessionExists(session_key, net_log);
58 } 73 }
59 74
60 static bool IsLiveSession(QuicStreamFactory* factory, 75 static bool IsLiveSession(QuicStreamFactory* factory,
61 QuicClientSession* session) { 76 QuicClientSession* session) {
62 for (QuicStreamFactory::SessionSet::iterator it = 77 for (QuicStreamFactory::SessionSet::iterator it =
63 factory->all_sessions_.begin(); 78 factory->all_sessions_.begin();
64 it != factory->all_sessions_.end(); ++it) { 79 it != factory->all_sessions_.end(); ++it) {
65 if (*it == session) 80 if (*it == session)
66 return true; 81 return true;
67 } 82 }
(...skipping 13 matching lines...) Expand all
81 &random_generator_, clock_, kDefaultMaxPacketSize, 96 &random_generator_, clock_, kDefaultMaxPacketSize,
82 SupportedVersions(GetParam()), true, true), 97 SupportedVersions(GetParam()), true, true),
83 host_port_proxy_pair_(HostPortPair(kDefaultServerHostName, 98 host_port_proxy_pair_(HostPortPair(kDefaultServerHostName,
84 kDefaultServerPort), 99 kDefaultServerPort),
85 ProxyServer::Direct()), 100 ProxyServer::Direct()),
86 is_https_(false), 101 is_https_(false),
87 cert_verifier_(CertVerifier::CreateDefault()) { 102 cert_verifier_(CertVerifier::CreateDefault()) {
88 factory_.set_require_confirmation(false); 103 factory_.set_require_confirmation(false);
89 } 104 }
90 105
106 scoped_ptr<QuicHttpStream> CreateIfSessionExists(
107 const HostPortProxyPair& host_port_proxy_pair,
108 const BoundNetLog& net_log) {
109 return QuicStreamFactoryPeer::CreateIfSessionExists(
110 &factory_, host_port_proxy_pair, false, net_log_);
111 }
91 112
92 int GetSourcePortForNewSession(const HostPortProxyPair& destination) { 113 int GetSourcePortForNewSession(const HostPortProxyPair& destination) {
93 return GetSourcePortForNewSessionInner(destination, false); 114 return GetSourcePortForNewSessionInner(destination, false);
94 } 115 }
95 116
96 int GetSourcePortForNewSessionAndGoAway( 117 int GetSourcePortForNewSessionAndGoAway(
97 const HostPortProxyPair& destination) { 118 const HostPortProxyPair& destination) {
98 return GetSourcePortForNewSessionInner(destination, true); 119 return GetSourcePortForNewSessionInner(destination, true);
99 } 120 }
100 121
101 int GetSourcePortForNewSessionInner(const HostPortProxyPair& destination, 122 int GetSourcePortForNewSessionInner(const HostPortProxyPair& destination,
102 bool goaway_received) { 123 bool goaway_received) {
103 // Should only be called if there is no active session for this destination. 124 // Should only be called if there is no active session for this destination.
104 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(destination, 125 EXPECT_EQ(NULL, CreateIfSessionExists(destination, net_log_).get());
105 net_log_).get());
106 size_t socket_count = socket_factory_.udp_client_sockets().size(); 126 size_t socket_count = socket_factory_.udp_client_sockets().size();
107 127
108 MockRead reads[] = { 128 MockRead reads[] = {
109 MockRead(ASYNC, OK, 0) // EOF 129 MockRead(ASYNC, OK, 0) // EOF
110 }; 130 };
111 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); 131 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
112 socket_data.StopAfter(1); 132 socket_data.StopAfter(1);
113 socket_factory_.AddSocketDataProvider(&socket_data); 133 socket_factory_.AddSocketDataProvider(&socket_data);
114 134
115 QuicStreamRequest request(&factory_); 135 QuicStreamRequest request(&factory_);
116 EXPECT_EQ(ERR_IO_PENDING, 136 EXPECT_EQ(ERR_IO_PENDING,
117 request.Request(destination, 137 request.Request(destination,
118 is_https_, 138 is_https_,
119 "GET", 139 "GET",
120 cert_verifier_.get(), 140 cert_verifier_.get(),
121 net_log_, 141 net_log_,
122 callback_.callback())); 142 callback_.callback()));
123 143
124 EXPECT_EQ(OK, callback_.WaitForResult()); 144 EXPECT_EQ(OK, callback_.WaitForResult());
125 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); 145 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
126 EXPECT_TRUE(stream.get()); 146 EXPECT_TRUE(stream.get());
127 stream.reset(); 147 stream.reset();
128 148
129 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( 149 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
130 &factory_, destination); 150 &factory_, destination, is_https_);
131 151
132 if (socket_count + 1 != socket_factory_.udp_client_sockets().size()) { 152 if (socket_count + 1 != socket_factory_.udp_client_sockets().size()) {
133 EXPECT_TRUE(false); 153 EXPECT_TRUE(false);
134 return 0; 154 return 0;
135 } 155 }
136 156
137 IPEndPoint endpoint; 157 IPEndPoint endpoint;
138 socket_factory_. 158 socket_factory_.
139 udp_client_sockets()[socket_count]->GetLocalAddress(&endpoint); 159 udp_client_sockets()[socket_count]->GetLocalAddress(&endpoint);
140 int port = endpoint.port(); 160 int port = endpoint.port();
141 if (goaway_received) { 161 if (goaway_received) {
142 QuicGoAwayFrame goaway(QUIC_NO_ERROR, 1, ""); 162 QuicGoAwayFrame goaway(QUIC_NO_ERROR, 1, "");
143 session->OnGoAway(goaway); 163 session->OnGoAway(goaway);
144 } 164 }
145 165
146 factory_.OnSessionClosed(session); 166 factory_.OnSessionClosed(session);
147 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(destination, 167 EXPECT_EQ(NULL, CreateIfSessionExists(destination, net_log_).get());
eroman 2014/03/08 01:04:25 BTW I seem to remember having issues with this pat
148 net_log_).get());
149 EXPECT_TRUE(socket_data.at_read_eof()); 168 EXPECT_TRUE(socket_data.at_read_eof());
150 EXPECT_TRUE(socket_data.at_write_eof()); 169 EXPECT_TRUE(socket_data.at_write_eof());
151 return port; 170 return port;
152 } 171 }
153 172
154 scoped_ptr<QuicEncryptedPacket> ConstructRstPacket() { 173 scoped_ptr<QuicEncryptedPacket> ConstructRstPacket() {
155 QuicStreamId stream_id = 5; 174 QuicStreamId stream_id = 5;
156 return maker_.MakeRstPacket(1, true, stream_id, QUIC_STREAM_NO_ERROR); 175 return maker_.MakeRstPacket(1, true, stream_id, QUIC_STREAM_NO_ERROR);
157 } 176 }
158 177
159 MockHostResolver host_resolver_; 178 MockHostResolver host_resolver_;
160 DeterministicMockClientSocketFactory socket_factory_; 179 DeterministicMockClientSocketFactory socket_factory_;
161 MockCryptoClientStreamFactory crypto_client_stream_factory_; 180 MockCryptoClientStreamFactory crypto_client_stream_factory_;
162 MockRandom random_generator_; 181 MockRandom random_generator_;
163 QuicTestPacketMaker maker_; 182 QuicTestPacketMaker maker_;
164 MockClock* clock_; // Owned by factory_. 183 MockClock* clock_; // Owned by factory_.
165 QuicStreamFactory factory_; 184 QuicStreamFactory factory_;
166 HostPortProxyPair host_port_proxy_pair_; 185 HostPortProxyPair host_port_proxy_pair_;
167 bool is_https_; 186 bool is_https_;
168 scoped_ptr<CertVerifier> cert_verifier_; 187 scoped_ptr<CertVerifier> cert_verifier_;
169 BoundNetLog net_log_; 188 BoundNetLog net_log_;
170 TestCompletionCallback callback_; 189 TestCompletionCallback callback_;
171 }; 190 };
172 191
173 INSTANTIATE_TEST_CASE_P(Version, QuicStreamFactoryTest, 192 INSTANTIATE_TEST_CASE_P(Version, QuicStreamFactoryTest,
174 ::testing::ValuesIn(QuicSupportedVersions())); 193 ::testing::ValuesIn(QuicSupportedVersions()));
175 194
176 TEST_P(QuicStreamFactoryTest, CreateIfSessionExists) { 195 TEST_P(QuicStreamFactoryTest, CreateIfSessionExists) {
177 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(host_port_proxy_pair_, 196 EXPECT_EQ(NULL, CreateIfSessionExists(host_port_proxy_pair_, net_log_).get());
178 net_log_).get());
179 } 197 }
180 198
181 TEST_P(QuicStreamFactoryTest, Create) { 199 TEST_P(QuicStreamFactoryTest, Create) {
182 MockRead reads[] = { 200 MockRead reads[] = {
183 MockRead(ASYNC, OK, 0) // EOF 201 MockRead(ASYNC, OK, 0) // EOF
184 }; 202 };
185 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); 203 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
186 socket_factory_.AddSocketDataProvider(&socket_data); 204 socket_factory_.AddSocketDataProvider(&socket_data);
187 socket_data.StopAfter(1); 205 socket_data.StopAfter(1);
188 206
189 QuicStreamRequest request(&factory_); 207 QuicStreamRequest request(&factory_);
190 EXPECT_EQ(ERR_IO_PENDING, 208 EXPECT_EQ(ERR_IO_PENDING,
191 request.Request(host_port_proxy_pair_, 209 request.Request(host_port_proxy_pair_,
192 is_https_, 210 is_https_,
193 "GET", 211 "GET",
194 cert_verifier_.get(), 212 cert_verifier_.get(),
195 net_log_, 213 net_log_,
196 callback_.callback())); 214 callback_.callback()));
197 215
198 EXPECT_EQ(OK, callback_.WaitForResult()); 216 EXPECT_EQ(OK, callback_.WaitForResult());
199 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); 217 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
200 EXPECT_TRUE(stream.get()); 218 EXPECT_TRUE(stream.get());
201 219
202 // Will reset stream 3. 220 // Will reset stream 3.
203 stream = factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_); 221 stream = CreateIfSessionExists(host_port_proxy_pair_, net_log_);
204 EXPECT_TRUE(stream.get()); 222 EXPECT_TRUE(stream.get());
205 223
206 // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result 224 // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result
207 // in streams on different sessions. 225 // in streams on different sessions.
208 QuicStreamRequest request2(&factory_); 226 QuicStreamRequest request2(&factory_);
209 EXPECT_EQ(OK, 227 EXPECT_EQ(OK,
210 request2.Request(host_port_proxy_pair_, 228 request2.Request(host_port_proxy_pair_,
211 is_https_, 229 is_https_,
212 "GET", 230 "GET",
213 cert_verifier_.get(), 231 cert_verifier_.get(),
214 net_log_, 232 net_log_,
215 callback_.callback())); 233 callback_.callback()));
216 stream = request2.ReleaseStream(); // Will reset stream 5. 234 stream = request2.ReleaseStream(); // Will reset stream 5.
217 stream.reset(); // Will reset stream 7. 235 stream.reset(); // Will reset stream 7.
218 236
219 EXPECT_TRUE(socket_data.at_read_eof()); 237 EXPECT_TRUE(socket_data.at_read_eof());
220 EXPECT_TRUE(socket_data.at_write_eof()); 238 EXPECT_TRUE(socket_data.at_write_eof());
221 } 239 }
222 240
241 TEST_P(QuicStreamFactoryTest, CreateHttpVsHttps) {
242 MockRead reads[] = {
243 MockRead(ASYNC, OK, 0) // EOF
244 };
245 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0);
246 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0);
247 socket_factory_.AddSocketDataProvider(&socket_data1);
248 socket_factory_.AddSocketDataProvider(&socket_data2);
249 socket_data1.StopAfter(1);
250 socket_data2.StopAfter(1);
251
252 QuicStreamRequest request(&factory_);
253 EXPECT_EQ(ERR_IO_PENDING,
254 request.Request(host_port_proxy_pair_,
255 is_https_,
256 "GET",
257 cert_verifier_.get(),
258 net_log_,
259 callback_.callback()));
260
261 EXPECT_EQ(OK, callback_.WaitForResult());
262 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
263 EXPECT_TRUE(stream.get());
264
265 QuicStreamRequest request2(&factory_);
266 EXPECT_EQ(ERR_IO_PENDING,
267 request2.Request(host_port_proxy_pair_,
268 !is_https_,
269 "GET",
270 cert_verifier_.get(),
271 net_log_,
272 callback_.callback()));
273 EXPECT_EQ(OK, callback_.WaitForResult());
274 stream = request2.ReleaseStream();
275 EXPECT_TRUE(stream.get());
276 stream.reset();
277
278 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
279 &factory_, host_port_proxy_pair_, is_https_),
280 QuicStreamFactoryPeer::GetActiveSession(
281 &factory_, host_port_proxy_pair_, !is_https_));
282
283 EXPECT_TRUE(socket_data1.at_read_eof());
284 EXPECT_TRUE(socket_data1.at_write_eof());
285 EXPECT_TRUE(socket_data2.at_read_eof());
286 EXPECT_TRUE(socket_data2.at_write_eof());
287 }
288
223 TEST_P(QuicStreamFactoryTest, Pooling) { 289 TEST_P(QuicStreamFactoryTest, Pooling) {
224 MockRead reads[] = { 290 MockRead reads[] = {
225 MockRead(ASYNC, OK, 0) // EOF 291 MockRead(ASYNC, OK, 0) // EOF
226 }; 292 };
227 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); 293 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
228 socket_factory_.AddSocketDataProvider(&socket_data); 294 socket_factory_.AddSocketDataProvider(&socket_data);
229 socket_data.StopAfter(1); 295 socket_data.StopAfter(1);
230 296
231 HostPortProxyPair server2 = HostPortProxyPair( 297 HostPortProxyPair server2 = HostPortProxyPair(
232 HostPortPair("mail.google.com", kDefaultServerPort), 298 HostPortPair("mail.google.com", kDefaultServerPort),
(...skipping 22 matching lines...) Expand all
255 request2.Request(server2, 321 request2.Request(server2,
256 is_https_, 322 is_https_,
257 "GET", 323 "GET",
258 cert_verifier_.get(), 324 cert_verifier_.get(),
259 net_log_, 325 net_log_,
260 callback.callback())); 326 callback.callback()));
261 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); 327 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
262 EXPECT_TRUE(stream2.get()); 328 EXPECT_TRUE(stream2.get());
263 329
264 EXPECT_EQ( 330 EXPECT_EQ(
265 QuicStreamFactoryPeer::GetActiveSession(&factory_, host_port_proxy_pair_), 331 QuicStreamFactoryPeer::GetActiveSession(
266 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2)); 332 &factory_, host_port_proxy_pair_, is_https_),
333 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_));
267 334
268 EXPECT_TRUE(socket_data.at_read_eof()); 335 EXPECT_TRUE(socket_data.at_read_eof());
269 EXPECT_TRUE(socket_data.at_write_eof()); 336 EXPECT_TRUE(socket_data.at_write_eof());
270 } 337 }
271 338
272 TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) { 339 TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) {
273 MockRead reads[] = { 340 MockRead reads[] = {
274 MockRead(ASYNC, OK, 0) // EOF 341 MockRead(ASYNC, OK, 0) // EOF
275 }; 342 };
276 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); 343 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0);
(...skipping 29 matching lines...) Expand all
306 EXPECT_EQ(OK, 373 EXPECT_EQ(OK,
307 request2.Request(server2, 374 request2.Request(server2,
308 is_https_, 375 is_https_,
309 "GET", 376 "GET",
310 cert_verifier_.get(), 377 cert_verifier_.get(),
311 net_log_, 378 net_log_,
312 callback.callback())); 379 callback.callback()));
313 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); 380 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
314 EXPECT_TRUE(stream2.get()); 381 EXPECT_TRUE(stream2.get());
315 382
316 factory_.OnSessionGoingAway( 383 factory_.OnSessionGoingAway(QuicStreamFactoryPeer::GetActiveSession(
317 QuicStreamFactoryPeer::GetActiveSession(&factory_, 384 &factory_, host_port_proxy_pair_, is_https_));
318 host_port_proxy_pair_)); 385 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
319 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(&factory_, 386 &factory_, host_port_proxy_pair_, is_https_));
320 host_port_proxy_pair_)); 387 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
321 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(&factory_, server2)); 388 &factory_, server2, is_https_));
322 389
323 TestCompletionCallback callback3; 390 TestCompletionCallback callback3;
324 QuicStreamRequest request3(&factory_); 391 QuicStreamRequest request3(&factory_);
325 EXPECT_EQ(OK, 392 EXPECT_EQ(OK,
326 request3.Request(server2, 393 request3.Request(server2,
327 is_https_, 394 is_https_,
328 "GET", 395 "GET",
329 cert_verifier_.get(), 396 cert_verifier_.get(),
330 net_log_, 397 net_log_,
331 callback3.callback())); 398 callback3.callback()));
332 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream(); 399 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
333 EXPECT_TRUE(stream3.get()); 400 EXPECT_TRUE(stream3.get());
334 401
335 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_, server2)); 402 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(
403 &factory_, server2, is_https_));
336 404
337 EXPECT_TRUE(socket_data1.at_read_eof()); 405 EXPECT_TRUE(socket_data1.at_read_eof());
338 EXPECT_TRUE(socket_data1.at_write_eof()); 406 EXPECT_TRUE(socket_data1.at_write_eof());
339 EXPECT_TRUE(socket_data2.at_read_eof()); 407 EXPECT_TRUE(socket_data2.at_read_eof());
340 EXPECT_TRUE(socket_data2.at_write_eof()); 408 EXPECT_TRUE(socket_data2.at_write_eof());
341 } 409 }
342 410
343 TEST_P(QuicStreamFactoryTest, HttpsPooling) { 411 TEST_P(QuicStreamFactoryTest, HttpsPooling) {
344 MockRead reads[] = { 412 MockRead reads[] = {
345 MockRead(ASYNC, OK, 0) // EOF 413 MockRead(ASYNC, OK, 0) // EOF
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 EXPECT_EQ(OK, 456 EXPECT_EQ(OK,
389 request2.Request(server2, 457 request2.Request(server2,
390 is_https_, 458 is_https_,
391 "GET", 459 "GET",
392 cert_verifier_.get(), 460 cert_verifier_.get(),
393 net_log_, 461 net_log_,
394 callback_.callback())); 462 callback_.callback()));
395 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); 463 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
396 EXPECT_TRUE(stream2.get()); 464 EXPECT_TRUE(stream2.get());
397 465
398 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession(&factory_, server1), 466 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession(
399 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2)); 467 &factory_, server1, is_https_),
468 QuicStreamFactoryPeer::GetActiveSession(
469 &factory_, server2, is_https_));
400 470
401 EXPECT_TRUE(socket_data.at_read_eof()); 471 EXPECT_TRUE(socket_data.at_read_eof());
402 EXPECT_TRUE(socket_data.at_write_eof()); 472 EXPECT_TRUE(socket_data.at_write_eof());
403 } 473 }
404 474
405 TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithCertMismatch) { 475 TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithCertMismatch) {
406 MockRead reads[] = { 476 MockRead reads[] = {
407 MockRead(ASYNC, OK, 0) // EOF 477 MockRead(ASYNC, OK, 0) // EOF
408 }; 478 };
409 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); 479 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 EXPECT_EQ(OK, 524 EXPECT_EQ(OK,
455 request2.Request(server2, 525 request2.Request(server2,
456 is_https_, 526 is_https_,
457 "GET", 527 "GET",
458 cert_verifier_.get(), 528 cert_verifier_.get(),
459 net_log_, 529 net_log_,
460 callback_.callback())); 530 callback_.callback()));
461 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); 531 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
462 EXPECT_TRUE(stream2.get()); 532 EXPECT_TRUE(stream2.get());
463 533
464 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(&factory_, server1), 534 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
465 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2)); 535 &factory_, server1, is_https_),
536 QuicStreamFactoryPeer::GetActiveSession(
537 &factory_, server2, is_https_));
466 538
467 EXPECT_TRUE(socket_data1.at_read_eof()); 539 EXPECT_TRUE(socket_data1.at_read_eof());
468 EXPECT_TRUE(socket_data1.at_write_eof()); 540 EXPECT_TRUE(socket_data1.at_write_eof());
469 EXPECT_TRUE(socket_data2.at_read_eof()); 541 EXPECT_TRUE(socket_data2.at_read_eof());
470 EXPECT_TRUE(socket_data2.at_write_eof()); 542 EXPECT_TRUE(socket_data2.at_write_eof());
471 } 543 }
472 544
473 TEST_P(QuicStreamFactoryTest, Goaway) { 545 TEST_P(QuicStreamFactoryTest, Goaway) {
474 MockRead reads[] = { 546 MockRead reads[] = {
475 MockRead(ASYNC, OK, 0) // EOF 547 MockRead(ASYNC, OK, 0) // EOF
(...skipping 14 matching lines...) Expand all
490 net_log_, 562 net_log_,
491 callback_.callback())); 563 callback_.callback()));
492 564
493 EXPECT_EQ(OK, callback_.WaitForResult()); 565 EXPECT_EQ(OK, callback_.WaitForResult());
494 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); 566 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
495 EXPECT_TRUE(stream.get()); 567 EXPECT_TRUE(stream.get());
496 568
497 // Mark the session as going away. Ensure that while it is still alive 569 // Mark the session as going away. Ensure that while it is still alive
498 // that it is no longer active. 570 // that it is no longer active.
499 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( 571 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
500 &factory_, host_port_proxy_pair_); 572 &factory_, host_port_proxy_pair_, is_https_);
501 factory_.OnSessionGoingAway(session); 573 factory_.OnSessionGoingAway(session);
502 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); 574 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session));
503 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(&factory_, 575 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
504 host_port_proxy_pair_)); 576 &factory_, host_port_proxy_pair_, is_https_));
505 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(host_port_proxy_pair_, 577 EXPECT_EQ(NULL, CreateIfSessionExists(host_port_proxy_pair_, net_log_).get());
506 net_log_).get());
507 578
508 // Create a new request for the same destination and verify that a 579 // Create a new request for the same destination and verify that a
509 // new session is created. 580 // new session is created.
510 QuicStreamRequest request2(&factory_); 581 QuicStreamRequest request2(&factory_);
511 EXPECT_EQ(ERR_IO_PENDING, 582 EXPECT_EQ(ERR_IO_PENDING,
512 request2.Request(host_port_proxy_pair_, 583 request2.Request(host_port_proxy_pair_,
513 is_https_, 584 is_https_,
514 "GET", 585 "GET",
515 cert_verifier_.get(), 586 cert_verifier_.get(),
516 net_log_, 587 net_log_,
517 callback_.callback())); 588 callback_.callback()));
518 EXPECT_EQ(OK, callback_.WaitForResult()); 589 EXPECT_EQ(OK, callback_.WaitForResult());
519 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); 590 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
520 EXPECT_TRUE(stream2.get()); 591 EXPECT_TRUE(stream2.get());
521 592
522 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_, 593 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_,
523 host_port_proxy_pair_)); 594 host_port_proxy_pair_,
595 is_https_));
524 EXPECT_NE(session, 596 EXPECT_NE(session,
525 QuicStreamFactoryPeer::GetActiveSession( 597 QuicStreamFactoryPeer::GetActiveSession(
526 &factory_, host_port_proxy_pair_)); 598 &factory_, host_port_proxy_pair_, is_https_));
527 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); 599 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session));
528 600
529 stream2.reset(); 601 stream2.reset();
530 stream.reset(); 602 stream.reset();
531 603
532 EXPECT_TRUE(socket_data.at_read_eof()); 604 EXPECT_TRUE(socket_data.at_read_eof());
533 EXPECT_TRUE(socket_data.at_write_eof()); 605 EXPECT_TRUE(socket_data.at_write_eof());
534 EXPECT_TRUE(socket_data2.at_read_eof()); 606 EXPECT_TRUE(socket_data2.at_read_eof());
535 EXPECT_TRUE(socket_data2.at_write_eof()); 607 EXPECT_TRUE(socket_data2.at_write_eof());
536 } 608 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 cert_verifier_.get(), 730 cert_verifier_.get(),
659 net_log_, 731 net_log_,
660 callback_.callback())); 732 callback_.callback()));
661 } 733 }
662 734
663 socket_data.StopAfter(1); 735 socket_data.StopAfter(1);
664 base::RunLoop run_loop; 736 base::RunLoop run_loop;
665 run_loop.RunUntilIdle(); 737 run_loop.RunUntilIdle();
666 738
667 scoped_ptr<QuicHttpStream> stream( 739 scoped_ptr<QuicHttpStream> stream(
668 factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_)); 740 CreateIfSessionExists(host_port_proxy_pair_, net_log_));
669 EXPECT_TRUE(stream.get()); 741 EXPECT_TRUE(stream.get());
670 stream.reset(); 742 stream.reset();
671 743
672 EXPECT_TRUE(socket_data.at_read_eof()); 744 EXPECT_TRUE(socket_data.at_read_eof());
673 EXPECT_TRUE(socket_data.at_write_eof()); 745 EXPECT_TRUE(socket_data.at_write_eof());
674 } 746 }
675 747
676 TEST_P(QuicStreamFactoryTest, CreateConsistentEphemeralPort) { 748 TEST_P(QuicStreamFactoryTest, CreateConsistentEphemeralPort) {
677 // Sequentially connect to the default host, then another host, and then the 749 // Sequentially connect to the default host, then another host, and then the
678 // default host. Verify that the default host gets a consistent ephemeral 750 // default host. Verify that the default host gets a consistent ephemeral
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { 1038 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) {
967 string r1_host_name("r1"); 1039 string r1_host_name("r1");
968 string r2_host_name("r2"); 1040 string r2_host_name("r2");
969 r1_host_name.append(cannoncial_suffixes[i]); 1041 r1_host_name.append(cannoncial_suffixes[i]);
970 r2_host_name.append(cannoncial_suffixes[i]); 1042 r2_host_name.append(cannoncial_suffixes[i]);
971 1043
972 HostPortProxyPair host_port_proxy_pair1(HostPortPair(r1_host_name, 80), 1044 HostPortProxyPair host_port_proxy_pair1(HostPortPair(r1_host_name, 80),
973 ProxyServer::Direct()); 1045 ProxyServer::Direct());
974 1046
975 QuicCryptoClientConfig* crypto_config1 = 1047 QuicCryptoClientConfig* crypto_config1 =
976 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_, 1048 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(
977 host_port_proxy_pair1); 1049 &factory_, host_port_proxy_pair1, is_https_);
978 DCHECK(crypto_config1); 1050 DCHECK(crypto_config1);
979 QuicCryptoClientConfig::CachedState* cached1 = 1051 QuicCryptoClientConfig::CachedState* cached1 =
980 crypto_config1->LookupOrCreate(host_port_proxy_pair1.first.host()); 1052 crypto_config1->LookupOrCreate(host_port_proxy_pair1.first.host());
981 EXPECT_FALSE(cached1->proof_valid()); 1053 EXPECT_FALSE(cached1->proof_valid());
982 EXPECT_TRUE(cached1->source_address_token().empty()); 1054 EXPECT_TRUE(cached1->source_address_token().empty());
983 1055
984 // Mutate the cached1 to have different data. 1056 // Mutate the cached1 to have different data.
985 // TODO(rtenneti): mutate other members of CachedState. 1057 // TODO(rtenneti): mutate other members of CachedState.
986 cached1->set_source_address_token(r1_host_name); 1058 cached1->set_source_address_token(r1_host_name);
987 cached1->SetProofValid(); 1059 cached1->SetProofValid();
988 1060
989 HostPortProxyPair host_port_proxy_pair2(HostPortPair(r2_host_name, 80), 1061 HostPortProxyPair host_port_proxy_pair2(HostPortPair(r2_host_name, 80),
990 ProxyServer::Direct()); 1062 ProxyServer::Direct());
991 QuicCryptoClientConfig* crypto_config2 = 1063 QuicCryptoClientConfig* crypto_config2 =
992 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_, 1064 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(
993 host_port_proxy_pair2); 1065 &factory_, host_port_proxy_pair2, is_https_);
994 DCHECK(crypto_config2); 1066 DCHECK(crypto_config2);
995 QuicCryptoClientConfig::CachedState* cached2 = 1067 QuicCryptoClientConfig::CachedState* cached2 =
996 crypto_config2->LookupOrCreate(host_port_proxy_pair2.first.host()); 1068 crypto_config2->LookupOrCreate(host_port_proxy_pair2.first.host());
997 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); 1069 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token());
998 EXPECT_TRUE(cached2->proof_valid()); 1070 EXPECT_TRUE(cached2->proof_valid());
999 } 1071 }
1000 } 1072 }
1001 1073
1002 TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { 1074 TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) {
1003 vector<string> cannoncial_suffixes; 1075 vector<string> cannoncial_suffixes;
1004 cannoncial_suffixes.push_back(string(".c.youtube.com")); 1076 cannoncial_suffixes.push_back(string(".c.youtube.com"));
1005 cannoncial_suffixes.push_back(string(".googlevideo.com")); 1077 cannoncial_suffixes.push_back(string(".googlevideo.com"));
1006 1078
1007 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { 1079 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) {
1008 string r3_host_name("r3"); 1080 string r3_host_name("r3");
1009 string r4_host_name("r4"); 1081 string r4_host_name("r4");
1010 r3_host_name.append(cannoncial_suffixes[i]); 1082 r3_host_name.append(cannoncial_suffixes[i]);
1011 r4_host_name.append(cannoncial_suffixes[i]); 1083 r4_host_name.append(cannoncial_suffixes[i]);
1012 1084
1013 HostPortProxyPair host_port_proxy_pair1(HostPortPair(r3_host_name, 80), 1085 HostPortProxyPair host_port_proxy_pair1(HostPortPair(r3_host_name, 80),
1014 ProxyServer::Direct()); 1086 ProxyServer::Direct());
1015 1087
1016 QuicCryptoClientConfig* crypto_config1 = 1088 QuicCryptoClientConfig* crypto_config1 =
1017 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_, 1089 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(
1018 host_port_proxy_pair1); 1090 &factory_, host_port_proxy_pair1, is_https_);
1019 DCHECK(crypto_config1); 1091 DCHECK(crypto_config1);
1020 QuicCryptoClientConfig::CachedState* cached1 = 1092 QuicCryptoClientConfig::CachedState* cached1 =
1021 crypto_config1->LookupOrCreate(host_port_proxy_pair1.first.host()); 1093 crypto_config1->LookupOrCreate(host_port_proxy_pair1.first.host());
1022 EXPECT_FALSE(cached1->proof_valid()); 1094 EXPECT_FALSE(cached1->proof_valid());
1023 EXPECT_TRUE(cached1->source_address_token().empty()); 1095 EXPECT_TRUE(cached1->source_address_token().empty());
1024 1096
1025 // Mutate the cached1 to have different data. 1097 // Mutate the cached1 to have different data.
1026 // TODO(rtenneti): mutate other members of CachedState. 1098 // TODO(rtenneti): mutate other members of CachedState.
1027 cached1->set_source_address_token(r3_host_name); 1099 cached1->set_source_address_token(r3_host_name);
1028 cached1->SetProofInvalid(); 1100 cached1->SetProofInvalid();
1029 1101
1030 HostPortProxyPair host_port_proxy_pair2(HostPortPair(r4_host_name, 80), 1102 HostPortProxyPair host_port_proxy_pair2(HostPortPair(r4_host_name, 80),
1031 ProxyServer::Direct()); 1103 ProxyServer::Direct());
1032 QuicCryptoClientConfig* crypto_config2 = 1104 QuicCryptoClientConfig* crypto_config2 =
1033 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_, 1105 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(
1034 host_port_proxy_pair2); 1106 &factory_, host_port_proxy_pair2, is_https_);
1035 DCHECK(crypto_config2); 1107 DCHECK(crypto_config2);
1036 QuicCryptoClientConfig::CachedState* cached2 = 1108 QuicCryptoClientConfig::CachedState* cached2 =
1037 crypto_config2->LookupOrCreate(host_port_proxy_pair2.first.host()); 1109 crypto_config2->LookupOrCreate(host_port_proxy_pair2.first.host());
1038 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); 1110 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token());
1039 EXPECT_TRUE(cached2->source_address_token().empty()); 1111 EXPECT_TRUE(cached2->source_address_token().empty());
1040 EXPECT_FALSE(cached2->proof_valid()); 1112 EXPECT_FALSE(cached2->proof_valid());
1041 } 1113 }
1042 } 1114 }
1043 1115
1044 } // namespace test 1116 } // namespace test
1045 } // namespace net 1117 } // 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