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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 EXPECT_EQ(kUploadData, std::string(buf3->data(), kUploadDataSize)); | 515 EXPECT_EQ(kUploadData, std::string(buf3->data(), kUploadDataSize)); |
516 | 516 |
517 // Finish reading the |EOF|. | 517 // Finish reading the |EOF|. |
518 deterministic_data()->RunFor(1); | 518 deterministic_data()->RunFor(1); |
519 ASSERT_TRUE(response.headers.get()); | 519 ASSERT_TRUE(response.headers.get()); |
520 ASSERT_EQ(200, response.headers->response_code()); | 520 ASSERT_EQ(200, response.headers->response_code()); |
521 EXPECT_TRUE(deterministic_data()->at_read_eof()); | 521 EXPECT_TRUE(deterministic_data()->at_read_eof()); |
522 EXPECT_TRUE(deterministic_data()->at_write_eof()); | 522 EXPECT_TRUE(deterministic_data()->at_write_eof()); |
523 } | 523 } |
524 | 524 |
525 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be | |
526 // made available is handled correctly. | |
527 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { | |
528 if (GetParam() < kProtoSPDY3) | |
529 return; | |
530 | |
531 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | |
532 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
533 MockWrite writes[] = { | |
534 CreateMockWrite(*req.get(), 0), | |
535 CreateMockWrite(*chunk1, 1), | |
536 }; | |
537 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | |
538 scoped_ptr<SpdyFrame> window_update( | |
539 spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); | |
540 MockRead reads[] = { | |
541 CreateMockRead(*window_update, 2), | |
542 CreateMockRead(*resp, 3), | |
543 CreateMockRead(*chunk1, 4), | |
544 MockRead(ASYNC, 0, 5) // EOF | |
545 }; | |
546 | |
547 HostPortPair host_port_pair("www.google.com", 80); | |
548 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
549 kPrivacyModeDisabled); | |
550 | |
551 DeterministicSocketData data(reads, arraysize(reads), | |
552 writes, arraysize(writes)); | |
553 | |
554 DeterministicMockClientSocketFactory* socket_factory = | |
555 session_deps_.deterministic_socket_factory.get(); | |
556 socket_factory->AddSocketDataProvider(&data); | |
557 | |
558 http_session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( | |
559 &session_deps_); | |
560 session_ = http_session_->spdy_session_pool()->Get(key, BoundNetLog()); | |
561 transport_params_ = new TransportSocketParams(host_port_pair, | |
562 MEDIUM, false, false, | |
563 OnHostResolutionCallback()); | |
564 | |
565 TestCompletionCallback callback; | |
566 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | |
567 | |
568 EXPECT_EQ(ERR_IO_PENDING, | |
569 connection->Init(host_port_pair.ToString(), | |
570 transport_params_, | |
571 MEDIUM, | |
572 callback.callback(), | |
573 http_session_->GetTransportSocketPool( | |
574 HttpNetworkSession::NORMAL_SOCKET_POOL), | |
575 BoundNetLog())); | |
576 | |
577 callback.WaitForResult(); | |
578 EXPECT_EQ(OK, | |
579 session_->InitializeWithSocket(connection.release(), false, OK)); | |
580 | |
581 UploadDataStream upload_stream(UploadDataStream::CHUNKED, 0); | |
582 | |
583 HttpRequestInfo request; | |
584 request.method = "POST"; | |
585 request.url = GURL("http://www.google.com/"); | |
586 request.upload_data_stream = &upload_stream; | |
587 | |
588 ASSERT_EQ(OK, upload_stream.Init(CompletionCallback())); | |
589 upload_stream.AppendChunk(kUploadData, kUploadDataSize, true); | |
590 | |
591 BoundNetLog net_log; | |
592 scoped_ptr<SpdyHttpStream> http_stream( | |
593 new SpdyHttpStream(session_.get(), true)); | |
594 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, | |
595 net_log, CompletionCallback())); | |
596 | |
597 HttpRequestHeaders headers; | |
598 HttpResponseInfo response; | |
599 // This will attempt to Write() the initial request and headers, which will | |
600 // complete asynchronously. | |
601 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | |
602 callback.callback())); | |
603 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(key)); | |
604 | |
605 // Complete the initial request write and first chunk. | |
606 data.RunFor(2); | |
607 ASSERT_TRUE(callback.have_result()); | |
608 EXPECT_EQ(OK, callback.WaitForResult()); | |
609 | |
610 // Verify that the window size has decreased. | |
611 ASSERT_TRUE(http_stream->stream() != NULL); | |
612 EXPECT_NE(static_cast<int>(kSpdyStreamInitialWindowSize), | |
613 http_stream->stream()->send_window_size()); | |
614 | |
615 // Read window update. | |
616 data.RunFor(1); | |
617 | |
618 // Verify the window update. | |
619 ASSERT_TRUE(http_stream->stream() != NULL); | |
620 EXPECT_EQ(static_cast<int>(kSpdyStreamInitialWindowSize), | |
621 http_stream->stream()->send_window_size()); | |
622 | |
623 // Read response headers. | |
624 data.RunFor(1); | |
625 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); | |
626 | |
627 // Read and check |chunk1| response. | |
628 data.RunFor(1); | |
629 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); | |
630 ASSERT_EQ(kUploadDataSize, | |
631 http_stream->ReadResponseBody( | |
632 buf1.get(), kUploadDataSize, callback.callback())); | |
633 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); | |
634 | |
635 // Finish reading the |EOF|. | |
636 data.RunFor(1); | |
637 ASSERT_TRUE(response.headers.get()); | |
638 ASSERT_EQ(200, response.headers->response_code()); | |
639 EXPECT_TRUE(data.at_read_eof()); | |
640 EXPECT_TRUE(data.at_write_eof()); | |
641 } | |
642 | |
643 // 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 |
644 TEST_P(SpdyHttpStreamTest, SpdyURLTest) { | 526 TEST_P(SpdyHttpStreamTest, SpdyURLTest) { |
645 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"; |
646 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"; |
647 scoped_ptr<SpdyFrame> req( | 529 scoped_ptr<SpdyFrame> req( |
648 spdy_util_.ConstructSpdyGet(base_url, false, 1, LOWEST)); | 530 spdy_util_.ConstructSpdyGet(base_url, false, 1, LOWEST)); |
649 MockWrite writes[] = { | 531 MockWrite writes[] = { |
650 CreateMockWrite(*req.get(), 1), | 532 CreateMockWrite(*req.get(), 1), |
651 }; | 533 }; |
652 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 534 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 callback.WaitForResult(); | 755 callback.WaitForResult(); |
874 | 756 |
875 EXPECT_EQ(ERR_IO_PENDING, http_stream2->ReadResponseHeaders( | 757 EXPECT_EQ(ERR_IO_PENDING, http_stream2->ReadResponseHeaders( |
876 callback.callback())); | 758 callback.callback())); |
877 data.RunFor(1); | 759 data.RunFor(1); |
878 EXPECT_EQ(OK, callback.WaitForResult()); | 760 EXPECT_EQ(OK, callback.WaitForResult()); |
879 ASSERT_TRUE(response.headers.get() != NULL); | 761 ASSERT_TRUE(response.headers.get() != NULL); |
880 ASSERT_EQ(200, response.headers->response_code()); | 762 ASSERT_EQ(200, response.headers->response_code()); |
881 } | 763 } |
882 | 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 |
883 TEST_P(SpdyHttpStreamTest, SendCredentialsEC) { | 885 TEST_P(SpdyHttpStreamTest, SendCredentialsEC) { |
884 if (GetParam() < kProtoSPDY3) | 886 if (GetParam() < kProtoSPDY3) |
885 return; | 887 return; |
886 | 888 |
887 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = | 889 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = |
888 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); | 890 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); |
889 scoped_ptr<ServerBoundCertService> server_bound_cert_service( | 891 scoped_ptr<ServerBoundCertService> server_bound_cert_service( |
890 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), | 892 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), |
891 sequenced_worker_pool)); | 893 sequenced_worker_pool)); |
892 std::string cert; | 894 std::string cert; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 data.RunFor(1); | 1033 data.RunFor(1); |
1032 sequenced_worker_pool->Shutdown(); | 1034 sequenced_worker_pool->Shutdown(); |
1033 } | 1035 } |
1034 | 1036 |
1035 #endif // !defined(USE_OPENSSL) | 1037 #endif // !defined(USE_OPENSSL) |
1036 | 1038 |
1037 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 1039 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
1038 // methods. | 1040 // methods. |
1039 | 1041 |
1040 } // namespace net | 1042 } // namespace net |
OLD | NEW |