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