OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/spdy/spdy_http_stream.h" | 5 #include "net/spdy/spdy_http_stream.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 EXPECT_TRUE(stream.GetLoadTimingInfo(&load_timing_info)); | 68 EXPECT_TRUE(stream.GetLoadTimingInfo(&load_timing_info)); |
69 | 69 |
70 EXPECT_FALSE(load_timing_info.socket_reused); | 70 EXPECT_FALSE(load_timing_info.socket_reused); |
71 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 71 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
72 | 72 |
73 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, | 73 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
74 CONNECT_TIMING_HAS_DNS_TIMES); | 74 CONNECT_TIMING_HAS_DNS_TIMES); |
75 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); | 75 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); |
76 } | 76 } |
77 | 77 |
78 class ReadErrorUploadDataStream : public UploadDataStream { | |
79 public: | |
80 enum class FailureMode { SYNC, ASYNC }; | |
81 | |
82 explicit ReadErrorUploadDataStream(FailureMode mode) | |
83 : UploadDataStream(true, 0), async_(mode), weak_factory_(this) {} | |
84 | |
85 private: | |
86 void CompleteRead() { UploadDataStream::OnReadCompleted(ERR_FAILED); } | |
87 | |
88 // UploadDataStream implementation: | |
89 int InitInternal() override { return OK; } | |
90 | |
91 int ReadInternal(IOBuffer* buf, int buf_len) override { | |
92 if (async_ == FailureMode::ASYNC) { | |
93 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
94 FROM_HERE, base::Bind(&ReadErrorUploadDataStream::CompleteRead, | |
95 weak_factory_.GetWeakPtr()), | |
96 base::TimeDelta::FromSeconds(1)); | |
Bence
2016/06/10 17:39:17
Is there a way to avoid time delay in tests? In g
maksims (do not use this acc)
2016/06/20 08:14:24
Done.
| |
97 return ERR_IO_PENDING; | |
98 } | |
99 return ERR_FAILED; | |
100 } | |
101 | |
102 void ResetInternal() override {} | |
103 | |
104 const FailureMode async_; | |
105 | |
106 base::WeakPtrFactory<ReadErrorUploadDataStream> weak_factory_; | |
107 | |
108 DISALLOW_COPY_AND_ASSIGN(ReadErrorUploadDataStream); | |
109 }; | |
110 | |
78 } // namespace | 111 } // namespace |
79 | 112 |
80 class SpdyHttpStreamTest : public testing::Test, | 113 class SpdyHttpStreamTest : public testing::Test, |
81 public testing::WithParamInterface<TestCase> { | 114 public testing::WithParamInterface<TestCase> { |
82 public: | 115 public: |
83 SpdyHttpStreamTest() | 116 SpdyHttpStreamTest() |
84 : spdy_util_(GetProtocol(), GetDependenciesFromPriority()), | 117 : spdy_util_(GetProtocol(), GetDependenciesFromPriority()), |
85 session_deps_(GetProtocol()) { | 118 session_deps_(GetProtocol()) { |
86 session_deps_.enable_priority_dependencies = GetDependenciesFromPriority(); | 119 session_deps_.enable_priority_dependencies = GetDependenciesFromPriority(); |
87 session_deps_.net_log = &net_log_; | 120 session_deps_.net_log = &net_log_; |
88 } | 121 } |
89 | 122 |
90 ~SpdyHttpStreamTest() {} | 123 ~SpdyHttpStreamTest() {} |
91 | 124 |
92 protected: | 125 protected: |
93 NextProto GetProtocol() const { | 126 NextProto GetProtocol() const { |
94 return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; | 127 return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; |
95 } | 128 } |
96 | 129 |
97 bool GetDependenciesFromPriority() const { | 130 bool GetDependenciesFromPriority() const { |
98 return GetParam() == kTestCaseHTTP2PriorityDependencies; | 131 return GetParam() == kTestCaseHTTP2PriorityDependencies; |
99 } | 132 } |
100 | 133 |
101 void TearDown() override { | 134 void TearDown() override { |
102 crypto::ECSignatureCreator::SetFactoryForTesting(NULL); | 135 crypto::ECSignatureCreator::SetFactoryForTesting(nullptr); |
103 base::MessageLoop::current()->RunUntilIdle(); | 136 base::MessageLoop::current()->RunUntilIdle(); |
104 EXPECT_TRUE(sequenced_data_->AllReadDataConsumed()); | 137 EXPECT_TRUE(sequenced_data_->AllReadDataConsumed()); |
105 EXPECT_TRUE(sequenced_data_->AllWriteDataConsumed()); | 138 EXPECT_TRUE(sequenced_data_->AllWriteDataConsumed()); |
106 } | 139 } |
107 | 140 |
108 // Initializes the session using SequencedSocketData. | 141 // Initializes the session using SequencedSocketData. |
109 void InitSession(MockRead* reads, | 142 void InitSession(MockRead* reads, |
110 size_t reads_count, | 143 size_t reads_count, |
111 MockWrite* writes, | 144 MockWrite* writes, |
112 size_t writes_count, | 145 size_t writes_count, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 // SpdyHttpStream::GetUploadProgress() should still work even before the | 177 // SpdyHttpStream::GetUploadProgress() should still work even before the |
145 // stream is initialized. | 178 // stream is initialized. |
146 TEST_P(SpdyHttpStreamTest, GetUploadProgressBeforeInitialization) { | 179 TEST_P(SpdyHttpStreamTest, GetUploadProgressBeforeInitialization) { |
147 MockRead reads[] = { | 180 MockRead reads[] = { |
148 MockRead(ASYNC, 0, 0) // EOF | 181 MockRead(ASYNC, 0, 0) // EOF |
149 }; | 182 }; |
150 | 183 |
151 HostPortPair host_port_pair("www.example.org", 80); | 184 HostPortPair host_port_pair("www.example.org", 80); |
152 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 185 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
153 PRIVACY_MODE_DISABLED); | 186 PRIVACY_MODE_DISABLED); |
154 InitSession(reads, arraysize(reads), NULL, 0, key); | 187 InitSession(reads, arraysize(reads), nullptr, 0, key); |
155 | 188 |
156 SpdyHttpStream stream(session_, false); | 189 SpdyHttpStream stream(session_, false); |
157 UploadProgress progress = stream.GetUploadProgress(); | 190 UploadProgress progress = stream.GetUploadProgress(); |
158 EXPECT_EQ(0u, progress.size()); | 191 EXPECT_EQ(0u, progress.size()); |
159 EXPECT_EQ(0u, progress.position()); | 192 EXPECT_EQ(0u, progress.position()); |
160 | 193 |
161 // Pump the event loop so |reads| is consumed before the function returns. | 194 // Pump the event loop so |reads| is consumed before the function returns. |
162 base::RunLoop().RunUntilIdle(); | 195 base::RunLoop().RunUntilIdle(); |
163 } | 196 } |
164 | 197 |
165 TEST_P(SpdyHttpStreamTest, SendRequest) { | 198 TEST_P(SpdyHttpStreamTest, SendRequest) { |
166 std::unique_ptr<SpdySerializedFrame> req( | 199 std::unique_ptr<SpdySerializedFrame> req( |
167 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 200 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
168 MockWrite writes[] = { | 201 MockWrite writes[] = { |
169 CreateMockWrite(*req.get(), 0), | 202 CreateMockWrite(*req.get(), 0), |
170 }; | 203 }; |
171 std::unique_ptr<SpdySerializedFrame> resp( | 204 std::unique_ptr<SpdySerializedFrame> resp( |
172 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 205 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
173 MockRead reads[] = { | 206 MockRead reads[] = { |
174 CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF | 207 CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF |
175 }; | 208 }; |
176 | 209 |
177 HostPortPair host_port_pair("www.example.org", 80); | 210 HostPortPair host_port_pair("www.example.org", 80); |
178 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 211 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
179 PRIVACY_MODE_DISABLED); | 212 PRIVACY_MODE_DISABLED); |
180 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | 213 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); |
181 | 214 |
182 HttpRequestInfo request; | 215 HttpRequestInfo request; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 TEST_P(SpdyHttpStreamTest, LoadTimingTwoRequests) { | 260 TEST_P(SpdyHttpStreamTest, LoadTimingTwoRequests) { |
228 std::unique_ptr<SpdySerializedFrame> req1( | 261 std::unique_ptr<SpdySerializedFrame> req1( |
229 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 262 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
230 std::unique_ptr<SpdySerializedFrame> req2( | 263 std::unique_ptr<SpdySerializedFrame> req2( |
231 spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); | 264 spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
232 MockWrite writes[] = { | 265 MockWrite writes[] = { |
233 CreateMockWrite(*req1, 0), | 266 CreateMockWrite(*req1, 0), |
234 CreateMockWrite(*req2, 1), | 267 CreateMockWrite(*req2, 1), |
235 }; | 268 }; |
236 std::unique_ptr<SpdySerializedFrame> resp1( | 269 std::unique_ptr<SpdySerializedFrame> resp1( |
237 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 270 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
238 std::unique_ptr<SpdySerializedFrame> body1( | 271 std::unique_ptr<SpdySerializedFrame> body1( |
239 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); | 272 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); |
240 std::unique_ptr<SpdySerializedFrame> resp2( | 273 std::unique_ptr<SpdySerializedFrame> resp2( |
241 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); | 274 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 3)); |
242 std::unique_ptr<SpdySerializedFrame> body2( | 275 std::unique_ptr<SpdySerializedFrame> body2( |
243 spdy_util_.ConstructSpdyBodyFrame(3, "", 0, true)); | 276 spdy_util_.ConstructSpdyBodyFrame(3, "", 0, true)); |
244 MockRead reads[] = { | 277 MockRead reads[] = { |
245 CreateMockRead(*resp1, 2), | 278 CreateMockRead(*resp1, 2), |
246 CreateMockRead(*body1, 3), | 279 CreateMockRead(*body1, 3), |
247 CreateMockRead(*resp2, 4), | 280 CreateMockRead(*resp2, 4), |
248 CreateMockRead(*body2, 5), | 281 CreateMockRead(*body2, 5), |
249 MockRead(ASYNC, 0, 6) // EOF | 282 MockRead(ASYNC, 0, 6) // EOF |
250 }; | 283 }; |
251 | 284 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 EXPECT_EQ(static_cast<int64_t>(req2->size()), | 356 EXPECT_EQ(static_cast<int64_t>(req2->size()), |
324 http_stream2->GetTotalSentBytes()); | 357 http_stream2->GetTotalSentBytes()); |
325 EXPECT_EQ(static_cast<int64_t>(resp2->size() + body2->size()), | 358 EXPECT_EQ(static_cast<int64_t>(resp2->size() + body2->size()), |
326 http_stream2->GetTotalReceivedBytes()); | 359 http_stream2->GetTotalReceivedBytes()); |
327 } | 360 } |
328 | 361 |
329 TEST_P(SpdyHttpStreamTest, SendChunkedPost) { | 362 TEST_P(SpdyHttpStreamTest, SendChunkedPost) { |
330 BufferedSpdyFramer framer(spdy_util_.spdy_version()); | 363 BufferedSpdyFramer framer(spdy_util_.spdy_version()); |
331 | 364 |
332 std::unique_ptr<SpdySerializedFrame> req( | 365 std::unique_ptr<SpdySerializedFrame> req( |
333 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 366 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
334 std::unique_ptr<SpdySerializedFrame> body( | 367 std::unique_ptr<SpdySerializedFrame> body( |
335 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_FIN)); | 368 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_FIN)); |
336 MockWrite writes[] = { | 369 MockWrite writes[] = { |
337 CreateMockWrite(*req, 0), // request | 370 CreateMockWrite(*req, 0), // request |
338 CreateMockWrite(*body, 1) // POST upload frame | 371 CreateMockWrite(*body, 1) // POST upload frame |
339 }; | 372 }; |
340 | 373 |
341 std::unique_ptr<SpdySerializedFrame> resp( | 374 std::unique_ptr<SpdySerializedFrame> resp( |
342 spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 375 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
343 MockRead reads[] = { | 376 MockRead reads[] = { |
344 CreateMockRead(*resp, 2), | 377 CreateMockRead(*resp, 2), |
345 CreateMockRead(*body, 3), | 378 CreateMockRead(*body, 3), |
346 MockRead(SYNCHRONOUS, 0, 4) // EOF | 379 MockRead(SYNCHRONOUS, 0, 4) // EOF |
347 }; | 380 }; |
348 | 381 |
349 HostPortPair host_port_pair("www.example.org", 80); | 382 HostPortPair host_port_pair("www.example.org", 80); |
350 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 383 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
351 PRIVACY_MODE_DISABLED); | 384 PRIVACY_MODE_DISABLED); |
352 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | 385 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 | 421 |
389 // Because the server closed the connection, we there shouldn't be a session | 422 // Because the server closed the connection, we there shouldn't be a session |
390 // in the pool anymore. | 423 // in the pool anymore. |
391 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 424 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
392 } | 425 } |
393 | 426 |
394 TEST_P(SpdyHttpStreamTest, ConnectionClosedDuringChunkedPost) { | 427 TEST_P(SpdyHttpStreamTest, ConnectionClosedDuringChunkedPost) { |
395 BufferedSpdyFramer framer(spdy_util_.spdy_version()); | 428 BufferedSpdyFramer framer(spdy_util_.spdy_version()); |
396 | 429 |
397 std::unique_ptr<SpdySerializedFrame> req( | 430 std::unique_ptr<SpdySerializedFrame> req( |
398 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 431 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
399 std::unique_ptr<SpdySerializedFrame> body( | 432 std::unique_ptr<SpdySerializedFrame> body( |
400 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_NONE)); | 433 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_NONE)); |
401 MockWrite writes[] = { | 434 MockWrite writes[] = { |
402 CreateMockWrite(*req, 0), // Request | 435 CreateMockWrite(*req, 0), // Request |
403 CreateMockWrite(*body, 1) // First POST upload frame | 436 CreateMockWrite(*body, 1) // First POST upload frame |
404 }; | 437 }; |
405 | 438 |
406 std::unique_ptr<SpdySerializedFrame> resp( | 439 std::unique_ptr<SpdySerializedFrame> resp( |
407 spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 440 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
408 MockRead reads[] = { | 441 MockRead reads[] = { |
409 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 2) // Server hangs up early. | 442 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 2) // Server hangs up early. |
410 }; | 443 }; |
411 | 444 |
412 HostPortPair host_port_pair("www.example.org", 80); | 445 HostPortPair host_port_pair("www.example.org", 80); |
413 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 446 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
414 PRIVACY_MODE_DISABLED); | 447 PRIVACY_MODE_DISABLED); |
415 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | 448 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); |
416 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); | 449 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); |
417 | 450 |
(...skipping 13 matching lines...) Expand all Loading... | |
431 HttpRequestHeaders headers; | 464 HttpRequestHeaders headers; |
432 BoundNetLog net_log; | 465 BoundNetLog net_log; |
433 SpdyHttpStream http_stream(session_, true); | 466 SpdyHttpStream http_stream(session_, true); |
434 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 467 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
435 net_log, CompletionCallback())); | 468 net_log, CompletionCallback())); |
436 | 469 |
437 EXPECT_EQ(ERR_IO_PENDING, | 470 EXPECT_EQ(ERR_IO_PENDING, |
438 http_stream.SendRequest(headers, &response, callback.callback())); | 471 http_stream.SendRequest(headers, &response, callback.callback())); |
439 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 472 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
440 | 473 |
474 // Server closes the connection. Thus, callback now returns | |
475 // "CONNECTION_CLOSED" error. | |
441 EXPECT_EQ(OK, callback.WaitForResult()); | 476 EXPECT_EQ(OK, callback.WaitForResult()); |
maksims (do not use this acc)
2016/06/03 11:39:08
As I said this returns OK instead of ERR_CONNECTIO
| |
442 | 477 |
443 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), | 478 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), |
444 http_stream.GetTotalSentBytes()); | 479 http_stream.GetTotalSentBytes()); |
445 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); | 480 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); |
446 | 481 |
447 // Because the server closed the connection, we there shouldn't be a session | 482 // Because the server closed the connection, we there shouldn't be a session |
448 // in the pool anymore. | 483 // in the pool anymore. |
449 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 484 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
450 | 485 |
451 // Appending a second chunk now should not result in a crash. | 486 // Appending a second chunk now should not result in a crash. |
452 upload_stream.AppendData(kUploadData, kUploadDataSize, true); | 487 upload_stream.AppendData(kUploadData, kUploadDataSize, true); |
453 // Appending data is currently done synchronously, but seems best to be | 488 // Appending data is currently done synchronously, but seems best to be |
454 // paranoid. | 489 // paranoid. |
455 base::RunLoop().RunUntilIdle(); | 490 base::RunLoop().RunUntilIdle(); |
456 | 491 |
457 // The total sent and received bytes should be unchanged. | 492 // The total sent and received bytes should be unchanged. |
458 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), | 493 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), |
459 http_stream.GetTotalSentBytes()); | 494 http_stream.GetTotalSentBytes()); |
460 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); | 495 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); |
461 } | 496 } |
462 | 497 |
463 // Test to ensure the SpdyStream state machine does not get confused when a | 498 // Test to ensure the SpdyStream state machine does not get confused when a |
464 // chunk becomes available while a write is pending. | 499 // chunk becomes available while a write is pending. |
465 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPost) { | 500 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPost) { |
466 const char kUploadData1[] = "12345678"; | 501 const char kUploadData1[] = "12345678"; |
467 const int kUploadData1Size = arraysize(kUploadData1)-1; | 502 const int kUploadData1Size = arraysize(kUploadData1)-1; |
468 std::unique_ptr<SpdySerializedFrame> req( | 503 std::unique_ptr<SpdySerializedFrame> req( |
469 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 504 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
470 std::unique_ptr<SpdySerializedFrame> chunk1( | 505 std::unique_ptr<SpdySerializedFrame> chunk1( |
471 spdy_util_.ConstructSpdyBodyFrame(1, false)); | 506 spdy_util_.ConstructSpdyBodyFrame(1, false)); |
472 std::unique_ptr<SpdySerializedFrame> chunk2(spdy_util_.ConstructSpdyBodyFrame( | 507 std::unique_ptr<SpdySerializedFrame> chunk2(spdy_util_.ConstructSpdyBodyFrame( |
473 1, kUploadData1, kUploadData1Size, false)); | 508 1, kUploadData1, kUploadData1Size, false)); |
474 std::unique_ptr<SpdySerializedFrame> chunk3( | 509 std::unique_ptr<SpdySerializedFrame> chunk3( |
475 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 510 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
476 MockWrite writes[] = { | 511 MockWrite writes[] = { |
477 CreateMockWrite(*req.get(), 0), | 512 CreateMockWrite(*req.get(), 0), |
478 CreateMockWrite(*chunk1, 1), // POST upload frames | 513 CreateMockWrite(*chunk1, 1), // POST upload frames |
479 CreateMockWrite(*chunk2, 2), | 514 CreateMockWrite(*chunk2, 2), |
480 CreateMockWrite(*chunk3, 3), | 515 CreateMockWrite(*chunk3, 3), |
481 }; | 516 }; |
482 std::unique_ptr<SpdySerializedFrame> resp( | 517 std::unique_ptr<SpdySerializedFrame> resp( |
483 spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 518 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
484 MockRead reads[] = { | 519 MockRead reads[] = { |
485 CreateMockRead(*resp, 4), | 520 CreateMockRead(*resp, 4), |
486 CreateMockRead(*chunk1, 5), | 521 CreateMockRead(*chunk1, 5), |
487 CreateMockRead(*chunk2, 6), | 522 CreateMockRead(*chunk2, 6), |
488 CreateMockRead(*chunk3, 7), | 523 CreateMockRead(*chunk3, 7), |
489 MockRead(ASYNC, 0, 8) // EOF | 524 MockRead(ASYNC, 0, 8) // EOF |
490 }; | 525 }; |
491 | 526 |
492 HostPortPair host_port_pair("www.example.org", 80); | 527 HostPortPair host_port_pair("www.example.org", 80); |
493 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 528 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
563 EXPECT_EQ(kUploadData, std::string(buf3->data(), kUploadDataSize)); | 598 EXPECT_EQ(kUploadData, std::string(buf3->data(), kUploadDataSize)); |
564 | 599 |
565 ASSERT_TRUE(response.headers.get()); | 600 ASSERT_TRUE(response.headers.get()); |
566 ASSERT_EQ(200, response.headers->response_code()); | 601 ASSERT_EQ(200, response.headers->response_code()); |
567 } | 602 } |
568 | 603 |
569 // Test that the SpdyStream state machine can handle sending a final empty data | 604 // Test that the SpdyStream state machine can handle sending a final empty data |
570 // frame when uploading a chunked data stream. | 605 // frame when uploading a chunked data stream. |
571 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithEmptyFinalDataFrame) { | 606 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithEmptyFinalDataFrame) { |
572 std::unique_ptr<SpdySerializedFrame> req( | 607 std::unique_ptr<SpdySerializedFrame> req( |
573 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 608 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
574 std::unique_ptr<SpdySerializedFrame> chunk1( | 609 std::unique_ptr<SpdySerializedFrame> chunk1( |
575 spdy_util_.ConstructSpdyBodyFrame(1, false)); | 610 spdy_util_.ConstructSpdyBodyFrame(1, false)); |
576 std::unique_ptr<SpdySerializedFrame> chunk2( | 611 std::unique_ptr<SpdySerializedFrame> chunk2( |
577 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); | 612 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); |
578 MockWrite writes[] = { | 613 MockWrite writes[] = { |
579 CreateMockWrite(*req.get(), 0), | 614 CreateMockWrite(*req.get(), 0), |
580 CreateMockWrite(*chunk1, 1), // POST upload frames | 615 CreateMockWrite(*chunk1, 1), // POST upload frames |
581 CreateMockWrite(*chunk2, 2), | 616 CreateMockWrite(*chunk2, 2), |
582 }; | 617 }; |
583 std::unique_ptr<SpdySerializedFrame> resp( | 618 std::unique_ptr<SpdySerializedFrame> resp( |
584 spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 619 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
585 MockRead reads[] = { | 620 MockRead reads[] = { |
586 CreateMockRead(*resp, 3), | 621 CreateMockRead(*resp, 3), |
587 CreateMockRead(*chunk1, 4), | 622 CreateMockRead(*chunk1, 4), |
588 CreateMockRead(*chunk2, 5), | 623 CreateMockRead(*chunk2, 5), |
589 MockRead(ASYNC, 0, 6) // EOF | 624 MockRead(ASYNC, 0, 6) // EOF |
590 }; | 625 }; |
591 | 626 |
592 HostPortPair host_port_pair("www.example.org", 80); | 627 HostPortPair host_port_pair("www.example.org", 80); |
593 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 628 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
594 PRIVACY_MODE_DISABLED); | 629 PRIVACY_MODE_DISABLED); |
(...skipping 27 matching lines...) Expand all Loading... | |
622 // Complete the initial request write and the first chunk. | 657 // Complete the initial request write and the first chunk. |
623 base::RunLoop().RunUntilIdle(); | 658 base::RunLoop().RunUntilIdle(); |
624 ASSERT_TRUE(callback.have_result()); | 659 ASSERT_TRUE(callback.have_result()); |
625 EXPECT_EQ(OK, callback.WaitForResult()); | 660 EXPECT_EQ(OK, callback.WaitForResult()); |
626 | 661 |
627 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), | 662 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), |
628 http_stream->GetTotalSentBytes()); | 663 http_stream->GetTotalSentBytes()); |
629 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); | 664 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); |
630 | 665 |
631 // Now end the stream with an empty data frame and the FIN set. | 666 // Now end the stream with an empty data frame and the FIN set. |
632 upload_stream.AppendData(NULL, 0, true); | 667 upload_stream.AppendData(nullptr, 0, true); |
633 | 668 |
634 // Finish writing the final frame, and perform all reads. | 669 // Finish writing the final frame, and perform all reads. |
635 base::RunLoop().RunUntilIdle(); | 670 base::RunLoop().RunUntilIdle(); |
636 | 671 |
637 // Check response headers. | 672 // Check response headers. |
638 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); | 673 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); |
639 | 674 |
640 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size()), | 675 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size()), |
641 http_stream->GetTotalSentBytes()); | 676 http_stream->GetTotalSentBytes()); |
642 EXPECT_EQ( | 677 EXPECT_EQ( |
(...skipping 13 matching lines...) Expand all Loading... | |
656 buf1.get(), kUploadDataSize, callback.callback())); | 691 buf1.get(), kUploadDataSize, callback.callback())); |
657 | 692 |
658 ASSERT_TRUE(response.headers.get()); | 693 ASSERT_TRUE(response.headers.get()); |
659 ASSERT_EQ(200, response.headers->response_code()); | 694 ASSERT_EQ(200, response.headers->response_code()); |
660 } | 695 } |
661 | 696 |
662 // Test that the SpdyStream state machine handles a chunked upload with no | 697 // Test that the SpdyStream state machine handles a chunked upload with no |
663 // payload. Unclear if this is a case worth supporting. | 698 // payload. Unclear if this is a case worth supporting. |
664 TEST_P(SpdyHttpStreamTest, ChunkedPostWithEmptyPayload) { | 699 TEST_P(SpdyHttpStreamTest, ChunkedPostWithEmptyPayload) { |
665 std::unique_ptr<SpdySerializedFrame> req( | 700 std::unique_ptr<SpdySerializedFrame> req( |
666 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 701 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
667 std::unique_ptr<SpdySerializedFrame> chunk( | 702 std::unique_ptr<SpdySerializedFrame> chunk( |
668 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); | 703 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); |
669 MockWrite writes[] = { | 704 MockWrite writes[] = { |
670 CreateMockWrite(*req.get(), 0), | 705 CreateMockWrite(*req.get(), 0), |
671 CreateMockWrite(*chunk, 1), | 706 CreateMockWrite(*chunk, 1), |
672 }; | 707 }; |
673 std::unique_ptr<SpdySerializedFrame> resp( | 708 std::unique_ptr<SpdySerializedFrame> resp( |
674 spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 709 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
675 MockRead reads[] = { | 710 MockRead reads[] = { |
676 CreateMockRead(*resp, 2), | 711 CreateMockRead(*resp, 2), |
677 CreateMockRead(*chunk, 3), | 712 CreateMockRead(*chunk, 3), |
678 MockRead(ASYNC, 0, 4) // EOF | 713 MockRead(ASYNC, 0, 4) // EOF |
679 }; | 714 }; |
680 | 715 |
681 HostPortPair host_port_pair("www.example.org", 80); | 716 HostPortPair host_port_pair("www.example.org", 80); |
682 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 717 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
683 PRIVACY_MODE_DISABLED); | 718 PRIVACY_MODE_DISABLED); |
684 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | 719 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
734 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 | 769 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 |
735 TEST_P(SpdyHttpStreamTest, SpdyURLTest) { | 770 TEST_P(SpdyHttpStreamTest, SpdyURLTest) { |
736 const char* const full_url = "http://www.example.org/foo?query=what#anchor"; | 771 const char* const full_url = "http://www.example.org/foo?query=what#anchor"; |
737 const char* const base_url = "http://www.example.org/foo?query=what"; | 772 const char* const base_url = "http://www.example.org/foo?query=what"; |
738 std::unique_ptr<SpdySerializedFrame> req( | 773 std::unique_ptr<SpdySerializedFrame> req( |
739 spdy_util_.ConstructSpdyGet(base_url, 1, LOWEST)); | 774 spdy_util_.ConstructSpdyGet(base_url, 1, LOWEST)); |
740 MockWrite writes[] = { | 775 MockWrite writes[] = { |
741 CreateMockWrite(*req.get(), 0), | 776 CreateMockWrite(*req.get(), 0), |
742 }; | 777 }; |
743 std::unique_ptr<SpdySerializedFrame> resp( | 778 std::unique_ptr<SpdySerializedFrame> resp( |
744 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 779 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
745 MockRead reads[] = { | 780 MockRead reads[] = { |
746 CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF | 781 CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF |
747 }; | 782 }; |
748 | 783 |
749 HostPortPair host_port_pair("www.example.org", 80); | 784 HostPortPair host_port_pair("www.example.org", 80); |
750 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 785 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
751 PRIVACY_MODE_DISABLED); | 786 PRIVACY_MODE_DISABLED); |
752 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | 787 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); |
753 | 788 |
754 HttpRequestInfo request; | 789 HttpRequestInfo request; |
(...skipping 23 matching lines...) Expand all Loading... | |
778 | 813 |
779 // Because we abandoned the stream, we don't expect to find a session in the | 814 // Because we abandoned the stream, we don't expect to find a session in the |
780 // pool anymore. | 815 // pool anymore. |
781 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 816 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
782 } | 817 } |
783 | 818 |
784 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be | 819 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be |
785 // made available is handled correctly. | 820 // made available is handled correctly. |
786 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { | 821 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { |
787 std::unique_ptr<SpdySerializedFrame> req( | 822 std::unique_ptr<SpdySerializedFrame> req( |
788 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 823 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
789 std::unique_ptr<SpdySerializedFrame> chunk1( | 824 std::unique_ptr<SpdySerializedFrame> chunk1( |
790 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 825 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
791 MockWrite writes[] = { | 826 MockWrite writes[] = { |
792 CreateMockWrite(*req.get(), 0), | 827 CreateMockWrite(*req.get(), 0), |
793 CreateMockWrite(*chunk1, 1), | 828 CreateMockWrite(*chunk1, 1), |
794 }; | 829 }; |
795 std::unique_ptr<SpdySerializedFrame> resp( | 830 std::unique_ptr<SpdySerializedFrame> resp( |
796 spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 831 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
797 std::unique_ptr<SpdySerializedFrame> window_update( | 832 std::unique_ptr<SpdySerializedFrame> window_update( |
798 spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); | 833 spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); |
799 MockRead reads[] = { | 834 MockRead reads[] = { |
800 CreateMockRead(*window_update, 2), | 835 CreateMockRead(*window_update, 2), |
801 MockRead(ASYNC, ERR_IO_PENDING, 3), | 836 MockRead(ASYNC, ERR_IO_PENDING, 3), |
802 CreateMockRead(*resp, 4), | 837 CreateMockRead(*resp, 4), |
803 CreateMockRead(*chunk1, 5), | 838 CreateMockRead(*chunk1, 5), |
804 MockRead(ASYNC, 0, 6) // EOF | 839 MockRead(ASYNC, 0, 6) // EOF |
805 }; | 840 }; |
806 | 841 |
(...skipping 22 matching lines...) Expand all Loading... | |
829 HttpResponseInfo response; | 864 HttpResponseInfo response; |
830 // This will attempt to Write() the initial request and headers, which will | 865 // This will attempt to Write() the initial request and headers, which will |
831 // complete asynchronously. | 866 // complete asynchronously. |
832 TestCompletionCallback callback; | 867 TestCompletionCallback callback; |
833 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 868 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
834 callback.callback())); | 869 callback.callback())); |
835 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 870 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
836 | 871 |
837 // Complete the initial request write and first chunk. | 872 // Complete the initial request write and first chunk. |
838 base::RunLoop().RunUntilIdle(); | 873 base::RunLoop().RunUntilIdle(); |
839 ASSERT_TRUE(callback.have_result()); | |
840 EXPECT_EQ(OK, callback.WaitForResult()); | |
841 | 874 |
842 EXPECT_EQ(static_cast<int64_t>(req->size()), | 875 EXPECT_EQ(static_cast<int64_t>(req->size()), |
843 http_stream->GetTotalSentBytes()); | 876 http_stream->GetTotalSentBytes()); |
844 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); | 877 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); |
845 | 878 |
846 upload_stream.AppendData(kUploadData, kUploadDataSize, true); | 879 upload_stream.AppendData(kUploadData, kUploadDataSize, true); |
847 | 880 |
848 // Verify that the window size has decreased. | 881 // Verify that the window size has decreased. |
849 ASSERT_TRUE(http_stream->stream() != NULL); | 882 ASSERT_TRUE(http_stream->stream() != nullptr); |
850 EXPECT_NE(static_cast<int>( | 883 EXPECT_NE(static_cast<int>( |
851 SpdySession::GetDefaultInitialWindowSize(session_->protocol())), | 884 SpdySession::GetDefaultInitialWindowSize(session_->protocol())), |
852 http_stream->stream()->send_window_size()); | 885 http_stream->stream()->send_window_size()); |
853 | 886 |
887 ASSERT_TRUE(callback.have_result()); | |
888 EXPECT_EQ(OK, callback.WaitForResult()); | |
maksims (do not use this acc)
2016/06/03 11:39:08
Due to new behavior, the callback should be read o
| |
889 | |
854 // Read window update. | 890 // Read window update. |
855 base::RunLoop().RunUntilIdle(); | 891 base::RunLoop().RunUntilIdle(); |
856 | 892 |
857 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), | 893 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), |
858 http_stream->GetTotalSentBytes()); | 894 http_stream->GetTotalSentBytes()); |
859 // The window update is not counted in the total received bytes. | 895 // The window update is not counted in the total received bytes. |
860 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); | 896 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); |
861 | 897 |
862 // Verify the window update. | 898 // Verify the window update. |
863 ASSERT_TRUE(http_stream->stream() != NULL); | 899 ASSERT_TRUE(http_stream->stream() != nullptr); |
864 EXPECT_EQ(static_cast<int>( | 900 EXPECT_EQ(static_cast<int>( |
865 SpdySession::GetDefaultInitialWindowSize(session_->protocol())), | 901 SpdySession::GetDefaultInitialWindowSize(session_->protocol())), |
866 http_stream->stream()->send_window_size()); | 902 http_stream->stream()->send_window_size()); |
867 | 903 |
868 // Read rest of data. | 904 // Read rest of data. |
869 sequenced_data_->Resume(); | 905 sequenced_data_->Resume(); |
870 base::RunLoop().RunUntilIdle(); | 906 base::RunLoop().RunUntilIdle(); |
871 | 907 |
872 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), | 908 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), |
873 http_stream->GetTotalSentBytes()); | 909 http_stream->GetTotalSentBytes()); |
874 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size()), | 910 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size()), |
875 http_stream->GetTotalReceivedBytes()); | 911 http_stream->GetTotalReceivedBytes()); |
876 | 912 |
877 // Check response headers. | 913 // Check response headers. |
878 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); | 914 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); |
879 | 915 |
880 // Check |chunk1| response. | 916 // Check |chunk1| response. |
881 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); | 917 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); |
882 ASSERT_EQ(kUploadDataSize, | 918 ASSERT_EQ(kUploadDataSize, |
883 http_stream->ReadResponseBody( | 919 http_stream->ReadResponseBody( |
884 buf1.get(), kUploadDataSize, callback.callback())); | 920 buf1.get(), kUploadDataSize, callback.callback())); |
885 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); | 921 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); |
886 | 922 |
887 ASSERT_TRUE(response.headers.get()); | 923 ASSERT_TRUE(response.headers.get()); |
888 ASSERT_EQ(200, response.headers->response_code()); | 924 ASSERT_EQ(200, response.headers->response_code()); |
889 } | 925 } |
890 | 926 |
927 TEST_P(SpdyHttpStreamTest, DataReadErrorSynchronous) { | |
928 std::unique_ptr<SpdySerializedFrame> req( | |
929 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | |
930 | |
931 // Server receives RST_STREAM_INTERNAL_ERROR on clients' internal failure. | |
932 // The failure is a reading error in this case caused by | |
933 // UploadDataStream::Read() | |
934 std::unique_ptr<SpdySerializedFrame> rst_frame( | |
935 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_INTERNAL_ERROR)); | |
936 | |
937 MockWrite writes[] = { | |
938 CreateMockWrite(*req, 0, SYNCHRONOUS), // Request | |
939 CreateMockWrite(*rst_frame, 1, SYNCHRONOUS) // Reset frame | |
940 }; | |
941 | |
942 std::unique_ptr<SpdySerializedFrame> resp( | |
943 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | |
944 | |
945 MockRead reads[] = { | |
946 CreateMockRead(*resp, 2), | |
947 MockRead(SYNCHRONOUS, 0, 3), | |
948 }; | |
949 | |
950 HostPortPair host_port_pair("www.example.org", 80); | |
951 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
952 PRIVACY_MODE_DISABLED); | |
953 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | |
954 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); | |
955 ReadErrorUploadDataStream upload_data_stream( | |
956 ReadErrorUploadDataStream::FailureMode::SYNC); | |
957 ASSERT_EQ(OK, upload_data_stream.Init(TestCompletionCallback().callback())); | |
958 | |
959 HttpRequestInfo request; | |
960 request.method = "POST"; | |
961 request.url = GURL("http://www.example.org/"); | |
962 request.upload_data_stream = &upload_data_stream; | |
963 | |
964 TestCompletionCallback callback; | |
965 HttpResponseInfo response; | |
966 HttpRequestHeaders headers; | |
967 BoundNetLog net_log; | |
968 SpdyHttpStream http_stream(session_, true); | |
969 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | |
970 net_log, CompletionCallback())); | |
971 | |
972 int result = http_stream.SendRequest(headers, &response, callback.callback()); | |
973 EXPECT_EQ(ERR_FAILED, callback.GetResult(result)); | |
974 | |
975 // Because the server has not closed the connection yet, there shouldn't be | |
976 // a stream but a session in the pool | |
977 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | |
978 } | |
979 | |
980 TEST_P(SpdyHttpStreamTest, DataReadErrorAsynchronous) { | |
981 std::unique_ptr<SpdySerializedFrame> req( | |
982 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | |
983 | |
984 // Server receives RST_STREAM_INTERNAL_ERROR on clients' internal failure. | |
985 // The failure is a reading error in this case caused by | |
986 // UploadDataStream::Read() | |
987 std::unique_ptr<SpdySerializedFrame> rst_frame( | |
988 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_INTERNAL_ERROR)); | |
989 | |
990 MockWrite writes[] = { | |
991 CreateMockWrite(*req, 0), // Request | |
992 CreateMockWrite(*rst_frame, 1) // Reset frame | |
993 }; | |
994 | |
995 std::unique_ptr<SpdySerializedFrame> resp( | |
996 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | |
997 | |
998 MockRead reads[] = { | |
999 MockRead(ASYNC, 0, 2), | |
1000 }; | |
1001 | |
1002 HostPortPair host_port_pair("www.example.org", 80); | |
1003 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
1004 PRIVACY_MODE_DISABLED); | |
1005 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | |
1006 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); | |
1007 | |
1008 ReadErrorUploadDataStream upload_data_stream( | |
1009 ReadErrorUploadDataStream::FailureMode::ASYNC); | |
1010 ASSERT_EQ(OK, upload_data_stream.Init(TestCompletionCallback().callback())); | |
1011 | |
1012 HttpRequestInfo request; | |
1013 request.method = "POST"; | |
1014 request.url = GURL("http://www.example.org/"); | |
1015 request.upload_data_stream = &upload_data_stream; | |
1016 | |
1017 TestCompletionCallback callback; | |
1018 HttpResponseInfo response; | |
1019 HttpRequestHeaders headers; | |
1020 BoundNetLog net_log; | |
1021 SpdyHttpStream http_stream(session_, true); | |
1022 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | |
1023 net_log, CompletionCallback())); | |
1024 | |
1025 int result = http_stream.SendRequest(headers, &response, callback.callback()); | |
1026 EXPECT_EQ(ERR_IO_PENDING, result); | |
1027 EXPECT_EQ(ERR_FAILED, callback.GetResult(result)); | |
1028 | |
1029 // Because the server has closed the connection, there shouldn't be a session | |
1030 // in the pool anymore. | |
1031 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | |
1032 } | |
1033 | |
891 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 1034 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
892 // methods. | 1035 // methods. |
893 | 1036 |
894 } // namespace net | 1037 } // namespace net |
OLD | NEW |