Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: net/quic/chromium/quic_chromium_client_stream_test.cc

Issue 2900533002: Add an async ReadTrailers method to QuicChromiumClientStream::Handle (Closed)
Patch Set: Fix comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/chromium/quic_chromium_client_stream.cc ('k') | net/quic/chromium/quic_http_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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()));
512 504
513 // Read the body and verify that it arrives correctly. 505 // Read the body and verify that it arrives correctly.
514 EXPECT_EQ(0, 506 EXPECT_EQ(0,
515 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback())); 507 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback()));
516 508
517 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. 509 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers.
518 trailers.erase(kFinalOffsetHeaderKey); 510 trailers.erase(kFinalOffsetHeaderKey);
519 EXPECT_EQ(trailers, delegate_.trailers_); 511 EXPECT_EQ(trailers, delegate_.trailers_);
520 base::RunLoop().RunUntilIdle(); 512 base::RunLoop().RunUntilIdle();
521 EXPECT_CALL(delegate_, OnClose()); 513 EXPECT_CALL(delegate_, OnClose());
(...skipping 21 matching lines...) Expand all
543 EXPECT_THAT( 535 EXPECT_THAT(
544 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback()), 536 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback()),
545 IsError(ERR_IO_PENDING)); 537 IsError(ERR_IO_PENDING));
546 538
547 SpdyHeaderBlock trailers; 539 SpdyHeaderBlock trailers;
548 trailers["bar"] = "foo"; 540 trailers["bar"] = "foo";
549 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); 541 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data));
550 QuicHeaderList t = ProcessTrailers(trailers); 542 QuicHeaderList t = ProcessTrailers(trailers);
551 EXPECT_FALSE(stream_->IsDoneReading()); 543 EXPECT_FALSE(stream_->IsDoneReading());
552 544
553 base::RunLoop run_loop2; 545 EXPECT_EQ(
554 EXPECT_CALL(delegate_, 546 static_cast<int>(t.uncompressed_header_bytes()),
555 OnTrailingHeadersAvailableMock(_, t.uncompressed_header_bytes())) 547 handle_->ReadTrailingHeaders(&delegate_.trailers_, callback.callback()));
556 .WillOnce(
557 testing::InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); }));
558
559 run_loop2.Run();
560 548
561 // Read the body and verify that it arrives correctly. 549 // Read the body and verify that it arrives correctly.
562 EXPECT_EQ(0, callback.WaitForResult()); 550 EXPECT_EQ(0, callback.WaitForResult());
563 551
564 // Make sure the stream is properly closed since trailers and data are all 552 // Make sure the stream is properly closed since trailers and data are all
565 // consumed. 553 // consumed.
566 EXPECT_TRUE(stream_->IsDoneReading()); 554 EXPECT_TRUE(stream_->IsDoneReading());
567 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. 555 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers.
568 trailers.erase(kFinalOffsetHeaderKey); 556 trailers.erase(kFinalOffsetHeaderKey);
569 EXPECT_EQ(trailers, delegate_.trailers_); 557 EXPECT_EQ(trailers, delegate_.trailers_);
(...skipping 30 matching lines...) Expand all
600 588
601 EXPECT_FALSE(stream_->IsDoneReading()); 589 EXPECT_FALSE(stream_->IsDoneReading());
602 // Read again, it return ERR_IO_PENDING. 590 // Read again, it return ERR_IO_PENDING.
603 EXPECT_THAT( 591 EXPECT_THAT(
604 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback()), 592 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback()),
605 IsError(ERR_IO_PENDING)); 593 IsError(ERR_IO_PENDING));
606 594
607 // Trailers are not delivered 595 // Trailers are not delivered
608 EXPECT_FALSE(stream_->IsDoneReading()); 596 EXPECT_FALSE(stream_->IsDoneReading());
609 597
610 base::RunLoop run_loop2; 598 TestCompletionCallback callback2;
611 EXPECT_CALL(delegate_, 599 EXPECT_EQ(
612 OnTrailingHeadersAvailableMock(_, t.uncompressed_header_bytes())) 600 static_cast<int>(t.uncompressed_header_bytes()),
613 .WillOnce( 601 handle_->ReadTrailingHeaders(&delegate_.trailers_, callback2.callback()));
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
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
OLDNEW
« no previous file with comments | « net/quic/chromium/quic_chromium_client_stream.cc ('k') | net/quic/chromium/quic_http_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698