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

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

Issue 10821086: Fix bug in SpdySession (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Complete 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 1538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 data.RunFor(1); 1549 data.RunFor(1);
1550 1550
1551 EXPECT_EQ(0u, spdy_stream1->stream_id()); 1551 EXPECT_EQ(0u, spdy_stream1->stream_id());
1552 EXPECT_EQ(1u, spdy_stream2->stream_id()); 1552 EXPECT_EQ(1u, spdy_stream2->stream_id());
1553 1553
1554 spdy_stream1 = NULL; 1554 spdy_stream1 = NULL;
1555 spdy_stream2->Cancel(); 1555 spdy_stream2->Cancel();
1556 spdy_stream2 = NULL; 1556 spdy_stream2 = NULL;
1557 } 1557 }
1558 1558
1559 namespace {
1560
1561 class ClosingDelegate : public SpdyStream::Delegate {
1562 public:
1563 ClosingDelegate(SpdyStream* stream) : stream_(stream) {}
1564
1565 virtual bool OnSendHeadersComplete(int status) {
1566 return false;
1567 }
1568 virtual int OnSendBody() {
1569 return OK;
1570 }
1571 virtual int OnSendBodyComplete(int status, bool* eof) {
1572 return OK;
1573 }
1574 virtual int OnResponseReceived(const SpdyHeaderBlock& response,
1575 base::Time response_time,
1576 int status) {
1577 return OK;
1578 }
1579 virtual void OnDataReceived(const char* data, int length) {}
1580 virtual void OnDataSent(int length) {}
1581 virtual void OnClose(int status) {
1582 stream_->Close();
1583 }
1584 private:
1585 SpdyStream* stream_;
1586 };
1587
1588 } // namespace
1589
1590 TEST_F(SpdySessionSpdy3Test, CloseSessionWithTwoCreatedStreams) {
1591 MockConnect connect_data(SYNCHRONOUS, OK);
1592 // Request 1, at HIGHEST priority, will be cancelled before it writes data.
1593 // Request 2, at LOWEST priority, will be a full request and will be id 1.
1594 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
1595 MockWrite writes[] = {
1596 CreateMockWrite(*req2, 0),
1597 };
1598
1599 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 1));
1600 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(1, true));
1601 MockRead reads[] = {
1602 CreateMockRead(*resp2, 1),
1603 CreateMockRead(*body2, 2),
1604 MockRead(ASYNC, 0, 3) // EOF
1605 };
1606
1607 SpdySessionDependencies session_deps;
1608 session_deps.host_resolver->set_synchronous_mode(true);
1609
1610 DeterministicSocketData data(reads, arraysize(reads),
1611 writes, arraysize(writes));
1612 data.set_connect_data(connect_data);
1613 session_deps.deterministic_socket_factory->AddSocketDataProvider(&data);
1614
1615 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1616 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1617
1618 scoped_refptr<HttpNetworkSession> http_session(
1619 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps));
1620
1621 const std::string kTestHost("www.foo.com");
1622 const int kTestPort = 80;
1623 HostPortPair test_host_port_pair(kTestHost, kTestPort);
1624 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct());
1625
1626 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool());
1627
1628 // Create a session.
1629 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
1630 scoped_refptr<SpdySession> session =
1631 spdy_session_pool->Get(pair, BoundNetLog());
1632 ASSERT_TRUE(spdy_session_pool->HasSession(pair));
1633
1634 scoped_refptr<TransportSocketParams> transport_params(
1635 new TransportSocketParams(test_host_port_pair,
1636 MEDIUM,
1637 false,
1638 false,
1639 OnHostResolutionCallback()));
1640 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
1641 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(),
1642 transport_params, MEDIUM, CompletionCallback(),
1643 http_session->GetTransportSocketPool(
1644 HttpNetworkSession::NORMAL_SOCKET_POOL),
1645 BoundNetLog()));
1646 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
1647
1648 scoped_refptr<SpdyStream> spdy_stream1;
1649 TestCompletionCallback callback1;
1650 GURL url1("http://www.google.com");
1651 EXPECT_EQ(OK, session->CreateStream(url1, HIGHEST, &spdy_stream1,
1652 BoundNetLog(), callback1.callback()));
1653 EXPECT_EQ(0u, spdy_stream1->stream_id());
1654
1655 scoped_refptr<SpdyStream> spdy_stream2;
1656 TestCompletionCallback callback2;
1657 GURL url2("http://www.google.com");
1658 EXPECT_EQ(OK, session->CreateStream(url2, LOWEST, &spdy_stream2,
1659 BoundNetLog(), callback2.callback()));
1660 EXPECT_EQ(0u, spdy_stream2->stream_id());
1661
1662 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
1663 (*headers)["method"] = "GET";
1664 (*headers)["scheme"] = url1.scheme();
1665 (*headers)["host"] = url1.host();
1666 (*headers)["url"] = url1.path();
1667 (*headers)["version"] = "HTTP/1.1";
1668 scoped_ptr<SpdyHeaderBlock> headers2(new SpdyHeaderBlock);
1669 *headers2 = *headers;
1670
1671 spdy_stream1->set_spdy_headers(headers.Pass());
1672 EXPECT_TRUE(spdy_stream1->HasUrl());
1673 ClosingDelegate delegate1(spdy_stream1.get());
1674 spdy_stream1->SetDelegate(&delegate1);
1675
1676 spdy_stream2->set_spdy_headers(headers2.Pass());
1677 EXPECT_TRUE(spdy_stream2->HasUrl());
1678 ClosingDelegate delegate2(spdy_stream2.get());
1679 spdy_stream2->SetDelegate(&delegate2);
1680
1681 spdy_stream1->SendRequest(false);
1682 spdy_stream2->SendRequest(false);
1683
1684 EXPECT_EQ(0u, spdy_stream1->stream_id());
1685 EXPECT_EQ(0u, spdy_stream2->stream_id());
1686
1687 session->CloseSessionOnError(ERR_ABORTED, true, "");
1688
1689 EXPECT_EQ(0u, spdy_stream1->stream_id());
1690 EXPECT_EQ(0u, spdy_stream2->stream_id());
1691
1692 spdy_stream1 = NULL;
1693 spdy_stream2 = NULL;
1694 }
1695
1559 } // namespace net 1696 } // namespace net
OLDNEW
« net/spdy/spdy_session_spdy2_unittest.cc ('K') | « net/spdy/spdy_session_spdy2_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698