| 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_server.h" |    5 #include "net/tools/quic/quic_server.h" | 
|    6  |    6  | 
|    7 #include "net/quic/core/crypto/quic_random.h" |    7 #include "net/quic/core/crypto/quic_random.h" | 
|    8 #include "net/quic/core/quic_utils.h" |    8 #include "net/quic/core/quic_utils.h" | 
|    9 #include "net/quic/platform/api/quic_socket_address.h" |    9 #include "net/quic/platform/api/quic_socket_address.h" | 
|   10 #include "net/quic/test_tools/crypto_test_utils.h" |   10 #include "net/quic/test_tools/crypto_test_utils.h" | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|   25 namespace { |   25 namespace { | 
|   26  |   26  | 
|   27 class MockQuicSimpleDispatcher : public QuicSimpleDispatcher { |   27 class MockQuicSimpleDispatcher : public QuicSimpleDispatcher { | 
|   28  public: |   28  public: | 
|   29   MockQuicSimpleDispatcher( |   29   MockQuicSimpleDispatcher( | 
|   30       const QuicConfig& config, |   30       const QuicConfig& config, | 
|   31       const QuicCryptoServerConfig* crypto_config, |   31       const QuicCryptoServerConfig* crypto_config, | 
|   32       QuicVersionManager* version_manager, |   32       QuicVersionManager* version_manager, | 
|   33       std::unique_ptr<QuicConnectionHelperInterface> helper, |   33       std::unique_ptr<QuicConnectionHelperInterface> helper, | 
|   34       std::unique_ptr<QuicCryptoServerStream::Helper> session_helper, |   34       std::unique_ptr<QuicCryptoServerStream::Helper> session_helper, | 
|   35       std::unique_ptr<QuicAlarmFactory> alarm_factory) |   35       std::unique_ptr<QuicAlarmFactory> alarm_factory, | 
 |   36       QuicInMemoryCache* in_memory_cache) | 
|   36       : QuicSimpleDispatcher(config, |   37       : QuicSimpleDispatcher(config, | 
|   37                              crypto_config, |   38                              crypto_config, | 
|   38                              version_manager, |   39                              version_manager, | 
|   39                              std::move(helper), |   40                              std::move(helper), | 
|   40                              std::move(session_helper), |   41                              std::move(session_helper), | 
|   41                              std::move(alarm_factory)) {} |   42                              std::move(alarm_factory), | 
 |   43                              in_memory_cache) {} | 
|   42   ~MockQuicSimpleDispatcher() override {} |   44   ~MockQuicSimpleDispatcher() override {} | 
|   43  |   45  | 
|   44   MOCK_METHOD0(OnCanWrite, void()); |   46   MOCK_METHOD0(OnCanWrite, void()); | 
|   45   MOCK_CONST_METHOD0(HasPendingWrites, bool()); |   47   MOCK_CONST_METHOD0(HasPendingWrites, bool()); | 
|   46   MOCK_CONST_METHOD0(HasChlosBuffered, bool()); |   48   MOCK_CONST_METHOD0(HasChlosBuffered, bool()); | 
|   47   MOCK_METHOD1(ProcessBufferedChlos, void(size_t)); |   49   MOCK_METHOD1(ProcessBufferedChlos, void(size_t)); | 
|   48 }; |   50 }; | 
|   49  |   51  | 
|   50 class TestQuicServer : public QuicServer { |   52 class TestQuicServer : public QuicServer { | 
|   51  public: |   53  public: | 
|   52   TestQuicServer() : QuicServer(CryptoTestUtils::ProofSourceForTesting()) {} |   54   TestQuicServer() | 
 |   55       : QuicServer(CryptoTestUtils::ProofSourceForTesting(), | 
 |   56                    &in_memory_cache_) {} | 
|   53  |   57  | 
|   54   ~TestQuicServer() override {} |   58   ~TestQuicServer() override {} | 
|   55  |   59  | 
|   56   MockQuicSimpleDispatcher* mock_dispatcher() { return mock_dispatcher_; } |   60   MockQuicSimpleDispatcher* mock_dispatcher() { return mock_dispatcher_; } | 
|   57  |   61  | 
|   58  protected: |   62  protected: | 
|   59   QuicDispatcher* CreateQuicDispatcher() override { |   63   QuicDispatcher* CreateQuicDispatcher() override { | 
|   60     mock_dispatcher_ = new MockQuicSimpleDispatcher( |   64     mock_dispatcher_ = new MockQuicSimpleDispatcher( | 
|   61         config(), &crypto_config(), version_manager(), |   65         config(), &crypto_config(), version_manager(), | 
|   62         std::unique_ptr<QuicEpollConnectionHelper>( |   66         std::unique_ptr<QuicEpollConnectionHelper>( | 
|   63             new QuicEpollConnectionHelper(epoll_server(), |   67             new QuicEpollConnectionHelper(epoll_server(), | 
|   64                                           QuicAllocator::BUFFER_POOL)), |   68                                           QuicAllocator::BUFFER_POOL)), | 
|   65         std::unique_ptr<QuicCryptoServerStream::Helper>( |   69         std::unique_ptr<QuicCryptoServerStream::Helper>( | 
|   66             new QuicSimpleCryptoServerStreamHelper(QuicRandom::GetInstance())), |   70             new QuicSimpleCryptoServerStreamHelper(QuicRandom::GetInstance())), | 
|   67         std::unique_ptr<QuicEpollAlarmFactory>( |   71         std::unique_ptr<QuicEpollAlarmFactory>( | 
|   68             new QuicEpollAlarmFactory(epoll_server()))); |   72             new QuicEpollAlarmFactory(epoll_server())), | 
 |   73         &in_memory_cache_); | 
|   69     return mock_dispatcher_; |   74     return mock_dispatcher_; | 
|   70   } |   75   } | 
|   71  |   76  | 
|   72   MockQuicSimpleDispatcher* mock_dispatcher_; |   77   MockQuicSimpleDispatcher* mock_dispatcher_; | 
 |   78   QuicInMemoryCache in_memory_cache_; | 
|   73 }; |   79 }; | 
|   74  |   80  | 
|   75 class QuicServerEpollInTest : public ::testing::Test { |   81 class QuicServerEpollInTest : public ::testing::Test { | 
|   76  public: |   82  public: | 
|   77   QuicServerEpollInTest() |   83   QuicServerEpollInTest() | 
|   78       : port_(net::test::kTestPort), |   84       : port_(net::test::kTestPort), | 
|   79         server_address_(QuicIpAddress::Loopback4(), port_) {} |   85         server_address_(QuicIpAddress::Loopback4(), port_) {} | 
|   80  |   86  | 
|   81   void StartListening() { |   87   void StartListening() { | 
|   82     server_.CreateUDPSocketAndListen(server_address_); |   88     server_.CreateUDPSocketAndListen(server_address_); | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  148             config_, |  154             config_, | 
|  149             &crypto_config_, |  155             &crypto_config_, | 
|  150             &version_manager_, |  156             &version_manager_, | 
|  151             std::unique_ptr<QuicEpollConnectionHelper>( |  157             std::unique_ptr<QuicEpollConnectionHelper>( | 
|  152                 new QuicEpollConnectionHelper(&eps_, |  158                 new QuicEpollConnectionHelper(&eps_, | 
|  153                                               QuicAllocator::BUFFER_POOL)), |  159                                               QuicAllocator::BUFFER_POOL)), | 
|  154             std::unique_ptr<QuicCryptoServerStream::Helper>( |  160             std::unique_ptr<QuicCryptoServerStream::Helper>( | 
|  155                 new QuicSimpleCryptoServerStreamHelper( |  161                 new QuicSimpleCryptoServerStreamHelper( | 
|  156                     QuicRandom::GetInstance())), |  162                     QuicRandom::GetInstance())), | 
|  157             std::unique_ptr<QuicEpollAlarmFactory>( |  163             std::unique_ptr<QuicEpollAlarmFactory>( | 
|  158                 new QuicEpollAlarmFactory(&eps_))) { |  164                 new QuicEpollAlarmFactory(&eps_)), | 
 |  165             &in_memory_cache_) { | 
|  159     dispatcher_.InitializeWithWriter(new QuicDefaultPacketWriter(1234)); |  166     dispatcher_.InitializeWithWriter(new QuicDefaultPacketWriter(1234)); | 
|  160   } |  167   } | 
|  161  |  168  | 
|  162   void DispatchPacket(const QuicReceivedPacket& packet) { |  169   void DispatchPacket(const QuicReceivedPacket& packet) { | 
|  163     QuicSocketAddress client_addr, server_addr; |  170     QuicSocketAddress client_addr, server_addr; | 
|  164     dispatcher_.ProcessPacket(server_addr, client_addr, packet); |  171     dispatcher_.ProcessPacket(server_addr, client_addr, packet); | 
|  165   } |  172   } | 
|  166  |  173  | 
|  167  protected: |  174  protected: | 
|  168   QuicConfig config_; |  175   QuicConfig config_; | 
|  169   QuicCryptoServerConfig crypto_config_; |  176   QuicCryptoServerConfig crypto_config_; | 
|  170   QuicVersionManager version_manager_; |  177   QuicVersionManager version_manager_; | 
|  171   EpollServer eps_; |  178   EpollServer eps_; | 
 |  179   QuicInMemoryCache in_memory_cache_; | 
|  172   MockQuicDispatcher dispatcher_; |  180   MockQuicDispatcher dispatcher_; | 
|  173 }; |  181 }; | 
|  174  |  182  | 
|  175 TEST_F(QuicServerDispatchPacketTest, DispatchPacket) { |  183 TEST_F(QuicServerDispatchPacketTest, DispatchPacket) { | 
|  176   // clang-format off |  184   // clang-format off | 
|  177   unsigned char valid_packet[] = { |  185   unsigned char valid_packet[] = { | 
|  178     // public flags (8 byte connection_id) |  186     // public flags (8 byte connection_id) | 
|  179     0x3C, |  187     0x3C, | 
|  180     // connection_id |  188     // connection_id | 
|  181     0x10, 0x32, 0x54, 0x76, |  189     0x10, 0x32, 0x54, 0x76, | 
|  182     0x98, 0xBA, 0xDC, 0xFE, |  190     0x98, 0xBA, 0xDC, 0xFE, | 
|  183     // packet number |  191     // packet number | 
|  184     0xBC, 0x9A, 0x78, 0x56, |  192     0xBC, 0x9A, 0x78, 0x56, | 
|  185     0x34, 0x12, |  193     0x34, 0x12, | 
|  186     // private flags |  194     // private flags | 
|  187     0x00 |  195     0x00 | 
|  188   }; |  196   }; | 
|  189   // clang-format on |  197   // clang-format on | 
|  190   QuicReceivedPacket encrypted_valid_packet( |  198   QuicReceivedPacket encrypted_valid_packet( | 
|  191       reinterpret_cast<char*>(valid_packet), arraysize(valid_packet), |  199       reinterpret_cast<char*>(valid_packet), arraysize(valid_packet), | 
|  192       QuicTime::Zero(), false); |  200       QuicTime::Zero(), false); | 
|  193  |  201  | 
|  194   EXPECT_CALL(dispatcher_, ProcessPacket(_, _, _)).Times(1); |  202   EXPECT_CALL(dispatcher_, ProcessPacket(_, _, _)).Times(1); | 
|  195   DispatchPacket(encrypted_valid_packet); |  203   DispatchPacket(encrypted_valid_packet); | 
|  196 } |  204 } | 
|  197  |  205  | 
|  198 }  // namespace |  206 }  // namespace | 
|  199 }  // namespace test |  207 }  // namespace test | 
|  200 }  // namespace net |  208 }  // namespace net | 
| OLD | NEW |