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

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

Issue 2880643004: Move the async write handling from QuicChromiumClientStream to the Handle (Closed)
Patch Set: Rebase Created 3 years, 7 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') | no next file » | 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 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 TEST_P(QuicChromiumClientStreamTest, WriteStreamData) { 634 TEST_P(QuicChromiumClientStreamTest, WriteStreamData) {
635 EXPECT_CALL(delegate_, OnClose()); 635 EXPECT_CALL(delegate_, OnClose());
636 636
637 const char kData1[] = "hello world"; 637 const char kData1[] = "hello world";
638 const size_t kDataLen = arraysize(kData1); 638 const size_t kDataLen = arraysize(kData1);
639 639
640 // All data written. 640 // All data written.
641 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) 641 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
642 .WillOnce(Return(QuicConsumedData(kDataLen, true))); 642 .WillOnce(Return(QuicConsumedData(kDataLen, true)));
643 TestCompletionCallback callback; 643 TestCompletionCallback callback;
644 EXPECT_EQ(OK, stream_->WriteStreamData(QuicStringPiece(kData1, kDataLen), 644 EXPECT_EQ(OK, handle_->WriteStreamData(QuicStringPiece(kData1, kDataLen),
645 true, callback.callback())); 645 true, callback.callback()));
646 } 646 }
647 647
648 TEST_P(QuicChromiumClientStreamTest, WriteStreamDataAsync) { 648 TEST_P(QuicChromiumClientStreamTest, WriteStreamDataAsync) {
649 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber()); 649 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber());
650 EXPECT_CALL(delegate_, OnClose()); 650 EXPECT_CALL(delegate_, OnClose());
651 651
652 const char kData1[] = "hello world"; 652 const char kData1[] = "hello world";
653 const size_t kDataLen = arraysize(kData1); 653 const size_t kDataLen = arraysize(kData1);
654 654
655 // No data written. 655 // No data written.
656 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) 656 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
657 .WillOnce(Return(QuicConsumedData(0, false))); 657 .WillOnce(Return(QuicConsumedData(0, false)));
658 TestCompletionCallback callback; 658 TestCompletionCallback callback;
659 EXPECT_EQ(ERR_IO_PENDING, 659 EXPECT_EQ(ERR_IO_PENDING,
660 stream_->WriteStreamData(QuicStringPiece(kData1, kDataLen), true, 660 handle_->WriteStreamData(QuicStringPiece(kData1, kDataLen), true,
661 callback.callback())); 661 callback.callback()));
662 ASSERT_FALSE(callback.have_result()); 662 ASSERT_FALSE(callback.have_result());
663 663
664 // All data written. 664 // All data written.
665 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) 665 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
666 .WillOnce(Return(QuicConsumedData(kDataLen, true))); 666 .WillOnce(Return(QuicConsumedData(kDataLen, true)));
667 stream_->OnCanWrite(); 667 stream_->OnCanWrite();
668 ASSERT_TRUE(callback.have_result()); 668 ASSERT_TRUE(callback.have_result());
669 EXPECT_THAT(callback.WaitForResult(), IsOk()); 669 EXPECT_THAT(callback.WaitForResult(), IsOk());
670 } 670 }
671 671
672 TEST_P(QuicChromiumClientStreamTest, WritevStreamData) { 672 TEST_P(QuicChromiumClientStreamTest, WritevStreamData) {
673 EXPECT_CALL(delegate_, OnClose()); 673 EXPECT_CALL(delegate_, OnClose());
674 674
675 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!")); 675 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!"));
676 scoped_refptr<StringIOBuffer> buf2( 676 scoped_refptr<StringIOBuffer> buf2(
677 new StringIOBuffer("Just a small payload")); 677 new StringIOBuffer("Just a small payload"));
678 678
679 // All data written. 679 // All data written.
680 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) 680 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
681 .WillOnce(Return(QuicConsumedData(buf1->size(), false))) 681 .WillOnce(Return(QuicConsumedData(buf1->size(), false)))
682 .WillOnce(Return(QuicConsumedData(buf2->size(), true))); 682 .WillOnce(Return(QuicConsumedData(buf2->size(), true)));
683 TestCompletionCallback callback; 683 TestCompletionCallback callback;
684 EXPECT_EQ( 684 EXPECT_EQ(
685 OK, stream_->WritevStreamData({buf1, buf2}, {buf1->size(), buf2->size()}, 685 OK, handle_->WritevStreamData({buf1, buf2}, {buf1->size(), buf2->size()},
686 true, callback.callback())); 686 true, callback.callback()));
687 } 687 }
688 688
689 TEST_P(QuicChromiumClientStreamTest, WritevStreamDataAsync) { 689 TEST_P(QuicChromiumClientStreamTest, WritevStreamDataAsync) {
690 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber()); 690 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber());
691 EXPECT_CALL(delegate_, OnClose()); 691 EXPECT_CALL(delegate_, OnClose());
692 692
693 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!")); 693 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!"));
694 scoped_refptr<StringIOBuffer> buf2( 694 scoped_refptr<StringIOBuffer> buf2(
695 new StringIOBuffer("Just a small payload")); 695 new StringIOBuffer("Just a small payload"));
696 696
697 // Only a part of the data is written. 697 // Only a part of the data is written.
698 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) 698 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
699 // First piece of data is written. 699 // First piece of data is written.
700 .WillOnce(Return(QuicConsumedData(buf1->size(), false))) 700 .WillOnce(Return(QuicConsumedData(buf1->size(), false)))
701 // Second piece of data is queued. 701 // Second piece of data is queued.
702 .WillOnce(Return(QuicConsumedData(0, false))); 702 .WillOnce(Return(QuicConsumedData(0, false)));
703 TestCompletionCallback callback; 703 TestCompletionCallback callback;
704 EXPECT_EQ(ERR_IO_PENDING, 704 EXPECT_EQ(ERR_IO_PENDING,
705 stream_->WritevStreamData({buf1.get(), buf2.get()}, 705 handle_->WritevStreamData({buf1.get(), buf2.get()},
706 {buf1->size(), buf2->size()}, true, 706 {buf1->size(), buf2->size()}, true,
707 callback.callback())); 707 callback.callback()));
708 ASSERT_FALSE(callback.have_result()); 708 ASSERT_FALSE(callback.have_result());
709 709
710 // The second piece of data is written. 710 // The second piece of data is written.
711 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) 711 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
712 .WillOnce(Return(QuicConsumedData(buf2->size(), true))); 712 .WillOnce(Return(QuicConsumedData(buf2->size(), true)));
713 stream_->OnCanWrite(); 713 stream_->OnCanWrite();
714 ASSERT_TRUE(callback.have_result()); 714 ASSERT_TRUE(callback.have_result());
715 EXPECT_THAT(callback.WaitForResult(), IsOk()); 715 EXPECT_THAT(callback.WaitForResult(), IsOk());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len)); 780 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len));
781 781
782 // Both delegates should be notified that theirs streams are closed. 782 // Both delegates should be notified that theirs streams are closed.
783 EXPECT_CALL(delegate2_, OnClose()); 783 EXPECT_CALL(delegate2_, OnClose());
784 EXPECT_CALL(delegate_, OnClose()); 784 EXPECT_CALL(delegate_, OnClose());
785 } 785 }
786 786
787 } // namespace 787 } // namespace
788 } // namespace test 788 } // namespace test
789 } // namespace net 789 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/chromium/quic_chromium_client_stream.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698