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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 EXPECT_FALSE(load_timing_info.socket_reused); | 69 EXPECT_FALSE(load_timing_info.socket_reused); |
70 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 70 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
71 | 71 |
72 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, | 72 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
73 CONNECT_TIMING_HAS_DNS_TIMES); | 73 CONNECT_TIMING_HAS_DNS_TIMES); |
74 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); | 74 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); |
75 } | 75 } |
76 | 76 |
77 } // namespace | 77 } // namespace |
78 | 78 |
| 79 class ReadErrorUploadDataStream : public UploadDataStream { |
| 80 public: |
| 81 enum class FailureMode { SYNC, ASYNC }; |
| 82 |
| 83 explicit ReadErrorUploadDataStream(FailureMode mode) |
| 84 : UploadDataStream(true, 0), async_(mode), weak_factory_(this) {} |
| 85 |
| 86 private: |
| 87 void CompleteRead() { UploadDataStream::OnReadCompleted(ERR_FAILED); } |
| 88 |
| 89 // UploadDataStream implementation: |
| 90 int InitInternal() override { return OK; } |
| 91 |
| 92 int ReadInternal(IOBuffer* buf, int buf_len) override { |
| 93 if (async_ == FailureMode::ASYNC) { |
| 94 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 95 FROM_HERE, base::Bind(&ReadErrorUploadDataStream::CompleteRead, |
| 96 weak_factory_.GetWeakPtr())); |
| 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 |
79 class SpdyHttpStreamTest : public testing::Test, | 111 class SpdyHttpStreamTest : public testing::Test, |
80 public testing::WithParamInterface<TestCase> { | 112 public testing::WithParamInterface<TestCase> { |
81 public: | 113 public: |
82 SpdyHttpStreamTest() | 114 SpdyHttpStreamTest() |
83 : spdy_util_(GetProtocol(), GetDependenciesFromPriority()), | 115 : spdy_util_(GetProtocol(), GetDependenciesFromPriority()), |
84 session_deps_(GetProtocol()) { | 116 session_deps_(GetProtocol()) { |
85 session_deps_.enable_priority_dependencies = GetDependenciesFromPriority(); | 117 session_deps_.enable_priority_dependencies = GetDependenciesFromPriority(); |
86 session_deps_.net_log = &net_log_; | 118 session_deps_.net_log = &net_log_; |
87 } | 119 } |
88 | 120 |
89 ~SpdyHttpStreamTest() {} | 121 ~SpdyHttpStreamTest() {} |
90 | 122 |
91 protected: | 123 protected: |
92 NextProto GetProtocol() const { | 124 NextProto GetProtocol() const { |
93 return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; | 125 return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; |
94 } | 126 } |
95 | 127 |
96 bool GetDependenciesFromPriority() const { | 128 bool GetDependenciesFromPriority() const { |
97 return GetParam() == kTestCaseHTTP2PriorityDependencies; | 129 return GetParam() == kTestCaseHTTP2PriorityDependencies; |
98 } | 130 } |
99 | 131 |
100 void TearDown() override { | 132 void TearDown() override { |
101 crypto::ECSignatureCreator::SetFactoryForTesting(NULL); | 133 crypto::ECSignatureCreator::SetFactoryForTesting(nullptr); |
102 base::RunLoop().RunUntilIdle(); | 134 base::RunLoop().RunUntilIdle(); |
103 EXPECT_TRUE(sequenced_data_->AllReadDataConsumed()); | 135 EXPECT_TRUE(sequenced_data_->AllReadDataConsumed()); |
104 EXPECT_TRUE(sequenced_data_->AllWriteDataConsumed()); | 136 EXPECT_TRUE(sequenced_data_->AllWriteDataConsumed()); |
105 } | 137 } |
106 | 138 |
107 // Initializes the session using SequencedSocketData. | 139 // Initializes the session using SequencedSocketData. |
108 void InitSession(MockRead* reads, | 140 void InitSession(MockRead* reads, |
109 size_t reads_count, | 141 size_t reads_count, |
110 MockWrite* writes, | 142 MockWrite* writes, |
111 size_t writes_count, | 143 size_t writes_count, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // SpdyHttpStream::GetUploadProgress() should still work even before the | 175 // SpdyHttpStream::GetUploadProgress() should still work even before the |
144 // stream is initialized. | 176 // stream is initialized. |
145 TEST_P(SpdyHttpStreamTest, GetUploadProgressBeforeInitialization) { | 177 TEST_P(SpdyHttpStreamTest, GetUploadProgressBeforeInitialization) { |
146 MockRead reads[] = { | 178 MockRead reads[] = { |
147 MockRead(ASYNC, 0, 0) // EOF | 179 MockRead(ASYNC, 0, 0) // EOF |
148 }; | 180 }; |
149 | 181 |
150 HostPortPair host_port_pair("www.example.org", 80); | 182 HostPortPair host_port_pair("www.example.org", 80); |
151 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 183 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
152 PRIVACY_MODE_DISABLED); | 184 PRIVACY_MODE_DISABLED); |
153 InitSession(reads, arraysize(reads), NULL, 0, key); | 185 InitSession(reads, arraysize(reads), nullptr, 0, key); |
154 | 186 |
155 SpdyHttpStream stream(session_, false); | 187 SpdyHttpStream stream(session_, false); |
156 UploadProgress progress = stream.GetUploadProgress(); | 188 UploadProgress progress = stream.GetUploadProgress(); |
157 EXPECT_EQ(0u, progress.size()); | 189 EXPECT_EQ(0u, progress.size()); |
158 EXPECT_EQ(0u, progress.position()); | 190 EXPECT_EQ(0u, progress.position()); |
159 | 191 |
160 // Pump the event loop so |reads| is consumed before the function returns. | 192 // Pump the event loop so |reads| is consumed before the function returns. |
161 base::RunLoop().RunUntilIdle(); | 193 base::RunLoop().RunUntilIdle(); |
162 } | 194 } |
163 | 195 |
164 TEST_P(SpdyHttpStreamTest, SendRequest) { | 196 TEST_P(SpdyHttpStreamTest, SendRequest) { |
165 std::unique_ptr<SpdySerializedFrame> req( | 197 std::unique_ptr<SpdySerializedFrame> req( |
166 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 198 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
167 MockWrite writes[] = { | 199 MockWrite writes[] = { |
168 CreateMockWrite(*req.get(), 0), | 200 CreateMockWrite(*req.get(), 0), |
169 }; | 201 }; |
170 std::unique_ptr<SpdySerializedFrame> resp( | 202 std::unique_ptr<SpdySerializedFrame> resp( |
171 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 203 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
172 MockRead reads[] = { | 204 MockRead reads[] = { |
173 CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF | 205 CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF |
174 }; | 206 }; |
175 | 207 |
176 HostPortPair host_port_pair("www.example.org", 80); | 208 HostPortPair host_port_pair("www.example.org", 80); |
177 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 209 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
178 PRIVACY_MODE_DISABLED); | 210 PRIVACY_MODE_DISABLED); |
179 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | 211 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); |
180 | 212 |
181 HttpRequestInfo request; | 213 HttpRequestInfo request; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 TEST_P(SpdyHttpStreamTest, LoadTimingTwoRequests) { | 258 TEST_P(SpdyHttpStreamTest, LoadTimingTwoRequests) { |
227 std::unique_ptr<SpdySerializedFrame> req1( | 259 std::unique_ptr<SpdySerializedFrame> req1( |
228 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 260 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
229 std::unique_ptr<SpdySerializedFrame> req2( | 261 std::unique_ptr<SpdySerializedFrame> req2( |
230 spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); | 262 spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
231 MockWrite writes[] = { | 263 MockWrite writes[] = { |
232 CreateMockWrite(*req1, 0), | 264 CreateMockWrite(*req1, 0), |
233 CreateMockWrite(*req2, 1), | 265 CreateMockWrite(*req2, 1), |
234 }; | 266 }; |
235 std::unique_ptr<SpdySerializedFrame> resp1( | 267 std::unique_ptr<SpdySerializedFrame> resp1( |
236 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 268 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
237 std::unique_ptr<SpdySerializedFrame> body1( | 269 std::unique_ptr<SpdySerializedFrame> body1( |
238 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); | 270 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); |
239 std::unique_ptr<SpdySerializedFrame> resp2( | 271 std::unique_ptr<SpdySerializedFrame> resp2( |
240 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); | 272 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 3)); |
241 std::unique_ptr<SpdySerializedFrame> body2( | 273 std::unique_ptr<SpdySerializedFrame> body2( |
242 spdy_util_.ConstructSpdyBodyFrame(3, "", 0, true)); | 274 spdy_util_.ConstructSpdyBodyFrame(3, "", 0, true)); |
243 MockRead reads[] = { | 275 MockRead reads[] = { |
244 CreateMockRead(*resp1, 2), | 276 CreateMockRead(*resp1, 2), |
245 CreateMockRead(*body1, 3), | 277 CreateMockRead(*body1, 3), |
246 CreateMockRead(*resp2, 4), | 278 CreateMockRead(*resp2, 4), |
247 CreateMockRead(*body2, 5), | 279 CreateMockRead(*body2, 5), |
248 MockRead(ASYNC, 0, 6) // EOF | 280 MockRead(ASYNC, 0, 6) // EOF |
249 }; | 281 }; |
250 | 282 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 EXPECT_EQ(static_cast<int64_t>(req2->size()), | 354 EXPECT_EQ(static_cast<int64_t>(req2->size()), |
323 http_stream2->GetTotalSentBytes()); | 355 http_stream2->GetTotalSentBytes()); |
324 EXPECT_EQ(static_cast<int64_t>(resp2->size() + body2->size()), | 356 EXPECT_EQ(static_cast<int64_t>(resp2->size() + body2->size()), |
325 http_stream2->GetTotalReceivedBytes()); | 357 http_stream2->GetTotalReceivedBytes()); |
326 } | 358 } |
327 | 359 |
328 TEST_P(SpdyHttpStreamTest, SendChunkedPost) { | 360 TEST_P(SpdyHttpStreamTest, SendChunkedPost) { |
329 BufferedSpdyFramer framer(spdy_util_.spdy_version()); | 361 BufferedSpdyFramer framer(spdy_util_.spdy_version()); |
330 | 362 |
331 std::unique_ptr<SpdySerializedFrame> req( | 363 std::unique_ptr<SpdySerializedFrame> req( |
332 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 364 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
333 std::unique_ptr<SpdySerializedFrame> body( | 365 std::unique_ptr<SpdySerializedFrame> body( |
334 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_FIN)); | 366 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_FIN)); |
335 MockWrite writes[] = { | 367 MockWrite writes[] = { |
336 CreateMockWrite(*req, 0), // request | 368 CreateMockWrite(*req, 0), // request |
337 CreateMockWrite(*body, 1) // POST upload frame | 369 CreateMockWrite(*body, 1) // POST upload frame |
338 }; | 370 }; |
339 | 371 |
340 std::unique_ptr<SpdySerializedFrame> resp( | 372 std::unique_ptr<SpdySerializedFrame> resp( |
341 spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 373 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
342 MockRead reads[] = { | 374 MockRead reads[] = { |
343 CreateMockRead(*resp, 2), | 375 CreateMockRead(*resp, 2), |
344 CreateMockRead(*body, 3), | 376 CreateMockRead(*body, 3), |
345 MockRead(SYNCHRONOUS, 0, 4) // EOF | 377 MockRead(SYNCHRONOUS, 0, 4) // EOF |
346 }; | 378 }; |
347 | 379 |
348 HostPortPair host_port_pair("www.example.org", 80); | 380 HostPortPair host_port_pair("www.example.org", 80); |
349 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 381 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
350 PRIVACY_MODE_DISABLED); | 382 PRIVACY_MODE_DISABLED); |
351 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | 383 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 http_stream.GetTotalReceivedBytes()); | 418 http_stream.GetTotalReceivedBytes()); |
387 | 419 |
388 // Because the server closed the connection, we there shouldn't be a session | 420 // Because the server closed the connection, we there shouldn't be a session |
389 // in the pool anymore. | 421 // in the pool anymore. |
390 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 422 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
391 } | 423 } |
392 | 424 |
393 // This unittest tests the request callback is properly called and handled. | 425 // This unittest tests the request callback is properly called and handled. |
394 TEST_P(SpdyHttpStreamTest, SendChunkedPostLastEmpty) { | 426 TEST_P(SpdyHttpStreamTest, SendChunkedPostLastEmpty) { |
395 std::unique_ptr<SpdySerializedFrame> req( | 427 std::unique_ptr<SpdySerializedFrame> req( |
396 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 428 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
397 std::unique_ptr<SpdySerializedFrame> chunk( | 429 std::unique_ptr<SpdySerializedFrame> chunk( |
398 spdy_util_.ConstructSpdyBodyFrame(1, nullptr, 0, true)); | 430 spdy_util_.ConstructSpdyBodyFrame(1, nullptr, 0, true)); |
399 MockWrite writes[] = { | 431 MockWrite writes[] = { |
400 CreateMockWrite(*req, 0), // request | 432 CreateMockWrite(*req, 0), // request |
401 CreateMockWrite(*chunk, 1), | 433 CreateMockWrite(*chunk, 1), |
402 }; | 434 }; |
403 | 435 |
404 std::unique_ptr<SpdySerializedFrame> resp( | 436 std::unique_ptr<SpdySerializedFrame> resp( |
405 spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 437 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
406 MockRead reads[] = { | 438 MockRead reads[] = { |
407 CreateMockRead(*resp, 2), | 439 CreateMockRead(*resp, 2), |
408 CreateMockRead(*chunk, 3), | 440 CreateMockRead(*chunk, 3), |
409 MockRead(SYNCHRONOUS, 0, 4) // EOF | 441 MockRead(SYNCHRONOUS, 0, 4) // EOF |
410 }; | 442 }; |
411 | 443 |
412 HostPortPair host_port_pair("www.example.org", 80); | 444 HostPortPair host_port_pair("www.example.org", 80); |
413 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 445 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
414 PRIVACY_MODE_DISABLED); | 446 PRIVACY_MODE_DISABLED); |
415 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | 447 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); |
(...skipping 29 matching lines...) Expand all Loading... |
445 | 477 |
446 // Because the server closed the connection, there shouldn't be a session | 478 // Because the server closed the connection, there shouldn't be a session |
447 // in the pool anymore. | 479 // in the pool anymore. |
448 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 480 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
449 } | 481 } |
450 | 482 |
451 TEST_P(SpdyHttpStreamTest, ConnectionClosedDuringChunkedPost) { | 483 TEST_P(SpdyHttpStreamTest, ConnectionClosedDuringChunkedPost) { |
452 BufferedSpdyFramer framer(spdy_util_.spdy_version()); | 484 BufferedSpdyFramer framer(spdy_util_.spdy_version()); |
453 | 485 |
454 std::unique_ptr<SpdySerializedFrame> req( | 486 std::unique_ptr<SpdySerializedFrame> req( |
455 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 487 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
456 std::unique_ptr<SpdySerializedFrame> body( | 488 std::unique_ptr<SpdySerializedFrame> body( |
457 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_NONE)); | 489 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_NONE)); |
458 MockWrite writes[] = { | 490 MockWrite writes[] = { |
459 CreateMockWrite(*req, 0), // Request | 491 CreateMockWrite(*req, 0), // Request |
460 CreateMockWrite(*body, 1) // First POST upload frame | 492 CreateMockWrite(*body, 1) // First POST upload frame |
461 }; | 493 }; |
462 | 494 |
463 std::unique_ptr<SpdySerializedFrame> resp( | 495 std::unique_ptr<SpdySerializedFrame> resp( |
464 spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 496 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
465 MockRead reads[] = { | 497 MockRead reads[] = { |
466 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 2) // Server hangs up early. | 498 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 2) // Server hangs up early. |
467 }; | 499 }; |
468 | 500 |
469 HostPortPair host_port_pair("www.example.org", 80); | 501 HostPortPair host_port_pair("www.example.org", 80); |
470 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 502 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
471 PRIVACY_MODE_DISABLED); | 503 PRIVACY_MODE_DISABLED); |
472 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | 504 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); |
473 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); | 505 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); |
474 | 506 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 http_stream.GetTotalSentBytes()); | 548 http_stream.GetTotalSentBytes()); |
517 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); | 549 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); |
518 } | 550 } |
519 | 551 |
520 // Test to ensure the SpdyStream state machine does not get confused when a | 552 // Test to ensure the SpdyStream state machine does not get confused when a |
521 // chunk becomes available while a write is pending. | 553 // chunk becomes available while a write is pending. |
522 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPost) { | 554 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPost) { |
523 const char kUploadData1[] = "12345678"; | 555 const char kUploadData1[] = "12345678"; |
524 const int kUploadData1Size = arraysize(kUploadData1)-1; | 556 const int kUploadData1Size = arraysize(kUploadData1)-1; |
525 std::unique_ptr<SpdySerializedFrame> req( | 557 std::unique_ptr<SpdySerializedFrame> req( |
526 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 558 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
527 std::unique_ptr<SpdySerializedFrame> chunk1( | 559 std::unique_ptr<SpdySerializedFrame> chunk1( |
528 spdy_util_.ConstructSpdyBodyFrame(1, false)); | 560 spdy_util_.ConstructSpdyBodyFrame(1, false)); |
529 std::unique_ptr<SpdySerializedFrame> chunk2(spdy_util_.ConstructSpdyBodyFrame( | 561 std::unique_ptr<SpdySerializedFrame> chunk2(spdy_util_.ConstructSpdyBodyFrame( |
530 1, kUploadData1, kUploadData1Size, false)); | 562 1, kUploadData1, kUploadData1Size, false)); |
531 std::unique_ptr<SpdySerializedFrame> chunk3( | 563 std::unique_ptr<SpdySerializedFrame> chunk3( |
532 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 564 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
533 MockWrite writes[] = { | 565 MockWrite writes[] = { |
534 CreateMockWrite(*req.get(), 0), | 566 CreateMockWrite(*req.get(), 0), |
535 CreateMockWrite(*chunk1, 1), // POST upload frames | 567 CreateMockWrite(*chunk1, 1), // POST upload frames |
536 CreateMockWrite(*chunk2, 2), | 568 CreateMockWrite(*chunk2, 2), |
537 CreateMockWrite(*chunk3, 3), | 569 CreateMockWrite(*chunk3, 3), |
538 }; | 570 }; |
539 std::unique_ptr<SpdySerializedFrame> resp( | 571 std::unique_ptr<SpdySerializedFrame> resp( |
540 spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 572 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
541 MockRead reads[] = { | 573 MockRead reads[] = { |
542 CreateMockRead(*resp, 4), | 574 CreateMockRead(*resp, 4), |
543 CreateMockRead(*chunk1, 5), | 575 CreateMockRead(*chunk1, 5), |
544 CreateMockRead(*chunk2, 6), | 576 CreateMockRead(*chunk2, 6), |
545 CreateMockRead(*chunk3, 7), | 577 CreateMockRead(*chunk3, 7), |
546 MockRead(ASYNC, 0, 8) // EOF | 578 MockRead(ASYNC, 0, 8) // EOF |
547 }; | 579 }; |
548 | 580 |
549 HostPortPair host_port_pair("www.example.org", 80); | 581 HostPortPair host_port_pair("www.example.org", 80); |
550 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 582 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 EXPECT_EQ(kUploadData, std::string(buf3->data(), kUploadDataSize)); | 653 EXPECT_EQ(kUploadData, std::string(buf3->data(), kUploadDataSize)); |
622 | 654 |
623 ASSERT_TRUE(response.headers.get()); | 655 ASSERT_TRUE(response.headers.get()); |
624 ASSERT_EQ(200, response.headers->response_code()); | 656 ASSERT_EQ(200, response.headers->response_code()); |
625 } | 657 } |
626 | 658 |
627 // Test that the SpdyStream state machine can handle sending a final empty data | 659 // Test that the SpdyStream state machine can handle sending a final empty data |
628 // frame when uploading a chunked data stream. | 660 // frame when uploading a chunked data stream. |
629 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithEmptyFinalDataFrame) { | 661 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithEmptyFinalDataFrame) { |
630 std::unique_ptr<SpdySerializedFrame> req( | 662 std::unique_ptr<SpdySerializedFrame> req( |
631 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 663 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
632 std::unique_ptr<SpdySerializedFrame> chunk1( | 664 std::unique_ptr<SpdySerializedFrame> chunk1( |
633 spdy_util_.ConstructSpdyBodyFrame(1, false)); | 665 spdy_util_.ConstructSpdyBodyFrame(1, false)); |
634 std::unique_ptr<SpdySerializedFrame> chunk2( | 666 std::unique_ptr<SpdySerializedFrame> chunk2( |
635 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); | 667 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); |
636 MockWrite writes[] = { | 668 MockWrite writes[] = { |
637 CreateMockWrite(*req.get(), 0), | 669 CreateMockWrite(*req.get(), 0), |
638 CreateMockWrite(*chunk1, 1), // POST upload frames | 670 CreateMockWrite(*chunk1, 1), // POST upload frames |
639 CreateMockWrite(*chunk2, 2), | 671 CreateMockWrite(*chunk2, 2), |
640 }; | 672 }; |
641 std::unique_ptr<SpdySerializedFrame> resp( | 673 std::unique_ptr<SpdySerializedFrame> resp( |
642 spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 674 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
643 MockRead reads[] = { | 675 MockRead reads[] = { |
644 CreateMockRead(*resp, 3), | 676 CreateMockRead(*resp, 3), |
645 CreateMockRead(*chunk1, 4), | 677 CreateMockRead(*chunk1, 4), |
646 CreateMockRead(*chunk2, 5), | 678 CreateMockRead(*chunk2, 5), |
647 MockRead(ASYNC, 0, 6) // EOF | 679 MockRead(ASYNC, 0, 6) // EOF |
648 }; | 680 }; |
649 | 681 |
650 HostPortPair host_port_pair("www.example.org", 80); | 682 HostPortPair host_port_pair("www.example.org", 80); |
651 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 683 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
652 PRIVACY_MODE_DISABLED); | 684 PRIVACY_MODE_DISABLED); |
(...skipping 26 matching lines...) Expand all Loading... |
679 | 711 |
680 // Complete the initial request write and the first chunk. | 712 // Complete the initial request write and the first chunk. |
681 base::RunLoop().RunUntilIdle(); | 713 base::RunLoop().RunUntilIdle(); |
682 ASSERT_FALSE(callback.have_result()); | 714 ASSERT_FALSE(callback.have_result()); |
683 | 715 |
684 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), | 716 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), |
685 http_stream->GetTotalSentBytes()); | 717 http_stream->GetTotalSentBytes()); |
686 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); | 718 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); |
687 | 719 |
688 // Now end the stream with an empty data frame and the FIN set. | 720 // Now end the stream with an empty data frame and the FIN set. |
689 upload_stream.AppendData(NULL, 0, true); | 721 upload_stream.AppendData(nullptr, 0, true); |
690 | 722 |
691 // Finish writing the final frame, and perform all reads. | 723 // Finish writing the final frame, and perform all reads. |
692 base::RunLoop().RunUntilIdle(); | 724 base::RunLoop().RunUntilIdle(); |
693 ASSERT_TRUE(callback.have_result()); | 725 ASSERT_TRUE(callback.have_result()); |
694 EXPECT_EQ(OK, callback.WaitForResult()); | 726 EXPECT_EQ(OK, callback.WaitForResult()); |
695 | 727 |
696 // Check response headers. | 728 // Check response headers. |
697 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); | 729 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); |
698 | 730 |
699 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size()), | 731 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size()), |
(...skipping 15 matching lines...) Expand all Loading... |
715 buf1.get(), kUploadDataSize, callback.callback())); | 747 buf1.get(), kUploadDataSize, callback.callback())); |
716 | 748 |
717 ASSERT_TRUE(response.headers.get()); | 749 ASSERT_TRUE(response.headers.get()); |
718 ASSERT_EQ(200, response.headers->response_code()); | 750 ASSERT_EQ(200, response.headers->response_code()); |
719 } | 751 } |
720 | 752 |
721 // Test that the SpdyStream state machine handles a chunked upload with no | 753 // Test that the SpdyStream state machine handles a chunked upload with no |
722 // payload. Unclear if this is a case worth supporting. | 754 // payload. Unclear if this is a case worth supporting. |
723 TEST_P(SpdyHttpStreamTest, ChunkedPostWithEmptyPayload) { | 755 TEST_P(SpdyHttpStreamTest, ChunkedPostWithEmptyPayload) { |
724 std::unique_ptr<SpdySerializedFrame> req( | 756 std::unique_ptr<SpdySerializedFrame> req( |
725 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 757 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
726 std::unique_ptr<SpdySerializedFrame> chunk( | 758 std::unique_ptr<SpdySerializedFrame> chunk( |
727 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); | 759 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); |
728 MockWrite writes[] = { | 760 MockWrite writes[] = { |
729 CreateMockWrite(*req.get(), 0), | 761 CreateMockWrite(*req.get(), 0), |
730 CreateMockWrite(*chunk, 1), | 762 CreateMockWrite(*chunk, 1), |
731 }; | 763 }; |
732 std::unique_ptr<SpdySerializedFrame> resp( | 764 std::unique_ptr<SpdySerializedFrame> resp( |
733 spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 765 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
734 MockRead reads[] = { | 766 MockRead reads[] = { |
735 CreateMockRead(*resp, 2), | 767 CreateMockRead(*resp, 2), |
736 CreateMockRead(*chunk, 3), | 768 CreateMockRead(*chunk, 3), |
737 MockRead(ASYNC, 0, 4) // EOF | 769 MockRead(ASYNC, 0, 4) // EOF |
738 }; | 770 }; |
739 | 771 |
740 HostPortPair host_port_pair("www.example.org", 80); | 772 HostPortPair host_port_pair("www.example.org", 80); |
741 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 773 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
742 PRIVACY_MODE_DISABLED); | 774 PRIVACY_MODE_DISABLED); |
743 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | 775 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 | 825 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 |
794 TEST_P(SpdyHttpStreamTest, SpdyURLTest) { | 826 TEST_P(SpdyHttpStreamTest, SpdyURLTest) { |
795 const char* const full_url = "http://www.example.org/foo?query=what#anchor"; | 827 const char* const full_url = "http://www.example.org/foo?query=what#anchor"; |
796 const char* const base_url = "http://www.example.org/foo?query=what"; | 828 const char* const base_url = "http://www.example.org/foo?query=what"; |
797 std::unique_ptr<SpdySerializedFrame> req( | 829 std::unique_ptr<SpdySerializedFrame> req( |
798 spdy_util_.ConstructSpdyGet(base_url, 1, LOWEST)); | 830 spdy_util_.ConstructSpdyGet(base_url, 1, LOWEST)); |
799 MockWrite writes[] = { | 831 MockWrite writes[] = { |
800 CreateMockWrite(*req.get(), 0), | 832 CreateMockWrite(*req.get(), 0), |
801 }; | 833 }; |
802 std::unique_ptr<SpdySerializedFrame> resp( | 834 std::unique_ptr<SpdySerializedFrame> resp( |
803 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 835 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
804 MockRead reads[] = { | 836 MockRead reads[] = { |
805 CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF | 837 CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF |
806 }; | 838 }; |
807 | 839 |
808 HostPortPair host_port_pair("www.example.org", 80); | 840 HostPortPair host_port_pair("www.example.org", 80); |
809 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 841 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
810 PRIVACY_MODE_DISABLED); | 842 PRIVACY_MODE_DISABLED); |
811 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | 843 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); |
812 | 844 |
813 HttpRequestInfo request; | 845 HttpRequestInfo request; |
(...skipping 23 matching lines...) Expand all Loading... |
837 | 869 |
838 // Because we abandoned the stream, we don't expect to find a session in the | 870 // Because we abandoned the stream, we don't expect to find a session in the |
839 // pool anymore. | 871 // pool anymore. |
840 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 872 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
841 } | 873 } |
842 | 874 |
843 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be | 875 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be |
844 // made available is handled correctly. | 876 // made available is handled correctly. |
845 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { | 877 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { |
846 std::unique_ptr<SpdySerializedFrame> req( | 878 std::unique_ptr<SpdySerializedFrame> req( |
847 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 879 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
848 std::unique_ptr<SpdySerializedFrame> chunk1( | 880 std::unique_ptr<SpdySerializedFrame> chunk1( |
849 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 881 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
850 MockWrite writes[] = { | 882 MockWrite writes[] = { |
851 CreateMockWrite(*req.get(), 0), | 883 CreateMockWrite(*req.get(), 0), |
852 CreateMockWrite(*chunk1, 1), | 884 CreateMockWrite(*chunk1, 1), |
853 }; | 885 }; |
854 std::unique_ptr<SpdySerializedFrame> resp( | 886 std::unique_ptr<SpdySerializedFrame> resp( |
855 spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 887 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
856 std::unique_ptr<SpdySerializedFrame> window_update( | 888 std::unique_ptr<SpdySerializedFrame> window_update( |
857 spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); | 889 spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); |
858 MockRead reads[] = { | 890 MockRead reads[] = { |
859 CreateMockRead(*window_update, 2), | 891 CreateMockRead(*window_update, 2), |
860 MockRead(ASYNC, ERR_IO_PENDING, 3), | 892 MockRead(ASYNC, ERR_IO_PENDING, 3), |
861 CreateMockRead(*resp, 4), | 893 CreateMockRead(*resp, 4), |
862 CreateMockRead(*chunk1, 5), | 894 CreateMockRead(*chunk1, 5), |
863 MockRead(ASYNC, 0, 6) // EOF | 895 MockRead(ASYNC, 0, 6) // EOF |
864 }; | 896 }; |
865 | 897 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 EXPECT_EQ(static_cast<int64_t>(req->size()), | 932 EXPECT_EQ(static_cast<int64_t>(req->size()), |
901 http_stream->GetTotalSentBytes()); | 933 http_stream->GetTotalSentBytes()); |
902 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); | 934 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); |
903 | 935 |
904 upload_stream.AppendData(kUploadData, kUploadDataSize, true); | 936 upload_stream.AppendData(kUploadData, kUploadDataSize, true); |
905 | 937 |
906 ASSERT_TRUE(callback.have_result()); | 938 ASSERT_TRUE(callback.have_result()); |
907 EXPECT_EQ(OK, callback.WaitForResult()); | 939 EXPECT_EQ(OK, callback.WaitForResult()); |
908 | 940 |
909 // Verify that the window size has decreased. | 941 // Verify that the window size has decreased. |
910 ASSERT_TRUE(http_stream->stream() != NULL); | 942 ASSERT_TRUE(http_stream->stream() != nullptr); |
911 EXPECT_NE(static_cast<int>( | 943 EXPECT_NE(static_cast<int>( |
912 SpdySession::GetDefaultInitialWindowSize(session_->protocol())), | 944 SpdySession::GetDefaultInitialWindowSize(session_->protocol())), |
913 http_stream->stream()->send_window_size()); | 945 http_stream->stream()->send_window_size()); |
914 | 946 |
915 // Read window update. | 947 // Read window update. |
916 base::RunLoop().RunUntilIdle(); | 948 base::RunLoop().RunUntilIdle(); |
917 | 949 |
918 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), | 950 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), |
919 http_stream->GetTotalSentBytes()); | 951 http_stream->GetTotalSentBytes()); |
920 // The window update is not counted in the total received bytes. | 952 // The window update is not counted in the total received bytes. |
921 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); | 953 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); |
922 | 954 |
923 // Verify the window update. | 955 // Verify the window update. |
924 ASSERT_TRUE(http_stream->stream() != NULL); | 956 ASSERT_TRUE(http_stream->stream() != nullptr); |
925 EXPECT_EQ(static_cast<int>( | 957 EXPECT_EQ(static_cast<int>( |
926 SpdySession::GetDefaultInitialWindowSize(session_->protocol())), | 958 SpdySession::GetDefaultInitialWindowSize(session_->protocol())), |
927 http_stream->stream()->send_window_size()); | 959 http_stream->stream()->send_window_size()); |
928 | 960 |
929 // Read rest of data. | 961 // Read rest of data. |
930 sequenced_data_->Resume(); | 962 sequenced_data_->Resume(); |
931 base::RunLoop().RunUntilIdle(); | 963 base::RunLoop().RunUntilIdle(); |
932 | 964 |
933 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), | 965 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), |
934 http_stream->GetTotalSentBytes()); | 966 http_stream->GetTotalSentBytes()); |
935 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size()), | 967 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size()), |
936 http_stream->GetTotalReceivedBytes()); | 968 http_stream->GetTotalReceivedBytes()); |
937 | 969 |
938 // Check response headers. | 970 // Check response headers. |
939 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); | 971 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); |
940 | 972 |
941 // Check |chunk1| response. | 973 // Check |chunk1| response. |
942 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); | 974 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); |
943 ASSERT_EQ(kUploadDataSize, | 975 ASSERT_EQ(kUploadDataSize, |
944 http_stream->ReadResponseBody( | 976 http_stream->ReadResponseBody( |
945 buf1.get(), kUploadDataSize, callback.callback())); | 977 buf1.get(), kUploadDataSize, callback.callback())); |
946 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); | 978 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); |
947 | 979 |
948 ASSERT_TRUE(response.headers.get()); | 980 ASSERT_TRUE(response.headers.get()); |
949 ASSERT_EQ(200, response.headers->response_code()); | 981 ASSERT_EQ(200, response.headers->response_code()); |
950 } | 982 } |
951 | 983 |
| 984 TEST_P(SpdyHttpStreamTest, DataReadErrorSynchronous) { |
| 985 std::unique_ptr<SpdySerializedFrame> req( |
| 986 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 987 |
| 988 // Server receives RST_STREAM_INTERNAL_ERROR on clients' internal failure. |
| 989 // The failure is a reading error in this case caused by |
| 990 // UploadDataStream::Read() |
| 991 std::unique_ptr<SpdySerializedFrame> rst_frame( |
| 992 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_INTERNAL_ERROR)); |
| 993 |
| 994 MockWrite writes[] = { |
| 995 CreateMockWrite(*req, 0, SYNCHRONOUS), // Request |
| 996 CreateMockWrite(*rst_frame, 1, SYNCHRONOUS) // Reset frame |
| 997 }; |
| 998 |
| 999 std::unique_ptr<SpdySerializedFrame> resp( |
| 1000 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
| 1001 |
| 1002 MockRead reads[] = { |
| 1003 CreateMockRead(*resp, 2), MockRead(SYNCHRONOUS, 0, 3), |
| 1004 }; |
| 1005 |
| 1006 HostPortPair host_port_pair("www.example.org", 80); |
| 1007 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
| 1008 PRIVACY_MODE_DISABLED); |
| 1009 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); |
| 1010 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); |
| 1011 ReadErrorUploadDataStream upload_data_stream( |
| 1012 ReadErrorUploadDataStream::FailureMode::SYNC); |
| 1013 ASSERT_EQ(OK, upload_data_stream.Init(TestCompletionCallback().callback())); |
| 1014 |
| 1015 HttpRequestInfo request; |
| 1016 request.method = "POST"; |
| 1017 request.url = GURL("http://www.example.org/"); |
| 1018 request.upload_data_stream = &upload_data_stream; |
| 1019 |
| 1020 TestCompletionCallback callback; |
| 1021 HttpResponseInfo response; |
| 1022 HttpRequestHeaders headers; |
| 1023 BoundNetLog net_log; |
| 1024 SpdyHttpStream http_stream(session_, true); |
| 1025 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
| 1026 net_log, CompletionCallback())); |
| 1027 |
| 1028 int result = http_stream.SendRequest(headers, &response, callback.callback()); |
| 1029 EXPECT_EQ(ERR_FAILED, callback.GetResult(result)); |
| 1030 |
| 1031 // Because the server has not closed the connection yet, there shouldn't be |
| 1032 // a stream but a session in the pool |
| 1033 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
| 1034 } |
| 1035 |
| 1036 TEST_P(SpdyHttpStreamTest, DataReadErrorAsynchronous) { |
| 1037 std::unique_ptr<SpdySerializedFrame> req( |
| 1038 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 1039 |
| 1040 // Server receives RST_STREAM_INTERNAL_ERROR on clients' internal failure. |
| 1041 // The failure is a reading error in this case caused by |
| 1042 // UploadDataStream::Read() |
| 1043 std::unique_ptr<SpdySerializedFrame> rst_frame( |
| 1044 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_INTERNAL_ERROR)); |
| 1045 |
| 1046 MockWrite writes[] = { |
| 1047 CreateMockWrite(*req, 0), // Request |
| 1048 CreateMockWrite(*rst_frame, 1) // Reset frame |
| 1049 }; |
| 1050 |
| 1051 std::unique_ptr<SpdySerializedFrame> resp( |
| 1052 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
| 1053 |
| 1054 MockRead reads[] = { |
| 1055 MockRead(ASYNC, 0, 2), |
| 1056 }; |
| 1057 |
| 1058 HostPortPair host_port_pair("www.example.org", 80); |
| 1059 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
| 1060 PRIVACY_MODE_DISABLED); |
| 1061 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); |
| 1062 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); |
| 1063 |
| 1064 ReadErrorUploadDataStream upload_data_stream( |
| 1065 ReadErrorUploadDataStream::FailureMode::ASYNC); |
| 1066 ASSERT_EQ(OK, upload_data_stream.Init(TestCompletionCallback().callback())); |
| 1067 |
| 1068 HttpRequestInfo request; |
| 1069 request.method = "POST"; |
| 1070 request.url = GURL("http://www.example.org/"); |
| 1071 request.upload_data_stream = &upload_data_stream; |
| 1072 |
| 1073 TestCompletionCallback callback; |
| 1074 HttpResponseInfo response; |
| 1075 HttpRequestHeaders headers; |
| 1076 BoundNetLog net_log; |
| 1077 SpdyHttpStream http_stream(session_, true); |
| 1078 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
| 1079 net_log, CompletionCallback())); |
| 1080 |
| 1081 int result = http_stream.SendRequest(headers, &response, callback.callback()); |
| 1082 EXPECT_EQ(ERR_IO_PENDING, result); |
| 1083 EXPECT_EQ(ERR_FAILED, callback.GetResult(result)); |
| 1084 |
| 1085 // Because the server has closed the connection, there shouldn't be a session |
| 1086 // in the pool anymore. |
| 1087 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
| 1088 } |
| 1089 |
952 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 1090 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
953 // methods. | 1091 // methods. |
954 | 1092 |
955 } // namespace net | 1093 } // namespace net |
OLD | NEW |