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

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: Address Andrei's comment and self review 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,
mef 2016/06/01 21:33:21 if it is /*ignored*/, why does it have to change t
xunjieli 2016/06/01 22:27:16 Done.
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
135 void SendData(const scoped_refptr<IOBuffer>& data, 137 void SendData(const scoped_refptr<IOBuffer>& data,
136 int length, 138 int length,
137 bool end_of_stream) { 139 bool end_of_stream) {
138 not_expect_callback_ = true; 140 not_expect_callback_ = true;
139 stream_->SendData(data, length, end_of_stream); 141 stream_->SendData(data, length, end_of_stream);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 SpdyHeaderBlock response_headers_; 217 SpdyHeaderBlock response_headers_;
216 SpdyHeaderBlock trailers_; 218 SpdyHeaderBlock trailers_;
217 int error_; 219 int error_;
218 int on_data_read_count_; 220 int on_data_read_count_;
219 int on_data_sent_count_; 221 int on_data_sent_count_;
220 bool do_not_start_read_; 222 bool do_not_start_read_;
221 bool run_until_completion_; 223 bool run_until_completion_;
222 // This is to ensure that delegate callback is not invoked synchronously when 224 // This is to ensure that delegate callback is not invoked synchronously when
223 // calling into |stream_|. 225 // calling into |stream_|.
224 bool not_expect_callback_; 226 bool not_expect_callback_;
225 bool disable_auto_flush_;
226 227
227 CompletionCallback callback_; 228 CompletionCallback callback_;
228 DISALLOW_COPY_AND_ASSIGN(TestDelegateBase); 229 DISALLOW_COPY_AND_ASSIGN(TestDelegateBase);
229 }; 230 };
230 231
231 // A delegate that deletes the stream in a particular callback. 232 // A delegate that deletes the stream in a particular callback.
232 class CancelOrDeleteStreamDelegate : public TestDelegateBase { 233 class CancelOrDeleteStreamDelegate : public TestDelegateBase {
233 public: 234 public:
234 // Specifies in which callback the stream can be deleted. 235 // Specifies in which callback the stream can be deleted.
235 enum Phase { 236 enum Phase {
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 request_info->url = GURL("https://www.example.org/"); 753 request_info->url = GURL("https://www.example.org/");
753 request_info->priority = LOWEST; 754 request_info->priority = LOWEST;
754 request_info->extra_headers.SetHeader(net::HttpRequestHeaders::kContentLength, 755 request_info->extra_headers.SetHeader(net::HttpRequestHeaders::kContentLength,
755 base::SizeTToString(kBodyDataSize * 1)); 756 base::SizeTToString(kBodyDataSize * 1));
756 757
757 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); 758 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize));
758 MockTimer* timer = new MockTimer(); 759 MockTimer* timer = new MockTimer();
759 std::unique_ptr<TestDelegateBase> delegate(new TestDelegateBase( 760 std::unique_ptr<TestDelegateBase> delegate(new TestDelegateBase(
760 read_buffer.get(), kReadBufferSize, base::WrapUnique(timer))); 761 read_buffer.get(), kReadBufferSize, base::WrapUnique(timer)));
761 delegate->set_do_not_start_read(true); 762 delegate->set_do_not_start_read(true);
762 delegate->DisableAutoFlush();
763 TestCompletionCallback callback; 763 TestCompletionCallback callback;
764 delegate->Start(std::move(request_info), http_session_.get(), 764 delegate->Start(std::move(request_info), http_session_.get(),
765 callback.callback()); 765 callback.callback());
766 // Wait until the stream is ready. 766 // Wait until the stream is ready.
767 callback.WaitForResult(); 767 callback.WaitForResult();
768 // Send a DATA frame. 768 // Send a DATA frame.
769 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(body_data.substr(0, 5))); 769 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(body_data.substr(0, 5)));
770 scoped_refptr<StringIOBuffer> buf2( 770 scoped_refptr<StringIOBuffer> buf2(
771 new StringIOBuffer(body_data.substr(5, body_data.size() - 5))); 771 new StringIOBuffer(body_data.substr(5, body_data.size() - 5)));
772 delegate->SendvData({buf, buf2.get()}, {buf->size(), buf2->size()}, true); 772 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 = 1501 AlternativeServiceVector alternative_service_vector =
1502 http_session_->http_server_properties()->GetAlternativeServices(server); 1502 http_session_->http_server_properties()->GetAlternativeServices(server);
1503 ASSERT_EQ(1u, alternative_service_vector.size()); 1503 ASSERT_EQ(1u, alternative_service_vector.size());
1504 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3), 1504 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3),
1505 alternative_service_vector[0].protocol); 1505 alternative_service_vector[0].protocol);
1506 EXPECT_EQ("www.example.org", alternative_service_vector[0].host); 1506 EXPECT_EQ("www.example.org", alternative_service_vector[0].host);
1507 EXPECT_EQ(443, alternative_service_vector[0].port); 1507 EXPECT_EQ(443, alternative_service_vector[0].port);
1508 } 1508 }
1509 1509
1510 } // namespace net 1510 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698