Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: net/spdy/spdy_session_spdy2_unittest.cc

Issue 10829066: Fix a SPDY crash bug where a CHECK() is hit because a cancelled stream is considered active by the … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add SPDY/3 test. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/spdy/spdy_session.h" 5 #include "net/spdy/spdy_session.h"
6 6
7 #include "net/base/host_cache.h" 7 #include "net/base/host_cache.h"
8 #include "net/base/ip_endpoint.h" 8 #include "net/base/ip_endpoint.h"
9 #include "net/base/net_log_unittest.h" 9 #include "net/base/net_log_unittest.h"
10 #include "net/spdy/spdy_io_buffer.h" 10 #include "net/spdy/spdy_io_buffer.h"
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 EXPECT_EQ(3u, spdy_stream1->stream_id()); 1273 EXPECT_EQ(3u, spdy_stream1->stream_id());
1274 EXPECT_EQ(1u, spdy_stream2->stream_id()); 1274 EXPECT_EQ(1u, spdy_stream2->stream_id());
1275 1275
1276 spdy_stream1->Cancel(); 1276 spdy_stream1->Cancel();
1277 spdy_stream1 = NULL; 1277 spdy_stream1 = NULL;
1278 1278
1279 spdy_stream2->Cancel(); 1279 spdy_stream2->Cancel();
1280 spdy_stream2 = NULL; 1280 spdy_stream2 = NULL;
1281 } 1281 }
1282 1282
1283 TEST_F(SpdySessionSpdy2Test, CancelStream) {
1284 MockConnect connect_data(SYNCHRONOUS, OK);
1285 // Request 1, at HIGHEST priority, will be cancelled before it writes data.
1286 // Request 2, at LOWEST priority, will be a full request and will be id 1.
1287 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
1288 MockWrite writes[] = {
1289 CreateMockWrite(*req2, 0),
1290 };
1291
1292 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 1));
1293 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(1, true));
1294 MockRead reads[] = {
1295 CreateMockRead(*resp2, 1),
1296 CreateMockRead(*body2, 2),
1297 MockRead(ASYNC, 0, 3) // EOF
1298 };
1299
1300 SpdySessionDependencies session_deps;
1301 session_deps.host_resolver->set_synchronous_mode(true);
1302
1303 DeterministicSocketData data(reads, arraysize(reads),
1304 writes, arraysize(writes));
1305 data.set_connect_data(connect_data);
1306 session_deps.deterministic_socket_factory->AddSocketDataProvider(&data);
1307
1308 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1309 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1310
1311
ramant (doing other things) 2012/07/27 21:43:58 overly nit: consider deleting extra blank line. :-
Ryan Hamilton 2012/07/27 21:51:35 Done.
1312 scoped_refptr<HttpNetworkSession> http_session(
1313 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps));
1314
1315 const std::string kTestHost("www.foo.com");
1316 const int kTestPort = 80;
1317 HostPortPair test_host_port_pair(kTestHost, kTestPort);
1318 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct());
1319
1320 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool());
1321
1322 // Create a session.
1323 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
1324 scoped_refptr<SpdySession> session =
1325 spdy_session_pool->Get(pair, BoundNetLog());
1326 ASSERT_TRUE(spdy_session_pool->HasSession(pair));
1327
1328 scoped_refptr<TransportSocketParams> transport_params(
1329 new TransportSocketParams(test_host_port_pair,
1330 MEDIUM,
1331 false,
1332 false,
1333 OnHostResolutionCallback()));
1334 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
1335 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(),
1336 transport_params, MEDIUM, CompletionCallback(),
1337 http_session->GetTransportSocketPool(
1338 HttpNetworkSession::NORMAL_SOCKET_POOL),
1339 BoundNetLog()));
1340 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
1341
1342 scoped_refptr<SpdyStream> spdy_stream1;
1343 TestCompletionCallback callback1;
1344 GURL url1("http://www.google.com");
1345 EXPECT_EQ(OK, session->CreateStream(url1, HIGHEST, &spdy_stream1,
1346 BoundNetLog(), callback1.callback()));
1347 EXPECT_EQ(0u, spdy_stream1->stream_id());
1348
1349 scoped_refptr<SpdyStream> spdy_stream2;
1350 TestCompletionCallback callback2;
1351 GURL url2("http://www.google.com");
1352 EXPECT_EQ(OK, session->CreateStream(url2, LOWEST, &spdy_stream2,
1353 BoundNetLog(), callback2.callback()));
1354 EXPECT_EQ(0u, spdy_stream2->stream_id());
1355
1356 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
1357 (*headers)["method"] = "GET";
1358 (*headers)["scheme"] = url1.scheme();
1359 (*headers)["host"] = url1.host();
1360 (*headers)["url"] = url1.path();
1361 (*headers)["version"] = "HTTP/1.1";
1362 scoped_ptr<SpdyHeaderBlock> headers2(new SpdyHeaderBlock);
1363 *headers2 = *headers;
1364
1365 spdy_stream1->set_spdy_headers(headers.Pass());
1366 EXPECT_TRUE(spdy_stream1->HasUrl());
1367
1368 spdy_stream2->set_spdy_headers(headers2.Pass());
1369 EXPECT_TRUE(spdy_stream2->HasUrl());
1370
1371 spdy_stream1->SendRequest(false);
1372 spdy_stream2->SendRequest(false);
1373
1374 EXPECT_EQ(0u, spdy_stream1->stream_id());
1375
1376 spdy_stream1->Cancel();
1377
1378 EXPECT_EQ(0u, spdy_stream1->stream_id());
1379
1380 data.RunFor(1);
1381
1382 EXPECT_EQ(0u, spdy_stream1->stream_id());
1383 EXPECT_EQ(1u, spdy_stream2->stream_id());
1384
1385 spdy_stream1 = NULL;
1386 spdy_stream2->Cancel();
1387 spdy_stream2 = NULL;
1388 }
1389
1283 } // namespace net 1390 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698