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

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

Issue 1992953004: [Cronet] Make delaying sending request headers explicit in bidirectional stream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review 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
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 int read_buf_len, 68 int read_buf_len,
69 std::unique_ptr<base::Timer> timer) 69 std::unique_ptr<base::Timer> timer)
70 : read_buf_(read_buf), 70 : read_buf_(read_buf),
71 read_buf_len_(read_buf_len), 71 read_buf_len_(read_buf_len),
72 timer_(std::move(timer)), 72 timer_(std::move(timer)),
73 loop_(nullptr), 73 loop_(nullptr),
74 error_(OK), 74 error_(OK),
75 on_data_read_count_(0), 75 on_data_read_count_(0),
76 on_data_sent_count_(0), 76 on_data_sent_count_(0),
77 not_expect_callback_(false), 77 not_expect_callback_(false),
78 disable_auto_flush_(false) { 78 delay_headers_until_next_send_data_(false) {
79 loop_.reset(new base::RunLoop); 79 loop_.reset(new base::RunLoop);
80 } 80 }
81 81
82 ~TestDelegateBase() override {} 82 ~TestDelegateBase() override {}
83 83
84 void OnStreamReady() override { 84 void OnStreamReady() override {
85 CHECK(!not_expect_callback_); 85 CHECK(!not_expect_callback_);
86 loop_->Quit(); 86 loop_->Quit();
87 } 87 }
88 88
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 CHECK_NE(OK, error); 123 CHECK_NE(OK, error);
124 124
125 error_ = error; 125 error_ = error;
126 loop_->Quit(); 126 loop_->Quit();
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,
134 nullptr); 134 delay_headers_until_next_send_data_, this, nullptr);
135 } 135 }
136 136
137 void SendData(const scoped_refptr<IOBuffer>& data, 137 void SendData(const scoped_refptr<IOBuffer>& data,
138 int length, 138 int length,
139 bool end_of_stream) { 139 bool end_of_stream) {
140 not_expect_callback_ = true; 140 not_expect_callback_ = true;
141 stream_job_->SendData(data, length, end_of_stream); 141 stream_job_->SendData(data, length, end_of_stream);
142 not_expect_callback_ = false; 142 not_expect_callback_ = false;
143 } 143 }
144 144
(...skipping 27 matching lines...) Expand all
172 void CancelStream() { stream_job_->Cancel(); } 172 void CancelStream() { stream_job_->Cancel(); }
173 173
174 NextProto GetProtocol() const { return stream_job_->GetProtocol(); } 174 NextProto GetProtocol() const { return stream_job_->GetProtocol(); }
175 175
176 int64_t GetTotalReceivedBytes() const { 176 int64_t GetTotalReceivedBytes() const {
177 return stream_job_->GetTotalReceivedBytes(); 177 return stream_job_->GetTotalReceivedBytes();
178 } 178 }
179 179
180 int64_t GetTotalSentBytes() const { return stream_job_->GetTotalSentBytes(); } 180 int64_t GetTotalSentBytes() const { return stream_job_->GetTotalSentBytes(); }
181 181
182 void DisableAutoFlush() { disable_auto_flush_ = true; } 182 void DelayHeadersUntilNextSendData() {
183 delay_headers_until_next_send_data_ = true;
184 }
183 185
184 // Const getters for internal states. 186 // Const getters for internal states.
185 const std::string& data_received() const { return data_received_; } 187 const std::string& data_received() const { return data_received_; }
186 int error() const { return error_; } 188 int error() const { return error_; }
187 const SpdyHeaderBlock& response_headers() const { return response_headers_; } 189 const SpdyHeaderBlock& response_headers() const { return response_headers_; }
188 const SpdyHeaderBlock& trailers() const { return trailers_; } 190 const SpdyHeaderBlock& trailers() const { return trailers_; }
189 int on_data_read_count() const { return on_data_read_count_; } 191 int on_data_read_count() const { return on_data_read_count_; }
190 int on_data_sent_count() const { return on_data_sent_count_; } 192 int on_data_sent_count() const { return on_data_sent_count_; }
191 193
192 protected: 194 protected:
(...skipping 12 matching lines...) Expand all
205 std::unique_ptr<base::RunLoop> loop_; 207 std::unique_ptr<base::RunLoop> loop_;
206 SpdyHeaderBlock response_headers_; 208 SpdyHeaderBlock response_headers_;
207 SpdyHeaderBlock trailers_; 209 SpdyHeaderBlock trailers_;
208 int error_; 210 int error_;
209 int on_data_read_count_; 211 int on_data_read_count_;
210 int on_data_sent_count_; 212 int on_data_sent_count_;
211 // This is to ensure that delegate callback is not invoked synchronously when 213 // This is to ensure that delegate callback is not invoked synchronously when
212 // calling into |stream_|. 214 // calling into |stream_|.
213 bool not_expect_callback_; 215 bool not_expect_callback_;
214 CompletionCallback callback_; 216 CompletionCallback callback_;
215 bool disable_auto_flush_; 217 bool delay_headers_until_next_send_data_;
216 218
217 DISALLOW_COPY_AND_ASSIGN(TestDelegateBase); 219 DISALLOW_COPY_AND_ASSIGN(TestDelegateBase);
218 }; 220 };
219 221
220 // A delegate that deletes the stream in a particular callback. 222 // A delegate that deletes the stream in a particular callback.
221 class DeleteStreamDelegate : public TestDelegateBase { 223 class DeleteStreamDelegate : public TestDelegateBase {
222 public: 224 public:
223 // Specifies in which callback the stream can be deleted. 225 // Specifies in which callback the stream can be deleted.
224 enum Phase { 226 enum Phase {
225 ON_HEADERS_RECEIVED, 227 ON_HEADERS_RECEIVED,
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 700
699 BidirectionalStreamRequestInfo request; 701 BidirectionalStreamRequestInfo request;
700 request.method = "POST"; 702 request.method = "POST";
701 request.url = GURL("http://www.google.com/"); 703 request.url = GURL("http://www.google.com/");
702 request.end_stream_on_headers = false; 704 request.end_stream_on_headers = false;
703 request.priority = DEFAULT_PRIORITY; 705 request.priority = DEFAULT_PRIORITY;
704 706
705 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); 707 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize));
706 std::unique_ptr<TestDelegateBase> delegate( 708 std::unique_ptr<TestDelegateBase> delegate(
707 new TestDelegateBase(read_buffer.get(), kReadBufferSize)); 709 new TestDelegateBase(read_buffer.get(), kReadBufferSize));
708 delegate->DisableAutoFlush(); 710 delegate->DelayHeadersUntilNextSendData();
709 delegate->Start(&request, net_log().bound(), session()->GetWeakPtr()); 711 delegate->Start(&request, net_log().bound(), session()->GetWeakPtr());
710 delegate->WaitUntilNextCallback(); // OnStreamReady 712 delegate->WaitUntilNextCallback(); // OnStreamReady
711 713
712 // Send a Data packet. 714 // Send a Data packet.
713 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer(kBody1)); 715 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer(kBody1));
714 scoped_refptr<StringIOBuffer> buf2(new StringIOBuffer(kBody2)); 716 scoped_refptr<StringIOBuffer> buf2(new StringIOBuffer(kBody2));
715 717
716 std::vector<int> lengths = {buf1->size(), buf2->size()}; 718 std::vector<int> lengths = {buf1->size(), buf2->size()};
717 delegate->SendvData({buf1, buf2}, lengths, !kFin); 719 delegate->SendvData({buf1, buf2}, lengths, !kFin);
718 delegate->WaitUntilNextCallback(); // OnDataSent 720 delegate->WaitUntilNextCallback(); // OnDataSent
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 1344
1343 base::MessageLoop::current()->RunUntilIdle(); 1345 base::MessageLoop::current()->RunUntilIdle();
1344 1346
1345 EXPECT_EQ(1, delegate->on_data_read_count()); 1347 EXPECT_EQ(1, delegate->on_data_read_count());
1346 EXPECT_EQ(0, delegate->on_data_sent_count()); 1348 EXPECT_EQ(0, delegate->on_data_sent_count());
1347 } 1349 }
1348 1350
1349 } // namespace test 1351 } // namespace test
1350 1352
1351 } // namespace net 1353 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698