Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <cstddef> | 5 #include <cstddef> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 data.RunFor(GetNumReads() + GetNumWrites()); | 168 data.RunFor(GetNumReads() + GetNumWrites()); |
| 169 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); | 169 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
| 170 | 170 |
| 171 EXPECT_TRUE(delegate.send_headers_completed()); | 171 EXPECT_TRUE(delegate.send_headers_completed()); |
| 172 EXPECT_EQ("200", delegate.GetResponseHeaderValue(spdy_util_.GetStatusKey())); | 172 EXPECT_EQ("200", delegate.GetResponseHeaderValue(spdy_util_.GetStatusKey())); |
| 173 EXPECT_EQ(std::string(kPostBody, kPostBodyLength), | 173 EXPECT_EQ(std::string(kPostBody, kPostBodyLength), |
| 174 delegate.TakeReceivedData()); | 174 delegate.TakeReceivedData()); |
| 175 EXPECT_TRUE(data.AllWriteDataConsumed()); | 175 EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 176 } | 176 } |
| 177 | 177 |
| 178 // Delegate that receives trailers. | |
| 179 class StreamDelegateWithTrailers : public test::StreamDelegateWithBody { | |
| 180 public: | |
| 181 StreamDelegateWithTrailers(const base::WeakPtr<SpdyStream>& stream, | |
| 182 base::StringPiece data) | |
| 183 : StreamDelegateWithBody(stream, data) {} | |
| 184 | |
| 185 ~StreamDelegateWithTrailers() override {} | |
| 186 | |
| 187 void OnTrailers(const SpdyHeaderBlock& trailers) override { | |
| 188 trailers_ = trailers; | |
| 189 } | |
| 190 | |
| 191 const SpdyHeaderBlock& GetTrailers() { return trailers_; } | |
|
Ryan Hamilton
2015/08/10 17:23:25
nit: the style guide would suggest this be called
xunjieli
2015/08/10 20:31:07
Done.
| |
| 192 | |
| 193 private: | |
| 194 SpdyHeaderBlock trailers_; | |
| 195 }; | |
| 196 | |
| 197 // Regression test for crbug.com/481033. | |
| 198 TEST_P(SpdyStreamTest, Trailers) { | |
| 199 GURL url(kStreamUrl); | |
| 200 | |
| 201 session_ = | |
| 202 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_); | |
| 203 | |
| 204 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( | |
| 205 kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0)); | |
| 206 AddWrite(*req); | |
| 207 | |
| 208 scoped_ptr<SpdyFrame> msg( | |
| 209 spdy_util_.ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, true)); | |
| 210 AddWrite(*msg); | |
| 211 | |
| 212 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | |
| 213 AddRead(*resp); | |
| 214 | |
| 215 scoped_ptr<SpdyFrame> echo( | |
| 216 spdy_util_.ConstructSpdyBodyFrame(1, kPostBody, kPostBodyLength, false)); | |
| 217 AddRead(*echo); | |
| 218 | |
| 219 const char* const kExtraHeaders[] = {"foo", "bar"}; | |
| 220 scoped_ptr<SpdyFrame> trailers( | |
| 221 spdy_util_.ConstructSpdyHeaderFrame(1, kExtraHeaders, 1)); | |
| 222 AddRead(*trailers); | |
| 223 | |
| 224 AddReadEOF(); | |
| 225 | |
| 226 DeterministicSocketData data(GetReads(), GetNumReads(), GetWrites(), | |
| 227 GetNumWrites()); | |
| 228 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 229 data.set_connect_data(connect_data); | |
| 230 | |
| 231 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); | |
| 232 | |
| 233 base::WeakPtr<SpdySession> session(CreateDefaultSpdySession()); | |
| 234 | |
| 235 base::WeakPtr<SpdyStream> stream = CreateStreamSynchronously( | |
| 236 SPDY_REQUEST_RESPONSE_STREAM, session, url, LOWEST, BoundNetLog()); | |
| 237 ASSERT_TRUE(stream.get() != NULL); | |
| 238 | |
| 239 StreamDelegateWithTrailers delegate(stream, kPostBodyStringPiece); | |
| 240 stream->SetDelegate(&delegate); | |
| 241 | |
| 242 EXPECT_FALSE(stream->HasUrlFromHeaders()); | |
| 243 | |
| 244 scoped_ptr<SpdyHeaderBlock> headers( | |
| 245 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); | |
| 246 EXPECT_EQ(ERR_IO_PENDING, | |
| 247 stream->SendRequestHeaders(headers.Pass(), MORE_DATA_TO_SEND)); | |
| 248 EXPECT_TRUE(stream->HasUrlFromHeaders()); | |
| 249 EXPECT_EQ(kStreamUrl, stream->GetUrlFromHeaders().spec()); | |
| 250 | |
| 251 data.RunFor(GetNumReads() + GetNumWrites()); | |
| 252 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); | |
|
Ryan Hamilton
2015/08/10 17:23:25
If the last IO state is the read of EOF, it would
| |
| 253 | |
| 254 EXPECT_TRUE(delegate.send_headers_completed()); | |
| 255 EXPECT_EQ("200", delegate.GetResponseHeaderValue(spdy_util_.GetStatusKey())); | |
| 256 const SpdyHeaderBlock& received_trailers = delegate.GetTrailers(); | |
| 257 SpdyHeaderBlock::const_iterator it = received_trailers.find("foo"); | |
| 258 EXPECT_EQ("bar", it->second); | |
| 259 EXPECT_EQ(std::string(kPostBody, kPostBodyLength), | |
| 260 delegate.TakeReceivedData()); | |
| 261 EXPECT_TRUE(data.AllWriteDataConsumed()); | |
| 262 } | |
| 263 | |
| 178 TEST_P(SpdyStreamTest, PushedStream) { | 264 TEST_P(SpdyStreamTest, PushedStream) { |
| 179 session_ = | 265 session_ = |
| 180 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_); | 266 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_); |
| 181 | 267 |
| 182 AddReadEOF(); | 268 AddReadEOF(); |
| 183 | 269 |
| 184 DeterministicSocketData data(GetReads(), GetNumReads(), GetWrites(), | 270 DeterministicSocketData data(GetReads(), GetNumReads(), GetWrites(), |
| 185 GetNumWrites()); | 271 GetNumWrites()); |
| 186 MockConnect connect_data(SYNCHRONOUS, OK); | 272 MockConnect connect_data(SYNCHRONOUS, OK); |
| 187 data.set_connect_data(connect_data); | 273 data.set_connect_data(connect_data); |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1040 data.RunFor(1); // FIN | 1126 data.RunFor(1); // FIN |
| 1041 | 1127 |
| 1042 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); | 1128 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
| 1043 } | 1129 } |
| 1044 | 1130 |
| 1045 } // namespace | 1131 } // namespace |
| 1046 | 1132 |
| 1047 } // namespace test | 1133 } // namespace test |
| 1048 | 1134 |
| 1049 } // namespace net | 1135 } // namespace net |
| OLD | NEW |