[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] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 8 | #include "base/memory/weak_ptr.h" |
[email protected] | d069c11a | 2013-04-13 00:01:55 | [diff] [blame] | 9 | #include "base/strings/string_piece.h" |
[email protected] | 5a76b81 | 2011-12-21 20:52:00 | [diff] [blame] | 10 | #include "net/base/completion_callback.h" |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 11 | #include "net/base/net_log_unittest.h" |
[email protected] | 1bbabc8 | 2013-03-25 21:11:02 | [diff] [blame] | 12 | #include "net/base/request_priority.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13 | #include "net/socket/next_proto.h" |
[email protected] | f54c8579 | 2012-03-08 19:06:41 | [diff] [blame] | 14 | #include "net/spdy/buffered_spdy_framer.h" |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 15 | #include "net/spdy/spdy_http_utils.h" |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 16 | #include "net/spdy/spdy_protocol.h" |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 17 | #include "net/spdy/spdy_session.h" |
[email protected] | d069c11a | 2013-04-13 00:01:55 | [diff] [blame] | 18 | #include "net/spdy/spdy_stream.h" |
[email protected] | 39d13d94 | 2012-07-19 16:48:20 | [diff] [blame] | 19 | #include "net/spdy/spdy_stream_test_util.h" |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 20 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 21 | #include "net/spdy/spdy_test_util_spdy3.h" |
[email protected] | 5e248dc | 2012-08-21 02:27:32 | [diff] [blame] | 22 | #include "net/spdy/spdy_websocket_test_util_spdy3.h" |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 23 | #include "testing/gtest/include/gtest/gtest.h" |
| 24 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 25 | using namespace net::test_spdy3; |
| 26 | |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 27 | // TODO(ukai): factor out common part with spdy_http_stream_unittest.cc |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 28 | // |
| 29 | namespace net { |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 30 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 31 | namespace test { |
| 32 | |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 33 | namespace { |
| 34 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 35 | const char kStreamUrl[] = "http://www.google.com/"; |
| 36 | const char kPostBody[] = "\0hello!\xff"; |
| 37 | const size_t kPostBodyLength = arraysize(kPostBody); |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 38 | const base::StringPiece kPostBodyStringPiece(kPostBody, kPostBodyLength); |
[email protected] | 39d13d94 | 2012-07-19 16:48:20 | [diff] [blame] | 39 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 40 | class SpdyStreamSpdy3Test : public testing::Test { |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 41 | protected: |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 42 | // A function that takes a SpdyStream and the number of bytes which |
| 43 | // will unstall the next frame completely. |
| 44 | typedef base::Callback<void(const base::WeakPtr<SpdyStream>&, int32)> |
| 45 | UnstallFunction; |
| 46 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 47 | SpdyStreamSpdy3Test() |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame] | 48 | : spdy_util_(kProtoSPDY3), |
| 49 | host_port_pair_("www.google.com", 80), |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 50 | session_deps_(kProtoSPDY3) {} |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 51 | |
| 52 | scoped_refptr<SpdySession> CreateSpdySession() { |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 53 | SpdySessionKey key(host_port_pair_, ProxyServer::Direct(), |
| 54 | kPrivacyModeDisabled); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 55 | scoped_refptr<SpdySession> session( |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 56 | session_->spdy_session_pool()->Get(key, BoundNetLog())); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 57 | return session; |
| 58 | } |
| 59 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 60 | void InitializeSpdySession(const scoped_refptr<SpdySession>& session, |
| 61 | const HostPortPair& host_port_pair) { |
| 62 | scoped_refptr<TransportSocketParams> transport_params( |
| 63 | new TransportSocketParams(host_port_pair, LOWEST, false, false, |
| 64 | OnHostResolutionCallback())); |
| 65 | |
| 66 | scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 67 | EXPECT_EQ(OK, connection->Init(host_port_pair.ToString(), transport_params, |
| 68 | LOWEST, CompletionCallback(), |
| 69 | session_->GetTransportSocketPool( |
| 70 | HttpNetworkSession::NORMAL_SOCKET_POOL), |
| 71 | BoundNetLog())); |
| 72 | session->InitializeWithSocket(connection.release(), false, OK); |
| 73 | } |
| 74 | |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 75 | virtual void TearDown() { |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 76 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 77 | } |
| 78 | |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 79 | void RunResumeAfterUnstallRequestResponseTest( |
| 80 | const UnstallFunction& unstall_function); |
| 81 | |
| 82 | void RunResumeAfterUnstallBidirectionalTest( |
| 83 | const UnstallFunction& unstall_function); |
| 84 | |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame] | 85 | SpdyTestUtil spdy_util_; |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 86 | HostPortPair host_port_pair_; |
| 87 | SpdySessionDependencies session_deps_; |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 88 | scoped_refptr<HttpNetworkSession> session_; |
| 89 | }; |
| 90 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 91 | TEST_F(SpdyStreamSpdy3Test, SendDataAfterOpen) { |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 92 | GURL url(kStreamUrl); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 93 | session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 94 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 95 | scoped_ptr<SpdyFrame> req( |
| 96 | ConstructSpdyPost(kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0)); |
| 97 | scoped_ptr<SpdyFrame> msg( |
| 98 | ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 99 | MockWrite writes[] = { |
| 100 | CreateMockWrite(*req), |
| 101 | CreateMockWrite(*msg), |
| 102 | }; |
| 103 | writes[0].sequence_number = 0; |
| 104 | writes[1].sequence_number = 2; |
| 105 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 106 | scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 107 | scoped_ptr<SpdyFrame> echo( |
| 108 | ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 109 | MockRead reads[] = { |
| 110 | CreateMockRead(*resp), |
| 111 | CreateMockRead(*echo), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 112 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 113 | }; |
| 114 | reads[0].sequence_number = 1; |
| 115 | reads[1].sequence_number = 3; |
| 116 | reads[2].sequence_number = 4; |
| 117 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 118 | OrderedSocketData data(reads, arraysize(reads), |
| 119 | writes, arraysize(writes)); |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 120 | MockConnect connect_data(SYNCHRONOUS, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 121 | data.set_connect_data(connect_data); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 122 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 123 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 124 | |
| 125 | scoped_refptr<SpdySession> session(CreateSpdySession()); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 126 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 127 | InitializeSpdySession(session, host_port_pair_); |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 128 | |
[email protected] | d26ff35 | 2013-05-13 08:48:28 | [diff] [blame] | 129 | base::WeakPtr<SpdyStream> stream = |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 130 | CreateStreamSynchronously(session, url, LOWEST, BoundNetLog()); |
| 131 | ASSERT_TRUE(stream.get() != NULL); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 132 | |
[email protected] | 194cfcf | 2013-05-23 21:44:44 | [diff] [blame^] | 133 | StreamDelegateSendImmediate delegate(stream, kPostBodyStringPiece); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 134 | stream->SetDelegate(&delegate); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 135 | |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 136 | EXPECT_FALSE(stream->HasUrl()); |
| 137 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 138 | stream->set_spdy_headers( |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame] | 139 | spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 140 | EXPECT_TRUE(stream->HasUrl()); |
| 141 | EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 142 | |
[email protected] | a5c493b9 | 2010-08-06 23:04:29 | [diff] [blame] | 143 | EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 144 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 145 | EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 146 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 147 | EXPECT_TRUE(delegate.send_headers_completed()); |
| 148 | EXPECT_EQ("200", delegate.GetResponseHeaderValue(":status")); |
| 149 | EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue(":version")); |
[email protected] | 09a8d917 | 2013-04-17 19:23:49 | [diff] [blame] | 150 | EXPECT_EQ(std::string(kPostBody, kPostBodyLength), |
| 151 | delegate.TakeReceivedData()); |
[email protected] | aa19cfc | 2013-05-23 16:41:38 | [diff] [blame] | 152 | EXPECT_TRUE(data.at_write_eof()); |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 153 | } |
| 154 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 155 | TEST_F(SpdyStreamSpdy3Test, PushedStream) { |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 156 | session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 157 | scoped_refptr<SpdySession> spdy_session(CreateSpdySession()); |
[email protected] | 0e861e9 | 2012-03-15 18:42:19 | [diff] [blame] | 158 | |
| 159 | MockRead reads[] = { |
| 160 | MockRead(ASYNC, 0, 0), // EOF |
| 161 | }; |
| 162 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 163 | OrderedSocketData data(reads, arraysize(reads), NULL, 0); |
[email protected] | 0e861e9 | 2012-03-15 18:42:19 | [diff] [blame] | 164 | MockConnect connect_data(SYNCHRONOUS, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 165 | data.set_connect_data(connect_data); |
[email protected] | 0e861e9 | 2012-03-15 18:42:19 | [diff] [blame] | 166 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 167 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 0e861e9 | 2012-03-15 18:42:19 | [diff] [blame] | 168 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 169 | InitializeSpdySession(spdy_session, host_port_pair_); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 170 | BoundNetLog net_log; |
| 171 | |
| 172 | // Conjure up a stream. |
[email protected] | 1c12c06 | 2013-05-14 23:13:48 | [diff] [blame] | 173 | SpdyStream stream(spdy_session, |
| 174 | std::string(), |
| 175 | DEFAULT_PRIORITY, |
| 176 | kSpdyStreamInitialWindowSize, |
| 177 | kSpdyStreamInitialWindowSize, |
| 178 | true, |
| 179 | net_log); |
| 180 | stream.set_stream_id(2); |
| 181 | EXPECT_FALSE(stream.response_received()); |
| 182 | EXPECT_FALSE(stream.HasUrl()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 183 | |
| 184 | // Set a couple of headers. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 185 | SpdyHeaderBlock response; |
[email protected] | 0e861e9 | 2012-03-15 18:42:19 | [diff] [blame] | 186 | GURL url(kStreamUrl); |
| 187 | response[":host"] = url.host(); |
| 188 | response[":scheme"] = url.scheme(); |
| 189 | response[":path"] = url.path(); |
[email protected] | 1c12c06 | 2013-05-14 23:13:48 | [diff] [blame] | 190 | stream.OnResponseReceived(response); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 191 | |
| 192 | // Send some basic headers. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 193 | SpdyHeaderBlock headers; |
[email protected] | d42dedd0 | 2012-04-03 19:42:06 | [diff] [blame] | 194 | response[":status"] = "200"; |
| 195 | response[":version"] = "OK"; |
[email protected] | 1c12c06 | 2013-05-14 23:13:48 | [diff] [blame] | 196 | stream.OnHeaders(headers); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 197 | |
[email protected] | 1c12c06 | 2013-05-14 23:13:48 | [diff] [blame] | 198 | stream.set_response_received(); |
| 199 | EXPECT_TRUE(stream.response_received()); |
| 200 | EXPECT_TRUE(stream.HasUrl()); |
| 201 | EXPECT_EQ(kStreamUrl, stream.GetUrl().spec()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 202 | } |
| 203 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 204 | TEST_F(SpdyStreamSpdy3Test, StreamError) { |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 205 | GURL url(kStreamUrl); |
| 206 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 207 | session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 208 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 209 | scoped_ptr<SpdyFrame> req( |
| 210 | ConstructSpdyPost(kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0)); |
| 211 | scoped_ptr<SpdyFrame> msg( |
| 212 | ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 213 | MockWrite writes[] = { |
| 214 | CreateMockWrite(*req), |
| 215 | CreateMockWrite(*msg), |
| 216 | }; |
| 217 | writes[0].sequence_number = 0; |
| 218 | writes[1].sequence_number = 2; |
| 219 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 220 | scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 221 | scoped_ptr<SpdyFrame> echo( |
| 222 | ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 223 | MockRead reads[] = { |
| 224 | CreateMockRead(*resp), |
| 225 | CreateMockRead(*echo), |
| 226 | MockRead(ASYNC, 0, 0), // EOF |
| 227 | }; |
| 228 | reads[0].sequence_number = 1; |
| 229 | reads[1].sequence_number = 3; |
| 230 | reads[2].sequence_number = 4; |
| 231 | |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 232 | CapturingBoundNetLog log; |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 233 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 234 | OrderedSocketData data(reads, arraysize(reads), |
| 235 | writes, arraysize(writes)); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 236 | MockConnect connect_data(SYNCHRONOUS, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 237 | data.set_connect_data(connect_data); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 238 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 239 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 240 | |
| 241 | scoped_refptr<SpdySession> session(CreateSpdySession()); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 242 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 243 | InitializeSpdySession(session, host_port_pair_); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 244 | |
[email protected] | d26ff35 | 2013-05-13 08:48:28 | [diff] [blame] | 245 | base::WeakPtr<SpdyStream> stream = |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 246 | CreateStreamSynchronously(session, url, LOWEST, log.bound()); |
| 247 | ASSERT_TRUE(stream.get() != NULL); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 248 | |
[email protected] | 194cfcf | 2013-05-23 21:44:44 | [diff] [blame^] | 249 | StreamDelegateSendImmediate delegate(stream, kPostBodyStringPiece); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 250 | stream->SetDelegate(&delegate); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 251 | |
| 252 | EXPECT_FALSE(stream->HasUrl()); |
| 253 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 254 | stream->set_spdy_headers( |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame] | 255 | spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 256 | EXPECT_TRUE(stream->HasUrl()); |
| 257 | EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
| 258 | |
| 259 | EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
| 260 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 261 | EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
[email protected] | 218f4b6 | 2012-07-20 20:12:41 | [diff] [blame] | 262 | |
[email protected] | d26ff35 | 2013-05-13 08:48:28 | [diff] [blame] | 263 | const SpdyStreamId stream_id = delegate.stream_id(); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 264 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 265 | EXPECT_TRUE(delegate.send_headers_completed()); |
| 266 | EXPECT_EQ("200", delegate.GetResponseHeaderValue(":status")); |
| 267 | EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue(":version")); |
[email protected] | 09a8d917 | 2013-04-17 19:23:49 | [diff] [blame] | 268 | EXPECT_EQ(std::string(kPostBody, kPostBodyLength), |
| 269 | delegate.TakeReceivedData()); |
[email protected] | aa19cfc | 2013-05-23 16:41:38 | [diff] [blame] | 270 | EXPECT_TRUE(data.at_write_eof()); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 271 | |
| 272 | // Check that the NetLog was filled reasonably. |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 273 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 274 | log.GetEntries(&entries); |
| 275 | EXPECT_LT(0u, entries.size()); |
| 276 | |
| 277 | // Check that we logged SPDY_STREAM_ERROR correctly. |
| 278 | int pos = net::ExpectLogContainsSomewhere( |
| 279 | entries, 0, |
| 280 | net::NetLog::TYPE_SPDY_STREAM_ERROR, |
| 281 | net::NetLog::PHASE_NONE); |
| 282 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 283 | int stream_id2; |
| 284 | ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &stream_id2)); |
| 285 | EXPECT_EQ(static_cast<int>(stream_id), stream_id2); |
[email protected] | d245c34 | 2012-02-23 20:49:15 | [diff] [blame] | 286 | } |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 287 | |
[email protected] | aa19cfc | 2013-05-23 16:41:38 | [diff] [blame] | 288 | // Make sure that large blocks of data are properly split up into |
| 289 | // frame-sized chunks for a request/response (i.e., an HTTP-like) |
| 290 | // stream. |
| 291 | TEST_F(SpdyStreamSpdy3Test, SendLargeDataAfterOpenRequestResponse) { |
| 292 | GURL url(kStreamUrl); |
| 293 | |
| 294 | session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
| 295 | |
| 296 | scoped_ptr<SpdyFrame> req( |
| 297 | ConstructSpdyPost(kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0)); |
| 298 | std::string chunk_data(kMaxSpdyFrameChunkSize, 'x'); |
| 299 | scoped_ptr<SpdyFrame> chunk( |
| 300 | ConstructSpdyBodyFrame( |
| 301 | 1, chunk_data.data(), chunk_data.length(), false)); |
| 302 | MockWrite writes[] = { |
| 303 | CreateMockWrite(*req, 0), |
| 304 | CreateMockWrite(*chunk, 1), |
| 305 | CreateMockWrite(*chunk, 2), |
| 306 | CreateMockWrite(*chunk, 3), |
| 307 | }; |
| 308 | |
| 309 | scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); |
| 310 | MockRead reads[] = { |
| 311 | CreateMockRead(*resp, 4), |
| 312 | MockRead(ASYNC, 0, 0, 5), // EOF |
| 313 | }; |
| 314 | |
| 315 | OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 316 | MockConnect connect_data(SYNCHRONOUS, OK); |
| 317 | data.set_connect_data(connect_data); |
| 318 | |
| 319 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 320 | |
| 321 | scoped_refptr<SpdySession> session(CreateSpdySession()); |
| 322 | |
| 323 | InitializeSpdySession(session, host_port_pair_); |
| 324 | |
| 325 | base::WeakPtr<SpdyStream> stream = |
| 326 | CreateStreamSynchronously(session, url, LOWEST, BoundNetLog()); |
| 327 | ASSERT_TRUE(stream.get() != NULL); |
| 328 | |
| 329 | std::string body_data(3 * kMaxSpdyFrameChunkSize, 'x'); |
| 330 | StreamDelegateWithBody delegate(stream, body_data); |
| 331 | stream->SetDelegate(&delegate); |
| 332 | |
| 333 | EXPECT_FALSE(stream->HasUrl()); |
| 334 | |
| 335 | stream->set_spdy_headers( |
| 336 | spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
| 337 | EXPECT_TRUE(stream->HasUrl()); |
| 338 | EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
| 339 | |
| 340 | EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
| 341 | |
| 342 | EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
| 343 | |
| 344 | EXPECT_TRUE(delegate.send_headers_completed()); |
| 345 | EXPECT_EQ("200", delegate.GetResponseHeaderValue(":status")); |
| 346 | EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue(":version")); |
| 347 | EXPECT_EQ(std::string(), delegate.TakeReceivedData()); |
| 348 | EXPECT_TRUE(data.at_write_eof()); |
| 349 | } |
| 350 | |
| 351 | // Make sure that large blocks of data are properly split up into |
| 352 | // frame-sized chunks for a bidirectional (i.e., non-HTTP-like) |
| 353 | // stream. |
| 354 | TEST_F(SpdyStreamSpdy3Test, SendLargeDataAfterOpenBidirectional) { |
| 355 | GURL url(kStreamUrl); |
| 356 | |
| 357 | session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
| 358 | |
| 359 | scoped_ptr<SpdyFrame> req( |
| 360 | ConstructSpdyPost(kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0)); |
| 361 | std::string chunk_data(kMaxSpdyFrameChunkSize, 'x'); |
| 362 | scoped_ptr<SpdyFrame> chunk( |
| 363 | ConstructSpdyBodyFrame( |
| 364 | 1, chunk_data.data(), chunk_data.length(), false)); |
| 365 | MockWrite writes[] = { |
| 366 | CreateMockWrite(*req, 0), |
| 367 | CreateMockWrite(*chunk, 2), |
| 368 | CreateMockWrite(*chunk, 3), |
| 369 | CreateMockWrite(*chunk, 4), |
| 370 | }; |
| 371 | |
| 372 | scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); |
| 373 | MockRead reads[] = { |
| 374 | CreateMockRead(*resp, 1), |
| 375 | MockRead(ASYNC, 0, 0, 5), // EOF |
| 376 | }; |
| 377 | |
| 378 | OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 379 | MockConnect connect_data(SYNCHRONOUS, OK); |
| 380 | data.set_connect_data(connect_data); |
| 381 | |
| 382 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 383 | |
| 384 | scoped_refptr<SpdySession> session(CreateSpdySession()); |
| 385 | |
| 386 | InitializeSpdySession(session, host_port_pair_); |
| 387 | |
| 388 | base::WeakPtr<SpdyStream> stream = |
| 389 | CreateStreamSynchronously(session, url, LOWEST, BoundNetLog()); |
| 390 | ASSERT_TRUE(stream.get() != NULL); |
| 391 | |
| 392 | std::string body_data(3 * kMaxSpdyFrameChunkSize, 'x'); |
[email protected] | 194cfcf | 2013-05-23 21:44:44 | [diff] [blame^] | 393 | StreamDelegateSendImmediate delegate(stream, body_data); |
[email protected] | aa19cfc | 2013-05-23 16:41:38 | [diff] [blame] | 394 | stream->SetDelegate(&delegate); |
| 395 | |
| 396 | EXPECT_FALSE(stream->HasUrl()); |
| 397 | |
| 398 | stream->set_spdy_headers( |
| 399 | spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
| 400 | EXPECT_TRUE(stream->HasUrl()); |
| 401 | EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
| 402 | |
| 403 | EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
| 404 | |
| 405 | EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
| 406 | |
| 407 | EXPECT_TRUE(delegate.send_headers_completed()); |
| 408 | EXPECT_EQ("200", delegate.GetResponseHeaderValue(":status")); |
| 409 | EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue(":version")); |
| 410 | EXPECT_EQ(std::string(), delegate.TakeReceivedData()); |
| 411 | EXPECT_TRUE(data.at_write_eof()); |
| 412 | } |
| 413 | |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 414 | // Call IncreaseSendWindowSize on a stream with a large enough delta |
| 415 | // to overflow an int32. The SpdyStream should handle that case |
| 416 | // gracefully. |
| 417 | TEST_F(SpdyStreamSpdy3Test, IncreaseSendWindowSizeOverflow) { |
[email protected] | 1c12c06 | 2013-05-14 23:13:48 | [diff] [blame] | 418 | session_ = |
| 419 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 420 | |
| 421 | MockRead reads[] = { |
[email protected] | 1c12c06 | 2013-05-14 23:13:48 | [diff] [blame] | 422 | MockRead(ASYNC, 0, 2), // EOF |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 423 | }; |
| 424 | |
[email protected] | 1c12c06 | 2013-05-14 23:13:48 | [diff] [blame] | 425 | scoped_ptr<SpdyFrame> req( |
| 426 | ConstructSpdyPost(kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0)); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 427 | // Triggered by the overflowing call to IncreaseSendWindowSize |
| 428 | // below. |
| 429 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 430 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_FLOW_CONTROL_ERROR)); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 431 | MockWrite writes[] = { |
[email protected] | 1c12c06 | 2013-05-14 23:13:48 | [diff] [blame] | 432 | CreateMockWrite(*req, 0), |
| 433 | CreateMockWrite(*rst, 1), |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 434 | }; |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 435 | |
| 436 | CapturingBoundNetLog log; |
| 437 | |
[email protected] | 1c12c06 | 2013-05-14 23:13:48 | [diff] [blame] | 438 | DeterministicSocketData data( |
| 439 | reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 440 | MockConnect connect_data(SYNCHRONOUS, OK); |
| 441 | data.set_connect_data(connect_data); |
| 442 | |
[email protected] | 1c12c06 | 2013-05-14 23:13:48 | [diff] [blame] | 443 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 444 | |
| 445 | scoped_refptr<SpdySession> session(CreateSpdySession()); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 446 | GURL url(kStreamUrl); |
| 447 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 448 | InitializeSpdySession(session, host_port_pair_); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 449 | |
[email protected] | d26ff35 | 2013-05-13 08:48:28 | [diff] [blame] | 450 | base::WeakPtr<SpdyStream> stream = |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 451 | CreateStreamSynchronously(session, url, LOWEST, log.bound()); |
| 452 | ASSERT_TRUE(stream.get() != NULL); |
[email protected] | 194cfcf | 2013-05-23 21:44:44 | [diff] [blame^] | 453 | StreamDelegateSendImmediate delegate(stream, kPostBodyStringPiece); |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 454 | stream->SetDelegate(&delegate); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 455 | |
[email protected] | 1c12c06 | 2013-05-14 23:13:48 | [diff] [blame] | 456 | stream->set_spdy_headers( |
| 457 | spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
| 458 | EXPECT_TRUE(stream->HasUrl()); |
| 459 | EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
| 460 | |
| 461 | EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
| 462 | |
| 463 | data.RunFor(1); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 464 | |
| 465 | int32 old_send_window_size = stream->send_window_size(); |
| 466 | ASSERT_GT(old_send_window_size, 0); |
| 467 | int32 delta_window_size = kint32max - old_send_window_size + 1; |
| 468 | stream->IncreaseSendWindowSize(delta_window_size); |
[email protected] | 1c12c06 | 2013-05-14 23:13:48 | [diff] [blame] | 469 | EXPECT_EQ(NULL, stream.get()); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 470 | |
[email protected] | 1c12c06 | 2013-05-14 23:13:48 | [diff] [blame] | 471 | data.RunFor(2); |
| 472 | |
| 473 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, delegate.WaitForClose()); |
[email protected] | 1e5ebd8 | 2013-02-20 20:07:24 | [diff] [blame] | 474 | } |
| 475 | |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 476 | // Functions used with |
| 477 | // RunResumeAfterUnstall{RequestResponse,Bidirectional}Test(). |
| 478 | |
| 479 | void StallStream(const base::WeakPtr<SpdyStream>& stream) { |
| 480 | // Reduce the send window size to 0 to stall. |
| 481 | while (stream->send_window_size() > 0) { |
| 482 | stream->DecreaseSendWindowSize( |
| 483 | std::min(kMaxSpdyFrameChunkSize, stream->send_window_size())); |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | void IncreaseStreamSendWindowSize(const base::WeakPtr<SpdyStream>& stream, |
| 488 | int32 delta_window_size) { |
| 489 | EXPECT_TRUE(stream->send_stalled_by_flow_control()); |
| 490 | stream->IncreaseSendWindowSize(delta_window_size); |
| 491 | EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
| 492 | } |
| 493 | |
| 494 | void AdjustStreamSendWindowSize(const base::WeakPtr<SpdyStream>& stream, |
| 495 | int32 delta_window_size) { |
| 496 | // Make sure that negative adjustments are handled properly. |
| 497 | EXPECT_TRUE(stream->send_stalled_by_flow_control()); |
| 498 | stream->AdjustSendWindowSize(-delta_window_size); |
| 499 | EXPECT_TRUE(stream->send_stalled_by_flow_control()); |
| 500 | stream->AdjustSendWindowSize(+delta_window_size); |
| 501 | EXPECT_TRUE(stream->send_stalled_by_flow_control()); |
| 502 | stream->AdjustSendWindowSize(+delta_window_size); |
| 503 | EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
| 504 | } |
| 505 | |
| 506 | // Given an unstall function, runs a test to make sure that a |
| 507 | // request/response (i.e., an HTTP-like) stream resumes after a stall |
| 508 | // and unstall. |
| 509 | void SpdyStreamSpdy3Test::RunResumeAfterUnstallRequestResponseTest( |
| 510 | const UnstallFunction& unstall_function) { |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 511 | GURL url(kStreamUrl); |
| 512 | |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 513 | session_ = |
| 514 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_); |
| 515 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 516 | scoped_ptr<SpdyFrame> req( |
| 517 | ConstructSpdyPost(kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0)); |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 518 | scoped_ptr<SpdyFrame> body( |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 519 | ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 520 | MockWrite writes[] = { |
| 521 | CreateMockWrite(*req, 0), |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 522 | CreateMockWrite(*body, 1), |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 523 | }; |
| 524 | |
| 525 | scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 526 | MockRead reads[] = { |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 527 | CreateMockRead(*resp, 2), |
| 528 | MockRead(ASYNC, 0, 0, 3), // EOF |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 529 | }; |
| 530 | |
| 531 | DeterministicSocketData data(reads, arraysize(reads), |
| 532 | writes, arraysize(writes)); |
| 533 | MockConnect connect_data(SYNCHRONOUS, OK); |
| 534 | data.set_connect_data(connect_data); |
| 535 | |
| 536 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 537 | |
| 538 | scoped_refptr<SpdySession> session(CreateSpdySession()); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 539 | |
| 540 | InitializeSpdySession(session, host_port_pair_); |
| 541 | |
[email protected] | d26ff35 | 2013-05-13 08:48:28 | [diff] [blame] | 542 | base::WeakPtr<SpdyStream> stream = |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 543 | CreateStreamSynchronously(session, url, LOWEST, BoundNetLog()); |
| 544 | ASSERT_TRUE(stream.get() != NULL); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 545 | |
[email protected] | d26ff35 | 2013-05-13 08:48:28 | [diff] [blame] | 546 | StreamDelegateWithBody delegate(stream, kPostBodyStringPiece); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 547 | stream->SetDelegate(&delegate); |
| 548 | |
| 549 | EXPECT_FALSE(stream->HasUrl()); |
| 550 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 551 | stream->set_spdy_headers( |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame] | 552 | spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 553 | EXPECT_TRUE(stream->HasUrl()); |
| 554 | EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
| 555 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 556 | EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 557 | |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 558 | EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 559 | |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 560 | StallStream(stream); |
| 561 | |
| 562 | data.RunFor(1); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 563 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 564 | EXPECT_TRUE(stream->send_stalled_by_flow_control()); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 565 | |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 566 | unstall_function.Run(stream, kPostBodyLength); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 567 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 568 | EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 569 | |
| 570 | data.RunFor(3); |
| 571 | |
| 572 | EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
| 573 | |
| 574 | EXPECT_TRUE(delegate.send_headers_completed()); |
| 575 | EXPECT_EQ("200", delegate.GetResponseHeaderValue(":status")); |
| 576 | EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue(":version")); |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 577 | EXPECT_EQ(std::string(), delegate.TakeReceivedData()); |
[email protected] | aa19cfc | 2013-05-23 16:41:38 | [diff] [blame] | 578 | EXPECT_TRUE(data.at_write_eof()); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 579 | } |
| 580 | |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 581 | TEST_F(SpdyStreamSpdy3Test, ResumeAfterSendWindowSizeIncreaseRequestResponse) { |
| 582 | RunResumeAfterUnstallRequestResponseTest( |
| 583 | base::Bind(&IncreaseStreamSendWindowSize)); |
| 584 | } |
| 585 | |
| 586 | TEST_F(SpdyStreamSpdy3Test, ResumeAfterSendWindowSizeAdjustRequestResponse) { |
| 587 | RunResumeAfterUnstallRequestResponseTest( |
| 588 | base::Bind(&AdjustStreamSendWindowSize)); |
| 589 | } |
| 590 | |
| 591 | // Given an unstall function, runs a test to make sure that a |
[email protected] | 63c8cb0 | 2013-05-22 22:34:04 | [diff] [blame] | 592 | // bidirectional (i.e., non-HTTP-like) stream resumes after a stall |
| 593 | // and unstall. |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 594 | void SpdyStreamSpdy3Test::RunResumeAfterUnstallBidirectionalTest( |
| 595 | const UnstallFunction& unstall_function) { |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 596 | GURL url(kStreamUrl); |
| 597 | |
| 598 | session_ = |
| 599 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_); |
| 600 | |
| 601 | scoped_ptr<SpdyFrame> req( |
| 602 | ConstructSpdyPost(kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0)); |
| 603 | scoped_ptr<SpdyFrame> msg( |
| 604 | ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); |
| 605 | MockWrite writes[] = { |
| 606 | CreateMockWrite(*req, 0), |
| 607 | CreateMockWrite(*msg, 2), |
| 608 | }; |
| 609 | |
| 610 | scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 611 | scoped_ptr<SpdyFrame> echo( |
| 612 | ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); |
| 613 | MockRead reads[] = { |
| 614 | CreateMockRead(*resp, 1), |
| 615 | CreateMockRead(*echo, 3), |
| 616 | MockRead(ASYNC, 0, 0, 4), // EOF |
| 617 | }; |
| 618 | |
| 619 | DeterministicSocketData data(reads, arraysize(reads), |
| 620 | writes, arraysize(writes)); |
| 621 | MockConnect connect_data(SYNCHRONOUS, OK); |
| 622 | data.set_connect_data(connect_data); |
| 623 | |
| 624 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 625 | |
| 626 | scoped_refptr<SpdySession> session(CreateSpdySession()); |
| 627 | |
| 628 | InitializeSpdySession(session, host_port_pair_); |
| 629 | |
[email protected] | d26ff35 | 2013-05-13 08:48:28 | [diff] [blame] | 630 | base::WeakPtr<SpdyStream> stream = |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 631 | CreateStreamSynchronously(session, url, LOWEST, BoundNetLog()); |
| 632 | ASSERT_TRUE(stream.get() != NULL); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 633 | |
[email protected] | 194cfcf | 2013-05-23 21:44:44 | [diff] [blame^] | 634 | StreamDelegateSendImmediate delegate(stream, kPostBodyStringPiece); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 635 | stream->SetDelegate(&delegate); |
| 636 | |
| 637 | EXPECT_FALSE(stream->HasUrl()); |
| 638 | |
| 639 | stream->set_spdy_headers( |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame] | 640 | spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 641 | EXPECT_TRUE(stream->HasUrl()); |
| 642 | EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
| 643 | |
| 644 | EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
| 645 | |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 646 | data.RunFor(1); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 647 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 648 | EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 649 | |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 650 | StallStream(stream); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 651 | |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 652 | data.RunFor(1); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 653 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 654 | EXPECT_TRUE(stream->send_stalled_by_flow_control()); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 655 | |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 656 | unstall_function.Run(stream, kPostBodyLength); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 657 | |
[email protected] | 1c6b12a | 2013-03-21 00:59:11 | [diff] [blame] | 658 | EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 659 | |
| 660 | data.RunFor(3); |
| 661 | |
| 662 | EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
| 663 | |
| 664 | EXPECT_TRUE(delegate.send_headers_completed()); |
| 665 | EXPECT_EQ("200", delegate.GetResponseHeaderValue(":status")); |
| 666 | EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue(":version")); |
[email protected] | 09a8d917 | 2013-04-17 19:23:49 | [diff] [blame] | 667 | EXPECT_EQ(std::string(kPostBody, kPostBodyLength), |
| 668 | delegate.TakeReceivedData()); |
[email protected] | aa19cfc | 2013-05-23 16:41:38 | [diff] [blame] | 669 | EXPECT_TRUE(data.at_write_eof()); |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 670 | } |
| 671 | |
[email protected] | aa19cfc | 2013-05-23 16:41:38 | [diff] [blame] | 672 | TEST_F(SpdyStreamSpdy3Test, ResumeAfterSendWindowSizeIncreaseBidirectional) { |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 673 | RunResumeAfterUnstallBidirectionalTest( |
| 674 | base::Bind(&IncreaseStreamSendWindowSize)); |
| 675 | } |
| 676 | |
[email protected] | aa19cfc | 2013-05-23 16:41:38 | [diff] [blame] | 677 | TEST_F(SpdyStreamSpdy3Test, ResumeAfterSendWindowSizeAdjustBidirectional) { |
[email protected] | d2de7da | 2013-05-22 07:49:56 | [diff] [blame] | 678 | RunResumeAfterUnstallBidirectionalTest( |
| 679 | base::Bind(&AdjustStreamSendWindowSize)); |
[email protected] | 34a4dea | 2013-03-13 00:42:30 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | } // namespace |
| 683 | |
[email protected] | 39d13d94 | 2012-07-19 16:48:20 | [diff] [blame] | 684 | } // namespace test |
| 685 | |
[email protected] | 4f38642 | 2010-07-20 04:19:49 | [diff] [blame] | 686 | } // namespace net |