| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/tools/quic/quic_simple_server_session.h" | 5 #include "net/tools/quic/quic_simple_server_session.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "net/quic/test_tools/quic_test_utils.h" | 26 #include "net/quic/test_tools/quic_test_utils.h" |
| 27 #include "net/test/gtest_util.h" | 27 #include "net/test/gtest_util.h" |
| 28 #include "net/tools/quic/quic_simple_server_stream.h" | 28 #include "net/tools/quic/quic_simple_server_stream.h" |
| 29 #include "net/tools/quic/test_tools/mock_quic_server_session_visitor.h" | 29 #include "net/tools/quic/test_tools/mock_quic_server_session_visitor.h" |
| 30 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" | 30 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" |
| 31 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 33 | 33 |
| 34 using net::test::CryptoTestUtils; | 34 using net::test::CryptoTestUtils; |
| 35 using net::test::GenerateBody; | 35 using net::test::GenerateBody; |
| 36 using net::test::MockConnection; | 36 using net::test::MockQuicConnection; |
| 37 using net::test::MockConnectionHelper; | 37 using net::test::MockQuicConnectionHelper; |
| 38 using net::test::QuicConfigPeer; | 38 using net::test::QuicConfigPeer; |
| 39 using net::test::QuicConnectionPeer; | 39 using net::test::QuicConnectionPeer; |
| 40 using net::test::QuicSpdyStreamPeer; | 40 using net::test::QuicSpdyStreamPeer; |
| 41 using net::test::QuicSentPacketManagerPeer; | 41 using net::test::QuicSentPacketManagerPeer; |
| 42 using net::test::QuicSessionPeer; | 42 using net::test::QuicSessionPeer; |
| 43 using net::test::QuicSpdySessionPeer; | 43 using net::test::QuicSpdySessionPeer; |
| 44 using net::test::QuicSustainedBandwidthRecorderPeer; | 44 using net::test::QuicSustainedBandwidthRecorderPeer; |
| 45 using net::test::SupportedVersions; | 45 using net::test::SupportedVersions; |
| 46 using net::test::ValueRestore; | 46 using net::test::ValueRestore; |
| 47 using net::test::kClientDataStreamId1; | 47 using net::test::kClientDataStreamId1; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 void(const CachedNetworkParameters* cached_network_parameters)); | 96 void(const CachedNetworkParameters* cached_network_parameters)); |
| 97 | 97 |
| 98 void set_encryption_established(bool has_established) { | 98 void set_encryption_established(bool has_established) { |
| 99 encryption_established_ = has_established; | 99 encryption_established_ = has_established; |
| 100 } | 100 } |
| 101 | 101 |
| 102 private: | 102 private: |
| 103 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoServerStream); | 103 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoServerStream); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 class MockConnectionWithSendStreamData : public MockConnection { | 106 class MockQuicConnectionWithSendStreamData : public MockQuicConnection { |
| 107 public: | 107 public: |
| 108 MockConnectionWithSendStreamData(MockConnectionHelper* helper, | 108 MockQuicConnectionWithSendStreamData( |
| 109 MockAlarmFactory* alarm_factory, | 109 MockQuicConnectionHelper* helper, |
| 110 Perspective perspective, | 110 MockAlarmFactory* alarm_factory, |
| 111 const QuicVersionVector& supported_versions) | 111 Perspective perspective, |
| 112 : MockConnection(helper, alarm_factory, perspective, supported_versions) { | 112 const QuicVersionVector& supported_versions) |
| 113 } | 113 : MockQuicConnection(helper, |
| 114 alarm_factory, |
| 115 perspective, |
| 116 supported_versions) {} |
| 114 | 117 |
| 115 MOCK_METHOD5(SendStreamData, | 118 MOCK_METHOD5(SendStreamData, |
| 116 QuicConsumedData(QuicStreamId id, | 119 QuicConsumedData(QuicStreamId id, |
| 117 QuicIOVector iov, | 120 QuicIOVector iov, |
| 118 QuicStreamOffset offset, | 121 QuicStreamOffset offset, |
| 119 bool fin, | 122 bool fin, |
| 120 QuicAckListenerInterface* listern)); | 123 QuicAckListenerInterface* listern)); |
| 121 }; | 124 }; |
| 122 | 125 |
| 123 class QuicSimpleServerSessionPeer { | 126 class QuicSimpleServerSessionPeer { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 CryptoTestUtils::ProofSourceForTesting()), | 165 CryptoTestUtils::ProofSourceForTesting()), |
| 163 compressed_certs_cache_( | 166 compressed_certs_cache_( |
| 164 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize) { | 167 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize) { |
| 165 FLAGS_quic_always_log_bugs_for_tests = true; | 168 FLAGS_quic_always_log_bugs_for_tests = true; |
| 166 config_.SetMaxStreamsPerConnection(kMaxStreamsForTest, kMaxStreamsForTest); | 169 config_.SetMaxStreamsPerConnection(kMaxStreamsForTest, kMaxStreamsForTest); |
| 167 config_.SetInitialStreamFlowControlWindowToSend( | 170 config_.SetInitialStreamFlowControlWindowToSend( |
| 168 kInitialStreamFlowControlWindowForTest); | 171 kInitialStreamFlowControlWindowForTest); |
| 169 config_.SetInitialSessionFlowControlWindowToSend( | 172 config_.SetInitialSessionFlowControlWindowToSend( |
| 170 kInitialSessionFlowControlWindowForTest); | 173 kInitialSessionFlowControlWindowForTest); |
| 171 | 174 |
| 172 connection_ = new StrictMock<MockConnectionWithSendStreamData>( | 175 connection_ = new StrictMock<MockQuicConnectionWithSendStreamData>( |
| 173 &helper_, &alarm_factory_, Perspective::IS_SERVER, | 176 &helper_, &alarm_factory_, Perspective::IS_SERVER, |
| 174 SupportedVersions(GetParam())); | 177 SupportedVersions(GetParam())); |
| 175 session_.reset(new QuicSimpleServerSession(config_, connection_, &owner_, | 178 session_.reset(new QuicSimpleServerSession(config_, connection_, &owner_, |
| 176 &crypto_config_, | 179 &crypto_config_, |
| 177 &compressed_certs_cache_)); | 180 &compressed_certs_cache_)); |
| 178 MockClock clock; | 181 MockClock clock; |
| 179 handshake_message_.reset(crypto_config_.AddDefaultConfig( | 182 handshake_message_.reset(crypto_config_.AddDefaultConfig( |
| 180 QuicRandom::GetInstance(), &clock, | 183 QuicRandom::GetInstance(), &clock, |
| 181 QuicCryptoServerConfig::ConfigOptions())); | 184 QuicCryptoServerConfig::ConfigOptions())); |
| 182 session_->Initialize(); | 185 session_->Initialize(); |
| 183 visitor_ = QuicConnectionPeer::GetVisitor(connection_); | 186 visitor_ = QuicConnectionPeer::GetVisitor(connection_); |
| 184 headers_stream_ = new MockQuicHeadersStream(session_.get()); | 187 headers_stream_ = new MockQuicHeadersStream(session_.get()); |
| 185 QuicSpdySessionPeer::SetHeadersStream(session_.get(), headers_stream_); | 188 QuicSpdySessionPeer::SetHeadersStream(session_.get(), headers_stream_); |
| 186 // TODO(jri): Remove this line once tests pass. | 189 // TODO(jri): Remove this line once tests pass. |
| 187 FLAGS_quic_cede_correctly = false; | 190 FLAGS_quic_cede_correctly = false; |
| 188 } | 191 } |
| 189 | 192 |
| 190 StrictMock<MockQuicServerSessionVisitor> owner_; | 193 StrictMock<MockQuicServerSessionVisitor> owner_; |
| 191 MockConnectionHelper helper_; | 194 MockQuicConnectionHelper helper_; |
| 192 MockAlarmFactory alarm_factory_; | 195 MockAlarmFactory alarm_factory_; |
| 193 StrictMock<MockConnectionWithSendStreamData>* connection_; | 196 StrictMock<MockQuicConnectionWithSendStreamData>* connection_; |
| 194 QuicConfig config_; | 197 QuicConfig config_; |
| 195 QuicCryptoServerConfig crypto_config_; | 198 QuicCryptoServerConfig crypto_config_; |
| 196 QuicCompressedCertsCache compressed_certs_cache_; | 199 QuicCompressedCertsCache compressed_certs_cache_; |
| 197 std::unique_ptr<QuicSimpleServerSession> session_; | 200 std::unique_ptr<QuicSimpleServerSession> session_; |
| 198 std::unique_ptr<CryptoHandshakeMessage> handshake_message_; | 201 std::unique_ptr<CryptoHandshakeMessage> handshake_message_; |
| 199 QuicConnectionVisitorInterface* visitor_; | 202 QuicConnectionVisitorInterface* visitor_; |
| 200 MockQuicHeadersStream* headers_stream_; | 203 MockQuicHeadersStream* headers_stream_; |
| 201 }; | 204 }; |
| 202 | 205 |
| 203 INSTANTIATE_TEST_CASE_P(Tests, | 206 INSTANTIATE_TEST_CASE_P(Tests, |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 // Reset connection level flow control window to be 1.5 MB which is large | 402 // Reset connection level flow control window to be 1.5 MB which is large |
| 400 // enough that it won't block any stream to write before stream level flow | 403 // enough that it won't block any stream to write before stream level flow |
| 401 // control blocks it. | 404 // control blocks it. |
| 402 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow( | 405 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow( |
| 403 &config_, kInitialSessionFlowControlWindowForTest); | 406 &config_, kInitialSessionFlowControlWindowForTest); |
| 404 // Enable server push. | 407 // Enable server push. |
| 405 QuicTagVector copt; | 408 QuicTagVector copt; |
| 406 copt.push_back(kSPSH); | 409 copt.push_back(kSPSH); |
| 407 QuicConfigPeer::SetReceivedConnectionOptions(&config_, copt); | 410 QuicConfigPeer::SetReceivedConnectionOptions(&config_, copt); |
| 408 | 411 |
| 409 connection_ = new StrictMock<MockConnectionWithSendStreamData>( | 412 connection_ = new StrictMock<MockQuicConnectionWithSendStreamData>( |
| 410 &helper_, &alarm_factory_, Perspective::IS_SERVER, | 413 &helper_, &alarm_factory_, Perspective::IS_SERVER, |
| 411 SupportedVersions(GetParam())); | 414 SupportedVersions(GetParam())); |
| 412 session_.reset(new QuicSimpleServerSession(config_, connection_, &owner_, | 415 session_.reset(new QuicSimpleServerSession(config_, connection_, &owner_, |
| 413 &crypto_config_, | 416 &crypto_config_, |
| 414 &compressed_certs_cache_)); | 417 &compressed_certs_cache_)); |
| 415 session_->Initialize(); | 418 session_->Initialize(); |
| 416 // Needed to make new session flow control window and server push work. | 419 // Needed to make new session flow control window and server push work. |
| 417 session_->OnConfigNegotiated(); | 420 session_->OnConfigNegotiated(); |
| 418 | 421 |
| 419 visitor_ = QuicConnectionPeer::GetVisitor(connection_); | 422 visitor_ = QuicConnectionPeer::GetVisitor(connection_); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 573 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
| 571 | 574 |
| 572 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); | 575 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); |
| 573 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); | 576 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); |
| 574 visitor_->OnRstStream(rst); | 577 visitor_->OnRstStream(rst); |
| 575 } | 578 } |
| 576 | 579 |
| 577 } // namespace | 580 } // namespace |
| 578 } // namespace test | 581 } // namespace test |
| 579 } // namespace net | 582 } // namespace net |
| OLD | NEW |