| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 private: | 161 private: |
| 162 MockECSignatureCreatorFactory ec_signature_creator_factory_; | 162 MockECSignatureCreatorFactory ec_signature_creator_factory_; |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 INSTANTIATE_TEST_CASE_P( | 165 INSTANTIATE_TEST_CASE_P( |
| 166 NextProto, | 166 NextProto, |
| 167 SpdyHttpStreamTest, | 167 SpdyHttpStreamTest, |
| 168 testing::Values(kProtoSPDY2, kProtoSPDY3, kProtoSPDY31, kProtoSPDY4a2)); | 168 testing::Values(kProtoSPDY2, kProtoSPDY3, kProtoSPDY31, kProtoSPDY4a2)); |
| 169 | 169 |
| 170 // TODO(akalin): Don't early-exit in the tests below for values > | |
| 171 // kProtoSPDY3. | |
| 172 | |
| 173 // SpdyHttpStream::GetUploadProgress() should still work even before the | 170 // SpdyHttpStream::GetUploadProgress() should still work even before the |
| 174 // stream is initialized. | 171 // stream is initialized. |
| 175 TEST_P(SpdyHttpStreamTest, GetUploadProgressBeforeInitialization) { | 172 TEST_P(SpdyHttpStreamTest, GetUploadProgressBeforeInitialization) { |
| 176 if (GetParam() > kProtoSPDY3) | |
| 177 return; | |
| 178 | |
| 179 MockRead reads[] = { | 173 MockRead reads[] = { |
| 180 MockRead(ASYNC, 0, 0) // EOF | 174 MockRead(ASYNC, 0, 0) // EOF |
| 181 }; | 175 }; |
| 182 | 176 |
| 183 HostPortPair host_port_pair("www.google.com", 80); | 177 HostPortPair host_port_pair("www.google.com", 80); |
| 184 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 178 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
| 185 kPrivacyModeDisabled); | 179 kPrivacyModeDisabled); |
| 186 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), NULL, 0, host_port_pair)); | 180 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), NULL, 0, host_port_pair)); |
| 187 | 181 |
| 188 SpdyHttpStream stream(session_, false); | 182 SpdyHttpStream stream(session_, false); |
| 189 UploadProgress progress = stream.GetUploadProgress(); | 183 UploadProgress progress = stream.GetUploadProgress(); |
| 190 EXPECT_EQ(0u, progress.size()); | 184 EXPECT_EQ(0u, progress.size()); |
| 191 EXPECT_EQ(0u, progress.position()); | 185 EXPECT_EQ(0u, progress.position()); |
| 192 } | 186 } |
| 193 | 187 |
| 194 TEST_P(SpdyHttpStreamTest, SendRequest) { | 188 TEST_P(SpdyHttpStreamTest, SendRequest) { |
| 195 if (GetParam() > kProtoSPDY3) | |
| 196 return; | |
| 197 | |
| 198 scoped_ptr<SpdyFrame> req( | 189 scoped_ptr<SpdyFrame> req( |
| 199 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 190 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 200 MockWrite writes[] = { | 191 MockWrite writes[] = { |
| 201 CreateMockWrite(*req.get(), 1), | 192 CreateMockWrite(*req.get(), 1), |
| 202 }; | 193 }; |
| 203 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 194 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 204 MockRead reads[] = { | 195 MockRead reads[] = { |
| 205 CreateMockRead(*resp, 2), | 196 CreateMockRead(*resp, 2), |
| 206 MockRead(SYNCHRONOUS, 0, 3) // EOF | 197 MockRead(SYNCHRONOUS, 0, 3) // EOF |
| 207 }; | 198 }; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 EXPECT_TRUE(data()->at_write_eof()); | 243 EXPECT_TRUE(data()->at_write_eof()); |
| 253 | 244 |
| 254 TestLoadTimingNotReused(*http_stream); | 245 TestLoadTimingNotReused(*http_stream); |
| 255 http_stream->Close(true); | 246 http_stream->Close(true); |
| 256 // Test that there's no crash when trying to get the load timing after the | 247 // Test that there's no crash when trying to get the load timing after the |
| 257 // stream has been closed. | 248 // stream has been closed. |
| 258 TestLoadTimingNotReused(*http_stream); | 249 TestLoadTimingNotReused(*http_stream); |
| 259 } | 250 } |
| 260 | 251 |
| 261 TEST_P(SpdyHttpStreamTest, LoadTimingTwoRequests) { | 252 TEST_P(SpdyHttpStreamTest, LoadTimingTwoRequests) { |
| 262 if (GetParam() > kProtoSPDY3) | |
| 263 return; | |
| 264 | |
| 265 scoped_ptr<SpdyFrame> req1( | 253 scoped_ptr<SpdyFrame> req1( |
| 266 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 254 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 267 scoped_ptr<SpdyFrame> req2( | 255 scoped_ptr<SpdyFrame> req2( |
| 268 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); | 256 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
| 269 MockWrite writes[] = { | 257 MockWrite writes[] = { |
| 270 CreateMockWrite(*req1, 0), | 258 CreateMockWrite(*req1, 0), |
| 271 CreateMockWrite(*req2, 1), | 259 CreateMockWrite(*req2, 1), |
| 272 }; | 260 }; |
| 273 scoped_ptr<SpdyFrame> resp1( | 261 scoped_ptr<SpdyFrame> resp1( |
| 274 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 262 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 343 |
| 356 // Stream 1 has been read to completion. | 344 // Stream 1 has been read to completion. |
| 357 TestLoadTimingNotReused(*http_stream1); | 345 TestLoadTimingNotReused(*http_stream1); |
| 358 // Stream 2 still has queued body data. | 346 // Stream 2 still has queued body data. |
| 359 TestLoadTimingReused(*http_stream2); | 347 TestLoadTimingReused(*http_stream2); |
| 360 } | 348 } |
| 361 | 349 |
| 362 TEST_P(SpdyHttpStreamTest, SendChunkedPost) { | 350 TEST_P(SpdyHttpStreamTest, SendChunkedPost) { |
| 363 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 351 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 364 | 352 |
| 365 scoped_ptr<SpdyFrame> initial_window_update( | |
| 366 framer.CreateWindowUpdate( | |
| 367 kSessionFlowControlStreamId, | |
| 368 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | |
| 369 scoped_ptr<SpdyFrame> req( | 353 scoped_ptr<SpdyFrame> req( |
| 370 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 354 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 371 scoped_ptr<SpdyFrame> body( | 355 scoped_ptr<SpdyFrame> body( |
| 372 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_FIN)); | 356 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_FIN)); |
| 373 std::vector<MockWrite> writes; | 357 std::vector<MockWrite> writes; |
| 374 int seq = 0; | 358 int seq = 0; |
| 375 if (GetParam() >= kProtoSPDY31) { | |
| 376 writes.push_back(CreateMockWrite(*initial_window_update, seq++)); | |
| 377 } | |
| 378 writes.push_back(CreateMockWrite(*req, seq++)); | 359 writes.push_back(CreateMockWrite(*req, seq++)); |
| 379 writes.push_back(CreateMockWrite(*body, seq++)); // POST upload frame | 360 writes.push_back(CreateMockWrite(*body, seq++)); // POST upload frame |
| 380 | 361 |
| 381 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 362 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 382 std::vector<MockRead> reads; | 363 std::vector<MockRead> reads; |
| 383 reads.push_back(CreateMockRead(*resp, seq++)); | 364 reads.push_back(CreateMockRead(*resp, seq++)); |
| 384 reads.push_back(CreateMockRead(*body, seq++)); | 365 reads.push_back(CreateMockRead(*body, seq++)); |
| 385 reads.push_back(MockRead(SYNCHRONOUS, 0, seq++)); // EOF | 366 reads.push_back(MockRead(SYNCHRONOUS, 0, seq++)); // EOF |
| 386 | 367 |
| 387 HostPortPair host_port_pair("www.google.com", 80); | 368 HostPortPair host_port_pair("www.google.com", 80); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 // Because we abandoned the stream, we don't expect to find a session in the | 411 // Because we abandoned the stream, we don't expect to find a session in the |
| 431 // pool anymore. | 412 // pool anymore. |
| 432 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(key)); | 413 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(key)); |
| 433 EXPECT_TRUE(data()->at_read_eof()); | 414 EXPECT_TRUE(data()->at_read_eof()); |
| 434 EXPECT_TRUE(data()->at_write_eof()); | 415 EXPECT_TRUE(data()->at_write_eof()); |
| 435 } | 416 } |
| 436 | 417 |
| 437 // Test to ensure the SpdyStream state machine does not get confused when a | 418 // Test to ensure the SpdyStream state machine does not get confused when a |
| 438 // chunk becomes available while a write is pending. | 419 // chunk becomes available while a write is pending. |
| 439 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPost) { | 420 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPost) { |
| 440 if (GetParam() > kProtoSPDY3) | |
| 441 return; | |
| 442 | |
| 443 const char kUploadData1[] = "12345678"; | 421 const char kUploadData1[] = "12345678"; |
| 444 const int kUploadData1Size = arraysize(kUploadData1)-1; | 422 const int kUploadData1Size = arraysize(kUploadData1)-1; |
| 445 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 423 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 446 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); | 424 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 447 scoped_ptr<SpdyFrame> chunk2( | 425 scoped_ptr<SpdyFrame> chunk2( |
| 448 spdy_util_.ConstructSpdyBodyFrame( | 426 spdy_util_.ConstructSpdyBodyFrame( |
| 449 1, kUploadData1, kUploadData1Size, false)); | 427 1, kUploadData1, kUploadData1Size, false)); |
| 450 scoped_ptr<SpdyFrame> chunk3(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 428 scoped_ptr<SpdyFrame> chunk3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 451 MockWrite writes[] = { | 429 MockWrite writes[] = { |
| 452 CreateMockWrite(*req.get(), 0), | 430 CreateMockWrite(*req.get(), 0), |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 EXPECT_EQ(kUploadData, std::string(buf3->data(), kUploadDataSize)); | 515 EXPECT_EQ(kUploadData, std::string(buf3->data(), kUploadDataSize)); |
| 538 | 516 |
| 539 // Finish reading the |EOF|. | 517 // Finish reading the |EOF|. |
| 540 deterministic_data()->RunFor(1); | 518 deterministic_data()->RunFor(1); |
| 541 ASSERT_TRUE(response.headers.get()); | 519 ASSERT_TRUE(response.headers.get()); |
| 542 ASSERT_EQ(200, response.headers->response_code()); | 520 ASSERT_EQ(200, response.headers->response_code()); |
| 543 EXPECT_TRUE(deterministic_data()->at_read_eof()); | 521 EXPECT_TRUE(deterministic_data()->at_read_eof()); |
| 544 EXPECT_TRUE(deterministic_data()->at_write_eof()); | 522 EXPECT_TRUE(deterministic_data()->at_write_eof()); |
| 545 } | 523 } |
| 546 | 524 |
| 547 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be | |
| 548 // made available is handled correctly. | |
| 549 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { | |
| 550 if (GetParam() != kProtoSPDY3) | |
| 551 return; | |
| 552 | |
| 553 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | |
| 554 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 555 MockWrite writes[] = { | |
| 556 CreateMockWrite(*req.get(), 0), | |
| 557 CreateMockWrite(*chunk1, 1), | |
| 558 }; | |
| 559 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | |
| 560 scoped_ptr<SpdyFrame> window_update( | |
| 561 spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); | |
| 562 MockRead reads[] = { | |
| 563 CreateMockRead(*window_update, 2), | |
| 564 CreateMockRead(*resp, 3), | |
| 565 CreateMockRead(*chunk1, 4), | |
| 566 MockRead(ASYNC, 0, 5) // EOF | |
| 567 }; | |
| 568 | |
| 569 HostPortPair host_port_pair("www.google.com", 80); | |
| 570 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
| 571 kPrivacyModeDisabled); | |
| 572 | |
| 573 DeterministicSocketData data(reads, arraysize(reads), | |
| 574 writes, arraysize(writes)); | |
| 575 | |
| 576 DeterministicMockClientSocketFactory* socket_factory = | |
| 577 session_deps_.deterministic_socket_factory.get(); | |
| 578 socket_factory->AddSocketDataProvider(&data); | |
| 579 | |
| 580 http_session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( | |
| 581 &session_deps_); | |
| 582 session_ = http_session_->spdy_session_pool()->Get(key, BoundNetLog()); | |
| 583 transport_params_ = new TransportSocketParams(host_port_pair, | |
| 584 MEDIUM, false, false, | |
| 585 OnHostResolutionCallback()); | |
| 586 | |
| 587 TestCompletionCallback callback; | |
| 588 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | |
| 589 | |
| 590 EXPECT_EQ(ERR_IO_PENDING, | |
| 591 connection->Init(host_port_pair.ToString(), | |
| 592 transport_params_, | |
| 593 MEDIUM, | |
| 594 callback.callback(), | |
| 595 http_session_->GetTransportSocketPool( | |
| 596 HttpNetworkSession::NORMAL_SOCKET_POOL), | |
| 597 BoundNetLog())); | |
| 598 | |
| 599 callback.WaitForResult(); | |
| 600 EXPECT_EQ(OK, | |
| 601 session_->InitializeWithSocket(connection.release(), false, OK)); | |
| 602 | |
| 603 UploadDataStream upload_stream(UploadDataStream::CHUNKED, 0); | |
| 604 | |
| 605 HttpRequestInfo request; | |
| 606 request.method = "POST"; | |
| 607 request.url = GURL("http://www.google.com/"); | |
| 608 request.upload_data_stream = &upload_stream; | |
| 609 | |
| 610 ASSERT_EQ(OK, upload_stream.Init(CompletionCallback())); | |
| 611 upload_stream.AppendChunk(kUploadData, kUploadDataSize, true); | |
| 612 | |
| 613 BoundNetLog net_log; | |
| 614 scoped_ptr<SpdyHttpStream> http_stream( | |
| 615 new SpdyHttpStream(session_.get(), true)); | |
| 616 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, | |
| 617 net_log, CompletionCallback())); | |
| 618 | |
| 619 HttpRequestHeaders headers; | |
| 620 HttpResponseInfo response; | |
| 621 // This will attempt to Write() the initial request and headers, which will | |
| 622 // complete asynchronously. | |
| 623 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | |
| 624 callback.callback())); | |
| 625 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); | |
| 626 | |
| 627 // Complete the initial request write and first chunk. | |
| 628 data.RunFor(2); | |
| 629 ASSERT_TRUE(callback.have_result()); | |
| 630 EXPECT_EQ(OK, callback.WaitForResult()); | |
| 631 | |
| 632 // Verify that the window size has decreased. | |
| 633 ASSERT_TRUE(http_stream->stream() != NULL); | |
| 634 EXPECT_NE(static_cast<int>(kSpdyStreamInitialWindowSize), | |
| 635 http_stream->stream()->send_window_size()); | |
| 636 | |
| 637 // Read window update. | |
| 638 data.RunFor(1); | |
| 639 | |
| 640 // Verify the window update. | |
| 641 ASSERT_TRUE(http_stream->stream() != NULL); | |
| 642 EXPECT_EQ(static_cast<int>(kSpdyStreamInitialWindowSize), | |
| 643 http_stream->stream()->send_window_size()); | |
| 644 | |
| 645 // Read response headers. | |
| 646 data.RunFor(1); | |
| 647 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); | |
| 648 | |
| 649 // Read and check |chunk1| response. | |
| 650 data.RunFor(1); | |
| 651 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); | |
| 652 ASSERT_EQ(kUploadDataSize, | |
| 653 http_stream->ReadResponseBody( | |
| 654 buf1.get(), kUploadDataSize, callback.callback())); | |
| 655 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); | |
| 656 | |
| 657 // Finish reading the |EOF|. | |
| 658 data.RunFor(1); | |
| 659 ASSERT_TRUE(response.headers.get()); | |
| 660 ASSERT_EQ(200, response.headers->response_code()); | |
| 661 EXPECT_TRUE(data.at_read_eof()); | |
| 662 EXPECT_TRUE(data.at_write_eof()); | |
| 663 } | |
| 664 | |
| 665 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 | 525 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 |
| 666 TEST_P(SpdyHttpStreamTest, SpdyURLTest) { | 526 TEST_P(SpdyHttpStreamTest, SpdyURLTest) { |
| 667 if (GetParam() > kProtoSPDY3) | |
| 668 return; | |
| 669 | |
| 670 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; | 527 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; |
| 671 const char * const base_url = "http://www.google.com/foo?query=what"; | 528 const char * const base_url = "http://www.google.com/foo?query=what"; |
| 672 scoped_ptr<SpdyFrame> req( | 529 scoped_ptr<SpdyFrame> req( |
| 673 spdy_util_.ConstructSpdyGet(base_url, false, 1, LOWEST)); | 530 spdy_util_.ConstructSpdyGet(base_url, false, 1, LOWEST)); |
| 674 MockWrite writes[] = { | 531 MockWrite writes[] = { |
| 675 CreateMockWrite(*req.get(), 1), | 532 CreateMockWrite(*req.get(), 1), |
| 676 }; | 533 }; |
| 677 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 534 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 678 MockRead reads[] = { | 535 MockRead reads[] = { |
| 679 CreateMockRead(*resp, 2), | 536 CreateMockRead(*resp, 2), |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 callback.WaitForResult(); | 755 callback.WaitForResult(); |
| 899 | 756 |
| 900 EXPECT_EQ(ERR_IO_PENDING, http_stream2->ReadResponseHeaders( | 757 EXPECT_EQ(ERR_IO_PENDING, http_stream2->ReadResponseHeaders( |
| 901 callback.callback())); | 758 callback.callback())); |
| 902 data.RunFor(1); | 759 data.RunFor(1); |
| 903 EXPECT_EQ(OK, callback.WaitForResult()); | 760 EXPECT_EQ(OK, callback.WaitForResult()); |
| 904 ASSERT_TRUE(response.headers.get() != NULL); | 761 ASSERT_TRUE(response.headers.get() != NULL); |
| 905 ASSERT_EQ(200, response.headers->response_code()); | 762 ASSERT_EQ(200, response.headers->response_code()); |
| 906 } | 763 } |
| 907 | 764 |
| 765 // The tests below are only for SPDY/3 and above. |
| 766 |
| 767 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be |
| 768 // made available is handled correctly. |
| 769 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { |
| 770 if (GetParam() < kProtoSPDY3) |
| 771 return; |
| 772 |
| 773 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 774 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 775 MockWrite writes[] = { |
| 776 CreateMockWrite(*req.get(), 0), |
| 777 CreateMockWrite(*chunk1, 1), |
| 778 }; |
| 779 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 780 scoped_ptr<SpdyFrame> window_update( |
| 781 spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); |
| 782 MockRead reads[] = { |
| 783 CreateMockRead(*window_update, 2), |
| 784 CreateMockRead(*resp, 3), |
| 785 CreateMockRead(*chunk1, 4), |
| 786 MockRead(ASYNC, 0, 5) // EOF |
| 787 }; |
| 788 |
| 789 HostPortPair host_port_pair("www.google.com", 80); |
| 790 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
| 791 kPrivacyModeDisabled); |
| 792 |
| 793 DeterministicSocketData data(reads, arraysize(reads), |
| 794 writes, arraysize(writes)); |
| 795 |
| 796 DeterministicMockClientSocketFactory* socket_factory = |
| 797 session_deps_.deterministic_socket_factory.get(); |
| 798 socket_factory->AddSocketDataProvider(&data); |
| 799 |
| 800 http_session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( |
| 801 &session_deps_); |
| 802 session_ = http_session_->spdy_session_pool()->Get(key, BoundNetLog()); |
| 803 transport_params_ = new TransportSocketParams(host_port_pair, |
| 804 MEDIUM, false, false, |
| 805 OnHostResolutionCallback()); |
| 806 |
| 807 TestCompletionCallback callback; |
| 808 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 809 |
| 810 EXPECT_EQ(ERR_IO_PENDING, |
| 811 connection->Init(host_port_pair.ToString(), |
| 812 transport_params_, |
| 813 MEDIUM, |
| 814 callback.callback(), |
| 815 http_session_->GetTransportSocketPool( |
| 816 HttpNetworkSession::NORMAL_SOCKET_POOL), |
| 817 BoundNetLog())); |
| 818 |
| 819 callback.WaitForResult(); |
| 820 EXPECT_EQ(OK, |
| 821 session_->InitializeWithSocket(connection.release(), false, OK)); |
| 822 |
| 823 UploadDataStream upload_stream(UploadDataStream::CHUNKED, 0); |
| 824 |
| 825 HttpRequestInfo request; |
| 826 request.method = "POST"; |
| 827 request.url = GURL("http://www.google.com/"); |
| 828 request.upload_data_stream = &upload_stream; |
| 829 |
| 830 ASSERT_EQ(OK, upload_stream.Init(CompletionCallback())); |
| 831 upload_stream.AppendChunk(kUploadData, kUploadDataSize, true); |
| 832 |
| 833 BoundNetLog net_log; |
| 834 scoped_ptr<SpdyHttpStream> http_stream( |
| 835 new SpdyHttpStream(session_.get(), true)); |
| 836 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, |
| 837 net_log, CompletionCallback())); |
| 838 |
| 839 HttpRequestHeaders headers; |
| 840 HttpResponseInfo response; |
| 841 // This will attempt to Write() the initial request and headers, which will |
| 842 // complete asynchronously. |
| 843 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
| 844 callback.callback())); |
| 845 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); |
| 846 |
| 847 // Complete the initial request write and first chunk. |
| 848 data.RunFor(2); |
| 849 ASSERT_TRUE(callback.have_result()); |
| 850 EXPECT_EQ(OK, callback.WaitForResult()); |
| 851 |
| 852 // Verify that the window size has decreased. |
| 853 ASSERT_TRUE(http_stream->stream() != NULL); |
| 854 EXPECT_NE(static_cast<int>(kSpdyStreamInitialWindowSize), |
| 855 http_stream->stream()->send_window_size()); |
| 856 |
| 857 // Read window update. |
| 858 data.RunFor(1); |
| 859 |
| 860 // Verify the window update. |
| 861 ASSERT_TRUE(http_stream->stream() != NULL); |
| 862 EXPECT_EQ(static_cast<int>(kSpdyStreamInitialWindowSize), |
| 863 http_stream->stream()->send_window_size()); |
| 864 |
| 865 // Read response headers. |
| 866 data.RunFor(1); |
| 867 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); |
| 868 |
| 869 // Read and check |chunk1| response. |
| 870 data.RunFor(1); |
| 871 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); |
| 872 ASSERT_EQ(kUploadDataSize, |
| 873 http_stream->ReadResponseBody( |
| 874 buf1.get(), kUploadDataSize, callback.callback())); |
| 875 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); |
| 876 |
| 877 // Finish reading the |EOF|. |
| 878 data.RunFor(1); |
| 879 ASSERT_TRUE(response.headers.get()); |
| 880 ASSERT_EQ(200, response.headers->response_code()); |
| 881 EXPECT_TRUE(data.at_read_eof()); |
| 882 EXPECT_TRUE(data.at_write_eof()); |
| 883 } |
| 884 |
| 908 TEST_P(SpdyHttpStreamTest, SendCredentialsEC) { | 885 TEST_P(SpdyHttpStreamTest, SendCredentialsEC) { |
| 909 if (GetParam() != kProtoSPDY3) | 886 if (GetParam() < kProtoSPDY3) |
| 910 return; | 887 return; |
| 911 | 888 |
| 912 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = | 889 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = |
| 913 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); | 890 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); |
| 914 scoped_ptr<ServerBoundCertService> server_bound_cert_service( | 891 scoped_ptr<ServerBoundCertService> server_bound_cert_service( |
| 915 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), | 892 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), |
| 916 sequenced_worker_pool)); | 893 sequenced_worker_pool)); |
| 917 std::string cert; | 894 std::string cert; |
| 918 std::string proof; | 895 std::string proof; |
| 919 GetECServerBoundCertAndProof("www.gmail.com", | 896 GetECServerBoundCertAndProof("www.gmail.com", |
| 920 server_bound_cert_service.get(), | 897 server_bound_cert_service.get(), |
| 921 &cert, &proof); | 898 &cert, &proof); |
| 922 | 899 |
| 923 TestSendCredentials(server_bound_cert_service.get(), cert, proof); | 900 TestSendCredentials(server_bound_cert_service.get(), cert, proof); |
| 924 | 901 |
| 925 sequenced_worker_pool->Shutdown(); | 902 sequenced_worker_pool->Shutdown(); |
| 926 } | 903 } |
| 927 | 904 |
| 928 TEST_P(SpdyHttpStreamTest, DontSendCredentialsForHttpUrlsEC) { | 905 TEST_P(SpdyHttpStreamTest, DontSendCredentialsForHttpUrlsEC) { |
| 929 if (GetParam() != kProtoSPDY3) | 906 if (GetParam() < kProtoSPDY3) |
| 930 return; | 907 return; |
| 931 | 908 |
| 932 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = | 909 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = |
| 933 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); | 910 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); |
| 934 scoped_ptr<ServerBoundCertService> server_bound_cert_service( | 911 scoped_ptr<ServerBoundCertService> server_bound_cert_service( |
| 935 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), | 912 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), |
| 936 sequenced_worker_pool)); | 913 sequenced_worker_pool)); |
| 937 std::string cert; | 914 std::string cert; |
| 938 std::string proof; | 915 std::string proof; |
| 939 GetECServerBoundCertAndProof("proxy.google.com", | 916 GetECServerBoundCertAndProof("proxy.google.com", |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 data.RunFor(1); | 1033 data.RunFor(1); |
| 1057 sequenced_worker_pool->Shutdown(); | 1034 sequenced_worker_pool->Shutdown(); |
| 1058 } | 1035 } |
| 1059 | 1036 |
| 1060 #endif // !defined(USE_OPENSSL) | 1037 #endif // !defined(USE_OPENSSL) |
| 1061 | 1038 |
| 1062 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 1039 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
| 1063 // methods. | 1040 // methods. |
| 1064 | 1041 |
| 1065 } // namespace net | 1042 } // namespace net |
| OLD | NEW |