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

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: Fix compile error 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
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 /*ignored*/ true, this,
121 std::move(timer_)));
120 if (run_until_completion_) 122 if (run_until_completion_)
121 loop_->Run(); 123 loop_->Run();
122 } 124 }
123 125
124 void Start(std::unique_ptr<BidirectionalStreamRequestInfo> request_info, 126 void Start(std::unique_ptr<BidirectionalStreamRequestInfo> request_info,
125 HttpNetworkSession* session, 127 HttpNetworkSession* session,
126 const CompletionCallback& cb) { 128 const CompletionCallback& cb) {
127 callback_ = cb; 129 callback_ = cb;
128 stream_.reset(new BidirectionalStream(std::move(request_info), session, 130 stream_.reset(new BidirectionalStream(std::move(request_info), session,
129 disable_auto_flush_, this, 131 /*ignored*/ true, this,
130 std::move(timer_))); 132 std::move(timer_)));
131 if (run_until_completion_) 133 if (run_until_completion_)
132 loop_->Run(); 134 loop_->Run();
133 } 135 }
134 136
137 void SendRequestHeaders() { stream_->SendRequestHeaders(); }
138
135 void SendData(const scoped_refptr<IOBuffer>& data, 139 void SendData(const scoped_refptr<IOBuffer>& data,
136 int length, 140 int length,
137 bool end_of_stream) { 141 bool end_of_stream) {
138 not_expect_callback_ = true; 142 not_expect_callback_ = true;
139 stream_->SendData(data, length, end_of_stream); 143 stream_->SendData(data, length, end_of_stream);
140 not_expect_callback_ = false; 144 not_expect_callback_ = false;
141 } 145 }
142 146
143 void SendvData(const std::vector<scoped_refptr<IOBuffer>>& data, 147 void SendvData(const std::vector<scoped_refptr<IOBuffer>>& data,
144 const std::vector<int>& length, 148 const std::vector<int>& length,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 SpdyHeaderBlock response_headers_; 219 SpdyHeaderBlock response_headers_;
216 SpdyHeaderBlock trailers_; 220 SpdyHeaderBlock trailers_;
217 int error_; 221 int error_;
218 int on_data_read_count_; 222 int on_data_read_count_;
219 int on_data_sent_count_; 223 int on_data_sent_count_;
220 bool do_not_start_read_; 224 bool do_not_start_read_;
221 bool run_until_completion_; 225 bool run_until_completion_;
222 // This is to ensure that delegate callback is not invoked synchronously when 226 // This is to ensure that delegate callback is not invoked synchronously when
223 // calling into |stream_|. 227 // calling into |stream_|.
224 bool not_expect_callback_; 228 bool not_expect_callback_;
225 bool disable_auto_flush_;
226 229
227 CompletionCallback callback_; 230 CompletionCallback callback_;
228 DISALLOW_COPY_AND_ASSIGN(TestDelegateBase); 231 DISALLOW_COPY_AND_ASSIGN(TestDelegateBase);
229 }; 232 };
230 233
231 // A delegate that deletes the stream in a particular callback. 234 // A delegate that deletes the stream in a particular callback.
232 class CancelOrDeleteStreamDelegate : public TestDelegateBase { 235 class CancelOrDeleteStreamDelegate : public TestDelegateBase {
233 public: 236 public:
234 // Specifies in which callback the stream can be deleted. 237 // Specifies in which callback the stream can be deleted.
235 enum Phase { 238 enum Phase {
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 request_info->url = GURL("https://www.example.org/"); 755 request_info->url = GURL("https://www.example.org/");
753 request_info->priority = LOWEST; 756 request_info->priority = LOWEST;
754 request_info->extra_headers.SetHeader(net::HttpRequestHeaders::kContentLength, 757 request_info->extra_headers.SetHeader(net::HttpRequestHeaders::kContentLength,
755 base::SizeTToString(kBodyDataSize * 1)); 758 base::SizeTToString(kBodyDataSize * 1));
756 759
757 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); 760 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize));
758 MockTimer* timer = new MockTimer(); 761 MockTimer* timer = new MockTimer();
759 std::unique_ptr<TestDelegateBase> delegate(new TestDelegateBase( 762 std::unique_ptr<TestDelegateBase> delegate(new TestDelegateBase(
760 read_buffer.get(), kReadBufferSize, base::WrapUnique(timer))); 763 read_buffer.get(), kReadBufferSize, base::WrapUnique(timer)));
761 delegate->set_do_not_start_read(true); 764 delegate->set_do_not_start_read(true);
762 delegate->DisableAutoFlush();
763 TestCompletionCallback callback; 765 TestCompletionCallback callback;
764 delegate->Start(std::move(request_info), http_session_.get(), 766 delegate->Start(std::move(request_info), http_session_.get(),
765 callback.callback()); 767 callback.callback());
766 // Wait until the stream is ready. 768 // Wait until the stream is ready.
767 callback.WaitForResult(); 769 callback.WaitForResult();
770 // Sending request headers explicitly should do nothing in H2's case, and it
771 // should not crash because headers have been sent automatically.
772 delegate->SendRequestHeaders();
768 // Send a DATA frame. 773 // Send a DATA frame.
769 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(body_data.substr(0, 5))); 774 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(body_data.substr(0, 5)));
770 scoped_refptr<StringIOBuffer> buf2( 775 scoped_refptr<StringIOBuffer> buf2(
771 new StringIOBuffer(body_data.substr(5, body_data.size() - 5))); 776 new StringIOBuffer(body_data.substr(5, body_data.size() - 5)));
772 delegate->SendvData({buf, buf2.get()}, {buf->size(), buf2->size()}, true); 777 delegate->SendvData({buf, buf2.get()}, {buf->size(), buf2->size()}, true);
773 sequenced_data_->RunUntilPaused(); // OnHeadersReceived. 778 sequenced_data_->RunUntilPaused(); // OnHeadersReceived.
774 // ReadData and it should return asynchronously because no data is buffered. 779 // ReadData and it should return asynchronously because no data is buffered.
775 EXPECT_EQ(ERR_IO_PENDING, delegate->ReadData()); 780 EXPECT_EQ(ERR_IO_PENDING, delegate->ReadData());
776 sequenced_data_->Resume(); 781 sequenced_data_->Resume();
777 base::RunLoop().RunUntilIdle(); 782 base::RunLoop().RunUntilIdle();
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 AlternativeServiceVector alternative_service_vector = 1506 AlternativeServiceVector alternative_service_vector =
1502 http_session_->http_server_properties()->GetAlternativeServices(server); 1507 http_session_->http_server_properties()->GetAlternativeServices(server);
1503 ASSERT_EQ(1u, alternative_service_vector.size()); 1508 ASSERT_EQ(1u, alternative_service_vector.size());
1504 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3), 1509 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3),
1505 alternative_service_vector[0].protocol); 1510 alternative_service_vector[0].protocol);
1506 EXPECT_EQ("www.example.org", alternative_service_vector[0].host); 1511 EXPECT_EQ("www.example.org", alternative_service_vector[0].host);
1507 EXPECT_EQ(443, alternative_service_vector[0].port); 1512 EXPECT_EQ(443, alternative_service_vector[0].port);
1508 } 1513 }
1509 1514
1510 } // namespace net 1515 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698