Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "net/spdy/bidirectional_stream_spdy_impl.h" | 5 #include "net/spdy/bidirectional_stream_spdy_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 EXPECT_EQ(0, delegate->on_data_read_count()); | 425 EXPECT_EQ(0, delegate->on_data_read_count()); |
| 426 EXPECT_EQ(0, delegate->on_data_sent_count()); | 426 EXPECT_EQ(0, delegate->on_data_sent_count()); |
| 427 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); | 427 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); |
| 428 // BidirectionalStreamSpdyStreamJob does not count the bytes sent for |rst| | 428 // BidirectionalStreamSpdyStreamJob does not count the bytes sent for |rst| |
| 429 // because it is sent after SpdyStream::Delegate::OnClose is called. | 429 // because it is sent after SpdyStream::Delegate::OnClose is called. |
| 430 EXPECT_EQ(CountWriteBytes(writes, 1), delegate->GetTotalSentBytes()); | 430 EXPECT_EQ(CountWriteBytes(writes, 1), delegate->GetTotalSentBytes()); |
| 431 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 431 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 432 delegate->GetTotalReceivedBytes()); | 432 delegate->GetTotalReceivedBytes()); |
| 433 } | 433 } |
| 434 | 434 |
| 435 // Tests that when received RST_STREAM with NO_ERROR, BidirectionalStream does | |
| 436 // not crash when processing pending writes. See crbug.com/650438. | |
| 437 TEST_F(BidirectionalStreamSpdyImplTest, RstWithNoErrorBeforeSendIsComplete) { | |
|
kapishnikov
2016/10/31 17:21:47
We need a similar test for SendvData
xunjieli
2016/10/31 18:42:19
Done.
| |
| 438 SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( | |
| 439 kDefaultUrl, 1, kBodyDataSize * 3, LOW, nullptr, 0)); | |
| 440 MockWrite writes[] = {CreateMockWrite(req, 0)}; | |
| 441 | |
| 442 SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(nullptr, 0)); | |
| 443 SpdySerializedFrame rst( | |
| 444 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_NO_ERROR)); | |
| 445 MockRead reads[] = {CreateMockRead(resp, 1), | |
| 446 MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause. | |
| 447 CreateMockRead(rst, 3), MockRead(ASYNC, 0, 4)}; | |
| 448 | |
| 449 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | |
| 450 | |
| 451 BidirectionalStreamRequestInfo request_info; | |
| 452 request_info.method = "POST"; | |
| 453 request_info.url = default_url_; | |
| 454 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kContentLength, | |
| 455 base::SizeTToString(kBodyDataSize * 3)); | |
| 456 | |
| 457 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); | |
| 458 std::unique_ptr<TestDelegateBase> delegate( | |
| 459 new TestDelegateBase(session_, read_buffer.get(), kReadBufferSize)); | |
| 460 delegate->SetRunUntilCompletion(true); | |
| 461 delegate->Start(&request_info, net_log_.bound()); | |
| 462 sequenced_data_->RunUntilPaused(); | |
| 463 // Make a write pending before receiving RST_STREAM. | |
| 464 scoped_refptr<StringIOBuffer> write_buffer( | |
| 465 new StringIOBuffer(std::string(kBodyData, kBodyDataSize))); | |
| 466 delegate->SendData(write_buffer.get(), write_buffer->size(), false); | |
| 467 sequenced_data_->Resume(); | |
| 468 base::RunLoop().RunUntilIdle(); | |
| 469 | |
| 470 // Make sure OnClose() without an error completes any pending write(). | |
| 471 EXPECT_EQ(1, delegate->on_data_sent_count()); | |
| 472 EXPECT_FALSE(delegate->on_failed_called()); | |
| 473 | |
| 474 for (size_t i = 0; i < 3; i++) { | |
| 475 delegate->SendData(write_buffer.get(), write_buffer->size(), i == 2); | |
| 476 base::RunLoop().RunUntilIdle(); | |
| 477 } | |
| 478 delegate->WaitUntilCompletion(); | |
| 479 LoadTimingInfo load_timing_info; | |
| 480 EXPECT_TRUE(delegate->GetLoadTimingInfo(&load_timing_info)); | |
| 481 TestLoadTimingNotReused(load_timing_info); | |
| 482 | |
| 483 EXPECT_THAT(delegate->error(), IsError(OK)); | |
| 484 EXPECT_EQ(1, delegate->on_data_read_count()); | |
| 485 EXPECT_EQ(4, delegate->on_data_sent_count()); | |
| 486 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); | |
| 487 EXPECT_EQ(CountWriteBytes(writes, 1), delegate->GetTotalSentBytes()); | |
| 488 // Should not count RST stream. | |
| 489 EXPECT_EQ(CountReadBytes(reads, arraysize(reads) - 2), | |
| 490 delegate->GetTotalReceivedBytes()); | |
| 491 | |
| 492 // Now call SendData again should produce an error because end of stream flag | |
| 493 // has been written. | |
| 494 delegate->SendData(write_buffer.get(), write_buffer->size(), true); | |
| 495 base::RunLoop().RunUntilIdle(); | |
| 496 EXPECT_THAT(delegate->error(), IsError(ERR_UNEXPECTED)); | |
| 497 EXPECT_TRUE(delegate->on_failed_called()); | |
| 498 EXPECT_EQ(4, delegate->on_data_sent_count()); | |
| 499 } | |
| 500 | |
| 435 } // namespace net | 501 } // namespace net |
| OLD | NEW |