| 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 void OnError(QuicFramer* framer) override {} |
| 194 virtual void OnPacket() override {} | 194 void OnPacket() override {} |
| 195 virtual void OnPublicResetPacket( | 195 void OnPublicResetPacket(const QuicPublicResetPacket& packet) override {} |
| 196 const QuicPublicResetPacket& packet) override {} | 196 void OnVersionNegotiationPacket( |
| 197 virtual void OnVersionNegotiationPacket( | |
| 198 const QuicVersionNegotiationPacket& packet) override {} | 197 const QuicVersionNegotiationPacket& packet) override {} |
| 199 virtual void OnRevivedPacket() override {} | 198 void OnRevivedPacket() override {} |
| 200 virtual bool OnProtocolVersionMismatch(QuicVersion version) override; | 199 bool OnProtocolVersionMismatch(QuicVersion version) override; |
| 201 virtual bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override; | 200 bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override; |
| 202 virtual bool OnUnauthenticatedPublicHeader( | 201 bool OnUnauthenticatedPublicHeader( |
| 203 const QuicPacketPublicHeader& header) override; | 202 const QuicPacketPublicHeader& header) override; |
| 204 virtual void OnDecryptedPacket(EncryptionLevel level) override {} | 203 void OnDecryptedPacket(EncryptionLevel level) override {} |
| 205 virtual bool OnPacketHeader(const QuicPacketHeader& header) override; | 204 bool OnPacketHeader(const QuicPacketHeader& header) override; |
| 206 virtual void OnFecProtectedPayload(base::StringPiece payload) override {} | 205 void OnFecProtectedPayload(base::StringPiece payload) override {} |
| 207 virtual bool OnStreamFrame(const QuicStreamFrame& frame) override; | 206 bool OnStreamFrame(const QuicStreamFrame& frame) override; |
| 208 virtual bool OnAckFrame(const QuicAckFrame& frame) override; | 207 bool OnAckFrame(const QuicAckFrame& frame) override; |
| 209 virtual bool OnCongestionFeedbackFrame( | 208 bool OnCongestionFeedbackFrame( |
| 210 const QuicCongestionFeedbackFrame& frame) override; | 209 const QuicCongestionFeedbackFrame& frame) override; |
| 211 virtual bool OnStopWaitingFrame( | 210 bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override; |
| 212 const QuicStopWaitingFrame& frame) override; | 211 bool OnPingFrame(const QuicPingFrame& frame) override; |
| 213 virtual bool OnPingFrame(const QuicPingFrame& frame) override; | 212 void OnFecData(const QuicFecData& fec) override {} |
| 214 virtual void OnFecData(const QuicFecData& fec) override {} | 213 bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override; |
| 215 virtual bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override; | 214 bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override; |
| 216 virtual bool OnConnectionCloseFrame( | 215 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override; |
| 217 const QuicConnectionCloseFrame& frame) override; | 216 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; |
| 218 virtual bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override; | 217 bool OnBlockedFrame(const QuicBlockedFrame& frame) override; |
| 219 virtual bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; | 218 void OnPacketComplete() override {} |
| 220 virtual bool OnBlockedFrame(const QuicBlockedFrame& frame) override; | |
| 221 virtual void OnPacketComplete() override {} | |
| 222 | 219 |
| 223 private: | 220 private: |
| 224 DISALLOW_COPY_AND_ASSIGN(NoOpFramerVisitor); | 221 DISALLOW_COPY_AND_ASSIGN(NoOpFramerVisitor); |
| 225 }; | 222 }; |
| 226 | 223 |
| 227 class MockConnectionVisitor : public QuicConnectionVisitorInterface { | 224 class MockConnectionVisitor : public QuicConnectionVisitorInterface { |
| 228 public: | 225 public: |
| 229 MockConnectionVisitor(); | 226 MockConnectionVisitor(); |
| 230 virtual ~MockConnectionVisitor(); | 227 virtual ~MockConnectionVisitor(); |
| 231 | 228 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 247 void(const QuicVersion& version)); | 244 void(const QuicVersion& version)); |
| 248 MOCK_METHOD0(OnConfigNegotiated, void()); | 245 MOCK_METHOD0(OnConfigNegotiated, void()); |
| 249 | 246 |
| 250 private: | 247 private: |
| 251 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor); | 248 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor); |
| 252 }; | 249 }; |
| 253 | 250 |
| 254 class MockHelper : public QuicConnectionHelperInterface { | 251 class MockHelper : public QuicConnectionHelperInterface { |
| 255 public: | 252 public: |
| 256 MockHelper(); | 253 MockHelper(); |
| 257 virtual ~MockHelper(); | 254 ~MockHelper() override; |
| 258 virtual const QuicClock* GetClock() const override; | 255 const QuicClock* GetClock() const override; |
| 259 virtual QuicRandom* GetRandomGenerator() override; | 256 QuicRandom* GetRandomGenerator() override; |
| 260 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override; | 257 QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override; |
| 261 void AdvanceTime(QuicTime::Delta delta); | 258 void AdvanceTime(QuicTime::Delta delta); |
| 262 | 259 |
| 263 private: | 260 private: |
| 264 MockClock clock_; | 261 MockClock clock_; |
| 265 MockRandom random_generator_; | 262 MockRandom random_generator_; |
| 266 | 263 |
| 267 DISALLOW_COPY_AND_ASSIGN(MockHelper); | 264 DISALLOW_COPY_AND_ASSIGN(MockHelper); |
| 268 }; | 265 }; |
| 269 | 266 |
| 270 class MockConnection : public QuicConnection { | 267 class MockConnection : public QuicConnection { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 DISALLOW_COPY_AND_ASSIGN(MockConnection); | 319 DISALLOW_COPY_AND_ASSIGN(MockConnection); |
| 323 }; | 320 }; |
| 324 | 321 |
| 325 class PacketSavingConnection : public MockConnection { | 322 class PacketSavingConnection : public MockConnection { |
| 326 public: | 323 public: |
| 327 explicit PacketSavingConnection(bool is_server); | 324 explicit PacketSavingConnection(bool is_server); |
| 328 | 325 |
| 329 PacketSavingConnection(bool is_server, | 326 PacketSavingConnection(bool is_server, |
| 330 const QuicVersionVector& supported_versions); | 327 const QuicVersionVector& supported_versions); |
| 331 | 328 |
| 332 virtual ~PacketSavingConnection(); | 329 ~PacketSavingConnection() override; |
| 333 | 330 |
| 334 virtual void SendOrQueuePacket(QueuedPacket packet) override; | 331 void SendOrQueuePacket(QueuedPacket packet) override; |
| 335 | 332 |
| 336 std::vector<QuicPacket*> packets_; | 333 std::vector<QuicPacket*> packets_; |
| 337 std::vector<QuicEncryptedPacket*> encrypted_packets_; | 334 std::vector<QuicEncryptedPacket*> encrypted_packets_; |
| 338 | 335 |
| 339 private: | 336 private: |
| 340 DISALLOW_COPY_AND_ASSIGN(PacketSavingConnection); | 337 DISALLOW_COPY_AND_ASSIGN(PacketSavingConnection); |
| 341 }; | 338 }; |
| 342 | 339 |
| 343 class MockSession : public QuicSession { | 340 class MockSession : public QuicSession { |
| 344 public: | 341 public: |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 MOCK_CONST_METHOD0(GetLossTimeout, QuicTime()); | 484 MOCK_CONST_METHOD0(GetLossTimeout, QuicTime()); |
| 488 | 485 |
| 489 private: | 486 private: |
| 490 DISALLOW_COPY_AND_ASSIGN(MockLossAlgorithm); | 487 DISALLOW_COPY_AND_ASSIGN(MockLossAlgorithm); |
| 491 }; | 488 }; |
| 492 | 489 |
| 493 class TestEntropyCalculator : | 490 class TestEntropyCalculator : |
| 494 public QuicReceivedEntropyHashCalculatorInterface { | 491 public QuicReceivedEntropyHashCalculatorInterface { |
| 495 public: | 492 public: |
| 496 TestEntropyCalculator(); | 493 TestEntropyCalculator(); |
| 497 virtual ~TestEntropyCalculator(); | 494 ~TestEntropyCalculator() override; |
| 498 | 495 |
| 499 virtual QuicPacketEntropyHash EntropyHash( | 496 QuicPacketEntropyHash EntropyHash( |
| 500 QuicPacketSequenceNumber sequence_number) const override; | 497 QuicPacketSequenceNumber sequence_number) const override; |
| 501 | 498 |
| 502 private: | 499 private: |
| 503 DISALLOW_COPY_AND_ASSIGN(TestEntropyCalculator); | 500 DISALLOW_COPY_AND_ASSIGN(TestEntropyCalculator); |
| 504 }; | 501 }; |
| 505 | 502 |
| 506 class MockEntropyCalculator : public TestEntropyCalculator { | 503 class MockEntropyCalculator : public TestEntropyCalculator { |
| 507 public: | 504 public: |
| 508 MockEntropyCalculator(); | 505 MockEntropyCalculator(); |
| 509 virtual ~MockEntropyCalculator(); | 506 virtual ~MockEntropyCalculator(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 private: | 542 private: |
| 546 DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeVisitor); | 543 DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeVisitor); |
| 547 }; | 544 }; |
| 548 | 545 |
| 549 // Creates per-connection packet writers that register themselves with the | 546 // Creates per-connection packet writers that register themselves with the |
| 550 // TestWriterFactory on each write so that TestWriterFactory::OnPacketSent can | 547 // TestWriterFactory on each write so that TestWriterFactory::OnPacketSent can |
| 551 // be routed to the appropriate QuicConnection. | 548 // be routed to the appropriate QuicConnection. |
| 552 class TestWriterFactory : public QuicDispatcher::PacketWriterFactory { | 549 class TestWriterFactory : public QuicDispatcher::PacketWriterFactory { |
| 553 public: | 550 public: |
| 554 TestWriterFactory(); | 551 TestWriterFactory(); |
| 555 virtual ~TestWriterFactory(); | 552 ~TestWriterFactory() override; |
| 556 | 553 |
| 557 virtual QuicPacketWriter* Create(QuicServerPacketWriter* writer, | 554 QuicPacketWriter* Create(QuicServerPacketWriter* writer, |
| 558 QuicConnection* connection) override; | 555 QuicConnection* connection) override; |
| 559 | 556 |
| 560 // Calls OnPacketSent on the last QuicConnection to write through one of the | 557 // Calls OnPacketSent on the last QuicConnection to write through one of the |
| 561 // packet writers created by this factory. | 558 // packet writers created by this factory. |
| 562 void OnPacketSent(WriteResult result); | 559 void OnPacketSent(WriteResult result); |
| 563 | 560 |
| 564 private: | 561 private: |
| 565 class PerConnectionPacketWriter : public QuicPerConnectionPacketWriter { | 562 class PerConnectionPacketWriter : public QuicPerConnectionPacketWriter { |
| 566 public: | 563 public: |
| 567 PerConnectionPacketWriter(TestWriterFactory* factory, | 564 PerConnectionPacketWriter(TestWriterFactory* factory, |
| 568 QuicServerPacketWriter* writer, | 565 QuicServerPacketWriter* writer, |
| 569 QuicConnection* connection); | 566 QuicConnection* connection); |
| 570 virtual ~PerConnectionPacketWriter(); | 567 ~PerConnectionPacketWriter() override; |
| 571 | 568 |
| 572 virtual WriteResult WritePacket( | 569 WriteResult WritePacket(const char* buffer, |
| 573 const char* buffer, | 570 size_t buf_len, |
| 574 size_t buf_len, | 571 const IPAddressNumber& self_address, |
| 575 const IPAddressNumber& self_address, | 572 const IPEndPoint& peer_address) override; |
| 576 const IPEndPoint& peer_address) override; | |
| 577 | 573 |
| 578 private: | 574 private: |
| 579 TestWriterFactory* factory_; | 575 TestWriterFactory* factory_; |
| 580 }; | 576 }; |
| 581 | 577 |
| 582 // If an asynchronous write is happening and |writer| gets deleted, this | 578 // If an asynchronous write is happening and |writer| gets deleted, this |
| 583 // clears the pointer to it to prevent use-after-free. | 579 // clears the pointer to it to prevent use-after-free. |
| 584 void Unregister(PerConnectionPacketWriter* writer); | 580 void Unregister(PerConnectionPacketWriter* writer); |
| 585 | 581 |
| 586 PerConnectionPacketWriter* current_writer_; | 582 PerConnectionPacketWriter* current_writer_; |
| 587 }; | 583 }; |
| 588 | 584 |
| 589 } // namespace test | 585 } // namespace test |
| 590 } // namespace net | 586 } // namespace net |
| 591 | 587 |
| 592 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 588 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
| OLD | NEW |