OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
7 #include "net/spdy/spdy_io_buffer.h" | 7 #include "net/spdy/spdy_io_buffer.h" |
8 #include "net/spdy/spdy_stream.h" | 8 #include "net/spdy/spdy_stream.h" |
9 #include "net/spdy/spdy_test_util.h" | 9 #include "net/spdy/spdy_test_util.h" |
10 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 BoundNetLog(), | 229 BoundNetLog(), |
230 &stream_releaser)); | 230 &stream_releaser)); |
231 | 231 |
232 // Make sure |stream_releaser| holds the last refs. | 232 // Make sure |stream_releaser| holds the last refs. |
233 session = NULL; | 233 session = NULL; |
234 spdy_stream1 = NULL; | 234 spdy_stream1 = NULL; |
235 | 235 |
236 EXPECT_EQ(OK, stream_releaser.WaitForResult()); | 236 EXPECT_EQ(OK, stream_releaser.WaitForResult()); |
237 } | 237 } |
238 | 238 |
| 239 // Start with max concurrent streams set to 1. Request two streams. When the |
| 240 // first completes, have the callback close itself, which should trigger the |
| 241 // second stream creation. Then cancel that one immediately. Don't crash. |
| 242 // http://crbug.com/63532 |
| 243 TEST_F(SpdySessionTest, CancelPendingCreateStream) { |
| 244 SpdySessionDependencies session_deps; |
| 245 session_deps.host_resolver->set_synchronous_mode(true); |
| 246 |
| 247 // Set up the socket so we read a SETTINGS frame that raises max concurrent |
| 248 // streams to 2. |
| 249 MockRead reads[] = { |
| 250 MockRead(false, ERR_IO_PENDING) // Stall forever. |
| 251 }; |
| 252 |
| 253 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 254 MockConnect connect_data(false, OK); |
| 255 |
| 256 data.set_connect_data(connect_data); |
| 257 session_deps.socket_factory->AddSocketDataProvider(&data); |
| 258 |
| 259 SSLSocketDataProvider ssl(false, OK); |
| 260 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 261 |
| 262 scoped_refptr<HttpNetworkSession> http_session( |
| 263 SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| 264 |
| 265 const std::string kTestHost("www.foo.com"); |
| 266 const int kTestPort = 80; |
| 267 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 268 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
| 269 |
| 270 // Initialize the SpdySettingsStorage with 1 max concurrent streams. |
| 271 spdy::SpdySettings settings; |
| 272 spdy::SettingsFlagsAndId id(spdy::SETTINGS_MAX_CONCURRENT_STREAMS); |
| 273 id.set_id(spdy::SETTINGS_MAX_CONCURRENT_STREAMS); |
| 274 id.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); |
| 275 settings.push_back(spdy::SpdySetting(id, 1)); |
| 276 http_session->mutable_spdy_settings()->Set(test_host_port_pair, settings); |
| 277 |
| 278 // Create a session. |
| 279 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
| 280 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
| 281 scoped_refptr<SpdySession> session = |
| 282 spdy_session_pool->Get(pair, http_session->mutable_spdy_settings(), |
| 283 BoundNetLog()); |
| 284 ASSERT_TRUE(spdy_session_pool->HasSession(pair)); |
| 285 |
| 286 scoped_refptr<TCPSocketParams> tcp_params( |
| 287 new TCPSocketParams(kTestHost, kTestPort, MEDIUM, GURL(), false)); |
| 288 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 289 EXPECT_EQ(OK, |
| 290 connection->Init(test_host_port_pair.ToString(), tcp_params, MEDIUM, |
| 291 NULL, http_session->tcp_socket_pool(), |
| 292 BoundNetLog())); |
| 293 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 294 |
| 295 // Use scoped_ptr to let us invalidate the memory when we want to, to trigger |
| 296 // a valgrind error if the callback is invoked when it's not supposed to be. |
| 297 scoped_ptr<TestCompletionCallback> callback(new TestCompletionCallback); |
| 298 |
| 299 // Create 2 streams. First will succeed. Second will be pending. |
| 300 scoped_refptr<SpdyStream> spdy_stream1; |
| 301 GURL url("http://www.google.com"); |
| 302 ASSERT_EQ(OK, |
| 303 session->CreateStream(url, |
| 304 MEDIUM, /* priority, not important */ |
| 305 &spdy_stream1, |
| 306 BoundNetLog(), |
| 307 callback.get())); |
| 308 |
| 309 scoped_refptr<SpdyStream> spdy_stream2; |
| 310 ASSERT_EQ(ERR_IO_PENDING, |
| 311 session->CreateStream(url, |
| 312 MEDIUM, /* priority, not important */ |
| 313 &spdy_stream2, |
| 314 BoundNetLog(), |
| 315 callback.get())); |
| 316 |
| 317 // Release the first one, this will allow the second to be created. |
| 318 spdy_stream1->Cancel(); |
| 319 spdy_stream1 = NULL; |
| 320 |
| 321 session->CancelPendingCreateStreams(&spdy_stream2); |
| 322 callback.reset(); |
| 323 |
| 324 // Should not crash when running the pending callback. |
| 325 MessageLoop::current()->RunAllPending(); |
| 326 } |
| 327 |
239 } // namespace | 328 } // namespace |
240 | 329 |
241 } // namespace net | 330 } // namespace net |
OLD | NEW |