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
3 // found in the LICENSE file.
5 #include "net/quic/quic_stream_factory.h"
7 #include "base/run_loop.h"
8 #include "base/strings/string_util.h"
9 #include "net/base/test_data_directory.h"
10 #include "net/cert/cert_verifier.h"
11 #include "net/dns/mock_host_resolver.h"
12 #include "net/http/http_response_headers.h"
13 #include "net/http/http_response_info.h"
14 #include "net/http/http_util.h"
15 #include "net/http/transport_security_state.h"
16 #include "net/quic/crypto/crypto_handshake.h"
17 #include "net/quic/crypto/proof_verifier_chromium.h"
18 #include "net/quic/crypto/quic_decrypter.h"
19 #include "net/quic/crypto/quic_encrypter.h"
20 #include "net/quic/quic_http_stream.h"
21 #include "net/quic/quic_server_id.h"
22 #include "net/quic/test_tools/mock_clock.h"
23 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h"
24 #include "net/quic/test_tools/mock_random.h"
25 #include "net/quic/test_tools/quic_test_packet_maker.h"
26 #include "net/quic/test_tools/quic_test_utils.h"
27 #include "net/socket/socket_test_util.h"
28 #include "net/spdy/spdy_test_utils.h"
29 #include "net/ssl/channel_id_service.h"
30 #include "net/ssl/default_channel_id_store.h"
31 #include "net/test/cert_test_util.h"
32 #include "testing/gtest/include/gtest/gtest.h"
34 using base::StringPiece
;
42 const char kDefaultServerHostName
[] = "www.google.com";
43 const int kDefaultServerPort
= 443;
44 } // namespace anonymous
46 class QuicStreamFactoryPeer
{
48 static QuicCryptoClientConfig
* GetCryptoConfig(QuicStreamFactory
* factory
) {
49 return &factory
->crypto_config_
;
52 static bool HasActiveSession(QuicStreamFactory
* factory
,
53 const HostPortPair
& host_port_pair
,
55 QuicServerId
server_id(host_port_pair
, is_https
, PRIVACY_MODE_DISABLED
);
56 return factory
->HasActiveSession(server_id
);
59 static QuicClientSession
* GetActiveSession(
60 QuicStreamFactory
* factory
,
61 const HostPortPair
& host_port_pair
,
63 QuicServerId
server_id(host_port_pair
, is_https
, PRIVACY_MODE_DISABLED
);
64 DCHECK(factory
->HasActiveSession(server_id
));
65 return factory
->active_sessions_
[server_id
];
68 static scoped_ptr
<QuicHttpStream
> CreateIfSessionExists(
69 QuicStreamFactory
* factory
,
70 const HostPortPair
& host_port_pair
,
72 const BoundNetLog
& net_log
) {
73 QuicServerId
server_id(host_port_pair
, is_https
, PRIVACY_MODE_DISABLED
);
74 return factory
->CreateIfSessionExists(server_id
, net_log
);
77 static bool IsLiveSession(QuicStreamFactory
* factory
,
78 QuicClientSession
* session
) {
79 for (QuicStreamFactory::SessionIdMap::iterator it
=
80 factory
->all_sessions_
.begin();
81 it
!= factory
->all_sessions_
.end(); ++it
) {
82 if (it
->first
== session
)
89 class QuicStreamFactoryTest
: public ::testing::TestWithParam
<QuicVersion
> {
91 QuicStreamFactoryTest()
92 : random_generator_(0),
93 clock_(new MockClock()),
94 maker_(GetParam(), 0, clock_
),
95 cert_verifier_(CertVerifier::CreateDefault()),
96 channel_id_service_(new ChannelIDService(
97 new DefaultChannelIDStore(NULL
),
98 base::MessageLoopProxy::current())),
99 factory_(&host_resolver_
, &socket_factory_
,
100 base::WeakPtr
<HttpServerProperties
>(), cert_verifier_
.get(),
101 channel_id_service_
.get(), &transport_security_state_
,
102 &crypto_client_stream_factory_
, &random_generator_
, clock_
,
103 kDefaultMaxPacketSize
, std::string(),
104 SupportedVersions(GetParam()), true, true, QuicTagVector()),
105 host_port_pair_(kDefaultServerHostName
, kDefaultServerPort
),
107 privacy_mode_(PRIVACY_MODE_DISABLED
) {
108 factory_
.set_require_confirmation(false);
109 clock_
->AdvanceTime(QuicTime::Delta::FromSeconds(1));
112 scoped_ptr
<QuicHttpStream
> CreateIfSessionExists(
113 const HostPortPair
& host_port_pair
,
114 const BoundNetLog
& net_log
) {
115 return QuicStreamFactoryPeer::CreateIfSessionExists(
116 &factory_
, host_port_pair
, false, net_log_
);
119 int GetSourcePortForNewSession(const HostPortPair
& destination
) {
120 return GetSourcePortForNewSessionInner(destination
, false);
123 int GetSourcePortForNewSessionAndGoAway(
124 const HostPortPair
& destination
) {
125 return GetSourcePortForNewSessionInner(destination
, true);
128 int GetSourcePortForNewSessionInner(const HostPortPair
& destination
,
129 bool goaway_received
) {
130 // Should only be called if there is no active session for this destination.
131 EXPECT_EQ(NULL
, CreateIfSessionExists(destination
, net_log_
).get());
132 size_t socket_count
= socket_factory_
.udp_client_sockets().size();
135 MockRead(ASYNC
, OK
, 0) // EOF
137 DeterministicSocketData
socket_data(reads
, arraysize(reads
), NULL
, 0);
138 socket_data
.StopAfter(1);
139 socket_factory_
.AddSocketDataProvider(&socket_data
);
141 QuicStreamRequest
request(&factory_
);
142 EXPECT_EQ(ERR_IO_PENDING
,
143 request
.Request(destination
,
148 callback_
.callback()));
150 EXPECT_EQ(OK
, callback_
.WaitForResult());
151 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
152 EXPECT_TRUE(stream
.get());
155 QuicClientSession
* session
= QuicStreamFactoryPeer::GetActiveSession(
156 &factory_
, destination
, is_https_
);
158 if (socket_count
+ 1 != socket_factory_
.udp_client_sockets().size()) {
165 udp_client_sockets()[socket_count
]->GetLocalAddress(&endpoint
);
166 int port
= endpoint
.port();
167 if (goaway_received
) {
168 QuicGoAwayFrame
goaway(QUIC_NO_ERROR
, 1, "");
169 session
->OnGoAway(goaway
);
172 factory_
.OnSessionClosed(session
);
173 EXPECT_EQ(NULL
, CreateIfSessionExists(destination
, net_log_
).get());
174 EXPECT_TRUE(socket_data
.at_read_eof());
175 EXPECT_TRUE(socket_data
.at_write_eof());
179 scoped_ptr
<QuicEncryptedPacket
> ConstructRstPacket() {
180 QuicStreamId stream_id
= kClientDataStreamId1
;
181 return maker_
.MakeRstPacket(
183 AdjustErrorForVersion(QUIC_RST_FLOW_CONTROL_ACCOUNTING
, GetParam()));
186 MockHostResolver host_resolver_
;
187 DeterministicMockClientSocketFactory socket_factory_
;
188 MockCryptoClientStreamFactory crypto_client_stream_factory_
;
189 MockRandom random_generator_
;
190 MockClock
* clock_
; // Owned by factory_.
191 QuicTestPacketMaker maker_
;
192 scoped_ptr
<CertVerifier
> cert_verifier_
;
193 scoped_ptr
<ChannelIDService
> channel_id_service_
;
194 TransportSecurityState transport_security_state_
;
195 QuicStreamFactory factory_
;
196 HostPortPair host_port_pair_
;
198 PrivacyMode privacy_mode_
;
199 BoundNetLog net_log_
;
200 TestCompletionCallback callback_
;
203 INSTANTIATE_TEST_CASE_P(Version
, QuicStreamFactoryTest
,
204 ::testing::ValuesIn(QuicSupportedVersions()));
206 TEST_P(QuicStreamFactoryTest
, CreateIfSessionExists
) {
207 EXPECT_EQ(NULL
, CreateIfSessionExists(host_port_pair_
, net_log_
).get());
210 TEST_P(QuicStreamFactoryTest
, Create
) {
212 MockRead(ASYNC
, OK
, 0) // EOF
214 DeterministicSocketData
socket_data(reads
, arraysize(reads
), NULL
, 0);
215 socket_factory_
.AddSocketDataProvider(&socket_data
);
216 socket_data
.StopAfter(1);
218 QuicStreamRequest
request(&factory_
);
219 EXPECT_EQ(ERR_IO_PENDING
,
220 request
.Request(host_port_pair_
,
225 callback_
.callback()));
227 EXPECT_EQ(OK
, callback_
.WaitForResult());
228 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
229 EXPECT_TRUE(stream
.get());
231 // Will reset stream 3.
232 stream
= CreateIfSessionExists(host_port_pair_
, net_log_
);
233 EXPECT_TRUE(stream
.get());
235 // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result
236 // in streams on different sessions.
237 QuicStreamRequest
request2(&factory_
);
239 request2
.Request(host_port_pair_
,
244 callback_
.callback()));
245 stream
= request2
.ReleaseStream(); // Will reset stream 5.
246 stream
.reset(); // Will reset stream 7.
248 EXPECT_TRUE(socket_data
.at_read_eof());
249 EXPECT_TRUE(socket_data
.at_write_eof());
252 TEST_P(QuicStreamFactoryTest
, CreateZeroRtt
) {
254 MockRead(ASYNC
, OK
, 0) // EOF
256 DeterministicSocketData
socket_data(reads
, arraysize(reads
), NULL
, 0);
257 socket_factory_
.AddSocketDataProvider(&socket_data
);
258 socket_data
.StopAfter(1);
260 crypto_client_stream_factory_
.set_handshake_mode(
261 MockCryptoClientStream::ZERO_RTT
);
262 host_resolver_
.set_synchronous_mode(true);
263 host_resolver_
.rules()->AddIPLiteralRule(host_port_pair_
.host(),
266 QuicStreamRequest
request(&factory_
);
268 request
.Request(host_port_pair_
,
273 callback_
.callback()));
275 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
276 EXPECT_TRUE(stream
.get());
277 EXPECT_TRUE(socket_data
.at_read_eof());
278 EXPECT_TRUE(socket_data
.at_write_eof());
281 TEST_P(QuicStreamFactoryTest
, CreateZeroRttPost
) {
283 MockRead(ASYNC
, OK
, 0) // EOF
285 DeterministicSocketData
socket_data(reads
, arraysize(reads
), NULL
, 0);
286 socket_factory_
.AddSocketDataProvider(&socket_data
);
287 socket_data
.StopAfter(1);
289 crypto_client_stream_factory_
.set_handshake_mode(
290 MockCryptoClientStream::ZERO_RTT
);
291 host_resolver_
.set_synchronous_mode(true);
292 host_resolver_
.rules()->AddIPLiteralRule(host_port_pair_
.host(),
295 QuicStreamRequest
request(&factory_
);
296 // Posts require handshake confirmation, so this will return asynchronously.
297 EXPECT_EQ(ERR_IO_PENDING
,
298 request
.Request(host_port_pair_
,
303 callback_
.callback()));
305 // Confirm the handshake and verify that the stream is created.
306 crypto_client_stream_factory_
.last_stream()->SendOnCryptoHandshakeEvent(
307 QuicSession::HANDSHAKE_CONFIRMED
);
309 EXPECT_EQ(OK
, callback_
.WaitForResult());
310 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
311 EXPECT_TRUE(stream
.get());
312 EXPECT_TRUE(socket_data
.at_read_eof());
313 EXPECT_TRUE(socket_data
.at_write_eof());
316 TEST_P(QuicStreamFactoryTest
, CreateHttpVsHttps
) {
318 MockRead(ASYNC
, OK
, 0) // EOF
320 DeterministicSocketData
socket_data1(reads
, arraysize(reads
), NULL
, 0);
321 DeterministicSocketData
socket_data2(reads
, arraysize(reads
), NULL
, 0);
322 socket_factory_
.AddSocketDataProvider(&socket_data1
);
323 socket_factory_
.AddSocketDataProvider(&socket_data2
);
324 socket_data1
.StopAfter(1);
325 socket_data2
.StopAfter(1);
327 QuicStreamRequest
request(&factory_
);
328 EXPECT_EQ(ERR_IO_PENDING
,
329 request
.Request(host_port_pair_
,
334 callback_
.callback()));
336 EXPECT_EQ(OK
, callback_
.WaitForResult());
337 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
338 EXPECT_TRUE(stream
.get());
340 QuicStreamRequest
request2(&factory_
);
341 EXPECT_EQ(ERR_IO_PENDING
,
342 request2
.Request(host_port_pair_
,
347 callback_
.callback()));
348 EXPECT_EQ(OK
, callback_
.WaitForResult());
349 stream
= request2
.ReleaseStream();
350 EXPECT_TRUE(stream
.get());
353 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
354 &factory_
, host_port_pair_
, is_https_
),
355 QuicStreamFactoryPeer::GetActiveSession(
356 &factory_
, host_port_pair_
, !is_https_
));
358 EXPECT_TRUE(socket_data1
.at_read_eof());
359 EXPECT_TRUE(socket_data1
.at_write_eof());
360 EXPECT_TRUE(socket_data2
.at_read_eof());
361 EXPECT_TRUE(socket_data2
.at_write_eof());
364 TEST_P(QuicStreamFactoryTest
, Pooling
) {
366 MockRead(ASYNC
, OK
, 0) // EOF
368 DeterministicSocketData
socket_data(reads
, arraysize(reads
), NULL
, 0);
369 socket_factory_
.AddSocketDataProvider(&socket_data
);
370 socket_data
.StopAfter(1);
372 HostPortPair
server2("mail.google.com", kDefaultServerPort
);
373 host_resolver_
.set_synchronous_mode(true);
374 host_resolver_
.rules()->AddIPLiteralRule(
375 kDefaultServerHostName
, "192.168.0.1", "");
376 host_resolver_
.rules()->AddIPLiteralRule(
377 "mail.google.com", "192.168.0.1", "");
379 QuicStreamRequest
request(&factory_
);
381 request
.Request(host_port_pair_
,
386 callback_
.callback()));
387 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
388 EXPECT_TRUE(stream
.get());
390 TestCompletionCallback callback
;
391 QuicStreamRequest
request2(&factory_
);
393 request2
.Request(server2
,
398 callback
.callback()));
399 scoped_ptr
<QuicHttpStream
> stream2
= request2
.ReleaseStream();
400 EXPECT_TRUE(stream2
.get());
403 QuicStreamFactoryPeer::GetActiveSession(
404 &factory_
, host_port_pair_
, is_https_
),
405 QuicStreamFactoryPeer::GetActiveSession(&factory_
, server2
, is_https_
));
407 EXPECT_TRUE(socket_data
.at_read_eof());
408 EXPECT_TRUE(socket_data
.at_write_eof());
411 TEST_P(QuicStreamFactoryTest
, NoPoolingAfterGoAway
) {
413 MockRead(ASYNC
, OK
, 0) // EOF
415 DeterministicSocketData
socket_data1(reads
, arraysize(reads
), NULL
, 0);
416 DeterministicSocketData
socket_data2(reads
, arraysize(reads
), NULL
, 0);
417 socket_factory_
.AddSocketDataProvider(&socket_data1
);
418 socket_factory_
.AddSocketDataProvider(&socket_data2
);
419 socket_data1
.StopAfter(1);
420 socket_data2
.StopAfter(1);
422 HostPortPair
server2("mail.google.com", kDefaultServerPort
);
423 host_resolver_
.set_synchronous_mode(true);
424 host_resolver_
.rules()->AddIPLiteralRule(
425 kDefaultServerHostName
, "192.168.0.1", "");
426 host_resolver_
.rules()->AddIPLiteralRule(
427 "mail.google.com", "192.168.0.1", "");
429 QuicStreamRequest
request(&factory_
);
431 request
.Request(host_port_pair_
,
436 callback_
.callback()));
437 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
438 EXPECT_TRUE(stream
.get());
440 TestCompletionCallback callback
;
441 QuicStreamRequest
request2(&factory_
);
443 request2
.Request(server2
,
448 callback
.callback()));
449 scoped_ptr
<QuicHttpStream
> stream2
= request2
.ReleaseStream();
450 EXPECT_TRUE(stream2
.get());
452 factory_
.OnSessionGoingAway(QuicStreamFactoryPeer::GetActiveSession(
453 &factory_
, host_port_pair_
, is_https_
));
454 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
455 &factory_
, host_port_pair_
, is_https_
));
456 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
457 &factory_
, server2
, is_https_
));
459 TestCompletionCallback callback3
;
460 QuicStreamRequest
request3(&factory_
);
462 request3
.Request(server2
,
467 callback3
.callback()));
468 scoped_ptr
<QuicHttpStream
> stream3
= request3
.ReleaseStream();
469 EXPECT_TRUE(stream3
.get());
471 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(
472 &factory_
, server2
, is_https_
));
474 EXPECT_TRUE(socket_data1
.at_read_eof());
475 EXPECT_TRUE(socket_data1
.at_write_eof());
476 EXPECT_TRUE(socket_data2
.at_read_eof());
477 EXPECT_TRUE(socket_data2
.at_write_eof());
480 TEST_P(QuicStreamFactoryTest
, HttpsPooling
) {
482 MockRead(ASYNC
, OK
, 0) // EOF
484 DeterministicSocketData
socket_data(reads
, arraysize(reads
), NULL
, 0);
485 socket_factory_
.AddSocketDataProvider(&socket_data
);
486 socket_data
.StopAfter(1);
488 HostPortPair
server1("www.example.org", 443);
489 HostPortPair
server2("mail.example.org", 443);
491 // Load a cert that is valid for:
492 // www.example.org (server1)
493 // mail.example.org (server2)
495 base::FilePath certs_dir
= GetTestCertsDirectory();
496 scoped_refptr
<X509Certificate
> test_cert(
497 ImportCertFromFile(certs_dir
, "spdy_pooling.pem"));
498 ASSERT_NE(static_cast<X509Certificate
*>(NULL
), test_cert
.get());
499 ProofVerifyDetailsChromium verify_details
;
500 verify_details
.cert_verify_result
.verified_cert
= test_cert
;
501 verify_details
.cert_verify_result
.is_issued_by_known_root
= true;
502 crypto_client_stream_factory_
.set_proof_verify_details(&verify_details
);
504 host_resolver_
.set_synchronous_mode(true);
505 host_resolver_
.rules()->AddIPLiteralRule(server1
.host(), "192.168.0.1", "");
506 host_resolver_
.rules()->AddIPLiteralRule(server2
.host(), "192.168.0.1", "");
508 QuicStreamRequest
request(&factory_
);
511 request
.Request(server1
,
516 callback_
.callback()));
517 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
518 EXPECT_TRUE(stream
.get());
520 TestCompletionCallback callback
;
521 QuicStreamRequest
request2(&factory_
);
523 request2
.Request(server2
,
528 callback_
.callback()));
529 scoped_ptr
<QuicHttpStream
> stream2
= request2
.ReleaseStream();
530 EXPECT_TRUE(stream2
.get());
532 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession(
533 &factory_
, server1
, is_https_
),
534 QuicStreamFactoryPeer::GetActiveSession(
535 &factory_
, server2
, is_https_
));
537 EXPECT_TRUE(socket_data
.at_read_eof());
538 EXPECT_TRUE(socket_data
.at_write_eof());
541 TEST_P(QuicStreamFactoryTest
, NoHttpsPoolingWithCertMismatch
) {
543 MockRead(ASYNC
, OK
, 0) // EOF
545 DeterministicSocketData
socket_data1(reads
, arraysize(reads
), NULL
, 0);
546 DeterministicSocketData
socket_data2(reads
, arraysize(reads
), NULL
, 0);
547 socket_factory_
.AddSocketDataProvider(&socket_data1
);
548 socket_factory_
.AddSocketDataProvider(&socket_data2
);
549 socket_data1
.StopAfter(1);
550 socket_data2
.StopAfter(1);
552 HostPortPair
server1("www.example.org", 443);
553 HostPortPair
server2("mail.google.com", 443);
555 // Load a cert that is valid for:
556 // www.example.org (server1)
559 // But is not valid for mail.google.com (server2).
560 base::FilePath certs_dir
= GetTestCertsDirectory();
561 scoped_refptr
<X509Certificate
> test_cert(
562 ImportCertFromFile(certs_dir
, "spdy_pooling.pem"));
563 ASSERT_NE(static_cast<X509Certificate
*>(NULL
), test_cert
.get());
564 ProofVerifyDetailsChromium verify_details
;
565 verify_details
.cert_verify_result
.verified_cert
= test_cert
;
566 crypto_client_stream_factory_
.set_proof_verify_details(&verify_details
);
569 host_resolver_
.set_synchronous_mode(true);
570 host_resolver_
.rules()->AddIPLiteralRule(server1
.host(), "192.168.0.1", "");
571 host_resolver_
.rules()->AddIPLiteralRule(server2
.host(), "192.168.0.1", "");
573 QuicStreamRequest
request(&factory_
);
576 request
.Request(server1
,
581 callback_
.callback()));
582 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
583 EXPECT_TRUE(stream
.get());
585 TestCompletionCallback callback
;
586 QuicStreamRequest
request2(&factory_
);
588 request2
.Request(server2
,
593 callback_
.callback()));
594 scoped_ptr
<QuicHttpStream
> stream2
= request2
.ReleaseStream();
595 EXPECT_TRUE(stream2
.get());
597 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
598 &factory_
, server1
, is_https_
),
599 QuicStreamFactoryPeer::GetActiveSession(
600 &factory_
, server2
, is_https_
));
602 EXPECT_TRUE(socket_data1
.at_read_eof());
603 EXPECT_TRUE(socket_data1
.at_write_eof());
604 EXPECT_TRUE(socket_data2
.at_read_eof());
605 EXPECT_TRUE(socket_data2
.at_write_eof());
608 TEST_P(QuicStreamFactoryTest
, HttpsPoolingWithMatchingPins
) {
610 MockRead(ASYNC
, OK
, 0) // EOF
612 DeterministicSocketData
socket_data(reads
, arraysize(reads
), NULL
, 0);
613 socket_factory_
.AddSocketDataProvider(&socket_data
);
614 socket_data
.StopAfter(1);
616 HostPortPair
server1("www.example.org", 443);
617 HostPortPair
server2("mail.example.org", 443);
618 uint8 primary_pin
= 1;
619 uint8 backup_pin
= 2;
620 test::AddPin(&transport_security_state_
, "mail.example.org", primary_pin
,
623 // Load a cert that is valid for:
624 // www.example.org (server1)
625 // mail.example.org (server2)
626 base::FilePath certs_dir
= GetTestCertsDirectory();
627 scoped_refptr
<X509Certificate
> test_cert(
628 ImportCertFromFile(certs_dir
, "spdy_pooling.pem"));
629 ASSERT_NE(static_cast<X509Certificate
*>(NULL
), test_cert
.get());
630 ProofVerifyDetailsChromium verify_details
;
631 verify_details
.cert_verify_result
.verified_cert
= test_cert
;
632 verify_details
.cert_verify_result
.is_issued_by_known_root
= true;
633 verify_details
.cert_verify_result
.public_key_hashes
.push_back(
634 test::GetTestHashValue(primary_pin
));
635 crypto_client_stream_factory_
.set_proof_verify_details(&verify_details
);
638 host_resolver_
.set_synchronous_mode(true);
639 host_resolver_
.rules()->AddIPLiteralRule(server1
.host(), "192.168.0.1", "");
640 host_resolver_
.rules()->AddIPLiteralRule(server2
.host(), "192.168.0.1", "");
642 QuicStreamRequest
request(&factory_
);
645 request
.Request(server1
,
650 callback_
.callback()));
651 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
652 EXPECT_TRUE(stream
.get());
654 TestCompletionCallback callback
;
655 QuicStreamRequest
request2(&factory_
);
657 request2
.Request(server2
,
662 callback_
.callback()));
663 scoped_ptr
<QuicHttpStream
> stream2
= request2
.ReleaseStream();
664 EXPECT_TRUE(stream2
.get());
666 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession(
667 &factory_
, server1
, is_https_
),
668 QuicStreamFactoryPeer::GetActiveSession(
669 &factory_
, server2
, is_https_
));
671 EXPECT_TRUE(socket_data
.at_read_eof());
672 EXPECT_TRUE(socket_data
.at_write_eof());
675 TEST_P(QuicStreamFactoryTest
, NoHttpsPoolingWithDifferentPins
) {
677 MockRead(ASYNC
, OK
, 0) // EOF
679 DeterministicSocketData
socket_data1(reads
, arraysize(reads
), NULL
, 0);
680 DeterministicSocketData
socket_data2(reads
, arraysize(reads
), NULL
, 0);
681 socket_factory_
.AddSocketDataProvider(&socket_data1
);
682 socket_factory_
.AddSocketDataProvider(&socket_data2
);
683 socket_data1
.StopAfter(1);
684 socket_data2
.StopAfter(1);
686 HostPortPair
server1("www.example.org", 443);
687 HostPortPair
server2("mail.example.org", 443);
688 uint8 primary_pin
= 1;
689 uint8 backup_pin
= 2;
691 test::AddPin(&transport_security_state_
, "mail.example.org", primary_pin
,
694 // Load a cert that is valid for:
695 // www.example.org (server1)
696 // mail.example.org (server2)
697 base::FilePath certs_dir
= GetTestCertsDirectory();
698 scoped_refptr
<X509Certificate
> test_cert(
699 ImportCertFromFile(certs_dir
, "spdy_pooling.pem"));
700 ASSERT_NE(static_cast<X509Certificate
*>(NULL
), test_cert
.get());
701 ProofVerifyDetailsChromium verify_details
;
702 verify_details
.cert_verify_result
.verified_cert
= test_cert
;
703 verify_details
.cert_verify_result
.is_issued_by_known_root
= true;
704 verify_details
.cert_verify_result
.public_key_hashes
.push_back(
705 test::GetTestHashValue(bad_pin
));
706 crypto_client_stream_factory_
.set_proof_verify_details(&verify_details
);
709 host_resolver_
.set_synchronous_mode(true);
710 host_resolver_
.rules()->AddIPLiteralRule(server1
.host(), "192.168.0.1", "");
711 host_resolver_
.rules()->AddIPLiteralRule(server2
.host(), "192.168.0.1", "");
713 QuicStreamRequest
request(&factory_
);
716 request
.Request(server1
,
721 callback_
.callback()));
722 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
723 EXPECT_TRUE(stream
.get());
725 TestCompletionCallback callback
;
726 QuicStreamRequest
request2(&factory_
);
728 request2
.Request(server2
,
733 callback_
.callback()));
734 scoped_ptr
<QuicHttpStream
> stream2
= request2
.ReleaseStream();
735 EXPECT_TRUE(stream2
.get());
737 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
738 &factory_
, server1
, is_https_
),
739 QuicStreamFactoryPeer::GetActiveSession(
740 &factory_
, server2
, is_https_
));
742 EXPECT_TRUE(socket_data1
.at_read_eof());
743 EXPECT_TRUE(socket_data1
.at_write_eof());
744 EXPECT_TRUE(socket_data2
.at_read_eof());
745 EXPECT_TRUE(socket_data2
.at_write_eof());
748 TEST_P(QuicStreamFactoryTest
, Goaway
) {
750 MockRead(ASYNC
, OK
, 0) // EOF
752 DeterministicSocketData
socket_data(reads
, arraysize(reads
), NULL
, 0);
753 socket_data
.StopAfter(1);
754 socket_factory_
.AddSocketDataProvider(&socket_data
);
755 DeterministicSocketData
socket_data2(reads
, arraysize(reads
), NULL
, 0);
756 socket_data2
.StopAfter(1);
757 socket_factory_
.AddSocketDataProvider(&socket_data2
);
759 QuicStreamRequest
request(&factory_
);
760 EXPECT_EQ(ERR_IO_PENDING
,
761 request
.Request(host_port_pair_
,
766 callback_
.callback()));
768 EXPECT_EQ(OK
, callback_
.WaitForResult());
769 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
770 EXPECT_TRUE(stream
.get());
772 // Mark the session as going away. Ensure that while it is still alive
773 // that it is no longer active.
774 QuicClientSession
* session
= QuicStreamFactoryPeer::GetActiveSession(
775 &factory_
, host_port_pair_
, is_https_
);
776 factory_
.OnSessionGoingAway(session
);
777 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_
, session
));
778 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
779 &factory_
, host_port_pair_
, is_https_
));
780 EXPECT_EQ(NULL
, CreateIfSessionExists(host_port_pair_
, net_log_
).get());
782 // Create a new request for the same destination and verify that a
783 // new session is created.
784 QuicStreamRequest
request2(&factory_
);
785 EXPECT_EQ(ERR_IO_PENDING
,
786 request2
.Request(host_port_pair_
,
791 callback_
.callback()));
792 EXPECT_EQ(OK
, callback_
.WaitForResult());
793 scoped_ptr
<QuicHttpStream
> stream2
= request2
.ReleaseStream();
794 EXPECT_TRUE(stream2
.get());
796 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_
,
800 QuicStreamFactoryPeer::GetActiveSession(
801 &factory_
, host_port_pair_
, is_https_
));
802 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_
, session
));
807 EXPECT_TRUE(socket_data
.at_read_eof());
808 EXPECT_TRUE(socket_data
.at_write_eof());
809 EXPECT_TRUE(socket_data2
.at_read_eof());
810 EXPECT_TRUE(socket_data2
.at_write_eof());
813 TEST_P(QuicStreamFactoryTest
, MaxOpenStream
) {
815 MockRead(ASYNC
, OK
, 0) // EOF
817 QuicStreamId stream_id
= kClientDataStreamId1
;
818 scoped_ptr
<QuicEncryptedPacket
> rst(
819 maker_
.MakeRstPacket(1, true, stream_id
, QUIC_STREAM_CANCELLED
));
820 MockWrite writes
[] = {
821 MockWrite(ASYNC
, rst
->data(), rst
->length(), 1),
823 DeterministicSocketData
socket_data(reads
, arraysize(reads
),
824 writes
, arraysize(writes
));
825 socket_factory_
.AddSocketDataProvider(&socket_data
);
826 socket_data
.StopAfter(1);
828 HttpRequestInfo request_info
;
829 std::vector
<QuicHttpStream
*> streams
;
830 // The MockCryptoClientStream sets max_open_streams to be
831 // 2 * kDefaultMaxStreamsPerConnection.
832 for (size_t i
= 0; i
< 2 * kDefaultMaxStreamsPerConnection
; i
++) {
833 QuicStreamRequest
request(&factory_
);
834 int rv
= request
.Request(host_port_pair_
,
839 callback_
.callback());
841 EXPECT_EQ(ERR_IO_PENDING
, rv
);
842 EXPECT_EQ(OK
, callback_
.WaitForResult());
846 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
848 EXPECT_EQ(OK
, stream
->InitializeStream(
849 &request_info
, DEFAULT_PRIORITY
, net_log_
, CompletionCallback()));
850 streams
.push_back(stream
.release());
853 QuicStreamRequest
request(&factory_
);
855 request
.Request(host_port_pair_
,
860 CompletionCallback()));
861 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
863 EXPECT_EQ(ERR_IO_PENDING
, stream
->InitializeStream(
864 &request_info
, DEFAULT_PRIORITY
, net_log_
, callback_
.callback()));
866 // Close the first stream.
867 streams
.front()->Close(false);
869 ASSERT_TRUE(callback_
.have_result());
871 EXPECT_EQ(OK
, callback_
.WaitForResult());
873 EXPECT_TRUE(socket_data
.at_read_eof());
874 EXPECT_TRUE(socket_data
.at_write_eof());
875 STLDeleteElements(&streams
);
878 TEST_P(QuicStreamFactoryTest
, ResolutionErrorInCreate
) {
879 DeterministicSocketData
socket_data(NULL
, 0, NULL
, 0);
880 socket_factory_
.AddSocketDataProvider(&socket_data
);
882 host_resolver_
.rules()->AddSimulatedFailure(kDefaultServerHostName
);
884 QuicStreamRequest
request(&factory_
);
885 EXPECT_EQ(ERR_IO_PENDING
,
886 request
.Request(host_port_pair_
,
891 callback_
.callback()));
893 EXPECT_EQ(ERR_NAME_NOT_RESOLVED
, callback_
.WaitForResult());
895 EXPECT_TRUE(socket_data
.at_read_eof());
896 EXPECT_TRUE(socket_data
.at_write_eof());
899 TEST_P(QuicStreamFactoryTest
, ConnectErrorInCreate
) {
900 MockConnect
connect(SYNCHRONOUS
, ERR_ADDRESS_IN_USE
);
901 DeterministicSocketData
socket_data(NULL
, 0, NULL
, 0);
902 socket_data
.set_connect_data(connect
);
903 socket_factory_
.AddSocketDataProvider(&socket_data
);
904 socket_data
.StopAfter(1);
906 QuicStreamRequest
request(&factory_
);
907 EXPECT_EQ(ERR_IO_PENDING
,
908 request
.Request(host_port_pair_
,
913 callback_
.callback()));
915 EXPECT_EQ(ERR_ADDRESS_IN_USE
, callback_
.WaitForResult());
917 EXPECT_TRUE(socket_data
.at_read_eof());
918 EXPECT_TRUE(socket_data
.at_write_eof());
921 TEST_P(QuicStreamFactoryTest
, CancelCreate
) {
923 MockRead(ASYNC
, OK
, 0) // EOF
925 DeterministicSocketData
socket_data(reads
, arraysize(reads
), NULL
, 0);
926 socket_factory_
.AddSocketDataProvider(&socket_data
);
928 QuicStreamRequest
request(&factory_
);
929 EXPECT_EQ(ERR_IO_PENDING
,
930 request
.Request(host_port_pair_
,
935 callback_
.callback()));
938 socket_data
.StopAfter(1);
939 base::RunLoop run_loop
;
940 run_loop
.RunUntilIdle();
942 scoped_ptr
<QuicHttpStream
> stream(
943 CreateIfSessionExists(host_port_pair_
, net_log_
));
944 EXPECT_TRUE(stream
.get());
947 EXPECT_TRUE(socket_data
.at_read_eof());
948 EXPECT_TRUE(socket_data
.at_write_eof());
951 TEST_P(QuicStreamFactoryTest
, CreateConsistentEphemeralPort
) {
952 // Sequentially connect to the default host, then another host, and then the
953 // default host. Verify that the default host gets a consistent ephemeral
954 // port, that is different from the other host's connection.
956 std::string other_server_name
= "other.google.com";
957 EXPECT_NE(kDefaultServerHostName
, other_server_name
);
958 HostPortPair
host_port_pair2(other_server_name
, kDefaultServerPort
);
960 int original_port
= GetSourcePortForNewSession(host_port_pair_
);
961 EXPECT_NE(original_port
, GetSourcePortForNewSession(host_port_pair2
));
962 EXPECT_EQ(original_port
, GetSourcePortForNewSession(host_port_pair_
));
965 TEST_P(QuicStreamFactoryTest
, GoAwayDisablesConsistentEphemeralPort
) {
966 // Get a session to the host using the port suggester.
968 GetSourcePortForNewSessionAndGoAway(host_port_pair_
);
969 // Verify that the port is different after the goaway.
970 EXPECT_NE(original_port
, GetSourcePortForNewSession(host_port_pair_
));
971 // Since the previous session did not goaway we should see the original port.
972 EXPECT_EQ(original_port
, GetSourcePortForNewSession(host_port_pair_
));
975 TEST_P(QuicStreamFactoryTest
, CloseAllSessions
) {
977 MockRead(ASYNC
, 0, 0) // EOF
979 scoped_ptr
<QuicEncryptedPacket
> rst(ConstructRstPacket());
980 std::vector
<MockWrite
> writes
;
981 writes
.push_back(MockWrite(ASYNC
, rst
->data(), rst
->length(), 1));
982 DeterministicSocketData
socket_data(reads
, arraysize(reads
),
983 writes
.empty() ? NULL
: &writes
[0],
985 socket_factory_
.AddSocketDataProvider(&socket_data
);
986 socket_data
.StopAfter(1);
988 MockRead reads2
[] = {
989 MockRead(ASYNC
, 0, 0) // EOF
991 DeterministicSocketData
socket_data2(reads2
, arraysize(reads2
), NULL
, 0);
992 socket_factory_
.AddSocketDataProvider(&socket_data2
);
993 socket_data2
.StopAfter(1);
995 QuicStreamRequest
request(&factory_
);
996 EXPECT_EQ(ERR_IO_PENDING
,
997 request
.Request(host_port_pair_
,
1002 callback_
.callback()));
1004 EXPECT_EQ(OK
, callback_
.WaitForResult());
1005 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
1006 HttpRequestInfo request_info
;
1007 EXPECT_EQ(OK
, stream
->InitializeStream(&request_info
,
1009 net_log_
, CompletionCallback()));
1011 // Close the session and verify that stream saw the error.
1012 factory_
.CloseAllSessions(ERR_INTERNET_DISCONNECTED
);
1013 EXPECT_EQ(ERR_INTERNET_DISCONNECTED
,
1014 stream
->ReadResponseHeaders(callback_
.callback()));
1016 // Now attempting to request a stream to the same origin should create
1019 QuicStreamRequest
request2(&factory_
);
1020 EXPECT_EQ(ERR_IO_PENDING
,
1021 request2
.Request(host_port_pair_
,
1026 callback_
.callback()));
1028 EXPECT_EQ(OK
, callback_
.WaitForResult());
1029 stream
= request2
.ReleaseStream();
1030 stream
.reset(); // Will reset stream 3.
1032 EXPECT_TRUE(socket_data
.at_read_eof());
1033 EXPECT_TRUE(socket_data
.at_write_eof());
1034 EXPECT_TRUE(socket_data2
.at_read_eof());
1035 EXPECT_TRUE(socket_data2
.at_write_eof());
1038 TEST_P(QuicStreamFactoryTest
, OnIPAddressChanged
) {
1039 MockRead reads
[] = {
1040 MockRead(ASYNC
, 0, 0) // EOF
1042 scoped_ptr
<QuicEncryptedPacket
> rst(ConstructRstPacket());
1043 std::vector
<MockWrite
> writes
;
1044 writes
.push_back(MockWrite(ASYNC
, rst
->data(), rst
->length(), 1));
1045 DeterministicSocketData
socket_data(reads
, arraysize(reads
),
1046 writes
.empty() ? NULL
: &writes
[0],
1048 socket_factory_
.AddSocketDataProvider(&socket_data
);
1049 socket_data
.StopAfter(1);
1051 MockRead reads2
[] = {
1052 MockRead(ASYNC
, 0, 0) // EOF
1054 DeterministicSocketData
socket_data2(reads2
, arraysize(reads2
), NULL
, 0);
1055 socket_factory_
.AddSocketDataProvider(&socket_data2
);
1056 socket_data2
.StopAfter(1);
1058 QuicStreamRequest
request(&factory_
);
1059 EXPECT_EQ(ERR_IO_PENDING
,
1060 request
.Request(host_port_pair_
,
1065 callback_
.callback()));
1067 EXPECT_EQ(OK
, callback_
.WaitForResult());
1068 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
1069 HttpRequestInfo request_info
;
1070 EXPECT_EQ(OK
, stream
->InitializeStream(&request_info
,
1072 net_log_
, CompletionCallback()));
1074 // Change the IP address and verify that stream saw the error.
1075 factory_
.OnIPAddressChanged();
1076 EXPECT_EQ(ERR_NETWORK_CHANGED
,
1077 stream
->ReadResponseHeaders(callback_
.callback()));
1078 EXPECT_TRUE(factory_
.require_confirmation());
1080 // Now attempting to request a stream to the same origin should create
1083 QuicStreamRequest
request2(&factory_
);
1084 EXPECT_EQ(ERR_IO_PENDING
,
1085 request2
.Request(host_port_pair_
,
1090 callback_
.callback()));
1092 EXPECT_EQ(OK
, callback_
.WaitForResult());
1093 stream
= request2
.ReleaseStream();
1094 stream
.reset(); // Will reset stream 3.
1096 EXPECT_TRUE(socket_data
.at_read_eof());
1097 EXPECT_TRUE(socket_data
.at_write_eof());
1098 EXPECT_TRUE(socket_data2
.at_read_eof());
1099 EXPECT_TRUE(socket_data2
.at_write_eof());
1102 TEST_P(QuicStreamFactoryTest
, OnCertAdded
) {
1103 MockRead reads
[] = {
1104 MockRead(ASYNC
, 0, 0) // EOF
1106 scoped_ptr
<QuicEncryptedPacket
> rst(ConstructRstPacket());
1107 std::vector
<MockWrite
> writes
;
1108 writes
.push_back(MockWrite(ASYNC
, rst
->data(), rst
->length(), 1));
1109 DeterministicSocketData
socket_data(reads
, arraysize(reads
),
1110 writes
.empty() ? NULL
: &writes
[0],
1112 socket_factory_
.AddSocketDataProvider(&socket_data
);
1113 socket_data
.StopAfter(1);
1115 MockRead reads2
[] = {
1116 MockRead(ASYNC
, 0, 0) // EOF
1118 DeterministicSocketData
socket_data2(reads2
, arraysize(reads2
), NULL
, 0);
1119 socket_factory_
.AddSocketDataProvider(&socket_data2
);
1120 socket_data2
.StopAfter(1);
1122 QuicStreamRequest
request(&factory_
);
1123 EXPECT_EQ(ERR_IO_PENDING
,
1124 request
.Request(host_port_pair_
,
1129 callback_
.callback()));
1131 EXPECT_EQ(OK
, callback_
.WaitForResult());
1132 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
1133 HttpRequestInfo request_info
;
1134 EXPECT_EQ(OK
, stream
->InitializeStream(&request_info
,
1136 net_log_
, CompletionCallback()));
1138 // Add a cert and verify that stream saw the event.
1139 factory_
.OnCertAdded(NULL
);
1140 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED
,
1141 stream
->ReadResponseHeaders(callback_
.callback()));
1142 EXPECT_FALSE(factory_
.require_confirmation());
1144 // Now attempting to request a stream to the same origin should create
1147 QuicStreamRequest
request2(&factory_
);
1148 EXPECT_EQ(ERR_IO_PENDING
,
1149 request2
.Request(host_port_pair_
,
1154 callback_
.callback()));
1156 EXPECT_EQ(OK
, callback_
.WaitForResult());
1157 stream
= request2
.ReleaseStream();
1158 stream
.reset(); // Will reset stream 3.
1160 EXPECT_TRUE(socket_data
.at_read_eof());
1161 EXPECT_TRUE(socket_data
.at_write_eof());
1162 EXPECT_TRUE(socket_data2
.at_read_eof());
1163 EXPECT_TRUE(socket_data2
.at_write_eof());
1166 TEST_P(QuicStreamFactoryTest
, OnCACertChanged
) {
1167 MockRead reads
[] = {
1168 MockRead(ASYNC
, 0, 0) // EOF
1170 scoped_ptr
<QuicEncryptedPacket
> rst(ConstructRstPacket());
1171 std::vector
<MockWrite
> writes
;
1172 writes
.push_back(MockWrite(ASYNC
, rst
->data(), rst
->length(), 1));
1173 DeterministicSocketData
socket_data(reads
, arraysize(reads
),
1174 writes
.empty() ? NULL
: &writes
[0],
1176 socket_factory_
.AddSocketDataProvider(&socket_data
);
1177 socket_data
.StopAfter(1);
1179 MockRead reads2
[] = {
1180 MockRead(ASYNC
, 0, 0) // EOF
1182 DeterministicSocketData
socket_data2(reads2
, arraysize(reads2
), NULL
, 0);
1183 socket_factory_
.AddSocketDataProvider(&socket_data2
);
1184 socket_data2
.StopAfter(1);
1186 QuicStreamRequest
request(&factory_
);
1187 EXPECT_EQ(ERR_IO_PENDING
,
1188 request
.Request(host_port_pair_
,
1193 callback_
.callback()));
1195 EXPECT_EQ(OK
, callback_
.WaitForResult());
1196 scoped_ptr
<QuicHttpStream
> stream
= request
.ReleaseStream();
1197 HttpRequestInfo request_info
;
1198 EXPECT_EQ(OK
, stream
->InitializeStream(&request_info
,
1200 net_log_
, CompletionCallback()));
1202 // Change the CA cert and verify that stream saw the event.
1203 factory_
.OnCACertChanged(NULL
);
1204 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED
,
1205 stream
->ReadResponseHeaders(callback_
.callback()));
1206 EXPECT_FALSE(factory_
.require_confirmation());
1208 // Now attempting to request a stream to the same origin should create
1211 QuicStreamRequest
request2(&factory_
);
1212 EXPECT_EQ(ERR_IO_PENDING
,
1213 request2
.Request(host_port_pair_
,
1218 callback_
.callback()));
1220 EXPECT_EQ(OK
, callback_
.WaitForResult());
1221 stream
= request2
.ReleaseStream();
1222 stream
.reset(); // Will reset stream 3.
1224 EXPECT_TRUE(socket_data
.at_read_eof());
1225 EXPECT_TRUE(socket_data
.at_write_eof());
1226 EXPECT_TRUE(socket_data2
.at_read_eof());
1227 EXPECT_TRUE(socket_data2
.at_write_eof());
1230 TEST_P(QuicStreamFactoryTest
, SharedCryptoConfig
) {
1231 vector
<string
> cannoncial_suffixes
;
1232 cannoncial_suffixes
.push_back(string(".c.youtube.com"));
1233 cannoncial_suffixes
.push_back(string(".googlevideo.com"));
1235 for (unsigned i
= 0; i
< cannoncial_suffixes
.size(); ++i
) {
1236 string
r1_host_name("r1");
1237 string
r2_host_name("r2");
1238 r1_host_name
.append(cannoncial_suffixes
[i
]);
1239 r2_host_name
.append(cannoncial_suffixes
[i
]);
1241 HostPortPair
host_port_pair1(r1_host_name
, 80);
1242 QuicCryptoClientConfig
* crypto_config
=
1243 QuicStreamFactoryPeer::GetCryptoConfig(&factory_
);
1244 QuicServerId
server_id1(host_port_pair1
, is_https_
, privacy_mode_
);
1245 QuicCryptoClientConfig::CachedState
* cached1
=
1246 crypto_config
->LookupOrCreate(server_id1
);
1247 EXPECT_FALSE(cached1
->proof_valid());
1248 EXPECT_TRUE(cached1
->source_address_token().empty());
1250 // Mutate the cached1 to have different data.
1251 // TODO(rtenneti): mutate other members of CachedState.
1252 cached1
->set_source_address_token(r1_host_name
);
1253 cached1
->SetProofValid();
1255 HostPortPair
host_port_pair2(r2_host_name
, 80);
1256 QuicServerId
server_id2(host_port_pair2
, is_https_
, privacy_mode_
);
1257 QuicCryptoClientConfig::CachedState
* cached2
=
1258 crypto_config
->LookupOrCreate(server_id2
);
1259 EXPECT_EQ(cached1
->source_address_token(), cached2
->source_address_token());
1260 EXPECT_TRUE(cached2
->proof_valid());
1264 TEST_P(QuicStreamFactoryTest
, CryptoConfigWhenProofIsInvalid
) {
1265 vector
<string
> cannoncial_suffixes
;
1266 cannoncial_suffixes
.push_back(string(".c.youtube.com"));
1267 cannoncial_suffixes
.push_back(string(".googlevideo.com"));
1269 for (unsigned i
= 0; i
< cannoncial_suffixes
.size(); ++i
) {
1270 string
r3_host_name("r3");
1271 string
r4_host_name("r4");
1272 r3_host_name
.append(cannoncial_suffixes
[i
]);
1273 r4_host_name
.append(cannoncial_suffixes
[i
]);
1275 HostPortPair
host_port_pair1(r3_host_name
, 80);
1276 QuicCryptoClientConfig
* crypto_config
=
1277 QuicStreamFactoryPeer::GetCryptoConfig(&factory_
);
1278 QuicServerId
server_id1(host_port_pair1
, is_https_
, privacy_mode_
);
1279 QuicCryptoClientConfig::CachedState
* cached1
=
1280 crypto_config
->LookupOrCreate(server_id1
);
1281 EXPECT_FALSE(cached1
->proof_valid());
1282 EXPECT_TRUE(cached1
->source_address_token().empty());
1284 // Mutate the cached1 to have different data.
1285 // TODO(rtenneti): mutate other members of CachedState.
1286 cached1
->set_source_address_token(r3_host_name
);
1287 cached1
->SetProofInvalid();
1289 HostPortPair
host_port_pair2(r4_host_name
, 80);
1290 QuicServerId
server_id2(host_port_pair2
, is_https_
, privacy_mode_
);
1291 QuicCryptoClientConfig::CachedState
* cached2
=
1292 crypto_config
->LookupOrCreate(server_id2
);
1293 EXPECT_NE(cached1
->source_address_token(), cached2
->source_address_token());
1294 EXPECT_TRUE(cached2
->source_address_token().empty());
1295 EXPECT_FALSE(cached2
->proof_valid());