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

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

Issue 129873010: Deprecate instead of close SPDY sessions upon network change. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rework deprecation to be less intrusive and avoid making behavior on certain OSs worse Created 6 years, 11 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_pool.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 "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
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);
Johnny 2014/01/24 20:05:05 Possible to remove some of the boilerplate here no
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(
Johnny 2014/01/24 20:05:05 indent
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 // The SpdySessionPool behavior differs based on how the OSs reacts to
782 // network changes, see comment in SpdySessionPool::OnIPAddressChanged().
783 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS)
784 // For OSs where the TCP connections will close upon relevant network
785 // changes, SpdySessionPool doesn't need to force them to close, so in these
786 // cases verify the session has become unavailable but remains open and the
787 // pre-existing stream is still active.
788 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_));
789
790 EXPECT_FALSE(session->IsClosed());
791
792 EXPECT_TRUE(session->IsStreamActive(1));
793
794 // Should close the session.
795 spdy_stream->Close();
796 #endif
797 EXPECT_EQ(NULL, spdy_stream.get());
798
799 EXPECT_TRUE(session == NULL);
800 }
801
731 TEST_P(SpdySessionTest, ClientPing) { 802 TEST_P(SpdySessionTest, ClientPing) {
732 session_deps_.enable_ping = true; 803 session_deps_.enable_ping = true;
733 session_deps_.host_resolver->set_synchronous_mode(true); 804 session_deps_.host_resolver->set_synchronous_mode(true);
734 805
735 MockConnect connect_data(SYNCHRONOUS, OK); 806 MockConnect connect_data(SYNCHRONOUS, OK);
736 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(1)); 807 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(1));
737 MockRead reads[] = { 808 MockRead reads[] = {
738 CreateMockRead(*read_ping, 1), 809 CreateMockRead(*read_ping, 1),
739 MockRead(ASYNC, 0, 0, 2) // EOF 810 MockRead(ASYNC, 0, 0, 2) // EOF
740 }; 811 };
(...skipping 3394 matching lines...) Expand 10 before | Expand all | Expand 10 after
4135 EXPECT_TRUE(delegate1.send_headers_completed()); 4206 EXPECT_TRUE(delegate1.send_headers_completed());
4136 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); 4207 EXPECT_EQ(std::string(), delegate1.TakeReceivedData());
4137 4208
4138 EXPECT_TRUE(delegate2.send_headers_completed()); 4209 EXPECT_TRUE(delegate2.send_headers_completed());
4139 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); 4210 EXPECT_EQ(std::string(), delegate2.TakeReceivedData());
4140 4211
4141 EXPECT_TRUE(data.at_write_eof()); 4212 EXPECT_TRUE(data.at_write_eof());
4142 } 4213 }
4143 4214
4144 } // namespace net 4215 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session_pool.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698