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 // Common utilities for Quic tests | 5 // Common utilities for Quic tests |
6 | 6 |
7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 MOCK_METHOD0(OnPacketComplete, void()); | 183 MOCK_METHOD0(OnPacketComplete, void()); |
184 | 184 |
185 private: | 185 private: |
186 DISALLOW_COPY_AND_ASSIGN(MockFramerVisitor); | 186 DISALLOW_COPY_AND_ASSIGN(MockFramerVisitor); |
187 }; | 187 }; |
188 | 188 |
189 class NoOpFramerVisitor : public QuicFramerVisitorInterface { | 189 class NoOpFramerVisitor : public QuicFramerVisitorInterface { |
190 public: | 190 public: |
191 NoOpFramerVisitor() {} | 191 NoOpFramerVisitor() {} |
192 | 192 |
193 virtual void OnError(QuicFramer* framer) OVERRIDE {} | 193 virtual void OnError(QuicFramer* framer) override {} |
194 virtual void OnPacket() OVERRIDE {} | 194 virtual void OnPacket() override {} |
195 virtual void OnPublicResetPacket( | 195 virtual void OnPublicResetPacket( |
196 const QuicPublicResetPacket& packet) OVERRIDE {} | 196 const QuicPublicResetPacket& packet) override {} |
197 virtual void OnVersionNegotiationPacket( | 197 virtual void OnVersionNegotiationPacket( |
198 const QuicVersionNegotiationPacket& packet) OVERRIDE {} | 198 const QuicVersionNegotiationPacket& packet) override {} |
199 virtual void OnRevivedPacket() OVERRIDE {} | 199 virtual void OnRevivedPacket() override {} |
200 virtual bool OnProtocolVersionMismatch(QuicVersion version) OVERRIDE; | 200 virtual bool OnProtocolVersionMismatch(QuicVersion version) override; |
201 virtual bool OnUnauthenticatedHeader(const QuicPacketHeader& header) OVERRIDE; | 201 virtual bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override; |
202 virtual bool OnUnauthenticatedPublicHeader( | 202 virtual bool OnUnauthenticatedPublicHeader( |
203 const QuicPacketPublicHeader& header) OVERRIDE; | 203 const QuicPacketPublicHeader& header) override; |
204 virtual void OnDecryptedPacket(EncryptionLevel level) OVERRIDE {} | 204 virtual void OnDecryptedPacket(EncryptionLevel level) override {} |
205 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE; | 205 virtual bool OnPacketHeader(const QuicPacketHeader& header) override; |
206 virtual void OnFecProtectedPayload(base::StringPiece payload) OVERRIDE {} | 206 virtual void OnFecProtectedPayload(base::StringPiece payload) override {} |
207 virtual bool OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE; | 207 virtual bool OnStreamFrame(const QuicStreamFrame& frame) override; |
208 virtual bool OnAckFrame(const QuicAckFrame& frame) OVERRIDE; | 208 virtual bool OnAckFrame(const QuicAckFrame& frame) override; |
209 virtual bool OnCongestionFeedbackFrame( | 209 virtual bool OnCongestionFeedbackFrame( |
210 const QuicCongestionFeedbackFrame& frame) OVERRIDE; | 210 const QuicCongestionFeedbackFrame& frame) override; |
211 virtual bool OnStopWaitingFrame( | 211 virtual bool OnStopWaitingFrame( |
212 const QuicStopWaitingFrame& frame) OVERRIDE; | 212 const QuicStopWaitingFrame& frame) override; |
213 virtual bool OnPingFrame(const QuicPingFrame& frame) OVERRIDE; | 213 virtual bool OnPingFrame(const QuicPingFrame& frame) override; |
214 virtual void OnFecData(const QuicFecData& fec) OVERRIDE {} | 214 virtual void OnFecData(const QuicFecData& fec) override {} |
215 virtual bool OnRstStreamFrame(const QuicRstStreamFrame& frame) OVERRIDE; | 215 virtual bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override; |
216 virtual bool OnConnectionCloseFrame( | 216 virtual bool OnConnectionCloseFrame( |
217 const QuicConnectionCloseFrame& frame) OVERRIDE; | 217 const QuicConnectionCloseFrame& frame) override; |
218 virtual bool OnGoAwayFrame(const QuicGoAwayFrame& frame) OVERRIDE; | 218 virtual bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override; |
219 virtual bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) OVERRIDE; | 219 virtual bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; |
220 virtual bool OnBlockedFrame(const QuicBlockedFrame& frame) OVERRIDE; | 220 virtual bool OnBlockedFrame(const QuicBlockedFrame& frame) override; |
221 virtual void OnPacketComplete() OVERRIDE {} | 221 virtual void OnPacketComplete() override {} |
222 | 222 |
223 private: | 223 private: |
224 DISALLOW_COPY_AND_ASSIGN(NoOpFramerVisitor); | 224 DISALLOW_COPY_AND_ASSIGN(NoOpFramerVisitor); |
225 }; | 225 }; |
226 | 226 |
227 class MockConnectionVisitor : public QuicConnectionVisitorInterface { | 227 class MockConnectionVisitor : public QuicConnectionVisitorInterface { |
228 public: | 228 public: |
229 MockConnectionVisitor(); | 229 MockConnectionVisitor(); |
230 virtual ~MockConnectionVisitor(); | 230 virtual ~MockConnectionVisitor(); |
231 | 231 |
(...skipping 16 matching lines...) Expand all Loading... |
248 MOCK_METHOD0(OnConfigNegotiated, void()); | 248 MOCK_METHOD0(OnConfigNegotiated, void()); |
249 | 249 |
250 private: | 250 private: |
251 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor); | 251 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor); |
252 }; | 252 }; |
253 | 253 |
254 class MockHelper : public QuicConnectionHelperInterface { | 254 class MockHelper : public QuicConnectionHelperInterface { |
255 public: | 255 public: |
256 MockHelper(); | 256 MockHelper(); |
257 virtual ~MockHelper(); | 257 virtual ~MockHelper(); |
258 virtual const QuicClock* GetClock() const OVERRIDE; | 258 virtual const QuicClock* GetClock() const override; |
259 virtual QuicRandom* GetRandomGenerator() OVERRIDE; | 259 virtual QuicRandom* GetRandomGenerator() override; |
260 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) OVERRIDE; | 260 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override; |
261 void AdvanceTime(QuicTime::Delta delta); | 261 void AdvanceTime(QuicTime::Delta delta); |
262 | 262 |
263 private: | 263 private: |
264 MockClock clock_; | 264 MockClock clock_; |
265 MockRandom random_generator_; | 265 MockRandom random_generator_; |
266 | 266 |
267 DISALLOW_COPY_AND_ASSIGN(MockHelper); | 267 DISALLOW_COPY_AND_ASSIGN(MockHelper); |
268 }; | 268 }; |
269 | 269 |
270 class MockConnection : public QuicConnection { | 270 class MockConnection : public QuicConnection { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 MOCK_METHOD2(SendWindowUpdate, void(QuicStreamId id, | 305 MOCK_METHOD2(SendWindowUpdate, void(QuicStreamId id, |
306 QuicStreamOffset byte_offset)); | 306 QuicStreamOffset byte_offset)); |
307 MOCK_METHOD0(OnCanWrite, void()); | 307 MOCK_METHOD0(OnCanWrite, void()); |
308 | 308 |
309 void ProcessUdpPacketInternal(const IPEndPoint& self_address, | 309 void ProcessUdpPacketInternal(const IPEndPoint& self_address, |
310 const IPEndPoint& peer_address, | 310 const IPEndPoint& peer_address, |
311 const QuicEncryptedPacket& packet) { | 311 const QuicEncryptedPacket& packet) { |
312 QuicConnection::ProcessUdpPacket(self_address, peer_address, packet); | 312 QuicConnection::ProcessUdpPacket(self_address, peer_address, packet); |
313 } | 313 } |
314 | 314 |
315 virtual bool OnProtocolVersionMismatch(QuicVersion version) OVERRIDE { | 315 virtual bool OnProtocolVersionMismatch(QuicVersion version) override { |
316 return false; | 316 return false; |
317 } | 317 } |
318 | 318 |
319 private: | 319 private: |
320 scoped_ptr<QuicConnectionHelperInterface> helper_; | 320 scoped_ptr<QuicConnectionHelperInterface> helper_; |
321 | 321 |
322 DISALLOW_COPY_AND_ASSIGN(MockConnection); | 322 DISALLOW_COPY_AND_ASSIGN(MockConnection); |
323 }; | 323 }; |
324 | 324 |
325 class PacketSavingConnection : public MockConnection { | 325 class PacketSavingConnection : public MockConnection { |
326 public: | 326 public: |
327 explicit PacketSavingConnection(bool is_server); | 327 explicit PacketSavingConnection(bool is_server); |
328 | 328 |
329 PacketSavingConnection(bool is_server, | 329 PacketSavingConnection(bool is_server, |
330 const QuicVersionVector& supported_versions); | 330 const QuicVersionVector& supported_versions); |
331 | 331 |
332 virtual ~PacketSavingConnection(); | 332 virtual ~PacketSavingConnection(); |
333 | 333 |
334 virtual void SendOrQueuePacket(QueuedPacket packet) OVERRIDE; | 334 virtual void SendOrQueuePacket(QueuedPacket packet) override; |
335 | 335 |
336 std::vector<QuicPacket*> packets_; | 336 std::vector<QuicPacket*> packets_; |
337 std::vector<QuicEncryptedPacket*> encrypted_packets_; | 337 std::vector<QuicEncryptedPacket*> encrypted_packets_; |
338 | 338 |
339 private: | 339 private: |
340 DISALLOW_COPY_AND_ASSIGN(PacketSavingConnection); | 340 DISALLOW_COPY_AND_ASSIGN(PacketSavingConnection); |
341 }; | 341 }; |
342 | 342 |
343 class MockSession : public QuicSession { | 343 class MockSession : public QuicSession { |
344 public: | 344 public: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 class TestSession : public QuicSession { | 376 class TestSession : public QuicSession { |
377 public: | 377 public: |
378 TestSession(QuicConnection* connection, const QuicConfig& config); | 378 TestSession(QuicConnection* connection, const QuicConfig& config); |
379 virtual ~TestSession(); | 379 virtual ~TestSession(); |
380 | 380 |
381 MOCK_METHOD1(CreateIncomingDataStream, QuicDataStream*(QuicStreamId id)); | 381 MOCK_METHOD1(CreateIncomingDataStream, QuicDataStream*(QuicStreamId id)); |
382 MOCK_METHOD0(CreateOutgoingDataStream, QuicDataStream*()); | 382 MOCK_METHOD0(CreateOutgoingDataStream, QuicDataStream*()); |
383 | 383 |
384 void SetCryptoStream(QuicCryptoStream* stream); | 384 void SetCryptoStream(QuicCryptoStream* stream); |
385 | 385 |
386 virtual QuicCryptoStream* GetCryptoStream() OVERRIDE; | 386 virtual QuicCryptoStream* GetCryptoStream() override; |
387 | 387 |
388 private: | 388 private: |
389 QuicCryptoStream* crypto_stream_; | 389 QuicCryptoStream* crypto_stream_; |
390 | 390 |
391 DISALLOW_COPY_AND_ASSIGN(TestSession); | 391 DISALLOW_COPY_AND_ASSIGN(TestSession); |
392 }; | 392 }; |
393 | 393 |
394 class TestClientSession : public QuicClientSessionBase { | 394 class TestClientSession : public QuicClientSessionBase { |
395 public: | 395 public: |
396 TestClientSession(QuicConnection* connection, const QuicConfig& config); | 396 TestClientSession(QuicConnection* connection, const QuicConfig& config); |
397 virtual ~TestClientSession(); | 397 virtual ~TestClientSession(); |
398 | 398 |
399 // QuicClientSessionBase | 399 // QuicClientSessionBase |
400 MOCK_METHOD1(OnProofValid, | 400 MOCK_METHOD1(OnProofValid, |
401 void(const QuicCryptoClientConfig::CachedState& cached)); | 401 void(const QuicCryptoClientConfig::CachedState& cached)); |
402 MOCK_METHOD1(OnProofVerifyDetailsAvailable, | 402 MOCK_METHOD1(OnProofVerifyDetailsAvailable, |
403 void(const ProofVerifyDetails& verify_details)); | 403 void(const ProofVerifyDetails& verify_details)); |
404 | 404 |
405 // TestClientSession | 405 // TestClientSession |
406 MOCK_METHOD1(CreateIncomingDataStream, QuicDataStream*(QuicStreamId id)); | 406 MOCK_METHOD1(CreateIncomingDataStream, QuicDataStream*(QuicStreamId id)); |
407 MOCK_METHOD0(CreateOutgoingDataStream, QuicDataStream*()); | 407 MOCK_METHOD0(CreateOutgoingDataStream, QuicDataStream*()); |
408 | 408 |
409 void SetCryptoStream(QuicCryptoStream* stream); | 409 void SetCryptoStream(QuicCryptoStream* stream); |
410 | 410 |
411 virtual QuicCryptoStream* GetCryptoStream() OVERRIDE; | 411 virtual QuicCryptoStream* GetCryptoStream() override; |
412 | 412 |
413 private: | 413 private: |
414 QuicCryptoStream* crypto_stream_; | 414 QuicCryptoStream* crypto_stream_; |
415 | 415 |
416 DISALLOW_COPY_AND_ASSIGN(TestClientSession); | 416 DISALLOW_COPY_AND_ASSIGN(TestClientSession); |
417 }; | 417 }; |
418 | 418 |
419 class MockPacketWriter : public QuicPacketWriter { | 419 class MockPacketWriter : public QuicPacketWriter { |
420 public: | 420 public: |
421 MockPacketWriter(); | 421 MockPacketWriter(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 DISALLOW_COPY_AND_ASSIGN(MockLossAlgorithm); | 489 DISALLOW_COPY_AND_ASSIGN(MockLossAlgorithm); |
490 }; | 490 }; |
491 | 491 |
492 class TestEntropyCalculator : | 492 class TestEntropyCalculator : |
493 public QuicReceivedEntropyHashCalculatorInterface { | 493 public QuicReceivedEntropyHashCalculatorInterface { |
494 public: | 494 public: |
495 TestEntropyCalculator(); | 495 TestEntropyCalculator(); |
496 virtual ~TestEntropyCalculator(); | 496 virtual ~TestEntropyCalculator(); |
497 | 497 |
498 virtual QuicPacketEntropyHash EntropyHash( | 498 virtual QuicPacketEntropyHash EntropyHash( |
499 QuicPacketSequenceNumber sequence_number) const OVERRIDE; | 499 QuicPacketSequenceNumber sequence_number) const override; |
500 | 500 |
501 private: | 501 private: |
502 DISALLOW_COPY_AND_ASSIGN(TestEntropyCalculator); | 502 DISALLOW_COPY_AND_ASSIGN(TestEntropyCalculator); |
503 }; | 503 }; |
504 | 504 |
505 class MockEntropyCalculator : public TestEntropyCalculator { | 505 class MockEntropyCalculator : public TestEntropyCalculator { |
506 public: | 506 public: |
507 MockEntropyCalculator(); | 507 MockEntropyCalculator(); |
508 virtual ~MockEntropyCalculator(); | 508 virtual ~MockEntropyCalculator(); |
509 | 509 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 | 547 |
548 // Creates per-connection packet writers that register themselves with the | 548 // Creates per-connection packet writers that register themselves with the |
549 // TestWriterFactory on each write so that TestWriterFactory::OnPacketSent can | 549 // TestWriterFactory on each write so that TestWriterFactory::OnPacketSent can |
550 // be routed to the appropriate QuicConnection. | 550 // be routed to the appropriate QuicConnection. |
551 class TestWriterFactory : public QuicDispatcher::PacketWriterFactory { | 551 class TestWriterFactory : public QuicDispatcher::PacketWriterFactory { |
552 public: | 552 public: |
553 TestWriterFactory(); | 553 TestWriterFactory(); |
554 virtual ~TestWriterFactory(); | 554 virtual ~TestWriterFactory(); |
555 | 555 |
556 virtual QuicPacketWriter* Create(QuicServerPacketWriter* writer, | 556 virtual QuicPacketWriter* Create(QuicServerPacketWriter* writer, |
557 QuicConnection* connection) OVERRIDE; | 557 QuicConnection* connection) override; |
558 | 558 |
559 // Calls OnPacketSent on the last QuicConnection to write through one of the | 559 // Calls OnPacketSent on the last QuicConnection to write through one of the |
560 // packet writers created by this factory. | 560 // packet writers created by this factory. |
561 void OnPacketSent(WriteResult result); | 561 void OnPacketSent(WriteResult result); |
562 | 562 |
563 private: | 563 private: |
564 class PerConnectionPacketWriter : public QuicPerConnectionPacketWriter { | 564 class PerConnectionPacketWriter : public QuicPerConnectionPacketWriter { |
565 public: | 565 public: |
566 PerConnectionPacketWriter(TestWriterFactory* factory, | 566 PerConnectionPacketWriter(TestWriterFactory* factory, |
567 QuicServerPacketWriter* writer, | 567 QuicServerPacketWriter* writer, |
568 QuicConnection* connection); | 568 QuicConnection* connection); |
569 virtual ~PerConnectionPacketWriter(); | 569 virtual ~PerConnectionPacketWriter(); |
570 | 570 |
571 virtual WriteResult WritePacket( | 571 virtual WriteResult WritePacket( |
572 const char* buffer, | 572 const char* buffer, |
573 size_t buf_len, | 573 size_t buf_len, |
574 const IPAddressNumber& self_address, | 574 const IPAddressNumber& self_address, |
575 const IPEndPoint& peer_address) OVERRIDE; | 575 const IPEndPoint& peer_address) override; |
576 | 576 |
577 private: | 577 private: |
578 TestWriterFactory* factory_; | 578 TestWriterFactory* factory_; |
579 }; | 579 }; |
580 | 580 |
581 // If an asynchronous write is happening and |writer| gets deleted, this | 581 // If an asynchronous write is happening and |writer| gets deleted, this |
582 // clears the pointer to it to prevent use-after-free. | 582 // clears the pointer to it to prevent use-after-free. |
583 void Unregister(PerConnectionPacketWriter* writer); | 583 void Unregister(PerConnectionPacketWriter* writer); |
584 | 584 |
585 PerConnectionPacketWriter* current_writer_; | 585 PerConnectionPacketWriter* current_writer_; |
586 }; | 586 }; |
587 | 587 |
588 } // namespace test | 588 } // namespace test |
589 } // namespace net | 589 } // namespace net |
590 | 590 |
591 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 591 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
OLD | NEW |