Chromium Code Reviews| 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 28 matching lines...) Expand all Loading... | |
| 39 | 39 |
| 40 class QuicStreamFactoryPeer { | 40 class QuicStreamFactoryPeer { |
| 41 public: | 41 public: |
| 42 static QuicCryptoClientConfig* GetOrCreateCryptoConfig( | 42 static QuicCryptoClientConfig* GetOrCreateCryptoConfig( |
| 43 QuicStreamFactory* factory, | 43 QuicStreamFactory* factory, |
| 44 const HostPortProxyPair& host_port_proxy_pair) { | 44 const HostPortProxyPair& host_port_proxy_pair) { |
| 45 return factory->GetOrCreateCryptoConfig(host_port_proxy_pair); | 45 return factory->GetOrCreateCryptoConfig(host_port_proxy_pair); |
| 46 } | 46 } |
| 47 | 47 |
| 48 static bool HasActiveSession(QuicStreamFactory* factory, | 48 static bool HasActiveSession(QuicStreamFactory* factory, |
| 49 const HostPortProxyPair& host_port_proxy_pair) { | 49 const HostPortProxyPair& host_port_proxy_pair, |
| 50 return factory->HasActiveSession(host_port_proxy_pair); | 50 bool is_https) { |
| 51 QuicStreamFactory::SessionKey session_key(host_port_proxy_pair, is_https); | |
| 52 return factory->HasActiveSession(session_key); | |
| 51 } | 53 } |
| 52 | 54 |
| 53 static QuicClientSession* GetActiveSession( | 55 static QuicClientSession* GetActiveSession( |
| 54 QuicStreamFactory* factory, | 56 QuicStreamFactory* factory, |
| 55 const HostPortProxyPair& host_port_proxy_pair) { | 57 const HostPortProxyPair& host_port_proxy_pair, |
| 56 DCHECK(factory->HasActiveSession(host_port_proxy_pair)); | 58 bool is_https) { |
| 57 return factory->active_sessions_[host_port_proxy_pair]; | 59 QuicStreamFactory::SessionKey session_key(host_port_proxy_pair, is_https); |
| 60 DCHECK(factory->HasActiveSession(session_key)); | |
| 61 return factory->active_sessions_[session_key]; | |
| 62 } | |
| 63 | |
| 64 static scoped_ptr<QuicHttpStream> CreateIfSessionExists( | |
| 65 QuicStreamFactory* factory, | |
| 66 const HostPortProxyPair& host_port_proxy_pair, | |
| 67 bool is_https, | |
| 68 const BoundNetLog& net_log) { | |
| 69 QuicStreamFactory::SessionKey session_key(host_port_proxy_pair, is_https); | |
| 70 return factory->CreateIfSessionExists(session_key, net_log); | |
| 58 } | 71 } |
| 59 | 72 |
| 60 static bool IsLiveSession(QuicStreamFactory* factory, | 73 static bool IsLiveSession(QuicStreamFactory* factory, |
| 61 QuicClientSession* session) { | 74 QuicClientSession* session) { |
| 62 for (QuicStreamFactory::SessionSet::iterator it = | 75 for (QuicStreamFactory::SessionSet::iterator it = |
| 63 factory->all_sessions_.begin(); | 76 factory->all_sessions_.begin(); |
| 64 it != factory->all_sessions_.end(); ++it) { | 77 it != factory->all_sessions_.end(); ++it) { |
| 65 if (*it == session) | 78 if (*it == session) |
| 66 return true; | 79 return true; |
| 67 } | 80 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 81 &random_generator_, clock_, kDefaultMaxPacketSize, | 94 &random_generator_, clock_, kDefaultMaxPacketSize, |
| 82 SupportedVersions(GetParam()), true, true), | 95 SupportedVersions(GetParam()), true, true), |
| 83 host_port_proxy_pair_(HostPortPair(kDefaultServerHostName, | 96 host_port_proxy_pair_(HostPortPair(kDefaultServerHostName, |
| 84 kDefaultServerPort), | 97 kDefaultServerPort), |
| 85 ProxyServer::Direct()), | 98 ProxyServer::Direct()), |
| 86 is_https_(false), | 99 is_https_(false), |
| 87 cert_verifier_(CertVerifier::CreateDefault()) { | 100 cert_verifier_(CertVerifier::CreateDefault()) { |
| 88 factory_.set_require_confirmation(false); | 101 factory_.set_require_confirmation(false); |
| 89 } | 102 } |
| 90 | 103 |
| 104 scoped_ptr<QuicHttpStream> CreateIfSessionExists( | |
| 105 const HostPortProxyPair& host_port_proxy_pair, | |
| 106 const BoundNetLog& net_log) { | |
| 107 return QuicStreamFactoryPeer::CreateIfSessionExists( | |
| 108 &factory_, host_port_proxy_pair, false, net_log_); | |
| 109 } | |
| 91 | 110 |
| 92 int GetSourcePortForNewSession(const HostPortProxyPair& destination) { | 111 int GetSourcePortForNewSession(const HostPortProxyPair& destination) { |
| 93 return GetSourcePortForNewSessionInner(destination, false); | 112 return GetSourcePortForNewSessionInner(destination, false); |
| 94 } | 113 } |
| 95 | 114 |
| 96 int GetSourcePortForNewSessionAndGoAway( | 115 int GetSourcePortForNewSessionAndGoAway( |
| 97 const HostPortProxyPair& destination) { | 116 const HostPortProxyPair& destination) { |
| 98 return GetSourcePortForNewSessionInner(destination, true); | 117 return GetSourcePortForNewSessionInner(destination, true); |
| 99 } | 118 } |
| 100 | 119 |
| 101 int GetSourcePortForNewSessionInner(const HostPortProxyPair& destination, | 120 int GetSourcePortForNewSessionInner(const HostPortProxyPair& destination, |
| 102 bool goaway_received) { | 121 bool goaway_received) { |
| 103 // Should only be called if there is no active session for this destination. | 122 // Should only be called if there is no active session for this destination. |
| 104 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(destination, | 123 EXPECT_EQ(NULL, CreateIfSessionExists(destination, net_log_).get()); |
| 105 net_log_).get()); | |
| 106 size_t socket_count = socket_factory_.udp_client_sockets().size(); | 124 size_t socket_count = socket_factory_.udp_client_sockets().size(); |
| 107 | 125 |
| 108 MockRead reads[] = { | 126 MockRead reads[] = { |
| 109 MockRead(ASYNC, OK, 0) // EOF | 127 MockRead(ASYNC, OK, 0) // EOF |
| 110 }; | 128 }; |
| 111 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); | 129 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 112 socket_data.StopAfter(1); | 130 socket_data.StopAfter(1); |
| 113 socket_factory_.AddSocketDataProvider(&socket_data); | 131 socket_factory_.AddSocketDataProvider(&socket_data); |
| 114 | 132 |
| 115 QuicStreamRequest request(&factory_); | 133 QuicStreamRequest request(&factory_); |
| 116 EXPECT_EQ(ERR_IO_PENDING, | 134 EXPECT_EQ(ERR_IO_PENDING, |
| 117 request.Request(destination, | 135 request.Request(destination, |
| 118 is_https_, | 136 is_https_, |
| 119 "GET", | 137 "GET", |
| 120 cert_verifier_.get(), | 138 cert_verifier_.get(), |
| 121 net_log_, | 139 net_log_, |
| 122 callback_.callback())); | 140 callback_.callback())); |
| 123 | 141 |
| 124 EXPECT_EQ(OK, callback_.WaitForResult()); | 142 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 125 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 143 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 126 EXPECT_TRUE(stream.get()); | 144 EXPECT_TRUE(stream.get()); |
| 127 stream.reset(); | 145 stream.reset(); |
| 128 | 146 |
| 129 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( | 147 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( |
| 130 &factory_, destination); | 148 &factory_, destination, is_https_); |
| 131 | 149 |
| 132 if (socket_count + 1 != socket_factory_.udp_client_sockets().size()) { | 150 if (socket_count + 1 != socket_factory_.udp_client_sockets().size()) { |
| 133 EXPECT_TRUE(false); | 151 EXPECT_TRUE(false); |
| 134 return 0; | 152 return 0; |
| 135 } | 153 } |
| 136 | 154 |
| 137 IPEndPoint endpoint; | 155 IPEndPoint endpoint; |
| 138 socket_factory_. | 156 socket_factory_. |
| 139 udp_client_sockets()[socket_count]->GetLocalAddress(&endpoint); | 157 udp_client_sockets()[socket_count]->GetLocalAddress(&endpoint); |
| 140 int port = endpoint.port(); | 158 int port = endpoint.port(); |
| 141 if (goaway_received) { | 159 if (goaway_received) { |
| 142 QuicGoAwayFrame goaway(QUIC_NO_ERROR, 1, ""); | 160 QuicGoAwayFrame goaway(QUIC_NO_ERROR, 1, ""); |
| 143 session->OnGoAway(goaway); | 161 session->OnGoAway(goaway); |
| 144 } | 162 } |
| 145 | 163 |
| 146 factory_.OnSessionClosed(session); | 164 factory_.OnSessionClosed(session); |
| 147 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(destination, | 165 EXPECT_EQ(NULL, CreateIfSessionExists(destination, net_log_).get()); |
| 148 net_log_).get()); | |
| 149 EXPECT_TRUE(socket_data.at_read_eof()); | 166 EXPECT_TRUE(socket_data.at_read_eof()); |
| 150 EXPECT_TRUE(socket_data.at_write_eof()); | 167 EXPECT_TRUE(socket_data.at_write_eof()); |
| 151 return port; | 168 return port; |
| 152 } | 169 } |
| 153 | 170 |
| 154 scoped_ptr<QuicEncryptedPacket> ConstructRstPacket() { | 171 scoped_ptr<QuicEncryptedPacket> ConstructRstPacket() { |
| 155 QuicStreamId stream_id = 5; | 172 QuicStreamId stream_id = 5; |
| 156 return maker_.MakeRstPacket(1, true, stream_id, QUIC_STREAM_NO_ERROR); | 173 return maker_.MakeRstPacket(1, true, stream_id, QUIC_STREAM_NO_ERROR); |
| 157 } | 174 } |
| 158 | 175 |
| 159 MockHostResolver host_resolver_; | 176 MockHostResolver host_resolver_; |
| 160 DeterministicMockClientSocketFactory socket_factory_; | 177 DeterministicMockClientSocketFactory socket_factory_; |
| 161 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 178 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
| 162 MockRandom random_generator_; | 179 MockRandom random_generator_; |
| 163 QuicTestPacketMaker maker_; | 180 QuicTestPacketMaker maker_; |
| 164 MockClock* clock_; // Owned by factory_. | 181 MockClock* clock_; // Owned by factory_. |
| 165 QuicStreamFactory factory_; | 182 QuicStreamFactory factory_; |
| 166 HostPortProxyPair host_port_proxy_pair_; | 183 HostPortProxyPair host_port_proxy_pair_; |
| 167 bool is_https_; | 184 bool is_https_; |
| 168 scoped_ptr<CertVerifier> cert_verifier_; | 185 scoped_ptr<CertVerifier> cert_verifier_; |
| 169 BoundNetLog net_log_; | 186 BoundNetLog net_log_; |
| 170 TestCompletionCallback callback_; | 187 TestCompletionCallback callback_; |
| 171 }; | 188 }; |
| 172 | 189 |
| 173 INSTANTIATE_TEST_CASE_P(Version, QuicStreamFactoryTest, | 190 INSTANTIATE_TEST_CASE_P(Version, QuicStreamFactoryTest, |
| 174 ::testing::ValuesIn(QuicSupportedVersions())); | 191 ::testing::ValuesIn(QuicSupportedVersions())); |
| 175 | 192 |
| 176 TEST_P(QuicStreamFactoryTest, CreateIfSessionExists) { | 193 TEST_P(QuicStreamFactoryTest, CreateIfSessionExists) { |
| 177 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(host_port_proxy_pair_, | 194 EXPECT_EQ(NULL, CreateIfSessionExists(host_port_proxy_pair_, net_log_).get()); |
| 178 net_log_).get()); | |
| 179 } | 195 } |
| 180 | 196 |
| 181 TEST_P(QuicStreamFactoryTest, Create) { | 197 TEST_P(QuicStreamFactoryTest, Create) { |
| 182 MockRead reads[] = { | 198 MockRead reads[] = { |
| 183 MockRead(ASYNC, OK, 0) // EOF | 199 MockRead(ASYNC, OK, 0) // EOF |
| 184 }; | 200 }; |
| 185 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); | 201 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 186 socket_factory_.AddSocketDataProvider(&socket_data); | 202 socket_factory_.AddSocketDataProvider(&socket_data); |
| 187 socket_data.StopAfter(1); | 203 socket_data.StopAfter(1); |
| 188 | 204 |
| 189 QuicStreamRequest request(&factory_); | 205 QuicStreamRequest request(&factory_); |
| 190 EXPECT_EQ(ERR_IO_PENDING, | 206 EXPECT_EQ(ERR_IO_PENDING, |
| 191 request.Request(host_port_proxy_pair_, | 207 request.Request(host_port_proxy_pair_, |
| 192 is_https_, | 208 is_https_, |
| 193 "GET", | 209 "GET", |
| 194 cert_verifier_.get(), | 210 cert_verifier_.get(), |
| 195 net_log_, | 211 net_log_, |
| 196 callback_.callback())); | 212 callback_.callback())); |
| 197 | 213 |
| 198 EXPECT_EQ(OK, callback_.WaitForResult()); | 214 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 199 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 215 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 200 EXPECT_TRUE(stream.get()); | 216 EXPECT_TRUE(stream.get()); |
| 201 | 217 |
| 202 // Will reset stream 3. | 218 // Will reset stream 3. |
| 203 stream = factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_); | 219 stream = CreateIfSessionExists(host_port_proxy_pair_, net_log_); |
| 204 EXPECT_TRUE(stream.get()); | 220 EXPECT_TRUE(stream.get()); |
| 205 | 221 |
| 206 // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result | 222 // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result |
| 207 // in streams on different sessions. | 223 // in streams on different sessions. |
| 208 QuicStreamRequest request2(&factory_); | 224 QuicStreamRequest request2(&factory_); |
| 209 EXPECT_EQ(OK, | 225 EXPECT_EQ(OK, |
| 210 request2.Request(host_port_proxy_pair_, | 226 request2.Request(host_port_proxy_pair_, |
| 211 is_https_, | 227 is_https_, |
| 212 "GET", | 228 "GET", |
| 213 cert_verifier_.get(), | 229 cert_verifier_.get(), |
| 214 net_log_, | 230 net_log_, |
| 215 callback_.callback())); | 231 callback_.callback())); |
| 216 stream = request2.ReleaseStream(); // Will reset stream 5. | 232 stream = request2.ReleaseStream(); // Will reset stream 5. |
| 217 stream.reset(); // Will reset stream 7. | 233 stream.reset(); // Will reset stream 7. |
| 218 | 234 |
| 219 EXPECT_TRUE(socket_data.at_read_eof()); | 235 EXPECT_TRUE(socket_data.at_read_eof()); |
| 220 EXPECT_TRUE(socket_data.at_write_eof()); | 236 EXPECT_TRUE(socket_data.at_write_eof()); |
| 221 } | 237 } |
| 222 | 238 |
| 239 TEST_P(QuicStreamFactoryTest, CreateHttpVsHttps) { | |
| 240 MockRead reads[] = { | |
| 241 MockRead(ASYNC, OK, 0) // EOF | |
| 242 }; | |
| 243 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); | |
| 244 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); | |
| 245 socket_factory_.AddSocketDataProvider(&socket_data1); | |
| 246 socket_factory_.AddSocketDataProvider(&socket_data2); | |
| 247 socket_data1.StopAfter(1); | |
| 248 socket_data2.StopAfter(1); | |
| 249 | |
| 250 QuicStreamRequest request(&factory_); | |
| 251 EXPECT_EQ(ERR_IO_PENDING, | |
| 252 request.Request(host_port_proxy_pair_, | |
| 253 is_https_, | |
| 254 "GET", | |
| 255 cert_verifier_.get(), | |
| 256 net_log_, | |
| 257 callback_.callback())); | |
| 258 | |
| 259 EXPECT_EQ(OK, callback_.WaitForResult()); | |
| 260 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | |
| 261 EXPECT_TRUE(stream.get()); | |
| 262 | |
| 263 QuicStreamRequest request2(&factory_); | |
| 264 EXPECT_EQ(ERR_IO_PENDING, | |
| 265 request2.Request(host_port_proxy_pair_, | |
| 266 !is_https_, | |
| 267 "GET", | |
| 268 cert_verifier_.get(), | |
| 269 net_log_, | |
| 270 callback_.callback())); | |
| 271 EXPECT_EQ(OK, callback_.WaitForResult()); | |
| 272 stream = request2.ReleaseStream(); | |
| 273 EXPECT_TRUE(stream.get()); | |
| 274 stream.reset(); | |
| 275 | |
| 276 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( | |
| 277 &factory_, host_port_proxy_pair_, is_https_), | |
| 278 QuicStreamFactoryPeer::GetActiveSession( | |
| 279 &factory_, host_port_proxy_pair_, !is_https_)); | |
| 280 | |
| 281 EXPECT_TRUE(socket_data1.at_read_eof()); | |
| 282 EXPECT_TRUE(socket_data1.at_write_eof()); | |
| 283 EXPECT_TRUE(socket_data2.at_read_eof()); | |
| 284 EXPECT_TRUE(socket_data2.at_write_eof()); | |
| 285 } | |
| 286 | |
| 223 TEST_P(QuicStreamFactoryTest, Pooling) { | 287 TEST_P(QuicStreamFactoryTest, Pooling) { |
| 224 MockRead reads[] = { | 288 MockRead reads[] = { |
| 225 MockRead(ASYNC, OK, 0) // EOF | 289 MockRead(ASYNC, OK, 0) // EOF |
| 226 }; | 290 }; |
| 227 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); | 291 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 228 socket_factory_.AddSocketDataProvider(&socket_data); | 292 socket_factory_.AddSocketDataProvider(&socket_data); |
| 229 socket_data.StopAfter(1); | 293 socket_data.StopAfter(1); |
| 230 | 294 |
| 231 HostPortProxyPair server2 = HostPortProxyPair( | 295 HostPortProxyPair server2 = HostPortProxyPair( |
| 232 HostPortPair("mail.google.com", kDefaultServerPort), | 296 HostPortPair("mail.google.com", kDefaultServerPort), |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 255 request2.Request(server2, | 319 request2.Request(server2, |
| 256 is_https_, | 320 is_https_, |
| 257 "GET", | 321 "GET", |
| 258 cert_verifier_.get(), | 322 cert_verifier_.get(), |
| 259 net_log_, | 323 net_log_, |
| 260 callback.callback())); | 324 callback.callback())); |
| 261 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 325 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 262 EXPECT_TRUE(stream2.get()); | 326 EXPECT_TRUE(stream2.get()); |
| 263 | 327 |
| 264 EXPECT_EQ( | 328 EXPECT_EQ( |
| 265 QuicStreamFactoryPeer::GetActiveSession(&factory_, host_port_proxy_pair_), | 329 QuicStreamFactoryPeer::GetActiveSession( |
| 266 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2)); | 330 &factory_, host_port_proxy_pair_, is_https_), |
| 331 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_)); | |
| 267 | 332 |
| 268 EXPECT_TRUE(socket_data.at_read_eof()); | 333 EXPECT_TRUE(socket_data.at_read_eof()); |
| 269 EXPECT_TRUE(socket_data.at_write_eof()); | 334 EXPECT_TRUE(socket_data.at_write_eof()); |
| 270 } | 335 } |
| 271 | 336 |
| 272 TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) { | 337 TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) { |
| 273 MockRead reads[] = { | 338 MockRead reads[] = { |
| 274 MockRead(ASYNC, OK, 0) // EOF | 339 MockRead(ASYNC, OK, 0) // EOF |
| 275 }; | 340 }; |
| 276 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); | 341 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 306 EXPECT_EQ(OK, | 371 EXPECT_EQ(OK, |
| 307 request2.Request(server2, | 372 request2.Request(server2, |
| 308 is_https_, | 373 is_https_, |
| 309 "GET", | 374 "GET", |
| 310 cert_verifier_.get(), | 375 cert_verifier_.get(), |
| 311 net_log_, | 376 net_log_, |
| 312 callback.callback())); | 377 callback.callback())); |
| 313 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 378 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 314 EXPECT_TRUE(stream2.get()); | 379 EXPECT_TRUE(stream2.get()); |
| 315 | 380 |
| 316 factory_.OnSessionGoingAway( | 381 factory_.OnSessionGoingAway(QuicStreamFactoryPeer::GetActiveSession( |
| 317 QuicStreamFactoryPeer::GetActiveSession(&factory_, | 382 &factory_, host_port_proxy_pair_, is_https_)); |
|
ramant (doing other things)
2014/03/07 23:42:56
nit: 4 spaces indentation on line# 382
Ryan Hamilton
2014/03/08 00:58:34
Done.
| |
| 318 host_port_proxy_pair_)); | 383 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
| 319 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(&factory_, | 384 &factory_, host_port_proxy_pair_, is_https_)); |
| 320 host_port_proxy_pair_)); | 385 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
| 321 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(&factory_, server2)); | 386 &factory_, server2, is_https_)); |
| 322 | 387 |
| 323 TestCompletionCallback callback3; | 388 TestCompletionCallback callback3; |
| 324 QuicStreamRequest request3(&factory_); | 389 QuicStreamRequest request3(&factory_); |
| 325 EXPECT_EQ(OK, | 390 EXPECT_EQ(OK, |
| 326 request3.Request(server2, | 391 request3.Request(server2, |
| 327 is_https_, | 392 is_https_, |
| 328 "GET", | 393 "GET", |
| 329 cert_verifier_.get(), | 394 cert_verifier_.get(), |
| 330 net_log_, | 395 net_log_, |
| 331 callback3.callback())); | 396 callback3.callback())); |
| 332 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream(); | 397 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream(); |
| 333 EXPECT_TRUE(stream3.get()); | 398 EXPECT_TRUE(stream3.get()); |
| 334 | 399 |
| 335 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_, server2)); | 400 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession( |
| 401 &factory_, server2, is_https_)); | |
| 336 | 402 |
| 337 EXPECT_TRUE(socket_data1.at_read_eof()); | 403 EXPECT_TRUE(socket_data1.at_read_eof()); |
| 338 EXPECT_TRUE(socket_data1.at_write_eof()); | 404 EXPECT_TRUE(socket_data1.at_write_eof()); |
| 339 EXPECT_TRUE(socket_data2.at_read_eof()); | 405 EXPECT_TRUE(socket_data2.at_read_eof()); |
| 340 EXPECT_TRUE(socket_data2.at_write_eof()); | 406 EXPECT_TRUE(socket_data2.at_write_eof()); |
| 341 } | 407 } |
| 342 | 408 |
| 343 TEST_P(QuicStreamFactoryTest, HttpsPooling) { | 409 TEST_P(QuicStreamFactoryTest, HttpsPooling) { |
| 344 MockRead reads[] = { | 410 MockRead reads[] = { |
| 345 MockRead(ASYNC, OK, 0) // EOF | 411 MockRead(ASYNC, OK, 0) // EOF |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 EXPECT_EQ(OK, | 454 EXPECT_EQ(OK, |
| 389 request2.Request(server2, | 455 request2.Request(server2, |
| 390 is_https_, | 456 is_https_, |
| 391 "GET", | 457 "GET", |
| 392 cert_verifier_.get(), | 458 cert_verifier_.get(), |
| 393 net_log_, | 459 net_log_, |
| 394 callback_.callback())); | 460 callback_.callback())); |
| 395 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 461 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 396 EXPECT_TRUE(stream2.get()); | 462 EXPECT_TRUE(stream2.get()); |
| 397 | 463 |
| 398 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession(&factory_, server1), | 464 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession( |
| 399 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2)); | 465 &factory_, server1, is_https_), |
| 466 QuicStreamFactoryPeer::GetActiveSession( | |
| 467 &factory_, server2, is_https_)); | |
| 400 | 468 |
| 401 EXPECT_TRUE(socket_data.at_read_eof()); | 469 EXPECT_TRUE(socket_data.at_read_eof()); |
| 402 EXPECT_TRUE(socket_data.at_write_eof()); | 470 EXPECT_TRUE(socket_data.at_write_eof()); |
| 403 } | 471 } |
| 404 | 472 |
| 405 TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithCertMismatch) { | 473 TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithCertMismatch) { |
| 406 MockRead reads[] = { | 474 MockRead reads[] = { |
| 407 MockRead(ASYNC, OK, 0) // EOF | 475 MockRead(ASYNC, OK, 0) // EOF |
| 408 }; | 476 }; |
| 409 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); | 477 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 454 EXPECT_EQ(OK, | 522 EXPECT_EQ(OK, |
| 455 request2.Request(server2, | 523 request2.Request(server2, |
| 456 is_https_, | 524 is_https_, |
| 457 "GET", | 525 "GET", |
| 458 cert_verifier_.get(), | 526 cert_verifier_.get(), |
| 459 net_log_, | 527 net_log_, |
| 460 callback_.callback())); | 528 callback_.callback())); |
| 461 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 529 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 462 EXPECT_TRUE(stream2.get()); | 530 EXPECT_TRUE(stream2.get()); |
| 463 | 531 |
| 464 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(&factory_, server1), | 532 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( |
| 465 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2)); | 533 &factory_, server1, is_https_), |
| 534 QuicStreamFactoryPeer::GetActiveSession( | |
| 535 &factory_, server2, is_https_)); | |
| 466 | 536 |
| 467 EXPECT_TRUE(socket_data1.at_read_eof()); | 537 EXPECT_TRUE(socket_data1.at_read_eof()); |
| 468 EXPECT_TRUE(socket_data1.at_write_eof()); | 538 EXPECT_TRUE(socket_data1.at_write_eof()); |
| 469 EXPECT_TRUE(socket_data2.at_read_eof()); | 539 EXPECT_TRUE(socket_data2.at_read_eof()); |
| 470 EXPECT_TRUE(socket_data2.at_write_eof()); | 540 EXPECT_TRUE(socket_data2.at_write_eof()); |
| 471 } | 541 } |
| 472 | 542 |
| 473 TEST_P(QuicStreamFactoryTest, Goaway) { | 543 TEST_P(QuicStreamFactoryTest, Goaway) { |
| 474 MockRead reads[] = { | 544 MockRead reads[] = { |
| 475 MockRead(ASYNC, OK, 0) // EOF | 545 MockRead(ASYNC, OK, 0) // EOF |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 490 net_log_, | 560 net_log_, |
| 491 callback_.callback())); | 561 callback_.callback())); |
| 492 | 562 |
| 493 EXPECT_EQ(OK, callback_.WaitForResult()); | 563 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 494 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 564 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 495 EXPECT_TRUE(stream.get()); | 565 EXPECT_TRUE(stream.get()); |
| 496 | 566 |
| 497 // Mark the session as going away. Ensure that while it is still alive | 567 // Mark the session as going away. Ensure that while it is still alive |
| 498 // that it is no longer active. | 568 // that it is no longer active. |
| 499 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( | 569 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( |
| 500 &factory_, host_port_proxy_pair_); | 570 &factory_, host_port_proxy_pair_, is_https_); |
| 501 factory_.OnSessionGoingAway(session); | 571 factory_.OnSessionGoingAway(session); |
| 502 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); | 572 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); |
| 503 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(&factory_, | 573 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
| 504 host_port_proxy_pair_)); | 574 &factory_, host_port_proxy_pair_, is_https_)); |
| 505 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(host_port_proxy_pair_, | 575 EXPECT_EQ(NULL, CreateIfSessionExists(host_port_proxy_pair_, net_log_).get()); |
| 506 net_log_).get()); | |
| 507 | 576 |
| 508 // Create a new request for the same destination and verify that a | 577 // Create a new request for the same destination and verify that a |
| 509 // new session is created. | 578 // new session is created. |
| 510 QuicStreamRequest request2(&factory_); | 579 QuicStreamRequest request2(&factory_); |
| 511 EXPECT_EQ(ERR_IO_PENDING, | 580 EXPECT_EQ(ERR_IO_PENDING, |
| 512 request2.Request(host_port_proxy_pair_, | 581 request2.Request(host_port_proxy_pair_, |
| 513 is_https_, | 582 is_https_, |
| 514 "GET", | 583 "GET", |
| 515 cert_verifier_.get(), | 584 cert_verifier_.get(), |
| 516 net_log_, | 585 net_log_, |
| 517 callback_.callback())); | 586 callback_.callback())); |
| 518 EXPECT_EQ(OK, callback_.WaitForResult()); | 587 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 519 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 588 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 520 EXPECT_TRUE(stream2.get()); | 589 EXPECT_TRUE(stream2.get()); |
| 521 | 590 |
| 522 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_, | 591 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_, |
| 523 host_port_proxy_pair_)); | 592 host_port_proxy_pair_, |
| 593 is_https_)); | |
| 524 EXPECT_NE(session, | 594 EXPECT_NE(session, |
| 525 QuicStreamFactoryPeer::GetActiveSession( | 595 QuicStreamFactoryPeer::GetActiveSession( |
| 526 &factory_, host_port_proxy_pair_)); | 596 &factory_, host_port_proxy_pair_, is_https_)); |
| 527 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); | 597 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); |
| 528 | 598 |
| 529 stream2.reset(); | 599 stream2.reset(); |
| 530 stream.reset(); | 600 stream.reset(); |
| 531 | 601 |
| 532 EXPECT_TRUE(socket_data.at_read_eof()); | 602 EXPECT_TRUE(socket_data.at_read_eof()); |
| 533 EXPECT_TRUE(socket_data.at_write_eof()); | 603 EXPECT_TRUE(socket_data.at_write_eof()); |
| 534 EXPECT_TRUE(socket_data2.at_read_eof()); | 604 EXPECT_TRUE(socket_data2.at_read_eof()); |
| 535 EXPECT_TRUE(socket_data2.at_write_eof()); | 605 EXPECT_TRUE(socket_data2.at_write_eof()); |
| 536 } | 606 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 cert_verifier_.get(), | 728 cert_verifier_.get(), |
| 659 net_log_, | 729 net_log_, |
| 660 callback_.callback())); | 730 callback_.callback())); |
| 661 } | 731 } |
| 662 | 732 |
| 663 socket_data.StopAfter(1); | 733 socket_data.StopAfter(1); |
| 664 base::RunLoop run_loop; | 734 base::RunLoop run_loop; |
| 665 run_loop.RunUntilIdle(); | 735 run_loop.RunUntilIdle(); |
| 666 | 736 |
| 667 scoped_ptr<QuicHttpStream> stream( | 737 scoped_ptr<QuicHttpStream> stream( |
| 668 factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_)); | 738 CreateIfSessionExists(host_port_proxy_pair_, net_log_)); |
| 669 EXPECT_TRUE(stream.get()); | 739 EXPECT_TRUE(stream.get()); |
| 670 stream.reset(); | 740 stream.reset(); |
| 671 | 741 |
| 672 EXPECT_TRUE(socket_data.at_read_eof()); | 742 EXPECT_TRUE(socket_data.at_read_eof()); |
| 673 EXPECT_TRUE(socket_data.at_write_eof()); | 743 EXPECT_TRUE(socket_data.at_write_eof()); |
| 674 } | 744 } |
| 675 | 745 |
| 676 TEST_P(QuicStreamFactoryTest, CreateConsistentEphemeralPort) { | 746 TEST_P(QuicStreamFactoryTest, CreateConsistentEphemeralPort) { |
| 677 // Sequentially connect to the default host, then another host, and then the | 747 // Sequentially connect to the default host, then another host, and then the |
| 678 // default host. Verify that the default host gets a consistent ephemeral | 748 // default host. Verify that the default host gets a consistent ephemeral |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1036 QuicCryptoClientConfig::CachedState* cached2 = | 1106 QuicCryptoClientConfig::CachedState* cached2 = |
| 1037 crypto_config2->LookupOrCreate(host_port_proxy_pair2.first.host()); | 1107 crypto_config2->LookupOrCreate(host_port_proxy_pair2.first.host()); |
| 1038 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); | 1108 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
| 1039 EXPECT_TRUE(cached2->source_address_token().empty()); | 1109 EXPECT_TRUE(cached2->source_address_token().empty()); |
| 1040 EXPECT_FALSE(cached2->proof_valid()); | 1110 EXPECT_FALSE(cached2->proof_valid()); |
| 1041 } | 1111 } |
| 1042 } | 1112 } |
| 1043 | 1113 |
| 1044 } // namespace test | 1114 } // namespace test |
| 1045 } // namespace net | 1115 } // namespace net |
| OLD | NEW |