| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/bidirectional_stream_spdy_impl.h" | 5 #include "net/spdy/bidirectional_stream_spdy_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | |
| 9 | 8 |
| 10 #include "base/macros.h" | 9 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 12 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 13 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 15 #include "base/timer/mock_timer.h" | 14 #include "base/timer/mock_timer.h" |
| 16 #include "net/base/load_timing_info.h" | 15 #include "net/base/load_timing_info.h" |
| 17 #include "net/base/load_timing_info_test_util.h" | 16 #include "net/base/load_timing_info_test_util.h" |
| 18 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 19 #include "net/http/http_request_info.h" | 18 #include "net/http/http_request_info.h" |
| 20 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
| 21 #include "net/http/http_response_info.h" | 20 #include "net/http/http_response_info.h" |
| 22 #include "net/log/test_net_log.h" | 21 #include "net/log/test_net_log.h" |
| 23 #include "net/socket/socket_test_util.h" | 22 #include "net/socket/socket_test_util.h" |
| 23 #include "net/spdy/platform/api/spdy_string.h" |
| 24 #include "net/spdy/spdy_session.h" | 24 #include "net/spdy/spdy_session.h" |
| 25 #include "net/spdy/spdy_test_util_common.h" | 25 #include "net/spdy/spdy_test_util_common.h" |
| 26 #include "net/test/cert_test_util.h" | 26 #include "net/test/cert_test_util.h" |
| 27 #include "net/test/gtest_util.h" | 27 #include "net/test/gtest_util.h" |
| 28 #include "net/test/test_data_directory.h" | 28 #include "net/test/test_data_directory.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 31 |
| 32 using net::test::IsError; | 32 using net::test::IsError; |
| 33 using net::test::IsOk; | 33 using net::test::IsOk; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 189 |
| 190 int64_t GetTotalSentBytes() const { | 190 int64_t GetTotalSentBytes() const { |
| 191 return stream_->GetTotalSentBytes(); | 191 return stream_->GetTotalSentBytes(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const { | 194 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const { |
| 195 return stream_->GetLoadTimingInfo(load_timing_info); | 195 return stream_->GetLoadTimingInfo(load_timing_info); |
| 196 } | 196 } |
| 197 | 197 |
| 198 // Const getters for internal states. | 198 // Const getters for internal states. |
| 199 const std::string& data_received() const { return data_received_; } | 199 const SpdyString& data_received() const { return data_received_; } |
| 200 int bytes_read() const { return bytes_read_; } | 200 int bytes_read() const { return bytes_read_; } |
| 201 int error() const { return error_; } | 201 int error() const { return error_; } |
| 202 const SpdyHeaderBlock& response_headers() const { return response_headers_; } | 202 const SpdyHeaderBlock& response_headers() const { return response_headers_; } |
| 203 const SpdyHeaderBlock& trailers() const { return trailers_; } | 203 const SpdyHeaderBlock& trailers() const { return trailers_; } |
| 204 int on_data_read_count() const { return on_data_read_count_; } | 204 int on_data_read_count() const { return on_data_read_count_; } |
| 205 int on_data_sent_count() const { return on_data_sent_count_; } | 205 int on_data_sent_count() const { return on_data_sent_count_; } |
| 206 bool on_failed_called() const { return on_failed_called_; } | 206 bool on_failed_called() const { return on_failed_called_; } |
| 207 | 207 |
| 208 // Sets whether the delegate should automatically start reading. | 208 // Sets whether the delegate should automatically start reading. |
| 209 void set_do_not_start_read(bool do_not_start_read) { | 209 void set_do_not_start_read(bool do_not_start_read) { |
| 210 do_not_start_read_ = do_not_start_read; | 210 do_not_start_read_ = do_not_start_read; |
| 211 } | 211 } |
| 212 | 212 |
| 213 private: | 213 private: |
| 214 std::unique_ptr<BidirectionalStreamSpdyImpl> stream_; | 214 std::unique_ptr<BidirectionalStreamSpdyImpl> stream_; |
| 215 scoped_refptr<IOBuffer> read_buf_; | 215 scoped_refptr<IOBuffer> read_buf_; |
| 216 int read_buf_len_; | 216 int read_buf_len_; |
| 217 std::string data_received_; | 217 SpdyString data_received_; |
| 218 std::unique_ptr<base::RunLoop> loop_; | 218 std::unique_ptr<base::RunLoop> loop_; |
| 219 SpdyHeaderBlock response_headers_; | 219 SpdyHeaderBlock response_headers_; |
| 220 SpdyHeaderBlock trailers_; | 220 SpdyHeaderBlock trailers_; |
| 221 int error_; | 221 int error_; |
| 222 int bytes_read_; | 222 int bytes_read_; |
| 223 int on_data_read_count_; | 223 int on_data_read_count_; |
| 224 int on_data_sent_count_; | 224 int on_data_sent_count_; |
| 225 bool do_not_start_read_; | 225 bool do_not_start_read_; |
| 226 bool run_until_completion_; | 226 bool run_until_completion_; |
| 227 bool not_expect_callback_; | 227 bool not_expect_callback_; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 base::SizeTToString(kBodyDataSize)); | 306 base::SizeTToString(kBodyDataSize)); |
| 307 | 307 |
| 308 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); | 308 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); |
| 309 std::unique_ptr<TestDelegateBase> delegate( | 309 std::unique_ptr<TestDelegateBase> delegate( |
| 310 new TestDelegateBase(session_, read_buffer.get(), kReadBufferSize)); | 310 new TestDelegateBase(session_, read_buffer.get(), kReadBufferSize)); |
| 311 delegate->SetRunUntilCompletion(true); | 311 delegate->SetRunUntilCompletion(true); |
| 312 delegate->Start(&request_info, net_log_.bound()); | 312 delegate->Start(&request_info, net_log_.bound()); |
| 313 sequenced_data_->RunUntilPaused(); | 313 sequenced_data_->RunUntilPaused(); |
| 314 | 314 |
| 315 scoped_refptr<StringIOBuffer> write_buffer( | 315 scoped_refptr<StringIOBuffer> write_buffer( |
| 316 new StringIOBuffer(std::string(kBodyData, kBodyDataSize))); | 316 new StringIOBuffer(SpdyString(kBodyData, kBodyDataSize))); |
| 317 delegate->SendData(write_buffer.get(), write_buffer->size(), true); | 317 delegate->SendData(write_buffer.get(), write_buffer->size(), true); |
| 318 sequenced_data_->Resume(); | 318 sequenced_data_->Resume(); |
| 319 base::RunLoop().RunUntilIdle(); | 319 base::RunLoop().RunUntilIdle(); |
| 320 delegate->WaitUntilCompletion(); | 320 delegate->WaitUntilCompletion(); |
| 321 LoadTimingInfo load_timing_info; | 321 LoadTimingInfo load_timing_info; |
| 322 EXPECT_TRUE(delegate->GetLoadTimingInfo(&load_timing_info)); | 322 EXPECT_TRUE(delegate->GetLoadTimingInfo(&load_timing_info)); |
| 323 TestLoadTimingNotReused(load_timing_info); | 323 TestLoadTimingNotReused(load_timing_info); |
| 324 | 324 |
| 325 EXPECT_EQ(1, delegate->on_data_read_count()); | 325 EXPECT_EQ(1, delegate->on_data_read_count()); |
| 326 EXPECT_EQ(1, delegate->on_data_sent_count()); | 326 EXPECT_EQ(1, delegate->on_data_sent_count()); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 base::SizeTToString(kBodyDataSize * 3)); | 458 base::SizeTToString(kBodyDataSize * 3)); |
| 459 | 459 |
| 460 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); | 460 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); |
| 461 std::unique_ptr<TestDelegateBase> delegate( | 461 std::unique_ptr<TestDelegateBase> delegate( |
| 462 new TestDelegateBase(session_, read_buffer.get(), kReadBufferSize)); | 462 new TestDelegateBase(session_, read_buffer.get(), kReadBufferSize)); |
| 463 delegate->SetRunUntilCompletion(true); | 463 delegate->SetRunUntilCompletion(true); |
| 464 delegate->Start(&request_info, net_log_.bound()); | 464 delegate->Start(&request_info, net_log_.bound()); |
| 465 sequenced_data_->RunUntilPaused(); | 465 sequenced_data_->RunUntilPaused(); |
| 466 // Make a write pending before receiving RST_STREAM. | 466 // Make a write pending before receiving RST_STREAM. |
| 467 scoped_refptr<StringIOBuffer> write_buffer( | 467 scoped_refptr<StringIOBuffer> write_buffer( |
| 468 new StringIOBuffer(std::string(kBodyData, kBodyDataSize))); | 468 new StringIOBuffer(SpdyString(kBodyData, kBodyDataSize))); |
| 469 delegate->SendData(write_buffer.get(), write_buffer->size(), false); | 469 delegate->SendData(write_buffer.get(), write_buffer->size(), false); |
| 470 sequenced_data_->Resume(); | 470 sequenced_data_->Resume(); |
| 471 base::RunLoop().RunUntilIdle(); | 471 base::RunLoop().RunUntilIdle(); |
| 472 | 472 |
| 473 // Make sure OnClose() without an error completes any pending write(). | 473 // Make sure OnClose() without an error completes any pending write(). |
| 474 EXPECT_EQ(1, delegate->on_data_sent_count()); | 474 EXPECT_EQ(1, delegate->on_data_sent_count()); |
| 475 EXPECT_FALSE(delegate->on_failed_called()); | 475 EXPECT_FALSE(delegate->on_failed_called()); |
| 476 | 476 |
| 477 if (is_test_sendv) { | 477 if (is_test_sendv) { |
| 478 std::vector<scoped_refptr<IOBuffer>> three_buffers = { | 478 std::vector<scoped_refptr<IOBuffer>> three_buffers = { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 } else { | 511 } else { |
| 512 delegate->SendData(write_buffer.get(), write_buffer->size(), true); | 512 delegate->SendData(write_buffer.get(), write_buffer->size(), true); |
| 513 } | 513 } |
| 514 base::RunLoop().RunUntilIdle(); | 514 base::RunLoop().RunUntilIdle(); |
| 515 EXPECT_THAT(delegate->error(), IsError(ERR_UNEXPECTED)); | 515 EXPECT_THAT(delegate->error(), IsError(ERR_UNEXPECTED)); |
| 516 EXPECT_TRUE(delegate->on_failed_called()); | 516 EXPECT_TRUE(delegate->on_failed_called()); |
| 517 EXPECT_EQ(is_test_sendv ? 2 : 4, delegate->on_data_sent_count()); | 517 EXPECT_EQ(is_test_sendv ? 2 : 4, delegate->on_data_sent_count()); |
| 518 } | 518 } |
| 519 | 519 |
| 520 } // namespace net | 520 } // namespace net |
| OLD | NEW |