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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 stream_ = base::MakeUnique<BidirectionalStreamQuicImpl>(std::move(session)); | 157 stream_ = base::MakeUnique<BidirectionalStreamQuicImpl>(std::move(session)); |
| 158 stream_->Start(request_info, net_log, send_request_headers_automatically_, | 158 stream_->Start(request_info, net_log, send_request_headers_automatically_, |
| 159 this, nullptr); | 159 this, nullptr); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void SendRequestHeaders() { stream_->SendRequestHeaders(); } | 162 void SendRequestHeaders() { stream_->SendRequestHeaders(); } |
| 163 | 163 |
| 164 void SendData(const scoped_refptr<IOBuffer>& data, | 164 void SendData(const scoped_refptr<IOBuffer>& data, |
| 165 int length, | 165 int length, |
| 166 bool end_of_stream) { | 166 bool end_of_stream) { |
| 167 not_expect_callback_ = true; | |
|
Ryan Hamilton
2017/06/01 00:45:33
This scares me, because it sure seems like the cla
| |
| 168 stream_->SendData(data, length, end_of_stream); | 167 stream_->SendData(data, length, end_of_stream); |
| 169 not_expect_callback_ = false; | |
| 170 } | 168 } |
| 171 | 169 |
| 172 void SendvData(const std::vector<scoped_refptr<IOBuffer>>& data, | 170 void SendvData(const std::vector<scoped_refptr<IOBuffer>>& data, |
| 173 const std::vector<int>& lengths, | 171 const std::vector<int>& lengths, |
| 174 bool end_of_stream) { | 172 bool end_of_stream) { |
| 175 not_expect_callback_ = true; | |
| 176 stream_->SendvData(data, lengths, end_of_stream); | 173 stream_->SendvData(data, lengths, end_of_stream); |
| 177 not_expect_callback_ = false; | |
| 178 } | 174 } |
| 179 | 175 |
| 180 // Waits until next Delegate callback. | 176 // Waits until next Delegate callback. |
| 181 void WaitUntilNextCallback() { | 177 void WaitUntilNextCallback() { |
| 182 loop_->Run(); | 178 loop_->Run(); |
| 183 loop_.reset(new base::RunLoop); | 179 loop_.reset(new base::RunLoop); |
| 184 } | 180 } |
| 185 | 181 |
| 186 // Calls ReadData on the |stream_| and updates |data_received_|. | 182 // Calls ReadData on the |stream_| and updates |data_received_|. |
| 187 int ReadData(const CompletionCallback& callback) { | 183 int ReadData(const CompletionCallback& callback) { |
| (...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1214 static_cast<int64_t>(spdy_request_headers_frame_length + strlen(kBody1) + | 1210 static_cast<int64_t>(spdy_request_headers_frame_length + strlen(kBody1) + |
| 1215 strlen(kBody2) + strlen(kBody3) + strlen(kBody4) + | 1211 strlen(kBody2) + strlen(kBody3) + strlen(kBody4) + |
| 1216 strlen(kBody5)), | 1212 strlen(kBody5)), |
| 1217 delegate->GetTotalSentBytes()); | 1213 delegate->GetTotalSentBytes()); |
| 1218 EXPECT_EQ( | 1214 EXPECT_EQ( |
| 1219 static_cast<int64_t>(spdy_response_headers_frame_length + | 1215 static_cast<int64_t>(spdy_response_headers_frame_length + |
| 1220 strlen(kResponseBody) + spdy_trailers_frame_length), | 1216 strlen(kResponseBody) + spdy_trailers_frame_length), |
| 1221 delegate->GetTotalReceivedBytes()); | 1217 delegate->GetTotalReceivedBytes()); |
| 1222 } | 1218 } |
| 1223 | 1219 |
| 1220 // Tests that when request headers are delayed and SendData triggers the | |
| 1221 // headers to be sent, if that write fails the stream does not crash. | |
| 1222 TEST_P(BidirectionalStreamQuicImplTest, | |
| 1223 SendDataWriteErrorCoalesceDataBufferAndHeaderFrame) { | |
| 1224 QuicStreamOffset header_stream_offset = 0; | |
| 1225 AddWrite(ConstructInitialSettingsPacket(1, &header_stream_offset)); | |
| 1226 AddWriteError(SYNCHRONOUS, ERR_CONNECTION_REFUSED); | |
| 1227 | |
| 1228 Initialize(); | |
| 1229 | |
| 1230 BidirectionalStreamRequestInfo request; | |
| 1231 request.method = "POST"; | |
| 1232 request.url = GURL("http://www.google.com/"); | |
| 1233 request.end_stream_on_headers = false; | |
| 1234 request.priority = DEFAULT_PRIORITY; | |
| 1235 request.extra_headers.SetHeader("cookie", std::string(2048, 'A')); | |
| 1236 | |
| 1237 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); | |
| 1238 std::unique_ptr<DeleteStreamDelegate> delegate(new DeleteStreamDelegate( | |
| 1239 read_buffer.get(), kReadBufferSize, DeleteStreamDelegate::ON_FAILED)); | |
| 1240 delegate->DoNotSendRequestHeadersAutomatically(); | |
| 1241 delegate->Start(&request, net_log().bound(), session()->CreateHandle()); | |
| 1242 ConfirmHandshake(); | |
| 1243 delegate->WaitUntilNextCallback(); // OnStreamReady | |
| 1244 | |
| 1245 // Attempt to send the headers and data. | |
| 1246 const char kBody1[] = "here are some data"; | |
| 1247 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer(kBody1)); | |
| 1248 delegate->SendData(buf1, buf1->size(), !kFin); | |
| 1249 | |
| 1250 delegate->WaitUntilNextCallback(); // OnFailed | |
| 1251 EXPECT_TRUE(delegate->on_failed_called()); | |
| 1252 } | |
| 1253 | |
| 1254 // Tests that when request headers are delayed and SendvData triggers the | |
| 1255 // headers to be sent, if that write fails the stream does not crash. | |
| 1256 TEST_P(BidirectionalStreamQuicImplTest, | |
| 1257 SendvDataWriteErrorCoalesceDataBufferAndHeaderFrame) { | |
| 1258 QuicStreamOffset header_stream_offset = 0; | |
| 1259 AddWrite(ConstructInitialSettingsPacket(1, &header_stream_offset)); | |
| 1260 AddWriteError(SYNCHRONOUS, ERR_CONNECTION_REFUSED); | |
| 1261 | |
| 1262 Initialize(); | |
| 1263 | |
| 1264 BidirectionalStreamRequestInfo request; | |
| 1265 request.method = "POST"; | |
| 1266 request.url = GURL("http://www.google.com/"); | |
| 1267 request.end_stream_on_headers = false; | |
| 1268 request.priority = DEFAULT_PRIORITY; | |
| 1269 request.extra_headers.SetHeader("cookie", std::string(2048, 'A')); | |
| 1270 | |
| 1271 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); | |
| 1272 std::unique_ptr<DeleteStreamDelegate> delegate(new DeleteStreamDelegate( | |
| 1273 read_buffer.get(), kReadBufferSize, DeleteStreamDelegate::ON_FAILED)); | |
| 1274 delegate->DoNotSendRequestHeadersAutomatically(); | |
| 1275 delegate->Start(&request, net_log().bound(), session()->CreateHandle()); | |
| 1276 ConfirmHandshake(); | |
| 1277 delegate->WaitUntilNextCallback(); // OnStreamReady | |
| 1278 | |
| 1279 // Attempt to send the headers and data. | |
| 1280 const char kBody1[] = "here are some data"; | |
| 1281 const char kBody2[] = "data keep coming"; | |
| 1282 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer(kBody1)); | |
| 1283 scoped_refptr<StringIOBuffer> buf2(new StringIOBuffer(kBody2)); | |
| 1284 std::vector<int> lengths = {buf1->size(), buf2->size()}; | |
| 1285 delegate->SendvData({buf1, buf2}, lengths, !kFin); | |
| 1286 | |
| 1287 delegate->WaitUntilNextCallback(); // OnFailed | |
| 1288 EXPECT_TRUE(delegate->on_failed_called()); | |
| 1289 } | |
| 1290 | |
| 1224 TEST_P(BidirectionalStreamQuicImplTest, PostRequest) { | 1291 TEST_P(BidirectionalStreamQuicImplTest, PostRequest) { |
| 1225 SetRequest("POST", "/", DEFAULT_PRIORITY); | 1292 SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 1226 size_t spdy_request_headers_frame_length; | 1293 size_t spdy_request_headers_frame_length; |
| 1227 QuicStreamOffset header_stream_offset = 0; | 1294 QuicStreamOffset header_stream_offset = 0; |
| 1228 AddWrite(ConstructInitialSettingsPacket(1, &header_stream_offset)); | 1295 AddWrite(ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 1229 AddWrite(ConstructRequestHeadersPacketInner( | 1296 AddWrite(ConstructRequestHeadersPacketInner( |
| 1230 2, GetNthClientInitiatedStreamId(0), !kFin, DEFAULT_PRIORITY, | 1297 2, GetNthClientInitiatedStreamId(0), !kFin, DEFAULT_PRIORITY, |
| 1231 &spdy_request_headers_frame_length, &header_stream_offset)); | 1298 &spdy_request_headers_frame_length, &header_stream_offset)); |
| 1232 AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, 0, kUploadData, | 1299 AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, 0, kUploadData, |
| 1233 &client_maker_)); | 1300 &client_maker_)); |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1971 | 2038 |
| 1972 base::RunLoop().RunUntilIdle(); | 2039 base::RunLoop().RunUntilIdle(); |
| 1973 | 2040 |
| 1974 EXPECT_EQ(1, delegate->on_data_read_count()); | 2041 EXPECT_EQ(1, delegate->on_data_read_count()); |
| 1975 EXPECT_EQ(0, delegate->on_data_sent_count()); | 2042 EXPECT_EQ(0, delegate->on_data_sent_count()); |
| 1976 } | 2043 } |
| 1977 | 2044 |
| 1978 } // namespace test | 2045 } // namespace test |
| 1979 | 2046 |
| 1980 } // namespace net | 2047 } // namespace net |
| OLD | NEW |