[email protected] | a159531 | 2012-01-22 03:25:04 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 5 | #include "base/basictypes.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 6 | #include "base/memory/ref_counted.h" |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 7 | #include "base/memory/scoped_ptr.h" |
[email protected] | d069c11a | 2013-04-13 00:01:55 | [diff] [blame] | 8 | #include "base/strings/string_piece.h" |
[email protected] | 5a76b81 | 2011-12-21 20:52:00 | [diff] [blame] | 9 | #include "net/base/completion_callback.h" |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 10 | #include "net/base/net_log_unittest.h" |
[email protected] | 1bbabc8 | 2013-03-25 21:11:02 | [diff] [blame] | 11 | #include "net/base/request_priority.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12 | #include "net/socket/next_proto.h" |
[email protected] | f54c8579 | 2012-03-08 19:06:41 | [diff] [blame] | 13 | #include "net/spdy/buffered_spdy_framer.h" |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 14 | #include "net/spdy/spdy_http_utils.h" |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 15 | #include "net/spdy/spdy_protocol.h" |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 16 | #include "net/spdy/spdy_session.h" |
[email protected] | d069c11a | 2013-04-13 00:01:55 | [diff] [blame] | 17 | #include "net/spdy/spdy_stream.h" |
[email protected] | 39d13d94 | 2012-07-19 16:48:20 | [diff] [blame] | 18 | #include "net/spdy/spdy_stream_test_util.h" |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 19 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 20 | #include "net/spdy/spdy_test_util_spdy3.h" |
[email protected] | 5e248dc | 2012-08-21 02:27:32 | [diff] [blame] | 21 | #include "net/spdy/spdy_websocket_test_util_spdy3.h" |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 22 | #include "testing/gtest/include/gtest/gtest.h" |
| 23 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 24 | using namespace net::test_spdy3; |
| 25 | |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 26 | // TODO(ukai): factor out common part with spdy_http_stream_unittest.cc |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 27 | // |
| 28 | namespace net { |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 29 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 30 | namespace test { |
| 31 | |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 32 | namespace { |
| 33 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 34 | const char kStreamUrl[] = "http://www.google.com/"; |
| 35 | const char kPostBody[] = "\0hello!\xff"; |
| 36 | const size_t kPostBodyLength = arraysize(kPostBody); |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 37 | const base::StringPiece kPostBodyStringPiece(kPostBody, kPostBodyLength); |
[email protected] | 39d13d94 | 2012-07-19 16:48:20 | [diff] [blame] | 38 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 39 | class SpdyStreamSpdy3Test : public testing::Test { |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 40 | protected: |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 41 | SpdyStreamSpdy3Test() |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame^] | 42 | : spdy_util_(kProtoSPDY3), |
| 43 | host_port_pair_("www.google.com", 80), |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 44 | session_deps_(kProtoSPDY3) {} |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 45 | |
| 46 | scoped_refptr<SpdySession> CreateSpdySession() { |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 47 | HostPortProxyPair pair(host_port_pair_, ProxyServer::Direct()); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 48 | scoped_refptr<SpdySession> session( |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 49 | session_->spdy_session_pool()->Get(pair, BoundNetLog())); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 50 | return session; |
| 51 | } |
| 52 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 53 | void InitializeSpdySession(const scoped_refptr<SpdySession>& session, |
| 54 | const HostPortPair& host_port_pair) { |
| 55 | scoped_refptr<TransportSocketParams> transport_params( |
| 56 | new TransportSocketParams(host_port_pair, LOWEST, false, false, |
| 57 | OnHostResolutionCallback())); |
| 58 | |
| 59 | scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 60 | EXPECT_EQ(OK, connection->Init(host_port_pair.ToString(), transport_params, |
| 61 | LOWEST, CompletionCallback(), |
| 62 | session_->GetTransportSocketPool( |
| 63 | HttpNetworkSession::NORMAL_SOCKET_POOL), |
| 64 | BoundNetLog())); |
| 65 | session->InitializeWithSocket(connection.release(), false, OK); |
| 66 | } |
| 67 | |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 68 | virtual void TearDown() { |
[email protected] | b4c62eb | 2012-11-14 18:36:51 | [diff] [blame] | 69 | MessageLoop::current()->RunUntilIdle(); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 70 | } |
| 71 | |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame^] | 72 | SpdyTestUtil spdy_util_; |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 73 | HostPortPair host_port_pair_; |
| 74 | SpdySessionDependencies session_deps_; |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 75 | scoped_refptr<HttpNetworkSession> session_; |
| 76 | }; |
| 77 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 78 | TEST_F(SpdyStreamSpdy3Test, SendDataAfterOpen) { |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 79 | GURL url(kStreamUrl); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 80 | session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 81 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 82 | scoped_ptr<SpdyFrame> req( |
| 83 | ConstructSpdyPost(kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0)); |
| 84 | scoped_ptr<SpdyFrame> msg( |
| 85 | ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 86 | MockWrite writes[] = { |
| 87 | CreateMockWrite(*req), |
| 88 | CreateMockWrite(*msg), |
| 89 | }; |
| 90 | writes[0].sequence_number = 0; |
| 91 | writes[1].sequence_number = 2; |
| 92 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 93 | scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 94 | scoped_ptr<SpdyFrame> echo( |
| 95 | ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 96 | MockRead reads[] = { |
| 97 | CreateMockRead(*resp), |
| 98 | CreateMockRead(*echo), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 99 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 100 | }; |
| 101 | reads[0].sequence_number = 1; |
| 102 | reads[1].sequence_number = 3; |
| 103 | reads[2].sequence_number = 4; |
| 104 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 105 | OrderedSocketData data(reads, arraysize(reads), |
| 106 | writes, arraysize(writes)); |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 107 | MockConnect connect_data(SYNCHRONOUS, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 108 | data.set_connect_data(connect_data); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 109 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 110 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 111 | |
| 112 | scoped_refptr<SpdySession> session(CreateSpdySession()); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 113 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 114 | InitializeSpdySession(session, host_port_pair_); |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 115 | |
| 116 | scoped_refptr<SpdyStream> stream = |
| 117 | CreateStreamSynchronously(session, url, LOWEST, BoundNetLog()); |
| 118 | ASSERT_TRUE(stream.get() != NULL); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 119 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 120 | StreamDelegateSendImmediate delegate( |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 121 | stream.get(), scoped_ptr<SpdyHeaderBlock>(), kPostBodyStringPiece); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 122 | stream->SetDelegate(&delegate); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 123 | |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 124 | EXPECT_FALSE(stream->HasUrl()); |
| 125 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 126 | stream->set_spdy_headers( |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame^] | 127 | spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 128 | EXPECT_TRUE(stream->HasUrl()); |
| 129 | EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 130 | |
[email protected] | a5c493b9 | 2010-08-06 23:04:29 | [diff] [blame] | 131 | EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 132 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 133 | EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 134 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 135 | EXPECT_TRUE(delegate.send_headers_completed()); |
| 136 | EXPECT_EQ("200", delegate.GetResponseHeaderValue(":status")); |
| 137 | EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue(":version")); |
[email protected] | 09a8d917 | 2013-04-17 19:23:49 | [diff] [blame] | 138 | EXPECT_EQ(std::string(kPostBody, kPostBodyLength), |
| 139 | delegate.TakeReceivedData()); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 140 | EXPECT_EQ(static_cast<int>(kPostBodyLength), delegate.data_sent()); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 141 | } |
| 142 | |
[email protected] | 0837bc6 | 2012-08-03 07:31:26 | [diff] [blame] | 143 | TEST_F(SpdyStreamSpdy3Test, SendHeaderAndDataAfterOpen) { |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 144 | session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
[email protected] | 0837bc6 | 2012-08-03 07:31:26 | [diff] [blame] | 145 | |
[email protected] | 5e248dc | 2012-08-21 02:27:32 | [diff] [blame] | 146 | scoped_ptr<SpdyFrame> expected_request(ConstructSpdyWebSocketSynStream( |
[email protected] | 0837bc6 | 2012-08-03 07:31:26 | [diff] [blame] | 147 | 1, |
| 148 | "/chat", |
| 149 | "server.example.com", |
| 150 | "http://example.com")); |
| 151 | scoped_ptr<SpdyFrame> expected_headers(ConstructSpdyWebSocketHeadersFrame( |
| 152 | 1, "6", true)); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 153 | scoped_ptr<SpdyFrame> expected_message( |
| 154 | ConstructSpdyBodyFrame(1, "hello!", 6, false)); |
[email protected] | 0837bc6 | 2012-08-03 07:31:26 | [diff] [blame] | 155 | MockWrite writes[] = { |
| 156 | CreateMockWrite(*expected_request), |
| 157 | CreateMockWrite(*expected_headers), |
| 158 | CreateMockWrite(*expected_message) |
| 159 | }; |
| 160 | writes[0].sequence_number = 0; |
| 161 | writes[1].sequence_number = 2; |
| 162 | writes[1].sequence_number = 3; |
| 163 | |
| 164 | scoped_ptr<SpdyFrame> response( |
| 165 | ConstructSpdyWebSocketSynReply(1)); |
| 166 | MockRead reads[] = { |
| 167 | CreateMockRead(*response), |
| 168 | MockRead(ASYNC, 0, 0), // EOF |
| 169 | }; |
| 170 | reads[0].sequence_number = 1; |
| 171 | reads[1].sequence_number = 4; |
| 172 | |
| 173 | OrderedSocketData data(reads, arraysize(reads), |
| 174 | writes, arraysize(writes)); |
| 175 | MockConnect connect_data(SYNCHRONOUS, OK); |
| 176 | data.set_connect_data(connect_data); |
| 177 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 178 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 0837bc6 | 2012-08-03 07:31:26 | [diff] [blame] | 179 | |
| 180 | scoped_refptr<SpdySession> session(CreateSpdySession()); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 181 | GURL url("ws://server.example.com/chat"); |
[email protected] | 0837bc6 | 2012-08-03 07:31:26 | [diff] [blame] | 182 | |
| 183 | HostPortPair host_port_pair("server.example.com", 80); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 184 | InitializeSpdySession(session, host_port_pair); |
[email protected] | 0837bc6 | 2012-08-03 07:31:26 | [diff] [blame] | 185 | |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 186 | scoped_refptr<SpdyStream> stream = |
| 187 | CreateStreamSynchronously(session, url, HIGHEST, BoundNetLog()); |
| 188 | ASSERT_TRUE(stream.get() != NULL); |
[email protected] | 0837bc6 | 2012-08-03 07:31:26 | [diff] [blame] | 189 | TestCompletionCallback callback; |
| 190 | scoped_ptr<SpdyHeaderBlock> message_headers(new SpdyHeaderBlock); |
| 191 | (*message_headers)[":opcode"] = "1"; |
| 192 | (*message_headers)[":length"] = "6"; |
| 193 | (*message_headers)[":fin"] = "1"; |
| 194 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 195 | StreamDelegateSendImmediate delegate( |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 196 | stream.get(), message_headers.Pass(), base::StringPiece("hello!", 6)); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 197 | stream->SetDelegate(&delegate); |
[email protected] | 0837bc6 | 2012-08-03 07:31:26 | [diff] [blame] | 198 | |
| 199 | EXPECT_FALSE(stream->HasUrl()); |
| 200 | |
| 201 | scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); |
| 202 | (*headers)[":path"] = url.path(); |
| 203 | (*headers)[":host"] = url.host(); |
| 204 | (*headers)[":version"] = "WebSocket/13"; |
| 205 | (*headers)[":scheme"] = url.scheme(); |
| 206 | (*headers)[":origin"] = "http://example.com"; |
| 207 | stream->set_spdy_headers(headers.Pass()); |
| 208 | EXPECT_TRUE(stream->HasUrl()); |
| 209 | |
| 210 | EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
| 211 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 212 | EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
[email protected] | 0837bc6 | 2012-08-03 07:31:26 | [diff] [blame] | 213 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 214 | EXPECT_TRUE(delegate.send_headers_completed()); |
| 215 | EXPECT_EQ("101", delegate.GetResponseHeaderValue(":status")); |
| 216 | EXPECT_EQ(1, delegate.headers_sent()); |
[email protected] | 09a8d917 | 2013-04-17 19:23:49 | [diff] [blame] | 217 | EXPECT_EQ(std::string(), delegate.TakeReceivedData()); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 218 | EXPECT_EQ(6, delegate.data_sent()); |
[email protected] | 0837bc6 | 2012-08-03 07:31:26 | [diff] [blame] | 219 | } |
| 220 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 221 | TEST_F(SpdyStreamSpdy3Test, PushedStream) { |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 222 | session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 223 | scoped_refptr<SpdySession> spdy_session(CreateSpdySession()); |
[email protected] | 0e861e9 | 2012-03-15 18:42:19 | [diff] [blame] | 224 | |
| 225 | MockRead reads[] = { |
| 226 | MockRead(ASYNC, 0, 0), // EOF |
| 227 | }; |
| 228 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 229 | OrderedSocketData data(reads, arraysize(reads), NULL, 0); |
[email protected] | 0e861e9 | 2012-03-15 18:42:19 | [diff] [blame] | 230 | MockConnect connect_data(SYNCHRONOUS, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 231 | data.set_connect_data(connect_data); |
[email protected] | 0e861e9 | 2012-03-15 18:42:19 | [diff] [blame] | 232 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 233 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 0e861e9 | 2012-03-15 18:42:19 | [diff] [blame] | 234 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 235 | InitializeSpdySession(spdy_session, host_port_pair_); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 236 | BoundNetLog net_log; |
| 237 | |
| 238 | // Conjure up a stream. |
[email protected] | 1bbabc8 | 2013-03-25 21:11:02 | [diff] [blame] | 239 | scoped_refptr<SpdyStream> stream = |
| 240 | new SpdyStream(spdy_session, |
| 241 | std::string(), |
| 242 | DEFAULT_PRIORITY, |
| 243 | kSpdyStreamInitialWindowSize, |
| 244 | kSpdyStreamInitialWindowSize, |
| 245 | true, |
| 246 | net_log); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 247 | stream->set_stream_id(2); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 248 | EXPECT_FALSE(stream->response_received()); |
| 249 | EXPECT_FALSE(stream->HasUrl()); |
| 250 | |
| 251 | // Set a couple of headers. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 252 | SpdyHeaderBlock response; |
[email protected] | 0e861e9 | 2012-03-15 18:42:19 | [diff] [blame] | 253 | GURL url(kStreamUrl); |
| 254 | response[":host"] = url.host(); |
| 255 | response[":scheme"] = url.scheme(); |
| 256 | response[":path"] = url.path(); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 257 | stream->OnResponseReceived(response); |
| 258 | |
| 259 | // Send some basic headers. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 260 | SpdyHeaderBlock headers; |
[email protected] | d42dedd0 | 2012-04-03 19:42:06 | [diff] [blame] | 261 | response[":status"] = "200"; |
| 262 | response[":version"] = "OK"; |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 263 | stream->OnHeaders(headers); |
| 264 | |
| 265 | stream->set_response_received(); |
| 266 | EXPECT_TRUE(stream->response_received()); |
| 267 | EXPECT_TRUE(stream->HasUrl()); |
| 268 | EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
| 269 | } |
| 270 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 271 | TEST_F(SpdyStreamSpdy3Test, StreamError) { |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 272 | GURL url(kStreamUrl); |
| 273 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 274 | session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 275 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 276 | scoped_ptr<SpdyFrame> req( |
| 277 | ConstructSpdyPost(kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0)); |
| 278 | scoped_ptr<SpdyFrame> msg( |
| 279 | ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 280 | MockWrite writes[] = { |
| 281 | CreateMockWrite(*req), |
| 282 | CreateMockWrite(*msg), |
| 283 | }; |
| 284 | writes[0].sequence_number = 0; |
| 285 | writes[1].sequence_number = 2; |
| 286 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 287 | scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 288 | scoped_ptr<SpdyFrame> echo( |
| 289 | ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 290 | MockRead reads[] = { |
| 291 | CreateMockRead(*resp), |
| 292 | CreateMockRead(*echo), |
| 293 | MockRead(ASYNC, 0, 0), // EOF |
| 294 | }; |
| 295 | reads[0].sequence_number = 1; |
| 296 | reads[1].sequence_number = 3; |
| 297 | reads[2].sequence_number = 4; |
| 298 | |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 299 | CapturingBoundNetLog log; |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 300 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 301 | OrderedSocketData data(reads, arraysize(reads), |
| 302 | writes, arraysize(writes)); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 303 | MockConnect connect_data(SYNCHRONOUS, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 304 | data.set_connect_data(connect_data); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 305 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 306 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 307 | |
| 308 | scoped_refptr<SpdySession> session(CreateSpdySession()); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 309 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 310 | InitializeSpdySession(session, host_port_pair_); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 311 | |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 312 | scoped_refptr<SpdyStream> stream = |
| 313 | CreateStreamSynchronously(session, url, LOWEST, log.bound()); |
| 314 | ASSERT_TRUE(stream.get() != NULL); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 315 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 316 | StreamDelegateSendImmediate delegate( |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 317 | stream.get(), scoped_ptr<SpdyHeaderBlock>(), kPostBodyStringPiece); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 318 | stream->SetDelegate(&delegate); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 319 | |
| 320 | EXPECT_FALSE(stream->HasUrl()); |
| 321 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 322 | stream->set_spdy_headers( |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame^] | 323 | spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 324 | EXPECT_TRUE(stream->HasUrl()); |
| 325 | EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
| 326 | |
| 327 | EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
| 328 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 329 | EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
[email protected] | 218f4b6 | 2012-07-20 20:12:41 | [diff] [blame] | 330 | |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 331 | const SpdyStreamId stream_id = stream->stream_id(); |
| 332 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 333 | EXPECT_TRUE(delegate.send_headers_completed()); |
| 334 | EXPECT_EQ("200", delegate.GetResponseHeaderValue(":status")); |
| 335 | EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue(":version")); |
[email protected] | 09a8d917 | 2013-04-17 19:23:49 | [diff] [blame] | 336 | EXPECT_EQ(std::string(kPostBody, kPostBodyLength), |
| 337 | delegate.TakeReceivedData()); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 338 | EXPECT_EQ(static_cast<int>(kPostBodyLength), delegate.data_sent()); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 339 | |
| 340 | // Check that the NetLog was filled reasonably. |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 341 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 342 | log.GetEntries(&entries); |
| 343 | EXPECT_LT(0u, entries.size()); |
| 344 | |
| 345 | // Check that we logged SPDY_STREAM_ERROR correctly. |
| 346 | int pos = net::ExpectLogContainsSomewhere( |
| 347 | entries, 0, |
| 348 | net::NetLog::TYPE_SPDY_STREAM_ERROR, |
| 349 | net::NetLog::PHASE_NONE); |
| 350 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 351 | int stream_id2; |
| 352 | ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &stream_id2)); |
| 353 | EXPECT_EQ(static_cast<int>(stream_id), stream_id2); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 354 | } |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 355 | |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 356 | // Call IncreaseSendWindowSize on a stream with a large enough delta |
| 357 | // to overflow an int32. The SpdyStream should handle that case |
| 358 | // gracefully. |
| 359 | TEST_F(SpdyStreamSpdy3Test, IncreaseSendWindowSizeOverflow) { |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 360 | session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 361 | |
| 362 | MockRead reads[] = { |
| 363 | MockRead(ASYNC, 0, 1), // EOF |
| 364 | }; |
| 365 | |
| 366 | // Triggered by the overflowing call to IncreaseSendWindowSize |
| 367 | // below. |
| 368 | scoped_ptr<SpdyFrame> rst( |
| 369 | ConstructSpdyRstStream(0, RST_STREAM_FLOW_CONTROL_ERROR)); |
| 370 | MockWrite writes[] = { |
| 371 | CreateMockWrite(*rst), |
| 372 | }; |
| 373 | writes[0].sequence_number = 0; |
| 374 | |
| 375 | CapturingBoundNetLog log; |
| 376 | |
| 377 | OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 378 | MockConnect connect_data(SYNCHRONOUS, OK); |
| 379 | data.set_connect_data(connect_data); |
| 380 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 381 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 382 | |
| 383 | scoped_refptr<SpdySession> session(CreateSpdySession()); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 384 | GURL url(kStreamUrl); |
| 385 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 386 | InitializeSpdySession(session, host_port_pair_); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 387 | |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 388 | scoped_refptr<SpdyStream> stream = |
| 389 | CreateStreamSynchronously(session, url, LOWEST, log.bound()); |
| 390 | ASSERT_TRUE(stream.get() != NULL); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 391 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 392 | StreamDelegateSendImmediate delegate( |
| 393 | stream.get(), scoped_ptr<SpdyHeaderBlock>(), kPostBodyStringPiece); |
| 394 | stream->SetDelegate(&delegate); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 395 | |
| 396 | EXPECT_FALSE(stream->HasUrl()); |
| 397 | EXPECT_EQ(0u, stream->stream_id()); |
| 398 | EXPECT_FALSE(stream->closed()); |
| 399 | |
| 400 | int32 old_send_window_size = stream->send_window_size(); |
| 401 | ASSERT_GT(old_send_window_size, 0); |
| 402 | int32 delta_window_size = kint32max - old_send_window_size + 1; |
| 403 | stream->IncreaseSendWindowSize(delta_window_size); |
| 404 | EXPECT_EQ(old_send_window_size, stream->send_window_size()); |
| 405 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 406 | EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 407 | } |
| 408 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 409 | // Cause a send stall by reducing the flow control send window to |
| 410 | // 0. The stream should resume when that window is then increased. |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 411 | TEST_F(SpdyStreamSpdy3Test, ResumeAfterSendWindowSizeIncrease) { |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 412 | GURL url(kStreamUrl); |
| 413 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 414 | session_ = |
| 415 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_); |
| 416 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 417 | scoped_ptr<SpdyFrame> req( |
| 418 | ConstructSpdyPost(kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0)); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 419 | scoped_ptr<SpdyFrame> msg( |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 420 | ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 421 | MockWrite writes[] = { |
| 422 | CreateMockWrite(*req, 0), |
| 423 | CreateMockWrite(*msg, 2), |
| 424 | }; |
| 425 | |
| 426 | scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 427 | scoped_ptr<SpdyFrame> echo( |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 428 | ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 429 | MockRead reads[] = { |
| 430 | CreateMockRead(*resp, 1), |
| 431 | CreateMockRead(*echo, 3), |
| 432 | MockRead(ASYNC, 0, 0, 4), // EOF |
| 433 | }; |
| 434 | |
| 435 | DeterministicSocketData data(reads, arraysize(reads), |
| 436 | writes, arraysize(writes)); |
| 437 | MockConnect connect_data(SYNCHRONOUS, OK); |
| 438 | data.set_connect_data(connect_data); |
| 439 | |
| 440 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 441 | |
| 442 | scoped_refptr<SpdySession> session(CreateSpdySession()); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 443 | |
| 444 | InitializeSpdySession(session, host_port_pair_); |
| 445 | |
| 446 | scoped_refptr<SpdyStream> stream = |
| 447 | CreateStreamSynchronously(session, url, LOWEST, BoundNetLog()); |
| 448 | ASSERT_TRUE(stream.get() != NULL); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 449 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 450 | StreamDelegateWithBody delegate(stream.get(), kPostBodyStringPiece); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 451 | stream->SetDelegate(&delegate); |
| 452 | |
| 453 | EXPECT_FALSE(stream->HasUrl()); |
| 454 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 455 | stream->set_spdy_headers( |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame^] | 456 | spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 457 | EXPECT_TRUE(stream->HasUrl()); |
| 458 | EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
| 459 | |
| 460 | EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
| 461 | |
| 462 | data.RunFor(2); |
| 463 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 464 | EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 465 | |
| 466 | // Reduce the send window size to 0 to stall. |
| 467 | while (stream->send_window_size() > 0) { |
| 468 | stream->DecreaseSendWindowSize( |
| 469 | std::min(kMaxSpdyFrameChunkSize, stream->send_window_size())); |
| 470 | } |
| 471 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 472 | EXPECT_EQ(ERR_IO_PENDING, delegate.OnSendBody()); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 473 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 474 | EXPECT_TRUE(stream->send_stalled_by_flow_control()); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 475 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 476 | stream->IncreaseSendWindowSize(kPostBodyLength); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 477 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 478 | EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 479 | |
| 480 | data.RunFor(3); |
| 481 | |
| 482 | EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
| 483 | |
| 484 | EXPECT_TRUE(delegate.send_headers_completed()); |
| 485 | EXPECT_EQ("200", delegate.GetResponseHeaderValue(":status")); |
| 486 | EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue(":version")); |
[email protected] | 09a8d917 | 2013-04-17 19:23:49 | [diff] [blame] | 487 | EXPECT_EQ(std::string(kPostBody, kPostBodyLength), |
| 488 | delegate.TakeReceivedData()); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 489 | EXPECT_EQ(static_cast<int>(kPostBodyLength), delegate.body_data_sent()); |
| 490 | } |
| 491 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 492 | // Cause a send stall by reducing the flow control send window to |
| 493 | // 0. The stream should resume when that window is then adjusted |
| 494 | // positively. |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 495 | TEST_F(SpdyStreamSpdy3Test, ResumeAfterSendWindowSizeAdjust) { |
| 496 | GURL url(kStreamUrl); |
| 497 | |
| 498 | session_ = |
| 499 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_); |
| 500 | |
| 501 | scoped_ptr<SpdyFrame> req( |
| 502 | ConstructSpdyPost(kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0)); |
| 503 | scoped_ptr<SpdyFrame> msg( |
| 504 | ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); |
| 505 | MockWrite writes[] = { |
| 506 | CreateMockWrite(*req, 0), |
| 507 | CreateMockWrite(*msg, 2), |
| 508 | }; |
| 509 | |
| 510 | scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 511 | scoped_ptr<SpdyFrame> echo( |
| 512 | ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); |
| 513 | MockRead reads[] = { |
| 514 | CreateMockRead(*resp, 1), |
| 515 | CreateMockRead(*echo, 3), |
| 516 | MockRead(ASYNC, 0, 0, 4), // EOF |
| 517 | }; |
| 518 | |
| 519 | DeterministicSocketData data(reads, arraysize(reads), |
| 520 | writes, arraysize(writes)); |
| 521 | MockConnect connect_data(SYNCHRONOUS, OK); |
| 522 | data.set_connect_data(connect_data); |
| 523 | |
| 524 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 525 | |
| 526 | scoped_refptr<SpdySession> session(CreateSpdySession()); |
| 527 | |
| 528 | InitializeSpdySession(session, host_port_pair_); |
| 529 | |
| 530 | scoped_refptr<SpdyStream> stream = |
| 531 | CreateStreamSynchronously(session, url, LOWEST, BoundNetLog()); |
| 532 | ASSERT_TRUE(stream.get() != NULL); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 533 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 534 | StreamDelegateWithBody delegate(stream.get(), kPostBodyStringPiece); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 535 | stream->SetDelegate(&delegate); |
| 536 | |
| 537 | EXPECT_FALSE(stream->HasUrl()); |
| 538 | |
| 539 | stream->set_spdy_headers( |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame^] | 540 | spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 541 | EXPECT_TRUE(stream->HasUrl()); |
| 542 | EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
| 543 | |
| 544 | EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
| 545 | |
| 546 | data.RunFor(2); |
| 547 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 548 | EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 549 | |
| 550 | // Reduce the send window size to 0 to stall. |
| 551 | while (stream->send_window_size() > 0) { |
| 552 | stream->DecreaseSendWindowSize( |
| 553 | std::min(kMaxSpdyFrameChunkSize, stream->send_window_size())); |
| 554 | } |
| 555 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 556 | EXPECT_EQ(ERR_IO_PENDING, delegate.OnSendBody()); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 557 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 558 | EXPECT_TRUE(stream->send_stalled_by_flow_control()); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 559 | |
| 560 | stream->AdjustSendWindowSize(-static_cast<int>(kPostBodyLength)); |
| 561 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 562 | EXPECT_TRUE(stream->send_stalled_by_flow_control()); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 563 | |
| 564 | stream->AdjustSendWindowSize(kPostBodyLength); |
| 565 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 566 | EXPECT_TRUE(stream->send_stalled_by_flow_control()); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 567 | |
| 568 | stream->AdjustSendWindowSize(kPostBodyLength); |
| 569 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 570 | EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 571 | |
| 572 | data.RunFor(3); |
| 573 | |
| 574 | EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
| 575 | |
| 576 | EXPECT_TRUE(delegate.send_headers_completed()); |
| 577 | EXPECT_EQ("200", delegate.GetResponseHeaderValue(":status")); |
| 578 | EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue(":version")); |
[email protected] | 09a8d917 | 2013-04-17 19:23:49 | [diff] [blame] | 579 | EXPECT_EQ(std::string(kPostBody, kPostBodyLength), |
| 580 | delegate.TakeReceivedData()); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 581 | EXPECT_EQ(static_cast<int>(kPostBodyLength), delegate.body_data_sent()); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | } // namespace |
| 585 | |
[email protected] | 39d13d94 | 2012-07-19 16:48:20 | [diff] [blame] | 586 | } // namespace test |
| 587 | |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 588 | } // namespace net |