[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "net/quic/quic_stream_factory.h" |
| 6 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 7 | #include "base/run_loop.h" |
[email protected] | fc9be580 | 2013-06-11 10:56:51 | [diff] [blame] | 8 | #include "base/strings/string_util.h" |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 9 | #include "net/cert/cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 10 | #include "net/dns/mock_host_resolver.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 11 | #include "net/http/http_response_headers.h" |
| 12 | #include "net/http/http_response_info.h" |
| 13 | #include "net/http/http_util.h" |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 14 | #include "net/quic/crypto/crypto_handshake.h" |
[email protected] | 4df6984 | 2013-02-27 06:32:16 | [diff] [blame] | 15 | #include "net/quic/crypto/quic_decrypter.h" |
| 16 | #include "net/quic/crypto/quic_encrypter.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 17 | #include "net/quic/quic_http_stream.h" |
| 18 | #include "net/quic/test_tools/mock_clock.h" |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 19 | #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" |
[email protected] | 9558c5d3 | 2012-12-22 00:08:14 | [diff] [blame] | 20 | #include "net/quic/test_tools/mock_random.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 21 | #include "net/quic/test_tools/quic_test_utils.h" |
| 22 | #include "net/socket/socket_test_util.h" |
| 23 | #include "testing/gtest/include/gtest/gtest.h" |
| 24 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 25 | using base::StringPiece; |
| 26 | using std::string; |
| 27 | using std::vector; |
| 28 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 29 | namespace net { |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 30 | namespace test { |
| 31 | |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 32 | class QuicStreamFactoryPeer { |
| 33 | public: |
| 34 | static QuicCryptoClientConfig* GetOrCreateCryptoConfig( |
| 35 | QuicStreamFactory* factory, |
| 36 | const HostPortProxyPair& host_port_proxy_pair) { |
| 37 | return factory->GetOrCreateCryptoConfig(host_port_proxy_pair); |
| 38 | } |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 39 | |
| 40 | static bool HasActiveSession(QuicStreamFactory* factory, |
| 41 | const HostPortProxyPair& host_port_proxy_pair) { |
| 42 | return factory->HasActiveSession(host_port_proxy_pair); |
| 43 | } |
| 44 | |
| 45 | static QuicClientSession* GetActiveSession( |
| 46 | QuicStreamFactory* factory, |
| 47 | const HostPortProxyPair& host_port_proxy_pair) { |
| 48 | DCHECK(factory->HasActiveSession(host_port_proxy_pair)); |
| 49 | return factory->active_sessions_[host_port_proxy_pair]; |
| 50 | } |
| 51 | |
| 52 | static bool IsLiveSession(QuicStreamFactory* factory, |
| 53 | QuicClientSession* session) { |
| 54 | for (QuicStreamFactory::SessionSet::iterator it = |
| 55 | factory->all_sessions_.begin(); |
| 56 | it != factory->all_sessions_.end(); ++it) { |
| 57 | if (*it == session) |
| 58 | return true; |
| 59 | } |
| 60 | return false; |
| 61 | } |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 62 | }; |
| 63 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 64 | class QuicStreamFactoryTest : public ::testing::Test { |
| 65 | protected: |
| 66 | QuicStreamFactoryTest() |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame^] | 67 | : random_generator_(0), |
| 68 | clock_(new MockClock()), |
[email protected] | 872edd9e | 2013-01-16 08:51:15 | [diff] [blame] | 69 | factory_(&host_resolver_, &socket_factory_, |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 70 | base::WeakPtr<HttpServerProperties>(), |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 71 | &crypto_client_stream_factory_, |
[email protected] | 256fe9b | 2013-11-27 01:58:02 | [diff] [blame] | 72 | &random_generator_, clock_, kDefaultMaxPacketSize), |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 73 | host_port_proxy_pair_(HostPortPair("www.google.com", 443), |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 74 | ProxyServer::Direct()), |
| 75 | is_https_(false), |
| 76 | cert_verifier_(CertVerifier::CreateDefault()) { |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 77 | factory_.set_require_confirmation(false); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 78 | } |
| 79 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 80 | scoped_ptr<QuicEncryptedPacket> ConstructRstPacket( |
| 81 | QuicPacketSequenceNumber num, |
| 82 | QuicStreamId stream_id) { |
| 83 | QuicPacketHeader header; |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame^] | 84 | header.public_header.guid = random_generator_.RandUint64(); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 85 | header.public_header.reset_flag = false; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 86 | header.public_header.version_flag = true; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 87 | header.packet_sequence_number = num; |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 88 | header.public_header.sequence_number_length = PACKET_1BYTE_SEQUENCE_NUMBER; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 89 | header.entropy_flag = false; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 90 | header.fec_flag = false; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 91 | header.fec_group = 0; |
| 92 | |
[email protected] | 6548b66 | 2013-10-23 01:38:53 | [diff] [blame] | 93 | QuicRstStreamFrame rst(stream_id, QUIC_STREAM_CANCELLED); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 94 | return scoped_ptr<QuicEncryptedPacket>( |
| 95 | ConstructPacket(header, QuicFrame(&rst))); |
| 96 | } |
| 97 | |
| 98 | scoped_ptr<QuicEncryptedPacket> ConstructAckPacket( |
| 99 | QuicPacketSequenceNumber largest_received, |
| 100 | QuicPacketSequenceNumber least_unacked) { |
| 101 | QuicPacketHeader header; |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame^] | 102 | header.public_header.guid = random_generator_.RandUint64(); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 103 | header.public_header.reset_flag = false; |
| 104 | header.public_header.version_flag = false; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 105 | header.packet_sequence_number = 2; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 106 | header.entropy_flag = false; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 107 | header.fec_flag = false; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 108 | header.fec_group = 0; |
| 109 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 110 | QuicAckFrame ack(largest_received, QuicTime::Zero(), least_unacked); |
[email protected] | dda3e9b | 2012-12-22 21:49:25 | [diff] [blame] | 111 | QuicCongestionFeedbackFrame feedback; |
| 112 | feedback.type = kTCP; |
| 113 | feedback.tcp.accumulated_number_of_lost_packets = 0; |
| 114 | feedback.tcp.receive_window = 16000; |
| 115 | |
[email protected] | b007e63 | 2013-10-28 08:39:25 | [diff] [blame] | 116 | QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), false); |
[email protected] | dda3e9b | 2012-12-22 21:49:25 | [diff] [blame] | 117 | QuicFrames frames; |
| 118 | frames.push_back(QuicFrame(&ack)); |
| 119 | frames.push_back(QuicFrame(&feedback)); |
| 120 | scoped_ptr<QuicPacket> packet( |
[email protected] | 3e60db8 | 2013-08-05 19:43:06 | [diff] [blame] | 121 | framer.BuildUnsizedDataPacket(header, frames).packet); |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 122 | return scoped_ptr<QuicEncryptedPacket>(framer.EncryptPacket( |
| 123 | ENCRYPTION_NONE, header.packet_sequence_number, *packet)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 124 | } |
| 125 | |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 126 | // Returns a newly created packet to send congestion feedback data. |
| 127 | scoped_ptr<QuicEncryptedPacket> ConstructFeedbackPacket( |
| 128 | QuicPacketSequenceNumber sequence_number) { |
| 129 | QuicPacketHeader header; |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame^] | 130 | header.public_header.guid = random_generator_.RandUint64(); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 131 | header.public_header.reset_flag = false; |
| 132 | header.public_header.version_flag = false; |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 133 | header.packet_sequence_number = sequence_number; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 134 | header.entropy_flag = false; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 135 | header.fec_flag = false; |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 136 | header.fec_group = 0; |
| 137 | |
| 138 | QuicCongestionFeedbackFrame frame; |
| 139 | frame.type = kTCP; |
| 140 | frame.tcp.accumulated_number_of_lost_packets = 0; |
| 141 | frame.tcp.receive_window = 16000; |
| 142 | |
| 143 | return scoped_ptr<QuicEncryptedPacket>( |
| 144 | ConstructPacket(header, QuicFrame(&frame))); |
| 145 | } |
| 146 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 147 | scoped_ptr<QuicEncryptedPacket> ConstructPacket( |
| 148 | const QuicPacketHeader& header, |
| 149 | const QuicFrame& frame) { |
[email protected] | b007e63 | 2013-10-28 08:39:25 | [diff] [blame] | 150 | QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), false); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 151 | QuicFrames frames; |
| 152 | frames.push_back(frame); |
[email protected] | 610a7e94 | 2012-12-18 00:21:39 | [diff] [blame] | 153 | scoped_ptr<QuicPacket> packet( |
[email protected] | 3e60db8 | 2013-08-05 19:43:06 | [diff] [blame] | 154 | framer.BuildUnsizedDataPacket(header, frames).packet); |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 155 | return scoped_ptr<QuicEncryptedPacket>(framer.EncryptPacket( |
| 156 | ENCRYPTION_NONE, header.packet_sequence_number, *packet)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | MockHostResolver host_resolver_; |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 160 | DeterministicMockClientSocketFactory socket_factory_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 161 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
[email protected] | 9558c5d3 | 2012-12-22 00:08:14 | [diff] [blame] | 162 | MockRandom random_generator_; |
[email protected] | 872edd9e | 2013-01-16 08:51:15 | [diff] [blame] | 163 | MockClock* clock_; // Owned by factory_. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 164 | QuicStreamFactory factory_; |
| 165 | HostPortProxyPair host_port_proxy_pair_; |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 166 | bool is_https_; |
[email protected] | ce542d5 | 2013-07-11 01:08:39 | [diff] [blame] | 167 | scoped_ptr<CertVerifier> cert_verifier_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 168 | BoundNetLog net_log_; |
| 169 | TestCompletionCallback callback_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | TEST_F(QuicStreamFactoryTest, CreateIfSessionExists) { |
| 173 | EXPECT_EQ(NULL, factory_.CreateIfSessionExists(host_port_proxy_pair_, |
| 174 | net_log_).get()); |
| 175 | } |
| 176 | |
| 177 | TEST_F(QuicStreamFactoryTest, Create) { |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 178 | MockRead reads[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 179 | MockRead(ASYNC, OK, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 180 | }; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 181 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 182 | socket_factory_.AddSocketDataProvider(&socket_data); |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 183 | socket_data.StopAfter(1); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 184 | |
| 185 | QuicStreamRequest request(&factory_); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 186 | EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, is_https_, |
[email protected] | ce542d5 | 2013-07-11 01:08:39 | [diff] [blame] | 187 | cert_verifier_.get(), net_log_, |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 188 | callback_.callback())); |
| 189 | |
| 190 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 191 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 192 | EXPECT_TRUE(stream.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 193 | |
| 194 | // Will reset stream 3. |
| 195 | stream = factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_); |
| 196 | EXPECT_TRUE(stream.get()); |
| 197 | |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 198 | // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result |
| 199 | // in streams on different sessions. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 200 | QuicStreamRequest request2(&factory_); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 201 | EXPECT_EQ(OK, request2.Request(host_port_proxy_pair_, is_https_, |
[email protected] | ce542d5 | 2013-07-11 01:08:39 | [diff] [blame] | 202 | cert_verifier_.get(), net_log_, |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 203 | callback_.callback())); |
| 204 | stream = request2.ReleaseStream(); // Will reset stream 5. |
| 205 | stream.reset(); // Will reset stream 7. |
| 206 | |
| 207 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 208 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 209 | } |
| 210 | |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 211 | TEST_F(QuicStreamFactoryTest, Goaway) { |
| 212 | MockRead reads[] = { |
| 213 | MockRead(ASYNC, OK, 0) // EOF |
| 214 | }; |
| 215 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 216 | socket_data.StopAfter(1); |
| 217 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 218 | DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); |
| 219 | socket_data2.StopAfter(1); |
| 220 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 221 | |
| 222 | QuicStreamRequest request(&factory_); |
| 223 | EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, is_https_, |
| 224 | cert_verifier_.get(), net_log_, |
| 225 | callback_.callback())); |
| 226 | |
| 227 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 228 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 229 | EXPECT_TRUE(stream.get()); |
| 230 | |
| 231 | // Mark the session as going away. Ensure that while it is still alive |
| 232 | // that it is no longer active. |
| 233 | QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( |
| 234 | &factory_, host_port_proxy_pair_); |
| 235 | factory_.OnSessionGoingAway(session); |
| 236 | EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); |
| 237 | EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(&factory_, |
| 238 | host_port_proxy_pair_)); |
| 239 | EXPECT_EQ(NULL, factory_.CreateIfSessionExists(host_port_proxy_pair_, |
| 240 | net_log_).get()); |
| 241 | |
| 242 | // Create a new request for the same destination and verify that a |
| 243 | // new session is created. |
| 244 | QuicStreamRequest request2(&factory_); |
| 245 | EXPECT_EQ(ERR_IO_PENDING, request2.Request(host_port_proxy_pair_, is_https_, |
| 246 | cert_verifier_.get(), net_log_, |
| 247 | callback_.callback())); |
| 248 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 249 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 250 | EXPECT_TRUE(stream2.get()); |
| 251 | |
| 252 | EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_, |
| 253 | host_port_proxy_pair_)); |
| 254 | EXPECT_NE(session, |
| 255 | QuicStreamFactoryPeer::GetActiveSession( |
| 256 | &factory_, host_port_proxy_pair_)); |
| 257 | EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); |
| 258 | |
| 259 | stream2.reset(); |
| 260 | stream.reset(); |
| 261 | |
| 262 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 263 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 264 | } |
| 265 | |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 266 | TEST_F(QuicStreamFactoryTest, MaxOpenStream) { |
| 267 | MockRead reads[] = { |
| 268 | MockRead(ASYNC, OK, 0) // EOF |
| 269 | }; |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 270 | scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket(1, 3)); |
| 271 | MockWrite writes[] = { |
| 272 | MockWrite(ASYNC, rst->data(), rst->length(), 1), |
| 273 | }; |
| 274 | DeterministicSocketData socket_data(reads, arraysize(reads), |
| 275 | writes, arraysize(writes)); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 276 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 277 | socket_data.StopAfter(1); |
| 278 | |
| 279 | HttpRequestInfo request_info; |
| 280 | std::vector<QuicHttpStream*> streams; |
| 281 | // The MockCryptoClientStream sets max_open_streams to be |
| 282 | // 2 * kDefaultMaxStreamsPerConnection. |
| 283 | for (size_t i = 0; i < 2 * kDefaultMaxStreamsPerConnection; i++) { |
| 284 | QuicStreamRequest request(&factory_); |
| 285 | int rv = request.Request(host_port_proxy_pair_, is_https_, |
| 286 | cert_verifier_.get(), net_log_, |
| 287 | callback_.callback()); |
| 288 | if (i == 0) { |
| 289 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 290 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 291 | } else { |
| 292 | EXPECT_EQ(OK, rv); |
| 293 | } |
| 294 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 295 | EXPECT_TRUE(stream); |
| 296 | EXPECT_EQ(OK, stream->InitializeStream( |
| 297 | &request_info, DEFAULT_PRIORITY, net_log_, CompletionCallback())); |
| 298 | streams.push_back(stream.release()); |
| 299 | } |
| 300 | |
| 301 | QuicStreamRequest request(&factory_); |
| 302 | EXPECT_EQ(OK, request.Request(host_port_proxy_pair_, is_https_, |
| 303 | cert_verifier_.get(), net_log_, |
| 304 | CompletionCallback())); |
| 305 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 306 | EXPECT_TRUE(stream); |
| 307 | EXPECT_EQ(ERR_IO_PENDING, stream->InitializeStream( |
| 308 | &request_info, DEFAULT_PRIORITY, net_log_, callback_.callback())); |
| 309 | |
| 310 | // Close the first stream. |
| 311 | streams.front()->Close(false); |
| 312 | |
| 313 | ASSERT_TRUE(callback_.have_result()); |
| 314 | |
| 315 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 316 | |
| 317 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 318 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 319 | STLDeleteElements(&streams); |
| 320 | } |
| 321 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 322 | TEST_F(QuicStreamFactoryTest, CreateError) { |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 323 | DeterministicSocketData socket_data(NULL, 0, NULL, 0); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 324 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 325 | |
| 326 | host_resolver_.rules()->AddSimulatedFailure("www.google.com"); |
| 327 | |
| 328 | QuicStreamRequest request(&factory_); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 329 | EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, is_https_, |
[email protected] | ce542d5 | 2013-07-11 01:08:39 | [diff] [blame] | 330 | cert_verifier_.get(), net_log_, |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 331 | callback_.callback())); |
| 332 | |
| 333 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); |
| 334 | |
| 335 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 336 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 337 | } |
| 338 | |
| 339 | TEST_F(QuicStreamFactoryTest, CancelCreate) { |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 340 | MockRead reads[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 341 | MockRead(ASYNC, OK, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 342 | }; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 343 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 344 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 345 | { |
| 346 | QuicStreamRequest request(&factory_); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 347 | EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, is_https_, |
[email protected] | ce542d5 | 2013-07-11 01:08:39 | [diff] [blame] | 348 | cert_verifier_.get(), net_log_, |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 349 | callback_.callback())); |
| 350 | } |
| 351 | |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 352 | socket_data.StopAfter(1); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 353 | base::RunLoop run_loop; |
| 354 | run_loop.RunUntilIdle(); |
| 355 | |
| 356 | scoped_ptr<QuicHttpStream> stream( |
| 357 | factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_)); |
| 358 | EXPECT_TRUE(stream.get()); |
| 359 | stream.reset(); |
| 360 | |
| 361 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 362 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 363 | } |
| 364 | |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 365 | TEST_F(QuicStreamFactoryTest, CloseAllSessions) { |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 366 | MockRead reads[] = { |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 367 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 368 | }; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 369 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 370 | socket_factory_.AddSocketDataProvider(&socket_data); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 371 | socket_data.StopAfter(1); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 372 | |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 373 | MockRead reads2[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 374 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 375 | }; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 376 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 377 | socket_factory_.AddSocketDataProvider(&socket_data2); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 378 | socket_data2.StopAfter(1); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 379 | |
| 380 | QuicStreamRequest request(&factory_); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 381 | EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, is_https_, |
[email protected] | ce542d5 | 2013-07-11 01:08:39 | [diff] [blame] | 382 | cert_verifier_.get(), net_log_, |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 383 | callback_.callback())); |
| 384 | |
| 385 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 386 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 387 | HttpRequestInfo request_info; |
| 388 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 389 | DEFAULT_PRIORITY, |
| 390 | net_log_, CompletionCallback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 391 | |
| 392 | // Close the session and verify that stream saw the error. |
| 393 | factory_.CloseAllSessions(ERR_INTERNET_DISCONNECTED); |
| 394 | EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
| 395 | stream->ReadResponseHeaders(callback_.callback())); |
| 396 | |
| 397 | // Now attempting to request a stream to the same origin should create |
| 398 | // a new session. |
| 399 | |
| 400 | QuicStreamRequest request2(&factory_); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 401 | EXPECT_EQ(ERR_IO_PENDING, request2.Request(host_port_proxy_pair_, is_https_, |
[email protected] | ce542d5 | 2013-07-11 01:08:39 | [diff] [blame] | 402 | cert_verifier_.get(), net_log_, |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 403 | callback_.callback())); |
| 404 | |
| 405 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 406 | stream = request2.ReleaseStream(); |
| 407 | stream.reset(); // Will reset stream 3. |
| 408 | |
| 409 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 410 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 411 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 412 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 413 | } |
| 414 | |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 415 | TEST_F(QuicStreamFactoryTest, OnIPAddressChanged) { |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 416 | MockRead reads[] = { |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 417 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 418 | }; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 419 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 420 | socket_factory_.AddSocketDataProvider(&socket_data); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 421 | socket_data.StopAfter(1); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 422 | |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 423 | MockRead reads2[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 424 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 425 | }; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 426 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 427 | socket_factory_.AddSocketDataProvider(&socket_data2); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 428 | socket_data2.StopAfter(1); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 429 | |
| 430 | QuicStreamRequest request(&factory_); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 431 | EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, is_https_, |
[email protected] | ce542d5 | 2013-07-11 01:08:39 | [diff] [blame] | 432 | cert_verifier_.get(), net_log_, |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 433 | callback_.callback())); |
| 434 | |
| 435 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 436 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 437 | HttpRequestInfo request_info; |
| 438 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 439 | DEFAULT_PRIORITY, |
| 440 | net_log_, CompletionCallback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 441 | |
| 442 | // Change the IP address and verify that stream saw the error. |
| 443 | factory_.OnIPAddressChanged(); |
| 444 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 445 | stream->ReadResponseHeaders(callback_.callback())); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 446 | EXPECT_TRUE(factory_.require_confirmation()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 447 | |
| 448 | // Now attempting to request a stream to the same origin should create |
| 449 | // a new session. |
| 450 | |
| 451 | QuicStreamRequest request2(&factory_); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 452 | EXPECT_EQ(ERR_IO_PENDING, request2.Request(host_port_proxy_pair_, is_https_, |
[email protected] | ce542d5 | 2013-07-11 01:08:39 | [diff] [blame] | 453 | cert_verifier_.get(), net_log_, |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 454 | callback_.callback())); |
| 455 | |
| 456 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 457 | stream = request2.ReleaseStream(); |
| 458 | stream.reset(); // Will reset stream 3. |
| 459 | |
| 460 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 461 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 462 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 463 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 464 | } |
| 465 | |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 466 | TEST_F(QuicStreamFactoryTest, OnCertAdded) { |
| 467 | MockRead reads[] = { |
| 468 | MockRead(ASYNC, 0, 0) // EOF |
| 469 | }; |
| 470 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 471 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 472 | socket_data.StopAfter(1); |
| 473 | |
| 474 | MockRead reads2[] = { |
| 475 | MockRead(ASYNC, 0, 0) // EOF |
| 476 | }; |
| 477 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
| 478 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 479 | socket_data2.StopAfter(1); |
| 480 | |
| 481 | QuicStreamRequest request(&factory_); |
| 482 | EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, is_https_, |
| 483 | cert_verifier_.get(), net_log_, |
| 484 | callback_.callback())); |
| 485 | |
| 486 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 487 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 488 | HttpRequestInfo request_info; |
| 489 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 490 | DEFAULT_PRIORITY, |
| 491 | net_log_, CompletionCallback())); |
| 492 | |
| 493 | // Add a cert and verify that stream saw the event. |
| 494 | factory_.OnCertAdded(NULL); |
| 495 | EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, |
| 496 | stream->ReadResponseHeaders(callback_.callback())); |
| 497 | EXPECT_FALSE(factory_.require_confirmation()); |
| 498 | |
| 499 | // Now attempting to request a stream to the same origin should create |
| 500 | // a new session. |
| 501 | |
| 502 | QuicStreamRequest request2(&factory_); |
| 503 | EXPECT_EQ(ERR_IO_PENDING, request2.Request(host_port_proxy_pair_, is_https_, |
| 504 | cert_verifier_.get(), net_log_, |
| 505 | callback_.callback())); |
| 506 | |
| 507 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 508 | stream = request2.ReleaseStream(); |
| 509 | stream.reset(); // Will reset stream 3. |
| 510 | |
| 511 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 512 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 513 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 514 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 515 | } |
| 516 | |
| 517 | TEST_F(QuicStreamFactoryTest, OnCACertChanged) { |
| 518 | MockRead reads[] = { |
| 519 | MockRead(ASYNC, 0, 0) // EOF |
| 520 | }; |
| 521 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 522 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 523 | socket_data.StopAfter(1); |
| 524 | |
| 525 | MockRead reads2[] = { |
| 526 | MockRead(ASYNC, 0, 0) // EOF |
| 527 | }; |
| 528 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
| 529 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 530 | socket_data2.StopAfter(1); |
| 531 | |
| 532 | QuicStreamRequest request(&factory_); |
| 533 | EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, is_https_, |
| 534 | cert_verifier_.get(), net_log_, |
| 535 | callback_.callback())); |
| 536 | |
| 537 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 538 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 539 | HttpRequestInfo request_info; |
| 540 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 541 | DEFAULT_PRIORITY, |
| 542 | net_log_, CompletionCallback())); |
| 543 | |
| 544 | // Change the CA cert and verify that stream saw the event. |
| 545 | factory_.OnCACertChanged(NULL); |
| 546 | EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, |
| 547 | stream->ReadResponseHeaders(callback_.callback())); |
| 548 | EXPECT_FALSE(factory_.require_confirmation()); |
| 549 | |
| 550 | // Now attempting to request a stream to the same origin should create |
| 551 | // a new session. |
| 552 | |
| 553 | QuicStreamRequest request2(&factory_); |
| 554 | EXPECT_EQ(ERR_IO_PENDING, request2.Request(host_port_proxy_pair_, is_https_, |
| 555 | cert_verifier_.get(), net_log_, |
| 556 | callback_.callback())); |
| 557 | |
| 558 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 559 | stream = request2.ReleaseStream(); |
| 560 | stream.reset(); // Will reset stream 3. |
| 561 | |
| 562 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 563 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 564 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 565 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 566 | } |
| 567 | |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 568 | TEST_F(QuicStreamFactoryTest, SharedCryptoConfig) { |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 569 | vector<string> cannoncial_suffixes; |
| 570 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 571 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 572 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 573 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 574 | string r1_host_name("r1"); |
| 575 | string r2_host_name("r2"); |
| 576 | r1_host_name.append(cannoncial_suffixes[i]); |
| 577 | r2_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 578 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 579 | HostPortProxyPair host_port_proxy_pair1(HostPortPair(r1_host_name, 80), |
| 580 | ProxyServer::Direct()); |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 581 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 582 | QuicCryptoClientConfig* crypto_config1 = |
| 583 | QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_, |
| 584 | host_port_proxy_pair1); |
| 585 | DCHECK(crypto_config1); |
| 586 | QuicCryptoClientConfig::CachedState* cached1 = |
| 587 | crypto_config1->LookupOrCreate(host_port_proxy_pair1.first.host()); |
| 588 | EXPECT_FALSE(cached1->proof_valid()); |
| 589 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 590 | |
| 591 | // Mutate the cached1 to have different data. |
| 592 | // TODO(rtenneti): mutate other members of CachedState. |
| 593 | cached1->set_source_address_token(r1_host_name); |
| 594 | cached1->SetProofValid(); |
| 595 | |
| 596 | HostPortProxyPair host_port_proxy_pair2(HostPortPair(r2_host_name, 80), |
| 597 | ProxyServer::Direct()); |
| 598 | QuicCryptoClientConfig* crypto_config2 = |
| 599 | QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_, |
| 600 | host_port_proxy_pair2); |
| 601 | DCHECK(crypto_config2); |
| 602 | QuicCryptoClientConfig::CachedState* cached2 = |
| 603 | crypto_config2->LookupOrCreate(host_port_proxy_pair2.first.host()); |
| 604 | EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); |
| 605 | EXPECT_TRUE(cached2->proof_valid()); |
| 606 | } |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | TEST_F(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 610 | vector<string> cannoncial_suffixes; |
| 611 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 612 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 613 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 614 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 615 | string r3_host_name("r3"); |
| 616 | string r4_host_name("r4"); |
| 617 | r3_host_name.append(cannoncial_suffixes[i]); |
| 618 | r4_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 619 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 620 | HostPortProxyPair host_port_proxy_pair1(HostPortPair(r3_host_name, 80), |
| 621 | ProxyServer::Direct()); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 622 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 623 | QuicCryptoClientConfig* crypto_config1 = |
| 624 | QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_, |
| 625 | host_port_proxy_pair1); |
| 626 | DCHECK(crypto_config1); |
| 627 | QuicCryptoClientConfig::CachedState* cached1 = |
| 628 | crypto_config1->LookupOrCreate(host_port_proxy_pair1.first.host()); |
| 629 | EXPECT_FALSE(cached1->proof_valid()); |
| 630 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 631 | |
| 632 | // Mutate the cached1 to have different data. |
| 633 | // TODO(rtenneti): mutate other members of CachedState. |
| 634 | cached1->set_source_address_token(r3_host_name); |
| 635 | cached1->SetProofInvalid(); |
| 636 | |
| 637 | HostPortProxyPair host_port_proxy_pair2(HostPortPair(r4_host_name, 80), |
| 638 | ProxyServer::Direct()); |
| 639 | QuicCryptoClientConfig* crypto_config2 = |
| 640 | QuicStreamFactoryPeer::GetOrCreateCryptoConfig(&factory_, |
| 641 | host_port_proxy_pair2); |
| 642 | DCHECK(crypto_config2); |
| 643 | QuicCryptoClientConfig::CachedState* cached2 = |
| 644 | crypto_config2->LookupOrCreate(host_port_proxy_pair2.first.host()); |
| 645 | EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
| 646 | EXPECT_TRUE(cached2->source_address_token().empty()); |
| 647 | EXPECT_FALSE(cached2->proof_valid()); |
| 648 | } |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 649 | } |
| 650 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 651 | } // namespace test |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 652 | } // namespace net |