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

Side by Side Diff: net/quic/bidirectional_stream_quic_impl_unittest.cc

Issue 1969893002: Remove unnecessary array allocation in cronet_bidirectional_stream_adapter.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add include vector Created 4 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/bidirectional_stream_quic_impl.cc ('k') | net/quic/quic_chromium_client_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 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/quic/bidirectional_stream_quic_impl.h" 5 #include "net/quic/bidirectional_stream_quic_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 127 }
128 128
129 void Start(const BidirectionalStreamRequestInfo* request_info, 129 void Start(const BidirectionalStreamRequestInfo* request_info,
130 const BoundNetLog& net_log, 130 const BoundNetLog& net_log,
131 const base::WeakPtr<QuicChromiumClientSession> session) { 131 const base::WeakPtr<QuicChromiumClientSession> session) {
132 stream_job_.reset(new BidirectionalStreamQuicImpl(session)); 132 stream_job_.reset(new BidirectionalStreamQuicImpl(session));
133 stream_job_->Start(request_info, net_log, disable_auto_flush_, this, 133 stream_job_->Start(request_info, net_log, disable_auto_flush_, this,
134 nullptr); 134 nullptr);
135 } 135 }
136 136
137 void SendData(IOBuffer* data, int length, bool end_of_stream) { 137 void SendData(const scoped_refptr<IOBuffer>& data,
138 int length,
139 bool end_of_stream) {
138 not_expect_callback_ = true; 140 not_expect_callback_ = true;
139 stream_job_->SendData(data, length, end_of_stream); 141 stream_job_->SendData(data, length, end_of_stream);
140 not_expect_callback_ = false; 142 not_expect_callback_ = false;
141 } 143 }
142 144
143 void SendvData(const std::vector<IOBuffer*>& data, 145 void SendvData(const std::vector<scoped_refptr<IOBuffer>>& data,
144 const std::vector<int>& lengths, 146 const std::vector<int>& lengths,
145 bool end_of_stream) { 147 bool end_of_stream) {
146 not_expect_callback_ = true; 148 not_expect_callback_ = true;
147 stream_job_->SendvData(data, lengths, end_of_stream); 149 stream_job_->SendvData(data, lengths, end_of_stream);
148 not_expect_callback_ = false; 150 not_expect_callback_ = false;
149 } 151 }
150 152
151 // Waits until next Delegate callback. 153 // Waits until next Delegate callback.
152 void WaitUntilNextCallback() { 154 void WaitUntilNextCallback() {
153 loop_->Run(); 155 loop_->Run();
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 std::unique_ptr<TestDelegateBase> delegate( 706 std::unique_ptr<TestDelegateBase> delegate(
705 new TestDelegateBase(read_buffer.get(), kReadBufferSize)); 707 new TestDelegateBase(read_buffer.get(), kReadBufferSize));
706 delegate->DisableAutoFlush(); 708 delegate->DisableAutoFlush();
707 delegate->Start(&request, net_log().bound(), session()->GetWeakPtr()); 709 delegate->Start(&request, net_log().bound(), session()->GetWeakPtr());
708 delegate->WaitUntilNextCallback(); // OnStreamReady 710 delegate->WaitUntilNextCallback(); // OnStreamReady
709 711
710 // Send a Data packet. 712 // Send a Data packet.
711 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer(kBody1)); 713 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer(kBody1));
712 scoped_refptr<StringIOBuffer> buf2(new StringIOBuffer(kBody2)); 714 scoped_refptr<StringIOBuffer> buf2(new StringIOBuffer(kBody2));
713 715
714 std::vector<IOBuffer*> buffers = {buf1.get(), buf2.get()};
715 std::vector<int> lengths = {buf1->size(), buf2->size()}; 716 std::vector<int> lengths = {buf1->size(), buf2->size()};
716 delegate->SendvData(buffers, lengths, !kFin); 717 delegate->SendvData({buf1, buf2}, lengths, !kFin);
717 delegate->WaitUntilNextCallback(); // OnDataSent 718 delegate->WaitUntilNextCallback(); // OnDataSent
718 719
719 // Server acks the request. 720 // Server acks the request.
720 ProcessPacket(ConstructServerAckPacket(1, 0, 0)); 721 ProcessPacket(ConstructServerAckPacket(1, 0, 0));
721 722
722 // Server sends the response headers. 723 // Server sends the response headers.
723 SpdyHeaderBlock response_headers = ConstructResponseHeaders("200"); 724 SpdyHeaderBlock response_headers = ConstructResponseHeaders("200");
724 size_t spdy_response_headers_frame_length; 725 size_t spdy_response_headers_frame_length;
725 QuicStreamOffset offset = 0; 726 QuicStreamOffset offset = 0;
726 ProcessPacket(ConstructResponseHeadersPacket( 727 ProcessPacket(ConstructResponseHeadersPacket(
(...skipping 10 matching lines...) Expand all
737 ProcessPacket( 738 ProcessPacket(
738 ConstructServerDataPacket(3, !kIncludeVersion, !kFin, 0, kResponseBody)); 739 ConstructServerDataPacket(3, !kIncludeVersion, !kFin, 0, kResponseBody));
739 740
740 EXPECT_EQ(static_cast<int>(strlen(kResponseBody)), cb.WaitForResult()); 741 EXPECT_EQ(static_cast<int>(strlen(kResponseBody)), cb.WaitForResult());
741 742
742 // Send a second Data packet. 743 // Send a second Data packet.
743 scoped_refptr<StringIOBuffer> buf3(new StringIOBuffer(kBody3)); 744 scoped_refptr<StringIOBuffer> buf3(new StringIOBuffer(kBody3));
744 scoped_refptr<StringIOBuffer> buf4(new StringIOBuffer(kBody4)); 745 scoped_refptr<StringIOBuffer> buf4(new StringIOBuffer(kBody4));
745 scoped_refptr<StringIOBuffer> buf5(new StringIOBuffer(kBody5)); 746 scoped_refptr<StringIOBuffer> buf5(new StringIOBuffer(kBody5));
746 747
747 delegate->SendvData({buf3.get(), buf4.get(), buf5.get()}, 748 delegate->SendvData({buf3, buf4, buf5},
748 {buf3->size(), buf4->size(), buf5->size()}, kFin); 749 {buf3->size(), buf4->size(), buf5->size()}, kFin);
749 delegate->WaitUntilNextCallback(); // OnDataSent 750 delegate->WaitUntilNextCallback(); // OnDataSent
750 751
751 size_t spdy_trailers_frame_length; 752 size_t spdy_trailers_frame_length;
752 SpdyHeaderBlock trailers; 753 SpdyHeaderBlock trailers;
753 trailers["foo"] = "bar"; 754 trailers["foo"] = "bar";
754 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(kResponseBody)); 755 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(kResponseBody));
755 // Server sends trailers. 756 // Server sends trailers.
756 ProcessPacket(ConstructResponseTrailersPacket( 757 ProcessPacket(ConstructResponseTrailersPacket(
757 4, kFin, trailers, &spdy_trailers_frame_length, &offset)); 758 4, kFin, trailers, &spdy_trailers_frame_length, &offset));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 795
795 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); 796 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize));
796 std::unique_ptr<TestDelegateBase> delegate( 797 std::unique_ptr<TestDelegateBase> delegate(
797 new TestDelegateBase(read_buffer.get(), kReadBufferSize)); 798 new TestDelegateBase(read_buffer.get(), kReadBufferSize));
798 delegate->Start(&request, net_log().bound(), session()->GetWeakPtr()); 799 delegate->Start(&request, net_log().bound(), session()->GetWeakPtr());
799 delegate->WaitUntilNextCallback(); // OnStreamReady 800 delegate->WaitUntilNextCallback(); // OnStreamReady
800 801
801 // Send a DATA frame. 802 // Send a DATA frame.
802 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(kUploadData)); 803 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(kUploadData));
803 804
804 delegate->SendData(buf.get(), buf->size(), true); 805 delegate->SendData(buf, buf->size(), true);
805 delegate->WaitUntilNextCallback(); // OnDataSent 806 delegate->WaitUntilNextCallback(); // OnDataSent
806 807
807 // Server acks the request. 808 // Server acks the request.
808 ProcessPacket(ConstructServerAckPacket(1, 0, 0)); 809 ProcessPacket(ConstructServerAckPacket(1, 0, 0));
809 810
810 // Server sends the response headers. 811 // Server sends the response headers.
811 SpdyHeaderBlock response_headers = ConstructResponseHeaders("200"); 812 SpdyHeaderBlock response_headers = ConstructResponseHeaders("200");
812 size_t spdy_response_headers_frame_length; 813 size_t spdy_response_headers_frame_length;
813 QuicStreamOffset offset = 0; 814 QuicStreamOffset offset = 0;
814 ProcessPacket(ConstructResponseHeadersPacket( 815 ProcessPacket(ConstructResponseHeadersPacket(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 size_t spdy_response_headers_frame_length; 885 size_t spdy_response_headers_frame_length;
885 ProcessPacket(ConstructResponseHeadersPacket( 886 ProcessPacket(ConstructResponseHeadersPacket(
886 2, !kFin, response_headers, &spdy_response_headers_frame_length, 0)); 887 2, !kFin, response_headers, &spdy_response_headers_frame_length, 0));
887 888
888 delegate->WaitUntilNextCallback(); // OnHeadersReceived 889 delegate->WaitUntilNextCallback(); // OnHeadersReceived
889 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); 890 EXPECT_EQ("200", delegate->response_headers().find(":status")->second);
890 891
891 // Client sends a data packet. 892 // Client sends a data packet.
892 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(kUploadData)); 893 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(kUploadData));
893 894
894 delegate->SendData(buf.get(), buf->size(), false); 895 delegate->SendData(buf, buf->size(), false);
895 delegate->WaitUntilNextCallback(); // OnDataSent 896 delegate->WaitUntilNextCallback(); // OnDataSent
896 897
897 TestCompletionCallback cb; 898 TestCompletionCallback cb;
898 int rv = delegate->ReadData(cb.callback()); 899 int rv = delegate->ReadData(cb.callback());
899 EXPECT_EQ(ERR_IO_PENDING, rv); 900 EXPECT_EQ(ERR_IO_PENDING, rv);
900 const char kResponseBody[] = "Hello world!"; 901 const char kResponseBody[] = "Hello world!";
901 902
902 // Server sends a data packet. 903 // Server sends a data packet.
903 ProcessPacket(ConstructAckAndDataPacket(3, !kIncludeVersion, 2, 1, !kFin, 0, 904 ProcessPacket(ConstructAckAndDataPacket(3, !kIncludeVersion, 2, 1, !kFin, 0,
904 kResponseBody, &server_maker_)); 905 kResponseBody, &server_maker_));
905 906
906 EXPECT_EQ(static_cast<int64_t>(strlen(kResponseBody)), cb.WaitForResult()); 907 EXPECT_EQ(static_cast<int64_t>(strlen(kResponseBody)), cb.WaitForResult());
907 EXPECT_EQ(std::string(kResponseBody), delegate->data_received()); 908 EXPECT_EQ(std::string(kResponseBody), delegate->data_received());
908 909
909 // Client sends a data packet. 910 // Client sends a data packet.
910 delegate->SendData(buf.get(), buf->size(), true); 911 delegate->SendData(buf, buf->size(), true);
911 delegate->WaitUntilNextCallback(); // OnDataSent 912 delegate->WaitUntilNextCallback(); // OnDataSent
912 913
913 TestCompletionCallback cb2; 914 TestCompletionCallback cb2;
914 rv = delegate->ReadData(cb2.callback()); 915 rv = delegate->ReadData(cb2.callback());
915 EXPECT_EQ(ERR_IO_PENDING, rv); 916 EXPECT_EQ(ERR_IO_PENDING, rv);
916 ProcessPacket(ConstructAckAndDataPacket(4, !kIncludeVersion, 3, 1, kFin, 917 ProcessPacket(ConstructAckAndDataPacket(4, !kIncludeVersion, 3, 1, kFin,
917 strlen(kResponseBody), kResponseBody, 918 strlen(kResponseBody), kResponseBody,
918 &server_maker_)); 919 &server_maker_));
919 920
920 EXPECT_EQ(static_cast<int64_t>(strlen(kResponseBody)), cb2.WaitForResult()); 921 EXPECT_EQ(static_cast<int64_t>(strlen(kResponseBody)), cb2.WaitForResult());
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 size_t spdy_response_headers_frame_length; 1060 size_t spdy_response_headers_frame_length;
1060 ProcessPacket(ConstructResponseHeadersPacket( 1061 ProcessPacket(ConstructResponseHeadersPacket(
1061 2, !kFin, response_headers, &spdy_response_headers_frame_length, 0)); 1062 2, !kFin, response_headers, &spdy_response_headers_frame_length, 0));
1062 1063
1063 delegate->WaitUntilNextCallback(); // OnHeadersReceived 1064 delegate->WaitUntilNextCallback(); // OnHeadersReceived
1064 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); 1065 EXPECT_EQ("200", delegate->response_headers().find(":status")->second);
1065 1066
1066 // Send a DATA frame. 1067 // Send a DATA frame.
1067 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(kUploadData)); 1068 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(kUploadData));
1068 1069
1069 delegate->SendData(buf.get(), buf->size(), false); 1070 delegate->SendData(buf, buf->size(), false);
1070 delegate->WaitUntilNextCallback(); // OnDataSent 1071 delegate->WaitUntilNextCallback(); // OnDataSent
1071 1072
1072 delegate->CancelStream(); 1073 delegate->CancelStream();
1073 base::MessageLoop::current()->RunUntilIdle(); 1074 base::MessageLoop::current()->RunUntilIdle();
1074 1075
1075 EXPECT_EQ(0, delegate->on_data_read_count()); 1076 EXPECT_EQ(0, delegate->on_data_read_count());
1076 EXPECT_EQ(1, delegate->on_data_sent_count()); 1077 EXPECT_EQ(1, delegate->on_data_sent_count());
1077 EXPECT_EQ(kProtoQUIC1SPDY3, delegate->GetProtocol()); 1078 EXPECT_EQ(kProtoQUIC1SPDY3, delegate->GetProtocol());
1078 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length + 1079 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length +
1079 strlen(kUploadData)), 1080 strlen(kUploadData)),
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 1342
1342 base::MessageLoop::current()->RunUntilIdle(); 1343 base::MessageLoop::current()->RunUntilIdle();
1343 1344
1344 EXPECT_EQ(1, delegate->on_data_read_count()); 1345 EXPECT_EQ(1, delegate->on_data_read_count());
1345 EXPECT_EQ(0, delegate->on_data_sent_count()); 1346 EXPECT_EQ(0, delegate->on_data_sent_count());
1346 } 1347 }
1347 1348
1348 } // namespace test 1349 } // namespace test
1349 1350
1350 } // namespace net 1351 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/bidirectional_stream_quic_impl.cc ('k') | net/quic/quic_chromium_client_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698