blob: 0bb7da6a19eca5f06fe63bc6361412006452c82b [file] [log] [blame]
[email protected]a1595312012-01-22 03:25:041// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]4f386422010-07-20 04:19:492// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]3b63f8f42011-03-28 01:54:155#include "base/memory/ref_counted.h"
[email protected]5a76b812011-12-21 20:52:006#include "net/base/completion_callback.h"
[email protected]d245c342012-02-23 20:49:157#include "net/base/net_log_unittest.h"
[email protected]f54c85792012-03-08 19:06:418#include "net/spdy/buffered_spdy_framer.h"
[email protected]4f386422010-07-20 04:19:499#include "net/spdy/spdy_stream.h"
[email protected]9e1bdd32011-02-03 21:48:3410#include "net/spdy/spdy_http_utils.h"
[email protected]4f386422010-07-20 04:19:4911#include "net/spdy/spdy_session.h"
[email protected]39d13d942012-07-19 16:48:2012#include "net/spdy/spdy_stream_test_util.h"
[email protected]448d4ca52012-03-04 04:12:2313#include "net/spdy/spdy_test_util_spdy3.h"
[email protected]5e248dc2012-08-21 02:27:3214#include "net/spdy/spdy_websocket_test_util_spdy3.h"
[email protected]4f386422010-07-20 04:19:4915#include "testing/gtest/include/gtest/gtest.h"
16
[email protected]448d4ca52012-03-04 04:12:2317using namespace net::test_spdy3;
18
[email protected]4f386422010-07-20 04:19:4919// TODO(ukai): factor out common part with spdy_http_stream_unittest.cc
[email protected]b9ec6882011-07-01 07:40:2620//
21namespace net {
[email protected]4f386422010-07-20 04:19:4922
23namespace {
24
[email protected]ff98d7f02012-03-22 21:44:1925SpdyFrame* ConstructSpdyBodyFrame(const char* data, int length) {
[email protected]f9cf5572012-12-04 15:52:0926 BufferedSpdyFramer framer(3, false);
[email protected]ff98d7f02012-03-22 21:44:1927 return framer.CreateDataFrame(1, data, length, DATA_FLAG_NONE);
[email protected]4f386422010-07-20 04:19:4928}
29
30} // anonymous namespace
31
[email protected]39d13d942012-07-19 16:48:2032namespace test {
33
[email protected]448d4ca52012-03-04 04:12:2334class SpdyStreamSpdy3Test : public testing::Test {
[email protected]4f386422010-07-20 04:19:4935 protected:
[email protected]448d4ca52012-03-04 04:12:2336 SpdyStreamSpdy3Test() {
[email protected]4f386422010-07-20 04:19:4937 }
38
39 scoped_refptr<SpdySession> CreateSpdySession() {
[email protected]4f386422010-07-20 04:19:4940 HostPortPair host_port_pair("www.google.com", 80);
[email protected]31e68d72010-08-25 06:36:5841 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct());
[email protected]4f386422010-07-20 04:19:4942 scoped_refptr<SpdySession> session(
[email protected]102e27c2011-02-23 01:01:3143 session_->spdy_session_pool()->Get(pair, BoundNetLog()));
[email protected]4f386422010-07-20 04:19:4944 return session;
45 }
46
47 virtual void TearDown() {
[email protected]b4c62eb2012-11-14 18:36:5148 MessageLoop::current()->RunUntilIdle();
[email protected]4f386422010-07-20 04:19:4949 }
50
51 scoped_refptr<HttpNetworkSession> session_;
52};
53
[email protected]448d4ca52012-03-04 04:12:2354TEST_F(SpdyStreamSpdy3Test, SendDataAfterOpen) {
[email protected]30c942b2010-07-21 16:59:5955 SpdySessionDependencies session_deps;
[email protected]4f386422010-07-20 04:19:4956
[email protected]30c942b2010-07-21 16:59:5957 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps);
[email protected]4f386422010-07-20 04:19:4958 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool());
59
60 const SpdyHeaderInfo kSynStartHeader = {
[email protected]ff98d7f02012-03-22 21:44:1961 SYN_STREAM,
[email protected]4f386422010-07-20 04:19:4962 1,
63 0,
[email protected]72074442012-04-17 20:51:5764 ConvertRequestPriorityToSpdyPriority(LOWEST, 3),
[email protected]1eb81432012-03-24 06:48:0065 0,
[email protected]ff98d7f02012-03-22 21:44:1966 CONTROL_FLAG_NONE,
[email protected]4f386422010-07-20 04:19:4967 false,
[email protected]5a7bb252013-02-09 00:21:0568 RST_STREAM_INVALID,
[email protected]4f386422010-07-20 04:19:4969 NULL,
70 0,
[email protected]ff98d7f02012-03-22 21:44:1971 DATA_FLAG_NONE
[email protected]4f386422010-07-20 04:19:4972 };
73 static const char* const kGetHeaders[] = {
[email protected]0e861e92012-03-15 18:42:1974 ":method",
[email protected]4f386422010-07-20 04:19:4975 "GET",
[email protected]0e861e92012-03-15 18:42:1976 ":scheme",
[email protected]a7a265ef2010-12-08 18:05:5777 "http",
[email protected]0e861e92012-03-15 18:42:1978 ":host",
[email protected]a7a265ef2010-12-08 18:05:5779 "www.google.com",
[email protected]0e861e92012-03-15 18:42:1980 ":path",
[email protected]a7a265ef2010-12-08 18:05:5781 "/",
[email protected]0e861e92012-03-15 18:42:1982 ":version",
[email protected]4f386422010-07-20 04:19:4983 "HTTP/1.1",
84 };
[email protected]ff98d7f02012-03-22 21:44:1985 scoped_ptr<SpdyFrame> req(
[email protected]4f386422010-07-20 04:19:4986 ConstructSpdyPacket(
87 kSynStartHeader, NULL, 0, kGetHeaders, arraysize(kGetHeaders) / 2));
[email protected]ff98d7f02012-03-22 21:44:1988 scoped_ptr<SpdyFrame> msg(
[email protected]4f386422010-07-20 04:19:4989 ConstructSpdyBodyFrame("\0hello!\xff", 8));
90 MockWrite writes[] = {
91 CreateMockWrite(*req),
92 CreateMockWrite(*msg),
93 };
94 writes[0].sequence_number = 0;
95 writes[1].sequence_number = 2;
96
[email protected]ff98d7f02012-03-22 21:44:1997 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
98 scoped_ptr<SpdyFrame> echo(
[email protected]4f386422010-07-20 04:19:4999 ConstructSpdyBodyFrame("\0hello!\xff", 8));
100 MockRead reads[] = {
101 CreateMockRead(*resp),
102 CreateMockRead(*echo),
[email protected]8ddf8322012-02-23 18:08:06103 MockRead(ASYNC, 0, 0), // EOF
[email protected]4f386422010-07-20 04:19:49104 };
105 reads[0].sequence_number = 1;
106 reads[1].sequence_number = 3;
107 reads[2].sequence_number = 4;
108
[email protected]dd54bd82012-07-19 23:44:57109 OrderedSocketData data(reads, arraysize(reads),
110 writes, arraysize(writes));
[email protected]d973e99a2012-02-17 21:02:36111 MockConnect connect_data(SYNCHRONOUS, OK);
[email protected]dd54bd82012-07-19 23:44:57112 data.set_connect_data(connect_data);
[email protected]4f386422010-07-20 04:19:49113
[email protected]dd54bd82012-07-19 23:44:57114 session_deps.socket_factory->AddSocketDataProvider(&data);
[email protected]4f386422010-07-20 04:19:49115
116 scoped_refptr<SpdySession> session(CreateSpdySession());
[email protected]a7a265ef2010-12-08 18:05:57117 const char* kStreamUrl = "http://www.google.com/";
118 GURL url(kStreamUrl);
[email protected]4f386422010-07-20 04:19:49119
120 HostPortPair host_port_pair("www.google.com", 80);
[email protected]ab739042011-04-07 15:22:28121 scoped_refptr<TransportSocketParams> transport_params(
[email protected]d2b5f092012-06-08 23:55:02122 new TransportSocketParams(host_port_pair, LOWEST, false, false,
123 OnHostResolutionCallback()));
[email protected]02b0c342010-09-25 21:09:38124
125 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
[email protected]6ecf2b92011-12-15 01:14:52126 EXPECT_EQ(OK, connection->Init(host_port_pair.ToString(), transport_params,
127 LOWEST, CompletionCallback(),
[email protected]e5c026642012-03-17 00:14:02128 session_->GetTransportSocketPool(
129 HttpNetworkSession::NORMAL_SOCKET_POOL),
[email protected]6ecf2b92011-12-15 01:14:52130 BoundNetLog()));
[email protected]02b0c342010-09-25 21:09:38131 session->InitializeWithSocket(connection.release(), false, OK);
[email protected]4f386422010-07-20 04:19:49132
133 scoped_refptr<SpdyStream> stream;
134 ASSERT_EQ(
135 OK,
[email protected]49639fa2011-12-20 23:22:41136 session->CreateStream(url, LOWEST, &stream, BoundNetLog(),
137 CompletionCallback()));
[email protected]4f386422010-07-20 04:19:49138 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(8));
139 memcpy(buf->data(), "\0hello!\xff", 8);
[email protected]5a76b812011-12-21 20:52:00140 TestCompletionCallback callback;
[email protected]4f386422010-07-20 04:19:49141
142 scoped_ptr<TestSpdyStreamDelegate> delegate(
[email protected]0837bc62012-08-03 07:31:26143 new TestSpdyStreamDelegate(
144 stream.get(), NULL, buf.get(), callback.callback()));
[email protected]4f386422010-07-20 04:19:49145 stream->SetDelegate(delegate.get());
146
[email protected]a7a265ef2010-12-08 18:05:57147 EXPECT_FALSE(stream->HasUrl());
148
[email protected]0a01d890fc2012-07-18 17:24:05149 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
[email protected]0e861e92012-03-15 18:42:19150 (*headers)[":method"] = "GET";
151 (*headers)[":scheme"] = url.scheme();
152 (*headers)[":host"] = url.host();
153 (*headers)[":path"] = url.path();
154 (*headers)[":version"] = "HTTP/1.1";
[email protected]0a01d890fc2012-07-18 17:24:05155 stream->set_spdy_headers(headers.Pass());
[email protected]a7a265ef2010-12-08 18:05:57156 EXPECT_TRUE(stream->HasUrl());
157 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec());
[email protected]4f386422010-07-20 04:19:49158
[email protected]a5c493b92010-08-06 23:04:29159 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true));
[email protected]4f386422010-07-20 04:19:49160
161 EXPECT_EQ(OK, callback.WaitForResult());
162
163 EXPECT_TRUE(delegate->send_headers_completed());
[email protected]d42dedd02012-04-03 19:42:06164 EXPECT_EQ("200", (*delegate->response())[":status"]);
165 EXPECT_EQ("HTTP/1.1", (*delegate->response())[":version"]);
[email protected]4f386422010-07-20 04:19:49166 EXPECT_EQ(std::string("\0hello!\xff", 8), delegate->received_data());
167 EXPECT_EQ(8, delegate->data_sent());
168 EXPECT_TRUE(delegate->closed());
169}
170
[email protected]0837bc62012-08-03 07:31:26171TEST_F(SpdyStreamSpdy3Test, SendHeaderAndDataAfterOpen) {
172 SpdySessionDependencies session_deps;
173
174 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps);
175 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool());
176
[email protected]5e248dc2012-08-21 02:27:32177 scoped_ptr<SpdyFrame> expected_request(ConstructSpdyWebSocketSynStream(
[email protected]0837bc62012-08-03 07:31:26178 1,
179 "/chat",
180 "server.example.com",
181 "http://example.com"));
182 scoped_ptr<SpdyFrame> expected_headers(ConstructSpdyWebSocketHeadersFrame(
183 1, "6", true));
184 scoped_ptr<SpdyFrame> expected_message(ConstructSpdyBodyFrame("hello!", 6));
185 MockWrite writes[] = {
186 CreateMockWrite(*expected_request),
187 CreateMockWrite(*expected_headers),
188 CreateMockWrite(*expected_message)
189 };
190 writes[0].sequence_number = 0;
191 writes[1].sequence_number = 2;
192 writes[1].sequence_number = 3;
193
194 scoped_ptr<SpdyFrame> response(
195 ConstructSpdyWebSocketSynReply(1));
196 MockRead reads[] = {
197 CreateMockRead(*response),
198 MockRead(ASYNC, 0, 0), // EOF
199 };
200 reads[0].sequence_number = 1;
201 reads[1].sequence_number = 4;
202
203 OrderedSocketData data(reads, arraysize(reads),
204 writes, arraysize(writes));
205 MockConnect connect_data(SYNCHRONOUS, OK);
206 data.set_connect_data(connect_data);
207
208 session_deps.socket_factory->AddSocketDataProvider(&data);
209
210 scoped_refptr<SpdySession> session(CreateSpdySession());
211 const char* kStreamUrl = "ws://server.example.com/chat";
212 GURL url(kStreamUrl);
213
214 HostPortPair host_port_pair("server.example.com", 80);
215 scoped_refptr<TransportSocketParams> transport_params(
216 new TransportSocketParams(host_port_pair, LOWEST, false, false,
217 OnHostResolutionCallback()));
218
219 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
220 EXPECT_EQ(OK, connection->Init(host_port_pair.ToString(), transport_params,
221 LOWEST, CompletionCallback(),
222 session_->GetTransportSocketPool(
223 HttpNetworkSession::NORMAL_SOCKET_POOL),
224 BoundNetLog()));
225 session->InitializeWithSocket(connection.release(), false, OK);
226
227 scoped_refptr<SpdyStream> stream;
228 ASSERT_EQ(
229 OK,
[email protected]5e248dc2012-08-21 02:27:32230 session->CreateStream(url, HIGHEST, &stream, BoundNetLog(),
[email protected]0837bc62012-08-03 07:31:26231 CompletionCallback()));
232 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(6));
233 memcpy(buf->data(), "hello!", 6);
234 TestCompletionCallback callback;
235 scoped_ptr<SpdyHeaderBlock> message_headers(new SpdyHeaderBlock);
236 (*message_headers)[":opcode"] = "1";
237 (*message_headers)[":length"] = "6";
238 (*message_headers)[":fin"] = "1";
239
240 scoped_ptr<TestSpdyStreamDelegate> delegate(
241 new TestSpdyStreamDelegate(stream.get(),
242 message_headers.release(),
243 buf.get(),
244 callback.callback()));
245 stream->SetDelegate(delegate.get());
246
247 EXPECT_FALSE(stream->HasUrl());
248
249 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
250 (*headers)[":path"] = url.path();
251 (*headers)[":host"] = url.host();
252 (*headers)[":version"] = "WebSocket/13";
253 (*headers)[":scheme"] = url.scheme();
254 (*headers)[":origin"] = "http://example.com";
255 stream->set_spdy_headers(headers.Pass());
256 EXPECT_TRUE(stream->HasUrl());
257
258 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true));
259
260 EXPECT_EQ(OK, callback.WaitForResult());
261
262 EXPECT_TRUE(delegate->send_headers_completed());
263 EXPECT_EQ("101", (*delegate->response())[":status"]);
[email protected]050b3602012-08-15 04:10:49264 EXPECT_EQ(1, delegate->headers_sent());
[email protected]0837bc62012-08-03 07:31:26265 EXPECT_EQ(std::string(), delegate->received_data());
[email protected]050b3602012-08-15 04:10:49266 EXPECT_EQ(6, delegate->data_sent());
[email protected]0837bc62012-08-03 07:31:26267}
268
[email protected]448d4ca52012-03-04 04:12:23269TEST_F(SpdyStreamSpdy3Test, PushedStream) {
[email protected]a7a265ef2010-12-08 18:05:57270 const char kStreamUrl[] = "http://www.google.com/";
271
272 SpdySessionDependencies session_deps;
273 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps);
274 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool());
275 scoped_refptr<SpdySession> spdy_session(CreateSpdySession());
[email protected]0e861e92012-03-15 18:42:19276
277 MockRead reads[] = {
278 MockRead(ASYNC, 0, 0), // EOF
279 };
280
[email protected]dd54bd82012-07-19 23:44:57281 OrderedSocketData data(reads, arraysize(reads), NULL, 0);
[email protected]0e861e92012-03-15 18:42:19282 MockConnect connect_data(SYNCHRONOUS, OK);
[email protected]dd54bd82012-07-19 23:44:57283 data.set_connect_data(connect_data);
[email protected]0e861e92012-03-15 18:42:19284
[email protected]dd54bd82012-07-19 23:44:57285 session_deps.socket_factory->AddSocketDataProvider(&data);
[email protected]0e861e92012-03-15 18:42:19286
287 HostPortPair host_port_pair("www.google.com", 80);
288 scoped_refptr<TransportSocketParams> transport_params(
[email protected]d2b5f092012-06-08 23:55:02289 new TransportSocketParams(host_port_pair, LOWEST, false, false,
290 OnHostResolutionCallback()));
291
[email protected]0e861e92012-03-15 18:42:19292 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
293 EXPECT_EQ(OK, connection->Init(host_port_pair.ToString(), transport_params,
294 LOWEST, CompletionCallback(),
[email protected]e5c026642012-03-17 00:14:02295 session_->GetTransportSocketPool(
296 HttpNetworkSession::NORMAL_SOCKET_POOL),
[email protected]0e861e92012-03-15 18:42:19297 BoundNetLog()));
298 spdy_session->InitializeWithSocket(connection.release(), false, OK);
[email protected]a7a265ef2010-12-08 18:05:57299 BoundNetLog net_log;
300
301 // Conjure up a stream.
302 scoped_refptr<SpdyStream> stream = new SpdyStream(spdy_session,
[email protected]a7a265ef2010-12-08 18:05:57303 true,
304 net_log);
[email protected]c92f4b4542012-07-26 23:53:21305 stream->set_stream_id(2);
[email protected]a7a265ef2010-12-08 18:05:57306 EXPECT_FALSE(stream->response_received());
307 EXPECT_FALSE(stream->HasUrl());
308
309 // Set a couple of headers.
[email protected]ff98d7f02012-03-22 21:44:19310 SpdyHeaderBlock response;
[email protected]0e861e92012-03-15 18:42:19311 GURL url(kStreamUrl);
312 response[":host"] = url.host();
313 response[":scheme"] = url.scheme();
314 response[":path"] = url.path();
[email protected]a7a265ef2010-12-08 18:05:57315 stream->OnResponseReceived(response);
316
317 // Send some basic headers.
[email protected]ff98d7f02012-03-22 21:44:19318 SpdyHeaderBlock headers;
[email protected]d42dedd02012-04-03 19:42:06319 response[":status"] = "200";
320 response[":version"] = "OK";
[email protected]a7a265ef2010-12-08 18:05:57321 stream->OnHeaders(headers);
322
323 stream->set_response_received();
324 EXPECT_TRUE(stream->response_received());
325 EXPECT_TRUE(stream->HasUrl());
326 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec());
327}
328
[email protected]448d4ca52012-03-04 04:12:23329TEST_F(SpdyStreamSpdy3Test, StreamError) {
[email protected]d245c342012-02-23 20:49:15330 SpdySessionDependencies session_deps;
331
332 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps);
333 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool());
334
335 const SpdyHeaderInfo kSynStartHeader = {
[email protected]ff98d7f02012-03-22 21:44:19336 SYN_STREAM,
[email protected]d245c342012-02-23 20:49:15337 1,
338 0,
[email protected]72074442012-04-17 20:51:57339 ConvertRequestPriorityToSpdyPriority(LOWEST, 3),
[email protected]1eb81432012-03-24 06:48:00340 0,
[email protected]ff98d7f02012-03-22 21:44:19341 CONTROL_FLAG_NONE,
[email protected]d245c342012-02-23 20:49:15342 false,
[email protected]5a7bb252013-02-09 00:21:05343 RST_STREAM_INVALID,
[email protected]d245c342012-02-23 20:49:15344 NULL,
345 0,
[email protected]ff98d7f02012-03-22 21:44:19346 DATA_FLAG_NONE
[email protected]d245c342012-02-23 20:49:15347 };
348 static const char* const kGetHeaders[] = {
[email protected]0e861e92012-03-15 18:42:19349 ":method",
[email protected]d245c342012-02-23 20:49:15350 "GET",
[email protected]0e861e92012-03-15 18:42:19351 ":scheme",
[email protected]d245c342012-02-23 20:49:15352 "http",
[email protected]0e861e92012-03-15 18:42:19353 ":host",
[email protected]d245c342012-02-23 20:49:15354 "www.google.com",
[email protected]0e861e92012-03-15 18:42:19355 ":path",
[email protected]d245c342012-02-23 20:49:15356 "/",
[email protected]0e861e92012-03-15 18:42:19357 ":version",
[email protected]d245c342012-02-23 20:49:15358 "HTTP/1.1",
359 };
[email protected]ff98d7f02012-03-22 21:44:19360 scoped_ptr<SpdyFrame> req(
[email protected]d245c342012-02-23 20:49:15361 ConstructSpdyPacket(
362 kSynStartHeader, NULL, 0, kGetHeaders, arraysize(kGetHeaders) / 2));
[email protected]ff98d7f02012-03-22 21:44:19363 scoped_ptr<SpdyFrame> msg(
[email protected]d245c342012-02-23 20:49:15364 ConstructSpdyBodyFrame("\0hello!\xff", 8));
365 MockWrite writes[] = {
366 CreateMockWrite(*req),
367 CreateMockWrite(*msg),
368 };
369 writes[0].sequence_number = 0;
370 writes[1].sequence_number = 2;
371
[email protected]ff98d7f02012-03-22 21:44:19372 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
373 scoped_ptr<SpdyFrame> echo(
[email protected]d245c342012-02-23 20:49:15374 ConstructSpdyBodyFrame("\0hello!\xff", 8));
375 MockRead reads[] = {
376 CreateMockRead(*resp),
377 CreateMockRead(*echo),
378 MockRead(ASYNC, 0, 0), // EOF
379 };
380 reads[0].sequence_number = 1;
381 reads[1].sequence_number = 3;
382 reads[2].sequence_number = 4;
383
[email protected]333bdf62012-06-08 22:57:29384 CapturingBoundNetLog log;
[email protected]d245c342012-02-23 20:49:15385
[email protected]dd54bd82012-07-19 23:44:57386 OrderedSocketData data(reads, arraysize(reads),
387 writes, arraysize(writes));
[email protected]d245c342012-02-23 20:49:15388 MockConnect connect_data(SYNCHRONOUS, OK);
[email protected]dd54bd82012-07-19 23:44:57389 data.set_connect_data(connect_data);
[email protected]d245c342012-02-23 20:49:15390
[email protected]dd54bd82012-07-19 23:44:57391 session_deps.socket_factory->AddSocketDataProvider(&data);
[email protected]d245c342012-02-23 20:49:15392
393 scoped_refptr<SpdySession> session(CreateSpdySession());
394 const char* kStreamUrl = "http://www.google.com/";
395 GURL url(kStreamUrl);
396
397 HostPortPair host_port_pair("www.google.com", 80);
398 scoped_refptr<TransportSocketParams> transport_params(
[email protected]d2b5f092012-06-08 23:55:02399 new TransportSocketParams(host_port_pair, LOWEST, false, false,
400 OnHostResolutionCallback()));
[email protected]d245c342012-02-23 20:49:15401
402 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
403 EXPECT_EQ(OK, connection->Init(host_port_pair.ToString(), transport_params,
404 LOWEST, CompletionCallback(),
[email protected]e5c026642012-03-17 00:14:02405 session_->GetTransportSocketPool(
406 HttpNetworkSession::NORMAL_SOCKET_POOL),
[email protected]d245c342012-02-23 20:49:15407 log.bound()));
408 session->InitializeWithSocket(connection.release(), false, OK);
409
410 scoped_refptr<SpdyStream> stream;
411 ASSERT_EQ(
412 OK,
413 session->CreateStream(url, LOWEST, &stream, log.bound(),
414 CompletionCallback()));
415 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(8));
416 memcpy(buf->data(), "\0hello!\xff", 8);
417 TestCompletionCallback callback;
418
419 scoped_ptr<TestSpdyStreamDelegate> delegate(
[email protected]0837bc62012-08-03 07:31:26420 new TestSpdyStreamDelegate(
421 stream.get(), NULL, buf.get(), callback.callback()));
[email protected]d245c342012-02-23 20:49:15422 stream->SetDelegate(delegate.get());
423
424 EXPECT_FALSE(stream->HasUrl());
425
[email protected]0a01d890fc2012-07-18 17:24:05426 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
[email protected]0e861e92012-03-15 18:42:19427 (*headers)[":method"] = "GET";
428 (*headers)[":scheme"] = url.scheme();
429 (*headers)[":host"] = url.host();
430 (*headers)[":path"] = url.path();
431 (*headers)[":version"] = "HTTP/1.1";
[email protected]0a01d890fc2012-07-18 17:24:05432 stream->set_spdy_headers(headers.Pass());
[email protected]d245c342012-02-23 20:49:15433 EXPECT_TRUE(stream->HasUrl());
434 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec());
435
436 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true));
437
[email protected]218f4b62012-07-20 20:12:41438 EXPECT_EQ(OK, callback.WaitForResult());
439
[email protected]c92f4b4542012-07-26 23:53:21440 const SpdyStreamId stream_id = stream->stream_id();
441
[email protected]d245c342012-02-23 20:49:15442 EXPECT_TRUE(delegate->send_headers_completed());
[email protected]d42dedd02012-04-03 19:42:06443 EXPECT_EQ("200", (*delegate->response())[":status"]);
444 EXPECT_EQ("HTTP/1.1", (*delegate->response())[":version"]);
[email protected]d245c342012-02-23 20:49:15445 EXPECT_EQ(std::string("\0hello!\xff", 8), delegate->received_data());
446 EXPECT_EQ(8, delegate->data_sent());
447 EXPECT_TRUE(delegate->closed());
448
449 // Check that the NetLog was filled reasonably.
[email protected]f3da152d2012-06-02 01:00:57450 net::CapturingNetLog::CapturedEntryList entries;
[email protected]d245c342012-02-23 20:49:15451 log.GetEntries(&entries);
452 EXPECT_LT(0u, entries.size());
453
454 // Check that we logged SPDY_STREAM_ERROR correctly.
455 int pos = net::ExpectLogContainsSomewhere(
456 entries, 0,
457 net::NetLog::TYPE_SPDY_STREAM_ERROR,
458 net::NetLog::PHASE_NONE);
459
[email protected]f3da152d2012-06-02 01:00:57460 int stream_id2;
461 ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &stream_id2));
462 EXPECT_EQ(static_cast<int>(stream_id), stream_id2);
[email protected]d245c342012-02-23 20:49:15463}
[email protected]a7a265ef2010-12-08 18:05:57464
[email protected]1e5ebd82013-02-20 20:07:24465// Call IncreaseSendWindowSize on a stream with a large enough delta
466// to overflow an int32. The SpdyStream should handle that case
467// gracefully.
468TEST_F(SpdyStreamSpdy3Test, IncreaseSendWindowSizeOverflow) {
469 SpdySessionDependencies session_deps;
470
471 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps);
472 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool());
473
474 MockRead reads[] = {
475 MockRead(ASYNC, 0, 1), // EOF
476 };
477
478 // Triggered by the overflowing call to IncreaseSendWindowSize
479 // below.
480 scoped_ptr<SpdyFrame> rst(
481 ConstructSpdyRstStream(0, RST_STREAM_FLOW_CONTROL_ERROR));
482 MockWrite writes[] = {
483 CreateMockWrite(*rst),
484 };
485 writes[0].sequence_number = 0;
486
487 CapturingBoundNetLog log;
488
489 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
490 MockConnect connect_data(SYNCHRONOUS, OK);
491 data.set_connect_data(connect_data);
492
493 session_deps.socket_factory->AddSocketDataProvider(&data);
494
495 scoped_refptr<SpdySession> session(CreateSpdySession());
496 const char kStreamUrl[] = "http://www.google.com/";
497 GURL url(kStreamUrl);
498
499 HostPortPair host_port_pair("www.google.com", 80);
500 scoped_refptr<TransportSocketParams> transport_params(
501 new TransportSocketParams(host_port_pair, LOWEST, false, false,
502 OnHostResolutionCallback()));
503
504 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
505 EXPECT_EQ(OK, connection->Init(host_port_pair.ToString(), transport_params,
506 LOWEST, CompletionCallback(),
507 session_->GetTransportSocketPool(
508 HttpNetworkSession::NORMAL_SOCKET_POOL),
509 log.bound()));
510 session->InitializeWithSocket(connection.release(), false, OK);
511
512 scoped_refptr<SpdyStream> stream;
513 ASSERT_EQ(
514 OK,
515 session->CreateStream(url, LOWEST, &stream, log.bound(),
516 CompletionCallback()));
517 TestCompletionCallback callback;
518
519 scoped_ptr<TestSpdyStreamDelegate> delegate(
520 new TestSpdyStreamDelegate(
521 stream.get(), NULL, new IOBufferWithSize(8), callback.callback()));
522 stream->SetDelegate(delegate.get());
523
524 EXPECT_FALSE(stream->HasUrl());
525 EXPECT_EQ(0u, stream->stream_id());
526 EXPECT_FALSE(stream->closed());
527
528 int32 old_send_window_size = stream->send_window_size();
529 ASSERT_GT(old_send_window_size, 0);
530 int32 delta_window_size = kint32max - old_send_window_size + 1;
531 stream->IncreaseSendWindowSize(delta_window_size);
532 EXPECT_EQ(old_send_window_size, stream->send_window_size());
533
534 EXPECT_EQ(OK, callback.WaitForResult());
535}
536
[email protected]39d13d942012-07-19 16:48:20537} // namespace test
538
[email protected]4f386422010-07-20 04:19:49539} // namespace net