| 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/tools/quic/quic_dispatcher.h" | 5 #include "net/tools/quic/quic_dispatcher.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
| 10 #include "net/quic/crypto/crypto_handshake.h" | 10 #include "net/quic/crypto/crypto_handshake.h" |
| 11 #include "net/quic/crypto/quic_crypto_server_config.h" | 11 #include "net/quic/crypto/quic_crypto_server_config.h" |
| 12 #include "net/quic/crypto/quic_random.h" | 12 #include "net/quic/crypto/quic_random.h" |
| 13 #include "net/quic/quic_crypto_stream.h" | 13 #include "net/quic/quic_crypto_stream.h" |
| 14 #include "net/quic/quic_flags.h" | 14 #include "net/quic/quic_flags.h" |
| 15 #include "net/quic/quic_utils.h" | 15 #include "net/quic/quic_utils.h" |
| 16 #include "net/quic/test_tools/quic_test_utils.h" | 16 #include "net/quic/test_tools/quic_test_utils.h" |
| 17 #include "net/tools/epoll_server/epoll_server.h" | 17 #include "net/tools/epoll_server/epoll_server.h" |
| 18 #include "net/tools/quic/quic_packet_writer_wrapper.h" | 18 #include "net/tools/quic/quic_packet_writer_wrapper.h" |
| 19 #include "net/tools/quic/quic_time_wait_list_manager.h" | 19 #include "net/tools/quic/quic_time_wait_list_manager.h" |
| 20 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" | 20 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" |
| 21 #include "net/tools/quic/test_tools/quic_test_utils.h" | 21 #include "net/tools/quic/test_tools/quic_test_utils.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 using base::StringPiece; | 25 using base::StringPiece; |
| 26 using net::EpollServer; | 26 using net::EpollServer; |
| 27 using net::test::ConstructEncryptedPacket; |
| 27 using net::test::MockSession; | 28 using net::test::MockSession; |
| 28 using net::test::ConstructEncryptedPacket; | 29 using net::test::ValueRestore; |
| 29 using net::tools::test::MockConnection; | 30 using net::tools::test::MockConnection; |
| 30 using std::make_pair; | 31 using std::make_pair; |
| 32 using testing::DoAll; |
| 33 using testing::InSequence; |
| 34 using testing::Invoke; |
| 35 using testing::WithoutArgs; |
| 31 using testing::_; | 36 using testing::_; |
| 32 using testing::DoAll; | |
| 33 using testing::Invoke; | |
| 34 using testing::InSequence; | |
| 35 using testing::WithoutArgs; | |
| 36 | 37 |
| 37 namespace net { | 38 namespace net { |
| 38 namespace tools { | 39 namespace tools { |
| 39 namespace test { | 40 namespace test { |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 class TestDispatcher : public QuicDispatcher { | 43 class TestDispatcher : public QuicDispatcher { |
| 43 public: | 44 public: |
| 44 explicit TestDispatcher(const QuicConfig& config, | 45 explicit TestDispatcher(const QuicConfig& config, |
| 45 const QuicCryptoServerConfig& crypto_config, | 46 const QuicCryptoServerConfig& crypto_config, |
| 46 EpollServer* eps) | 47 EpollServer* eps) |
| 47 : QuicDispatcher(config, | 48 : QuicDispatcher(config, |
| 48 crypto_config, | 49 crypto_config, |
| 49 QuicSupportedVersions(), | 50 QuicSupportedVersions(), |
| 50 eps, | 51 eps) { |
| 51 kInitialFlowControlWindowForTest) { | |
| 52 } | 52 } |
| 53 | 53 |
| 54 MOCK_METHOD3(CreateQuicSession, QuicSession*( | 54 MOCK_METHOD3(CreateQuicSession, QuicSession*( |
| 55 QuicConnectionId connection_id, | 55 QuicConnectionId connection_id, |
| 56 const IPEndPoint& server_address, | 56 const IPEndPoint& server_address, |
| 57 const IPEndPoint& client_address)); | 57 const IPEndPoint& client_address)); |
| 58 using QuicDispatcher::write_blocked_list; | 58 using QuicDispatcher::write_blocked_list; |
| 59 | 59 |
| 60 using QuicDispatcher::current_server_address; | 60 using QuicDispatcher::current_server_address; |
| 61 using QuicDispatcher::current_client_address; | 61 using QuicDispatcher::current_client_address; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 QuicConnectionId kCID = 1234; | 276 QuicConnectionId kCID = 1234; |
| 277 | 277 |
| 278 QuicVersion kTestQuicVersions[] = {QUIC_VERSION_17, | 278 QuicVersion kTestQuicVersions[] = {QUIC_VERSION_17, |
| 279 QUIC_VERSION_16, | 279 QUIC_VERSION_16, |
| 280 QUIC_VERSION_15}; | 280 QUIC_VERSION_15}; |
| 281 QuicVersionVector kTestVersions; | 281 QuicVersionVector kTestVersions; |
| 282 for (size_t i = 0; i < arraysize(kTestQuicVersions); ++i) { | 282 for (size_t i = 0; i < arraysize(kTestQuicVersions); ++i) { |
| 283 kTestVersions.push_back(kTestQuicVersions[i]); | 283 kTestVersions.push_back(kTestQuicVersions[i]); |
| 284 } | 284 } |
| 285 | 285 |
| 286 QuicDispatcher dispatcher(config, server_config, kTestVersions, &eps, | 286 QuicDispatcher dispatcher(config, server_config, kTestVersions, &eps); |
| 287 kInitialFlowControlWindowForTest); | |
| 288 dispatcher.Initialize(0); | 287 dispatcher.Initialize(0); |
| 289 | 288 |
| 290 // When flag is enabled, new connections should support QUIC_VERSION_17. | 289 // When flag is enabled, new connections should support QUIC_VERSION_17. |
| 291 FLAGS_enable_quic_stream_flow_control_2 = true; | 290 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control_2, true); |
| 292 scoped_ptr<QuicConnection> connection_1( | 291 scoped_ptr<QuicConnection> connection_1( |
| 293 QuicDispatcherPeer::CreateQuicConnection(&dispatcher, kCID, client, | 292 QuicDispatcherPeer::CreateQuicConnection(&dispatcher, kCID, client, |
| 294 server)); | 293 server)); |
| 295 EXPECT_EQ(QUIC_VERSION_17, connection_1->version()); | 294 EXPECT_EQ(QUIC_VERSION_17, connection_1->version()); |
| 296 | 295 |
| 297 | 296 |
| 298 // When flag is disabled, new connections should not support QUIC_VERSION_17. | 297 // When flag is disabled, new connections should not support QUIC_VERSION_17. |
| 299 FLAGS_enable_quic_stream_flow_control_2 = false; | 298 FLAGS_enable_quic_stream_flow_control_2 = false; |
| 300 scoped_ptr<QuicConnection> connection_2( | 299 scoped_ptr<QuicConnection> connection_2( |
| 301 QuicDispatcherPeer::CreateQuicConnection(&dispatcher, kCID, client, | 300 QuicDispatcherPeer::CreateQuicConnection(&dispatcher, kCID, client, |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 // And we'll resume where we left off when we get another call. | 493 // And we'll resume where we left off when we get another call. |
| 495 EXPECT_CALL(*connection2(), OnCanWrite()); | 494 EXPECT_CALL(*connection2(), OnCanWrite()); |
| 496 dispatcher_.OnCanWrite(); | 495 dispatcher_.OnCanWrite(); |
| 497 EXPECT_FALSE(dispatcher_.HasPendingWrites()); | 496 EXPECT_FALSE(dispatcher_.HasPendingWrites()); |
| 498 } | 497 } |
| 499 | 498 |
| 500 } // namespace | 499 } // namespace |
| 501 } // namespace test | 500 } // namespace test |
| 502 } // namespace tools | 501 } // namespace tools |
| 503 } // namespace net | 502 } // namespace net |
| OLD | NEW |