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

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

Issue 14232014: Correctly handle SPDY GOAWAY frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comments Created 7 years, 8 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 "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "net/base/io_buffer.h" 8 #include "net/base/io_buffer.h"
9 #include "net/base/ip_endpoint.h" 9 #include "net/base/ip_endpoint.h"
10 #include "net/base/net_log_unittest.h" 10 #include "net/base/net_log_unittest.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 SpdySessionPool* spdy_session_pool_; 103 SpdySessionPool* spdy_session_pool_;
104 GURL test_url_; 104 GURL test_url_;
105 HostPortPair test_host_port_pair_; 105 HostPortPair test_host_port_pair_;
106 HostPortProxyPair pair_; 106 HostPortProxyPair pair_;
107 }; 107 };
108 108
109 TEST_F(SpdySessionSpdy2Test, GoAway) { 109 TEST_F(SpdySessionSpdy2Test, GoAway) {
110 session_deps_.host_resolver->set_synchronous_mode(true); 110 session_deps_.host_resolver->set_synchronous_mode(true);
111 111
112 MockConnect connect_data(SYNCHRONOUS, OK); 112 MockConnect connect_data(SYNCHRONOUS, OK);
113 scoped_ptr<SpdyFrame> goaway(ConstructSpdyGoAway()); 113 scoped_ptr<SpdyFrame> goaway(ConstructSpdyGoAway(1));
114 MockRead reads[] = { 114 MockRead reads[] = {
115 CreateMockRead(*goaway), 115 CreateMockRead(*goaway, 2),
116 MockRead(SYNCHRONOUS, 0, 0) // EOF 116 MockRead(ASYNC, 0, 3) // EOF
117 }; 117 };
118 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 118 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, MEDIUM));
119 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, MEDIUM));
120 MockWrite writes[] = {
121 CreateMockWrite(*req1, 0),
122 CreateMockWrite(*req2, 1),
123 };
124 DeterministicSocketData data(reads, arraysize(reads),
125 writes, arraysize(writes));
119 data.set_connect_data(connect_data); 126 data.set_connect_data(connect_data);
120 session_deps_.socket_factory->AddSocketDataProvider(&data); 127 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
121 128
122 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 129 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
123 ssl.SetNextProto(kProtoSPDY2); 130 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
124 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
125 131
126 CreateNetworkSession(); 132 CreateDeterministicNetworkSession();
127 133
128 scoped_refptr<SpdySession> session = CreateInitializedSession(); 134 scoped_refptr<SpdySession> session = CreateInitializedSession();
129 135
130 EXPECT_EQ(2, session->GetProtocolVersion()); 136 EXPECT_EQ(2, session->GetProtocolVersion());
131 137
132 // Flush the SpdySession::OnReadComplete() task. 138 GURL url("http://www.google.com");
133 MessageLoop::current()->RunUntilIdle(); 139 scoped_refptr<SpdyStream> spdy_stream1 =
140 CreateStreamSynchronously(session, url, MEDIUM, BoundNetLog());
141
142 scoped_refptr<SpdyStream> spdy_stream2 =
143 CreateStreamSynchronously(session, url, MEDIUM, BoundNetLog());
144
145 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
146 (*headers)["method"] = "GET";
147 (*headers)["scheme"] = url.scheme();
148 (*headers)["host"] = url.host();
149 (*headers)["url"] = url.path();
150 (*headers)["version"] = "HTTP/1.1";
151 scoped_ptr<SpdyHeaderBlock> headers2(new SpdyHeaderBlock);
152 *headers2 = *headers;
153
154 spdy_stream1->set_spdy_headers(headers.Pass());
155 EXPECT_TRUE(spdy_stream1->HasUrl());
156
157 spdy_stream2->set_spdy_headers(headers2.Pass());
158 EXPECT_TRUE(spdy_stream2->HasUrl());
159
160 spdy_stream1->SendRequest(false);
161 spdy_stream2->SendRequest(false);
162 data.RunFor(2);
163
164 EXPECT_EQ(1u, spdy_stream1->stream_id());
165 EXPECT_EQ(3u, spdy_stream2->stream_id());
166
167 EXPECT_TRUE(spdy_session_pool_->HasSession(pair_));
168
169 // Read and process the GOAWAY frame.
170 data.RunFor(1);
134 171
135 EXPECT_FALSE(spdy_session_pool_->HasSession(pair_)); 172 EXPECT_FALSE(spdy_session_pool_->HasSession(pair_));
136 173
174 EXPECT_TRUE(session->IsStreamActive(1));
175 EXPECT_FALSE(session->IsStreamActive(3));
176
137 scoped_refptr<SpdySession> session2 = GetSession(pair_); 177 scoped_refptr<SpdySession> session2 = GetSession(pair_);
138 178
179 spdy_stream1->Close();
180 spdy_stream1 = NULL;
181 spdy_stream2 = NULL;
182
139 // Delete the first session. 183 // Delete the first session.
140 session = NULL; 184 session = NULL;
141 185
142 // Delete the second session. 186 // Delete the second session.
143 spdy_session_pool_->Remove(session2); 187 spdy_session_pool_->Remove(session2);
144 session2 = NULL; 188 session2 = NULL;
145 } 189 }
146 190
147 TEST_F(SpdySessionSpdy2Test, ClientPing) { 191 TEST_F(SpdySessionSpdy2Test, ClientPing) {
148 session_deps_.enable_ping = true; 192 session_deps_.enable_ping = true;
(...skipping 1797 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 http_session_.get(), session.get(), test_host_port_pair_); 1990 http_session_.get(), session.get(), test_host_port_pair_);
1947 1991
1948 EXPECT_EQ(SpdySession::FLOW_CONTROL_NONE, session->flow_control_state()); 1992 EXPECT_EQ(SpdySession::FLOW_CONTROL_NONE, session->flow_control_state());
1949 EXPECT_EQ(kSpdyVersion2, session->buffered_spdy_framer_->protocol_version()); 1993 EXPECT_EQ(kSpdyVersion2, session->buffered_spdy_framer_->protocol_version());
1950 EXPECT_EQ(0, session->session_send_window_size_); 1994 EXPECT_EQ(0, session->session_send_window_size_);
1951 EXPECT_EQ(0, session->session_recv_window_size_); 1995 EXPECT_EQ(0, session->session_recv_window_size_);
1952 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); 1996 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_);
1953 } 1997 }
1954 1998
1955 } // namespace net 1999 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698