Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(449)

Side by Side Diff: net/tools/quic/quic_server_test.cc

Issue 2547583002: Landing Recent QUIC changes until Fri Nov 18 23:21:04 2016 +0000 (Closed)
Patch Set: Remove explicit HTTP/2 enum usage Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/tools/quic/quic_server_bin.cc ('k') | net/tools/quic/quic_simple_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
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 QuicHttpResponseCache* response_cache)
37 : QuicSimpleDispatcher(config, 37 : QuicSimpleDispatcher(config,
38 crypto_config, 38 crypto_config,
39 version_manager, 39 version_manager,
40 std::move(helper), 40 std::move(helper),
41 std::move(session_helper), 41 std::move(session_helper),
42 std::move(alarm_factory), 42 std::move(alarm_factory),
43 in_memory_cache) {} 43 response_cache) {}
44 ~MockQuicSimpleDispatcher() override {} 44 ~MockQuicSimpleDispatcher() override {}
45 45
46 MOCK_METHOD0(OnCanWrite, void()); 46 MOCK_METHOD0(OnCanWrite, void());
47 MOCK_CONST_METHOD0(HasPendingWrites, bool()); 47 MOCK_CONST_METHOD0(HasPendingWrites, bool());
48 MOCK_CONST_METHOD0(HasChlosBuffered, bool()); 48 MOCK_CONST_METHOD0(HasChlosBuffered, bool());
49 MOCK_METHOD1(ProcessBufferedChlos, void(size_t)); 49 MOCK_METHOD1(ProcessBufferedChlos, void(size_t));
50 }; 50 };
51 51
52 class TestQuicServer : public QuicServer { 52 class TestQuicServer : public QuicServer {
53 public: 53 public:
54 TestQuicServer() 54 TestQuicServer()
55 : QuicServer(CryptoTestUtils::ProofSourceForTesting(), 55 : QuicServer(CryptoTestUtils::ProofSourceForTesting(), &response_cache_) {
56 &in_memory_cache_) {} 56 }
57 57
58 ~TestQuicServer() override {} 58 ~TestQuicServer() override {}
59 59
60 MockQuicSimpleDispatcher* mock_dispatcher() { return mock_dispatcher_; } 60 MockQuicSimpleDispatcher* mock_dispatcher() { return mock_dispatcher_; }
61 61
62 protected: 62 protected:
63 QuicDispatcher* CreateQuicDispatcher() override { 63 QuicDispatcher* CreateQuicDispatcher() override {
64 mock_dispatcher_ = new MockQuicSimpleDispatcher( 64 mock_dispatcher_ = new MockQuicSimpleDispatcher(
65 config(), &crypto_config(), version_manager(), 65 config(), &crypto_config(), version_manager(),
66 std::unique_ptr<QuicEpollConnectionHelper>( 66 std::unique_ptr<QuicEpollConnectionHelper>(
67 new QuicEpollConnectionHelper(epoll_server(), 67 new QuicEpollConnectionHelper(epoll_server(),
68 QuicAllocator::BUFFER_POOL)), 68 QuicAllocator::BUFFER_POOL)),
69 std::unique_ptr<QuicCryptoServerStream::Helper>( 69 std::unique_ptr<QuicCryptoServerStream::Helper>(
70 new QuicSimpleCryptoServerStreamHelper(QuicRandom::GetInstance())), 70 new QuicSimpleCryptoServerStreamHelper(QuicRandom::GetInstance())),
71 std::unique_ptr<QuicEpollAlarmFactory>( 71 std::unique_ptr<QuicEpollAlarmFactory>(
72 new QuicEpollAlarmFactory(epoll_server())), 72 new QuicEpollAlarmFactory(epoll_server())),
73 &in_memory_cache_); 73 &response_cache_);
74 return mock_dispatcher_; 74 return mock_dispatcher_;
75 } 75 }
76 76
77 MockQuicSimpleDispatcher* mock_dispatcher_; 77 MockQuicSimpleDispatcher* mock_dispatcher_;
78 QuicInMemoryCache in_memory_cache_; 78 QuicHttpResponseCache response_cache_;
79 }; 79 };
80 80
81 class QuicServerEpollInTest : public ::testing::Test { 81 class QuicServerEpollInTest : public ::testing::Test {
82 public: 82 public:
83 QuicServerEpollInTest() 83 QuicServerEpollInTest()
84 : port_(net::test::kTestPort), 84 : port_(net::test::kTestPort),
85 server_address_(QuicIpAddress::Loopback4(), port_) {} 85 server_address_(QuicIpAddress::Loopback4(), port_) {}
86 86
87 void StartListening() { 87 void StartListening() {
88 server_.CreateUDPSocketAndListen(server_address_); 88 server_.CreateUDPSocketAndListen(server_address_);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 &crypto_config_, 155 &crypto_config_,
156 &version_manager_, 156 &version_manager_,
157 std::unique_ptr<QuicEpollConnectionHelper>( 157 std::unique_ptr<QuicEpollConnectionHelper>(
158 new QuicEpollConnectionHelper(&eps_, 158 new QuicEpollConnectionHelper(&eps_,
159 QuicAllocator::BUFFER_POOL)), 159 QuicAllocator::BUFFER_POOL)),
160 std::unique_ptr<QuicCryptoServerStream::Helper>( 160 std::unique_ptr<QuicCryptoServerStream::Helper>(
161 new QuicSimpleCryptoServerStreamHelper( 161 new QuicSimpleCryptoServerStreamHelper(
162 QuicRandom::GetInstance())), 162 QuicRandom::GetInstance())),
163 std::unique_ptr<QuicEpollAlarmFactory>( 163 std::unique_ptr<QuicEpollAlarmFactory>(
164 new QuicEpollAlarmFactory(&eps_)), 164 new QuicEpollAlarmFactory(&eps_)),
165 &in_memory_cache_) { 165 &response_cache_) {
166 dispatcher_.InitializeWithWriter(new QuicDefaultPacketWriter(1234)); 166 dispatcher_.InitializeWithWriter(new QuicDefaultPacketWriter(1234));
167 } 167 }
168 168
169 void DispatchPacket(const QuicReceivedPacket& packet) { 169 void DispatchPacket(const QuicReceivedPacket& packet) {
170 QuicSocketAddress client_addr, server_addr; 170 QuicSocketAddress client_addr, server_addr;
171 dispatcher_.ProcessPacket(server_addr, client_addr, packet); 171 dispatcher_.ProcessPacket(server_addr, client_addr, packet);
172 } 172 }
173 173
174 protected: 174 protected:
175 QuicConfig config_; 175 QuicConfig config_;
176 QuicCryptoServerConfig crypto_config_; 176 QuicCryptoServerConfig crypto_config_;
177 QuicVersionManager version_manager_; 177 QuicVersionManager version_manager_;
178 EpollServer eps_; 178 EpollServer eps_;
179 QuicInMemoryCache in_memory_cache_; 179 QuicHttpResponseCache response_cache_;
180 MockQuicDispatcher dispatcher_; 180 MockQuicDispatcher dispatcher_;
181 }; 181 };
182 182
183 TEST_F(QuicServerDispatchPacketTest, DispatchPacket) { 183 TEST_F(QuicServerDispatchPacketTest, DispatchPacket) {
184 // clang-format off 184 // clang-format off
185 unsigned char valid_packet[] = { 185 unsigned char valid_packet[] = {
186 // public flags (8 byte connection_id) 186 // public flags (8 byte connection_id)
187 0x3C, 187 0x3C,
188 // connection_id 188 // connection_id
189 0x10, 0x32, 0x54, 0x76, 189 0x10, 0x32, 0x54, 0x76,
190 0x98, 0xBA, 0xDC, 0xFE, 190 0x98, 0xBA, 0xDC, 0xFE,
191 // packet number 191 // packet number
192 0xBC, 0x9A, 0x78, 0x56, 192 0xBC, 0x9A, 0x78, 0x56,
193 0x34, 0x12, 193 0x34, 0x12,
194 // private flags 194 // private flags
195 0x00 195 0x00
196 }; 196 };
197 // clang-format on 197 // clang-format on
198 QuicReceivedPacket encrypted_valid_packet( 198 QuicReceivedPacket encrypted_valid_packet(
199 reinterpret_cast<char*>(valid_packet), arraysize(valid_packet), 199 reinterpret_cast<char*>(valid_packet), arraysize(valid_packet),
200 QuicTime::Zero(), false); 200 QuicTime::Zero(), false);
201 201
202 EXPECT_CALL(dispatcher_, ProcessPacket(_, _, _)).Times(1); 202 EXPECT_CALL(dispatcher_, ProcessPacket(_, _, _)).Times(1);
203 DispatchPacket(encrypted_valid_packet); 203 DispatchPacket(encrypted_valid_packet);
204 } 204 }
205 205
206 } // namespace 206 } // namespace
207 } // namespace test 207 } // namespace test
208 } // namespace net 208 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_server_bin.cc ('k') | net/tools/quic/quic_simple_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698