| 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/quic/chromium/quic_chromium_client_stream.h" | 5 #include "net/quic/chromium/quic_chromium_client_stream.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
| 15 #include "net/quic/chromium/quic_chromium_client_session.h" | 15 #include "net/quic/chromium/quic_chromium_client_session.h" |
| 16 #include "net/quic/core/quic_client_session_base.h" | 16 #include "net/quic/core/quic_client_session_base.h" |
| 17 #include "net/quic/core/quic_utils.h" | 17 #include "net/quic/core/quic_utils.h" |
| 18 #include "net/quic/core/spdy_utils.h" | 18 #include "net/quic/core/spdy_utils.h" |
| 19 #include "net/quic/platform/api/quic_ptr_util.h" | |
| 20 #include "net/quic/test_tools/crypto_test_utils.h" | 19 #include "net/quic/test_tools/crypto_test_utils.h" |
| 21 #include "net/quic/test_tools/quic_spdy_session_peer.h" | |
| 22 #include "net/quic/test_tools/quic_test_utils.h" | 20 #include "net/quic/test_tools/quic_test_utils.h" |
| 23 #include "net/test/gtest_util.h" | 21 #include "net/test/gtest_util.h" |
| 24 #include "net/tools/quic/quic_spdy_client_stream.h" | |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gmock_mutant.h" | 23 #include "testing/gmock_mutant.h" |
| 27 | 24 |
| 28 using testing::AnyNumber; | 25 using testing::AnyNumber; |
| 29 using testing::CreateFunctor; | 26 using testing::CreateFunctor; |
| 30 using testing::Invoke; | 27 using testing::Invoke; |
| 31 using testing::Return; | 28 using testing::Return; |
| 32 using testing::StrEq; | 29 using testing::StrEq; |
| 33 using testing::_; | 30 using testing::_; |
| 34 | 31 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 56 MOCK_METHOD0(OnClose, void()); | 53 MOCK_METHOD0(OnClose, void()); |
| 57 MOCK_METHOD1(OnError, void(int)); | 54 MOCK_METHOD1(OnError, void(int)); |
| 58 MOCK_METHOD0(HasSendHeadersComplete, bool()); | 55 MOCK_METHOD0(HasSendHeadersComplete, bool()); |
| 59 | 56 |
| 60 SpdyHeaderBlock headers_; | 57 SpdyHeaderBlock headers_; |
| 61 | 58 |
| 62 private: | 59 private: |
| 63 DISALLOW_COPY_AND_ASSIGN(MockDelegate); | 60 DISALLOW_COPY_AND_ASSIGN(MockDelegate); |
| 64 }; | 61 }; |
| 65 | 62 |
| 66 class TestQuicClientSessionBaseStream : public QuicSpdyStream { | |
| 67 public: | |
| 68 TestQuicClientSessionBaseStream(QuicStreamId id, QuicSpdySession* session) | |
| 69 : QuicSpdyStream(id, session) {} | |
| 70 | |
| 71 void OnDataAvailable() override {} | |
| 72 }; | |
| 73 | |
| 74 class MockQuicClientSessionBase : public QuicClientSessionBase { | 63 class MockQuicClientSessionBase : public QuicClientSessionBase { |
| 75 public: | 64 public: |
| 76 explicit MockQuicClientSessionBase(QuicConnection* connection, | 65 explicit MockQuicClientSessionBase(QuicConnection* connection, |
| 77 QuicClientPushPromiseIndex* index); | 66 QuicClientPushPromiseIndex* index); |
| 78 ~MockQuicClientSessionBase() override; | 67 ~MockQuicClientSessionBase() override; |
| 79 | 68 |
| 80 const QuicCryptoStream* GetCryptoStream() const override { | 69 const QuicCryptoStream* GetCryptoStream() const override { |
| 81 return crypto_stream_.get(); | 70 return crypto_stream_.get(); |
| 82 } | 71 } |
| 83 | 72 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 MOCK_METHOD5( | 122 MOCK_METHOD5( |
| 134 WriteHeadersMock, | 123 WriteHeadersMock, |
| 135 size_t(QuicStreamId id, | 124 size_t(QuicStreamId id, |
| 136 const SpdyHeaderBlock& headers, | 125 const SpdyHeaderBlock& headers, |
| 137 bool fin, | 126 bool fin, |
| 138 SpdyPriority priority, | 127 SpdyPriority priority, |
| 139 const QuicReferenceCountedPointer<QuicAckListenerInterface>& | 128 const QuicReferenceCountedPointer<QuicAckListenerInterface>& |
| 140 ack_listener)); | 129 ack_listener)); |
| 141 MOCK_METHOD1(OnHeadersHeadOfLineBlocking, void(QuicTime::Delta delta)); | 130 MOCK_METHOD1(OnHeadersHeadOfLineBlocking, void(QuicTime::Delta delta)); |
| 142 | 131 |
| 143 std::unique_ptr<QuicStream> CreateStream(QuicStreamId id) { | |
| 144 return QuicMakeUnique<TestQuicClientSessionBaseStream>(id, this); | |
| 145 } | |
| 146 | |
| 147 using QuicSession::ActivateStream; | 132 using QuicSession::ActivateStream; |
| 148 | 133 |
| 149 // Returns a QuicConsumedData that indicates all of |data| (and |fin| if set) | 134 // Returns a QuicConsumedData that indicates all of |data| (and |fin| if set) |
| 150 // has been consumed. | 135 // has been consumed. |
| 151 static QuicConsumedData ConsumeAllData( | 136 static QuicConsumedData ConsumeAllData( |
| 152 QuicStreamId id, | 137 QuicStreamId id, |
| 153 const QuicIOVector& data, | 138 const QuicIOVector& data, |
| 154 QuicStreamOffset offset, | 139 QuicStreamOffset offset, |
| 155 bool fin, | 140 bool fin, |
| 156 QuicAckListenerInterface* ack_listener); | 141 QuicAckListenerInterface* ack_listener); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 QuicHeaderList ProcessHeadersFull(const SpdyHeaderBlock& headers) { | 239 QuicHeaderList ProcessHeadersFull(const SpdyHeaderBlock& headers) { |
| 255 QuicHeaderList h = ProcessHeaders(headers); | 240 QuicHeaderList h = ProcessHeaders(headers); |
| 256 EXPECT_CALL(delegate_, | 241 EXPECT_CALL(delegate_, |
| 257 OnHeadersAvailableMock(_, h.uncompressed_header_bytes())); | 242 OnHeadersAvailableMock(_, h.uncompressed_header_bytes())); |
| 258 base::RunLoop().RunUntilIdle(); | 243 base::RunLoop().RunUntilIdle(); |
| 259 EXPECT_EQ(headers, delegate_.headers_); | 244 EXPECT_EQ(headers, delegate_.headers_); |
| 260 EXPECT_TRUE(stream_->header_list().empty()); | 245 EXPECT_TRUE(stream_->header_list().empty()); |
| 261 return h; | 246 return h; |
| 262 } | 247 } |
| 263 | 248 |
| 264 QuicStreamId GetNthClientInitiatedStreamId(int n) { | |
| 265 return QuicSpdySessionPeer::GetNthClientInitiatedStreamId(session_, n); | |
| 266 } | |
| 267 | |
| 268 QuicStreamId GetNthServerInitiatedStreamId(int n) { | |
| 269 return QuicSpdySessionPeer::GetNthServerInitiatedStreamId(session_, n); | |
| 270 } | |
| 271 | |
| 272 QuicCryptoClientConfig crypto_config_; | 249 QuicCryptoClientConfig crypto_config_; |
| 273 testing::StrictMock<MockDelegate> delegate_; | 250 testing::StrictMock<MockDelegate> delegate_; |
| 274 MockQuicConnectionHelper helper_; | 251 MockQuicConnectionHelper helper_; |
| 275 MockAlarmFactory alarm_factory_; | 252 MockAlarmFactory alarm_factory_; |
| 276 MockQuicClientSessionBase session_; | 253 MockQuicClientSessionBase session_; |
| 277 QuicChromiumClientStream* stream_; | 254 QuicChromiumClientStream* stream_; |
| 278 SpdyHeaderBlock headers_; | 255 SpdyHeaderBlock headers_; |
| 279 QuicClientPushPromiseIndex push_promise_index_; | 256 QuicClientPushPromiseIndex push_promise_index_; |
| 280 }; | 257 }; |
| 281 | 258 |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 .WillOnce(Return(QuicConsumedData(buf2->size(), true))); | 586 .WillOnce(Return(QuicConsumedData(buf2->size(), true))); |
| 610 stream_->OnCanWrite(); | 587 stream_->OnCanWrite(); |
| 611 ASSERT_TRUE(callback.have_result()); | 588 ASSERT_TRUE(callback.have_result()); |
| 612 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 589 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 613 } | 590 } |
| 614 | 591 |
| 615 TEST_P(QuicChromiumClientStreamTest, HeadersBeforeDelegate) { | 592 TEST_P(QuicChromiumClientStreamTest, HeadersBeforeDelegate) { |
| 616 // We don't use stream_ because we want an incoming server push | 593 // We don't use stream_ because we want an incoming server push |
| 617 // stream. | 594 // stream. |
| 618 QuicChromiumClientStream* stream = new QuicChromiumClientStream( | 595 QuicChromiumClientStream* stream = new QuicChromiumClientStream( |
| 619 GetNthServerInitiatedStreamId(0), &session_, NetLogWithSource()); | 596 kServerDataStreamId1, &session_, NetLogWithSource()); |
| 620 session_.ActivateStream(base::WrapUnique(stream)); | 597 session_.ActivateStream(base::WrapUnique(stream)); |
| 621 | 598 |
| 622 InitializeHeaders(); | 599 InitializeHeaders(); |
| 623 stream->SetDelegate(&delegate_); | 600 stream->SetDelegate(&delegate_); |
| 624 ProcessHeadersFull(headers_); | 601 ProcessHeadersFull(headers_); |
| 625 | 602 |
| 626 // Times(2) because OnClose will be called for stream and stream_. | 603 // Times(2) because OnClose will be called for stream and stream_. |
| 627 EXPECT_CALL(delegate_, OnClose()).Times(2); | 604 EXPECT_CALL(delegate_, OnClose()).Times(2); |
| 628 } | 605 } |
| 629 | 606 |
| 630 } // namespace | 607 } // namespace |
| 631 } // namespace test | 608 } // namespace test |
| 632 } // namespace net | 609 } // namespace net |
| OLD | NEW |