blob: e0cbc3a38bf5e1253f97d9d304049f053347582e [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]e3861ca2013-03-02 01:00:4513#include "net/spdy/spdy_test_util_common.h"
[email protected]448d4ca52012-03-04 04:12:2314#include "net/spdy/spdy_test_util_spdy3.h"
[email protected]5e248dc2012-08-21 02:27:3215#include "net/spdy/spdy_websocket_test_util_spdy3.h"
[email protected]4f386422010-07-20 04:19:4916#include "testing/gtest/include/gtest/gtest.h"
17
[email protected]448d4ca52012-03-04 04:12:2318using namespace net::test_spdy3;
19
[email protected]4f386422010-07-20 04:19:4920// TODO(ukai): factor out common part with spdy_http_stream_unittest.cc
[email protected]b9ec6882011-07-01 07:40:2621//
22namespace net {
[email protected]4f386422010-07-20 04:19:4923
24namespace {
25
[email protected]ff98d7f02012-03-22 21:44:1926SpdyFrame* ConstructSpdyBodyFrame(const char* data, int length) {
[email protected]f9cf5572012-12-04 15:52:0927 BufferedSpdyFramer framer(3, false);
[email protected]ff98d7f02012-03-22 21:44:1928 return framer.CreateDataFrame(1, data, length, DATA_FLAG_NONE);
[email protected]4f386422010-07-20 04:19:4929}
30
31} // anonymous namespace
32
[email protected]39d13d942012-07-19 16:48:2033namespace test {
34
[email protected]448d4ca52012-03-04 04:12:2335class SpdyStreamSpdy3Test : public testing::Test {
[email protected]4f386422010-07-20 04:19:4936 protected:
[email protected]448d4ca52012-03-04 04:12:2337 SpdyStreamSpdy3Test() {
[email protected]4f386422010-07-20 04:19:4938 }
39
40 scoped_refptr<SpdySession> CreateSpdySession() {
[email protected]4f386422010-07-20 04:19:4941 HostPortPair host_port_pair("www.google.com", 80);
[email protected]31e68d72010-08-25 06:36:5842 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct());
[email protected]4f386422010-07-20 04:19:4943 scoped_refptr<SpdySession> session(
[email protected]102e27c2011-02-23 01:01:3144 session_->spdy_session_pool()->Get(pair, BoundNetLog()));
[email protected]4f386422010-07-20 04:19:4945 return session;
46 }
47
48 virtual void TearDown() {
[email protected]b4c62eb2012-11-14 18:36:5149 MessageLoop::current()->RunUntilIdle();
[email protected]4f386422010-07-20 04:19:4950 }
51
52 scoped_refptr<HttpNetworkSession> session_;
53};
54
[email protected]448d4ca52012-03-04 04:12:2355TEST_F(SpdyStreamSpdy3Test, SendDataAfterOpen) {
[email protected]30c942b2010-07-21 16:59:5956 SpdySessionDependencies session_deps;
[email protected]4f386422010-07-20 04:19:4957
[email protected]30c942b2010-07-21 16:59:5958 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps);
[email protected]4f386422010-07-20 04:19:4959 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool());
60
61 const SpdyHeaderInfo kSynStartHeader = {
[email protected]ff98d7f02012-03-22 21:44:1962 SYN_STREAM,
[email protected]4f386422010-07-20 04:19:4963 1,
64 0,
[email protected]72074442012-04-17 20:51:5765 ConvertRequestPriorityToSpdyPriority(LOWEST, 3),
[email protected]1eb81432012-03-24 06:48:0066 0,
[email protected]ff98d7f02012-03-22 21:44:1967 CONTROL_FLAG_NONE,
[email protected]4f386422010-07-20 04:19:4968 false,
[email protected]5a7bb252013-02-09 00:21:0569 RST_STREAM_INVALID,
[email protected]4f386422010-07-20 04:19:4970 NULL,
71 0,
[email protected]ff98d7f02012-03-22 21:44:1972 DATA_FLAG_NONE
[email protected]4f386422010-07-20 04:19:4973 };
74 static const char* const kGetHeaders[] = {
[email protected]0e861e92012-03-15 18:42:1975 ":method",
[email protected]4f386422010-07-20 04:19:4976 "GET",
[email protected]0e861e92012-03-15 18:42:1977 ":scheme",
[email protected]a7a265ef2010-12-08 18:05:5778 "http",
[email protected]0e861e92012-03-15 18:42:1979 ":host",
[email protected]a7a265ef2010-12-08 18:05:5780 "www.google.com",
[email protected]0e861e92012-03-15 18:42:1981 ":path",
[email protected]a7a265ef2010-12-08 18:05:5782 "/",
[email protected]0e861e92012-03-15 18:42:1983 ":version",
[email protected]4f386422010-07-20 04:19:4984 "HTTP/1.1",
85 };
[email protected]ff98d7f02012-03-22 21:44:1986 scoped_ptr<SpdyFrame> req(
[email protected]4f386422010-07-20 04:19:4987 ConstructSpdyPacket(
88 kSynStartHeader, NULL, 0, kGetHeaders, arraysize(kGetHeaders) / 2));
[email protected]ff98d7f02012-03-22 21:44:1989 scoped_ptr<SpdyFrame> msg(
[email protected]4f386422010-07-20 04:19:4990 ConstructSpdyBodyFrame("\0hello!\xff", 8));
91 MockWrite writes[] = {
92 CreateMockWrite(*req),
93 CreateMockWrite(*msg),
94 };
95 writes[0].sequence_number = 0;
96 writes[1].sequence_number = 2;
97
[email protected]ff98d7f02012-03-22 21:44:1998 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
99 scoped_ptr<SpdyFrame> echo(
[email protected]4f386422010-07-20 04:19:49100 ConstructSpdyBodyFrame("\0hello!\xff", 8));
101 MockRead reads[] = {
102 CreateMockRead(*resp),
103 CreateMockRead(*echo),
[email protected]8ddf8322012-02-23 18:08:06104 MockRead(ASYNC, 0, 0), // EOF
[email protected]4f386422010-07-20 04:19:49105 };
106 reads[0].sequence_number = 1;
107 reads[1].sequence_number = 3;
108 reads[2].sequence_number = 4;
109
[email protected]dd54bd82012-07-19 23:44:57110 OrderedSocketData data(reads, arraysize(reads),
111 writes, arraysize(writes));
[email protected]d973e99a2012-02-17 21:02:36112 MockConnect connect_data(SYNCHRONOUS, OK);
[email protected]dd54bd82012-07-19 23:44:57113 data.set_connect_data(connect_data);
[email protected]4f386422010-07-20 04:19:49114
[email protected]dd54bd82012-07-19 23:44:57115 session_deps.socket_factory->AddSocketDataProvider(&data);
[email protected]4f386422010-07-20 04:19:49116
117 scoped_refptr<SpdySession> session(CreateSpdySession());
[email protected]a7a265ef2010-12-08 18:05:57118 const char* kStreamUrl = "http://www.google.com/";
119 GURL url(kStreamUrl);
[email protected]4f386422010-07-20 04:19:49120
121 HostPortPair host_port_pair("www.google.com", 80);
[email protected]ab739042011-04-07 15:22:28122 scoped_refptr<TransportSocketParams> transport_params(
[email protected]d2b5f092012-06-08 23:55:02123 new TransportSocketParams(host_port_pair, LOWEST, false, false,
124 OnHostResolutionCallback()));
[email protected]02b0c342010-09-25 21:09:38125
126 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
[email protected]6ecf2b92011-12-15 01:14:52127 EXPECT_EQ(OK, connection->Init(host_port_pair.ToString(), transport_params,
128 LOWEST, CompletionCallback(),
[email protected]e5c026642012-03-17 00:14:02129 session_->GetTransportSocketPool(
130 HttpNetworkSession::NORMAL_SOCKET_POOL),
[email protected]6ecf2b92011-12-15 01:14:52131 BoundNetLog()));
[email protected]02b0c342010-09-25 21:09:38132 session->InitializeWithSocket(connection.release(), false, OK);
[email protected]4f386422010-07-20 04:19:49133
[email protected]e3861ca2013-03-02 01:00:45134
135 scoped_refptr<SpdyStream> stream =
136 CreateStreamSynchronously(session, url, LOWEST, BoundNetLog());
137 ASSERT_TRUE(stream.get() != NULL);
[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
[email protected]e3861ca2013-03-02 01:00:45227 scoped_refptr<SpdyStream> stream =
228 CreateStreamSynchronously(session, url, HIGHEST, BoundNetLog());
229 ASSERT_TRUE(stream.get() != NULL);
[email protected]0837bc62012-08-03 07:31:26230 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(6));
231 memcpy(buf->data(), "hello!", 6);
232 TestCompletionCallback callback;
233 scoped_ptr<SpdyHeaderBlock> message_headers(new SpdyHeaderBlock);
234 (*message_headers)[":opcode"] = "1";
235 (*message_headers)[":length"] = "6";
236 (*message_headers)[":fin"] = "1";
237
238 scoped_ptr<TestSpdyStreamDelegate> delegate(
239 new TestSpdyStreamDelegate(stream.get(),
240 message_headers.release(),
241 buf.get(),
242 callback.callback()));
243 stream->SetDelegate(delegate.get());
244
245 EXPECT_FALSE(stream->HasUrl());
246
247 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
248 (*headers)[":path"] = url.path();
249 (*headers)[":host"] = url.host();
250 (*headers)[":version"] = "WebSocket/13";
251 (*headers)[":scheme"] = url.scheme();
252 (*headers)[":origin"] = "http://example.com";
253 stream->set_spdy_headers(headers.Pass());
254 EXPECT_TRUE(stream->HasUrl());
255
256 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true));
257
258 EXPECT_EQ(OK, callback.WaitForResult());
259
260 EXPECT_TRUE(delegate->send_headers_completed());
261 EXPECT_EQ("101", (*delegate->response())[":status"]);
[email protected]050b3602012-08-15 04:10:49262 EXPECT_EQ(1, delegate->headers_sent());
[email protected]0837bc62012-08-03 07:31:26263 EXPECT_EQ(std::string(), delegate->received_data());
[email protected]050b3602012-08-15 04:10:49264 EXPECT_EQ(6, delegate->data_sent());
[email protected]0837bc62012-08-03 07:31:26265}
266
[email protected]448d4ca52012-03-04 04:12:23267TEST_F(SpdyStreamSpdy3Test, PushedStream) {
[email protected]a7a265ef2010-12-08 18:05:57268 const char kStreamUrl[] = "http://www.google.com/";
269
270 SpdySessionDependencies session_deps;
271 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps);
272 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool());
273 scoped_refptr<SpdySession> spdy_session(CreateSpdySession());
[email protected]0e861e92012-03-15 18:42:19274
275 MockRead reads[] = {
276 MockRead(ASYNC, 0, 0), // EOF
277 };
278
[email protected]dd54bd82012-07-19 23:44:57279 OrderedSocketData data(reads, arraysize(reads), NULL, 0);
[email protected]0e861e92012-03-15 18:42:19280 MockConnect connect_data(SYNCHRONOUS, OK);
[email protected]dd54bd82012-07-19 23:44:57281 data.set_connect_data(connect_data);
[email protected]0e861e92012-03-15 18:42:19282
[email protected]dd54bd82012-07-19 23:44:57283 session_deps.socket_factory->AddSocketDataProvider(&data);
[email protected]0e861e92012-03-15 18:42:19284
285 HostPortPair host_port_pair("www.google.com", 80);
286 scoped_refptr<TransportSocketParams> transport_params(
[email protected]d2b5f092012-06-08 23:55:02287 new TransportSocketParams(host_port_pair, LOWEST, false, false,
288 OnHostResolutionCallback()));
289
[email protected]0e861e92012-03-15 18:42:19290 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
291 EXPECT_EQ(OK, connection->Init(host_port_pair.ToString(), transport_params,
292 LOWEST, CompletionCallback(),
[email protected]e5c026642012-03-17 00:14:02293 session_->GetTransportSocketPool(
294 HttpNetworkSession::NORMAL_SOCKET_POOL),
[email protected]0e861e92012-03-15 18:42:19295 BoundNetLog()));
296 spdy_session->InitializeWithSocket(connection.release(), false, OK);
[email protected]a7a265ef2010-12-08 18:05:57297 BoundNetLog net_log;
298
299 // Conjure up a stream.
300 scoped_refptr<SpdyStream> stream = new SpdyStream(spdy_session,
[email protected]a7a265ef2010-12-08 18:05:57301 true,
302 net_log);
[email protected]c92f4b4542012-07-26 23:53:21303 stream->set_stream_id(2);
[email protected]a7a265ef2010-12-08 18:05:57304 EXPECT_FALSE(stream->response_received());
305 EXPECT_FALSE(stream->HasUrl());
306
307 // Set a couple of headers.
[email protected]ff98d7f02012-03-22 21:44:19308 SpdyHeaderBlock response;
[email protected]0e861e92012-03-15 18:42:19309 GURL url(kStreamUrl);
310 response[":host"] = url.host();
311 response[":scheme"] = url.scheme();
312 response[":path"] = url.path();
[email protected]a7a265ef2010-12-08 18:05:57313 stream->OnResponseReceived(response);
314
315 // Send some basic headers.
[email protected]ff98d7f02012-03-22 21:44:19316 SpdyHeaderBlock headers;
[email protected]d42dedd02012-04-03 19:42:06317 response[":status"] = "200";
318 response[":version"] = "OK";
[email protected]a7a265ef2010-12-08 18:05:57319 stream->OnHeaders(headers);
320
321 stream->set_response_received();
322 EXPECT_TRUE(stream->response_received());
323 EXPECT_TRUE(stream->HasUrl());
324 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec());
325}
326
[email protected]448d4ca52012-03-04 04:12:23327TEST_F(SpdyStreamSpdy3Test, StreamError) {
[email protected]d245c342012-02-23 20:49:15328 SpdySessionDependencies session_deps;
329
330 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps);
331 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool());
332
333 const SpdyHeaderInfo kSynStartHeader = {
[email protected]ff98d7f02012-03-22 21:44:19334 SYN_STREAM,
[email protected]d245c342012-02-23 20:49:15335 1,
336 0,
[email protected]72074442012-04-17 20:51:57337 ConvertRequestPriorityToSpdyPriority(LOWEST, 3),
[email protected]1eb81432012-03-24 06:48:00338 0,
[email protected]ff98d7f02012-03-22 21:44:19339 CONTROL_FLAG_NONE,
[email protected]d245c342012-02-23 20:49:15340 false,
[email protected]5a7bb252013-02-09 00:21:05341 RST_STREAM_INVALID,
[email protected]d245c342012-02-23 20:49:15342 NULL,
343 0,
[email protected]ff98d7f02012-03-22 21:44:19344 DATA_FLAG_NONE
[email protected]d245c342012-02-23 20:49:15345 };
346 static const char* const kGetHeaders[] = {
[email protected]0e861e92012-03-15 18:42:19347 ":method",
[email protected]d245c342012-02-23 20:49:15348 "GET",
[email protected]0e861e92012-03-15 18:42:19349 ":scheme",
[email protected]d245c342012-02-23 20:49:15350 "http",
[email protected]0e861e92012-03-15 18:42:19351 ":host",
[email protected]d245c342012-02-23 20:49:15352 "www.google.com",
[email protected]0e861e92012-03-15 18:42:19353 ":path",
[email protected]d245c342012-02-23 20:49:15354 "/",
[email protected]0e861e92012-03-15 18:42:19355 ":version",
[email protected]d245c342012-02-23 20:49:15356 "HTTP/1.1",
357 };
[email protected]ff98d7f02012-03-22 21:44:19358 scoped_ptr<SpdyFrame> req(
[email protected]d245c342012-02-23 20:49:15359 ConstructSpdyPacket(
360 kSynStartHeader, NULL, 0, kGetHeaders, arraysize(kGetHeaders) / 2));
[email protected]ff98d7f02012-03-22 21:44:19361 scoped_ptr<SpdyFrame> msg(
[email protected]d245c342012-02-23 20:49:15362 ConstructSpdyBodyFrame("\0hello!\xff", 8));
363 MockWrite writes[] = {
364 CreateMockWrite(*req),
365 CreateMockWrite(*msg),
366 };
367 writes[0].sequence_number = 0;
368 writes[1].sequence_number = 2;
369
[email protected]ff98d7f02012-03-22 21:44:19370 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
371 scoped_ptr<SpdyFrame> echo(
[email protected]d245c342012-02-23 20:49:15372 ConstructSpdyBodyFrame("\0hello!\xff", 8));
373 MockRead reads[] = {
374 CreateMockRead(*resp),
375 CreateMockRead(*echo),
376 MockRead(ASYNC, 0, 0), // EOF
377 };
378 reads[0].sequence_number = 1;
379 reads[1].sequence_number = 3;
380 reads[2].sequence_number = 4;
381
[email protected]333bdf62012-06-08 22:57:29382 CapturingBoundNetLog log;
[email protected]d245c342012-02-23 20:49:15383
[email protected]dd54bd82012-07-19 23:44:57384 OrderedSocketData data(reads, arraysize(reads),
385 writes, arraysize(writes));
[email protected]d245c342012-02-23 20:49:15386 MockConnect connect_data(SYNCHRONOUS, OK);
[email protected]dd54bd82012-07-19 23:44:57387 data.set_connect_data(connect_data);
[email protected]d245c342012-02-23 20:49:15388
[email protected]dd54bd82012-07-19 23:44:57389 session_deps.socket_factory->AddSocketDataProvider(&data);
[email protected]d245c342012-02-23 20:49:15390
391 scoped_refptr<SpdySession> session(CreateSpdySession());
392 const char* kStreamUrl = "http://www.google.com/";
393 GURL url(kStreamUrl);
394
395 HostPortPair host_port_pair("www.google.com", 80);
396 scoped_refptr<TransportSocketParams> transport_params(
[email protected]d2b5f092012-06-08 23:55:02397 new TransportSocketParams(host_port_pair, LOWEST, false, false,
398 OnHostResolutionCallback()));
[email protected]d245c342012-02-23 20:49:15399
400 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
401 EXPECT_EQ(OK, connection->Init(host_port_pair.ToString(), transport_params,
402 LOWEST, CompletionCallback(),
[email protected]e5c026642012-03-17 00:14:02403 session_->GetTransportSocketPool(
404 HttpNetworkSession::NORMAL_SOCKET_POOL),
[email protected]d245c342012-02-23 20:49:15405 log.bound()));
406 session->InitializeWithSocket(connection.release(), false, OK);
407
[email protected]e3861ca2013-03-02 01:00:45408 scoped_refptr<SpdyStream> stream =
409 CreateStreamSynchronously(session, url, LOWEST, log.bound());
410 ASSERT_TRUE(stream.get() != NULL);
[email protected]d245c342012-02-23 20:49:15411 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(8));
412 memcpy(buf->data(), "\0hello!\xff", 8);
413 TestCompletionCallback callback;
414
415 scoped_ptr<TestSpdyStreamDelegate> delegate(
[email protected]0837bc62012-08-03 07:31:26416 new TestSpdyStreamDelegate(
417 stream.get(), NULL, buf.get(), callback.callback()));
[email protected]d245c342012-02-23 20:49:15418 stream->SetDelegate(delegate.get());
419
420 EXPECT_FALSE(stream->HasUrl());
421
[email protected]0a01d890fc2012-07-18 17:24:05422 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
[email protected]0e861e92012-03-15 18:42:19423 (*headers)[":method"] = "GET";
424 (*headers)[":scheme"] = url.scheme();
425 (*headers)[":host"] = url.host();
426 (*headers)[":path"] = url.path();
427 (*headers)[":version"] = "HTTP/1.1";
[email protected]0a01d890fc2012-07-18 17:24:05428 stream->set_spdy_headers(headers.Pass());
[email protected]d245c342012-02-23 20:49:15429 EXPECT_TRUE(stream->HasUrl());
430 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec());
431
432 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true));
433
[email protected]218f4b62012-07-20 20:12:41434 EXPECT_EQ(OK, callback.WaitForResult());
435
[email protected]c92f4b4542012-07-26 23:53:21436 const SpdyStreamId stream_id = stream->stream_id();
437
[email protected]d245c342012-02-23 20:49:15438 EXPECT_TRUE(delegate->send_headers_completed());
[email protected]d42dedd02012-04-03 19:42:06439 EXPECT_EQ("200", (*delegate->response())[":status"]);
440 EXPECT_EQ("HTTP/1.1", (*delegate->response())[":version"]);
[email protected]d245c342012-02-23 20:49:15441 EXPECT_EQ(std::string("\0hello!\xff", 8), delegate->received_data());
442 EXPECT_EQ(8, delegate->data_sent());
443 EXPECT_TRUE(delegate->closed());
444
445 // Check that the NetLog was filled reasonably.
[email protected]f3da152d2012-06-02 01:00:57446 net::CapturingNetLog::CapturedEntryList entries;
[email protected]d245c342012-02-23 20:49:15447 log.GetEntries(&entries);
448 EXPECT_LT(0u, entries.size());
449
450 // Check that we logged SPDY_STREAM_ERROR correctly.
451 int pos = net::ExpectLogContainsSomewhere(
452 entries, 0,
453 net::NetLog::TYPE_SPDY_STREAM_ERROR,
454 net::NetLog::PHASE_NONE);
455
[email protected]f3da152d2012-06-02 01:00:57456 int stream_id2;
457 ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &stream_id2));
458 EXPECT_EQ(static_cast<int>(stream_id), stream_id2);
[email protected]d245c342012-02-23 20:49:15459}
[email protected]a7a265ef2010-12-08 18:05:57460
[email protected]1e5ebd82013-02-20 20:07:24461// Call IncreaseSendWindowSize on a stream with a large enough delta
462// to overflow an int32. The SpdyStream should handle that case
463// gracefully.
464TEST_F(SpdyStreamSpdy3Test, IncreaseSendWindowSizeOverflow) {
465 SpdySessionDependencies session_deps;
466
467 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps);
468 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool());
469
470 MockRead reads[] = {
471 MockRead(ASYNC, 0, 1), // EOF
472 };
473
474 // Triggered by the overflowing call to IncreaseSendWindowSize
475 // below.
476 scoped_ptr<SpdyFrame> rst(
477 ConstructSpdyRstStream(0, RST_STREAM_FLOW_CONTROL_ERROR));
478 MockWrite writes[] = {
479 CreateMockWrite(*rst),
480 };
481 writes[0].sequence_number = 0;
482
483 CapturingBoundNetLog log;
484
485 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
486 MockConnect connect_data(SYNCHRONOUS, OK);
487 data.set_connect_data(connect_data);
488
489 session_deps.socket_factory->AddSocketDataProvider(&data);
490
491 scoped_refptr<SpdySession> session(CreateSpdySession());
492 const char kStreamUrl[] = "http://www.google.com/";
493 GURL url(kStreamUrl);
494
495 HostPortPair host_port_pair("www.google.com", 80);
496 scoped_refptr<TransportSocketParams> transport_params(
497 new TransportSocketParams(host_port_pair, LOWEST, false, false,
498 OnHostResolutionCallback()));
499
500 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
501 EXPECT_EQ(OK, connection->Init(host_port_pair.ToString(), transport_params,
502 LOWEST, CompletionCallback(),
503 session_->GetTransportSocketPool(
504 HttpNetworkSession::NORMAL_SOCKET_POOL),
505 log.bound()));
506 session->InitializeWithSocket(connection.release(), false, OK);
507
[email protected]e3861ca2013-03-02 01:00:45508 scoped_refptr<SpdyStream> stream =
509 CreateStreamSynchronously(session, url, LOWEST, log.bound());
510 ASSERT_TRUE(stream.get() != NULL);
[email protected]1e5ebd82013-02-20 20:07:24511 TestCompletionCallback callback;
512
513 scoped_ptr<TestSpdyStreamDelegate> delegate(
514 new TestSpdyStreamDelegate(
515 stream.get(), NULL, new IOBufferWithSize(8), callback.callback()));
516 stream->SetDelegate(delegate.get());
517
518 EXPECT_FALSE(stream->HasUrl());
519 EXPECT_EQ(0u, stream->stream_id());
520 EXPECT_FALSE(stream->closed());
521
522 int32 old_send_window_size = stream->send_window_size();
523 ASSERT_GT(old_send_window_size, 0);
524 int32 delta_window_size = kint32max - old_send_window_size + 1;
525 stream->IncreaseSendWindowSize(delta_window_size);
526 EXPECT_EQ(old_send_window_size, stream->send_window_size());
527
528 EXPECT_EQ(OK, callback.WaitForResult());
529}
530
[email protected]39d13d942012-07-19 16:48:20531} // namespace test
532
[email protected]4f386422010-07-20 04:19:49533} // namespace net