blob: b8b323c465f82535210a64de6742dccee4d2703f [file] [log] [blame]
[email protected]e13201d82012-12-12 05:00:321// 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
3// found in the LICENSE file.
4
5#include "net/quic/quic_stream_factory.h"
6
[email protected]e13201d82012-12-12 05:00:327#include "base/run_loop.h"
[email protected]fc9be5802013-06-11 10:56:518#include "base/strings/string_util.h"
[email protected]eed749f92013-12-23 18:57:389#include "net/base/test_data_directory.h"
[email protected]6d1b4ed2013-07-10 03:57:5410#include "net/cert/cert_verifier.h"
[email protected]f2cb3cf2013-03-21 01:40:5311#include "net/dns/mock_host_resolver.h"
[email protected]e13201d82012-12-12 05:00:3212#include "net/http/http_response_headers.h"
13#include "net/http/http_response_info.h"
14#include "net/http/http_util.h"
[email protected]c49ff182013-09-28 08:33:2615#include "net/quic/crypto/crypto_handshake.h"
[email protected]4df69842013-02-27 06:32:1616#include "net/quic/crypto/quic_decrypter.h"
17#include "net/quic/crypto/quic_encrypter.h"
[email protected]e13201d82012-12-12 05:00:3218#include "net/quic/quic_http_stream.h"
19#include "net/quic/test_tools/mock_clock.h"
[email protected]e8ff26842013-03-22 21:02:0520#include "net/quic/test_tools/mock_crypto_client_stream_factory.h"
[email protected]9558c5d32012-12-22 00:08:1421#include "net/quic/test_tools/mock_random.h"
[email protected]1e960032013-12-20 19:00:2022#include "net/quic/test_tools/quic_test_packet_maker.h"
[email protected]e13201d82012-12-12 05:00:3223#include "net/quic/test_tools/quic_test_utils.h"
24#include "net/socket/socket_test_util.h"
[email protected]eed749f92013-12-23 18:57:3825#include "net/test/cert_test_util.h"
[email protected]e13201d82012-12-12 05:00:3226#include "testing/gtest/include/gtest/gtest.h"
27
[email protected]6e12d702013-11-13 00:17:1728using base::StringPiece;
29using std::string;
30using std::vector;
31
[email protected]e13201d82012-12-12 05:00:3232namespace net {
[email protected]e13201d82012-12-12 05:00:3233namespace test {
34
[email protected]3c772402013-12-18 21:38:1135namespace {
36const char kDefaultServerHostName[] = "www.google.com";
37const int kDefaultServerPort = 443;
38} // namespace anonymous
39
[email protected]c49ff182013-09-28 08:33:2640class QuicStreamFactoryPeer {
41 public:
42 static QuicCryptoClientConfig* GetOrCreateCryptoConfig(
43 QuicStreamFactory* factory,
44 const HostPortProxyPair& host_port_proxy_pair) {
45 return factory->GetOrCreateCryptoConfig(host_port_proxy_pair);
46 }
[email protected]4d283b32013-10-17 12:57:2747
48 static bool HasActiveSession(QuicStreamFactory* factory,
49 const HostPortProxyPair& host_port_proxy_pair) {
50 return factory->HasActiveSession(host_port_proxy_pair);
51 }
52
53 static QuicClientSession* GetActiveSession(
54 QuicStreamFactory* factory,
55 const HostPortProxyPair& host_port_proxy_pair) {
56 DCHECK(factory->HasActiveSession(host_port_proxy_pair));
57 return factory->active_sessions_[host_port_proxy_pair];
58 }
59
60 static bool IsLiveSession(QuicStreamFactory* factory,
61 QuicClientSession* session) {
62 for (QuicStreamFactory::SessionSet::iterator it =
63 factory->all_sessions_.begin();
64 it != factory->all_sessions_.end(); ++it) {
65 if (*it == session)
66 return true;
67 }
68 return false;
69 }
[email protected]c49ff182013-09-28 08:33:2670};
71
[email protected]1e960032013-12-20 19:00:2072class QuicStreamFactoryTest : public ::testing::TestWithParam<QuicVersion> {
[email protected]e13201d82012-12-12 05:00:3273 protected:
74 QuicStreamFactoryTest()
[email protected]457d6952013-12-13 09:24:5875 : random_generator_(0),
[email protected]1e960032013-12-20 19:00:2076 maker_(GetParam(), 0),
[email protected]457d6952013-12-13 09:24:5877 clock_(new MockClock()),
[email protected]872edd9e2013-01-16 08:51:1578 factory_(&host_resolver_, &socket_factory_,
[email protected]77c6c162013-08-17 02:57:4579 base::WeakPtr<HttpServerProperties>(),
[email protected]e8ff26842013-03-22 21:02:0580 &crypto_client_stream_factory_,
[email protected]1e960032013-12-20 19:00:2081 &random_generator_, clock_, kDefaultMaxPacketSize,
[email protected]c80f7c92014-02-27 13:12:0282 SupportedVersions(GetParam()), true, true),
[email protected]3c772402013-12-18 21:38:1183 host_port_proxy_pair_(HostPortPair(kDefaultServerHostName,
84 kDefaultServerPort),
[email protected]6d1b4ed2013-07-10 03:57:5485 ProxyServer::Direct()),
86 is_https_(false),
87 cert_verifier_(CertVerifier::CreateDefault()) {
[email protected]11c05872013-08-20 02:04:1288 factory_.set_require_confirmation(false);
[email protected]e13201d82012-12-12 05:00:3289 }
90
[email protected]e13201d82012-12-12 05:00:3291
[email protected]3c772402013-12-18 21:38:1192 int GetSourcePortForNewSession(const HostPortProxyPair& destination) {
93 // Should only be called if there is no active session for this destination.
94 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(destination,
95 net_log_).get());
96 size_t socket_count = socket_factory_.udp_client_sockets().size();
97
98 MockRead reads[] = {
99 MockRead(ASYNC, OK, 0) // EOF
100 };
101 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
102 socket_data.StopAfter(1);
103 socket_factory_.AddSocketDataProvider(&socket_data);
104
105 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59106 EXPECT_EQ(ERR_IO_PENDING,
107 request.Request(destination,
108 is_https_,
109 "GET",
110 cert_verifier_.get(),
111 net_log_,
112 callback_.callback()));
[email protected]3c772402013-12-18 21:38:11113
114 EXPECT_EQ(OK, callback_.WaitForResult());
115 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
116 EXPECT_TRUE(stream.get());
117 stream.reset();
118
119 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
120 &factory_, destination);
121
122 if (socket_count + 1 != socket_factory_.udp_client_sockets().size()) {
123 EXPECT_TRUE(false);
124 return 0;
125 }
126
127 IPEndPoint endpoint;
128 socket_factory_.
129 udp_client_sockets()[socket_count]->GetLocalAddress(&endpoint);
130 int port = endpoint.port();
131
132 factory_.OnSessionClosed(session);
133 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(destination,
134 net_log_).get());
135 EXPECT_TRUE(socket_data.at_read_eof());
136 EXPECT_TRUE(socket_data.at_write_eof());
137 return port;
138 }
139
[email protected]459a7402014-02-10 12:58:52140 scoped_ptr<QuicEncryptedPacket> ConstructRstPacket() {
[email protected]92bf17c2014-03-03 21:14:03141 QuicStreamId stream_id = 5;
[email protected]459a7402014-02-10 12:58:52142 return maker_.MakeRstPacket(1, true, stream_id, QUIC_STREAM_NO_ERROR);
143 }
144
[email protected]e13201d82012-12-12 05:00:32145 MockHostResolver host_resolver_;
[email protected]0edce6a2013-05-08 18:02:40146 DeterministicMockClientSocketFactory socket_factory_;
[email protected]e8ff26842013-03-22 21:02:05147 MockCryptoClientStreamFactory crypto_client_stream_factory_;
[email protected]9558c5d32012-12-22 00:08:14148 MockRandom random_generator_;
[email protected]1e960032013-12-20 19:00:20149 QuicTestPacketMaker maker_;
[email protected]872edd9e2013-01-16 08:51:15150 MockClock* clock_; // Owned by factory_.
[email protected]e13201d82012-12-12 05:00:32151 QuicStreamFactory factory_;
152 HostPortProxyPair host_port_proxy_pair_;
[email protected]6d1b4ed2013-07-10 03:57:54153 bool is_https_;
[email protected]ce542d52013-07-11 01:08:39154 scoped_ptr<CertVerifier> cert_verifier_;
[email protected]e13201d82012-12-12 05:00:32155 BoundNetLog net_log_;
156 TestCompletionCallback callback_;
[email protected]e13201d82012-12-12 05:00:32157};
158
[email protected]1e960032013-12-20 19:00:20159INSTANTIATE_TEST_CASE_P(Version, QuicStreamFactoryTest,
160 ::testing::ValuesIn(QuicSupportedVersions()));
161
162TEST_P(QuicStreamFactoryTest, CreateIfSessionExists) {
[email protected]e13201d82012-12-12 05:00:32163 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(host_port_proxy_pair_,
164 net_log_).get());
165}
166
[email protected]1e960032013-12-20 19:00:20167TEST_P(QuicStreamFactoryTest, Create) {
[email protected]69dfd1b2013-06-04 22:20:12168 MockRead reads[] = {
[email protected]25c31dc2013-06-05 17:56:04169 MockRead(ASYNC, OK, 0) // EOF
[email protected]69dfd1b2013-06-04 22:20:12170 };
[email protected]25c31dc2013-06-05 17:56:04171 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
[email protected]e13201d82012-12-12 05:00:32172 socket_factory_.AddSocketDataProvider(&socket_data);
[email protected]25c31dc2013-06-05 17:56:04173 socket_data.StopAfter(1);
[email protected]e13201d82012-12-12 05:00:32174
175 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59176 EXPECT_EQ(ERR_IO_PENDING,
177 request.Request(host_port_proxy_pair_,
178 is_https_,
179 "GET",
180 cert_verifier_.get(),
181 net_log_,
182 callback_.callback()));
[email protected]e13201d82012-12-12 05:00:32183
184 EXPECT_EQ(OK, callback_.WaitForResult());
185 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
[email protected]0edce6a2013-05-08 18:02:40186 EXPECT_TRUE(stream.get());
[email protected]e13201d82012-12-12 05:00:32187
188 // Will reset stream 3.
189 stream = factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_);
190 EXPECT_TRUE(stream.get());
191
[email protected]6d1b4ed2013-07-10 03:57:54192 // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result
193 // in streams on different sessions.
[email protected]e13201d82012-12-12 05:00:32194 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59195 EXPECT_EQ(OK,
196 request2.Request(host_port_proxy_pair_,
197 is_https_,
198 "GET",
199 cert_verifier_.get(),
200 net_log_,
201 callback_.callback()));
[email protected]e13201d82012-12-12 05:00:32202 stream = request2.ReleaseStream(); // Will reset stream 5.
203 stream.reset(); // Will reset stream 7.
204
205 EXPECT_TRUE(socket_data.at_read_eof());
206 EXPECT_TRUE(socket_data.at_write_eof());
207}
208
[email protected]eed749f92013-12-23 18:57:38209TEST_P(QuicStreamFactoryTest, Pooling) {
210 MockRead reads[] = {
211 MockRead(ASYNC, OK, 0) // EOF
212 };
213 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
214 socket_factory_.AddSocketDataProvider(&socket_data);
215 socket_data.StopAfter(1);
216
217 HostPortProxyPair server2 = HostPortProxyPair(
218 HostPortPair("mail.google.com", kDefaultServerPort),
219 host_port_proxy_pair_.second);
220
221 host_resolver_.set_synchronous_mode(true);
222 host_resolver_.rules()->AddIPLiteralRule(
223 kDefaultServerHostName, "192.168.0.1", "");
224 host_resolver_.rules()->AddIPLiteralRule(
225 "mail.google.com", "192.168.0.1", "");
226
227 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59228 EXPECT_EQ(OK,
229 request.Request(host_port_proxy_pair_,
230 is_https_,
231 "GET",
232 cert_verifier_.get(),
233 net_log_,
234 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38235 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
236 EXPECT_TRUE(stream.get());
237
238 TestCompletionCallback callback;
239 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59240 EXPECT_EQ(OK,
241 request2.Request(server2,
242 is_https_,
243 "GET",
244 cert_verifier_.get(),
245 net_log_,
246 callback.callback()));
[email protected]eed749f92013-12-23 18:57:38247 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
248 EXPECT_TRUE(stream2.get());
249
250 EXPECT_EQ(
251 QuicStreamFactoryPeer::GetActiveSession(&factory_, host_port_proxy_pair_),
252 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2));
253
254 EXPECT_TRUE(socket_data.at_read_eof());
255 EXPECT_TRUE(socket_data.at_write_eof());
256}
257
258TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) {
259 MockRead reads[] = {
260 MockRead(ASYNC, OK, 0) // EOF
261 };
262 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0);
263 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0);
264 socket_factory_.AddSocketDataProvider(&socket_data1);
265 socket_factory_.AddSocketDataProvider(&socket_data2);
266 socket_data1.StopAfter(1);
267 socket_data2.StopAfter(1);
268
269 HostPortProxyPair server2 = HostPortProxyPair(
270 HostPortPair("mail.google.com", kDefaultServerPort),
271 host_port_proxy_pair_.second);
272
273 host_resolver_.set_synchronous_mode(true);
274 host_resolver_.rules()->AddIPLiteralRule(
275 kDefaultServerHostName, "192.168.0.1", "");
276 host_resolver_.rules()->AddIPLiteralRule(
277 "mail.google.com", "192.168.0.1", "");
278
279 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59280 EXPECT_EQ(OK,
281 request.Request(host_port_proxy_pair_,
282 is_https_,
283 "GET",
284 cert_verifier_.get(),
285 net_log_,
286 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38287 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
288 EXPECT_TRUE(stream.get());
289
290 TestCompletionCallback callback;
291 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59292 EXPECT_EQ(OK,
293 request2.Request(server2,
294 is_https_,
295 "GET",
296 cert_verifier_.get(),
297 net_log_,
298 callback.callback()));
[email protected]eed749f92013-12-23 18:57:38299 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
300 EXPECT_TRUE(stream2.get());
301
302 factory_.OnSessionGoingAway(
303 QuicStreamFactoryPeer::GetActiveSession(&factory_,
304 host_port_proxy_pair_));
305 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(&factory_,
306 host_port_proxy_pair_));
307 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(&factory_, server2));
308
309 TestCompletionCallback callback3;
310 QuicStreamRequest request3(&factory_);
[email protected]974849d2014-02-06 01:32:59311 EXPECT_EQ(OK,
312 request3.Request(server2,
313 is_https_,
314 "GET",
315 cert_verifier_.get(),
316 net_log_,
317 callback3.callback()));
[email protected]eed749f92013-12-23 18:57:38318 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
319 EXPECT_TRUE(stream3.get());
320
321 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_, server2));
322
323 EXPECT_TRUE(socket_data1.at_read_eof());
324 EXPECT_TRUE(socket_data1.at_write_eof());
325 EXPECT_TRUE(socket_data2.at_read_eof());
326 EXPECT_TRUE(socket_data2.at_write_eof());
327}
328
329TEST_P(QuicStreamFactoryTest, HttpsPooling) {
330 MockRead reads[] = {
331 MockRead(ASYNC, OK, 0) // EOF
332 };
333 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
334 socket_factory_.AddSocketDataProvider(&socket_data);
335 socket_data.StopAfter(1);
336
337 HostPortProxyPair server1(HostPortPair("www.example.org", 443),
338 ProxyServer::Direct());
339 HostPortProxyPair server2(HostPortPair("mail.example.org", 443),
340 ProxyServer::Direct());
341
342 // Load a cert that is valid for:
343 // www.example.org (server1)
344 // mail.example.org (server2)
345 // www.example.com
346 base::FilePath certs_dir = GetTestCertsDirectory();
347 scoped_refptr<X509Certificate> test_cert(
348 ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
349 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert);
350 SSLInfo ssl_info;
351 ssl_info.cert = test_cert.get();
352 crypto_client_stream_factory_.set_ssl_info(&ssl_info);
353
354 host_resolver_.set_synchronous_mode(true);
355 host_resolver_.rules()->AddIPLiteralRule(
356 server1.first.host(), "192.168.0.1", "");
357 host_resolver_.rules()->AddIPLiteralRule(
358 server2.first.host(), "192.168.0.1", "");
359
360 QuicStreamRequest request(&factory_);
361 is_https_ = true;
[email protected]974849d2014-02-06 01:32:59362 EXPECT_EQ(OK,
363 request.Request(server1,
364 is_https_,
365 "GET",
366 cert_verifier_.get(),
367 net_log_,
368 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38369 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
370 EXPECT_TRUE(stream.get());
371
372 TestCompletionCallback callback;
373 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59374 EXPECT_EQ(OK,
375 request2.Request(server2,
376 is_https_,
377 "GET",
378 cert_verifier_.get(),
379 net_log_,
380 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38381 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
382 EXPECT_TRUE(stream2.get());
383
384 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession(&factory_, server1),
385 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2));
386
387 EXPECT_TRUE(socket_data.at_read_eof());
388 EXPECT_TRUE(socket_data.at_write_eof());
389}
390
391TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithCertMismatch) {
392 MockRead reads[] = {
393 MockRead(ASYNC, OK, 0) // EOF
394 };
395 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0);
396 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0);
397 socket_factory_.AddSocketDataProvider(&socket_data1);
398 socket_factory_.AddSocketDataProvider(&socket_data2);
399 socket_data1.StopAfter(1);
400 socket_data2.StopAfter(1);
401
402 HostPortProxyPair server1(HostPortPair("www.example.org", 443),
403 ProxyServer::Direct());
404 HostPortProxyPair server2(HostPortPair("mail.google.com", 443),
405 ProxyServer::Direct());
406
407 // Load a cert that is valid for:
408 // www.example.org (server1)
409 // mail.example.org
410 // www.example.com
411 // But is not valid for mail.google.com (server2).
412 base::FilePath certs_dir = GetTestCertsDirectory();
413 scoped_refptr<X509Certificate> test_cert(
414 ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
415 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert);
416 SSLInfo ssl_info;
417 ssl_info.cert = test_cert.get();
418 crypto_client_stream_factory_.set_ssl_info(&ssl_info);
419
420 host_resolver_.set_synchronous_mode(true);
421 host_resolver_.rules()->AddIPLiteralRule(
422 server1.first.host(), "192.168.0.1", "");
423 host_resolver_.rules()->AddIPLiteralRule(
424 server2.first.host(), "192.168.0.1", "");
425
426 QuicStreamRequest request(&factory_);
427 is_https_ = true;
[email protected]974849d2014-02-06 01:32:59428 EXPECT_EQ(OK,
429 request.Request(server1,
430 is_https_,
431 "GET",
432 cert_verifier_.get(),
433 net_log_,
434 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38435 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
436 EXPECT_TRUE(stream.get());
437
438 TestCompletionCallback callback;
439 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59440 EXPECT_EQ(OK,
441 request2.Request(server2,
442 is_https_,
443 "GET",
444 cert_verifier_.get(),
445 net_log_,
446 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38447 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
448 EXPECT_TRUE(stream2.get());
449
450 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(&factory_, server1),
451 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2));
452
453 EXPECT_TRUE(socket_data1.at_read_eof());
454 EXPECT_TRUE(socket_data1.at_write_eof());
455 EXPECT_TRUE(socket_data2.at_read_eof());
456 EXPECT_TRUE(socket_data2.at_write_eof());
457}
458
[email protected]1e960032013-12-20 19:00:20459TEST_P(QuicStreamFactoryTest, Goaway) {
[email protected]4d283b32013-10-17 12:57:27460 MockRead reads[] = {
461 MockRead(ASYNC, OK, 0) // EOF
462 };
463 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
464 socket_data.StopAfter(1);
465 socket_factory_.AddSocketDataProvider(&socket_data);
466 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0);
467 socket_data2.StopAfter(1);
468 socket_factory_.AddSocketDataProvider(&socket_data2);
469
470 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59471 EXPECT_EQ(ERR_IO_PENDING,
472 request.Request(host_port_proxy_pair_,
473 is_https_,
474 "GET",
475 cert_verifier_.get(),
476 net_log_,
477 callback_.callback()));
[email protected]4d283b32013-10-17 12:57:27478
479 EXPECT_EQ(OK, callback_.WaitForResult());
480 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
481 EXPECT_TRUE(stream.get());
482
483 // Mark the session as going away. Ensure that while it is still alive
484 // that it is no longer active.
485 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
486 &factory_, host_port_proxy_pair_);
487 factory_.OnSessionGoingAway(session);
488 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session));
489 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(&factory_,
490 host_port_proxy_pair_));
491 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(host_port_proxy_pair_,
492 net_log_).get());
493
494 // Create a new request for the same destination and verify that a
495 // new session is created.
496 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59497 EXPECT_EQ(ERR_IO_PENDING,
498 request2.Request(host_port_proxy_pair_,
499 is_https_,
500 "GET",
501 cert_verifier_.get(),
502 net_log_,
503 callback_.callback()));
[email protected]4d283b32013-10-17 12:57:27504 EXPECT_EQ(OK, callback_.WaitForResult());
505 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
506 EXPECT_TRUE(stream2.get());
507
508 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_,
509 host_port_proxy_pair_));
510 EXPECT_NE(session,
511 QuicStreamFactoryPeer::GetActiveSession(
512 &factory_, host_port_proxy_pair_));
513 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session));
514
515 stream2.reset();
516 stream.reset();
517
518 EXPECT_TRUE(socket_data.at_read_eof());
519 EXPECT_TRUE(socket_data.at_write_eof());
[email protected]3c772402013-12-18 21:38:11520 EXPECT_TRUE(socket_data2.at_read_eof());
521 EXPECT_TRUE(socket_data2.at_write_eof());
[email protected]4d283b32013-10-17 12:57:27522}
523
[email protected]1e960032013-12-20 19:00:20524TEST_P(QuicStreamFactoryTest, MaxOpenStream) {
[email protected]0b2294d32013-08-02 00:46:36525 MockRead reads[] = {
526 MockRead(ASYNC, OK, 0) // EOF
527 };
[email protected]92bf17c2014-03-03 21:14:03528 QuicStreamId stream_id = 5;
[email protected]1e960032013-12-20 19:00:20529 scoped_ptr<QuicEncryptedPacket> rst(
530 maker_.MakeRstPacket(1, true, stream_id, QUIC_STREAM_CANCELLED));
[email protected]06ff5152013-08-29 01:03:05531 MockWrite writes[] = {
532 MockWrite(ASYNC, rst->data(), rst->length(), 1),
533 };
534 DeterministicSocketData socket_data(reads, arraysize(reads),
535 writes, arraysize(writes));
[email protected]0b2294d32013-08-02 00:46:36536 socket_factory_.AddSocketDataProvider(&socket_data);
537 socket_data.StopAfter(1);
538
539 HttpRequestInfo request_info;
540 std::vector<QuicHttpStream*> streams;
541 // The MockCryptoClientStream sets max_open_streams to be
542 // 2 * kDefaultMaxStreamsPerConnection.
543 for (size_t i = 0; i < 2 * kDefaultMaxStreamsPerConnection; i++) {
544 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59545 int rv = request.Request(host_port_proxy_pair_,
546 is_https_,
547 "GET",
548 cert_verifier_.get(),
549 net_log_,
[email protected]0b2294d32013-08-02 00:46:36550 callback_.callback());
551 if (i == 0) {
552 EXPECT_EQ(ERR_IO_PENDING, rv);
553 EXPECT_EQ(OK, callback_.WaitForResult());
554 } else {
555 EXPECT_EQ(OK, rv);
556 }
557 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
558 EXPECT_TRUE(stream);
559 EXPECT_EQ(OK, stream->InitializeStream(
560 &request_info, DEFAULT_PRIORITY, net_log_, CompletionCallback()));
561 streams.push_back(stream.release());
562 }
563
564 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59565 EXPECT_EQ(OK,
566 request.Request(host_port_proxy_pair_,
567 is_https_,
568 "GET",
569 cert_verifier_.get(),
570 net_log_,
571 CompletionCallback()));
[email protected]0b2294d32013-08-02 00:46:36572 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
573 EXPECT_TRUE(stream);
574 EXPECT_EQ(ERR_IO_PENDING, stream->InitializeStream(
575 &request_info, DEFAULT_PRIORITY, net_log_, callback_.callback()));
576
577 // Close the first stream.
578 streams.front()->Close(false);
579
580 ASSERT_TRUE(callback_.have_result());
581
582 EXPECT_EQ(OK, callback_.WaitForResult());
583
584 EXPECT_TRUE(socket_data.at_read_eof());
585 EXPECT_TRUE(socket_data.at_write_eof());
586 STLDeleteElements(&streams);
587}
588
[email protected]1e960032013-12-20 19:00:20589TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) {
[email protected]0edce6a2013-05-08 18:02:40590 DeterministicSocketData socket_data(NULL, 0, NULL, 0);
[email protected]e13201d82012-12-12 05:00:32591 socket_factory_.AddSocketDataProvider(&socket_data);
592
[email protected]3c772402013-12-18 21:38:11593 host_resolver_.rules()->AddSimulatedFailure(kDefaultServerHostName);
[email protected]e13201d82012-12-12 05:00:32594
595 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59596 EXPECT_EQ(ERR_IO_PENDING,
597 request.Request(host_port_proxy_pair_,
598 is_https_,
599 "GET",
600 cert_verifier_.get(),
601 net_log_,
602 callback_.callback()));
[email protected]e13201d82012-12-12 05:00:32603
604 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult());
605
606 EXPECT_TRUE(socket_data.at_read_eof());
607 EXPECT_TRUE(socket_data.at_write_eof());
608}
609
[email protected]1e960032013-12-20 19:00:20610TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) {
[email protected]3c772402013-12-18 21:38:11611 MockConnect connect(SYNCHRONOUS, ERR_ADDRESS_IN_USE);
612 DeterministicSocketData socket_data(NULL, 0, NULL, 0);
613 socket_data.set_connect_data(connect);
614 socket_factory_.AddSocketDataProvider(&socket_data);
615 socket_data.StopAfter(1);
616
617 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59618 EXPECT_EQ(ERR_IO_PENDING,
619 request.Request(host_port_proxy_pair_,
620 is_https_,
621 "GET",
622 cert_verifier_.get(),
623 net_log_,
624 callback_.callback()));
[email protected]3c772402013-12-18 21:38:11625
626 EXPECT_EQ(ERR_ADDRESS_IN_USE, callback_.WaitForResult());
627
628 EXPECT_TRUE(socket_data.at_read_eof());
629 EXPECT_TRUE(socket_data.at_write_eof());
630}
631
[email protected]1e960032013-12-20 19:00:20632TEST_P(QuicStreamFactoryTest, CancelCreate) {
[email protected]69dfd1b2013-06-04 22:20:12633 MockRead reads[] = {
[email protected]25c31dc2013-06-05 17:56:04634 MockRead(ASYNC, OK, 0) // EOF
[email protected]69dfd1b2013-06-04 22:20:12635 };
[email protected]25c31dc2013-06-05 17:56:04636 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
[email protected]e13201d82012-12-12 05:00:32637 socket_factory_.AddSocketDataProvider(&socket_data);
638 {
639 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59640 EXPECT_EQ(ERR_IO_PENDING,
641 request.Request(host_port_proxy_pair_,
642 is_https_,
643 "GET",
644 cert_verifier_.get(),
645 net_log_,
646 callback_.callback()));
[email protected]e13201d82012-12-12 05:00:32647 }
648
[email protected]25c31dc2013-06-05 17:56:04649 socket_data.StopAfter(1);
[email protected]e13201d82012-12-12 05:00:32650 base::RunLoop run_loop;
651 run_loop.RunUntilIdle();
652
653 scoped_ptr<QuicHttpStream> stream(
654 factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_));
655 EXPECT_TRUE(stream.get());
656 stream.reset();
657
658 EXPECT_TRUE(socket_data.at_read_eof());
659 EXPECT_TRUE(socket_data.at_write_eof());
660}
661
[email protected]1e960032013-12-20 19:00:20662TEST_P(QuicStreamFactoryTest, CreateConsistentEphemeralPort) {
[email protected]3c772402013-12-18 21:38:11663 // Sequentially connect to the default host, then another host, and then the
664 // default host. Verify that the default host gets a consistent ephemeral
665 // port, that is different from the other host's connection.
666
667 std::string other_server_name = "other.google.com";
668 EXPECT_NE(kDefaultServerHostName, other_server_name);
669 HostPortPair host_port_pair2(other_server_name, kDefaultServerPort);
670 HostPortProxyPair host_port_proxy_pair2(host_port_pair2,
671 host_port_proxy_pair_.second);
672
673 int original_port = GetSourcePortForNewSession(host_port_proxy_pair_);
674 EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_proxy_pair2));
675 EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_proxy_pair_));
676}
677
[email protected]1e960032013-12-20 19:00:20678TEST_P(QuicStreamFactoryTest, CloseAllSessions) {
[email protected]56dfb902013-01-03 23:17:55679 MockRead reads[] = {
[email protected]0edce6a2013-05-08 18:02:40680 MockRead(ASYNC, 0, 0) // EOF
[email protected]56dfb902013-01-03 23:17:55681 };
[email protected]459a7402014-02-10 12:58:52682 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
683 std::vector<MockWrite> writes;
684 if (GetParam() > QUIC_VERSION_13)
685 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
686 DeterministicSocketData socket_data(reads, arraysize(reads),
687 writes.empty() ? NULL : &writes[0],
688 writes.size());
[email protected]56dfb902013-01-03 23:17:55689 socket_factory_.AddSocketDataProvider(&socket_data);
[email protected]0edce6a2013-05-08 18:02:40690 socket_data.StopAfter(1);
[email protected]56dfb902013-01-03 23:17:55691
[email protected]69dfd1b2013-06-04 22:20:12692 MockRead reads2[] = {
[email protected]25c31dc2013-06-05 17:56:04693 MockRead(ASYNC, 0, 0) // EOF
[email protected]69dfd1b2013-06-04 22:20:12694 };
[email protected]25c31dc2013-06-05 17:56:04695 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0);
[email protected]56dfb902013-01-03 23:17:55696 socket_factory_.AddSocketDataProvider(&socket_data2);
[email protected]0edce6a2013-05-08 18:02:40697 socket_data2.StopAfter(1);
[email protected]56dfb902013-01-03 23:17:55698
699 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59700 EXPECT_EQ(ERR_IO_PENDING,
701 request.Request(host_port_proxy_pair_,
702 is_https_,
703 "GET",
704 cert_verifier_.get(),
705 net_log_,
706 callback_.callback()));
[email protected]56dfb902013-01-03 23:17:55707
708 EXPECT_EQ(OK, callback_.WaitForResult());
709 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
[email protected]0b2294d32013-08-02 00:46:36710 HttpRequestInfo request_info;
711 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
712 DEFAULT_PRIORITY,
713 net_log_, CompletionCallback()));
[email protected]56dfb902013-01-03 23:17:55714
715 // Close the session and verify that stream saw the error.
716 factory_.CloseAllSessions(ERR_INTERNET_DISCONNECTED);
717 EXPECT_EQ(ERR_INTERNET_DISCONNECTED,
718 stream->ReadResponseHeaders(callback_.callback()));
719
720 // Now attempting to request a stream to the same origin should create
721 // a new session.
722
723 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59724 EXPECT_EQ(ERR_IO_PENDING,
725 request2.Request(host_port_proxy_pair_,
726 is_https_,
727 "GET",
728 cert_verifier_.get(),
729 net_log_,
730 callback_.callback()));
[email protected]56dfb902013-01-03 23:17:55731
732 EXPECT_EQ(OK, callback_.WaitForResult());
733 stream = request2.ReleaseStream();
734 stream.reset(); // Will reset stream 3.
735
736 EXPECT_TRUE(socket_data.at_read_eof());
737 EXPECT_TRUE(socket_data.at_write_eof());
738 EXPECT_TRUE(socket_data2.at_read_eof());
739 EXPECT_TRUE(socket_data2.at_write_eof());
740}
741
[email protected]1e960032013-12-20 19:00:20742TEST_P(QuicStreamFactoryTest, OnIPAddressChanged) {
[email protected]f698a012013-05-06 20:18:59743 MockRead reads[] = {
[email protected]0edce6a2013-05-08 18:02:40744 MockRead(ASYNC, 0, 0) // EOF
[email protected]f698a012013-05-06 20:18:59745 };
[email protected]459a7402014-02-10 12:58:52746 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
747 std::vector<MockWrite> writes;
748 if (GetParam() > QUIC_VERSION_13)
749 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
750 DeterministicSocketData socket_data(reads, arraysize(reads),
751 writes.empty() ? NULL : &writes[0],
752 writes.size());
[email protected]f698a012013-05-06 20:18:59753 socket_factory_.AddSocketDataProvider(&socket_data);
[email protected]0edce6a2013-05-08 18:02:40754 socket_data.StopAfter(1);
[email protected]f698a012013-05-06 20:18:59755
[email protected]69dfd1b2013-06-04 22:20:12756 MockRead reads2[] = {
[email protected]25c31dc2013-06-05 17:56:04757 MockRead(ASYNC, 0, 0) // EOF
[email protected]69dfd1b2013-06-04 22:20:12758 };
[email protected]25c31dc2013-06-05 17:56:04759 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0);
[email protected]f698a012013-05-06 20:18:59760 socket_factory_.AddSocketDataProvider(&socket_data2);
[email protected]0edce6a2013-05-08 18:02:40761 socket_data2.StopAfter(1);
[email protected]f698a012013-05-06 20:18:59762
763 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59764 EXPECT_EQ(ERR_IO_PENDING,
765 request.Request(host_port_proxy_pair_,
766 is_https_,
767 "GET",
768 cert_verifier_.get(),
769 net_log_,
770 callback_.callback()));
[email protected]f698a012013-05-06 20:18:59771
772 EXPECT_EQ(OK, callback_.WaitForResult());
773 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
[email protected]0b2294d32013-08-02 00:46:36774 HttpRequestInfo request_info;
775 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
776 DEFAULT_PRIORITY,
777 net_log_, CompletionCallback()));
[email protected]f698a012013-05-06 20:18:59778
779 // Change the IP address and verify that stream saw the error.
780 factory_.OnIPAddressChanged();
781 EXPECT_EQ(ERR_NETWORK_CHANGED,
782 stream->ReadResponseHeaders(callback_.callback()));
[email protected]11c05872013-08-20 02:04:12783 EXPECT_TRUE(factory_.require_confirmation());
[email protected]f698a012013-05-06 20:18:59784
785 // Now attempting to request a stream to the same origin should create
786 // a new session.
787
788 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59789 EXPECT_EQ(ERR_IO_PENDING,
790 request2.Request(host_port_proxy_pair_,
791 is_https_,
792 "GET",
793 cert_verifier_.get(),
794 net_log_,
795 callback_.callback()));
[email protected]f698a012013-05-06 20:18:59796
797 EXPECT_EQ(OK, callback_.WaitForResult());
798 stream = request2.ReleaseStream();
799 stream.reset(); // Will reset stream 3.
800
801 EXPECT_TRUE(socket_data.at_read_eof());
802 EXPECT_TRUE(socket_data.at_write_eof());
803 EXPECT_TRUE(socket_data2.at_read_eof());
804 EXPECT_TRUE(socket_data2.at_write_eof());
805}
806
[email protected]1e960032013-12-20 19:00:20807TEST_P(QuicStreamFactoryTest, OnCertAdded) {
[email protected]d7d1e50b2013-11-25 22:08:09808 MockRead reads[] = {
809 MockRead(ASYNC, 0, 0) // EOF
810 };
[email protected]459a7402014-02-10 12:58:52811 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
812 std::vector<MockWrite> writes;
813 if (GetParam() > QUIC_VERSION_13)
814 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
815 DeterministicSocketData socket_data(reads, arraysize(reads),
816 writes.empty() ? NULL : &writes[0],
817 writes.size());
[email protected]d7d1e50b2013-11-25 22:08:09818 socket_factory_.AddSocketDataProvider(&socket_data);
819 socket_data.StopAfter(1);
820
821 MockRead reads2[] = {
822 MockRead(ASYNC, 0, 0) // EOF
823 };
824 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0);
825 socket_factory_.AddSocketDataProvider(&socket_data2);
826 socket_data2.StopAfter(1);
827
828 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59829 EXPECT_EQ(ERR_IO_PENDING,
830 request.Request(host_port_proxy_pair_,
831 is_https_,
832 "GET",
833 cert_verifier_.get(),
834 net_log_,
835 callback_.callback()));
[email protected]d7d1e50b2013-11-25 22:08:09836
837 EXPECT_EQ(OK, callback_.WaitForResult());
838 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
839 HttpRequestInfo request_info;
840 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
841 DEFAULT_PRIORITY,
842 net_log_, CompletionCallback()));
843
844 // Add a cert and verify that stream saw the event.
845 factory_.OnCertAdded(NULL);
846 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED,
847 stream->ReadResponseHeaders(callback_.callback()));
848 EXPECT_FALSE(factory_.require_confirmation());
849
850 // Now attempting to request a stream to the same origin should create
851 // a new session.
852
853 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59854 EXPECT_EQ(ERR_IO_PENDING,
855 request2.Request(host_port_proxy_pair_,
856 is_https_,
857 "GET",
858 cert_verifier_.get(),
859 net_log_,
860 callback_.callback()));
[email protected]d7d1e50b2013-11-25 22:08:09861
862 EXPECT_EQ(OK, callback_.WaitForResult());
863 stream = request2.ReleaseStream();
864 stream.reset(); // Will reset stream 3.
865
866 EXPECT_TRUE(socket_data.at_read_eof());
867 EXPECT_TRUE(socket_data.at_write_eof());
868 EXPECT_TRUE(socket_data2.at_read_eof());
869 EXPECT_TRUE(socket_data2.at_write_eof());
870}
871
[email protected]1e960032013-12-20 19:00:20872TEST_P(QuicStreamFactoryTest, OnCACertChanged) {
[email protected]d7d1e50b2013-11-25 22:08:09873 MockRead reads[] = {
874 MockRead(ASYNC, 0, 0) // EOF
875 };
[email protected]459a7402014-02-10 12:58:52876 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
877 std::vector<MockWrite> writes;
878 if (GetParam() > QUIC_VERSION_13)
879 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
880 DeterministicSocketData socket_data(reads, arraysize(reads),
881 writes.empty() ? NULL : &writes[0],
882 writes.size());
[email protected]d7d1e50b2013-11-25 22:08:09883 socket_factory_.AddSocketDataProvider(&socket_data);
884 socket_data.StopAfter(1);
885
886 MockRead reads2[] = {
887 MockRead(ASYNC, 0, 0) // EOF
888 };
889 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0);
890 socket_factory_.AddSocketDataProvider(&socket_data2);
891 socket_data2.StopAfter(1);
892
893 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59894 EXPECT_EQ(ERR_IO_PENDING,
895 request.Request(host_port_proxy_pair_,
896 is_https_,
897 "GET",
898 cert_verifier_.get(),
899 net_log_,
900 callback_.callback()));
[email protected]d7d1e50b2013-11-25 22:08:09901
902 EXPECT_EQ(OK, callback_.WaitForResult());
903 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
904 HttpRequestInfo request_info;
905 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
906 DEFAULT_PRIORITY,
907 net_log_, CompletionCallback()));
908
909 // Change the CA cert and verify that stream saw the event.
910 factory_.OnCACertChanged(NULL);
911 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED,
912 stream->ReadResponseHeaders(callback_.callback()));
913 EXPECT_FALSE(factory_.require_confirmation());
914
915 // Now attempting to request a stream to the same origin should create
916 // a new session.
917
918 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59919 EXPECT_EQ(ERR_IO_PENDING,
920 request2.Request(host_port_proxy_pair_,
921 is_https_,
922 "GET",
923 cert_verifier_.get(),
924 net_log_,
925 callback_.callback()));
[email protected]d7d1e50b2013-11-25 22:08:09926
927 EXPECT_EQ(OK, callback_.WaitForResult());
928 stream = request2.ReleaseStream();
929 stream.reset(); // Will reset stream 3.
930
931 EXPECT_TRUE(socket_data.at_read_eof());
932 EXPECT_TRUE(socket_data.at_write_eof());
933 EXPECT_TRUE(socket_data2.at_read_eof());
934 EXPECT_TRUE(socket_data2.at_write_eof());
935}
936
[email protected]1e960032013-12-20 19:00:20937TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) {
[email protected]6e12d702013-11-13 00:17:17938 vector<string> cannoncial_suffixes;
939 cannoncial_suffixes.push_back(string(".c.youtube.com"));
940 cannoncial_suffixes.push_back(string(".googlevideo.com"));
[email protected]c49ff182013-09-28 08:33:26941
[email protected]6e12d702013-11-13 00:17:17942 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) {
943 string r1_host_name("r1");
944 string r2_host_name("r2");
945 r1_host_name.append(cannoncial_suffixes[i]);
946 r2_host_name.append(cannoncial_suffixes[i]);
[email protected]b70fdb792013-10-25 19:04:14947
[email protected]6e12d702013-11-13 00:17:17948 HostPortProxyPair host_port_proxy_pair1(HostPortPair(r1_host_name, 80),
949 ProxyServer::Direct());
[email protected]c49ff182013-09-28 08:33:26950
[email protected]6e12d702013-11-13 00:17:17951 QuicCryptoClientConfig* crypto_config1 =
952 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_,
953 host_port_proxy_pair1);
954 DCHECK(crypto_config1);
955 QuicCryptoClientConfig::CachedState* cached1 =
956 crypto_config1->LookupOrCreate(host_port_proxy_pair1.first.host());
957 EXPECT_FALSE(cached1->proof_valid());
958 EXPECT_TRUE(cached1->source_address_token().empty());
959
960 // Mutate the cached1 to have different data.
961 // TODO(rtenneti): mutate other members of CachedState.
962 cached1->set_source_address_token(r1_host_name);
963 cached1->SetProofValid();
964
965 HostPortProxyPair host_port_proxy_pair2(HostPortPair(r2_host_name, 80),
966 ProxyServer::Direct());
967 QuicCryptoClientConfig* crypto_config2 =
968 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_,
969 host_port_proxy_pair2);
970 DCHECK(crypto_config2);
971 QuicCryptoClientConfig::CachedState* cached2 =
972 crypto_config2->LookupOrCreate(host_port_proxy_pair2.first.host());
973 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token());
974 EXPECT_TRUE(cached2->proof_valid());
975 }
[email protected]b70fdb792013-10-25 19:04:14976}
977
[email protected]1e960032013-12-20 19:00:20978TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) {
[email protected]6e12d702013-11-13 00:17:17979 vector<string> cannoncial_suffixes;
980 cannoncial_suffixes.push_back(string(".c.youtube.com"));
981 cannoncial_suffixes.push_back(string(".googlevideo.com"));
[email protected]b70fdb792013-10-25 19:04:14982
[email protected]6e12d702013-11-13 00:17:17983 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) {
984 string r3_host_name("r3");
985 string r4_host_name("r4");
986 r3_host_name.append(cannoncial_suffixes[i]);
987 r4_host_name.append(cannoncial_suffixes[i]);
[email protected]b70fdb792013-10-25 19:04:14988
[email protected]6e12d702013-11-13 00:17:17989 HostPortProxyPair host_port_proxy_pair1(HostPortPair(r3_host_name, 80),
990 ProxyServer::Direct());
[email protected]b70fdb792013-10-25 19:04:14991
[email protected]6e12d702013-11-13 00:17:17992 QuicCryptoClientConfig* crypto_config1 =
993 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_,
994 host_port_proxy_pair1);
995 DCHECK(crypto_config1);
996 QuicCryptoClientConfig::CachedState* cached1 =
997 crypto_config1->LookupOrCreate(host_port_proxy_pair1.first.host());
998 EXPECT_FALSE(cached1->proof_valid());
999 EXPECT_TRUE(cached1->source_address_token().empty());
1000
1001 // Mutate the cached1 to have different data.
1002 // TODO(rtenneti): mutate other members of CachedState.
1003 cached1->set_source_address_token(r3_host_name);
1004 cached1->SetProofInvalid();
1005
1006 HostPortProxyPair host_port_proxy_pair2(HostPortPair(r4_host_name, 80),
1007 ProxyServer::Direct());
1008 QuicCryptoClientConfig* crypto_config2 =
1009 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_,
1010 host_port_proxy_pair2);
1011 DCHECK(crypto_config2);
1012 QuicCryptoClientConfig::CachedState* cached2 =
1013 crypto_config2->LookupOrCreate(host_port_proxy_pair2.first.host());
1014 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token());
1015 EXPECT_TRUE(cached2->source_address_token().empty());
1016 EXPECT_FALSE(cached2->proof_valid());
1017 }
[email protected]c49ff182013-09-28 08:33:261018}
1019
[email protected]e13201d82012-12-12 05:00:321020} // namespace test
[email protected]e13201d82012-12-12 05:00:321021} // namespace net