| 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/quic_chromium_client_stream.h" | 5 #include "net/quic/quic_chromium_client_stream.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 9 #include "net/base/test_completion_callback.h" | 9 #include "net/base/test_completion_callback.h" |
| 10 #include "net/quic/quic_chromium_client_session.h" | 10 #include "net/quic/quic_chromium_client_session.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 ~MockQuicClientSessionBase() override; | 53 ~MockQuicClientSessionBase() override; |
| 54 | 54 |
| 55 QuicCryptoStream* GetCryptoStream() override { return crypto_stream_.get(); } | 55 QuicCryptoStream* GetCryptoStream() override { return crypto_stream_.get(); } |
| 56 | 56 |
| 57 // From QuicSession. | 57 // From QuicSession. |
| 58 MOCK_METHOD2(OnConnectionClosed, | 58 MOCK_METHOD2(OnConnectionClosed, |
| 59 void(QuicErrorCode error, ConnectionCloseSource source)); | 59 void(QuicErrorCode error, ConnectionCloseSource source)); |
| 60 MOCK_METHOD1(CreateIncomingDynamicStream, QuicSpdyStream*(QuicStreamId id)); | 60 MOCK_METHOD1(CreateIncomingDynamicStream, QuicSpdyStream*(QuicStreamId id)); |
| 61 MOCK_METHOD1(CreateOutgoingDynamicStream, | 61 MOCK_METHOD1(CreateOutgoingDynamicStream, |
| 62 QuicChromiumClientStream*(SpdyPriority priority)); | 62 QuicChromiumClientStream*(SpdyPriority priority)); |
| 63 MOCK_METHOD6(WritevData, | 63 MOCK_METHOD5(WritevData, |
| 64 QuicConsumedData(QuicStreamId id, | 64 QuicConsumedData(QuicStreamId id, |
| 65 QuicIOVector data, | 65 QuicIOVector data, |
| 66 QuicStreamOffset offset, | 66 QuicStreamOffset offset, |
| 67 bool fin, | 67 bool fin, |
| 68 FecProtection fec_protection, | |
| 69 QuicAckListenerInterface*)); | 68 QuicAckListenerInterface*)); |
| 70 MOCK_METHOD3(SendRstStream, | 69 MOCK_METHOD3(SendRstStream, |
| 71 void(QuicStreamId stream_id, | 70 void(QuicStreamId stream_id, |
| 72 QuicRstStreamErrorCode error, | 71 QuicRstStreamErrorCode error, |
| 73 QuicStreamOffset bytes_written)); | 72 QuicStreamOffset bytes_written)); |
| 74 | 73 |
| 75 MOCK_METHOD2(OnStreamHeaders, | 74 MOCK_METHOD2(OnStreamHeaders, |
| 76 void(QuicStreamId stream_id, base::StringPiece headers_data)); | 75 void(QuicStreamId stream_id, base::StringPiece headers_data)); |
| 77 MOCK_METHOD2(OnStreamHeadersPriority, | 76 MOCK_METHOD2(OnStreamHeadersPriority, |
| 78 void(QuicStreamId stream_id, SpdyPriority priority)); | 77 void(QuicStreamId stream_id, SpdyPriority priority)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 95 | 94 |
| 96 using QuicSession::ActivateStream; | 95 using QuicSession::ActivateStream; |
| 97 | 96 |
| 98 // Returns a QuicConsumedData that indicates all of |data| (and |fin| if set) | 97 // Returns a QuicConsumedData that indicates all of |data| (and |fin| if set) |
| 99 // has been consumed. | 98 // has been consumed. |
| 100 static QuicConsumedData ConsumeAllData( | 99 static QuicConsumedData ConsumeAllData( |
| 101 QuicStreamId id, | 100 QuicStreamId id, |
| 102 const QuicIOVector& data, | 101 const QuicIOVector& data, |
| 103 QuicStreamOffset offset, | 102 QuicStreamOffset offset, |
| 104 bool fin, | 103 bool fin, |
| 105 FecProtection fec_protection, | |
| 106 QuicAckListenerInterface* ack_notifier_delegate); | 104 QuicAckListenerInterface* ack_notifier_delegate); |
| 107 | 105 |
| 108 void OnProofValid( | 106 void OnProofValid( |
| 109 const QuicCryptoClientConfig::CachedState& cached) override {} | 107 const QuicCryptoClientConfig::CachedState& cached) override {} |
| 110 void OnProofVerifyDetailsAvailable( | 108 void OnProofVerifyDetailsAvailable( |
| 111 const ProofVerifyDetails& verify_details) override {} | 109 const ProofVerifyDetails& verify_details) override {} |
| 112 bool IsAuthorized(const std::string& hostname) override { return true; } | 110 bool IsAuthorized(const std::string& hostname) override { return true; } |
| 113 | 111 |
| 114 private: | 112 private: |
| 115 scoped_ptr<QuicCryptoStream> crypto_stream_; | 113 scoped_ptr<QuicCryptoStream> crypto_stream_; |
| 116 | 114 |
| 117 DISALLOW_COPY_AND_ASSIGN(MockQuicClientSessionBase); | 115 DISALLOW_COPY_AND_ASSIGN(MockQuicClientSessionBase); |
| 118 }; | 116 }; |
| 119 | 117 |
| 120 MockQuicClientSessionBase::MockQuicClientSessionBase( | 118 MockQuicClientSessionBase::MockQuicClientSessionBase( |
| 121 QuicConnection* connection, | 119 QuicConnection* connection, |
| 122 QuicClientPushPromiseIndex* push_promise_index) | 120 QuicClientPushPromiseIndex* push_promise_index) |
| 123 : QuicClientSessionBase(connection, | 121 : QuicClientSessionBase(connection, |
| 124 push_promise_index, | 122 push_promise_index, |
| 125 DefaultQuicConfig()) { | 123 DefaultQuicConfig()) { |
| 126 crypto_stream_.reset(new QuicCryptoStream(this)); | 124 crypto_stream_.reset(new QuicCryptoStream(this)); |
| 127 Initialize(); | 125 Initialize(); |
| 128 ON_CALL(*this, WritevData(_, _, _, _, _, _)) | 126 ON_CALL(*this, WritevData(_, _, _, _, _)) |
| 129 .WillByDefault(testing::Return(QuicConsumedData(0, false))); | 127 .WillByDefault(testing::Return(QuicConsumedData(0, false))); |
| 130 } | 128 } |
| 131 | 129 |
| 132 MockQuicClientSessionBase::~MockQuicClientSessionBase() {} | 130 MockQuicClientSessionBase::~MockQuicClientSessionBase() {} |
| 133 | 131 |
| 134 class QuicChromiumClientStreamTest | 132 class QuicChromiumClientStreamTest |
| 135 : public ::testing::TestWithParam<QuicVersion> { | 133 : public ::testing::TestWithParam<QuicVersion> { |
| 136 public: | 134 public: |
| 137 QuicChromiumClientStreamTest() | 135 QuicChromiumClientStreamTest() |
| 138 : crypto_config_(CryptoTestUtils::ProofVerifierForTesting()), | 136 : crypto_config_(CryptoTestUtils::ProofVerifierForTesting()), |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); | 326 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); |
| 329 } | 327 } |
| 330 | 328 |
| 331 TEST_P(QuicChromiumClientStreamTest, WriteStreamData) { | 329 TEST_P(QuicChromiumClientStreamTest, WriteStreamData) { |
| 332 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); | 330 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); |
| 333 | 331 |
| 334 const char kData1[] = "hello world"; | 332 const char kData1[] = "hello world"; |
| 335 const size_t kDataLen = arraysize(kData1); | 333 const size_t kDataLen = arraysize(kData1); |
| 336 | 334 |
| 337 // All data written. | 335 // All data written. |
| 338 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _, _)) | 336 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _)) |
| 339 .WillOnce(Return(QuicConsumedData(kDataLen, true))); | 337 .WillOnce(Return(QuicConsumedData(kDataLen, true))); |
| 340 TestCompletionCallback callback; | 338 TestCompletionCallback callback; |
| 341 EXPECT_EQ(OK, stream_->WriteStreamData(base::StringPiece(kData1, kDataLen), | 339 EXPECT_EQ(OK, stream_->WriteStreamData(base::StringPiece(kData1, kDataLen), |
| 342 true, callback.callback())); | 340 true, callback.callback())); |
| 343 } | 341 } |
| 344 | 342 |
| 345 TEST_P(QuicChromiumClientStreamTest, WriteStreamDataAsync) { | 343 TEST_P(QuicChromiumClientStreamTest, WriteStreamDataAsync) { |
| 346 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber()); | 344 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber()); |
| 347 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); | 345 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); |
| 348 | 346 |
| 349 const char kData1[] = "hello world"; | 347 const char kData1[] = "hello world"; |
| 350 const size_t kDataLen = arraysize(kData1); | 348 const size_t kDataLen = arraysize(kData1); |
| 351 | 349 |
| 352 // No data written. | 350 // No data written. |
| 353 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _, _)) | 351 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _)) |
| 354 .WillOnce(Return(QuicConsumedData(0, false))); | 352 .WillOnce(Return(QuicConsumedData(0, false))); |
| 355 TestCompletionCallback callback; | 353 TestCompletionCallback callback; |
| 356 EXPECT_EQ(ERR_IO_PENDING, | 354 EXPECT_EQ(ERR_IO_PENDING, |
| 357 stream_->WriteStreamData(base::StringPiece(kData1, kDataLen), true, | 355 stream_->WriteStreamData(base::StringPiece(kData1, kDataLen), true, |
| 358 callback.callback())); | 356 callback.callback())); |
| 359 ASSERT_FALSE(callback.have_result()); | 357 ASSERT_FALSE(callback.have_result()); |
| 360 | 358 |
| 361 // All data written. | 359 // All data written. |
| 362 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _, _)) | 360 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _)) |
| 363 .WillOnce(Return(QuicConsumedData(kDataLen, true))); | 361 .WillOnce(Return(QuicConsumedData(kDataLen, true))); |
| 364 stream_->OnCanWrite(); | 362 stream_->OnCanWrite(); |
| 365 ASSERT_TRUE(callback.have_result()); | 363 ASSERT_TRUE(callback.have_result()); |
| 366 EXPECT_EQ(OK, callback.WaitForResult()); | 364 EXPECT_EQ(OK, callback.WaitForResult()); |
| 367 } | 365 } |
| 368 | 366 |
| 369 TEST_P(QuicChromiumClientStreamTest, HeadersBeforeDelegate) { | 367 TEST_P(QuicChromiumClientStreamTest, HeadersBeforeDelegate) { |
| 370 // We don't use stream_ because we want an incoming server push | 368 // We don't use stream_ because we want an incoming server push |
| 371 // stream. | 369 // stream. |
| 372 QuicChromiumClientStream* stream = new QuicChromiumClientStream( | 370 QuicChromiumClientStream* stream = new QuicChromiumClientStream( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 385 stream->SetDelegate(&delegate_); | 383 stream->SetDelegate(&delegate_); |
| 386 base::MessageLoop::current()->RunUntilIdle(); | 384 base::MessageLoop::current()->RunUntilIdle(); |
| 387 | 385 |
| 388 // Times(2) because OnClose will be called for stream and stream_. | 386 // Times(2) because OnClose will be called for stream and stream_. |
| 389 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)).Times(2); | 387 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)).Times(2); |
| 390 } | 388 } |
| 391 | 389 |
| 392 } // namespace | 390 } // namespace |
| 393 } // namespace test | 391 } // namespace test |
| 394 } // namespace net | 392 } // namespace net |
| OLD | NEW |