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

Side by Side Diff: net/http/bidirectional_stream_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/http/bidirectional_stream_impl.h ('k') | net/quic/bidirectional_stream_quic_impl.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/http/bidirectional_stream.h" 5 #include "net/http/bidirectional_stream.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 HttpNetworkSession* session, 125 HttpNetworkSession* session,
126 const CompletionCallback& cb) { 126 const CompletionCallback& cb) {
127 callback_ = cb; 127 callback_ = cb;
128 stream_.reset(new BidirectionalStream(std::move(request_info), session, 128 stream_.reset(new BidirectionalStream(std::move(request_info), session,
129 disable_auto_flush_, this, 129 disable_auto_flush_, this,
130 std::move(timer_))); 130 std::move(timer_)));
131 if (run_until_completion_) 131 if (run_until_completion_)
132 loop_->Run(); 132 loop_->Run();
133 } 133 }
134 134
135 void SendData(IOBuffer* data, int length, bool end_of_stream) { 135 void SendData(const scoped_refptr<IOBuffer>& data,
136 int length,
137 bool end_of_stream) {
136 not_expect_callback_ = true; 138 not_expect_callback_ = true;
137 stream_->SendData(data, length, end_of_stream); 139 stream_->SendData(data, length, end_of_stream);
138 not_expect_callback_ = false; 140 not_expect_callback_ = false;
139 } 141 }
140 142
141 void SendvData(const std::vector<IOBuffer*>& data, 143 void SendvData(const std::vector<scoped_refptr<IOBuffer>>& data,
142 const std::vector<int>& length, 144 const std::vector<int>& length,
143 bool end_of_stream) { 145 bool end_of_stream) {
144 not_expect_callback_ = true; 146 not_expect_callback_ = true;
145 stream_->SendvData(data, length, end_of_stream); 147 stream_->SendvData(data, length, end_of_stream);
146 not_expect_callback_ = false; 148 not_expect_callback_ = false;
147 } 149 }
148 150
149 // Starts or continues reading data from |stream_| until no more bytes 151 // Starts or continues reading data from |stream_| until no more bytes
150 // can be read synchronously. 152 // can be read synchronously.
151 void StartOrContinueReading() { 153 void StartOrContinueReading() {
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 read_buffer.get(), kReadBufferSize, base::WrapUnique(timer))); 535 read_buffer.get(), kReadBufferSize, base::WrapUnique(timer)));
534 delegate->set_do_not_start_read(true); 536 delegate->set_do_not_start_read(true);
535 delegate->Start(std::move(request_info), http_session_.get()); 537 delegate->Start(std::move(request_info), http_session_.get());
536 // Send the request and receive response headers. 538 // Send the request and receive response headers.
537 sequenced_data_->RunUntilPaused(); 539 sequenced_data_->RunUntilPaused();
538 EXPECT_FALSE(timer->IsRunning()); 540 EXPECT_FALSE(timer->IsRunning());
539 541
540 scoped_refptr<StringIOBuffer> buf( 542 scoped_refptr<StringIOBuffer> buf(
541 new StringIOBuffer(std::string(kBodyData, kBodyDataSize))); 543 new StringIOBuffer(std::string(kBodyData, kBodyDataSize)));
542 // Send a DATA frame. 544 // Send a DATA frame.
543 delegate->SendData(buf.get(), buf->size(), true); 545 delegate->SendData(buf, buf->size(), true);
544 // ReadData returns asynchronously because no data is buffered. 546 // ReadData returns asynchronously because no data is buffered.
545 int rv = delegate->ReadData(); 547 int rv = delegate->ReadData();
546 EXPECT_EQ(ERR_IO_PENDING, rv); 548 EXPECT_EQ(ERR_IO_PENDING, rv);
547 // Deliver the first DATA frame. 549 // Deliver the first DATA frame.
548 sequenced_data_->Resume(); 550 sequenced_data_->Resume();
549 sequenced_data_->RunUntilPaused(); 551 sequenced_data_->RunUntilPaused();
550 // |sequenced_data_| is now stopped after delivering first DATA frame but 552 // |sequenced_data_| is now stopped after delivering first DATA frame but
551 // before the second DATA frame. 553 // before the second DATA frame.
552 // Fire the timer to allow the first ReadData to complete asynchronously. 554 // Fire the timer to allow the first ReadData to complete asynchronously.
553 timer->Fire(); 555 timer->Fire();
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 delegate->Start(std::move(request_info), http_session_.get()); 666 delegate->Start(std::move(request_info), http_session_.get());
665 // Send the request and receive response headers. 667 // Send the request and receive response headers.
666 sequenced_data_->RunUntilPaused(); 668 sequenced_data_->RunUntilPaused();
667 EXPECT_FALSE(timer->IsRunning()); 669 EXPECT_FALSE(timer->IsRunning());
668 670
669 // Send a DATA frame. 671 // Send a DATA frame.
670 scoped_refptr<StringIOBuffer> buf( 672 scoped_refptr<StringIOBuffer> buf(
671 new StringIOBuffer(std::string(kBodyData, kBodyDataSize))); 673 new StringIOBuffer(std::string(kBodyData, kBodyDataSize)));
672 674
673 // Send a DATA frame. 675 // Send a DATA frame.
674 delegate->SendData(buf.get(), buf->size(), false); 676 delegate->SendData(buf, buf->size(), false);
675 // ReadData and it should return asynchronously because no data is buffered. 677 // ReadData and it should return asynchronously because no data is buffered.
676 int rv = delegate->ReadData(); 678 int rv = delegate->ReadData();
677 EXPECT_EQ(ERR_IO_PENDING, rv); 679 EXPECT_EQ(ERR_IO_PENDING, rv);
678 // Deliver a DATA frame, and fire the timer. 680 // Deliver a DATA frame, and fire the timer.
679 sequenced_data_->Resume(); 681 sequenced_data_->Resume();
680 sequenced_data_->RunUntilPaused(); 682 sequenced_data_->RunUntilPaused();
681 timer->Fire(); 683 timer->Fire();
682 base::RunLoop().RunUntilIdle(); 684 base::RunLoop().RunUntilIdle();
683 EXPECT_EQ(1, delegate->on_data_sent_count()); 685 EXPECT_EQ(1, delegate->on_data_sent_count());
684 EXPECT_EQ(1, delegate->on_data_read_count()); 686 EXPECT_EQ(1, delegate->on_data_read_count());
685 687
686 // Send a DATA frame. 688 // Send a DATA frame.
687 delegate->SendData(buf.get(), buf->size(), false); 689 delegate->SendData(buf, buf->size(), false);
688 // ReadData and it should return asynchronously because no data is buffered. 690 // ReadData and it should return asynchronously because no data is buffered.
689 rv = delegate->ReadData(); 691 rv = delegate->ReadData();
690 EXPECT_EQ(ERR_IO_PENDING, rv); 692 EXPECT_EQ(ERR_IO_PENDING, rv);
691 // Deliver a DATA frame, and fire the timer. 693 // Deliver a DATA frame, and fire the timer.
692 sequenced_data_->Resume(); 694 sequenced_data_->Resume();
693 sequenced_data_->RunUntilPaused(); 695 sequenced_data_->RunUntilPaused();
694 timer->Fire(); 696 timer->Fire();
695 base::RunLoop().RunUntilIdle(); 697 base::RunLoop().RunUntilIdle();
696 // Last DATA frame is read. Server half closes. 698 // Last DATA frame is read. Server half closes.
697 EXPECT_EQ(2, delegate->on_data_read_count()); 699 EXPECT_EQ(2, delegate->on_data_read_count());
698 EXPECT_EQ(2, delegate->on_data_sent_count()); 700 EXPECT_EQ(2, delegate->on_data_sent_count());
699 701
700 // Send the last body frame. Client half closes. 702 // Send the last body frame. Client half closes.
701 delegate->SendData(buf.get(), buf->size(), true); 703 delegate->SendData(buf, buf->size(), true);
702 sequenced_data_->Resume(); 704 sequenced_data_->Resume();
703 base::RunLoop().RunUntilIdle(); 705 base::RunLoop().RunUntilIdle();
704 EXPECT_EQ(3, delegate->on_data_sent_count()); 706 EXPECT_EQ(3, delegate->on_data_sent_count());
705 707
706 // OnClose is invoked since both sides are closed. 708 // OnClose is invoked since both sides are closed.
707 rv = delegate->ReadData(); 709 rv = delegate->ReadData();
708 EXPECT_EQ(OK, rv); 710 EXPECT_EQ(OK, rv);
709 711
710 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); 712 EXPECT_EQ("200", delegate->response_headers().find(":status")->second);
711 EXPECT_EQ(2, delegate->on_data_read_count()); 713 EXPECT_EQ(2, delegate->on_data_read_count());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 delegate->DisableAutoFlush(); 762 delegate->DisableAutoFlush();
761 TestCompletionCallback callback; 763 TestCompletionCallback callback;
762 delegate->Start(std::move(request_info), http_session_.get(), 764 delegate->Start(std::move(request_info), http_session_.get(),
763 callback.callback()); 765 callback.callback());
764 // Wait until the stream is ready. 766 // Wait until the stream is ready.
765 callback.WaitForResult(); 767 callback.WaitForResult();
766 // Send a DATA frame. 768 // Send a DATA frame.
767 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(body_data.substr(0, 5))); 769 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(body_data.substr(0, 5)));
768 scoped_refptr<StringIOBuffer> buf2( 770 scoped_refptr<StringIOBuffer> buf2(
769 new StringIOBuffer(body_data.substr(5, body_data.size() - 5))); 771 new StringIOBuffer(body_data.substr(5, body_data.size() - 5)));
770 delegate->SendvData({buf.get(), buf2.get()}, {buf->size(), buf2->size()}, 772 delegate->SendvData({buf, buf2.get()}, {buf->size(), buf2->size()}, true);
771 true);
772 sequenced_data_->RunUntilPaused(); // OnHeadersReceived. 773 sequenced_data_->RunUntilPaused(); // OnHeadersReceived.
773 // ReadData and it should return asynchronously because no data is buffered. 774 // ReadData and it should return asynchronously because no data is buffered.
774 EXPECT_EQ(ERR_IO_PENDING, delegate->ReadData()); 775 EXPECT_EQ(ERR_IO_PENDING, delegate->ReadData());
775 sequenced_data_->Resume(); 776 sequenced_data_->Resume();
776 base::RunLoop().RunUntilIdle(); 777 base::RunLoop().RunUntilIdle();
777 EXPECT_EQ(1, delegate->on_data_sent_count()); 778 EXPECT_EQ(1, delegate->on_data_sent_count());
778 EXPECT_EQ(1, delegate->on_data_read_count()); 779 EXPECT_EQ(1, delegate->on_data_read_count());
779 780
780 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); 781 EXPECT_EQ("200", delegate->response_headers().find(":status")->second);
781 EXPECT_EQ(1, delegate->on_data_read_count()); 782 EXPECT_EQ(1, delegate->on_data_read_count());
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 new TestDelegateBase(read_buffer.get(), kReadBufferSize)); 1060 new TestDelegateBase(read_buffer.get(), kReadBufferSize));
1060 delegate->set_do_not_start_read(true); 1061 delegate->set_do_not_start_read(true);
1061 delegate->Start(std::move(request_info), http_session_.get()); 1062 delegate->Start(std::move(request_info), http_session_.get());
1062 // Send the request and receive response headers. 1063 // Send the request and receive response headers.
1063 sequenced_data_->RunUntilPaused(); 1064 sequenced_data_->RunUntilPaused();
1064 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); 1065 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol());
1065 1066
1066 // Send a DATA frame. 1067 // Send a DATA frame.
1067 scoped_refptr<StringIOBuffer> buf( 1068 scoped_refptr<StringIOBuffer> buf(
1068 new StringIOBuffer(std::string(kBodyData, kBodyDataSize))); 1069 new StringIOBuffer(std::string(kBodyData, kBodyDataSize)));
1069 delegate->SendData(buf.get(), buf->size(), false); 1070 delegate->SendData(buf, buf->size(), false);
1070 sequenced_data_->Resume(); 1071 sequenced_data_->Resume();
1071 base::RunLoop().RunUntilIdle(); 1072 base::RunLoop().RunUntilIdle();
1072 // Cancel the stream. 1073 // Cancel the stream.
1073 delegate->CancelStream(); 1074 delegate->CancelStream();
1074 sequenced_data_->Resume(); 1075 sequenced_data_->Resume();
1075 base::RunLoop().RunUntilIdle(); 1076 base::RunLoop().RunUntilIdle();
1076 1077
1077 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); 1078 EXPECT_EQ("200", delegate->response_headers().find(":status")->second);
1078 EXPECT_EQ(0, delegate->on_data_read_count()); 1079 EXPECT_EQ(0, delegate->on_data_read_count());
1079 // EXPECT_EQ(1, delegate->on_data_send_count()); 1080 // EXPECT_EQ(1, delegate->on_data_send_count());
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 AlternativeServiceVector alternative_service_vector = 1501 AlternativeServiceVector alternative_service_vector =
1501 http_session_->http_server_properties()->GetAlternativeServices(server); 1502 http_session_->http_server_properties()->GetAlternativeServices(server);
1502 ASSERT_EQ(1u, alternative_service_vector.size()); 1503 ASSERT_EQ(1u, alternative_service_vector.size());
1503 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3), 1504 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3),
1504 alternative_service_vector[0].protocol); 1505 alternative_service_vector[0].protocol);
1505 EXPECT_EQ("www.example.org", alternative_service_vector[0].host); 1506 EXPECT_EQ("www.example.org", alternative_service_vector[0].host);
1506 EXPECT_EQ(443, alternative_service_vector[0].port); 1507 EXPECT_EQ(443, alternative_service_vector[0].port);
1507 } 1508 }
1508 1509
1509 } // namespace net 1510 } // namespace net
OLDNEW
« no previous file with comments | « net/http/bidirectional_stream_impl.h ('k') | net/quic/bidirectional_stream_quic_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698