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

Side by Side Diff: net/http/bidirectional_stream_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 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 std::unique_ptr<base::Timer> timer) 51 std::unique_ptr<base::Timer> timer)
52 : read_buf_(read_buf), 52 : read_buf_(read_buf),
53 read_buf_len_(read_buf_len), 53 read_buf_len_(read_buf_len),
54 timer_(std::move(timer)), 54 timer_(std::move(timer)),
55 loop_(nullptr), 55 loop_(nullptr),
56 error_(OK), 56 error_(OK),
57 on_data_read_count_(0), 57 on_data_read_count_(0),
58 on_data_sent_count_(0), 58 on_data_sent_count_(0),
59 do_not_start_read_(false), 59 do_not_start_read_(false),
60 run_until_completion_(false), 60 run_until_completion_(false),
61 not_expect_callback_(false), 61 not_expect_callback_(false) {}
62 disable_auto_flush_(false) {}
63 62
64 ~TestDelegateBase() override {} 63 ~TestDelegateBase() override {}
65 64
66 void OnStreamReady() override { 65 void OnStreamReady() override {
67 if (callback_.is_null()) 66 if (callback_.is_null())
68 return; 67 return;
69 callback_.Run(OK); 68 callback_.Run(OK);
70 } 69 }
71 70
72 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override { 71 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 void OnFailed(int error) override { 103 void OnFailed(int error) override {
105 CHECK(!not_expect_callback_); 104 CHECK(!not_expect_callback_);
106 CHECK_EQ(OK, error_); 105 CHECK_EQ(OK, error_);
107 CHECK_NE(OK, error); 106 CHECK_NE(OK, error);
108 107
109 error_ = error; 108 error_ = error;
110 if (run_until_completion_) 109 if (run_until_completion_)
111 loop_->Quit(); 110 loop_->Quit();
112 } 111 }
113 112
114 void DisableAutoFlush() { disable_auto_flush_ = true; }
115
116 void Start(std::unique_ptr<BidirectionalStreamRequestInfo> request_info, 113 void Start(std::unique_ptr<BidirectionalStreamRequestInfo> request_info,
117 HttpNetworkSession* session) { 114 HttpNetworkSession* session) {
118 stream_.reset(new BidirectionalStream(std::move(request_info), session, 115 stream_.reset(new BidirectionalStream(std::move(request_info), session,
119 false, this, std::move(timer_))); 116 false, this, std::move(timer_)));
120 if (run_until_completion_) 117 if (run_until_completion_)
121 loop_->Run(); 118 loop_->Run();
122 } 119 }
123 120
124 void Start(std::unique_ptr<BidirectionalStreamRequestInfo> request_info, 121 void Start(std::unique_ptr<BidirectionalStreamRequestInfo> request_info,
125 HttpNetworkSession* session, 122 HttpNetworkSession* session,
126 const CompletionCallback& cb) { 123 const CompletionCallback& cb) {
127 callback_ = cb; 124 callback_ = cb;
128 stream_.reset(new BidirectionalStream(std::move(request_info), session, 125 stream_.reset(new BidirectionalStream(std::move(request_info), session,
129 disable_auto_flush_, this, 126 /*ignored*/ false, this,
130 std::move(timer_))); 127 std::move(timer_)));
131 if (run_until_completion_) 128 if (run_until_completion_)
132 loop_->Run(); 129 loop_->Run();
133 } 130 }
134 131
135 void SendData(const scoped_refptr<IOBuffer>& data, 132 void SendData(const scoped_refptr<IOBuffer>& data,
136 int length, 133 int length,
137 bool end_of_stream) { 134 bool end_of_stream) {
138 not_expect_callback_ = true; 135 not_expect_callback_ = true;
139 stream_->SendData(data, length, end_of_stream); 136 stream_->SendData(data, length, end_of_stream);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 SpdyHeaderBlock response_headers_; 212 SpdyHeaderBlock response_headers_;
216 SpdyHeaderBlock trailers_; 213 SpdyHeaderBlock trailers_;
217 int error_; 214 int error_;
218 int on_data_read_count_; 215 int on_data_read_count_;
219 int on_data_sent_count_; 216 int on_data_sent_count_;
220 bool do_not_start_read_; 217 bool do_not_start_read_;
221 bool run_until_completion_; 218 bool run_until_completion_;
222 // This is to ensure that delegate callback is not invoked synchronously when 219 // This is to ensure that delegate callback is not invoked synchronously when
223 // calling into |stream_|. 220 // calling into |stream_|.
224 bool not_expect_callback_; 221 bool not_expect_callback_;
225 bool disable_auto_flush_;
226 222
227 CompletionCallback callback_; 223 CompletionCallback callback_;
228 DISALLOW_COPY_AND_ASSIGN(TestDelegateBase); 224 DISALLOW_COPY_AND_ASSIGN(TestDelegateBase);
229 }; 225 };
230 226
231 // A delegate that deletes the stream in a particular callback. 227 // A delegate that deletes the stream in a particular callback.
232 class CancelOrDeleteStreamDelegate : public TestDelegateBase { 228 class CancelOrDeleteStreamDelegate : public TestDelegateBase {
233 public: 229 public:
234 // Specifies in which callback the stream can be deleted. 230 // Specifies in which callback the stream can be deleted.
235 enum Phase { 231 enum Phase {
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 request_info->url = GURL("https://www.example.org/"); 748 request_info->url = GURL("https://www.example.org/");
753 request_info->priority = LOWEST; 749 request_info->priority = LOWEST;
754 request_info->extra_headers.SetHeader(net::HttpRequestHeaders::kContentLength, 750 request_info->extra_headers.SetHeader(net::HttpRequestHeaders::kContentLength,
755 base::SizeTToString(kBodyDataSize * 1)); 751 base::SizeTToString(kBodyDataSize * 1));
756 752
757 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); 753 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize));
758 MockTimer* timer = new MockTimer(); 754 MockTimer* timer = new MockTimer();
759 std::unique_ptr<TestDelegateBase> delegate(new TestDelegateBase( 755 std::unique_ptr<TestDelegateBase> delegate(new TestDelegateBase(
760 read_buffer.get(), kReadBufferSize, base::WrapUnique(timer))); 756 read_buffer.get(), kReadBufferSize, base::WrapUnique(timer)));
761 delegate->set_do_not_start_read(true); 757 delegate->set_do_not_start_read(true);
762 delegate->DisableAutoFlush();
763 TestCompletionCallback callback; 758 TestCompletionCallback callback;
764 delegate->Start(std::move(request_info), http_session_.get(), 759 delegate->Start(std::move(request_info), http_session_.get(),
765 callback.callback()); 760 callback.callback());
766 // Wait until the stream is ready. 761 // Wait until the stream is ready.
767 callback.WaitForResult(); 762 callback.WaitForResult();
768 // Send a DATA frame. 763 // Send a DATA frame.
769 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(body_data.substr(0, 5))); 764 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(body_data.substr(0, 5)));
770 scoped_refptr<StringIOBuffer> buf2( 765 scoped_refptr<StringIOBuffer> buf2(
771 new StringIOBuffer(body_data.substr(5, body_data.size() - 5))); 766 new StringIOBuffer(body_data.substr(5, body_data.size() - 5)));
772 delegate->SendvData({buf, buf2.get()}, {buf->size(), buf2->size()}, true); 767 delegate->SendvData({buf, buf2.get()}, {buf->size(), buf2->size()}, true);
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 AlternativeServiceVector alternative_service_vector = 1496 AlternativeServiceVector alternative_service_vector =
1502 http_session_->http_server_properties()->GetAlternativeServices(server); 1497 http_session_->http_server_properties()->GetAlternativeServices(server);
1503 ASSERT_EQ(1u, alternative_service_vector.size()); 1498 ASSERT_EQ(1u, alternative_service_vector.size());
1504 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3), 1499 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3),
1505 alternative_service_vector[0].protocol); 1500 alternative_service_vector[0].protocol);
1506 EXPECT_EQ("www.example.org", alternative_service_vector[0].host); 1501 EXPECT_EQ("www.example.org", alternative_service_vector[0].host);
1507 EXPECT_EQ(443, alternative_service_vector[0].port); 1502 EXPECT_EQ(443, alternative_service_vector[0].port);
1508 } 1503 }
1509 1504
1510 } // namespace net 1505 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698