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

Side by Side Diff: net/spdy/spdy_session_spdy3_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 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 EXPECT_EQ(3u, spdy_stream1->stream_id()); 1443 EXPECT_EQ(3u, spdy_stream1->stream_id());
1444 EXPECT_EQ(1u, spdy_stream2->stream_id()); 1444 EXPECT_EQ(1u, spdy_stream2->stream_id());
1445 1445
1446 spdy_stream1->Cancel(); 1446 spdy_stream1->Cancel();
1447 spdy_stream1 = NULL; 1447 spdy_stream1 = NULL;
1448 1448
1449 spdy_stream2->Cancel(); 1449 spdy_stream2->Cancel();
1450 spdy_stream2 = NULL; 1450 spdy_stream2 = NULL;
1451 } 1451 }
1452 1452
1453 TEST_F(SpdySessionSpdy3Test, CancelStream) {
1454 MockConnect connect_data(SYNCHRONOUS, OK);
1455 // Request 1, at HIGHEST priority, will be cancelled before it writes data.
1456 // Request 2, at LOWEST priority, will be a full request and will be id 1.
1457 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
1458 MockWrite writes[] = {
1459 CreateMockWrite(*req2, 0),
1460 };
1461
1462 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 1));
1463 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(1, true));
1464 MockRead reads[] = {
1465 CreateMockRead(*resp2, 1),
1466 CreateMockRead(*body2, 2),
1467 MockRead(ASYNC, 0, 3) // EOF
1468 };
1469
1470 SpdySessionDependencies session_deps;
1471 session_deps.host_resolver->set_synchronous_mode(true);
1472
1473 DeterministicSocketData data(reads, arraysize(reads),
1474 writes, arraysize(writes));
1475 data.set_connect_data(connect_data);
1476 session_deps.deterministic_socket_factory->AddSocketDataProvider(&data);
1477
1478 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1479 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1480
1481
1482 scoped_refptr<HttpNetworkSession> http_session(
1483 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps));
1484
1485 const std::string kTestHost("www.foo.com");
1486 const int kTestPort = 80;
1487 HostPortPair test_host_port_pair(kTestHost, kTestPort);
1488 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct());
1489
1490 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool());
1491
1492 // Create a session.
1493 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
1494 scoped_refptr<SpdySession> session =
1495 spdy_session_pool->Get(pair, BoundNetLog());
1496 ASSERT_TRUE(spdy_session_pool->HasSession(pair));
1497
1498 scoped_refptr<TransportSocketParams> transport_params(
1499 new TransportSocketParams(test_host_port_pair,
1500 MEDIUM,
1501 false,
1502 false,
1503 OnHostResolutionCallback()));
1504 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
1505 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(),
1506 transport_params, MEDIUM, CompletionCallback(),
1507 http_session->GetTransportSocketPool(
1508 HttpNetworkSession::NORMAL_SOCKET_POOL),
1509 BoundNetLog()));
1510 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
1511
1512 scoped_refptr<SpdyStream> spdy_stream1;
1513 TestCompletionCallback callback1;
1514 GURL url1("http://www.google.com");
1515 EXPECT_EQ(OK, session->CreateStream(url1, HIGHEST, &spdy_stream1,
1516 BoundNetLog(), callback1.callback()));
1517 EXPECT_EQ(0u, spdy_stream1->stream_id());
1518
1519 scoped_refptr<SpdyStream> spdy_stream2;
1520 TestCompletionCallback callback2;
1521 GURL url2("http://www.google.com");
1522 EXPECT_EQ(OK, session->CreateStream(url2, LOWEST, &spdy_stream2,
1523 BoundNetLog(), callback2.callback()));
1524 EXPECT_EQ(0u, spdy_stream2->stream_id());
1525
1526 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
1527 (*headers)[":method"] = "GET";
1528 (*headers)[":scheme"] = url1.scheme();
1529 (*headers)[":host"] = url1.host();
1530 (*headers)[":path"] = url1.path();
1531 (*headers)[":version"] = "HTTP/1.1";
1532 scoped_ptr<SpdyHeaderBlock> headers2(new SpdyHeaderBlock);
1533 *headers2 = *headers;
1534
1535 spdy_stream1->set_spdy_headers(headers.Pass());
1536 EXPECT_TRUE(spdy_stream1->HasUrl());
1537
1538 spdy_stream2->set_spdy_headers(headers2.Pass());
1539 EXPECT_TRUE(spdy_stream2->HasUrl());
1540
1541 spdy_stream1->SendRequest(false);
1542 spdy_stream2->SendRequest(false);
1543
1544 EXPECT_EQ(0u, spdy_stream1->stream_id());
1545
1546 spdy_stream1->Cancel();
1547
1548 EXPECT_EQ(0u, spdy_stream1->stream_id());
1549
1550 data.RunFor(1);
1551
1552 EXPECT_EQ(0u, spdy_stream1->stream_id());
1553 EXPECT_EQ(1u, spdy_stream2->stream_id());
1554
1555 spdy_stream1 = NULL;
1556 spdy_stream2->Cancel();
1557 spdy_stream2 = NULL;
1558 }
1559
1453 } // namespace net 1560 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698