| 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 11 matching lines...) Expand all Loading... |
| 22 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" | 22 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" |
| 23 #include "net/quic/test_tools/quic_session_peer.h" | 23 #include "net/quic/test_tools/quic_session_peer.h" |
| 24 #include "net/quic/test_tools/quic_spdy_session_peer.h" | 24 #include "net/quic/test_tools/quic_spdy_session_peer.h" |
| 25 #include "net/quic/test_tools/quic_spdy_stream_peer.h" | 25 #include "net/quic/test_tools/quic_spdy_stream_peer.h" |
| 26 #include "net/quic/test_tools/quic_stream_peer.h" | 26 #include "net/quic/test_tools/quic_stream_peer.h" |
| 27 #include "net/quic/test_tools/quic_sustained_bandwidth_recorder_peer.h" | 27 #include "net/quic/test_tools/quic_sustained_bandwidth_recorder_peer.h" |
| 28 #include "net/quic/test_tools/quic_test_utils.h" | 28 #include "net/quic/test_tools/quic_test_utils.h" |
| 29 #include "net/test/gtest_util.h" | 29 #include "net/test/gtest_util.h" |
| 30 #include "net/tools/quic/quic_simple_server_stream.h" | 30 #include "net/tools/quic/quic_simple_server_stream.h" |
| 31 #include "net/tools/quic/test_tools/mock_quic_server_session_visitor.h" | 31 #include "net/tools/quic/test_tools/mock_quic_server_session_visitor.h" |
| 32 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" | |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 35 | 34 |
| 36 using net::test::CryptoTestUtils; | 35 using net::test::CryptoTestUtils; |
| 37 using net::test::GenerateBody; | 36 using net::test::GenerateBody; |
| 38 using net::test::MockQuicConnection; | 37 using net::test::MockQuicConnection; |
| 39 using net::test::MockQuicConnectionHelper; | 38 using net::test::MockQuicConnectionHelper; |
| 40 using net::test::QuicConfigPeer; | 39 using net::test::QuicConfigPeer; |
| 41 using net::test::QuicConnectionPeer; | 40 using net::test::QuicConnectionPeer; |
| 42 using net::test::QuicSpdyStreamPeer; | 41 using net::test::QuicSpdyStreamPeer; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 QuicConfigPeer::SetReceivedMaxIncomingDynamicStreams(&config_, | 187 QuicConfigPeer::SetReceivedMaxIncomingDynamicStreams(&config_, |
| 189 kMaxStreamsForTest); | 188 kMaxStreamsForTest); |
| 190 config_.SetInitialStreamFlowControlWindowToSend( | 189 config_.SetInitialStreamFlowControlWindowToSend( |
| 191 kInitialStreamFlowControlWindowForTest); | 190 kInitialStreamFlowControlWindowForTest); |
| 192 config_.SetInitialSessionFlowControlWindowToSend( | 191 config_.SetInitialSessionFlowControlWindowToSend( |
| 193 kInitialSessionFlowControlWindowForTest); | 192 kInitialSessionFlowControlWindowForTest); |
| 194 | 193 |
| 195 connection_ = new StrictMock<MockQuicConnectionWithSendStreamData>( | 194 connection_ = new StrictMock<MockQuicConnectionWithSendStreamData>( |
| 196 &helper_, &alarm_factory_, Perspective::IS_SERVER, | 195 &helper_, &alarm_factory_, Perspective::IS_SERVER, |
| 197 SupportedVersions(GetParam())); | 196 SupportedVersions(GetParam())); |
| 198 session_.reset(new QuicSimpleServerSession(config_, connection_, &owner_, | 197 session_.reset(new QuicSimpleServerSession( |
| 199 &stream_helper_, &crypto_config_, | 198 config_, connection_, &owner_, &stream_helper_, &crypto_config_, |
| 200 &compressed_certs_cache_)); | 199 &compressed_certs_cache_, &in_memory_cache_)); |
| 201 MockClock clock; | 200 MockClock clock; |
| 202 handshake_message_.reset(crypto_config_.AddDefaultConfig( | 201 handshake_message_.reset(crypto_config_.AddDefaultConfig( |
| 203 QuicRandom::GetInstance(), &clock, | 202 QuicRandom::GetInstance(), &clock, |
| 204 QuicCryptoServerConfig::ConfigOptions())); | 203 QuicCryptoServerConfig::ConfigOptions())); |
| 205 session_->Initialize(); | 204 session_->Initialize(); |
| 206 visitor_ = QuicConnectionPeer::GetVisitor(connection_); | 205 visitor_ = QuicConnectionPeer::GetVisitor(connection_); |
| 207 headers_stream_ = new MockQuicHeadersStream(session_.get()); | 206 headers_stream_ = new MockQuicHeadersStream(session_.get()); |
| 208 QuicSpdySessionPeer::SetHeadersStream(session_.get(), headers_stream_); | 207 QuicSpdySessionPeer::SetHeadersStream(session_.get(), headers_stream_); |
| 209 | 208 |
| 210 session_->OnConfigNegotiated(); | 209 session_->OnConfigNegotiated(); |
| 211 } | 210 } |
| 212 | 211 |
| 213 StrictMock<MockQuicSessionVisitor> owner_; | 212 StrictMock<MockQuicSessionVisitor> owner_; |
| 214 StrictMock<MockQuicCryptoServerStreamHelper> stream_helper_; | 213 StrictMock<MockQuicCryptoServerStreamHelper> stream_helper_; |
| 215 MockQuicConnectionHelper helper_; | 214 MockQuicConnectionHelper helper_; |
| 216 MockAlarmFactory alarm_factory_; | 215 MockAlarmFactory alarm_factory_; |
| 217 StrictMock<MockQuicConnectionWithSendStreamData>* connection_; | 216 StrictMock<MockQuicConnectionWithSendStreamData>* connection_; |
| 218 QuicConfig config_; | 217 QuicConfig config_; |
| 219 QuicCryptoServerConfig crypto_config_; | 218 QuicCryptoServerConfig crypto_config_; |
| 220 QuicCompressedCertsCache compressed_certs_cache_; | 219 QuicCompressedCertsCache compressed_certs_cache_; |
| 220 QuicInMemoryCache in_memory_cache_; |
| 221 std::unique_ptr<QuicSimpleServerSession> session_; | 221 std::unique_ptr<QuicSimpleServerSession> session_; |
| 222 std::unique_ptr<CryptoHandshakeMessage> handshake_message_; | 222 std::unique_ptr<CryptoHandshakeMessage> handshake_message_; |
| 223 QuicConnectionVisitorInterface* visitor_; | 223 QuicConnectionVisitorInterface* visitor_; |
| 224 MockQuicHeadersStream* headers_stream_; | 224 MockQuicHeadersStream* headers_stream_; |
| 225 }; | 225 }; |
| 226 | 226 |
| 227 INSTANTIATE_TEST_CASE_P(Tests, | 227 INSTANTIATE_TEST_CASE_P(Tests, |
| 228 QuicSimpleServerSessionTest, | 228 QuicSimpleServerSessionTest, |
| 229 ::testing::ValuesIn(AllSupportedVersions())); | 229 ::testing::ValuesIn(AllSupportedVersions())); |
| 230 | 230 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow( | 427 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow( |
| 428 &config_, kInitialSessionFlowControlWindowForTest); | 428 &config_, kInitialSessionFlowControlWindowForTest); |
| 429 // Enable server push. | 429 // Enable server push. |
| 430 QuicTagVector copt; | 430 QuicTagVector copt; |
| 431 copt.push_back(kSPSH); | 431 copt.push_back(kSPSH); |
| 432 QuicConfigPeer::SetReceivedConnectionOptions(&config_, copt); | 432 QuicConfigPeer::SetReceivedConnectionOptions(&config_, copt); |
| 433 | 433 |
| 434 connection_ = new StrictMock<MockQuicConnectionWithSendStreamData>( | 434 connection_ = new StrictMock<MockQuicConnectionWithSendStreamData>( |
| 435 &helper_, &alarm_factory_, Perspective::IS_SERVER, | 435 &helper_, &alarm_factory_, Perspective::IS_SERVER, |
| 436 SupportedVersions(GetParam())); | 436 SupportedVersions(GetParam())); |
| 437 session_.reset(new QuicSimpleServerSession(config_, connection_, &owner_, | 437 session_.reset(new QuicSimpleServerSession( |
| 438 &stream_helper_, &crypto_config_, | 438 config_, connection_, &owner_, &stream_helper_, &crypto_config_, |
| 439 &compressed_certs_cache_)); | 439 &compressed_certs_cache_, &in_memory_cache_)); |
| 440 session_->Initialize(); | 440 session_->Initialize(); |
| 441 // Needed to make new session flow control window and server push work. | 441 // Needed to make new session flow control window and server push work. |
| 442 session_->OnConfigNegotiated(); | 442 session_->OnConfigNegotiated(); |
| 443 | 443 |
| 444 visitor_ = QuicConnectionPeer::GetVisitor(connection_); | 444 visitor_ = QuicConnectionPeer::GetVisitor(connection_); |
| 445 headers_stream_ = new MockQuicHeadersStream(session_.get()); | 445 headers_stream_ = new MockQuicHeadersStream(session_.get()); |
| 446 QuicSpdySessionPeer::SetHeadersStream(session_.get(), headers_stream_); | 446 QuicSpdySessionPeer::SetHeadersStream(session_.get(), headers_stream_); |
| 447 | 447 |
| 448 // Assume encryption already established. | 448 // Assume encryption already established. |
| 449 MockQuicCryptoServerStream* crypto_stream = new MockQuicCryptoServerStream( | 449 MockQuicCryptoServerStream* crypto_stream = new MockQuicCryptoServerStream( |
| 450 &crypto_config_, &compressed_certs_cache_, session_.get(), | 450 &crypto_config_, &compressed_certs_cache_, session_.get(), |
| 451 &stream_helper_); | 451 &stream_helper_); |
| 452 | 452 |
| 453 crypto_stream->set_encryption_established(true); | 453 crypto_stream->set_encryption_established(true); |
| 454 QuicSimpleServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream); | 454 QuicSimpleServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream); |
| 455 } | 455 } |
| 456 | 456 |
| 457 // Given |num_resources|, create this number of fake push resources and push | 457 // Given |num_resources|, create this number of fake push resources and push |
| 458 // them by sending PUSH_PROMISE for all and sending push responses for as much | 458 // them by sending PUSH_PROMISE for all and sending push responses for as much |
| 459 // as possible(limited by kMaxStreamsForTest). | 459 // as possible(limited by kMaxStreamsForTest). |
| 460 // If |num_resources| > kMaxStreamsForTest, the left over will be queued. | 460 // If |num_resources| > kMaxStreamsForTest, the left over will be queued. |
| 461 void PromisePushResources(size_t num_resources) { | 461 void PromisePushResources(size_t num_resources) { |
| 462 // To prevent push streams from being closed the response need to be larger | 462 // To prevent push streams from being closed the response need to be larger |
| 463 // than stream flow control window so stream won't send the full body. | 463 // than stream flow control window so stream won't send the full body. |
| 464 size_t body_size = 2 * kStreamFlowControlWindowSize; // 64KB. | 464 size_t body_size = 2 * kStreamFlowControlWindowSize; // 64KB. |
| 465 | 465 |
| 466 config_.SetMaxStreamsPerConnection(kMaxStreamsForTest, kMaxStreamsForTest); | 466 config_.SetMaxStreamsPerConnection(kMaxStreamsForTest, kMaxStreamsForTest); |
| 467 | 467 |
| 468 QuicInMemoryCachePeer::ResetForTests(); | |
| 469 | |
| 470 string request_url = "mail.google.com/"; | 468 string request_url = "mail.google.com/"; |
| 471 SpdyHeaderBlock request_headers; | 469 SpdyHeaderBlock request_headers; |
| 472 string resource_host = "www.google.com"; | 470 string resource_host = "www.google.com"; |
| 473 string partial_push_resource_path = "/server_push_src"; | 471 string partial_push_resource_path = "/server_push_src"; |
| 474 std::list<QuicInMemoryCache::ServerPushInfo> push_resources; | 472 std::list<QuicInMemoryCache::ServerPushInfo> push_resources; |
| 475 string scheme = "http"; | 473 string scheme = "http"; |
| 476 for (unsigned int i = 1; i <= num_resources; ++i) { | 474 for (unsigned int i = 1; i <= num_resources; ++i) { |
| 477 QuicStreamId stream_id = i * 2; | 475 QuicStreamId stream_id = i * 2; |
| 478 string path = partial_push_resource_path + base::UintToString(i); | 476 string path = partial_push_resource_path + base::UintToString(i); |
| 479 string url = scheme + "://" + resource_host + path; | 477 string url = scheme + "://" + resource_host + path; |
| 480 GURL resource_url = GURL(url); | 478 GURL resource_url = GURL(url); |
| 481 string body; | 479 string body; |
| 482 GenerateBody(&body, body_size); | 480 GenerateBody(&body, body_size); |
| 483 QuicInMemoryCache::GetInstance()->AddSimpleResponse(resource_host, path, | 481 in_memory_cache_.AddSimpleResponse(resource_host, path, 200, body); |
| 484 200, body); | |
| 485 push_resources.push_back(QuicInMemoryCache::ServerPushInfo( | 482 push_resources.push_back(QuicInMemoryCache::ServerPushInfo( |
| 486 resource_url, SpdyHeaderBlock(), kDefaultPriority, body)); | 483 resource_url, SpdyHeaderBlock(), kDefaultPriority, body)); |
| 487 // PUSH_PROMISED are sent for all the resources. | 484 // PUSH_PROMISED are sent for all the resources. |
| 488 EXPECT_CALL(*headers_stream_, | 485 EXPECT_CALL(*headers_stream_, |
| 489 WritePushPromiseMock(kClientDataStreamId1, stream_id, _)); | 486 WritePushPromiseMock(kClientDataStreamId1, stream_id, _)); |
| 490 if (i <= kMaxStreamsForTest) { | 487 if (i <= kMaxStreamsForTest) { |
| 491 // |kMaxStreamsForTest| promised responses should be sent. | 488 // |kMaxStreamsForTest| promised responses should be sent. |
| 492 EXPECT_CALL( | 489 EXPECT_CALL( |
| 493 *headers_stream_, | 490 *headers_stream_, |
| 494 WriteHeadersMock(stream_id, _, false, kDefaultPriority, nullptr)); | 491 WriteHeadersMock(stream_id, _, false, kDefaultPriority, nullptr)); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 623 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
| 627 | 624 |
| 628 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); | 625 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); |
| 629 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); | 626 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); |
| 630 visitor_->OnRstStream(rst); | 627 visitor_->OnRstStream(rst); |
| 631 } | 628 } |
| 632 | 629 |
| 633 } // namespace | 630 } // namespace |
| 634 } // namespace test | 631 } // namespace test |
| 635 } // namespace net | 632 } // namespace net |
| OLD | NEW |