OLD | NEW |
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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); | 721 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); |
722 EXPECT_TRUE(session->IsStreamActive(1)); | 722 EXPECT_TRUE(session->IsStreamActive(1)); |
723 | 723 |
724 // Read and process the SYN_STREAM frame, the subsequent RST_STREAM, | 724 // Read and process the SYN_STREAM frame, the subsequent RST_STREAM, |
725 // and EOF. | 725 // and EOF. |
726 data.RunFor(3); | 726 data.RunFor(3); |
727 | 727 |
728 EXPECT_TRUE(session == NULL); | 728 EXPECT_TRUE(session == NULL); |
729 } | 729 } |
730 | 730 |
| 731 // A session observing a network change with active streams should close |
| 732 // when the last active stream is closed. |
| 733 TEST_P(SpdySessionTest, NetworkChangeWithActiveStreams) { |
| 734 session_deps_.host_resolver->set_synchronous_mode(true); |
| 735 |
| 736 MockConnect connect_data(SYNCHRONOUS, OK); |
| 737 MockRead reads[] = { |
| 738 MockRead(ASYNC, 0, 1) // EOF |
| 739 }; |
| 740 scoped_ptr<SpdyFrame> req1( |
| 741 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); |
| 742 MockWrite writes[] = { |
| 743 CreateMockWrite(*req1, 0), |
| 744 }; |
| 745 DeterministicSocketData data(reads, arraysize(reads), |
| 746 writes, arraysize(writes)); |
| 747 data.set_connect_data(connect_data); |
| 748 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 749 |
| 750 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 751 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
| 752 |
| 753 CreateDeterministicNetworkSession(); |
| 754 |
| 755 base::WeakPtr<SpdySession> session = |
| 756 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); |
| 757 |
| 758 EXPECT_EQ(spdy_util_.spdy_version(), session->GetProtocolVersion()); |
| 759 |
| 760 GURL url("http://www.google.com"); |
| 761 base::WeakPtr<SpdyStream> spdy_stream = |
| 762 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, |
| 763 session, url, MEDIUM, BoundNetLog()); |
| 764 test::StreamDelegateDoNothing delegate(spdy_stream); |
| 765 spdy_stream->SetDelegate(&delegate); |
| 766 |
| 767 scoped_ptr<SpdyHeaderBlock> headers( |
| 768 spdy_util_.ConstructGetHeaderBlock(url.spec())); |
| 769 |
| 770 spdy_stream->SendRequestHeaders(headers.Pass(), NO_MORE_DATA_TO_SEND); |
| 771 EXPECT_TRUE(spdy_stream->HasUrlFromHeaders()); |
| 772 |
| 773 data.RunFor(1); |
| 774 |
| 775 EXPECT_EQ(1u, spdy_stream->stream_id()); |
| 776 |
| 777 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); |
| 778 |
| 779 spdy_session_pool_->OnIPAddressChanged(); |
| 780 |
| 781 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); |
| 782 |
| 783 EXPECT_TRUE(session->IsStreamActive(1)); |
| 784 |
| 785 EXPECT_FALSE(session->IsClosed()); |
| 786 |
| 787 // Should close the session. |
| 788 spdy_stream->Close(); |
| 789 EXPECT_EQ(NULL, spdy_stream.get()); |
| 790 |
| 791 EXPECT_TRUE(session == NULL); |
| 792 } |
| 793 |
731 TEST_P(SpdySessionTest, ClientPing) { | 794 TEST_P(SpdySessionTest, ClientPing) { |
732 session_deps_.enable_ping = true; | 795 session_deps_.enable_ping = true; |
733 session_deps_.host_resolver->set_synchronous_mode(true); | 796 session_deps_.host_resolver->set_synchronous_mode(true); |
734 | 797 |
735 MockConnect connect_data(SYNCHRONOUS, OK); | 798 MockConnect connect_data(SYNCHRONOUS, OK); |
736 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(1)); | 799 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(1)); |
737 MockRead reads[] = { | 800 MockRead reads[] = { |
738 CreateMockRead(*read_ping, 1), | 801 CreateMockRead(*read_ping, 1), |
739 MockRead(ASYNC, 0, 0, 2) // EOF | 802 MockRead(ASYNC, 0, 0, 2) // EOF |
740 }; | 803 }; |
(...skipping 3394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4135 EXPECT_TRUE(delegate1.send_headers_completed()); | 4198 EXPECT_TRUE(delegate1.send_headers_completed()); |
4136 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); | 4199 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); |
4137 | 4200 |
4138 EXPECT_TRUE(delegate2.send_headers_completed()); | 4201 EXPECT_TRUE(delegate2.send_headers_completed()); |
4139 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); | 4202 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); |
4140 | 4203 |
4141 EXPECT_TRUE(data.at_write_eof()); | 4204 EXPECT_TRUE(data.at_write_eof()); |
4142 } | 4205 } |
4143 | 4206 |
4144 } // namespace net | 4207 } // namespace net |
OLD | NEW |