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

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: correct a typo Created 4 years, 6 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/http/http_stream_factory_impl_unittest.cc » ('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 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(bool request_headers_sent) override {
66 // Request headers should always be sent in H2's case, because the
67 // functionality to combine header frame with data frames is not
68 // implemented.
69 EXPECT_TRUE(request_headers_sent);
67 if (callback_.is_null()) 70 if (callback_.is_null())
68 return; 71 return;
69 callback_.Run(OK); 72 callback_.Run(OK);
70 } 73 }
71 74
72 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override { 75 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override {
73 CHECK(!not_expect_callback_); 76 CHECK(!not_expect_callback_);
74 77
75 response_headers_ = response_headers; 78 response_headers_ = response_headers;
76 if (!do_not_start_read_) 79 if (!do_not_start_read_)
(...skipping 27 matching lines...) Expand all
104 void OnFailed(int error) override { 107 void OnFailed(int error) override {
105 CHECK(!not_expect_callback_); 108 CHECK(!not_expect_callback_);
106 CHECK_EQ(OK, error_); 109 CHECK_EQ(OK, error_);
107 CHECK_NE(OK, error); 110 CHECK_NE(OK, error);
108 111
109 error_ = error; 112 error_ = error;
110 if (run_until_completion_) 113 if (run_until_completion_)
111 loop_->Quit(); 114 loop_->Quit();
112 } 115 }
113 116
114 void DisableAutoFlush() { disable_auto_flush_ = true; }
115
116 void Start(std::unique_ptr<BidirectionalStreamRequestInfo> request_info, 117 void Start(std::unique_ptr<BidirectionalStreamRequestInfo> request_info,
117 HttpNetworkSession* session) { 118 HttpNetworkSession* session) {
118 stream_.reset(new BidirectionalStream(std::move(request_info), session, 119 stream_.reset(new BidirectionalStream(std::move(request_info), session,
119 false, this, std::move(timer_))); 120 true, this, std::move(timer_)));
120 if (run_until_completion_) 121 if (run_until_completion_)
121 loop_->Run(); 122 loop_->Run();
122 } 123 }
123 124
124 void Start(std::unique_ptr<BidirectionalStreamRequestInfo> request_info, 125 void Start(std::unique_ptr<BidirectionalStreamRequestInfo> request_info,
125 HttpNetworkSession* session, 126 HttpNetworkSession* session,
126 const CompletionCallback& cb) { 127 const CompletionCallback& cb) {
127 callback_ = cb; 128 callback_ = cb;
128 stream_.reset(new BidirectionalStream(std::move(request_info), session, 129 stream_.reset(new BidirectionalStream(std::move(request_info), session,
129 disable_auto_flush_, this, 130 true, this, 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(const scoped_refptr<IOBuffer>& data, 135 void SendData(const scoped_refptr<IOBuffer>& data,
136 int length, 136 int length,
137 bool end_of_stream) { 137 bool end_of_stream) {
138 not_expect_callback_ = true; 138 not_expect_callback_ = true;
139 stream_->SendData(data, length, end_of_stream); 139 stream_->SendData(data, length, end_of_stream);
140 not_expect_callback_ = false; 140 not_expect_callback_ = false;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 SpdyHeaderBlock response_headers_; 215 SpdyHeaderBlock response_headers_;
216 SpdyHeaderBlock trailers_; 216 SpdyHeaderBlock trailers_;
217 int error_; 217 int error_;
218 int on_data_read_count_; 218 int on_data_read_count_;
219 int on_data_sent_count_; 219 int on_data_sent_count_;
220 bool do_not_start_read_; 220 bool do_not_start_read_;
221 bool run_until_completion_; 221 bool run_until_completion_;
222 // This is to ensure that delegate callback is not invoked synchronously when 222 // This is to ensure that delegate callback is not invoked synchronously when
223 // calling into |stream_|. 223 // calling into |stream_|.
224 bool not_expect_callback_; 224 bool not_expect_callback_;
225 bool disable_auto_flush_;
226 225
227 CompletionCallback callback_; 226 CompletionCallback callback_;
228 DISALLOW_COPY_AND_ASSIGN(TestDelegateBase); 227 DISALLOW_COPY_AND_ASSIGN(TestDelegateBase);
229 }; 228 };
230 229
231 // A delegate that deletes the stream in a particular callback. 230 // A delegate that deletes the stream in a particular callback.
232 class CancelOrDeleteStreamDelegate : public TestDelegateBase { 231 class CancelOrDeleteStreamDelegate : public TestDelegateBase {
233 public: 232 public:
234 // Specifies in which callback the stream can be deleted. 233 // Specifies in which callback the stream can be deleted.
235 enum Phase { 234 enum Phase {
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 request_info->url = GURL("https://www.example.org/"); 751 request_info->url = GURL("https://www.example.org/");
753 request_info->priority = LOWEST; 752 request_info->priority = LOWEST;
754 request_info->extra_headers.SetHeader(net::HttpRequestHeaders::kContentLength, 753 request_info->extra_headers.SetHeader(net::HttpRequestHeaders::kContentLength,
755 base::SizeTToString(kBodyDataSize * 1)); 754 base::SizeTToString(kBodyDataSize * 1));
756 755
757 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); 756 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize));
758 MockTimer* timer = new MockTimer(); 757 MockTimer* timer = new MockTimer();
759 std::unique_ptr<TestDelegateBase> delegate(new TestDelegateBase( 758 std::unique_ptr<TestDelegateBase> delegate(new TestDelegateBase(
760 read_buffer.get(), kReadBufferSize, base::WrapUnique(timer))); 759 read_buffer.get(), kReadBufferSize, base::WrapUnique(timer)));
761 delegate->set_do_not_start_read(true); 760 delegate->set_do_not_start_read(true);
762 delegate->DisableAutoFlush();
763 TestCompletionCallback callback; 761 TestCompletionCallback callback;
764 delegate->Start(std::move(request_info), http_session_.get(), 762 delegate->Start(std::move(request_info), http_session_.get(),
765 callback.callback()); 763 callback.callback());
766 // Wait until the stream is ready. 764 // Wait until the stream is ready.
767 callback.WaitForResult(); 765 callback.WaitForResult();
768 // Send a DATA frame. 766 // Send a DATA frame.
769 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(body_data.substr(0, 5))); 767 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(body_data.substr(0, 5)));
770 scoped_refptr<StringIOBuffer> buf2( 768 scoped_refptr<StringIOBuffer> buf2(
771 new StringIOBuffer(body_data.substr(5, body_data.size() - 5))); 769 new StringIOBuffer(body_data.substr(5, body_data.size() - 5)));
772 delegate->SendvData({buf, buf2.get()}, {buf->size(), buf2->size()}, true); 770 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 = 1499 AlternativeServiceVector alternative_service_vector =
1502 http_session_->http_server_properties()->GetAlternativeServices(server); 1500 http_session_->http_server_properties()->GetAlternativeServices(server);
1503 ASSERT_EQ(1u, alternative_service_vector.size()); 1501 ASSERT_EQ(1u, alternative_service_vector.size());
1504 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3), 1502 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3),
1505 alternative_service_vector[0].protocol); 1503 alternative_service_vector[0].protocol);
1506 EXPECT_EQ("www.example.org", alternative_service_vector[0].host); 1504 EXPECT_EQ("www.example.org", alternative_service_vector[0].host);
1507 EXPECT_EQ(443, alternative_service_vector[0].port); 1505 EXPECT_EQ(443, alternative_service_vector[0].port);
1508 } 1506 }
1509 1507
1510 } // namespace net 1508 } // namespace net
OLDNEW
« no previous file with comments | « net/http/bidirectional_stream_impl.h ('k') | net/http/http_stream_factory_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698