Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/chromium/bidirectional_stream_quic_impl.h" | 5 #include "net/quic/chromium/bidirectional_stream_quic_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 stream_ = base::MakeUnique<BidirectionalStreamQuicImpl>(std::move(session)); | 166 stream_ = base::MakeUnique<BidirectionalStreamQuicImpl>(std::move(session)); |
| 167 stream_->Start(request_info, net_log, send_request_headers_automatically_, | 167 stream_->Start(request_info, net_log, send_request_headers_automatically_, |
| 168 this, nullptr); | 168 this, nullptr); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void SendRequestHeaders() { stream_->SendRequestHeaders(); } | 171 void SendRequestHeaders() { stream_->SendRequestHeaders(); } |
| 172 | 172 |
| 173 void SendData(const scoped_refptr<IOBuffer>& data, | 173 void SendData(const scoped_refptr<IOBuffer>& data, |
| 174 int length, | 174 int length, |
| 175 bool end_of_stream) { | 175 bool end_of_stream) { |
| 176 not_expect_callback_ = true; | |
| 177 stream_->SendData(data, length, end_of_stream); | 176 stream_->SendData(data, length, end_of_stream); |
| 178 not_expect_callback_ = false; | |
| 179 } | 177 } |
| 180 | 178 |
| 181 void SendvData(const std::vector<scoped_refptr<IOBuffer>>& data, | 179 void SendvData(const std::vector<scoped_refptr<IOBuffer>>& data, |
| 182 const std::vector<int>& lengths, | 180 const std::vector<int>& lengths, |
| 183 bool end_of_stream) { | 181 bool end_of_stream) { |
| 184 not_expect_callback_ = true; | |
| 185 stream_->SendvData(data, lengths, end_of_stream); | 182 stream_->SendvData(data, lengths, end_of_stream); |
| 186 not_expect_callback_ = false; | |
|
xunjieli
2017/06/01 14:22:43
Should we put back these guard checks?
Ryan Hamilton
2017/06/01 17:10:14
Done. Of course, putting the back meant that I nee
| |
| 187 } | 183 } |
| 188 | 184 |
| 189 // Waits until next Delegate callback. | 185 // Waits until next Delegate callback. |
| 190 void WaitUntilNextCallback(DelegateMethod method) { | 186 void WaitUntilNextCallback(DelegateMethod method) { |
| 191 ASSERT_FALSE(on_failed_called_); | 187 ASSERT_FALSE(on_failed_called_); |
| 192 bool is_ready = is_ready_; | 188 bool is_ready = is_ready_; |
| 193 bool headers_received = !response_headers_.empty(); | 189 bool headers_received = !response_headers_.empty(); |
| 194 bool trailers_received = trailers_received_; | 190 bool trailers_received = trailers_received_; |
| 195 int on_data_read_count = on_data_read_count_; | 191 int on_data_read_count = on_data_read_count_; |
| 196 int on_data_sent_count = on_data_sent_count_; | 192 int on_data_sent_count = on_data_sent_count_; |
| (...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1241 static_cast<int64_t>(spdy_request_headers_frame_length + strlen(kBody1) + | 1237 static_cast<int64_t>(spdy_request_headers_frame_length + strlen(kBody1) + |
| 1242 strlen(kBody2) + strlen(kBody3) + strlen(kBody4) + | 1238 strlen(kBody2) + strlen(kBody3) + strlen(kBody4) + |
| 1243 strlen(kBody5)), | 1239 strlen(kBody5)), |
| 1244 delegate->GetTotalSentBytes()); | 1240 delegate->GetTotalSentBytes()); |
| 1245 EXPECT_EQ( | 1241 EXPECT_EQ( |
| 1246 static_cast<int64_t>(spdy_response_headers_frame_length + | 1242 static_cast<int64_t>(spdy_response_headers_frame_length + |
| 1247 strlen(kResponseBody) + spdy_trailers_frame_length), | 1243 strlen(kResponseBody) + spdy_trailers_frame_length), |
| 1248 delegate->GetTotalReceivedBytes()); | 1244 delegate->GetTotalReceivedBytes()); |
| 1249 } | 1245 } |
| 1250 | 1246 |
| 1247 // Tests that when request headers are delayed and SendData triggers the | |
| 1248 // headers to be sent, if that write fails the stream does not crash. | |
| 1249 TEST_P(BidirectionalStreamQuicImplTest, | |
| 1250 SendDataWriteErrorCoalesceDataBufferAndHeaderFrame) { | |
| 1251 QuicStreamOffset header_stream_offset = 0; | |
| 1252 AddWrite(ConstructInitialSettingsPacket(1, &header_stream_offset)); | |
| 1253 AddWriteError(SYNCHRONOUS, ERR_CONNECTION_REFUSED); | |
| 1254 | |
| 1255 Initialize(); | |
| 1256 | |
| 1257 BidirectionalStreamRequestInfo request; | |
| 1258 request.method = "POST"; | |
| 1259 request.url = GURL("http://www.google.com/"); | |
| 1260 request.end_stream_on_headers = false; | |
| 1261 request.priority = DEFAULT_PRIORITY; | |
| 1262 request.extra_headers.SetHeader("cookie", std::string(2048, 'A')); | |
| 1263 | |
| 1264 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); | |
| 1265 std::unique_ptr<DeleteStreamDelegate> delegate(new DeleteStreamDelegate( | |
| 1266 read_buffer.get(), kReadBufferSize, DeleteStreamDelegate::ON_FAILED)); | |
| 1267 delegate->DoNotSendRequestHeadersAutomatically(); | |
| 1268 delegate->Start(&request, net_log().bound(), session()->CreateHandle()); | |
| 1269 ConfirmHandshake(); | |
| 1270 delegate->WaitUntilNextCallback(kOnStreamReady); | |
| 1271 | |
| 1272 // Attempt to send the headers and data. | |
| 1273 const char kBody1[] = "here are some data"; | |
| 1274 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer(kBody1)); | |
| 1275 delegate->SendData(buf1, buf1->size(), !kFin); | |
| 1276 | |
| 1277 EXPECT_TRUE(delegate->on_failed_called()); | |
| 1278 } | |
| 1279 | |
| 1280 // Tests that when request headers are delayed and SendvData triggers the | |
| 1281 // headers to be sent, if that write fails the stream does not crash. | |
| 1282 TEST_P(BidirectionalStreamQuicImplTest, | |
| 1283 SendvDataWriteErrorCoalesceDataBufferAndHeaderFrame) { | |
| 1284 QuicStreamOffset header_stream_offset = 0; | |
| 1285 AddWrite(ConstructInitialSettingsPacket(1, &header_stream_offset)); | |
| 1286 AddWriteError(SYNCHRONOUS, ERR_CONNECTION_REFUSED); | |
| 1287 | |
| 1288 Initialize(); | |
| 1289 | |
| 1290 BidirectionalStreamRequestInfo request; | |
| 1291 request.method = "POST"; | |
| 1292 request.url = GURL("http://www.google.com/"); | |
| 1293 request.end_stream_on_headers = false; | |
| 1294 request.priority = DEFAULT_PRIORITY; | |
| 1295 request.extra_headers.SetHeader("cookie", std::string(2048, 'A')); | |
| 1296 | |
| 1297 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); | |
| 1298 std::unique_ptr<DeleteStreamDelegate> delegate(new DeleteStreamDelegate( | |
| 1299 read_buffer.get(), kReadBufferSize, DeleteStreamDelegate::ON_FAILED)); | |
| 1300 delegate->DoNotSendRequestHeadersAutomatically(); | |
| 1301 delegate->Start(&request, net_log().bound(), session()->CreateHandle()); | |
| 1302 ConfirmHandshake(); | |
| 1303 delegate->WaitUntilNextCallback(kOnStreamReady); | |
| 1304 | |
| 1305 // Attempt to send the headers and data. | |
| 1306 const char kBody1[] = "here are some data"; | |
| 1307 const char kBody2[] = "data keep coming"; | |
| 1308 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer(kBody1)); | |
| 1309 scoped_refptr<StringIOBuffer> buf2(new StringIOBuffer(kBody2)); | |
| 1310 std::vector<int> lengths = {buf1->size(), buf2->size()}; | |
| 1311 delegate->SendvData({buf1, buf2}, lengths, !kFin); | |
| 1312 | |
| 1313 EXPECT_TRUE(delegate->on_failed_called()); | |
| 1314 } | |
| 1315 | |
| 1251 TEST_P(BidirectionalStreamQuicImplTest, PostRequest) { | 1316 TEST_P(BidirectionalStreamQuicImplTest, PostRequest) { |
| 1252 SetRequest("POST", "/", DEFAULT_PRIORITY); | 1317 SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 1253 size_t spdy_request_headers_frame_length; | 1318 size_t spdy_request_headers_frame_length; |
| 1254 QuicStreamOffset header_stream_offset = 0; | 1319 QuicStreamOffset header_stream_offset = 0; |
| 1255 AddWrite(ConstructInitialSettingsPacket(1, &header_stream_offset)); | 1320 AddWrite(ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 1256 AddWrite(ConstructRequestHeadersPacketInner( | 1321 AddWrite(ConstructRequestHeadersPacketInner( |
| 1257 2, GetNthClientInitiatedStreamId(0), !kFin, DEFAULT_PRIORITY, | 1322 2, GetNthClientInitiatedStreamId(0), !kFin, DEFAULT_PRIORITY, |
| 1258 &spdy_request_headers_frame_length, &header_stream_offset)); | 1323 &spdy_request_headers_frame_length, &header_stream_offset)); |
| 1259 AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, 0, kUploadData, | 1324 AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, 0, kUploadData, |
| 1260 &client_maker_)); | 1325 &client_maker_)); |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2043 | 2108 |
| 2044 base::RunLoop().RunUntilIdle(); | 2109 base::RunLoop().RunUntilIdle(); |
| 2045 | 2110 |
| 2046 EXPECT_EQ(1, delegate->on_data_read_count()); | 2111 EXPECT_EQ(1, delegate->on_data_read_count()); |
| 2047 EXPECT_EQ(0, delegate->on_data_sent_count()); | 2112 EXPECT_EQ(0, delegate->on_data_sent_count()); |
| 2048 } | 2113 } |
| 2049 | 2114 |
| 2050 } // namespace test | 2115 } // namespace test |
| 2051 | 2116 |
| 2052 } // namespace net | 2117 } // namespace net |
| OLD | NEW |