blob: a35e5ebc8159ee2105e0824c8078eb6fc849f07f [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]7832eeb2014-01-25 10:10:4380 NULL, // quic_server_info_factory
[email protected]e8ff26842013-03-22 21:02:0581 &crypto_client_stream_factory_,
[email protected]1e960032013-12-20 19:00:2082 &random_generator_, clock_, kDefaultMaxPacketSize,
[email protected]376d38a2014-01-22 03:47:3583 SupportedVersions(GetParam()), true),
[email protected]3c772402013-12-18 21:38:1184 host_port_proxy_pair_(HostPortPair(kDefaultServerHostName,
85 kDefaultServerPort),
[email protected]6d1b4ed2013-07-10 03:57:5486 ProxyServer::Direct()),
87 is_https_(false),
88 cert_verifier_(CertVerifier::CreateDefault()) {
[email protected]11c05872013-08-20 02:04:1289 factory_.set_require_confirmation(false);
[email protected]e13201d82012-12-12 05:00:3290 }
91
[email protected]e13201d82012-12-12 05:00:3292
[email protected]3c772402013-12-18 21:38:1193 int GetSourcePortForNewSession(const HostPortProxyPair& destination) {
94 // Should only be called if there is no active session for this destination.
95 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(destination,
96 net_log_).get());
97 size_t socket_count = socket_factory_.udp_client_sockets().size();
98
99 MockRead reads[] = {
100 MockRead(ASYNC, OK, 0) // EOF
101 };
102 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
103 socket_data.StopAfter(1);
104 socket_factory_.AddSocketDataProvider(&socket_data);
105
106 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59107 EXPECT_EQ(ERR_IO_PENDING,
108 request.Request(destination,
109 is_https_,
110 "GET",
111 cert_verifier_.get(),
112 net_log_,
113 callback_.callback()));
[email protected]3c772402013-12-18 21:38:11114
115 EXPECT_EQ(OK, callback_.WaitForResult());
116 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
117 EXPECT_TRUE(stream.get());
118 stream.reset();
119
120 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
121 &factory_, destination);
122
123 if (socket_count + 1 != socket_factory_.udp_client_sockets().size()) {
124 EXPECT_TRUE(false);
125 return 0;
126 }
127
128 IPEndPoint endpoint;
129 socket_factory_.
130 udp_client_sockets()[socket_count]->GetLocalAddress(&endpoint);
131 int port = endpoint.port();
132
133 factory_.OnSessionClosed(session);
134 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(destination,
135 net_log_).get());
136 EXPECT_TRUE(socket_data.at_read_eof());
137 EXPECT_TRUE(socket_data.at_write_eof());
138 return port;
139 }
140
[email protected]459a7402014-02-10 12:58:52141 scoped_ptr<QuicEncryptedPacket> ConstructRstPacket() {
142 QuicStreamId stream_id = GetParam() > QUIC_VERSION_12 ? 5 : 3;
143 return maker_.MakeRstPacket(1, true, stream_id, QUIC_STREAM_NO_ERROR);
144 }
145
[email protected]e13201d82012-12-12 05:00:32146 MockHostResolver host_resolver_;
[email protected]0edce6a2013-05-08 18:02:40147 DeterministicMockClientSocketFactory socket_factory_;
[email protected]e8ff26842013-03-22 21:02:05148 MockCryptoClientStreamFactory crypto_client_stream_factory_;
[email protected]9558c5d32012-12-22 00:08:14149 MockRandom random_generator_;
[email protected]1e960032013-12-20 19:00:20150 QuicTestPacketMaker maker_;
[email protected]872edd9e2013-01-16 08:51:15151 MockClock* clock_; // Owned by factory_.
[email protected]e13201d82012-12-12 05:00:32152 QuicStreamFactory factory_;
153 HostPortProxyPair host_port_proxy_pair_;
[email protected]6d1b4ed2013-07-10 03:57:54154 bool is_https_;
[email protected]ce542d52013-07-11 01:08:39155 scoped_ptr<CertVerifier> cert_verifier_;
[email protected]e13201d82012-12-12 05:00:32156 BoundNetLog net_log_;
157 TestCompletionCallback callback_;
[email protected]e13201d82012-12-12 05:00:32158};
159
[email protected]1e960032013-12-20 19:00:20160INSTANTIATE_TEST_CASE_P(Version, QuicStreamFactoryTest,
161 ::testing::ValuesIn(QuicSupportedVersions()));
162
163TEST_P(QuicStreamFactoryTest, CreateIfSessionExists) {
[email protected]e13201d82012-12-12 05:00:32164 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(host_port_proxy_pair_,
165 net_log_).get());
166}
167
[email protected]1e960032013-12-20 19:00:20168TEST_P(QuicStreamFactoryTest, Create) {
[email protected]69dfd1b2013-06-04 22:20:12169 MockRead reads[] = {
[email protected]25c31dc2013-06-05 17:56:04170 MockRead(ASYNC, OK, 0) // EOF
[email protected]69dfd1b2013-06-04 22:20:12171 };
[email protected]25c31dc2013-06-05 17:56:04172 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
[email protected]e13201d82012-12-12 05:00:32173 socket_factory_.AddSocketDataProvider(&socket_data);
[email protected]25c31dc2013-06-05 17:56:04174 socket_data.StopAfter(1);
[email protected]e13201d82012-12-12 05:00:32175
176 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59177 EXPECT_EQ(ERR_IO_PENDING,
178 request.Request(host_port_proxy_pair_,
179 is_https_,
180 "GET",
181 cert_verifier_.get(),
182 net_log_,
183 callback_.callback()));
[email protected]e13201d82012-12-12 05:00:32184
185 EXPECT_EQ(OK, callback_.WaitForResult());
186 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
[email protected]0edce6a2013-05-08 18:02:40187 EXPECT_TRUE(stream.get());
[email protected]e13201d82012-12-12 05:00:32188
189 // Will reset stream 3.
190 stream = factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_);
191 EXPECT_TRUE(stream.get());
192
[email protected]6d1b4ed2013-07-10 03:57:54193 // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result
194 // in streams on different sessions.
[email protected]e13201d82012-12-12 05:00:32195 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59196 EXPECT_EQ(OK,
197 request2.Request(host_port_proxy_pair_,
198 is_https_,
199 "GET",
200 cert_verifier_.get(),
201 net_log_,
202 callback_.callback()));
[email protected]e13201d82012-12-12 05:00:32203 stream = request2.ReleaseStream(); // Will reset stream 5.
204 stream.reset(); // Will reset stream 7.
205
206 EXPECT_TRUE(socket_data.at_read_eof());
207 EXPECT_TRUE(socket_data.at_write_eof());
208}
209
[email protected]eed749f92013-12-23 18:57:38210TEST_P(QuicStreamFactoryTest, Pooling) {
211 MockRead reads[] = {
212 MockRead(ASYNC, OK, 0) // EOF
213 };
214 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
215 socket_factory_.AddSocketDataProvider(&socket_data);
216 socket_data.StopAfter(1);
217
218 HostPortProxyPair server2 = HostPortProxyPair(
219 HostPortPair("mail.google.com", kDefaultServerPort),
220 host_port_proxy_pair_.second);
221
222 host_resolver_.set_synchronous_mode(true);
223 host_resolver_.rules()->AddIPLiteralRule(
224 kDefaultServerHostName, "192.168.0.1", "");
225 host_resolver_.rules()->AddIPLiteralRule(
226 "mail.google.com", "192.168.0.1", "");
227
228 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59229 EXPECT_EQ(OK,
230 request.Request(host_port_proxy_pair_,
231 is_https_,
232 "GET",
233 cert_verifier_.get(),
234 net_log_,
235 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38236 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
237 EXPECT_TRUE(stream.get());
238
239 TestCompletionCallback callback;
240 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59241 EXPECT_EQ(OK,
242 request2.Request(server2,
243 is_https_,
244 "GET",
245 cert_verifier_.get(),
246 net_log_,
247 callback.callback()));
[email protected]eed749f92013-12-23 18:57:38248 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
249 EXPECT_TRUE(stream2.get());
250
251 EXPECT_EQ(
252 QuicStreamFactoryPeer::GetActiveSession(&factory_, host_port_proxy_pair_),
253 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2));
254
255 EXPECT_TRUE(socket_data.at_read_eof());
256 EXPECT_TRUE(socket_data.at_write_eof());
257}
258
259TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) {
260 MockRead reads[] = {
261 MockRead(ASYNC, OK, 0) // EOF
262 };
263 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0);
264 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0);
265 socket_factory_.AddSocketDataProvider(&socket_data1);
266 socket_factory_.AddSocketDataProvider(&socket_data2);
267 socket_data1.StopAfter(1);
268 socket_data2.StopAfter(1);
269
270 HostPortProxyPair server2 = HostPortProxyPair(
271 HostPortPair("mail.google.com", kDefaultServerPort),
272 host_port_proxy_pair_.second);
273
274 host_resolver_.set_synchronous_mode(true);
275 host_resolver_.rules()->AddIPLiteralRule(
276 kDefaultServerHostName, "192.168.0.1", "");
277 host_resolver_.rules()->AddIPLiteralRule(
278 "mail.google.com", "192.168.0.1", "");
279
280 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59281 EXPECT_EQ(OK,
282 request.Request(host_port_proxy_pair_,
283 is_https_,
284 "GET",
285 cert_verifier_.get(),
286 net_log_,
287 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38288 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
289 EXPECT_TRUE(stream.get());
290
291 TestCompletionCallback callback;
292 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59293 EXPECT_EQ(OK,
294 request2.Request(server2,
295 is_https_,
296 "GET",
297 cert_verifier_.get(),
298 net_log_,
299 callback.callback()));
[email protected]eed749f92013-12-23 18:57:38300 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
301 EXPECT_TRUE(stream2.get());
302
303 factory_.OnSessionGoingAway(
304 QuicStreamFactoryPeer::GetActiveSession(&factory_,
305 host_port_proxy_pair_));
306 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(&factory_,
307 host_port_proxy_pair_));
308 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(&factory_, server2));
309
310 TestCompletionCallback callback3;
311 QuicStreamRequest request3(&factory_);
[email protected]974849d2014-02-06 01:32:59312 EXPECT_EQ(OK,
313 request3.Request(server2,
314 is_https_,
315 "GET",
316 cert_verifier_.get(),
317 net_log_,
318 callback3.callback()));
[email protected]eed749f92013-12-23 18:57:38319 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
320 EXPECT_TRUE(stream3.get());
321
322 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_, server2));
323
324 EXPECT_TRUE(socket_data1.at_read_eof());
325 EXPECT_TRUE(socket_data1.at_write_eof());
326 EXPECT_TRUE(socket_data2.at_read_eof());
327 EXPECT_TRUE(socket_data2.at_write_eof());
328}
329
330TEST_P(QuicStreamFactoryTest, HttpsPooling) {
331 MockRead reads[] = {
332 MockRead(ASYNC, OK, 0) // EOF
333 };
334 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
335 socket_factory_.AddSocketDataProvider(&socket_data);
336 socket_data.StopAfter(1);
337
338 HostPortProxyPair server1(HostPortPair("www.example.org", 443),
339 ProxyServer::Direct());
340 HostPortProxyPair server2(HostPortPair("mail.example.org", 443),
341 ProxyServer::Direct());
342
343 // Load a cert that is valid for:
344 // www.example.org (server1)
345 // mail.example.org (server2)
346 // www.example.com
347 base::FilePath certs_dir = GetTestCertsDirectory();
348 scoped_refptr<X509Certificate> test_cert(
349 ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
350 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert);
351 SSLInfo ssl_info;
352 ssl_info.cert = test_cert.get();
353 crypto_client_stream_factory_.set_ssl_info(&ssl_info);
354
355 host_resolver_.set_synchronous_mode(true);
356 host_resolver_.rules()->AddIPLiteralRule(
357 server1.first.host(), "192.168.0.1", "");
358 host_resolver_.rules()->AddIPLiteralRule(
359 server2.first.host(), "192.168.0.1", "");
360
361 QuicStreamRequest request(&factory_);
362 is_https_ = true;
[email protected]974849d2014-02-06 01:32:59363 EXPECT_EQ(OK,
364 request.Request(server1,
365 is_https_,
366 "GET",
367 cert_verifier_.get(),
368 net_log_,
369 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38370 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
371 EXPECT_TRUE(stream.get());
372
373 TestCompletionCallback callback;
374 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59375 EXPECT_EQ(OK,
376 request2.Request(server2,
377 is_https_,
378 "GET",
379 cert_verifier_.get(),
380 net_log_,
381 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38382 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
383 EXPECT_TRUE(stream2.get());
384
385 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession(&factory_, server1),
386 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2));
387
388 EXPECT_TRUE(socket_data.at_read_eof());
389 EXPECT_TRUE(socket_data.at_write_eof());
390}
391
392TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithCertMismatch) {
393 MockRead reads[] = {
394 MockRead(ASYNC, OK, 0) // EOF
395 };
396 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0);
397 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0);
398 socket_factory_.AddSocketDataProvider(&socket_data1);
399 socket_factory_.AddSocketDataProvider(&socket_data2);
400 socket_data1.StopAfter(1);
401 socket_data2.StopAfter(1);
402
403 HostPortProxyPair server1(HostPortPair("www.example.org", 443),
404 ProxyServer::Direct());
405 HostPortProxyPair server2(HostPortPair("mail.google.com", 443),
406 ProxyServer::Direct());
407
408 // Load a cert that is valid for:
409 // www.example.org (server1)
410 // mail.example.org
411 // www.example.com
412 // But is not valid for mail.google.com (server2).
413 base::FilePath certs_dir = GetTestCertsDirectory();
414 scoped_refptr<X509Certificate> test_cert(
415 ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
416 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert);
417 SSLInfo ssl_info;
418 ssl_info.cert = test_cert.get();
419 crypto_client_stream_factory_.set_ssl_info(&ssl_info);
420
421 host_resolver_.set_synchronous_mode(true);
422 host_resolver_.rules()->AddIPLiteralRule(
423 server1.first.host(), "192.168.0.1", "");
424 host_resolver_.rules()->AddIPLiteralRule(
425 server2.first.host(), "192.168.0.1", "");
426
427 QuicStreamRequest request(&factory_);
428 is_https_ = true;
[email protected]974849d2014-02-06 01:32:59429 EXPECT_EQ(OK,
430 request.Request(server1,
431 is_https_,
432 "GET",
433 cert_verifier_.get(),
434 net_log_,
435 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38436 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
437 EXPECT_TRUE(stream.get());
438
439 TestCompletionCallback callback;
440 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59441 EXPECT_EQ(OK,
442 request2.Request(server2,
443 is_https_,
444 "GET",
445 cert_verifier_.get(),
446 net_log_,
447 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38448 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
449 EXPECT_TRUE(stream2.get());
450
451 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(&factory_, server1),
452 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2));
453
454 EXPECT_TRUE(socket_data1.at_read_eof());
455 EXPECT_TRUE(socket_data1.at_write_eof());
456 EXPECT_TRUE(socket_data2.at_read_eof());
457 EXPECT_TRUE(socket_data2.at_write_eof());
458}
459
[email protected]1e960032013-12-20 19:00:20460TEST_P(QuicStreamFactoryTest, Goaway) {
[email protected]4d283b32013-10-17 12:57:27461 MockRead reads[] = {
462 MockRead(ASYNC, OK, 0) // EOF
463 };
464 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
465 socket_data.StopAfter(1);
466 socket_factory_.AddSocketDataProvider(&socket_data);
467 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0);
468 socket_data2.StopAfter(1);
469 socket_factory_.AddSocketDataProvider(&socket_data2);
470
471 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59472 EXPECT_EQ(ERR_IO_PENDING,
473 request.Request(host_port_proxy_pair_,
474 is_https_,
475 "GET",
476 cert_verifier_.get(),
477 net_log_,
478 callback_.callback()));
[email protected]4d283b32013-10-17 12:57:27479
480 EXPECT_EQ(OK, callback_.WaitForResult());
481 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
482 EXPECT_TRUE(stream.get());
483
484 // Mark the session as going away. Ensure that while it is still alive
485 // that it is no longer active.
486 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
487 &factory_, host_port_proxy_pair_);
488 factory_.OnSessionGoingAway(session);
489 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session));
490 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(&factory_,
491 host_port_proxy_pair_));
492 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(host_port_proxy_pair_,
493 net_log_).get());
494
495 // Create a new request for the same destination and verify that a
496 // new session is created.
497 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59498 EXPECT_EQ(ERR_IO_PENDING,
499 request2.Request(host_port_proxy_pair_,
500 is_https_,
501 "GET",
502 cert_verifier_.get(),
503 net_log_,
504 callback_.callback()));
[email protected]4d283b32013-10-17 12:57:27505 EXPECT_EQ(OK, callback_.WaitForResult());
506 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
507 EXPECT_TRUE(stream2.get());
508
509 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_,
510 host_port_proxy_pair_));
511 EXPECT_NE(session,
512 QuicStreamFactoryPeer::GetActiveSession(
513 &factory_, host_port_proxy_pair_));
514 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session));
515
516 stream2.reset();
517 stream.reset();
518
519 EXPECT_TRUE(socket_data.at_read_eof());
520 EXPECT_TRUE(socket_data.at_write_eof());
[email protected]3c772402013-12-18 21:38:11521 EXPECT_TRUE(socket_data2.at_read_eof());
522 EXPECT_TRUE(socket_data2.at_write_eof());
[email protected]4d283b32013-10-17 12:57:27523}
524
[email protected]1e960032013-12-20 19:00:20525TEST_P(QuicStreamFactoryTest, MaxOpenStream) {
[email protected]0b2294d32013-08-02 00:46:36526 MockRead reads[] = {
527 MockRead(ASYNC, OK, 0) // EOF
528 };
[email protected]1e960032013-12-20 19:00:20529 QuicStreamId stream_id = GetParam() > QUIC_VERSION_12 ? 5 : 3;
530 scoped_ptr<QuicEncryptedPacket> rst(
531 maker_.MakeRstPacket(1, true, stream_id, QUIC_STREAM_CANCELLED));
[email protected]06ff5152013-08-29 01:03:05532 MockWrite writes[] = {
533 MockWrite(ASYNC, rst->data(), rst->length(), 1),
534 };
535 DeterministicSocketData socket_data(reads, arraysize(reads),
536 writes, arraysize(writes));
[email protected]0b2294d32013-08-02 00:46:36537 socket_factory_.AddSocketDataProvider(&socket_data);
538 socket_data.StopAfter(1);
539
540 HttpRequestInfo request_info;
541 std::vector<QuicHttpStream*> streams;
542 // The MockCryptoClientStream sets max_open_streams to be
543 // 2 * kDefaultMaxStreamsPerConnection.
544 for (size_t i = 0; i < 2 * kDefaultMaxStreamsPerConnection; i++) {
545 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59546 int rv = request.Request(host_port_proxy_pair_,
547 is_https_,
548 "GET",
549 cert_verifier_.get(),
550 net_log_,
[email protected]0b2294d32013-08-02 00:46:36551 callback_.callback());
552 if (i == 0) {
553 EXPECT_EQ(ERR_IO_PENDING, rv);
554 EXPECT_EQ(OK, callback_.WaitForResult());
555 } else {
556 EXPECT_EQ(OK, rv);
557 }
558 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
559 EXPECT_TRUE(stream);
560 EXPECT_EQ(OK, stream->InitializeStream(
561 &request_info, DEFAULT_PRIORITY, net_log_, CompletionCallback()));
562 streams.push_back(stream.release());
563 }
564
565 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59566 EXPECT_EQ(OK,
567 request.Request(host_port_proxy_pair_,
568 is_https_,
569 "GET",
570 cert_verifier_.get(),
571 net_log_,
572 CompletionCallback()));
[email protected]0b2294d32013-08-02 00:46:36573 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
574 EXPECT_TRUE(stream);
575 EXPECT_EQ(ERR_IO_PENDING, stream->InitializeStream(
576 &request_info, DEFAULT_PRIORITY, net_log_, callback_.callback()));
577
578 // Close the first stream.
579 streams.front()->Close(false);
580
581 ASSERT_TRUE(callback_.have_result());
582
583 EXPECT_EQ(OK, callback_.WaitForResult());
584
585 EXPECT_TRUE(socket_data.at_read_eof());
586 EXPECT_TRUE(socket_data.at_write_eof());
587 STLDeleteElements(&streams);
588}
589
[email protected]1e960032013-12-20 19:00:20590TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) {
[email protected]0edce6a2013-05-08 18:02:40591 DeterministicSocketData socket_data(NULL, 0, NULL, 0);
[email protected]e13201d82012-12-12 05:00:32592 socket_factory_.AddSocketDataProvider(&socket_data);
593
[email protected]3c772402013-12-18 21:38:11594 host_resolver_.rules()->AddSimulatedFailure(kDefaultServerHostName);
[email protected]e13201d82012-12-12 05:00:32595
596 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59597 EXPECT_EQ(ERR_IO_PENDING,
598 request.Request(host_port_proxy_pair_,
599 is_https_,
600 "GET",
601 cert_verifier_.get(),
602 net_log_,
603 callback_.callback()));
[email protected]e13201d82012-12-12 05:00:32604
605 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult());
606
607 EXPECT_TRUE(socket_data.at_read_eof());
608 EXPECT_TRUE(socket_data.at_write_eof());
609}
610
[email protected]1e960032013-12-20 19:00:20611TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) {
[email protected]3c772402013-12-18 21:38:11612 MockConnect connect(SYNCHRONOUS, ERR_ADDRESS_IN_USE);
613 DeterministicSocketData socket_data(NULL, 0, NULL, 0);
614 socket_data.set_connect_data(connect);
615 socket_factory_.AddSocketDataProvider(&socket_data);
616 socket_data.StopAfter(1);
617
618 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59619 EXPECT_EQ(ERR_IO_PENDING,
620 request.Request(host_port_proxy_pair_,
621 is_https_,
622 "GET",
623 cert_verifier_.get(),
624 net_log_,
625 callback_.callback()));
[email protected]3c772402013-12-18 21:38:11626
627 EXPECT_EQ(ERR_ADDRESS_IN_USE, callback_.WaitForResult());
628
629 EXPECT_TRUE(socket_data.at_read_eof());
630 EXPECT_TRUE(socket_data.at_write_eof());
631}
632
[email protected]1e960032013-12-20 19:00:20633TEST_P(QuicStreamFactoryTest, CancelCreate) {
[email protected]69dfd1b2013-06-04 22:20:12634 MockRead reads[] = {
[email protected]25c31dc2013-06-05 17:56:04635 MockRead(ASYNC, OK, 0) // EOF
[email protected]69dfd1b2013-06-04 22:20:12636 };
[email protected]25c31dc2013-06-05 17:56:04637 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
[email protected]e13201d82012-12-12 05:00:32638 socket_factory_.AddSocketDataProvider(&socket_data);
639 {
640 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59641 EXPECT_EQ(ERR_IO_PENDING,
642 request.Request(host_port_proxy_pair_,
643 is_https_,
644 "GET",
645 cert_verifier_.get(),
646 net_log_,
647 callback_.callback()));
[email protected]e13201d82012-12-12 05:00:32648 }
649
[email protected]25c31dc2013-06-05 17:56:04650 socket_data.StopAfter(1);
[email protected]e13201d82012-12-12 05:00:32651 base::RunLoop run_loop;
652 run_loop.RunUntilIdle();
653
654 scoped_ptr<QuicHttpStream> stream(
655 factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_));
656 EXPECT_TRUE(stream.get());
657 stream.reset();
658
659 EXPECT_TRUE(socket_data.at_read_eof());
660 EXPECT_TRUE(socket_data.at_write_eof());
661}
662
[email protected]1e960032013-12-20 19:00:20663TEST_P(QuicStreamFactoryTest, CreateConsistentEphemeralPort) {
[email protected]3c772402013-12-18 21:38:11664 // Sequentially connect to the default host, then another host, and then the
665 // default host. Verify that the default host gets a consistent ephemeral
666 // port, that is different from the other host's connection.
667
668 std::string other_server_name = "other.google.com";
669 EXPECT_NE(kDefaultServerHostName, other_server_name);
670 HostPortPair host_port_pair2(other_server_name, kDefaultServerPort);
671 HostPortProxyPair host_port_proxy_pair2(host_port_pair2,
672 host_port_proxy_pair_.second);
673
674 int original_port = GetSourcePortForNewSession(host_port_proxy_pair_);
675 EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_proxy_pair2));
676 EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_proxy_pair_));
677}
678
[email protected]1e960032013-12-20 19:00:20679TEST_P(QuicStreamFactoryTest, CloseAllSessions) {
[email protected]56dfb902013-01-03 23:17:55680 MockRead reads[] = {
[email protected]0edce6a2013-05-08 18:02:40681 MockRead(ASYNC, 0, 0) // EOF
[email protected]56dfb902013-01-03 23:17:55682 };
[email protected]459a7402014-02-10 12:58:52683 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
684 std::vector<MockWrite> writes;
685 if (GetParam() > QUIC_VERSION_13)
686 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
687 DeterministicSocketData socket_data(reads, arraysize(reads),
688 writes.empty() ? NULL : &writes[0],
689 writes.size());
[email protected]56dfb902013-01-03 23:17:55690 socket_factory_.AddSocketDataProvider(&socket_data);
[email protected]0edce6a2013-05-08 18:02:40691 socket_data.StopAfter(1);
[email protected]56dfb902013-01-03 23:17:55692
[email protected]69dfd1b2013-06-04 22:20:12693 MockRead reads2[] = {
[email protected]25c31dc2013-06-05 17:56:04694 MockRead(ASYNC, 0, 0) // EOF
[email protected]69dfd1b2013-06-04 22:20:12695 };
[email protected]25c31dc2013-06-05 17:56:04696 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0);
[email protected]56dfb902013-01-03 23:17:55697 socket_factory_.AddSocketDataProvider(&socket_data2);
[email protected]0edce6a2013-05-08 18:02:40698 socket_data2.StopAfter(1);
[email protected]56dfb902013-01-03 23:17:55699
700 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59701 EXPECT_EQ(ERR_IO_PENDING,
702 request.Request(host_port_proxy_pair_,
703 is_https_,
704 "GET",
705 cert_verifier_.get(),
706 net_log_,
707 callback_.callback()));
[email protected]56dfb902013-01-03 23:17:55708
709 EXPECT_EQ(OK, callback_.WaitForResult());
710 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
[email protected]0b2294d32013-08-02 00:46:36711 HttpRequestInfo request_info;
712 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
713 DEFAULT_PRIORITY,
714 net_log_, CompletionCallback()));
[email protected]56dfb902013-01-03 23:17:55715
716 // Close the session and verify that stream saw the error.
717 factory_.CloseAllSessions(ERR_INTERNET_DISCONNECTED);
718 EXPECT_EQ(ERR_INTERNET_DISCONNECTED,
719 stream->ReadResponseHeaders(callback_.callback()));
720
721 // Now attempting to request a stream to the same origin should create
722 // a new session.
723
724 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59725 EXPECT_EQ(ERR_IO_PENDING,
726 request2.Request(host_port_proxy_pair_,
727 is_https_,
728 "GET",
729 cert_verifier_.get(),
730 net_log_,
731 callback_.callback()));
[email protected]56dfb902013-01-03 23:17:55732
733 EXPECT_EQ(OK, callback_.WaitForResult());
734 stream = request2.ReleaseStream();
735 stream.reset(); // Will reset stream 3.
736
737 EXPECT_TRUE(socket_data.at_read_eof());
738 EXPECT_TRUE(socket_data.at_write_eof());
739 EXPECT_TRUE(socket_data2.at_read_eof());
740 EXPECT_TRUE(socket_data2.at_write_eof());
741}
742
[email protected]1e960032013-12-20 19:00:20743TEST_P(QuicStreamFactoryTest, OnIPAddressChanged) {
[email protected]f698a012013-05-06 20:18:59744 MockRead reads[] = {
[email protected]0edce6a2013-05-08 18:02:40745 MockRead(ASYNC, 0, 0) // EOF
[email protected]f698a012013-05-06 20:18:59746 };
[email protected]459a7402014-02-10 12:58:52747 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
748 std::vector<MockWrite> writes;
749 if (GetParam() > QUIC_VERSION_13)
750 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
751 DeterministicSocketData socket_data(reads, arraysize(reads),
752 writes.empty() ? NULL : &writes[0],
753 writes.size());
[email protected]f698a012013-05-06 20:18:59754 socket_factory_.AddSocketDataProvider(&socket_data);
[email protected]0edce6a2013-05-08 18:02:40755 socket_data.StopAfter(1);
[email protected]f698a012013-05-06 20:18:59756
[email protected]69dfd1b2013-06-04 22:20:12757 MockRead reads2[] = {
[email protected]25c31dc2013-06-05 17:56:04758 MockRead(ASYNC, 0, 0) // EOF
[email protected]69dfd1b2013-06-04 22:20:12759 };
[email protected]25c31dc2013-06-05 17:56:04760 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0);
[email protected]f698a012013-05-06 20:18:59761 socket_factory_.AddSocketDataProvider(&socket_data2);
[email protected]0edce6a2013-05-08 18:02:40762 socket_data2.StopAfter(1);
[email protected]f698a012013-05-06 20:18:59763
764 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59765 EXPECT_EQ(ERR_IO_PENDING,
766 request.Request(host_port_proxy_pair_,
767 is_https_,
768 "GET",
769 cert_verifier_.get(),
770 net_log_,
771 callback_.callback()));
[email protected]f698a012013-05-06 20:18:59772
773 EXPECT_EQ(OK, callback_.WaitForResult());
774 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
[email protected]0b2294d32013-08-02 00:46:36775 HttpRequestInfo request_info;
776 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
777 DEFAULT_PRIORITY,
778 net_log_, CompletionCallback()));
[email protected]f698a012013-05-06 20:18:59779
780 // Change the IP address and verify that stream saw the error.
781 factory_.OnIPAddressChanged();
782 EXPECT_EQ(ERR_NETWORK_CHANGED,
783 stream->ReadResponseHeaders(callback_.callback()));
[email protected]11c05872013-08-20 02:04:12784 EXPECT_TRUE(factory_.require_confirmation());
[email protected]f698a012013-05-06 20:18:59785
786 // Now attempting to request a stream to the same origin should create
787 // a new session.
788
789 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59790 EXPECT_EQ(ERR_IO_PENDING,
791 request2.Request(host_port_proxy_pair_,
792 is_https_,
793 "GET",
794 cert_verifier_.get(),
795 net_log_,
796 callback_.callback()));
[email protected]f698a012013-05-06 20:18:59797
798 EXPECT_EQ(OK, callback_.WaitForResult());
799 stream = request2.ReleaseStream();
800 stream.reset(); // Will reset stream 3.
801
802 EXPECT_TRUE(socket_data.at_read_eof());
803 EXPECT_TRUE(socket_data.at_write_eof());
804 EXPECT_TRUE(socket_data2.at_read_eof());
805 EXPECT_TRUE(socket_data2.at_write_eof());
806}
807
[email protected]1e960032013-12-20 19:00:20808TEST_P(QuicStreamFactoryTest, OnCertAdded) {
[email protected]d7d1e50b2013-11-25 22:08:09809 MockRead reads[] = {
810 MockRead(ASYNC, 0, 0) // EOF
811 };
[email protected]459a7402014-02-10 12:58:52812 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
813 std::vector<MockWrite> writes;
814 if (GetParam() > QUIC_VERSION_13)
815 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
816 DeterministicSocketData socket_data(reads, arraysize(reads),
817 writes.empty() ? NULL : &writes[0],
818 writes.size());
[email protected]d7d1e50b2013-11-25 22:08:09819 socket_factory_.AddSocketDataProvider(&socket_data);
820 socket_data.StopAfter(1);
821
822 MockRead reads2[] = {
823 MockRead(ASYNC, 0, 0) // EOF
824 };
825 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0);
826 socket_factory_.AddSocketDataProvider(&socket_data2);
827 socket_data2.StopAfter(1);
828
829 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59830 EXPECT_EQ(ERR_IO_PENDING,
831 request.Request(host_port_proxy_pair_,
832 is_https_,
833 "GET",
834 cert_verifier_.get(),
835 net_log_,
836 callback_.callback()));
[email protected]d7d1e50b2013-11-25 22:08:09837
838 EXPECT_EQ(OK, callback_.WaitForResult());
839 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
840 HttpRequestInfo request_info;
841 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
842 DEFAULT_PRIORITY,
843 net_log_, CompletionCallback()));
844
845 // Add a cert and verify that stream saw the event.
846 factory_.OnCertAdded(NULL);
847 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED,
848 stream->ReadResponseHeaders(callback_.callback()));
849 EXPECT_FALSE(factory_.require_confirmation());
850
851 // Now attempting to request a stream to the same origin should create
852 // a new session.
853
854 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59855 EXPECT_EQ(ERR_IO_PENDING,
856 request2.Request(host_port_proxy_pair_,
857 is_https_,
858 "GET",
859 cert_verifier_.get(),
860 net_log_,
861 callback_.callback()));
[email protected]d7d1e50b2013-11-25 22:08:09862
863 EXPECT_EQ(OK, callback_.WaitForResult());
864 stream = request2.ReleaseStream();
865 stream.reset(); // Will reset stream 3.
866
867 EXPECT_TRUE(socket_data.at_read_eof());
868 EXPECT_TRUE(socket_data.at_write_eof());
869 EXPECT_TRUE(socket_data2.at_read_eof());
870 EXPECT_TRUE(socket_data2.at_write_eof());
871}
872
[email protected]1e960032013-12-20 19:00:20873TEST_P(QuicStreamFactoryTest, OnCACertChanged) {
[email protected]d7d1e50b2013-11-25 22:08:09874 MockRead reads[] = {
875 MockRead(ASYNC, 0, 0) // EOF
876 };
[email protected]459a7402014-02-10 12:58:52877 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
878 std::vector<MockWrite> writes;
879 if (GetParam() > QUIC_VERSION_13)
880 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
881 DeterministicSocketData socket_data(reads, arraysize(reads),
882 writes.empty() ? NULL : &writes[0],
883 writes.size());
[email protected]d7d1e50b2013-11-25 22:08:09884 socket_factory_.AddSocketDataProvider(&socket_data);
885 socket_data.StopAfter(1);
886
887 MockRead reads2[] = {
888 MockRead(ASYNC, 0, 0) // EOF
889 };
890 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0);
891 socket_factory_.AddSocketDataProvider(&socket_data2);
892 socket_data2.StopAfter(1);
893
894 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59895 EXPECT_EQ(ERR_IO_PENDING,
896 request.Request(host_port_proxy_pair_,
897 is_https_,
898 "GET",
899 cert_verifier_.get(),
900 net_log_,
901 callback_.callback()));
[email protected]d7d1e50b2013-11-25 22:08:09902
903 EXPECT_EQ(OK, callback_.WaitForResult());
904 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
905 HttpRequestInfo request_info;
906 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
907 DEFAULT_PRIORITY,
908 net_log_, CompletionCallback()));
909
910 // Change the CA cert and verify that stream saw the event.
911 factory_.OnCACertChanged(NULL);
912 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED,
913 stream->ReadResponseHeaders(callback_.callback()));
914 EXPECT_FALSE(factory_.require_confirmation());
915
916 // Now attempting to request a stream to the same origin should create
917 // a new session.
918
919 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59920 EXPECT_EQ(ERR_IO_PENDING,
921 request2.Request(host_port_proxy_pair_,
922 is_https_,
923 "GET",
924 cert_verifier_.get(),
925 net_log_,
926 callback_.callback()));
[email protected]d7d1e50b2013-11-25 22:08:09927
928 EXPECT_EQ(OK, callback_.WaitForResult());
929 stream = request2.ReleaseStream();
930 stream.reset(); // Will reset stream 3.
931
932 EXPECT_TRUE(socket_data.at_read_eof());
933 EXPECT_TRUE(socket_data.at_write_eof());
934 EXPECT_TRUE(socket_data2.at_read_eof());
935 EXPECT_TRUE(socket_data2.at_write_eof());
936}
937
[email protected]1e960032013-12-20 19:00:20938TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) {
[email protected]6e12d702013-11-13 00:17:17939 vector<string> cannoncial_suffixes;
940 cannoncial_suffixes.push_back(string(".c.youtube.com"));
941 cannoncial_suffixes.push_back(string(".googlevideo.com"));
[email protected]c49ff182013-09-28 08:33:26942
[email protected]6e12d702013-11-13 00:17:17943 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) {
944 string r1_host_name("r1");
945 string r2_host_name("r2");
946 r1_host_name.append(cannoncial_suffixes[i]);
947 r2_host_name.append(cannoncial_suffixes[i]);
[email protected]b70fdb792013-10-25 19:04:14948
[email protected]6e12d702013-11-13 00:17:17949 HostPortProxyPair host_port_proxy_pair1(HostPortPair(r1_host_name, 80),
950 ProxyServer::Direct());
[email protected]c49ff182013-09-28 08:33:26951
[email protected]6e12d702013-11-13 00:17:17952 QuicCryptoClientConfig* crypto_config1 =
953 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_,
954 host_port_proxy_pair1);
955 DCHECK(crypto_config1);
956 QuicCryptoClientConfig::CachedState* cached1 =
957 crypto_config1->LookupOrCreate(host_port_proxy_pair1.first.host());
958 EXPECT_FALSE(cached1->proof_valid());
959 EXPECT_TRUE(cached1->source_address_token().empty());
960
961 // Mutate the cached1 to have different data.
962 // TODO(rtenneti): mutate other members of CachedState.
963 cached1->set_source_address_token(r1_host_name);
964 cached1->SetProofValid();
965
966 HostPortProxyPair host_port_proxy_pair2(HostPortPair(r2_host_name, 80),
967 ProxyServer::Direct());
968 QuicCryptoClientConfig* crypto_config2 =
969 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_,
970 host_port_proxy_pair2);
971 DCHECK(crypto_config2);
972 QuicCryptoClientConfig::CachedState* cached2 =
973 crypto_config2->LookupOrCreate(host_port_proxy_pair2.first.host());
974 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token());
975 EXPECT_TRUE(cached2->proof_valid());
976 }
[email protected]b70fdb792013-10-25 19:04:14977}
978
[email protected]1e960032013-12-20 19:00:20979TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) {
[email protected]6e12d702013-11-13 00:17:17980 vector<string> cannoncial_suffixes;
981 cannoncial_suffixes.push_back(string(".c.youtube.com"));
982 cannoncial_suffixes.push_back(string(".googlevideo.com"));
[email protected]b70fdb792013-10-25 19:04:14983
[email protected]6e12d702013-11-13 00:17:17984 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) {
985 string r3_host_name("r3");
986 string r4_host_name("r4");
987 r3_host_name.append(cannoncial_suffixes[i]);
988 r4_host_name.append(cannoncial_suffixes[i]);
[email protected]b70fdb792013-10-25 19:04:14989
[email protected]6e12d702013-11-13 00:17:17990 HostPortProxyPair host_port_proxy_pair1(HostPortPair(r3_host_name, 80),
991 ProxyServer::Direct());
[email protected]b70fdb792013-10-25 19:04:14992
[email protected]6e12d702013-11-13 00:17:17993 QuicCryptoClientConfig* crypto_config1 =
994 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_,
995 host_port_proxy_pair1);
996 DCHECK(crypto_config1);
997 QuicCryptoClientConfig::CachedState* cached1 =
998 crypto_config1->LookupOrCreate(host_port_proxy_pair1.first.host());
999 EXPECT_FALSE(cached1->proof_valid());
1000 EXPECT_TRUE(cached1->source_address_token().empty());
1001
1002 // Mutate the cached1 to have different data.
1003 // TODO(rtenneti): mutate other members of CachedState.
1004 cached1->set_source_address_token(r3_host_name);
1005 cached1->SetProofInvalid();
1006
1007 HostPortProxyPair host_port_proxy_pair2(HostPortPair(r4_host_name, 80),
1008 ProxyServer::Direct());
1009 QuicCryptoClientConfig* crypto_config2 =
1010 QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_,
1011 host_port_proxy_pair2);
1012 DCHECK(crypto_config2);
1013 QuicCryptoClientConfig::CachedState* cached2 =
1014 crypto_config2->LookupOrCreate(host_port_proxy_pair2.first.host());
1015 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token());
1016 EXPECT_TRUE(cached2->source_address_token().empty());
1017 EXPECT_FALSE(cached2->proof_valid());
1018 }
[email protected]c49ff182013-09-28 08:33:261019}
1020
[email protected]e13201d82012-12-12 05:00:321021} // namespace test
[email protected]e13201d82012-12-12 05:00:321022} // namespace net