OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); | 135 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
136 | 136 |
137 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); | 137 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
138 | 138 |
139 EXPECT_TRUE(delegate.send_headers_completed()); | 139 EXPECT_TRUE(delegate.send_headers_completed()); |
140 EXPECT_EQ("200", delegate.GetResponseHeaderValue("status")); | 140 EXPECT_EQ("200", delegate.GetResponseHeaderValue("status")); |
141 EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue("version")); | 141 EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue("version")); |
142 EXPECT_EQ(std::string(kPostBody, kPostBodyLength), | 142 EXPECT_EQ(std::string(kPostBody, kPostBodyLength), |
143 delegate.TakeReceivedData()); | 143 delegate.TakeReceivedData()); |
144 EXPECT_EQ(static_cast<int>(kPostBodyLength), delegate.data_sent()); | 144 EXPECT_TRUE(data.at_write_eof()); |
145 } | 145 } |
146 | 146 |
147 TEST_F(SpdyStreamSpdy2Test, SendHeaderAndDataAfterOpen) { | 147 TEST_F(SpdyStreamSpdy2Test, SendHeaderAndDataAfterOpen) { |
148 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 148 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
149 | 149 |
150 scoped_ptr<SpdyFrame> expected_request(ConstructSpdyWebSocketSynStream( | 150 scoped_ptr<SpdyFrame> expected_request(ConstructSpdyWebSocketSynStream( |
151 1, | 151 1, |
152 "/chat", | 152 "/chat", |
153 "server.example.com", | 153 "server.example.com", |
154 "http://example.com")); | 154 "http://example.com")); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 (*headers)["origin"] = "http://example.com"; | 209 (*headers)["origin"] = "http://example.com"; |
210 stream->set_spdy_headers(headers.Pass()); | 210 stream->set_spdy_headers(headers.Pass()); |
211 EXPECT_TRUE(stream->HasUrl()); | 211 EXPECT_TRUE(stream->HasUrl()); |
212 | 212 |
213 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); | 213 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
214 | 214 |
215 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); | 215 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
216 | 216 |
217 EXPECT_TRUE(delegate.send_headers_completed()); | 217 EXPECT_TRUE(delegate.send_headers_completed()); |
218 EXPECT_EQ("101", delegate.GetResponseHeaderValue("status")); | 218 EXPECT_EQ("101", delegate.GetResponseHeaderValue("status")); |
219 EXPECT_EQ(1, delegate.headers_sent()); | |
220 EXPECT_EQ(std::string(), delegate.TakeReceivedData()); | 219 EXPECT_EQ(std::string(), delegate.TakeReceivedData()); |
221 EXPECT_EQ(6, delegate.data_sent()); | 220 EXPECT_TRUE(data.at_write_eof()); |
222 } | 221 } |
223 | 222 |
224 TEST_F(SpdyStreamSpdy2Test, PushedStream) { | 223 TEST_F(SpdyStreamSpdy2Test, PushedStream) { |
225 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 224 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
226 scoped_refptr<SpdySession> spdy_session(CreateSpdySession()); | 225 scoped_refptr<SpdySession> spdy_session(CreateSpdySession()); |
227 | 226 |
228 MockRead reads[] = { | 227 MockRead reads[] = { |
229 MockRead(ASYNC, 0, 0), // EOF | 228 MockRead(ASYNC, 0, 0), // EOF |
230 }; | 229 }; |
231 | 230 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 326 |
328 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); | 327 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
329 | 328 |
330 const SpdyStreamId stream_id = delegate.stream_id(); | 329 const SpdyStreamId stream_id = delegate.stream_id(); |
331 | 330 |
332 EXPECT_TRUE(delegate.send_headers_completed()); | 331 EXPECT_TRUE(delegate.send_headers_completed()); |
333 EXPECT_EQ("200", delegate.GetResponseHeaderValue("status")); | 332 EXPECT_EQ("200", delegate.GetResponseHeaderValue("status")); |
334 EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue("version")); | 333 EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue("version")); |
335 EXPECT_EQ(std::string(kPostBody, kPostBodyLength), | 334 EXPECT_EQ(std::string(kPostBody, kPostBodyLength), |
336 delegate.TakeReceivedData()); | 335 delegate.TakeReceivedData()); |
337 EXPECT_EQ(static_cast<int>(kPostBodyLength), delegate.data_sent()); | 336 EXPECT_TRUE(data.at_write_eof()); |
338 | 337 |
339 // Check that the NetLog was filled reasonably. | 338 // Check that the NetLog was filled reasonably. |
340 net::CapturingNetLog::CapturedEntryList entries; | 339 net::CapturingNetLog::CapturedEntryList entries; |
341 log.GetEntries(&entries); | 340 log.GetEntries(&entries); |
342 EXPECT_LT(0u, entries.size()); | 341 EXPECT_LT(0u, entries.size()); |
343 | 342 |
344 // Check that we logged SPDY_STREAM_ERROR correctly. | 343 // Check that we logged SPDY_STREAM_ERROR correctly. |
345 int pos = net::ExpectLogContainsSomewhere( | 344 int pos = net::ExpectLogContainsSomewhere( |
346 entries, 0, | 345 entries, 0, |
347 net::NetLog::TYPE_SPDY_STREAM_ERROR, | 346 net::NetLog::TYPE_SPDY_STREAM_ERROR, |
348 net::NetLog::PHASE_NONE); | 347 net::NetLog::PHASE_NONE); |
349 | 348 |
350 int stream_id2; | 349 int stream_id2; |
351 ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &stream_id2)); | 350 ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &stream_id2)); |
352 EXPECT_EQ(static_cast<int>(stream_id), stream_id2); | 351 EXPECT_EQ(static_cast<int>(stream_id), stream_id2); |
353 } | 352 } |
354 | 353 |
| 354 // Make sure that large blocks of data are properly split up into |
| 355 // frame-sized chunks for a request/response (i.e., an HTTP-like) |
| 356 // stream. |
| 357 TEST_F(SpdyStreamSpdy2Test, SendLargeDataAfterOpenRequestResponse) { |
| 358 GURL url(kStreamUrl); |
| 359 |
| 360 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
| 361 |
| 362 scoped_ptr<SpdyFrame> req( |
| 363 ConstructSpdyPost(kStreamUrl, kPostBodyLength, NULL, 0)); |
| 364 std::string chunk_data(kMaxSpdyFrameChunkSize, 'x'); |
| 365 scoped_ptr<SpdyFrame> chunk( |
| 366 ConstructSpdyBodyFrame( |
| 367 1, chunk_data.data(), chunk_data.length(), false)); |
| 368 MockWrite writes[] = { |
| 369 CreateMockWrite(*req, 0), |
| 370 CreateMockWrite(*chunk, 1), |
| 371 CreateMockWrite(*chunk, 2), |
| 372 CreateMockWrite(*chunk, 3), |
| 373 }; |
| 374 |
| 375 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); |
| 376 MockRead reads[] = { |
| 377 CreateMockRead(*resp, 4), |
| 378 MockRead(ASYNC, 0, 0, 5), // EOF |
| 379 }; |
| 380 |
| 381 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 382 MockConnect connect_data(SYNCHRONOUS, OK); |
| 383 data.set_connect_data(connect_data); |
| 384 |
| 385 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 386 |
| 387 scoped_refptr<SpdySession> session(CreateSpdySession()); |
| 388 |
| 389 InitializeSpdySession(session, host_port_pair_); |
| 390 |
| 391 base::WeakPtr<SpdyStream> stream = |
| 392 CreateStreamSynchronously(session, url, LOWEST, BoundNetLog()); |
| 393 ASSERT_TRUE(stream.get() != NULL); |
| 394 |
| 395 std::string body_data(3 * kMaxSpdyFrameChunkSize, 'x'); |
| 396 StreamDelegateWithBody delegate(stream, body_data); |
| 397 stream->SetDelegate(&delegate); |
| 398 |
| 399 EXPECT_FALSE(stream->HasUrl()); |
| 400 |
| 401 stream->set_spdy_headers( |
| 402 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
| 403 EXPECT_TRUE(stream->HasUrl()); |
| 404 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
| 405 |
| 406 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
| 407 |
| 408 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
| 409 |
| 410 EXPECT_TRUE(delegate.send_headers_completed()); |
| 411 EXPECT_EQ("200", delegate.GetResponseHeaderValue("status")); |
| 412 EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue("version")); |
| 413 EXPECT_EQ(std::string(), delegate.TakeReceivedData()); |
| 414 EXPECT_TRUE(data.at_write_eof()); |
| 415 } |
| 416 |
| 417 // Make sure that large blocks of data are properly split up into |
| 418 // frame-sized chunks for a bidirectional (i.e., non-HTTP-like) |
| 419 // stream. |
| 420 TEST_F(SpdyStreamSpdy2Test, SendLargeDataAfterOpenBidirectional) { |
| 421 GURL url(kStreamUrl); |
| 422 |
| 423 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
| 424 |
| 425 scoped_ptr<SpdyFrame> req( |
| 426 ConstructSpdyPost(kStreamUrl, kPostBodyLength, NULL, 0)); |
| 427 std::string chunk_data(kMaxSpdyFrameChunkSize, 'x'); |
| 428 scoped_ptr<SpdyFrame> chunk( |
| 429 ConstructSpdyBodyFrame( |
| 430 1, chunk_data.data(), chunk_data.length(), false)); |
| 431 MockWrite writes[] = { |
| 432 CreateMockWrite(*req, 0), |
| 433 CreateMockWrite(*chunk, 2), |
| 434 CreateMockWrite(*chunk, 3), |
| 435 CreateMockWrite(*chunk, 4), |
| 436 }; |
| 437 |
| 438 scoped_ptr<SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0)); |
| 439 MockRead reads[] = { |
| 440 CreateMockRead(*resp, 1), |
| 441 MockRead(ASYNC, 0, 0, 5), // EOF |
| 442 }; |
| 443 |
| 444 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 445 MockConnect connect_data(SYNCHRONOUS, OK); |
| 446 data.set_connect_data(connect_data); |
| 447 |
| 448 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 449 |
| 450 scoped_refptr<SpdySession> session(CreateSpdySession()); |
| 451 |
| 452 InitializeSpdySession(session, host_port_pair_); |
| 453 |
| 454 base::WeakPtr<SpdyStream> stream = |
| 455 CreateStreamSynchronously(session, url, LOWEST, BoundNetLog()); |
| 456 ASSERT_TRUE(stream.get() != NULL); |
| 457 |
| 458 std::string body_data(3 * kMaxSpdyFrameChunkSize, 'x'); |
| 459 StreamDelegateSendImmediate delegate( |
| 460 stream, scoped_ptr<SpdyHeaderBlock>(), body_data); |
| 461 stream->SetDelegate(&delegate); |
| 462 |
| 463 EXPECT_FALSE(stream->HasUrl()); |
| 464 |
| 465 stream->set_spdy_headers( |
| 466 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
| 467 EXPECT_TRUE(stream->HasUrl()); |
| 468 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
| 469 |
| 470 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
| 471 |
| 472 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
| 473 |
| 474 EXPECT_TRUE(delegate.send_headers_completed()); |
| 475 EXPECT_EQ("200", delegate.GetResponseHeaderValue("status")); |
| 476 EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue("version")); |
| 477 EXPECT_EQ(std::string(), delegate.TakeReceivedData()); |
| 478 EXPECT_TRUE(data.at_write_eof()); |
| 479 } |
| 480 |
355 } // namespace | 481 } // namespace |
356 | 482 |
357 } // namespace test | 483 } // namespace test |
358 | 484 |
359 } // namespace net | 485 } // namespace net |
OLD | NEW |