| 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 #include <string> | |
| 11 | 10 |
| 12 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 13 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "crypto/ec_private_key.h" | 14 #include "crypto/ec_private_key.h" |
| 16 #include "crypto/ec_signature_creator.h" | 15 #include "crypto/ec_signature_creator.h" |
| 17 #include "crypto/signature_creator.h" | 16 #include "crypto/signature_creator.h" |
| 18 #include "net/base/chunked_upload_data_stream.h" | 17 #include "net/base/chunked_upload_data_stream.h" |
| 19 #include "net/base/load_timing_info.h" | 18 #include "net/base/load_timing_info.h" |
| 20 #include "net/base/load_timing_info_test_util.h" | 19 #include "net/base/load_timing_info_test_util.h" |
| 21 #include "net/base/test_completion_callback.h" | 20 #include "net/base/test_completion_callback.h" |
| 22 #include "net/cert/asn1_util.h" | 21 #include "net/cert/asn1_util.h" |
| 23 #include "net/http/http_request_info.h" | 22 #include "net/http/http_request_info.h" |
| 24 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
| 25 #include "net/http/http_response_info.h" | 24 #include "net/http/http_response_info.h" |
| 26 #include "net/log/net_log_with_source.h" | 25 #include "net/log/net_log_with_source.h" |
| 27 #include "net/log/test_net_log.h" | 26 #include "net/log/test_net_log.h" |
| 28 #include "net/socket/socket_test_util.h" | 27 #include "net/socket/socket_test_util.h" |
| 28 #include "net/spdy/platform/api/spdy_string.h" |
| 29 #include "net/spdy/spdy_http_utils.h" | 29 #include "net/spdy/spdy_http_utils.h" |
| 30 #include "net/spdy/spdy_session.h" | 30 #include "net/spdy/spdy_session.h" |
| 31 #include "net/spdy/spdy_test_util_common.h" | 31 #include "net/spdy/spdy_test_util_common.h" |
| 32 #include "net/ssl/default_channel_id_store.h" | 32 #include "net/ssl/default_channel_id_store.h" |
| 33 #include "net/test/cert_test_util.h" | 33 #include "net/test/cert_test_util.h" |
| 34 #include "net/test/gtest_util.h" | 34 #include "net/test/gtest_util.h" |
| 35 #include "net/test/test_data_directory.h" | 35 #include "net/test/test_data_directory.h" |
| 36 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 38 | 38 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 154 |
| 155 ssl_.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); | 155 ssl_.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 156 ASSERT_TRUE(ssl_.cert); | 156 ASSERT_TRUE(ssl_.cert); |
| 157 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); | 157 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 158 | 158 |
| 159 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 159 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
| 160 session_ = | 160 session_ = |
| 161 CreateSecureSpdySession(http_session_.get(), key_, NetLogWithSource()); | 161 CreateSecureSpdySession(http_session_.get(), key_, NetLogWithSource()); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void TestSendCredentials( | 164 void TestSendCredentials(ChannelIDService* channel_id_service, |
| 165 ChannelIDService* channel_id_service, | 165 const SpdyString& cert, |
| 166 const std::string& cert, | 166 const SpdyString& proof); |
| 167 const std::string& proof); | |
| 168 | 167 |
| 169 SpdyTestUtil spdy_util_; | 168 SpdyTestUtil spdy_util_; |
| 170 TestNetLog net_log_; | 169 TestNetLog net_log_; |
| 171 SpdySessionDependencies session_deps_; | 170 SpdySessionDependencies session_deps_; |
| 172 const GURL url_; | 171 const GURL url_; |
| 173 const HostPortPair host_port_pair_; | 172 const HostPortPair host_port_pair_; |
| 174 const SpdySessionKey key_; | 173 const SpdySessionKey key_; |
| 175 std::unique_ptr<SequencedSocketData> sequenced_data_; | 174 std::unique_ptr<SequencedSocketData> sequenced_data_; |
| 176 std::unique_ptr<HttpNetworkSession> http_session_; | 175 std::unique_ptr<HttpNetworkSession> http_session_; |
| 177 base::WeakPtr<SpdySession> session_; | 176 base::WeakPtr<SpdySession> session_; |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 http_stream->GetTotalReceivedBytes()); | 583 http_stream->GetTotalReceivedBytes()); |
| 585 | 584 |
| 586 // Check response headers. | 585 // Check response headers. |
| 587 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk()); | 586 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk()); |
| 588 | 587 |
| 589 // Check |chunk1| response. | 588 // Check |chunk1| response. |
| 590 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); | 589 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); |
| 591 ASSERT_EQ(kUploadDataSize, | 590 ASSERT_EQ(kUploadDataSize, |
| 592 http_stream->ReadResponseBody( | 591 http_stream->ReadResponseBody( |
| 593 buf1.get(), kUploadDataSize, callback.callback())); | 592 buf1.get(), kUploadDataSize, callback.callback())); |
| 594 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); | 593 EXPECT_EQ(kUploadData, SpdyString(buf1->data(), kUploadDataSize)); |
| 595 | 594 |
| 596 // Check |chunk2| response. | 595 // Check |chunk2| response. |
| 597 scoped_refptr<IOBuffer> buf2(new IOBuffer(kUploadData1Size)); | 596 scoped_refptr<IOBuffer> buf2(new IOBuffer(kUploadData1Size)); |
| 598 ASSERT_EQ(kUploadData1Size, | 597 ASSERT_EQ(kUploadData1Size, |
| 599 http_stream->ReadResponseBody( | 598 http_stream->ReadResponseBody( |
| 600 buf2.get(), kUploadData1Size, callback.callback())); | 599 buf2.get(), kUploadData1Size, callback.callback())); |
| 601 EXPECT_EQ(kUploadData1, std::string(buf2->data(), kUploadData1Size)); | 600 EXPECT_EQ(kUploadData1, SpdyString(buf2->data(), kUploadData1Size)); |
| 602 | 601 |
| 603 // Check |chunk3| response. | 602 // Check |chunk3| response. |
| 604 scoped_refptr<IOBuffer> buf3(new IOBuffer(kUploadDataSize)); | 603 scoped_refptr<IOBuffer> buf3(new IOBuffer(kUploadDataSize)); |
| 605 ASSERT_EQ(kUploadDataSize, | 604 ASSERT_EQ(kUploadDataSize, |
| 606 http_stream->ReadResponseBody( | 605 http_stream->ReadResponseBody( |
| 607 buf3.get(), kUploadDataSize, callback.callback())); | 606 buf3.get(), kUploadDataSize, callback.callback())); |
| 608 EXPECT_EQ(kUploadData, std::string(buf3->data(), kUploadDataSize)); | 607 EXPECT_EQ(kUploadData, SpdyString(buf3->data(), kUploadDataSize)); |
| 609 | 608 |
| 610 ASSERT_TRUE(response.headers.get()); | 609 ASSERT_TRUE(response.headers.get()); |
| 611 ASSERT_EQ(200, response.headers->response_code()); | 610 ASSERT_EQ(200, response.headers->response_code()); |
| 612 } | 611 } |
| 613 | 612 |
| 614 // Test that the SpdyStream state machine can handle sending a final empty data | 613 // Test that the SpdyStream state machine can handle sending a final empty data |
| 615 // frame when uploading a chunked data stream. | 614 // frame when uploading a chunked data stream. |
| 616 TEST_F(SpdyHttpStreamTest, DelayedSendChunkedPostWithEmptyFinalDataFrame) { | 615 TEST_F(SpdyHttpStreamTest, DelayedSendChunkedPostWithEmptyFinalDataFrame) { |
| 617 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 616 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 618 SpdySerializedFrame chunk1(spdy_util_.ConstructSpdyDataFrame(1, false)); | 617 SpdySerializedFrame chunk1(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 EXPECT_EQ(static_cast<int64_t>(req.size() + chunk1.size() + chunk2.size()), | 679 EXPECT_EQ(static_cast<int64_t>(req.size() + chunk1.size() + chunk2.size()), |
| 681 http_stream->GetTotalSentBytes()); | 680 http_stream->GetTotalSentBytes()); |
| 682 EXPECT_EQ(static_cast<int64_t>(resp.size() + chunk1.size() + chunk2.size()), | 681 EXPECT_EQ(static_cast<int64_t>(resp.size() + chunk1.size() + chunk2.size()), |
| 683 http_stream->GetTotalReceivedBytes()); | 682 http_stream->GetTotalReceivedBytes()); |
| 684 | 683 |
| 685 // Check |chunk1| response. | 684 // Check |chunk1| response. |
| 686 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); | 685 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); |
| 687 ASSERT_EQ(kUploadDataSize, | 686 ASSERT_EQ(kUploadDataSize, |
| 688 http_stream->ReadResponseBody( | 687 http_stream->ReadResponseBody( |
| 689 buf1.get(), kUploadDataSize, callback.callback())); | 688 buf1.get(), kUploadDataSize, callback.callback())); |
| 690 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); | 689 EXPECT_EQ(kUploadData, SpdyString(buf1->data(), kUploadDataSize)); |
| 691 | 690 |
| 692 // Check |chunk2| response. | 691 // Check |chunk2| response. |
| 693 ASSERT_EQ(0, | 692 ASSERT_EQ(0, |
| 694 http_stream->ReadResponseBody( | 693 http_stream->ReadResponseBody( |
| 695 buf1.get(), kUploadDataSize, callback.callback())); | 694 buf1.get(), kUploadDataSize, callback.callback())); |
| 696 | 695 |
| 697 ASSERT_TRUE(response.headers.get()); | 696 ASSERT_TRUE(response.headers.get()); |
| 698 ASSERT_EQ(200, response.headers->response_code()); | 697 ASSERT_EQ(200, response.headers->response_code()); |
| 699 } | 698 } |
| 700 | 699 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 http_stream->GetTotalReceivedBytes()); | 894 http_stream->GetTotalReceivedBytes()); |
| 896 | 895 |
| 897 // Check response headers. | 896 // Check response headers. |
| 898 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk()); | 897 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk()); |
| 899 | 898 |
| 900 // Check |chunk1| response. | 899 // Check |chunk1| response. |
| 901 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); | 900 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); |
| 902 ASSERT_EQ(kUploadDataSize, | 901 ASSERT_EQ(kUploadDataSize, |
| 903 http_stream->ReadResponseBody( | 902 http_stream->ReadResponseBody( |
| 904 buf1.get(), kUploadDataSize, callback.callback())); | 903 buf1.get(), kUploadDataSize, callback.callback())); |
| 905 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); | 904 EXPECT_EQ(kUploadData, SpdyString(buf1->data(), kUploadDataSize)); |
| 906 | 905 |
| 907 ASSERT_TRUE(response.headers.get()); | 906 ASSERT_TRUE(response.headers.get()); |
| 908 ASSERT_EQ(200, response.headers->response_code()); | 907 ASSERT_EQ(200, response.headers->response_code()); |
| 909 } | 908 } |
| 910 | 909 |
| 911 TEST_F(SpdyHttpStreamTest, DataReadErrorSynchronous) { | 910 TEST_F(SpdyHttpStreamTest, DataReadErrorSynchronous) { |
| 912 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 911 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 913 | 912 |
| 914 // Server receives ERROR_CODE_INTERNAL_ERROR on client's internal failure. | 913 // Server receives ERROR_CODE_INTERNAL_ERROR on client's internal failure. |
| 915 // The failure is a reading error in this case caused by | 914 // The failure is a reading error in this case caused by |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 | 1061 |
| 1063 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 1062 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 1064 } | 1063 } |
| 1065 | 1064 |
| 1066 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 1065 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
| 1067 // methods. | 1066 // methods. |
| 1068 | 1067 |
| 1069 } // namespace test | 1068 } // namespace test |
| 1070 | 1069 |
| 1071 } // namespace net | 1070 } // namespace net |
| OLD | NEW |