OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "net/base/test_data_directory.h" | 9 #include "net/base/test_data_directory.h" |
10 #include "net/cert/cert_verifier.h" | 10 #include "net/cert/cert_verifier.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 class QuicStreamFactoryPeer { | 42 class QuicStreamFactoryPeer { |
43 public: | 43 public: |
44 static QuicCryptoClientConfig* GetCryptoConfig(QuicStreamFactory* factory) { | 44 static QuicCryptoClientConfig* GetCryptoConfig(QuicStreamFactory* factory) { |
45 return &factory->crypto_config_; | 45 return &factory->crypto_config_; |
46 } | 46 } |
47 | 47 |
48 static bool HasActiveSession(QuicStreamFactory* factory, | 48 static bool HasActiveSession(QuicStreamFactory* factory, |
49 const HostPortPair& host_port_pair, | 49 const HostPortPair& host_port_pair, |
50 bool is_https) { | 50 bool is_https) { |
51 QuicSessionKey server_key(host_port_pair, is_https); | 51 QuicSessionKey server_key(host_port_pair, is_https, kPrivacyModeDisabled); |
52 return factory->HasActiveSession(server_key); | 52 return factory->HasActiveSession(server_key); |
53 } | 53 } |
54 | 54 |
55 static QuicClientSession* GetActiveSession( | 55 static QuicClientSession* GetActiveSession( |
56 QuicStreamFactory* factory, | 56 QuicStreamFactory* factory, |
57 const HostPortPair& host_port_pair, | 57 const HostPortPair& host_port_pair, |
58 bool is_https) { | 58 bool is_https) { |
59 QuicSessionKey server_key(host_port_pair, is_https); | 59 QuicSessionKey server_key(host_port_pair, is_https, kPrivacyModeDisabled); |
60 DCHECK(factory->HasActiveSession(server_key)); | 60 DCHECK(factory->HasActiveSession(server_key)); |
61 return factory->active_sessions_[server_key]; | 61 return factory->active_sessions_[server_key]; |
62 } | 62 } |
63 | 63 |
64 static scoped_ptr<QuicHttpStream> CreateIfSessionExists( | 64 static scoped_ptr<QuicHttpStream> CreateIfSessionExists( |
65 QuicStreamFactory* factory, | 65 QuicStreamFactory* factory, |
66 const HostPortPair& host_port_pair, | 66 const HostPortPair& host_port_pair, |
67 bool is_https, | 67 bool is_https, |
68 const BoundNetLog& net_log) { | 68 const BoundNetLog& net_log) { |
69 QuicSessionKey server_key(host_port_pair, is_https); | 69 QuicSessionKey server_key(host_port_pair, is_https, kPrivacyModeDisabled); |
70 return factory->CreateIfSessionExists(server_key, net_log); | 70 return factory->CreateIfSessionExists(server_key, net_log); |
71 } | 71 } |
72 | 72 |
73 static bool IsLiveSession(QuicStreamFactory* factory, | 73 static bool IsLiveSession(QuicStreamFactory* factory, |
74 QuicClientSession* session) { | 74 QuicClientSession* session) { |
75 for (QuicStreamFactory::SessionSet::iterator it = | 75 for (QuicStreamFactory::SessionSet::iterator it = |
76 factory->all_sessions_.begin(); | 76 factory->all_sessions_.begin(); |
77 it != factory->all_sessions_.end(); ++it) { | 77 it != factory->all_sessions_.end(); ++it) { |
78 if (*it == session) | 78 if (*it == session) |
79 return true; | 79 return true; |
80 } | 80 } |
81 return false; | 81 return false; |
82 } | 82 } |
83 }; | 83 }; |
84 | 84 |
85 class QuicStreamFactoryTest : public ::testing::TestWithParam<QuicVersion> { | 85 class QuicStreamFactoryTest : public ::testing::TestWithParam<QuicVersion> { |
86 protected: | 86 protected: |
87 QuicStreamFactoryTest() | 87 QuicStreamFactoryTest() |
88 : random_generator_(0), | 88 : random_generator_(0), |
89 maker_(GetParam(), 0), | 89 maker_(GetParam(), 0), |
90 clock_(new MockClock()), | 90 clock_(new MockClock()), |
91 cert_verifier_(CertVerifier::CreateDefault()), | 91 cert_verifier_(CertVerifier::CreateDefault()), |
92 factory_(&host_resolver_, &socket_factory_, | 92 factory_(&host_resolver_, &socket_factory_, |
93 base::WeakPtr<HttpServerProperties>(), | 93 base::WeakPtr<HttpServerProperties>(), |
94 cert_verifier_.get(), | 94 cert_verifier_.get(), |
95 &crypto_client_stream_factory_, | 95 &crypto_client_stream_factory_, |
96 &random_generator_, clock_, kDefaultMaxPacketSize, | 96 &random_generator_, clock_, kDefaultMaxPacketSize, |
97 SupportedVersions(GetParam()), true, true), | 97 SupportedVersions(GetParam()), true, true), |
98 host_port_pair_(kDefaultServerHostName, kDefaultServerPort), | 98 host_port_pair_(kDefaultServerHostName, kDefaultServerPort), |
99 is_https_(false) { | 99 is_https_(false), |
| 100 privacy_mode_(kPrivacyModeDisabled) { |
100 factory_.set_require_confirmation(false); | 101 factory_.set_require_confirmation(false); |
101 } | 102 } |
102 | 103 |
103 scoped_ptr<QuicHttpStream> CreateIfSessionExists( | 104 scoped_ptr<QuicHttpStream> CreateIfSessionExists( |
104 const HostPortPair& host_port_pair, | 105 const HostPortPair& host_port_pair, |
105 const BoundNetLog& net_log) { | 106 const BoundNetLog& net_log) { |
106 return QuicStreamFactoryPeer::CreateIfSessionExists( | 107 return QuicStreamFactoryPeer::CreateIfSessionExists( |
107 &factory_, host_port_pair, false, net_log_); | 108 &factory_, host_port_pair, false, net_log_); |
108 } | 109 } |
109 | 110 |
(...skipping 16 matching lines...) Expand all Loading... |
126 MockRead(ASYNC, OK, 0) // EOF | 127 MockRead(ASYNC, OK, 0) // EOF |
127 }; | 128 }; |
128 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); | 129 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
129 socket_data.StopAfter(1); | 130 socket_data.StopAfter(1); |
130 socket_factory_.AddSocketDataProvider(&socket_data); | 131 socket_factory_.AddSocketDataProvider(&socket_data); |
131 | 132 |
132 QuicStreamRequest request(&factory_); | 133 QuicStreamRequest request(&factory_); |
133 EXPECT_EQ(ERR_IO_PENDING, | 134 EXPECT_EQ(ERR_IO_PENDING, |
134 request.Request(destination, | 135 request.Request(destination, |
135 is_https_, | 136 is_https_, |
| 137 privacy_mode_, |
136 "GET", | 138 "GET", |
137 net_log_, | 139 net_log_, |
138 callback_.callback())); | 140 callback_.callback())); |
139 | 141 |
140 EXPECT_EQ(OK, callback_.WaitForResult()); | 142 EXPECT_EQ(OK, callback_.WaitForResult()); |
141 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 143 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
142 EXPECT_TRUE(stream.get()); | 144 EXPECT_TRUE(stream.get()); |
143 stream.reset(); | 145 stream.reset(); |
144 | 146 |
145 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( | 147 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( |
(...skipping 28 matching lines...) Expand all Loading... |
174 MockHostResolver host_resolver_; | 176 MockHostResolver host_resolver_; |
175 DeterministicMockClientSocketFactory socket_factory_; | 177 DeterministicMockClientSocketFactory socket_factory_; |
176 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 178 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
177 MockRandom random_generator_; | 179 MockRandom random_generator_; |
178 QuicTestPacketMaker maker_; | 180 QuicTestPacketMaker maker_; |
179 MockClock* clock_; // Owned by factory_. | 181 MockClock* clock_; // Owned by factory_. |
180 scoped_ptr<CertVerifier> cert_verifier_; | 182 scoped_ptr<CertVerifier> cert_verifier_; |
181 QuicStreamFactory factory_; | 183 QuicStreamFactory factory_; |
182 HostPortPair host_port_pair_; | 184 HostPortPair host_port_pair_; |
183 bool is_https_; | 185 bool is_https_; |
| 186 PrivacyMode privacy_mode_; |
184 BoundNetLog net_log_; | 187 BoundNetLog net_log_; |
185 TestCompletionCallback callback_; | 188 TestCompletionCallback callback_; |
186 }; | 189 }; |
187 | 190 |
188 INSTANTIATE_TEST_CASE_P(Version, QuicStreamFactoryTest, | 191 INSTANTIATE_TEST_CASE_P(Version, QuicStreamFactoryTest, |
189 ::testing::ValuesIn(QuicSupportedVersions())); | 192 ::testing::ValuesIn(QuicSupportedVersions())); |
190 | 193 |
191 TEST_P(QuicStreamFactoryTest, CreateIfSessionExists) { | 194 TEST_P(QuicStreamFactoryTest, CreateIfSessionExists) { |
192 EXPECT_EQ(NULL, CreateIfSessionExists(host_port_pair_, net_log_).get()); | 195 EXPECT_EQ(NULL, CreateIfSessionExists(host_port_pair_, net_log_).get()); |
193 } | 196 } |
194 | 197 |
195 TEST_P(QuicStreamFactoryTest, Create) { | 198 TEST_P(QuicStreamFactoryTest, Create) { |
196 MockRead reads[] = { | 199 MockRead reads[] = { |
197 MockRead(ASYNC, OK, 0) // EOF | 200 MockRead(ASYNC, OK, 0) // EOF |
198 }; | 201 }; |
199 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); | 202 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
200 socket_factory_.AddSocketDataProvider(&socket_data); | 203 socket_factory_.AddSocketDataProvider(&socket_data); |
201 socket_data.StopAfter(1); | 204 socket_data.StopAfter(1); |
202 | 205 |
203 QuicStreamRequest request(&factory_); | 206 QuicStreamRequest request(&factory_); |
204 EXPECT_EQ(ERR_IO_PENDING, | 207 EXPECT_EQ(ERR_IO_PENDING, |
205 request.Request(host_port_pair_, | 208 request.Request(host_port_pair_, |
206 is_https_, | 209 is_https_, |
| 210 privacy_mode_, |
207 "GET", | 211 "GET", |
208 net_log_, | 212 net_log_, |
209 callback_.callback())); | 213 callback_.callback())); |
210 | 214 |
211 EXPECT_EQ(OK, callback_.WaitForResult()); | 215 EXPECT_EQ(OK, callback_.WaitForResult()); |
212 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 216 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
213 EXPECT_TRUE(stream.get()); | 217 EXPECT_TRUE(stream.get()); |
214 | 218 |
215 // Will reset stream 3. | 219 // Will reset stream 3. |
216 stream = CreateIfSessionExists(host_port_pair_, net_log_); | 220 stream = CreateIfSessionExists(host_port_pair_, net_log_); |
217 EXPECT_TRUE(stream.get()); | 221 EXPECT_TRUE(stream.get()); |
218 | 222 |
219 // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result | 223 // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result |
220 // in streams on different sessions. | 224 // in streams on different sessions. |
221 QuicStreamRequest request2(&factory_); | 225 QuicStreamRequest request2(&factory_); |
222 EXPECT_EQ(OK, | 226 EXPECT_EQ(OK, |
223 request2.Request(host_port_pair_, | 227 request2.Request(host_port_pair_, |
224 is_https_, | 228 is_https_, |
| 229 privacy_mode_, |
225 "GET", | 230 "GET", |
226 net_log_, | 231 net_log_, |
227 callback_.callback())); | 232 callback_.callback())); |
228 stream = request2.ReleaseStream(); // Will reset stream 5. | 233 stream = request2.ReleaseStream(); // Will reset stream 5. |
229 stream.reset(); // Will reset stream 7. | 234 stream.reset(); // Will reset stream 7. |
230 | 235 |
231 EXPECT_TRUE(socket_data.at_read_eof()); | 236 EXPECT_TRUE(socket_data.at_read_eof()); |
232 EXPECT_TRUE(socket_data.at_write_eof()); | 237 EXPECT_TRUE(socket_data.at_write_eof()); |
233 } | 238 } |
234 | 239 |
235 TEST_P(QuicStreamFactoryTest, CreateZeroRtt) { | 240 TEST_P(QuicStreamFactoryTest, CreateZeroRtt) { |
236 MockRead reads[] = { | 241 MockRead reads[] = { |
237 MockRead(ASYNC, OK, 0) // EOF | 242 MockRead(ASYNC, OK, 0) // EOF |
238 }; | 243 }; |
239 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); | 244 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
240 socket_factory_.AddSocketDataProvider(&socket_data); | 245 socket_factory_.AddSocketDataProvider(&socket_data); |
241 socket_data.StopAfter(1); | 246 socket_data.StopAfter(1); |
242 | 247 |
243 crypto_client_stream_factory_.set_handshake_mode( | 248 crypto_client_stream_factory_.set_handshake_mode( |
244 MockCryptoClientStream::ZERO_RTT); | 249 MockCryptoClientStream::ZERO_RTT); |
245 host_resolver_.set_synchronous_mode(true); | 250 host_resolver_.set_synchronous_mode(true); |
246 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), | 251 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), |
247 "192.168.0.1", ""); | 252 "192.168.0.1", ""); |
248 | 253 |
249 QuicStreamRequest request(&factory_); | 254 QuicStreamRequest request(&factory_); |
250 EXPECT_EQ(OK, | 255 EXPECT_EQ(OK, |
251 request.Request(host_port_pair_, | 256 request.Request(host_port_pair_, |
252 is_https_, | 257 is_https_, |
| 258 privacy_mode_, |
253 "GET", | 259 "GET", |
254 net_log_, | 260 net_log_, |
255 callback_.callback())); | 261 callback_.callback())); |
256 | 262 |
257 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 263 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
258 EXPECT_TRUE(stream.get()); | 264 EXPECT_TRUE(stream.get()); |
259 EXPECT_TRUE(socket_data.at_read_eof()); | 265 EXPECT_TRUE(socket_data.at_read_eof()); |
260 EXPECT_TRUE(socket_data.at_write_eof()); | 266 EXPECT_TRUE(socket_data.at_write_eof()); |
261 } | 267 } |
262 | 268 |
263 TEST_P(QuicStreamFactoryTest, CreateZeroRttPost) { | 269 TEST_P(QuicStreamFactoryTest, CreateZeroRttPost) { |
264 MockRead reads[] = { | 270 MockRead reads[] = { |
265 MockRead(ASYNC, OK, 0) // EOF | 271 MockRead(ASYNC, OK, 0) // EOF |
266 }; | 272 }; |
267 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); | 273 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
268 socket_factory_.AddSocketDataProvider(&socket_data); | 274 socket_factory_.AddSocketDataProvider(&socket_data); |
269 socket_data.StopAfter(1); | 275 socket_data.StopAfter(1); |
270 | 276 |
271 crypto_client_stream_factory_.set_handshake_mode( | 277 crypto_client_stream_factory_.set_handshake_mode( |
272 MockCryptoClientStream::ZERO_RTT); | 278 MockCryptoClientStream::ZERO_RTT); |
273 host_resolver_.set_synchronous_mode(true); | 279 host_resolver_.set_synchronous_mode(true); |
274 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), | 280 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), |
275 "192.168.0.1", ""); | 281 "192.168.0.1", ""); |
276 | 282 |
277 QuicStreamRequest request(&factory_); | 283 QuicStreamRequest request(&factory_); |
278 // Posts require handshake confirmation, so this will return asynchronously. | 284 // Posts require handshake confirmation, so this will return asynchronously. |
279 EXPECT_EQ(ERR_IO_PENDING, | 285 EXPECT_EQ(ERR_IO_PENDING, |
280 request.Request(host_port_pair_, | 286 request.Request(host_port_pair_, |
281 is_https_, | 287 is_https_, |
| 288 privacy_mode_, |
282 "POST", | 289 "POST", |
283 net_log_, | 290 net_log_, |
284 callback_.callback())); | 291 callback_.callback())); |
285 | 292 |
286 // Confirm the handshake and verify that the stream is created. | 293 // Confirm the handshake and verify that the stream is created. |
287 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( | 294 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
288 QuicSession::HANDSHAKE_CONFIRMED); | 295 QuicSession::HANDSHAKE_CONFIRMED); |
289 | 296 |
290 EXPECT_EQ(OK, callback_.WaitForResult()); | 297 EXPECT_EQ(OK, callback_.WaitForResult()); |
291 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 298 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
(...skipping 10 matching lines...) Expand all Loading... |
302 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); | 309 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); |
303 socket_factory_.AddSocketDataProvider(&socket_data1); | 310 socket_factory_.AddSocketDataProvider(&socket_data1); |
304 socket_factory_.AddSocketDataProvider(&socket_data2); | 311 socket_factory_.AddSocketDataProvider(&socket_data2); |
305 socket_data1.StopAfter(1); | 312 socket_data1.StopAfter(1); |
306 socket_data2.StopAfter(1); | 313 socket_data2.StopAfter(1); |
307 | 314 |
308 QuicStreamRequest request(&factory_); | 315 QuicStreamRequest request(&factory_); |
309 EXPECT_EQ(ERR_IO_PENDING, | 316 EXPECT_EQ(ERR_IO_PENDING, |
310 request.Request(host_port_pair_, | 317 request.Request(host_port_pair_, |
311 is_https_, | 318 is_https_, |
| 319 privacy_mode_, |
312 "GET", | 320 "GET", |
313 net_log_, | 321 net_log_, |
314 callback_.callback())); | 322 callback_.callback())); |
315 | 323 |
316 EXPECT_EQ(OK, callback_.WaitForResult()); | 324 EXPECT_EQ(OK, callback_.WaitForResult()); |
317 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 325 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
318 EXPECT_TRUE(stream.get()); | 326 EXPECT_TRUE(stream.get()); |
319 | 327 |
320 QuicStreamRequest request2(&factory_); | 328 QuicStreamRequest request2(&factory_); |
321 EXPECT_EQ(ERR_IO_PENDING, | 329 EXPECT_EQ(ERR_IO_PENDING, |
322 request2.Request(host_port_pair_, | 330 request2.Request(host_port_pair_, |
323 !is_https_, | 331 !is_https_, |
| 332 privacy_mode_, |
324 "GET", | 333 "GET", |
325 net_log_, | 334 net_log_, |
326 callback_.callback())); | 335 callback_.callback())); |
327 EXPECT_EQ(OK, callback_.WaitForResult()); | 336 EXPECT_EQ(OK, callback_.WaitForResult()); |
328 stream = request2.ReleaseStream(); | 337 stream = request2.ReleaseStream(); |
329 EXPECT_TRUE(stream.get()); | 338 EXPECT_TRUE(stream.get()); |
330 stream.reset(); | 339 stream.reset(); |
331 | 340 |
332 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( | 341 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( |
333 &factory_, host_port_pair_, is_https_), | 342 &factory_, host_port_pair_, is_https_), |
(...skipping 18 matching lines...) Expand all Loading... |
352 host_resolver_.set_synchronous_mode(true); | 361 host_resolver_.set_synchronous_mode(true); |
353 host_resolver_.rules()->AddIPLiteralRule( | 362 host_resolver_.rules()->AddIPLiteralRule( |
354 kDefaultServerHostName, "192.168.0.1", ""); | 363 kDefaultServerHostName, "192.168.0.1", ""); |
355 host_resolver_.rules()->AddIPLiteralRule( | 364 host_resolver_.rules()->AddIPLiteralRule( |
356 "mail.google.com", "192.168.0.1", ""); | 365 "mail.google.com", "192.168.0.1", ""); |
357 | 366 |
358 QuicStreamRequest request(&factory_); | 367 QuicStreamRequest request(&factory_); |
359 EXPECT_EQ(OK, | 368 EXPECT_EQ(OK, |
360 request.Request(host_port_pair_, | 369 request.Request(host_port_pair_, |
361 is_https_, | 370 is_https_, |
| 371 privacy_mode_, |
362 "GET", | 372 "GET", |
363 net_log_, | 373 net_log_, |
364 callback_.callback())); | 374 callback_.callback())); |
365 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 375 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
366 EXPECT_TRUE(stream.get()); | 376 EXPECT_TRUE(stream.get()); |
367 | 377 |
368 TestCompletionCallback callback; | 378 TestCompletionCallback callback; |
369 QuicStreamRequest request2(&factory_); | 379 QuicStreamRequest request2(&factory_); |
370 EXPECT_EQ(OK, | 380 EXPECT_EQ(OK, |
371 request2.Request(server2, | 381 request2.Request(server2, |
372 is_https_, | 382 is_https_, |
| 383 privacy_mode_, |
373 "GET", | 384 "GET", |
374 net_log_, | 385 net_log_, |
375 callback.callback())); | 386 callback.callback())); |
376 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 387 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
377 EXPECT_TRUE(stream2.get()); | 388 EXPECT_TRUE(stream2.get()); |
378 | 389 |
379 EXPECT_EQ( | 390 EXPECT_EQ( |
380 QuicStreamFactoryPeer::GetActiveSession( | 391 QuicStreamFactoryPeer::GetActiveSession( |
381 &factory_, host_port_pair_, is_https_), | 392 &factory_, host_port_pair_, is_https_), |
382 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_)); | 393 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_)); |
(...skipping 17 matching lines...) Expand all Loading... |
400 host_resolver_.set_synchronous_mode(true); | 411 host_resolver_.set_synchronous_mode(true); |
401 host_resolver_.rules()->AddIPLiteralRule( | 412 host_resolver_.rules()->AddIPLiteralRule( |
402 kDefaultServerHostName, "192.168.0.1", ""); | 413 kDefaultServerHostName, "192.168.0.1", ""); |
403 host_resolver_.rules()->AddIPLiteralRule( | 414 host_resolver_.rules()->AddIPLiteralRule( |
404 "mail.google.com", "192.168.0.1", ""); | 415 "mail.google.com", "192.168.0.1", ""); |
405 | 416 |
406 QuicStreamRequest request(&factory_); | 417 QuicStreamRequest request(&factory_); |
407 EXPECT_EQ(OK, | 418 EXPECT_EQ(OK, |
408 request.Request(host_port_pair_, | 419 request.Request(host_port_pair_, |
409 is_https_, | 420 is_https_, |
| 421 privacy_mode_, |
410 "GET", | 422 "GET", |
411 net_log_, | 423 net_log_, |
412 callback_.callback())); | 424 callback_.callback())); |
413 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 425 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
414 EXPECT_TRUE(stream.get()); | 426 EXPECT_TRUE(stream.get()); |
415 | 427 |
416 TestCompletionCallback callback; | 428 TestCompletionCallback callback; |
417 QuicStreamRequest request2(&factory_); | 429 QuicStreamRequest request2(&factory_); |
418 EXPECT_EQ(OK, | 430 EXPECT_EQ(OK, |
419 request2.Request(server2, | 431 request2.Request(server2, |
420 is_https_, | 432 is_https_, |
| 433 privacy_mode_, |
421 "GET", | 434 "GET", |
422 net_log_, | 435 net_log_, |
423 callback.callback())); | 436 callback.callback())); |
424 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 437 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
425 EXPECT_TRUE(stream2.get()); | 438 EXPECT_TRUE(stream2.get()); |
426 | 439 |
427 factory_.OnSessionGoingAway(QuicStreamFactoryPeer::GetActiveSession( | 440 factory_.OnSessionGoingAway(QuicStreamFactoryPeer::GetActiveSession( |
428 &factory_, host_port_pair_, is_https_)); | 441 &factory_, host_port_pair_, is_https_)); |
429 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( | 442 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
430 &factory_, host_port_pair_, is_https_)); | 443 &factory_, host_port_pair_, is_https_)); |
431 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( | 444 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
432 &factory_, server2, is_https_)); | 445 &factory_, server2, is_https_)); |
433 | 446 |
434 TestCompletionCallback callback3; | 447 TestCompletionCallback callback3; |
435 QuicStreamRequest request3(&factory_); | 448 QuicStreamRequest request3(&factory_); |
436 EXPECT_EQ(OK, | 449 EXPECT_EQ(OK, |
437 request3.Request(server2, | 450 request3.Request(server2, |
438 is_https_, | 451 is_https_, |
| 452 privacy_mode_, |
439 "GET", | 453 "GET", |
440 net_log_, | 454 net_log_, |
441 callback3.callback())); | 455 callback3.callback())); |
442 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream(); | 456 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream(); |
443 EXPECT_TRUE(stream3.get()); | 457 EXPECT_TRUE(stream3.get()); |
444 | 458 |
445 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession( | 459 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession( |
446 &factory_, server2, is_https_)); | 460 &factory_, server2, is_https_)); |
447 | 461 |
448 EXPECT_TRUE(socket_data1.at_read_eof()); | 462 EXPECT_TRUE(socket_data1.at_read_eof()); |
(...skipping 27 matching lines...) Expand all Loading... |
476 | 490 |
477 host_resolver_.set_synchronous_mode(true); | 491 host_resolver_.set_synchronous_mode(true); |
478 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); | 492 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
479 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); | 493 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
480 | 494 |
481 QuicStreamRequest request(&factory_); | 495 QuicStreamRequest request(&factory_); |
482 is_https_ = true; | 496 is_https_ = true; |
483 EXPECT_EQ(OK, | 497 EXPECT_EQ(OK, |
484 request.Request(server1, | 498 request.Request(server1, |
485 is_https_, | 499 is_https_, |
| 500 privacy_mode_, |
486 "GET", | 501 "GET", |
487 net_log_, | 502 net_log_, |
488 callback_.callback())); | 503 callback_.callback())); |
489 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 504 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
490 EXPECT_TRUE(stream.get()); | 505 EXPECT_TRUE(stream.get()); |
491 | 506 |
492 TestCompletionCallback callback; | 507 TestCompletionCallback callback; |
493 QuicStreamRequest request2(&factory_); | 508 QuicStreamRequest request2(&factory_); |
494 EXPECT_EQ(OK, | 509 EXPECT_EQ(OK, |
495 request2.Request(server2, | 510 request2.Request(server2, |
496 is_https_, | 511 is_https_, |
| 512 privacy_mode_, |
497 "GET", | 513 "GET", |
498 net_log_, | 514 net_log_, |
499 callback_.callback())); | 515 callback_.callback())); |
500 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 516 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
501 EXPECT_TRUE(stream2.get()); | 517 EXPECT_TRUE(stream2.get()); |
502 | 518 |
503 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession( | 519 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession( |
504 &factory_, server1, is_https_), | 520 &factory_, server1, is_https_), |
505 QuicStreamFactoryPeer::GetActiveSession( | 521 QuicStreamFactoryPeer::GetActiveSession( |
506 &factory_, server2, is_https_)); | 522 &factory_, server2, is_https_)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 | 555 |
540 host_resolver_.set_synchronous_mode(true); | 556 host_resolver_.set_synchronous_mode(true); |
541 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); | 557 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
542 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); | 558 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
543 | 559 |
544 QuicStreamRequest request(&factory_); | 560 QuicStreamRequest request(&factory_); |
545 is_https_ = true; | 561 is_https_ = true; |
546 EXPECT_EQ(OK, | 562 EXPECT_EQ(OK, |
547 request.Request(server1, | 563 request.Request(server1, |
548 is_https_, | 564 is_https_, |
| 565 privacy_mode_, |
549 "GET", | 566 "GET", |
550 net_log_, | 567 net_log_, |
551 callback_.callback())); | 568 callback_.callback())); |
552 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 569 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
553 EXPECT_TRUE(stream.get()); | 570 EXPECT_TRUE(stream.get()); |
554 | 571 |
555 TestCompletionCallback callback; | 572 TestCompletionCallback callback; |
556 QuicStreamRequest request2(&factory_); | 573 QuicStreamRequest request2(&factory_); |
557 EXPECT_EQ(OK, | 574 EXPECT_EQ(OK, |
558 request2.Request(server2, | 575 request2.Request(server2, |
559 is_https_, | 576 is_https_, |
| 577 privacy_mode_, |
560 "GET", | 578 "GET", |
561 net_log_, | 579 net_log_, |
562 callback_.callback())); | 580 callback_.callback())); |
563 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 581 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
564 EXPECT_TRUE(stream2.get()); | 582 EXPECT_TRUE(stream2.get()); |
565 | 583 |
566 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( | 584 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( |
567 &factory_, server1, is_https_), | 585 &factory_, server1, is_https_), |
568 QuicStreamFactoryPeer::GetActiveSession( | 586 QuicStreamFactoryPeer::GetActiveSession( |
569 &factory_, server2, is_https_)); | 587 &factory_, server2, is_https_)); |
(...skipping 12 matching lines...) Expand all Loading... |
582 socket_data.StopAfter(1); | 600 socket_data.StopAfter(1); |
583 socket_factory_.AddSocketDataProvider(&socket_data); | 601 socket_factory_.AddSocketDataProvider(&socket_data); |
584 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); | 602 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); |
585 socket_data2.StopAfter(1); | 603 socket_data2.StopAfter(1); |
586 socket_factory_.AddSocketDataProvider(&socket_data2); | 604 socket_factory_.AddSocketDataProvider(&socket_data2); |
587 | 605 |
588 QuicStreamRequest request(&factory_); | 606 QuicStreamRequest request(&factory_); |
589 EXPECT_EQ(ERR_IO_PENDING, | 607 EXPECT_EQ(ERR_IO_PENDING, |
590 request.Request(host_port_pair_, | 608 request.Request(host_port_pair_, |
591 is_https_, | 609 is_https_, |
| 610 privacy_mode_, |
592 "GET", | 611 "GET", |
593 net_log_, | 612 net_log_, |
594 callback_.callback())); | 613 callback_.callback())); |
595 | 614 |
596 EXPECT_EQ(OK, callback_.WaitForResult()); | 615 EXPECT_EQ(OK, callback_.WaitForResult()); |
597 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 616 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
598 EXPECT_TRUE(stream.get()); | 617 EXPECT_TRUE(stream.get()); |
599 | 618 |
600 // Mark the session as going away. Ensure that while it is still alive | 619 // Mark the session as going away. Ensure that while it is still alive |
601 // that it is no longer active. | 620 // that it is no longer active. |
602 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( | 621 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( |
603 &factory_, host_port_pair_, is_https_); | 622 &factory_, host_port_pair_, is_https_); |
604 factory_.OnSessionGoingAway(session); | 623 factory_.OnSessionGoingAway(session); |
605 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); | 624 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); |
606 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( | 625 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
607 &factory_, host_port_pair_, is_https_)); | 626 &factory_, host_port_pair_, is_https_)); |
608 EXPECT_EQ(NULL, CreateIfSessionExists(host_port_pair_, net_log_).get()); | 627 EXPECT_EQ(NULL, CreateIfSessionExists(host_port_pair_, net_log_).get()); |
609 | 628 |
610 // Create a new request for the same destination and verify that a | 629 // Create a new request for the same destination and verify that a |
611 // new session is created. | 630 // new session is created. |
612 QuicStreamRequest request2(&factory_); | 631 QuicStreamRequest request2(&factory_); |
613 EXPECT_EQ(ERR_IO_PENDING, | 632 EXPECT_EQ(ERR_IO_PENDING, |
614 request2.Request(host_port_pair_, | 633 request2.Request(host_port_pair_, |
615 is_https_, | 634 is_https_, |
| 635 privacy_mode_, |
616 "GET", | 636 "GET", |
617 net_log_, | 637 net_log_, |
618 callback_.callback())); | 638 callback_.callback())); |
619 EXPECT_EQ(OK, callback_.WaitForResult()); | 639 EXPECT_EQ(OK, callback_.WaitForResult()); |
620 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 640 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
621 EXPECT_TRUE(stream2.get()); | 641 EXPECT_TRUE(stream2.get()); |
622 | 642 |
623 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_, | 643 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_, |
624 host_port_pair_, | 644 host_port_pair_, |
625 is_https_)); | 645 is_https_)); |
(...skipping 27 matching lines...) Expand all Loading... |
653 socket_data.StopAfter(1); | 673 socket_data.StopAfter(1); |
654 | 674 |
655 HttpRequestInfo request_info; | 675 HttpRequestInfo request_info; |
656 std::vector<QuicHttpStream*> streams; | 676 std::vector<QuicHttpStream*> streams; |
657 // The MockCryptoClientStream sets max_open_streams to be | 677 // The MockCryptoClientStream sets max_open_streams to be |
658 // 2 * kDefaultMaxStreamsPerConnection. | 678 // 2 * kDefaultMaxStreamsPerConnection. |
659 for (size_t i = 0; i < 2 * kDefaultMaxStreamsPerConnection; i++) { | 679 for (size_t i = 0; i < 2 * kDefaultMaxStreamsPerConnection; i++) { |
660 QuicStreamRequest request(&factory_); | 680 QuicStreamRequest request(&factory_); |
661 int rv = request.Request(host_port_pair_, | 681 int rv = request.Request(host_port_pair_, |
662 is_https_, | 682 is_https_, |
| 683 privacy_mode_, |
663 "GET", | 684 "GET", |
664 net_log_, | 685 net_log_, |
665 callback_.callback()); | 686 callback_.callback()); |
666 if (i == 0) { | 687 if (i == 0) { |
667 EXPECT_EQ(ERR_IO_PENDING, rv); | 688 EXPECT_EQ(ERR_IO_PENDING, rv); |
668 EXPECT_EQ(OK, callback_.WaitForResult()); | 689 EXPECT_EQ(OK, callback_.WaitForResult()); |
669 } else { | 690 } else { |
670 EXPECT_EQ(OK, rv); | 691 EXPECT_EQ(OK, rv); |
671 } | 692 } |
672 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 693 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
673 EXPECT_TRUE(stream); | 694 EXPECT_TRUE(stream); |
674 EXPECT_EQ(OK, stream->InitializeStream( | 695 EXPECT_EQ(OK, stream->InitializeStream( |
675 &request_info, DEFAULT_PRIORITY, net_log_, CompletionCallback())); | 696 &request_info, DEFAULT_PRIORITY, net_log_, CompletionCallback())); |
676 streams.push_back(stream.release()); | 697 streams.push_back(stream.release()); |
677 } | 698 } |
678 | 699 |
679 QuicStreamRequest request(&factory_); | 700 QuicStreamRequest request(&factory_); |
680 EXPECT_EQ(OK, | 701 EXPECT_EQ(OK, |
681 request.Request(host_port_pair_, | 702 request.Request(host_port_pair_, |
682 is_https_, | 703 is_https_, |
| 704 privacy_mode_, |
683 "GET", | 705 "GET", |
684 net_log_, | 706 net_log_, |
685 CompletionCallback())); | 707 CompletionCallback())); |
686 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 708 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
687 EXPECT_TRUE(stream); | 709 EXPECT_TRUE(stream); |
688 EXPECT_EQ(ERR_IO_PENDING, stream->InitializeStream( | 710 EXPECT_EQ(ERR_IO_PENDING, stream->InitializeStream( |
689 &request_info, DEFAULT_PRIORITY, net_log_, callback_.callback())); | 711 &request_info, DEFAULT_PRIORITY, net_log_, callback_.callback())); |
690 | 712 |
691 // Close the first stream. | 713 // Close the first stream. |
692 streams.front()->Close(false); | 714 streams.front()->Close(false); |
(...skipping 10 matching lines...) Expand all Loading... |
703 TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) { | 725 TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) { |
704 DeterministicSocketData socket_data(NULL, 0, NULL, 0); | 726 DeterministicSocketData socket_data(NULL, 0, NULL, 0); |
705 socket_factory_.AddSocketDataProvider(&socket_data); | 727 socket_factory_.AddSocketDataProvider(&socket_data); |
706 | 728 |
707 host_resolver_.rules()->AddSimulatedFailure(kDefaultServerHostName); | 729 host_resolver_.rules()->AddSimulatedFailure(kDefaultServerHostName); |
708 | 730 |
709 QuicStreamRequest request(&factory_); | 731 QuicStreamRequest request(&factory_); |
710 EXPECT_EQ(ERR_IO_PENDING, | 732 EXPECT_EQ(ERR_IO_PENDING, |
711 request.Request(host_port_pair_, | 733 request.Request(host_port_pair_, |
712 is_https_, | 734 is_https_, |
| 735 privacy_mode_, |
713 "GET", | 736 "GET", |
714 net_log_, | 737 net_log_, |
715 callback_.callback())); | 738 callback_.callback())); |
716 | 739 |
717 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); | 740 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); |
718 | 741 |
719 EXPECT_TRUE(socket_data.at_read_eof()); | 742 EXPECT_TRUE(socket_data.at_read_eof()); |
720 EXPECT_TRUE(socket_data.at_write_eof()); | 743 EXPECT_TRUE(socket_data.at_write_eof()); |
721 } | 744 } |
722 | 745 |
723 TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) { | 746 TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) { |
724 MockConnect connect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); | 747 MockConnect connect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
725 DeterministicSocketData socket_data(NULL, 0, NULL, 0); | 748 DeterministicSocketData socket_data(NULL, 0, NULL, 0); |
726 socket_data.set_connect_data(connect); | 749 socket_data.set_connect_data(connect); |
727 socket_factory_.AddSocketDataProvider(&socket_data); | 750 socket_factory_.AddSocketDataProvider(&socket_data); |
728 socket_data.StopAfter(1); | 751 socket_data.StopAfter(1); |
729 | 752 |
730 QuicStreamRequest request(&factory_); | 753 QuicStreamRequest request(&factory_); |
731 EXPECT_EQ(ERR_IO_PENDING, | 754 EXPECT_EQ(ERR_IO_PENDING, |
732 request.Request(host_port_pair_, | 755 request.Request(host_port_pair_, |
733 is_https_, | 756 is_https_, |
| 757 privacy_mode_, |
734 "GET", | 758 "GET", |
735 net_log_, | 759 net_log_, |
736 callback_.callback())); | 760 callback_.callback())); |
737 | 761 |
738 EXPECT_EQ(ERR_ADDRESS_IN_USE, callback_.WaitForResult()); | 762 EXPECT_EQ(ERR_ADDRESS_IN_USE, callback_.WaitForResult()); |
739 | 763 |
740 EXPECT_TRUE(socket_data.at_read_eof()); | 764 EXPECT_TRUE(socket_data.at_read_eof()); |
741 EXPECT_TRUE(socket_data.at_write_eof()); | 765 EXPECT_TRUE(socket_data.at_write_eof()); |
742 } | 766 } |
743 | 767 |
744 TEST_P(QuicStreamFactoryTest, CancelCreate) { | 768 TEST_P(QuicStreamFactoryTest, CancelCreate) { |
745 MockRead reads[] = { | 769 MockRead reads[] = { |
746 MockRead(ASYNC, OK, 0) // EOF | 770 MockRead(ASYNC, OK, 0) // EOF |
747 }; | 771 }; |
748 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); | 772 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
749 socket_factory_.AddSocketDataProvider(&socket_data); | 773 socket_factory_.AddSocketDataProvider(&socket_data); |
750 { | 774 { |
751 QuicStreamRequest request(&factory_); | 775 QuicStreamRequest request(&factory_); |
752 EXPECT_EQ(ERR_IO_PENDING, | 776 EXPECT_EQ(ERR_IO_PENDING, |
753 request.Request(host_port_pair_, | 777 request.Request(host_port_pair_, |
754 is_https_, | 778 is_https_, |
| 779 privacy_mode_, |
755 "GET", | 780 "GET", |
756 net_log_, | 781 net_log_, |
757 callback_.callback())); | 782 callback_.callback())); |
758 } | 783 } |
759 | 784 |
760 socket_data.StopAfter(1); | 785 socket_data.StopAfter(1); |
761 base::RunLoop run_loop; | 786 base::RunLoop run_loop; |
762 run_loop.RunUntilIdle(); | 787 run_loop.RunUntilIdle(); |
763 | 788 |
764 scoped_ptr<QuicHttpStream> stream( | 789 scoped_ptr<QuicHttpStream> stream( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 MockRead(ASYNC, 0, 0) // EOF | 837 MockRead(ASYNC, 0, 0) // EOF |
813 }; | 838 }; |
814 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); | 839 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
815 socket_factory_.AddSocketDataProvider(&socket_data2); | 840 socket_factory_.AddSocketDataProvider(&socket_data2); |
816 socket_data2.StopAfter(1); | 841 socket_data2.StopAfter(1); |
817 | 842 |
818 QuicStreamRequest request(&factory_); | 843 QuicStreamRequest request(&factory_); |
819 EXPECT_EQ(ERR_IO_PENDING, | 844 EXPECT_EQ(ERR_IO_PENDING, |
820 request.Request(host_port_pair_, | 845 request.Request(host_port_pair_, |
821 is_https_, | 846 is_https_, |
| 847 privacy_mode_, |
822 "GET", | 848 "GET", |
823 net_log_, | 849 net_log_, |
824 callback_.callback())); | 850 callback_.callback())); |
825 | 851 |
826 EXPECT_EQ(OK, callback_.WaitForResult()); | 852 EXPECT_EQ(OK, callback_.WaitForResult()); |
827 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 853 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
828 HttpRequestInfo request_info; | 854 HttpRequestInfo request_info; |
829 EXPECT_EQ(OK, stream->InitializeStream(&request_info, | 855 EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
830 DEFAULT_PRIORITY, | 856 DEFAULT_PRIORITY, |
831 net_log_, CompletionCallback())); | 857 net_log_, CompletionCallback())); |
832 | 858 |
833 // Close the session and verify that stream saw the error. | 859 // Close the session and verify that stream saw the error. |
834 factory_.CloseAllSessions(ERR_INTERNET_DISCONNECTED); | 860 factory_.CloseAllSessions(ERR_INTERNET_DISCONNECTED); |
835 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, | 861 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
836 stream->ReadResponseHeaders(callback_.callback())); | 862 stream->ReadResponseHeaders(callback_.callback())); |
837 | 863 |
838 // Now attempting to request a stream to the same origin should create | 864 // Now attempting to request a stream to the same origin should create |
839 // a new session. | 865 // a new session. |
840 | 866 |
841 QuicStreamRequest request2(&factory_); | 867 QuicStreamRequest request2(&factory_); |
842 EXPECT_EQ(ERR_IO_PENDING, | 868 EXPECT_EQ(ERR_IO_PENDING, |
843 request2.Request(host_port_pair_, | 869 request2.Request(host_port_pair_, |
844 is_https_, | 870 is_https_, |
| 871 privacy_mode_, |
845 "GET", | 872 "GET", |
846 net_log_, | 873 net_log_, |
847 callback_.callback())); | 874 callback_.callback())); |
848 | 875 |
849 EXPECT_EQ(OK, callback_.WaitForResult()); | 876 EXPECT_EQ(OK, callback_.WaitForResult()); |
850 stream = request2.ReleaseStream(); | 877 stream = request2.ReleaseStream(); |
851 stream.reset(); // Will reset stream 3. | 878 stream.reset(); // Will reset stream 3. |
852 | 879 |
853 EXPECT_TRUE(socket_data.at_read_eof()); | 880 EXPECT_TRUE(socket_data.at_read_eof()); |
854 EXPECT_TRUE(socket_data.at_write_eof()); | 881 EXPECT_TRUE(socket_data.at_write_eof()); |
(...skipping 19 matching lines...) Expand all Loading... |
874 MockRead(ASYNC, 0, 0) // EOF | 901 MockRead(ASYNC, 0, 0) // EOF |
875 }; | 902 }; |
876 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); | 903 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
877 socket_factory_.AddSocketDataProvider(&socket_data2); | 904 socket_factory_.AddSocketDataProvider(&socket_data2); |
878 socket_data2.StopAfter(1); | 905 socket_data2.StopAfter(1); |
879 | 906 |
880 QuicStreamRequest request(&factory_); | 907 QuicStreamRequest request(&factory_); |
881 EXPECT_EQ(ERR_IO_PENDING, | 908 EXPECT_EQ(ERR_IO_PENDING, |
882 request.Request(host_port_pair_, | 909 request.Request(host_port_pair_, |
883 is_https_, | 910 is_https_, |
| 911 privacy_mode_, |
884 "GET", | 912 "GET", |
885 net_log_, | 913 net_log_, |
886 callback_.callback())); | 914 callback_.callback())); |
887 | 915 |
888 EXPECT_EQ(OK, callback_.WaitForResult()); | 916 EXPECT_EQ(OK, callback_.WaitForResult()); |
889 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 917 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
890 HttpRequestInfo request_info; | 918 HttpRequestInfo request_info; |
891 EXPECT_EQ(OK, stream->InitializeStream(&request_info, | 919 EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
892 DEFAULT_PRIORITY, | 920 DEFAULT_PRIORITY, |
893 net_log_, CompletionCallback())); | 921 net_log_, CompletionCallback())); |
894 | 922 |
895 // Change the IP address and verify that stream saw the error. | 923 // Change the IP address and verify that stream saw the error. |
896 factory_.OnIPAddressChanged(); | 924 factory_.OnIPAddressChanged(); |
897 EXPECT_EQ(ERR_NETWORK_CHANGED, | 925 EXPECT_EQ(ERR_NETWORK_CHANGED, |
898 stream->ReadResponseHeaders(callback_.callback())); | 926 stream->ReadResponseHeaders(callback_.callback())); |
899 EXPECT_TRUE(factory_.require_confirmation()); | 927 EXPECT_TRUE(factory_.require_confirmation()); |
900 | 928 |
901 // Now attempting to request a stream to the same origin should create | 929 // Now attempting to request a stream to the same origin should create |
902 // a new session. | 930 // a new session. |
903 | 931 |
904 QuicStreamRequest request2(&factory_); | 932 QuicStreamRequest request2(&factory_); |
905 EXPECT_EQ(ERR_IO_PENDING, | 933 EXPECT_EQ(ERR_IO_PENDING, |
906 request2.Request(host_port_pair_, | 934 request2.Request(host_port_pair_, |
907 is_https_, | 935 is_https_, |
| 936 privacy_mode_, |
908 "GET", | 937 "GET", |
909 net_log_, | 938 net_log_, |
910 callback_.callback())); | 939 callback_.callback())); |
911 | 940 |
912 EXPECT_EQ(OK, callback_.WaitForResult()); | 941 EXPECT_EQ(OK, callback_.WaitForResult()); |
913 stream = request2.ReleaseStream(); | 942 stream = request2.ReleaseStream(); |
914 stream.reset(); // Will reset stream 3. | 943 stream.reset(); // Will reset stream 3. |
915 | 944 |
916 EXPECT_TRUE(socket_data.at_read_eof()); | 945 EXPECT_TRUE(socket_data.at_read_eof()); |
917 EXPECT_TRUE(socket_data.at_write_eof()); | 946 EXPECT_TRUE(socket_data.at_write_eof()); |
(...skipping 19 matching lines...) Expand all Loading... |
937 MockRead(ASYNC, 0, 0) // EOF | 966 MockRead(ASYNC, 0, 0) // EOF |
938 }; | 967 }; |
939 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); | 968 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
940 socket_factory_.AddSocketDataProvider(&socket_data2); | 969 socket_factory_.AddSocketDataProvider(&socket_data2); |
941 socket_data2.StopAfter(1); | 970 socket_data2.StopAfter(1); |
942 | 971 |
943 QuicStreamRequest request(&factory_); | 972 QuicStreamRequest request(&factory_); |
944 EXPECT_EQ(ERR_IO_PENDING, | 973 EXPECT_EQ(ERR_IO_PENDING, |
945 request.Request(host_port_pair_, | 974 request.Request(host_port_pair_, |
946 is_https_, | 975 is_https_, |
| 976 privacy_mode_, |
947 "GET", | 977 "GET", |
948 net_log_, | 978 net_log_, |
949 callback_.callback())); | 979 callback_.callback())); |
950 | 980 |
951 EXPECT_EQ(OK, callback_.WaitForResult()); | 981 EXPECT_EQ(OK, callback_.WaitForResult()); |
952 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 982 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
953 HttpRequestInfo request_info; | 983 HttpRequestInfo request_info; |
954 EXPECT_EQ(OK, stream->InitializeStream(&request_info, | 984 EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
955 DEFAULT_PRIORITY, | 985 DEFAULT_PRIORITY, |
956 net_log_, CompletionCallback())); | 986 net_log_, CompletionCallback())); |
957 | 987 |
958 // Add a cert and verify that stream saw the event. | 988 // Add a cert and verify that stream saw the event. |
959 factory_.OnCertAdded(NULL); | 989 factory_.OnCertAdded(NULL); |
960 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, | 990 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, |
961 stream->ReadResponseHeaders(callback_.callback())); | 991 stream->ReadResponseHeaders(callback_.callback())); |
962 EXPECT_FALSE(factory_.require_confirmation()); | 992 EXPECT_FALSE(factory_.require_confirmation()); |
963 | 993 |
964 // Now attempting to request a stream to the same origin should create | 994 // Now attempting to request a stream to the same origin should create |
965 // a new session. | 995 // a new session. |
966 | 996 |
967 QuicStreamRequest request2(&factory_); | 997 QuicStreamRequest request2(&factory_); |
968 EXPECT_EQ(ERR_IO_PENDING, | 998 EXPECT_EQ(ERR_IO_PENDING, |
969 request2.Request(host_port_pair_, | 999 request2.Request(host_port_pair_, |
970 is_https_, | 1000 is_https_, |
| 1001 privacy_mode_, |
971 "GET", | 1002 "GET", |
972 net_log_, | 1003 net_log_, |
973 callback_.callback())); | 1004 callback_.callback())); |
974 | 1005 |
975 EXPECT_EQ(OK, callback_.WaitForResult()); | 1006 EXPECT_EQ(OK, callback_.WaitForResult()); |
976 stream = request2.ReleaseStream(); | 1007 stream = request2.ReleaseStream(); |
977 stream.reset(); // Will reset stream 3. | 1008 stream.reset(); // Will reset stream 3. |
978 | 1009 |
979 EXPECT_TRUE(socket_data.at_read_eof()); | 1010 EXPECT_TRUE(socket_data.at_read_eof()); |
980 EXPECT_TRUE(socket_data.at_write_eof()); | 1011 EXPECT_TRUE(socket_data.at_write_eof()); |
(...skipping 19 matching lines...) Expand all Loading... |
1000 MockRead(ASYNC, 0, 0) // EOF | 1031 MockRead(ASYNC, 0, 0) // EOF |
1001 }; | 1032 }; |
1002 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); | 1033 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
1003 socket_factory_.AddSocketDataProvider(&socket_data2); | 1034 socket_factory_.AddSocketDataProvider(&socket_data2); |
1004 socket_data2.StopAfter(1); | 1035 socket_data2.StopAfter(1); |
1005 | 1036 |
1006 QuicStreamRequest request(&factory_); | 1037 QuicStreamRequest request(&factory_); |
1007 EXPECT_EQ(ERR_IO_PENDING, | 1038 EXPECT_EQ(ERR_IO_PENDING, |
1008 request.Request(host_port_pair_, | 1039 request.Request(host_port_pair_, |
1009 is_https_, | 1040 is_https_, |
| 1041 privacy_mode_, |
1010 "GET", | 1042 "GET", |
1011 net_log_, | 1043 net_log_, |
1012 callback_.callback())); | 1044 callback_.callback())); |
1013 | 1045 |
1014 EXPECT_EQ(OK, callback_.WaitForResult()); | 1046 EXPECT_EQ(OK, callback_.WaitForResult()); |
1015 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 1047 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
1016 HttpRequestInfo request_info; | 1048 HttpRequestInfo request_info; |
1017 EXPECT_EQ(OK, stream->InitializeStream(&request_info, | 1049 EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
1018 DEFAULT_PRIORITY, | 1050 DEFAULT_PRIORITY, |
1019 net_log_, CompletionCallback())); | 1051 net_log_, CompletionCallback())); |
1020 | 1052 |
1021 // Change the CA cert and verify that stream saw the event. | 1053 // Change the CA cert and verify that stream saw the event. |
1022 factory_.OnCACertChanged(NULL); | 1054 factory_.OnCACertChanged(NULL); |
1023 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, | 1055 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, |
1024 stream->ReadResponseHeaders(callback_.callback())); | 1056 stream->ReadResponseHeaders(callback_.callback())); |
1025 EXPECT_FALSE(factory_.require_confirmation()); | 1057 EXPECT_FALSE(factory_.require_confirmation()); |
1026 | 1058 |
1027 // Now attempting to request a stream to the same origin should create | 1059 // Now attempting to request a stream to the same origin should create |
1028 // a new session. | 1060 // a new session. |
1029 | 1061 |
1030 QuicStreamRequest request2(&factory_); | 1062 QuicStreamRequest request2(&factory_); |
1031 EXPECT_EQ(ERR_IO_PENDING, | 1063 EXPECT_EQ(ERR_IO_PENDING, |
1032 request2.Request(host_port_pair_, | 1064 request2.Request(host_port_pair_, |
1033 is_https_, | 1065 is_https_, |
| 1066 privacy_mode_, |
1034 "GET", | 1067 "GET", |
1035 net_log_, | 1068 net_log_, |
1036 callback_.callback())); | 1069 callback_.callback())); |
1037 | 1070 |
1038 EXPECT_EQ(OK, callback_.WaitForResult()); | 1071 EXPECT_EQ(OK, callback_.WaitForResult()); |
1039 stream = request2.ReleaseStream(); | 1072 stream = request2.ReleaseStream(); |
1040 stream.reset(); // Will reset stream 3. | 1073 stream.reset(); // Will reset stream 3. |
1041 | 1074 |
1042 EXPECT_TRUE(socket_data.at_read_eof()); | 1075 EXPECT_TRUE(socket_data.at_read_eof()); |
1043 EXPECT_TRUE(socket_data.at_write_eof()); | 1076 EXPECT_TRUE(socket_data.at_write_eof()); |
1044 EXPECT_TRUE(socket_data2.at_read_eof()); | 1077 EXPECT_TRUE(socket_data2.at_read_eof()); |
1045 EXPECT_TRUE(socket_data2.at_write_eof()); | 1078 EXPECT_TRUE(socket_data2.at_write_eof()); |
1046 } | 1079 } |
1047 | 1080 |
1048 TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) { | 1081 TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) { |
1049 vector<string> cannoncial_suffixes; | 1082 vector<string> cannoncial_suffixes; |
1050 cannoncial_suffixes.push_back(string(".c.youtube.com")); | 1083 cannoncial_suffixes.push_back(string(".c.youtube.com")); |
1051 cannoncial_suffixes.push_back(string(".googlevideo.com")); | 1084 cannoncial_suffixes.push_back(string(".googlevideo.com")); |
1052 | 1085 |
1053 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { | 1086 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
1054 string r1_host_name("r1"); | 1087 string r1_host_name("r1"); |
1055 string r2_host_name("r2"); | 1088 string r2_host_name("r2"); |
1056 r1_host_name.append(cannoncial_suffixes[i]); | 1089 r1_host_name.append(cannoncial_suffixes[i]); |
1057 r2_host_name.append(cannoncial_suffixes[i]); | 1090 r2_host_name.append(cannoncial_suffixes[i]); |
1058 | 1091 |
1059 HostPortPair host_port_pair1(r1_host_name, 80); | 1092 HostPortPair host_port_pair1(r1_host_name, 80); |
1060 QuicCryptoClientConfig* crypto_config = | 1093 QuicCryptoClientConfig* crypto_config = |
1061 QuicStreamFactoryPeer::GetCryptoConfig(&factory_); | 1094 QuicStreamFactoryPeer::GetCryptoConfig(&factory_); |
1062 QuicSessionKey server_key1(host_port_pair1, is_https_); | 1095 QuicSessionKey server_key1(host_port_pair1, is_https_, privacy_mode_); |
1063 QuicCryptoClientConfig::CachedState* cached1 = | 1096 QuicCryptoClientConfig::CachedState* cached1 = |
1064 crypto_config->LookupOrCreate(server_key1); | 1097 crypto_config->LookupOrCreate(server_key1); |
1065 EXPECT_FALSE(cached1->proof_valid()); | 1098 EXPECT_FALSE(cached1->proof_valid()); |
1066 EXPECT_TRUE(cached1->source_address_token().empty()); | 1099 EXPECT_TRUE(cached1->source_address_token().empty()); |
1067 | 1100 |
1068 // Mutate the cached1 to have different data. | 1101 // Mutate the cached1 to have different data. |
1069 // TODO(rtenneti): mutate other members of CachedState. | 1102 // TODO(rtenneti): mutate other members of CachedState. |
1070 cached1->set_source_address_token(r1_host_name); | 1103 cached1->set_source_address_token(r1_host_name); |
1071 cached1->SetProofValid(); | 1104 cached1->SetProofValid(); |
1072 | 1105 |
1073 HostPortPair host_port_pair2(r2_host_name, 80); | 1106 HostPortPair host_port_pair2(r2_host_name, 80); |
1074 QuicSessionKey server_key2(host_port_pair2, is_https_); | 1107 QuicSessionKey server_key2(host_port_pair2, is_https_, privacy_mode_); |
1075 QuicCryptoClientConfig::CachedState* cached2 = | 1108 QuicCryptoClientConfig::CachedState* cached2 = |
1076 crypto_config->LookupOrCreate(server_key2); | 1109 crypto_config->LookupOrCreate(server_key2); |
1077 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); | 1110 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); |
1078 EXPECT_TRUE(cached2->proof_valid()); | 1111 EXPECT_TRUE(cached2->proof_valid()); |
1079 } | 1112 } |
1080 } | 1113 } |
1081 | 1114 |
1082 TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { | 1115 TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { |
1083 vector<string> cannoncial_suffixes; | 1116 vector<string> cannoncial_suffixes; |
1084 cannoncial_suffixes.push_back(string(".c.youtube.com")); | 1117 cannoncial_suffixes.push_back(string(".c.youtube.com")); |
1085 cannoncial_suffixes.push_back(string(".googlevideo.com")); | 1118 cannoncial_suffixes.push_back(string(".googlevideo.com")); |
1086 | 1119 |
1087 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { | 1120 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
1088 string r3_host_name("r3"); | 1121 string r3_host_name("r3"); |
1089 string r4_host_name("r4"); | 1122 string r4_host_name("r4"); |
1090 r3_host_name.append(cannoncial_suffixes[i]); | 1123 r3_host_name.append(cannoncial_suffixes[i]); |
1091 r4_host_name.append(cannoncial_suffixes[i]); | 1124 r4_host_name.append(cannoncial_suffixes[i]); |
1092 | 1125 |
1093 HostPortPair host_port_pair1(r3_host_name, 80); | 1126 HostPortPair host_port_pair1(r3_host_name, 80); |
1094 QuicCryptoClientConfig* crypto_config = | 1127 QuicCryptoClientConfig* crypto_config = |
1095 QuicStreamFactoryPeer::GetCryptoConfig(&factory_); | 1128 QuicStreamFactoryPeer::GetCryptoConfig(&factory_); |
1096 QuicSessionKey server_key1(host_port_pair1, is_https_); | 1129 QuicSessionKey server_key1(host_port_pair1, is_https_, privacy_mode_); |
1097 QuicCryptoClientConfig::CachedState* cached1 = | 1130 QuicCryptoClientConfig::CachedState* cached1 = |
1098 crypto_config->LookupOrCreate(server_key1); | 1131 crypto_config->LookupOrCreate(server_key1); |
1099 EXPECT_FALSE(cached1->proof_valid()); | 1132 EXPECT_FALSE(cached1->proof_valid()); |
1100 EXPECT_TRUE(cached1->source_address_token().empty()); | 1133 EXPECT_TRUE(cached1->source_address_token().empty()); |
1101 | 1134 |
1102 // Mutate the cached1 to have different data. | 1135 // Mutate the cached1 to have different data. |
1103 // TODO(rtenneti): mutate other members of CachedState. | 1136 // TODO(rtenneti): mutate other members of CachedState. |
1104 cached1->set_source_address_token(r3_host_name); | 1137 cached1->set_source_address_token(r3_host_name); |
1105 cached1->SetProofInvalid(); | 1138 cached1->SetProofInvalid(); |
1106 | 1139 |
1107 HostPortPair host_port_pair2(r4_host_name, 80); | 1140 HostPortPair host_port_pair2(r4_host_name, 80); |
1108 QuicSessionKey server_key2(host_port_pair2, is_https_); | 1141 QuicSessionKey server_key2(host_port_pair2, is_https_, privacy_mode_); |
1109 QuicCryptoClientConfig::CachedState* cached2 = | 1142 QuicCryptoClientConfig::CachedState* cached2 = |
1110 crypto_config->LookupOrCreate(server_key2); | 1143 crypto_config->LookupOrCreate(server_key2); |
1111 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); | 1144 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
1112 EXPECT_TRUE(cached2->source_address_token().empty()); | 1145 EXPECT_TRUE(cached2->source_address_token().empty()); |
1113 EXPECT_FALSE(cached2->proof_valid()); | 1146 EXPECT_FALSE(cached2->proof_valid()); |
1114 } | 1147 } |
1115 } | 1148 } |
1116 | 1149 |
1117 } // namespace test | 1150 } // namespace test |
1118 } // namespace net | 1151 } // namespace net |
OLD | NEW |