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, kPrivacyModeDisabled); | 51 QuicSessionKey server_key(host_port_pair, is_https); |
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, kPrivacyModeDisabled); | 59 QuicSessionKey server_key(host_port_pair, is_https); |
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, kPrivacyModeDisabled); | 69 QuicSessionKey server_key(host_port_pair, is_https); |
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) { | |
101 factory_.set_require_confirmation(false); | 100 factory_.set_require_confirmation(false); |
102 } | 101 } |
103 | 102 |
104 scoped_ptr<QuicHttpStream> CreateIfSessionExists( | 103 scoped_ptr<QuicHttpStream> CreateIfSessionExists( |
105 const HostPortPair& host_port_pair, | 104 const HostPortPair& host_port_pair, |
106 const BoundNetLog& net_log) { | 105 const BoundNetLog& net_log) { |
107 return QuicStreamFactoryPeer::CreateIfSessionExists( | 106 return QuicStreamFactoryPeer::CreateIfSessionExists( |
108 &factory_, host_port_pair, false, net_log_); | 107 &factory_, host_port_pair, false, net_log_); |
109 } | 108 } |
110 | 109 |
(...skipping 16 matching lines...) Expand all Loading... |
127 MockRead(ASYNC, OK, 0) // EOF | 126 MockRead(ASYNC, OK, 0) // EOF |
128 }; | 127 }; |
129 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); | 128 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
130 socket_data.StopAfter(1); | 129 socket_data.StopAfter(1); |
131 socket_factory_.AddSocketDataProvider(&socket_data); | 130 socket_factory_.AddSocketDataProvider(&socket_data); |
132 | 131 |
133 QuicStreamRequest request(&factory_); | 132 QuicStreamRequest request(&factory_); |
134 EXPECT_EQ(ERR_IO_PENDING, | 133 EXPECT_EQ(ERR_IO_PENDING, |
135 request.Request(destination, | 134 request.Request(destination, |
136 is_https_, | 135 is_https_, |
137 privacy_mode_, | |
138 "GET", | 136 "GET", |
139 net_log_, | 137 net_log_, |
140 callback_.callback())); | 138 callback_.callback())); |
141 | 139 |
142 EXPECT_EQ(OK, callback_.WaitForResult()); | 140 EXPECT_EQ(OK, callback_.WaitForResult()); |
143 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 141 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
144 EXPECT_TRUE(stream.get()); | 142 EXPECT_TRUE(stream.get()); |
145 stream.reset(); | 143 stream.reset(); |
146 | 144 |
147 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( | 145 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( |
(...skipping 28 matching lines...) Expand all Loading... |
176 MockHostResolver host_resolver_; | 174 MockHostResolver host_resolver_; |
177 DeterministicMockClientSocketFactory socket_factory_; | 175 DeterministicMockClientSocketFactory socket_factory_; |
178 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 176 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
179 MockRandom random_generator_; | 177 MockRandom random_generator_; |
180 QuicTestPacketMaker maker_; | 178 QuicTestPacketMaker maker_; |
181 MockClock* clock_; // Owned by factory_. | 179 MockClock* clock_; // Owned by factory_. |
182 scoped_ptr<CertVerifier> cert_verifier_; | 180 scoped_ptr<CertVerifier> cert_verifier_; |
183 QuicStreamFactory factory_; | 181 QuicStreamFactory factory_; |
184 HostPortPair host_port_pair_; | 182 HostPortPair host_port_pair_; |
185 bool is_https_; | 183 bool is_https_; |
186 PrivacyMode privacy_mode_; | |
187 BoundNetLog net_log_; | 184 BoundNetLog net_log_; |
188 TestCompletionCallback callback_; | 185 TestCompletionCallback callback_; |
189 }; | 186 }; |
190 | 187 |
191 INSTANTIATE_TEST_CASE_P(Version, QuicStreamFactoryTest, | 188 INSTANTIATE_TEST_CASE_P(Version, QuicStreamFactoryTest, |
192 ::testing::ValuesIn(QuicSupportedVersions())); | 189 ::testing::ValuesIn(QuicSupportedVersions())); |
193 | 190 |
194 TEST_P(QuicStreamFactoryTest, CreateIfSessionExists) { | 191 TEST_P(QuicStreamFactoryTest, CreateIfSessionExists) { |
195 EXPECT_EQ(NULL, CreateIfSessionExists(host_port_pair_, net_log_).get()); | 192 EXPECT_EQ(NULL, CreateIfSessionExists(host_port_pair_, net_log_).get()); |
196 } | 193 } |
197 | 194 |
198 TEST_P(QuicStreamFactoryTest, Create) { | 195 TEST_P(QuicStreamFactoryTest, Create) { |
199 MockRead reads[] = { | 196 MockRead reads[] = { |
200 MockRead(ASYNC, OK, 0) // EOF | 197 MockRead(ASYNC, OK, 0) // EOF |
201 }; | 198 }; |
202 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); | 199 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
203 socket_factory_.AddSocketDataProvider(&socket_data); | 200 socket_factory_.AddSocketDataProvider(&socket_data); |
204 socket_data.StopAfter(1); | 201 socket_data.StopAfter(1); |
205 | 202 |
206 QuicStreamRequest request(&factory_); | 203 QuicStreamRequest request(&factory_); |
207 EXPECT_EQ(ERR_IO_PENDING, | 204 EXPECT_EQ(ERR_IO_PENDING, |
208 request.Request(host_port_pair_, | 205 request.Request(host_port_pair_, |
209 is_https_, | 206 is_https_, |
210 privacy_mode_, | |
211 "GET", | 207 "GET", |
212 net_log_, | 208 net_log_, |
213 callback_.callback())); | 209 callback_.callback())); |
214 | 210 |
215 EXPECT_EQ(OK, callback_.WaitForResult()); | 211 EXPECT_EQ(OK, callback_.WaitForResult()); |
216 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 212 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
217 EXPECT_TRUE(stream.get()); | 213 EXPECT_TRUE(stream.get()); |
218 | 214 |
219 // Will reset stream 3. | 215 // Will reset stream 3. |
220 stream = CreateIfSessionExists(host_port_pair_, net_log_); | 216 stream = CreateIfSessionExists(host_port_pair_, net_log_); |
221 EXPECT_TRUE(stream.get()); | 217 EXPECT_TRUE(stream.get()); |
222 | 218 |
223 // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result | 219 // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result |
224 // in streams on different sessions. | 220 // in streams on different sessions. |
225 QuicStreamRequest request2(&factory_); | 221 QuicStreamRequest request2(&factory_); |
226 EXPECT_EQ(OK, | 222 EXPECT_EQ(OK, |
227 request2.Request(host_port_pair_, | 223 request2.Request(host_port_pair_, |
228 is_https_, | 224 is_https_, |
229 privacy_mode_, | |
230 "GET", | 225 "GET", |
231 net_log_, | 226 net_log_, |
232 callback_.callback())); | 227 callback_.callback())); |
233 stream = request2.ReleaseStream(); // Will reset stream 5. | 228 stream = request2.ReleaseStream(); // Will reset stream 5. |
234 stream.reset(); // Will reset stream 7. | 229 stream.reset(); // Will reset stream 7. |
235 | 230 |
236 EXPECT_TRUE(socket_data.at_read_eof()); | 231 EXPECT_TRUE(socket_data.at_read_eof()); |
237 EXPECT_TRUE(socket_data.at_write_eof()); | 232 EXPECT_TRUE(socket_data.at_write_eof()); |
238 } | 233 } |
239 | 234 |
240 TEST_P(QuicStreamFactoryTest, CreateHttpVsHttps) { | 235 TEST_P(QuicStreamFactoryTest, CreateHttpVsHttps) { |
241 MockRead reads[] = { | 236 MockRead reads[] = { |
242 MockRead(ASYNC, OK, 0) // EOF | 237 MockRead(ASYNC, OK, 0) // EOF |
243 }; | 238 }; |
244 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); | 239 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); |
245 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); | 240 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); |
246 socket_factory_.AddSocketDataProvider(&socket_data1); | 241 socket_factory_.AddSocketDataProvider(&socket_data1); |
247 socket_factory_.AddSocketDataProvider(&socket_data2); | 242 socket_factory_.AddSocketDataProvider(&socket_data2); |
248 socket_data1.StopAfter(1); | 243 socket_data1.StopAfter(1); |
249 socket_data2.StopAfter(1); | 244 socket_data2.StopAfter(1); |
250 | 245 |
251 QuicStreamRequest request(&factory_); | 246 QuicStreamRequest request(&factory_); |
252 EXPECT_EQ(ERR_IO_PENDING, | 247 EXPECT_EQ(ERR_IO_PENDING, |
253 request.Request(host_port_pair_, | 248 request.Request(host_port_pair_, |
254 is_https_, | 249 is_https_, |
255 privacy_mode_, | |
256 "GET", | 250 "GET", |
257 net_log_, | 251 net_log_, |
258 callback_.callback())); | 252 callback_.callback())); |
259 | 253 |
260 EXPECT_EQ(OK, callback_.WaitForResult()); | 254 EXPECT_EQ(OK, callback_.WaitForResult()); |
261 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 255 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
262 EXPECT_TRUE(stream.get()); | 256 EXPECT_TRUE(stream.get()); |
263 | 257 |
264 QuicStreamRequest request2(&factory_); | 258 QuicStreamRequest request2(&factory_); |
265 EXPECT_EQ(ERR_IO_PENDING, | 259 EXPECT_EQ(ERR_IO_PENDING, |
266 request2.Request(host_port_pair_, | 260 request2.Request(host_port_pair_, |
267 !is_https_, | 261 !is_https_, |
268 privacy_mode_, | |
269 "GET", | 262 "GET", |
270 net_log_, | 263 net_log_, |
271 callback_.callback())); | 264 callback_.callback())); |
272 EXPECT_EQ(OK, callback_.WaitForResult()); | 265 EXPECT_EQ(OK, callback_.WaitForResult()); |
273 stream = request2.ReleaseStream(); | 266 stream = request2.ReleaseStream(); |
274 EXPECT_TRUE(stream.get()); | 267 EXPECT_TRUE(stream.get()); |
275 stream.reset(); | 268 stream.reset(); |
276 | 269 |
277 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( | 270 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( |
278 &factory_, host_port_pair_, is_https_), | 271 &factory_, host_port_pair_, is_https_), |
(...skipping 18 matching lines...) Expand all Loading... |
297 host_resolver_.set_synchronous_mode(true); | 290 host_resolver_.set_synchronous_mode(true); |
298 host_resolver_.rules()->AddIPLiteralRule( | 291 host_resolver_.rules()->AddIPLiteralRule( |
299 kDefaultServerHostName, "192.168.0.1", ""); | 292 kDefaultServerHostName, "192.168.0.1", ""); |
300 host_resolver_.rules()->AddIPLiteralRule( | 293 host_resolver_.rules()->AddIPLiteralRule( |
301 "mail.google.com", "192.168.0.1", ""); | 294 "mail.google.com", "192.168.0.1", ""); |
302 | 295 |
303 QuicStreamRequest request(&factory_); | 296 QuicStreamRequest request(&factory_); |
304 EXPECT_EQ(OK, | 297 EXPECT_EQ(OK, |
305 request.Request(host_port_pair_, | 298 request.Request(host_port_pair_, |
306 is_https_, | 299 is_https_, |
307 privacy_mode_, | |
308 "GET", | 300 "GET", |
309 net_log_, | 301 net_log_, |
310 callback_.callback())); | 302 callback_.callback())); |
311 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 303 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
312 EXPECT_TRUE(stream.get()); | 304 EXPECT_TRUE(stream.get()); |
313 | 305 |
314 TestCompletionCallback callback; | 306 TestCompletionCallback callback; |
315 QuicStreamRequest request2(&factory_); | 307 QuicStreamRequest request2(&factory_); |
316 EXPECT_EQ(OK, | 308 EXPECT_EQ(OK, |
317 request2.Request(server2, | 309 request2.Request(server2, |
318 is_https_, | 310 is_https_, |
319 privacy_mode_, | |
320 "GET", | 311 "GET", |
321 net_log_, | 312 net_log_, |
322 callback.callback())); | 313 callback.callback())); |
323 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 314 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
324 EXPECT_TRUE(stream2.get()); | 315 EXPECT_TRUE(stream2.get()); |
325 | 316 |
326 EXPECT_EQ( | 317 EXPECT_EQ( |
327 QuicStreamFactoryPeer::GetActiveSession( | 318 QuicStreamFactoryPeer::GetActiveSession( |
328 &factory_, host_port_pair_, is_https_), | 319 &factory_, host_port_pair_, is_https_), |
329 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_)); | 320 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_)); |
(...skipping 17 matching lines...) Expand all Loading... |
347 host_resolver_.set_synchronous_mode(true); | 338 host_resolver_.set_synchronous_mode(true); |
348 host_resolver_.rules()->AddIPLiteralRule( | 339 host_resolver_.rules()->AddIPLiteralRule( |
349 kDefaultServerHostName, "192.168.0.1", ""); | 340 kDefaultServerHostName, "192.168.0.1", ""); |
350 host_resolver_.rules()->AddIPLiteralRule( | 341 host_resolver_.rules()->AddIPLiteralRule( |
351 "mail.google.com", "192.168.0.1", ""); | 342 "mail.google.com", "192.168.0.1", ""); |
352 | 343 |
353 QuicStreamRequest request(&factory_); | 344 QuicStreamRequest request(&factory_); |
354 EXPECT_EQ(OK, | 345 EXPECT_EQ(OK, |
355 request.Request(host_port_pair_, | 346 request.Request(host_port_pair_, |
356 is_https_, | 347 is_https_, |
357 privacy_mode_, | |
358 "GET", | 348 "GET", |
359 net_log_, | 349 net_log_, |
360 callback_.callback())); | 350 callback_.callback())); |
361 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 351 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
362 EXPECT_TRUE(stream.get()); | 352 EXPECT_TRUE(stream.get()); |
363 | 353 |
364 TestCompletionCallback callback; | 354 TestCompletionCallback callback; |
365 QuicStreamRequest request2(&factory_); | 355 QuicStreamRequest request2(&factory_); |
366 EXPECT_EQ(OK, | 356 EXPECT_EQ(OK, |
367 request2.Request(server2, | 357 request2.Request(server2, |
368 is_https_, | 358 is_https_, |
369 privacy_mode_, | |
370 "GET", | 359 "GET", |
371 net_log_, | 360 net_log_, |
372 callback.callback())); | 361 callback.callback())); |
373 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 362 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
374 EXPECT_TRUE(stream2.get()); | 363 EXPECT_TRUE(stream2.get()); |
375 | 364 |
376 factory_.OnSessionGoingAway(QuicStreamFactoryPeer::GetActiveSession( | 365 factory_.OnSessionGoingAway(QuicStreamFactoryPeer::GetActiveSession( |
377 &factory_, host_port_pair_, is_https_)); | 366 &factory_, host_port_pair_, is_https_)); |
378 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( | 367 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
379 &factory_, host_port_pair_, is_https_)); | 368 &factory_, host_port_pair_, is_https_)); |
380 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( | 369 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
381 &factory_, server2, is_https_)); | 370 &factory_, server2, is_https_)); |
382 | 371 |
383 TestCompletionCallback callback3; | 372 TestCompletionCallback callback3; |
384 QuicStreamRequest request3(&factory_); | 373 QuicStreamRequest request3(&factory_); |
385 EXPECT_EQ(OK, | 374 EXPECT_EQ(OK, |
386 request3.Request(server2, | 375 request3.Request(server2, |
387 is_https_, | 376 is_https_, |
388 privacy_mode_, | |
389 "GET", | 377 "GET", |
390 net_log_, | 378 net_log_, |
391 callback3.callback())); | 379 callback3.callback())); |
392 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream(); | 380 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream(); |
393 EXPECT_TRUE(stream3.get()); | 381 EXPECT_TRUE(stream3.get()); |
394 | 382 |
395 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession( | 383 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession( |
396 &factory_, server2, is_https_)); | 384 &factory_, server2, is_https_)); |
397 | 385 |
398 EXPECT_TRUE(socket_data1.at_read_eof()); | 386 EXPECT_TRUE(socket_data1.at_read_eof()); |
(...skipping 27 matching lines...) Expand all Loading... |
426 | 414 |
427 host_resolver_.set_synchronous_mode(true); | 415 host_resolver_.set_synchronous_mode(true); |
428 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); | 416 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
429 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); | 417 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
430 | 418 |
431 QuicStreamRequest request(&factory_); | 419 QuicStreamRequest request(&factory_); |
432 is_https_ = true; | 420 is_https_ = true; |
433 EXPECT_EQ(OK, | 421 EXPECT_EQ(OK, |
434 request.Request(server1, | 422 request.Request(server1, |
435 is_https_, | 423 is_https_, |
436 privacy_mode_, | |
437 "GET", | 424 "GET", |
438 net_log_, | 425 net_log_, |
439 callback_.callback())); | 426 callback_.callback())); |
440 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 427 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
441 EXPECT_TRUE(stream.get()); | 428 EXPECT_TRUE(stream.get()); |
442 | 429 |
443 TestCompletionCallback callback; | 430 TestCompletionCallback callback; |
444 QuicStreamRequest request2(&factory_); | 431 QuicStreamRequest request2(&factory_); |
445 EXPECT_EQ(OK, | 432 EXPECT_EQ(OK, |
446 request2.Request(server2, | 433 request2.Request(server2, |
447 is_https_, | 434 is_https_, |
448 privacy_mode_, | |
449 "GET", | 435 "GET", |
450 net_log_, | 436 net_log_, |
451 callback_.callback())); | 437 callback_.callback())); |
452 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 438 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
453 EXPECT_TRUE(stream2.get()); | 439 EXPECT_TRUE(stream2.get()); |
454 | 440 |
455 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession( | 441 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession( |
456 &factory_, server1, is_https_), | 442 &factory_, server1, is_https_), |
457 QuicStreamFactoryPeer::GetActiveSession( | 443 QuicStreamFactoryPeer::GetActiveSession( |
458 &factory_, server2, is_https_)); | 444 &factory_, server2, is_https_)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 | 477 |
492 host_resolver_.set_synchronous_mode(true); | 478 host_resolver_.set_synchronous_mode(true); |
493 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); | 479 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
494 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); | 480 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
495 | 481 |
496 QuicStreamRequest request(&factory_); | 482 QuicStreamRequest request(&factory_); |
497 is_https_ = true; | 483 is_https_ = true; |
498 EXPECT_EQ(OK, | 484 EXPECT_EQ(OK, |
499 request.Request(server1, | 485 request.Request(server1, |
500 is_https_, | 486 is_https_, |
501 privacy_mode_, | |
502 "GET", | 487 "GET", |
503 net_log_, | 488 net_log_, |
504 callback_.callback())); | 489 callback_.callback())); |
505 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 490 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
506 EXPECT_TRUE(stream.get()); | 491 EXPECT_TRUE(stream.get()); |
507 | 492 |
508 TestCompletionCallback callback; | 493 TestCompletionCallback callback; |
509 QuicStreamRequest request2(&factory_); | 494 QuicStreamRequest request2(&factory_); |
510 EXPECT_EQ(OK, | 495 EXPECT_EQ(OK, |
511 request2.Request(server2, | 496 request2.Request(server2, |
512 is_https_, | 497 is_https_, |
513 privacy_mode_, | |
514 "GET", | 498 "GET", |
515 net_log_, | 499 net_log_, |
516 callback_.callback())); | 500 callback_.callback())); |
517 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 501 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
518 EXPECT_TRUE(stream2.get()); | 502 EXPECT_TRUE(stream2.get()); |
519 | 503 |
520 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( | 504 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( |
521 &factory_, server1, is_https_), | 505 &factory_, server1, is_https_), |
522 QuicStreamFactoryPeer::GetActiveSession( | 506 QuicStreamFactoryPeer::GetActiveSession( |
523 &factory_, server2, is_https_)); | 507 &factory_, server2, is_https_)); |
(...skipping 12 matching lines...) Expand all Loading... |
536 socket_data.StopAfter(1); | 520 socket_data.StopAfter(1); |
537 socket_factory_.AddSocketDataProvider(&socket_data); | 521 socket_factory_.AddSocketDataProvider(&socket_data); |
538 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); | 522 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); |
539 socket_data2.StopAfter(1); | 523 socket_data2.StopAfter(1); |
540 socket_factory_.AddSocketDataProvider(&socket_data2); | 524 socket_factory_.AddSocketDataProvider(&socket_data2); |
541 | 525 |
542 QuicStreamRequest request(&factory_); | 526 QuicStreamRequest request(&factory_); |
543 EXPECT_EQ(ERR_IO_PENDING, | 527 EXPECT_EQ(ERR_IO_PENDING, |
544 request.Request(host_port_pair_, | 528 request.Request(host_port_pair_, |
545 is_https_, | 529 is_https_, |
546 privacy_mode_, | |
547 "GET", | 530 "GET", |
548 net_log_, | 531 net_log_, |
549 callback_.callback())); | 532 callback_.callback())); |
550 | 533 |
551 EXPECT_EQ(OK, callback_.WaitForResult()); | 534 EXPECT_EQ(OK, callback_.WaitForResult()); |
552 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 535 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
553 EXPECT_TRUE(stream.get()); | 536 EXPECT_TRUE(stream.get()); |
554 | 537 |
555 // Mark the session as going away. Ensure that while it is still alive | 538 // Mark the session as going away. Ensure that while it is still alive |
556 // that it is no longer active. | 539 // that it is no longer active. |
557 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( | 540 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( |
558 &factory_, host_port_pair_, is_https_); | 541 &factory_, host_port_pair_, is_https_); |
559 factory_.OnSessionGoingAway(session); | 542 factory_.OnSessionGoingAway(session); |
560 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); | 543 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); |
561 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( | 544 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
562 &factory_, host_port_pair_, is_https_)); | 545 &factory_, host_port_pair_, is_https_)); |
563 EXPECT_EQ(NULL, CreateIfSessionExists(host_port_pair_, net_log_).get()); | 546 EXPECT_EQ(NULL, CreateIfSessionExists(host_port_pair_, net_log_).get()); |
564 | 547 |
565 // Create a new request for the same destination and verify that a | 548 // Create a new request for the same destination and verify that a |
566 // new session is created. | 549 // new session is created. |
567 QuicStreamRequest request2(&factory_); | 550 QuicStreamRequest request2(&factory_); |
568 EXPECT_EQ(ERR_IO_PENDING, | 551 EXPECT_EQ(ERR_IO_PENDING, |
569 request2.Request(host_port_pair_, | 552 request2.Request(host_port_pair_, |
570 is_https_, | 553 is_https_, |
571 privacy_mode_, | |
572 "GET", | 554 "GET", |
573 net_log_, | 555 net_log_, |
574 callback_.callback())); | 556 callback_.callback())); |
575 EXPECT_EQ(OK, callback_.WaitForResult()); | 557 EXPECT_EQ(OK, callback_.WaitForResult()); |
576 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 558 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
577 EXPECT_TRUE(stream2.get()); | 559 EXPECT_TRUE(stream2.get()); |
578 | 560 |
579 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_, | 561 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_, |
580 host_port_pair_, | 562 host_port_pair_, |
581 is_https_)); | 563 is_https_)); |
(...skipping 27 matching lines...) Expand all Loading... |
609 socket_data.StopAfter(1); | 591 socket_data.StopAfter(1); |
610 | 592 |
611 HttpRequestInfo request_info; | 593 HttpRequestInfo request_info; |
612 std::vector<QuicHttpStream*> streams; | 594 std::vector<QuicHttpStream*> streams; |
613 // The MockCryptoClientStream sets max_open_streams to be | 595 // The MockCryptoClientStream sets max_open_streams to be |
614 // 2 * kDefaultMaxStreamsPerConnection. | 596 // 2 * kDefaultMaxStreamsPerConnection. |
615 for (size_t i = 0; i < 2 * kDefaultMaxStreamsPerConnection; i++) { | 597 for (size_t i = 0; i < 2 * kDefaultMaxStreamsPerConnection; i++) { |
616 QuicStreamRequest request(&factory_); | 598 QuicStreamRequest request(&factory_); |
617 int rv = request.Request(host_port_pair_, | 599 int rv = request.Request(host_port_pair_, |
618 is_https_, | 600 is_https_, |
619 privacy_mode_, | |
620 "GET", | 601 "GET", |
621 net_log_, | 602 net_log_, |
622 callback_.callback()); | 603 callback_.callback()); |
623 if (i == 0) { | 604 if (i == 0) { |
624 EXPECT_EQ(ERR_IO_PENDING, rv); | 605 EXPECT_EQ(ERR_IO_PENDING, rv); |
625 EXPECT_EQ(OK, callback_.WaitForResult()); | 606 EXPECT_EQ(OK, callback_.WaitForResult()); |
626 } else { | 607 } else { |
627 EXPECT_EQ(OK, rv); | 608 EXPECT_EQ(OK, rv); |
628 } | 609 } |
629 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 610 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
630 EXPECT_TRUE(stream); | 611 EXPECT_TRUE(stream); |
631 EXPECT_EQ(OK, stream->InitializeStream( | 612 EXPECT_EQ(OK, stream->InitializeStream( |
632 &request_info, DEFAULT_PRIORITY, net_log_, CompletionCallback())); | 613 &request_info, DEFAULT_PRIORITY, net_log_, CompletionCallback())); |
633 streams.push_back(stream.release()); | 614 streams.push_back(stream.release()); |
634 } | 615 } |
635 | 616 |
636 QuicStreamRequest request(&factory_); | 617 QuicStreamRequest request(&factory_); |
637 EXPECT_EQ(OK, | 618 EXPECT_EQ(OK, |
638 request.Request(host_port_pair_, | 619 request.Request(host_port_pair_, |
639 is_https_, | 620 is_https_, |
640 privacy_mode_, | |
641 "GET", | 621 "GET", |
642 net_log_, | 622 net_log_, |
643 CompletionCallback())); | 623 CompletionCallback())); |
644 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 624 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
645 EXPECT_TRUE(stream); | 625 EXPECT_TRUE(stream); |
646 EXPECT_EQ(ERR_IO_PENDING, stream->InitializeStream( | 626 EXPECT_EQ(ERR_IO_PENDING, stream->InitializeStream( |
647 &request_info, DEFAULT_PRIORITY, net_log_, callback_.callback())); | 627 &request_info, DEFAULT_PRIORITY, net_log_, callback_.callback())); |
648 | 628 |
649 // Close the first stream. | 629 // Close the first stream. |
650 streams.front()->Close(false); | 630 streams.front()->Close(false); |
(...skipping 10 matching lines...) Expand all Loading... |
661 TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) { | 641 TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) { |
662 DeterministicSocketData socket_data(NULL, 0, NULL, 0); | 642 DeterministicSocketData socket_data(NULL, 0, NULL, 0); |
663 socket_factory_.AddSocketDataProvider(&socket_data); | 643 socket_factory_.AddSocketDataProvider(&socket_data); |
664 | 644 |
665 host_resolver_.rules()->AddSimulatedFailure(kDefaultServerHostName); | 645 host_resolver_.rules()->AddSimulatedFailure(kDefaultServerHostName); |
666 | 646 |
667 QuicStreamRequest request(&factory_); | 647 QuicStreamRequest request(&factory_); |
668 EXPECT_EQ(ERR_IO_PENDING, | 648 EXPECT_EQ(ERR_IO_PENDING, |
669 request.Request(host_port_pair_, | 649 request.Request(host_port_pair_, |
670 is_https_, | 650 is_https_, |
671 privacy_mode_, | |
672 "GET", | 651 "GET", |
673 net_log_, | 652 net_log_, |
674 callback_.callback())); | 653 callback_.callback())); |
675 | 654 |
676 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); | 655 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); |
677 | 656 |
678 EXPECT_TRUE(socket_data.at_read_eof()); | 657 EXPECT_TRUE(socket_data.at_read_eof()); |
679 EXPECT_TRUE(socket_data.at_write_eof()); | 658 EXPECT_TRUE(socket_data.at_write_eof()); |
680 } | 659 } |
681 | 660 |
682 TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) { | 661 TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) { |
683 MockConnect connect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); | 662 MockConnect connect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
684 DeterministicSocketData socket_data(NULL, 0, NULL, 0); | 663 DeterministicSocketData socket_data(NULL, 0, NULL, 0); |
685 socket_data.set_connect_data(connect); | 664 socket_data.set_connect_data(connect); |
686 socket_factory_.AddSocketDataProvider(&socket_data); | 665 socket_factory_.AddSocketDataProvider(&socket_data); |
687 socket_data.StopAfter(1); | 666 socket_data.StopAfter(1); |
688 | 667 |
689 QuicStreamRequest request(&factory_); | 668 QuicStreamRequest request(&factory_); |
690 EXPECT_EQ(ERR_IO_PENDING, | 669 EXPECT_EQ(ERR_IO_PENDING, |
691 request.Request(host_port_pair_, | 670 request.Request(host_port_pair_, |
692 is_https_, | 671 is_https_, |
693 privacy_mode_, | |
694 "GET", | 672 "GET", |
695 net_log_, | 673 net_log_, |
696 callback_.callback())); | 674 callback_.callback())); |
697 | 675 |
698 EXPECT_EQ(ERR_ADDRESS_IN_USE, callback_.WaitForResult()); | 676 EXPECT_EQ(ERR_ADDRESS_IN_USE, callback_.WaitForResult()); |
699 | 677 |
700 EXPECT_TRUE(socket_data.at_read_eof()); | 678 EXPECT_TRUE(socket_data.at_read_eof()); |
701 EXPECT_TRUE(socket_data.at_write_eof()); | 679 EXPECT_TRUE(socket_data.at_write_eof()); |
702 } | 680 } |
703 | 681 |
704 TEST_P(QuicStreamFactoryTest, CancelCreate) { | 682 TEST_P(QuicStreamFactoryTest, CancelCreate) { |
705 MockRead reads[] = { | 683 MockRead reads[] = { |
706 MockRead(ASYNC, OK, 0) // EOF | 684 MockRead(ASYNC, OK, 0) // EOF |
707 }; | 685 }; |
708 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); | 686 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
709 socket_factory_.AddSocketDataProvider(&socket_data); | 687 socket_factory_.AddSocketDataProvider(&socket_data); |
710 { | 688 { |
711 QuicStreamRequest request(&factory_); | 689 QuicStreamRequest request(&factory_); |
712 EXPECT_EQ(ERR_IO_PENDING, | 690 EXPECT_EQ(ERR_IO_PENDING, |
713 request.Request(host_port_pair_, | 691 request.Request(host_port_pair_, |
714 is_https_, | 692 is_https_, |
715 privacy_mode_, | |
716 "GET", | 693 "GET", |
717 net_log_, | 694 net_log_, |
718 callback_.callback())); | 695 callback_.callback())); |
719 } | 696 } |
720 | 697 |
721 socket_data.StopAfter(1); | 698 socket_data.StopAfter(1); |
722 base::RunLoop run_loop; | 699 base::RunLoop run_loop; |
723 run_loop.RunUntilIdle(); | 700 run_loop.RunUntilIdle(); |
724 | 701 |
725 scoped_ptr<QuicHttpStream> stream( | 702 scoped_ptr<QuicHttpStream> stream( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 MockRead(ASYNC, 0, 0) // EOF | 750 MockRead(ASYNC, 0, 0) // EOF |
774 }; | 751 }; |
775 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); | 752 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
776 socket_factory_.AddSocketDataProvider(&socket_data2); | 753 socket_factory_.AddSocketDataProvider(&socket_data2); |
777 socket_data2.StopAfter(1); | 754 socket_data2.StopAfter(1); |
778 | 755 |
779 QuicStreamRequest request(&factory_); | 756 QuicStreamRequest request(&factory_); |
780 EXPECT_EQ(ERR_IO_PENDING, | 757 EXPECT_EQ(ERR_IO_PENDING, |
781 request.Request(host_port_pair_, | 758 request.Request(host_port_pair_, |
782 is_https_, | 759 is_https_, |
783 privacy_mode_, | |
784 "GET", | 760 "GET", |
785 net_log_, | 761 net_log_, |
786 callback_.callback())); | 762 callback_.callback())); |
787 | 763 |
788 EXPECT_EQ(OK, callback_.WaitForResult()); | 764 EXPECT_EQ(OK, callback_.WaitForResult()); |
789 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 765 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
790 HttpRequestInfo request_info; | 766 HttpRequestInfo request_info; |
791 EXPECT_EQ(OK, stream->InitializeStream(&request_info, | 767 EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
792 DEFAULT_PRIORITY, | 768 DEFAULT_PRIORITY, |
793 net_log_, CompletionCallback())); | 769 net_log_, CompletionCallback())); |
794 | 770 |
795 // Close the session and verify that stream saw the error. | 771 // Close the session and verify that stream saw the error. |
796 factory_.CloseAllSessions(ERR_INTERNET_DISCONNECTED); | 772 factory_.CloseAllSessions(ERR_INTERNET_DISCONNECTED); |
797 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, | 773 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
798 stream->ReadResponseHeaders(callback_.callback())); | 774 stream->ReadResponseHeaders(callback_.callback())); |
799 | 775 |
800 // Now attempting to request a stream to the same origin should create | 776 // Now attempting to request a stream to the same origin should create |
801 // a new session. | 777 // a new session. |
802 | 778 |
803 QuicStreamRequest request2(&factory_); | 779 QuicStreamRequest request2(&factory_); |
804 EXPECT_EQ(ERR_IO_PENDING, | 780 EXPECT_EQ(ERR_IO_PENDING, |
805 request2.Request(host_port_pair_, | 781 request2.Request(host_port_pair_, |
806 is_https_, | 782 is_https_, |
807 privacy_mode_, | |
808 "GET", | 783 "GET", |
809 net_log_, | 784 net_log_, |
810 callback_.callback())); | 785 callback_.callback())); |
811 | 786 |
812 EXPECT_EQ(OK, callback_.WaitForResult()); | 787 EXPECT_EQ(OK, callback_.WaitForResult()); |
813 stream = request2.ReleaseStream(); | 788 stream = request2.ReleaseStream(); |
814 stream.reset(); // Will reset stream 3. | 789 stream.reset(); // Will reset stream 3. |
815 | 790 |
816 EXPECT_TRUE(socket_data.at_read_eof()); | 791 EXPECT_TRUE(socket_data.at_read_eof()); |
817 EXPECT_TRUE(socket_data.at_write_eof()); | 792 EXPECT_TRUE(socket_data.at_write_eof()); |
(...skipping 19 matching lines...) Expand all Loading... |
837 MockRead(ASYNC, 0, 0) // EOF | 812 MockRead(ASYNC, 0, 0) // EOF |
838 }; | 813 }; |
839 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); | 814 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
840 socket_factory_.AddSocketDataProvider(&socket_data2); | 815 socket_factory_.AddSocketDataProvider(&socket_data2); |
841 socket_data2.StopAfter(1); | 816 socket_data2.StopAfter(1); |
842 | 817 |
843 QuicStreamRequest request(&factory_); | 818 QuicStreamRequest request(&factory_); |
844 EXPECT_EQ(ERR_IO_PENDING, | 819 EXPECT_EQ(ERR_IO_PENDING, |
845 request.Request(host_port_pair_, | 820 request.Request(host_port_pair_, |
846 is_https_, | 821 is_https_, |
847 privacy_mode_, | |
848 "GET", | 822 "GET", |
849 net_log_, | 823 net_log_, |
850 callback_.callback())); | 824 callback_.callback())); |
851 | 825 |
852 EXPECT_EQ(OK, callback_.WaitForResult()); | 826 EXPECT_EQ(OK, callback_.WaitForResult()); |
853 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 827 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
854 HttpRequestInfo request_info; | 828 HttpRequestInfo request_info; |
855 EXPECT_EQ(OK, stream->InitializeStream(&request_info, | 829 EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
856 DEFAULT_PRIORITY, | 830 DEFAULT_PRIORITY, |
857 net_log_, CompletionCallback())); | 831 net_log_, CompletionCallback())); |
858 | 832 |
859 // Change the IP address and verify that stream saw the error. | 833 // Change the IP address and verify that stream saw the error. |
860 factory_.OnIPAddressChanged(); | 834 factory_.OnIPAddressChanged(); |
861 EXPECT_EQ(ERR_NETWORK_CHANGED, | 835 EXPECT_EQ(ERR_NETWORK_CHANGED, |
862 stream->ReadResponseHeaders(callback_.callback())); | 836 stream->ReadResponseHeaders(callback_.callback())); |
863 EXPECT_TRUE(factory_.require_confirmation()); | 837 EXPECT_TRUE(factory_.require_confirmation()); |
864 | 838 |
865 // Now attempting to request a stream to the same origin should create | 839 // Now attempting to request a stream to the same origin should create |
866 // a new session. | 840 // a new session. |
867 | 841 |
868 QuicStreamRequest request2(&factory_); | 842 QuicStreamRequest request2(&factory_); |
869 EXPECT_EQ(ERR_IO_PENDING, | 843 EXPECT_EQ(ERR_IO_PENDING, |
870 request2.Request(host_port_pair_, | 844 request2.Request(host_port_pair_, |
871 is_https_, | 845 is_https_, |
872 privacy_mode_, | |
873 "GET", | 846 "GET", |
874 net_log_, | 847 net_log_, |
875 callback_.callback())); | 848 callback_.callback())); |
876 | 849 |
877 EXPECT_EQ(OK, callback_.WaitForResult()); | 850 EXPECT_EQ(OK, callback_.WaitForResult()); |
878 stream = request2.ReleaseStream(); | 851 stream = request2.ReleaseStream(); |
879 stream.reset(); // Will reset stream 3. | 852 stream.reset(); // Will reset stream 3. |
880 | 853 |
881 EXPECT_TRUE(socket_data.at_read_eof()); | 854 EXPECT_TRUE(socket_data.at_read_eof()); |
882 EXPECT_TRUE(socket_data.at_write_eof()); | 855 EXPECT_TRUE(socket_data.at_write_eof()); |
(...skipping 19 matching lines...) Expand all Loading... |
902 MockRead(ASYNC, 0, 0) // EOF | 875 MockRead(ASYNC, 0, 0) // EOF |
903 }; | 876 }; |
904 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); | 877 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
905 socket_factory_.AddSocketDataProvider(&socket_data2); | 878 socket_factory_.AddSocketDataProvider(&socket_data2); |
906 socket_data2.StopAfter(1); | 879 socket_data2.StopAfter(1); |
907 | 880 |
908 QuicStreamRequest request(&factory_); | 881 QuicStreamRequest request(&factory_); |
909 EXPECT_EQ(ERR_IO_PENDING, | 882 EXPECT_EQ(ERR_IO_PENDING, |
910 request.Request(host_port_pair_, | 883 request.Request(host_port_pair_, |
911 is_https_, | 884 is_https_, |
912 privacy_mode_, | |
913 "GET", | 885 "GET", |
914 net_log_, | 886 net_log_, |
915 callback_.callback())); | 887 callback_.callback())); |
916 | 888 |
917 EXPECT_EQ(OK, callback_.WaitForResult()); | 889 EXPECT_EQ(OK, callback_.WaitForResult()); |
918 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 890 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
919 HttpRequestInfo request_info; | 891 HttpRequestInfo request_info; |
920 EXPECT_EQ(OK, stream->InitializeStream(&request_info, | 892 EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
921 DEFAULT_PRIORITY, | 893 DEFAULT_PRIORITY, |
922 net_log_, CompletionCallback())); | 894 net_log_, CompletionCallback())); |
923 | 895 |
924 // Add a cert and verify that stream saw the event. | 896 // Add a cert and verify that stream saw the event. |
925 factory_.OnCertAdded(NULL); | 897 factory_.OnCertAdded(NULL); |
926 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, | 898 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, |
927 stream->ReadResponseHeaders(callback_.callback())); | 899 stream->ReadResponseHeaders(callback_.callback())); |
928 EXPECT_FALSE(factory_.require_confirmation()); | 900 EXPECT_FALSE(factory_.require_confirmation()); |
929 | 901 |
930 // Now attempting to request a stream to the same origin should create | 902 // Now attempting to request a stream to the same origin should create |
931 // a new session. | 903 // a new session. |
932 | 904 |
933 QuicStreamRequest request2(&factory_); | 905 QuicStreamRequest request2(&factory_); |
934 EXPECT_EQ(ERR_IO_PENDING, | 906 EXPECT_EQ(ERR_IO_PENDING, |
935 request2.Request(host_port_pair_, | 907 request2.Request(host_port_pair_, |
936 is_https_, | 908 is_https_, |
937 privacy_mode_, | |
938 "GET", | 909 "GET", |
939 net_log_, | 910 net_log_, |
940 callback_.callback())); | 911 callback_.callback())); |
941 | 912 |
942 EXPECT_EQ(OK, callback_.WaitForResult()); | 913 EXPECT_EQ(OK, callback_.WaitForResult()); |
943 stream = request2.ReleaseStream(); | 914 stream = request2.ReleaseStream(); |
944 stream.reset(); // Will reset stream 3. | 915 stream.reset(); // Will reset stream 3. |
945 | 916 |
946 EXPECT_TRUE(socket_data.at_read_eof()); | 917 EXPECT_TRUE(socket_data.at_read_eof()); |
947 EXPECT_TRUE(socket_data.at_write_eof()); | 918 EXPECT_TRUE(socket_data.at_write_eof()); |
(...skipping 19 matching lines...) Expand all Loading... |
967 MockRead(ASYNC, 0, 0) // EOF | 938 MockRead(ASYNC, 0, 0) // EOF |
968 }; | 939 }; |
969 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); | 940 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
970 socket_factory_.AddSocketDataProvider(&socket_data2); | 941 socket_factory_.AddSocketDataProvider(&socket_data2); |
971 socket_data2.StopAfter(1); | 942 socket_data2.StopAfter(1); |
972 | 943 |
973 QuicStreamRequest request(&factory_); | 944 QuicStreamRequest request(&factory_); |
974 EXPECT_EQ(ERR_IO_PENDING, | 945 EXPECT_EQ(ERR_IO_PENDING, |
975 request.Request(host_port_pair_, | 946 request.Request(host_port_pair_, |
976 is_https_, | 947 is_https_, |
977 privacy_mode_, | |
978 "GET", | 948 "GET", |
979 net_log_, | 949 net_log_, |
980 callback_.callback())); | 950 callback_.callback())); |
981 | 951 |
982 EXPECT_EQ(OK, callback_.WaitForResult()); | 952 EXPECT_EQ(OK, callback_.WaitForResult()); |
983 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 953 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
984 HttpRequestInfo request_info; | 954 HttpRequestInfo request_info; |
985 EXPECT_EQ(OK, stream->InitializeStream(&request_info, | 955 EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
986 DEFAULT_PRIORITY, | 956 DEFAULT_PRIORITY, |
987 net_log_, CompletionCallback())); | 957 net_log_, CompletionCallback())); |
988 | 958 |
989 // Change the CA cert and verify that stream saw the event. | 959 // Change the CA cert and verify that stream saw the event. |
990 factory_.OnCACertChanged(NULL); | 960 factory_.OnCACertChanged(NULL); |
991 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, | 961 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, |
992 stream->ReadResponseHeaders(callback_.callback())); | 962 stream->ReadResponseHeaders(callback_.callback())); |
993 EXPECT_FALSE(factory_.require_confirmation()); | 963 EXPECT_FALSE(factory_.require_confirmation()); |
994 | 964 |
995 // Now attempting to request a stream to the same origin should create | 965 // Now attempting to request a stream to the same origin should create |
996 // a new session. | 966 // a new session. |
997 | 967 |
998 QuicStreamRequest request2(&factory_); | 968 QuicStreamRequest request2(&factory_); |
999 EXPECT_EQ(ERR_IO_PENDING, | 969 EXPECT_EQ(ERR_IO_PENDING, |
1000 request2.Request(host_port_pair_, | 970 request2.Request(host_port_pair_, |
1001 is_https_, | 971 is_https_, |
1002 privacy_mode_, | |
1003 "GET", | 972 "GET", |
1004 net_log_, | 973 net_log_, |
1005 callback_.callback())); | 974 callback_.callback())); |
1006 | 975 |
1007 EXPECT_EQ(OK, callback_.WaitForResult()); | 976 EXPECT_EQ(OK, callback_.WaitForResult()); |
1008 stream = request2.ReleaseStream(); | 977 stream = request2.ReleaseStream(); |
1009 stream.reset(); // Will reset stream 3. | 978 stream.reset(); // Will reset stream 3. |
1010 | 979 |
1011 EXPECT_TRUE(socket_data.at_read_eof()); | 980 EXPECT_TRUE(socket_data.at_read_eof()); |
1012 EXPECT_TRUE(socket_data.at_write_eof()); | 981 EXPECT_TRUE(socket_data.at_write_eof()); |
1013 EXPECT_TRUE(socket_data2.at_read_eof()); | 982 EXPECT_TRUE(socket_data2.at_read_eof()); |
1014 EXPECT_TRUE(socket_data2.at_write_eof()); | 983 EXPECT_TRUE(socket_data2.at_write_eof()); |
1015 } | 984 } |
1016 | 985 |
1017 TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) { | 986 TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) { |
1018 vector<string> cannoncial_suffixes; | 987 vector<string> cannoncial_suffixes; |
1019 cannoncial_suffixes.push_back(string(".c.youtube.com")); | 988 cannoncial_suffixes.push_back(string(".c.youtube.com")); |
1020 cannoncial_suffixes.push_back(string(".googlevideo.com")); | 989 cannoncial_suffixes.push_back(string(".googlevideo.com")); |
1021 | 990 |
1022 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { | 991 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
1023 string r1_host_name("r1"); | 992 string r1_host_name("r1"); |
1024 string r2_host_name("r2"); | 993 string r2_host_name("r2"); |
1025 r1_host_name.append(cannoncial_suffixes[i]); | 994 r1_host_name.append(cannoncial_suffixes[i]); |
1026 r2_host_name.append(cannoncial_suffixes[i]); | 995 r2_host_name.append(cannoncial_suffixes[i]); |
1027 | 996 |
1028 HostPortPair host_port_pair1(r1_host_name, 80); | 997 HostPortPair host_port_pair1(r1_host_name, 80); |
1029 QuicCryptoClientConfig* crypto_config = | 998 QuicCryptoClientConfig* crypto_config = |
1030 QuicStreamFactoryPeer::GetCryptoConfig(&factory_); | 999 QuicStreamFactoryPeer::GetCryptoConfig(&factory_); |
1031 QuicSessionKey server_key1(host_port_pair1, is_https_, privacy_mode_); | 1000 QuicSessionKey server_key1(host_port_pair1, is_https_); |
1032 QuicCryptoClientConfig::CachedState* cached1 = | 1001 QuicCryptoClientConfig::CachedState* cached1 = |
1033 crypto_config->LookupOrCreate(server_key1); | 1002 crypto_config->LookupOrCreate(server_key1); |
1034 EXPECT_FALSE(cached1->proof_valid()); | 1003 EXPECT_FALSE(cached1->proof_valid()); |
1035 EXPECT_TRUE(cached1->source_address_token().empty()); | 1004 EXPECT_TRUE(cached1->source_address_token().empty()); |
1036 | 1005 |
1037 // Mutate the cached1 to have different data. | 1006 // Mutate the cached1 to have different data. |
1038 // TODO(rtenneti): mutate other members of CachedState. | 1007 // TODO(rtenneti): mutate other members of CachedState. |
1039 cached1->set_source_address_token(r1_host_name); | 1008 cached1->set_source_address_token(r1_host_name); |
1040 cached1->SetProofValid(); | 1009 cached1->SetProofValid(); |
1041 | 1010 |
1042 HostPortPair host_port_pair2(r2_host_name, 80); | 1011 HostPortPair host_port_pair2(r2_host_name, 80); |
1043 QuicSessionKey server_key2(host_port_pair2, is_https_, privacy_mode_); | 1012 QuicSessionKey server_key2(host_port_pair2, is_https_); |
1044 QuicCryptoClientConfig::CachedState* cached2 = | 1013 QuicCryptoClientConfig::CachedState* cached2 = |
1045 crypto_config->LookupOrCreate(server_key2); | 1014 crypto_config->LookupOrCreate(server_key2); |
1046 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); | 1015 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); |
1047 EXPECT_TRUE(cached2->proof_valid()); | 1016 EXPECT_TRUE(cached2->proof_valid()); |
1048 } | 1017 } |
1049 } | 1018 } |
1050 | 1019 |
1051 TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { | 1020 TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { |
1052 vector<string> cannoncial_suffixes; | 1021 vector<string> cannoncial_suffixes; |
1053 cannoncial_suffixes.push_back(string(".c.youtube.com")); | 1022 cannoncial_suffixes.push_back(string(".c.youtube.com")); |
1054 cannoncial_suffixes.push_back(string(".googlevideo.com")); | 1023 cannoncial_suffixes.push_back(string(".googlevideo.com")); |
1055 | 1024 |
1056 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { | 1025 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
1057 string r3_host_name("r3"); | 1026 string r3_host_name("r3"); |
1058 string r4_host_name("r4"); | 1027 string r4_host_name("r4"); |
1059 r3_host_name.append(cannoncial_suffixes[i]); | 1028 r3_host_name.append(cannoncial_suffixes[i]); |
1060 r4_host_name.append(cannoncial_suffixes[i]); | 1029 r4_host_name.append(cannoncial_suffixes[i]); |
1061 | 1030 |
1062 HostPortPair host_port_pair1(r3_host_name, 80); | 1031 HostPortPair host_port_pair1(r3_host_name, 80); |
1063 QuicCryptoClientConfig* crypto_config = | 1032 QuicCryptoClientConfig* crypto_config = |
1064 QuicStreamFactoryPeer::GetCryptoConfig(&factory_); | 1033 QuicStreamFactoryPeer::GetCryptoConfig(&factory_); |
1065 QuicSessionKey server_key1(host_port_pair1, is_https_, privacy_mode_); | 1034 QuicSessionKey server_key1(host_port_pair1, is_https_); |
1066 QuicCryptoClientConfig::CachedState* cached1 = | 1035 QuicCryptoClientConfig::CachedState* cached1 = |
1067 crypto_config->LookupOrCreate(server_key1); | 1036 crypto_config->LookupOrCreate(server_key1); |
1068 EXPECT_FALSE(cached1->proof_valid()); | 1037 EXPECT_FALSE(cached1->proof_valid()); |
1069 EXPECT_TRUE(cached1->source_address_token().empty()); | 1038 EXPECT_TRUE(cached1->source_address_token().empty()); |
1070 | 1039 |
1071 // Mutate the cached1 to have different data. | 1040 // Mutate the cached1 to have different data. |
1072 // TODO(rtenneti): mutate other members of CachedState. | 1041 // TODO(rtenneti): mutate other members of CachedState. |
1073 cached1->set_source_address_token(r3_host_name); | 1042 cached1->set_source_address_token(r3_host_name); |
1074 cached1->SetProofInvalid(); | 1043 cached1->SetProofInvalid(); |
1075 | 1044 |
1076 HostPortPair host_port_pair2(r4_host_name, 80); | 1045 HostPortPair host_port_pair2(r4_host_name, 80); |
1077 QuicSessionKey server_key2(host_port_pair2, is_https_, privacy_mode_); | 1046 QuicSessionKey server_key2(host_port_pair2, is_https_); |
1078 QuicCryptoClientConfig::CachedState* cached2 = | 1047 QuicCryptoClientConfig::CachedState* cached2 = |
1079 crypto_config->LookupOrCreate(server_key2); | 1048 crypto_config->LookupOrCreate(server_key2); |
1080 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); | 1049 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
1081 EXPECT_TRUE(cached2->source_address_token().empty()); | 1050 EXPECT_TRUE(cached2->source_address_token().empty()); |
1082 EXPECT_FALSE(cached2->proof_valid()); | 1051 EXPECT_FALSE(cached2->proof_valid()); |
1083 } | 1052 } |
1084 } | 1053 } |
1085 | 1054 |
1086 } // namespace test | 1055 } // namespace test |
1087 } // namespace net | 1056 } // namespace net |
OLD | NEW |