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 "net/quic/chromium/quic_chromium_client_stream.h" | 5 #include "net/quic/chromium/quic_chromium_client_stream.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 namespace { | 37 namespace { |
38 | 38 |
39 const QuicStreamId kTestStreamId = 5u; | 39 const QuicStreamId kTestStreamId = 5u; |
40 | 40 |
41 class MockDelegate : public QuicChromiumClientStream::Delegate { | 41 class MockDelegate : public QuicChromiumClientStream::Delegate { |
42 public: | 42 public: |
43 MockDelegate() {} | 43 MockDelegate() {} |
44 | 44 |
45 MOCK_METHOD0(OnSendData, int()); | 45 MOCK_METHOD0(OnSendData, int()); |
46 MOCK_METHOD2(OnSendDataComplete, int(int, bool*)); | 46 MOCK_METHOD2(OnSendDataComplete, int(int, bool*)); |
47 void OnTrailingHeadersAvailable(const SpdyHeaderBlock& headers, | |
48 size_t frame_len) override { | |
49 trailers_ = headers.Clone(); | |
50 OnTrailingHeadersAvailableMock(headers, frame_len); | |
51 } | |
52 MOCK_METHOD2(OnTrailingHeadersAvailableMock, | |
53 void(const SpdyHeaderBlock& headers, size_t frame_len)); | |
54 MOCK_METHOD0(OnClose, void()); | 47 MOCK_METHOD0(OnClose, void()); |
55 MOCK_METHOD1(OnError, void(int)); | 48 MOCK_METHOD1(OnError, void(int)); |
56 MOCK_METHOD0(HasSendHeadersComplete, bool()); | 49 MOCK_METHOD0(HasSendHeadersComplete, bool()); |
57 | 50 |
58 SpdyHeaderBlock headers_; | 51 SpdyHeaderBlock headers_; |
59 SpdyHeaderBlock trailers_; | 52 SpdyHeaderBlock trailers_; |
60 | 53 |
61 private: | 54 private: |
62 DISALLOW_COPY_AND_ASSIGN(MockDelegate); | 55 DISALLOW_COPY_AND_ASSIGN(MockDelegate); |
63 }; | 56 }; |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 scoped_refptr<IOBuffer> buffer(new IOBuffer(2 * data_len)); | 489 scoped_refptr<IOBuffer> buffer(new IOBuffer(2 * data_len)); |
497 EXPECT_EQ(data_len, | 490 EXPECT_EQ(data_len, |
498 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback())); | 491 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback())); |
499 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len)); | 492 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len)); |
500 | 493 |
501 SpdyHeaderBlock trailers; | 494 SpdyHeaderBlock trailers; |
502 trailers["bar"] = "foo"; | 495 trailers["bar"] = "foo"; |
503 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); | 496 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); |
504 | 497 |
505 auto t = ProcessTrailers(trailers); | 498 auto t = ProcessTrailers(trailers); |
506 base::RunLoop run_loop; | |
507 EXPECT_CALL(delegate_, | |
508 OnTrailingHeadersAvailableMock(_, t.uncompressed_header_bytes())) | |
509 .WillOnce(testing::InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | |
510 | 499 |
511 run_loop.Run(); | 500 TestCompletionCallback trailers_callback; |
501 EXPECT_EQ(static_cast<int>(t.uncompressed_header_bytes()), | |
502 handle_->ReadTrailingHeaders(&delegate_.trailers_, | |
503 trailers_callback.callback())); | |
504 base::RunLoop().RunUntilIdle(); | |
xunjieli
2017/05/29 14:06:08
nit: I think we can remove "base::RunLoop().RunUnt
Ryan Hamilton
2017/05/29 16:27:23
Whoops, meant to reply over the weekend, but forgo
| |
512 | 505 |
513 // Read the body and verify that it arrives correctly. | 506 // Read the body and verify that it arrives correctly. |
514 EXPECT_EQ(0, | 507 EXPECT_EQ(0, |
515 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback())); | 508 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback())); |
516 | 509 |
517 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. | 510 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. |
518 trailers.erase(kFinalOffsetHeaderKey); | 511 trailers.erase(kFinalOffsetHeaderKey); |
519 EXPECT_EQ(trailers, delegate_.trailers_); | 512 EXPECT_EQ(trailers, delegate_.trailers_); |
520 base::RunLoop().RunUntilIdle(); | 513 base::RunLoop().RunUntilIdle(); |
521 EXPECT_CALL(delegate_, OnClose()); | 514 EXPECT_CALL(delegate_, OnClose()); |
(...skipping 21 matching lines...) Expand all Loading... | |
543 EXPECT_THAT( | 536 EXPECT_THAT( |
544 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback()), | 537 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback()), |
545 IsError(ERR_IO_PENDING)); | 538 IsError(ERR_IO_PENDING)); |
546 | 539 |
547 SpdyHeaderBlock trailers; | 540 SpdyHeaderBlock trailers; |
548 trailers["bar"] = "foo"; | 541 trailers["bar"] = "foo"; |
549 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); | 542 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); |
550 QuicHeaderList t = ProcessTrailers(trailers); | 543 QuicHeaderList t = ProcessTrailers(trailers); |
551 EXPECT_FALSE(stream_->IsDoneReading()); | 544 EXPECT_FALSE(stream_->IsDoneReading()); |
552 | 545 |
553 base::RunLoop run_loop2; | 546 EXPECT_EQ( |
554 EXPECT_CALL(delegate_, | 547 static_cast<int>(t.uncompressed_header_bytes()), |
555 OnTrailingHeadersAvailableMock(_, t.uncompressed_header_bytes())) | 548 handle_->ReadTrailingHeaders(&delegate_.trailers_, callback.callback())); |
556 .WillOnce( | |
557 testing::InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); })); | |
558 | |
559 run_loop2.Run(); | |
560 | 549 |
561 // Read the body and verify that it arrives correctly. | 550 // Read the body and verify that it arrives correctly. |
562 EXPECT_EQ(0, callback.WaitForResult()); | 551 EXPECT_EQ(0, callback.WaitForResult()); |
563 | 552 |
564 // Make sure the stream is properly closed since trailers and data are all | 553 // Make sure the stream is properly closed since trailers and data are all |
565 // consumed. | 554 // consumed. |
566 EXPECT_TRUE(stream_->IsDoneReading()); | 555 EXPECT_TRUE(stream_->IsDoneReading()); |
567 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. | 556 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. |
568 trailers.erase(kFinalOffsetHeaderKey); | 557 trailers.erase(kFinalOffsetHeaderKey); |
569 EXPECT_EQ(trailers, delegate_.trailers_); | 558 EXPECT_EQ(trailers, delegate_.trailers_); |
(...skipping 30 matching lines...) Expand all Loading... | |
600 | 589 |
601 EXPECT_FALSE(stream_->IsDoneReading()); | 590 EXPECT_FALSE(stream_->IsDoneReading()); |
602 // Read again, it return ERR_IO_PENDING. | 591 // Read again, it return ERR_IO_PENDING. |
603 EXPECT_THAT( | 592 EXPECT_THAT( |
604 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback()), | 593 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback()), |
605 IsError(ERR_IO_PENDING)); | 594 IsError(ERR_IO_PENDING)); |
606 | 595 |
607 // Trailers are not delivered | 596 // Trailers are not delivered |
608 EXPECT_FALSE(stream_->IsDoneReading()); | 597 EXPECT_FALSE(stream_->IsDoneReading()); |
609 | 598 |
610 base::RunLoop run_loop2; | 599 EXPECT_EQ( |
611 EXPECT_CALL(delegate_, | 600 static_cast<int>(t.uncompressed_header_bytes()), |
612 OnTrailingHeadersAvailableMock(_, t.uncompressed_header_bytes())) | 601 handle_->ReadTrailingHeaders(&delegate_.trailers_, callback.callback())); |
613 .WillOnce( | |
614 testing::InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); })); | |
615 | |
616 run_loop2.Run(); | |
617 | 602 |
618 // Read the body and verify that it arrives correctly. | 603 // Read the body and verify that it arrives correctly. |
619 // OnDataAvailable() should follow right after and Read() will return 0. | 604 // OnDataAvailable() should follow right after and Read() will return 0. |
620 EXPECT_EQ(0, callback.WaitForResult()); | 605 EXPECT_EQ(0, callback.WaitForResult()); |
621 | 606 |
622 // Make sure the stream is properly closed since trailers and data are all | 607 // Make sure the stream is properly closed since trailers and data are all |
623 // consumed. | 608 // consumed. |
624 EXPECT_TRUE(stream_->IsDoneReading()); | 609 EXPECT_TRUE(stream_->IsDoneReading()); |
625 | 610 |
626 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. | 611 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
780 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len)); | 765 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len)); |
781 | 766 |
782 // Both delegates should be notified that theirs streams are closed. | 767 // Both delegates should be notified that theirs streams are closed. |
783 EXPECT_CALL(delegate2_, OnClose()); | 768 EXPECT_CALL(delegate2_, OnClose()); |
784 EXPECT_CALL(delegate_, OnClose()); | 769 EXPECT_CALL(delegate_, OnClose()); |
785 } | 770 } |
786 | 771 |
787 } // namespace | 772 } // namespace |
788 } // namespace test | 773 } // namespace test |
789 } // namespace net | 774 } // namespace net |
OLD | NEW |