| 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> |
| 10 | 11 |
| 11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 12 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "crypto/ec_private_key.h" | 15 #include "crypto/ec_private_key.h" |
| 15 #include "crypto/ec_signature_creator.h" | 16 #include "crypto/ec_signature_creator.h" |
| 16 #include "crypto/signature_creator.h" | 17 #include "crypto/signature_creator.h" |
| 17 #include "net/base/chunked_upload_data_stream.h" | 18 #include "net/base/chunked_upload_data_stream.h" |
| 18 #include "net/base/load_timing_info.h" | 19 #include "net/base/load_timing_info.h" |
| 19 #include "net/base/load_timing_info_test_util.h" | 20 #include "net/base/load_timing_info_test_util.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 98 |
| 98 const FailureMode async_; | 99 const FailureMode async_; |
| 99 | 100 |
| 100 base::WeakPtrFactory<ReadErrorUploadDataStream> weak_factory_; | 101 base::WeakPtrFactory<ReadErrorUploadDataStream> weak_factory_; |
| 101 | 102 |
| 102 DISALLOW_COPY_AND_ASSIGN(ReadErrorUploadDataStream); | 103 DISALLOW_COPY_AND_ASSIGN(ReadErrorUploadDataStream); |
| 103 }; | 104 }; |
| 104 | 105 |
| 105 class CancelStreamCallback : public TestCompletionCallbackBase { | 106 class CancelStreamCallback : public TestCompletionCallbackBase { |
| 106 public: | 107 public: |
| 107 CancelStreamCallback(SpdyHttpStream* stream) | 108 explicit CancelStreamCallback(SpdyHttpStream* stream) |
| 108 : stream_(stream), | 109 : stream_(stream), |
| 109 callback_(base::Bind(&CancelStreamCallback::CancelStream, | 110 callback_(base::Bind(&CancelStreamCallback::CancelStream, |
| 110 base::Unretained(this))) {} | 111 base::Unretained(this))) {} |
| 111 | 112 |
| 112 const CompletionCallback& callback() const { return callback_; } | 113 const CompletionCallback& callback() const { return callback_; } |
| 113 | 114 |
| 114 private: | 115 private: |
| 115 void CancelStream(int result) { | 116 void CancelStream(int result) { |
| 116 stream_->Cancel(); | 117 stream_->Cancel(); |
| 117 SetResult(result); | 118 SetResult(result); |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 buf1.get(), kUploadDataSize, callback.callback())); | 906 buf1.get(), kUploadDataSize, callback.callback())); |
| 906 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); | 907 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); |
| 907 | 908 |
| 908 ASSERT_TRUE(response.headers.get()); | 909 ASSERT_TRUE(response.headers.get()); |
| 909 ASSERT_EQ(200, response.headers->response_code()); | 910 ASSERT_EQ(200, response.headers->response_code()); |
| 910 } | 911 } |
| 911 | 912 |
| 912 TEST_F(SpdyHttpStreamTest, DataReadErrorSynchronous) { | 913 TEST_F(SpdyHttpStreamTest, DataReadErrorSynchronous) { |
| 913 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 914 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 914 | 915 |
| 915 // Server receives RST_STREAM_INTERNAL_ERROR on client's internal failure. | 916 // Server receives ERROR_CODE_INTERNAL_ERROR on client's internal failure. |
| 916 // The failure is a reading error in this case caused by | 917 // The failure is a reading error in this case caused by |
| 917 // UploadDataStream::Read(). | 918 // UploadDataStream::Read(). |
| 918 SpdySerializedFrame rst_frame( | 919 SpdySerializedFrame rst_frame( |
| 919 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_INTERNAL_ERROR)); | 920 spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_INTERNAL_ERROR)); |
| 920 | 921 |
| 921 MockWrite writes[] = { | 922 MockWrite writes[] = { |
| 922 CreateMockWrite(req, 0, SYNCHRONOUS), // Request | 923 CreateMockWrite(req, 0, SYNCHRONOUS), // Request |
| 923 CreateMockWrite(rst_frame, 1, SYNCHRONOUS) // Reset frame | 924 CreateMockWrite(rst_frame, 1, SYNCHRONOUS) // Reset frame |
| 924 }; | 925 }; |
| 925 | 926 |
| 926 SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(nullptr, 0)); | 927 SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(nullptr, 0)); |
| 927 | 928 |
| 928 MockRead reads[] = { | 929 MockRead reads[] = { |
| 929 CreateMockRead(resp, 2), MockRead(SYNCHRONOUS, 0, 3), | 930 CreateMockRead(resp, 2), MockRead(SYNCHRONOUS, 0, 3), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 958 base::RunLoop().RunUntilIdle(); | 959 base::RunLoop().RunUntilIdle(); |
| 959 | 960 |
| 960 // Because the server has not closed the connection yet, there shouldn't be | 961 // Because the server has not closed the connection yet, there shouldn't be |
| 961 // a stream but a session in the pool | 962 // a stream but a session in the pool |
| 962 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 963 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 963 } | 964 } |
| 964 | 965 |
| 965 TEST_F(SpdyHttpStreamTest, DataReadErrorAsynchronous) { | 966 TEST_F(SpdyHttpStreamTest, DataReadErrorAsynchronous) { |
| 966 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 967 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 967 | 968 |
| 968 // Server receives RST_STREAM_INTERNAL_ERROR on client's internal failure. | 969 // Server receives ERROR_CODE_INTERNAL_ERROR on client's internal failure. |
| 969 // The failure is a reading error in this case caused by | 970 // The failure is a reading error in this case caused by |
| 970 // UploadDataStream::Read(). | 971 // UploadDataStream::Read(). |
| 971 SpdySerializedFrame rst_frame( | 972 SpdySerializedFrame rst_frame( |
| 972 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_INTERNAL_ERROR)); | 973 spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_INTERNAL_ERROR)); |
| 973 | 974 |
| 974 MockWrite writes[] = { | 975 MockWrite writes[] = { |
| 975 CreateMockWrite(req, 0), // Request | 976 CreateMockWrite(req, 0), // Request |
| 976 CreateMockWrite(rst_frame, 1) // Reset frame | 977 CreateMockWrite(rst_frame, 1) // Reset frame |
| 977 }; | 978 }; |
| 978 | 979 |
| 979 SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(nullptr, 0)); | 980 SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(nullptr, 0)); |
| 980 | 981 |
| 981 MockRead reads[] = { | 982 MockRead reads[] = { |
| 982 MockRead(ASYNC, 0, 2), | 983 MockRead(ASYNC, 0, 2), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 // in the pool anymore. | 1016 // in the pool anymore. |
| 1016 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 1017 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 1017 } | 1018 } |
| 1018 | 1019 |
| 1019 // Regression test for https://crbug.com/622447. | 1020 // Regression test for https://crbug.com/622447. |
| 1020 TEST_F(SpdyHttpStreamTest, RequestCallbackCancelsStream) { | 1021 TEST_F(SpdyHttpStreamTest, RequestCallbackCancelsStream) { |
| 1021 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 1022 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 1022 SpdySerializedFrame chunk( | 1023 SpdySerializedFrame chunk( |
| 1023 spdy_util_.ConstructSpdyDataFrame(1, nullptr, 0, true)); | 1024 spdy_util_.ConstructSpdyDataFrame(1, nullptr, 0, true)); |
| 1024 SpdySerializedFrame rst( | 1025 SpdySerializedFrame rst( |
| 1025 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | 1026 spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
| 1026 MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(chunk, 1), | 1027 MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(chunk, 1), |
| 1027 CreateMockWrite(rst, 2)}; | 1028 CreateMockWrite(rst, 2)}; |
| 1028 MockRead reads[] = {MockRead(ASYNC, 0, 3)}; | 1029 MockRead reads[] = {MockRead(ASYNC, 0, 3)}; |
| 1029 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 1030 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 1030 | 1031 |
| 1031 HttpRequestInfo request; | 1032 HttpRequestInfo request; |
| 1032 request.method = "POST"; | 1033 request.method = "POST"; |
| 1033 request.url = url_; | 1034 request.url = url_; |
| 1034 ChunkedUploadDataStream upload_stream(0); | 1035 ChunkedUploadDataStream upload_stream(0); |
| 1035 request.upload_data_stream = &upload_stream; | 1036 request.upload_data_stream = &upload_stream; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1063 | 1064 |
| 1064 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 1065 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 1065 } | 1066 } |
| 1066 | 1067 |
| 1067 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 1068 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
| 1068 // methods. | 1069 // methods. |
| 1069 | 1070 |
| 1070 } // namespace test | 1071 } // namespace test |
| 1071 | 1072 |
| 1072 } // namespace net | 1073 } // namespace net |
| OLD | NEW |