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

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: Fix sleevi comments. 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
« no previous file with comments | « net/spdy/spdy_session_spdy2_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "net/spdy/spdy_session_pool.h" 11 #include "net/spdy/spdy_session_pool.h"
12 #include "net/spdy/spdy_stream.h" 12 #include "net/spdy/spdy_stream.h"
13 #include "net/spdy/spdy_test_util_spdy3.h" 13 #include "net/spdy/spdy_test_util_spdy3.h"
14 #include "testing/platform_test.h" 14 #include "testing/platform_test.h"
15 15
16 using namespace net::test_spdy3; 16 using namespace net::test_spdy3;
17 17
18 namespace net {
19
18 namespace { 20 namespace {
19 21
20 base::TimeTicks the_near_future() { 22 base::TimeTicks the_near_future() {
21 return base::TimeTicks::Now() + 23 return base::TimeTicks::Now() +
22 base::TimeDelta::FromSeconds(301); 24 base::TimeDelta::FromSeconds(301);
23 } 25 }
24 26
25 } // namespace 27 class ClosingDelegate : public SpdyStream::Delegate {
28 public:
29 ClosingDelegate(SpdyStream* stream) : stream_(stream) {}
26 30
27 namespace net { 31 // SpdyStream::Delegate implementation:
32 virtual bool OnSendHeadersComplete(int status) OVERRIDE {
33 return true;
34 }
35 virtual int OnSendBody() OVERRIDE {
36 return OK;
37 }
38 virtual int OnSendBodyComplete(int status, bool* eof) OVERRIDE {
39 return OK;
40 }
41 virtual int OnResponseReceived(const SpdyHeaderBlock& response,
42 base::Time response_time,
43 int status) OVERRIDE {
44 return OK;
45 }
46 virtual void OnDataReceived(const char* data, int length) OVERRIDE {}
47 virtual void OnDataSent(int length) OVERRIDE {}
48 virtual void OnClose(int status) OVERRIDE {
49 stream_->Close();
50 }
51 private:
52 SpdyStream* stream_;
53 };
28 54
29 // TODO(cbentzel): Expose compression setter/getter in public SpdySession
30 // interface rather than going through all these contortions.
31 class SpdySessionSpdy3Test : public PlatformTest {
32 protected:
33 virtual void SetUp() {
34 SpdySession::set_default_protocol(kProtoSPDY3);
35 }
36
37 private:
38 SpdyTestStateHelper spdy_state_;
39 };
40 55
41 class TestSpdyStreamDelegate : public net::SpdyStream::Delegate { 56 class TestSpdyStreamDelegate : public net::SpdyStream::Delegate {
42 public: 57 public:
43 explicit TestSpdyStreamDelegate(const CompletionCallback& callback) 58 explicit TestSpdyStreamDelegate(const CompletionCallback& callback)
44 : callback_(callback) {} 59 : callback_(callback) {}
45 virtual ~TestSpdyStreamDelegate() {} 60 virtual ~TestSpdyStreamDelegate() {}
46 61
47 virtual bool OnSendHeadersComplete(int status) { return true; } 62 virtual bool OnSendHeadersComplete(int status) { return true; }
48 63
49 virtual int OnSendBody() { 64 virtual int OnSendBody() {
(...skipping 19 matching lines...) Expand all
69 virtual void OnClose(int status) { 84 virtual void OnClose(int status) {
70 CompletionCallback callback = callback_; 85 CompletionCallback callback = callback_;
71 callback_.Reset(); 86 callback_.Reset();
72 callback.Run(OK); 87 callback.Run(OK);
73 } 88 }
74 89
75 private: 90 private:
76 CompletionCallback callback_; 91 CompletionCallback callback_;
77 }; 92 };
78 93
94 } // namespace
95
96 // TODO(cbentzel): Expose compression setter/getter in public SpdySession
97 // interface rather than going through all these contortions.
98 class SpdySessionSpdy3Test : public PlatformTest {
99 protected:
100 virtual void SetUp() {
101 SpdySession::set_default_protocol(kProtoSPDY3);
102 }
103
104 private:
105 SpdyTestStateHelper spdy_state_;
106 };
79 // Test the SpdyIOBuffer class. 107 // Test the SpdyIOBuffer class.
80 TEST_F(SpdySessionSpdy3Test, SpdyIOBuffer) { 108 TEST_F(SpdySessionSpdy3Test, SpdyIOBuffer) {
81 std::priority_queue<SpdyIOBuffer> queue_; 109 std::priority_queue<SpdyIOBuffer> queue_;
82 const size_t kQueueSize = 100; 110 const size_t kQueueSize = 100;
83 111
84 // Insert items with random priority and increasing buffer size 112 // Insert items with random priority and increasing buffer size
85 for (size_t index = 0; index < kQueueSize; ++index) { 113 for (size_t index = 0; index < kQueueSize; ++index) {
86 queue_.push(SpdyIOBuffer( 114 queue_.push(SpdyIOBuffer(
87 new IOBufferWithSize(index + 1), 115 new IOBufferWithSize(index + 1),
88 index + 1, 116 index + 1,
(...skipping 1460 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 data.RunFor(1); 1577 data.RunFor(1);
1550 1578
1551 EXPECT_EQ(0u, spdy_stream1->stream_id()); 1579 EXPECT_EQ(0u, spdy_stream1->stream_id());
1552 EXPECT_EQ(1u, spdy_stream2->stream_id()); 1580 EXPECT_EQ(1u, spdy_stream2->stream_id());
1553 1581
1554 spdy_stream1 = NULL; 1582 spdy_stream1 = NULL;
1555 spdy_stream2->Cancel(); 1583 spdy_stream2->Cancel();
1556 spdy_stream2 = NULL; 1584 spdy_stream2 = NULL;
1557 } 1585 }
1558 1586
1587 TEST_F(SpdySessionSpdy3Test, CloseSessionWithTwoCreatedStreams) {
1588 // Test that if a sesion is closed with two created streams pending,
1589 // it does not crash. http://crbug.com/139518
1590 MockConnect connect_data(SYNCHRONOUS, OK);
1591 SpdySessionDependencies session_deps;
1592 session_deps.host_resolver->set_synchronous_mode(true);
1593
1594 // No actual data will be sent.
1595 MockWrite writes[] = {
1596 MockWrite(ASYNC, 0, 1) // EOF
1597 };
1598
1599 MockRead reads[] = {
1600 MockRead(ASYNC, 0, 0) // EOF
1601 };
1602 DeterministicSocketData data(reads, arraysize(reads),
1603 writes, arraysize(writes));
1604 data.set_connect_data(connect_data);
1605 session_deps.deterministic_socket_factory->AddSocketDataProvider(&data);
1606
1607 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1608 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1609
1610 scoped_refptr<HttpNetworkSession> http_session(
1611 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps));
1612
1613 const std::string kTestHost("www.foo.com");
1614 const int kTestPort = 80;
1615 HostPortPair test_host_port_pair(kTestHost, kTestPort);
1616 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct());
1617
1618 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool());
1619
1620 // Create a session.
1621 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
1622 scoped_refptr<SpdySession> session =
1623 spdy_session_pool->Get(pair, BoundNetLog());
1624 ASSERT_TRUE(spdy_session_pool->HasSession(pair));
1625
1626 scoped_refptr<TransportSocketParams> transport_params(
1627 new TransportSocketParams(test_host_port_pair,
1628 MEDIUM,
1629 false,
1630 false,
1631 OnHostResolutionCallback()));
1632 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
1633 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(),
1634 transport_params, MEDIUM, CompletionCallback(),
1635 http_session->GetTransportSocketPool(
1636 HttpNetworkSession::NORMAL_SOCKET_POOL),
1637 BoundNetLog()));
1638 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
1639
1640 scoped_refptr<SpdyStream> spdy_stream1;
1641 TestCompletionCallback callback1;
1642 GURL url1("http://www.google.com");
1643 EXPECT_EQ(OK, session->CreateStream(url1, HIGHEST, &spdy_stream1,
1644 BoundNetLog(), callback1.callback()));
1645 EXPECT_EQ(0u, spdy_stream1->stream_id());
1646
1647 scoped_refptr<SpdyStream> spdy_stream2;
1648 TestCompletionCallback callback2;
1649 GURL url2("http://www.google.com");
1650 EXPECT_EQ(OK, session->CreateStream(url2, LOWEST, &spdy_stream2,
1651 BoundNetLog(), callback2.callback()));
1652 EXPECT_EQ(0u, spdy_stream2->stream_id());
1653
1654 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
1655 (*headers)["method"] = "GET";
1656 (*headers)["scheme"] = url1.scheme();
1657 (*headers)["host"] = url1.host();
1658 (*headers)["url"] = url1.path();
1659 (*headers)["version"] = "HTTP/1.1";
1660 scoped_ptr<SpdyHeaderBlock> headers2(new SpdyHeaderBlock);
1661 *headers2 = *headers;
1662
1663 spdy_stream1->set_spdy_headers(headers.Pass());
1664 EXPECT_TRUE(spdy_stream1->HasUrl());
1665 ClosingDelegate delegate1(spdy_stream1.get());
1666 spdy_stream1->SetDelegate(&delegate1);
1667
1668 spdy_stream2->set_spdy_headers(headers2.Pass());
1669 EXPECT_TRUE(spdy_stream2->HasUrl());
1670 ClosingDelegate delegate2(spdy_stream2.get());
1671 spdy_stream2->SetDelegate(&delegate2);
1672
1673 spdy_stream1->SendRequest(false);
1674 spdy_stream2->SendRequest(false);
1675
1676 // Ensure that the streams have not yet been activated and assigned an id.
1677 EXPECT_EQ(0u, spdy_stream1->stream_id());
1678 EXPECT_EQ(0u, spdy_stream2->stream_id());
1679
1680 // Ensure we don't crash while closing the session.
1681 session->CloseSessionOnError(ERR_ABORTED, true, "");
1682
1683 EXPECT_TRUE(spdy_stream1->closed());
1684 EXPECT_TRUE(spdy_stream2->closed());
1685
1686 spdy_stream1 = NULL;
1687 spdy_stream2 = NULL;
1688 }
1689
1559 } // namespace net 1690 } // namespace net
OLDNEW
« no previous file with comments | « 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