| 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 <cstdint> | 10 #include <cstdint> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/strings/string_piece.h" | |
| 18 #include "net/quic/core/congestion_control/loss_detection_interface.h" | 17 #include "net/quic/core/congestion_control/loss_detection_interface.h" |
| 19 #include "net/quic/core/congestion_control/send_algorithm_interface.h" | 18 #include "net/quic/core/congestion_control/send_algorithm_interface.h" |
| 20 #include "net/quic/core/quic_client_push_promise_index.h" | 19 #include "net/quic/core/quic_client_push_promise_index.h" |
| 21 #include "net/quic/core/quic_connection.h" | 20 #include "net/quic/core/quic_connection.h" |
| 22 #include "net/quic/core/quic_connection_close_delegate_interface.h" | 21 #include "net/quic/core/quic_connection_close_delegate_interface.h" |
| 23 #include "net/quic/core/quic_framer.h" | 22 #include "net/quic/core/quic_framer.h" |
| 24 #include "net/quic/core/quic_iovector.h" | 23 #include "net/quic/core/quic_iovector.h" |
| 25 #include "net/quic/core/quic_sent_packet_manager.h" | 24 #include "net/quic/core/quic_sent_packet_manager.h" |
| 26 #include "net/quic/core/quic_server_session_base.h" | 25 #include "net/quic/core/quic_server_session_base.h" |
| 27 #include "net/quic/core/quic_simple_buffer_allocator.h" | 26 #include "net/quic/core/quic_simple_buffer_allocator.h" |
| 27 #include "net/quic/platform/api/quic_string_piece.h" |
| 28 #include "net/quic/test_tools/mock_clock.h" | 28 #include "net/quic/test_tools/mock_clock.h" |
| 29 #include "net/quic/test_tools/mock_random.h" | 29 #include "net/quic/test_tools/mock_random.h" |
| 30 #include "net/test/gtest_util.h" | 30 #include "net/test/gtest_util.h" |
| 31 #include "net/tools/quic/quic_per_connection_packet_writer.h" | 31 #include "net/tools/quic/quic_per_connection_packet_writer.h" |
| 32 #include "net/tools/quic/test_tools/mock_quic_session_visitor.h" | 32 #include "net/tools/quic/test_tools/mock_quic_session_visitor.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 34 | 34 |
| 35 using base::StringPiece; | |
| 36 | |
| 37 // EXPECT_QUIC_BUG is like EXPECT_DFATAL, except it ensures that no DFATAL | 35 // EXPECT_QUIC_BUG is like EXPECT_DFATAL, except it ensures that no DFATAL |
| 38 // logging is skipped due to exponential backoff. | 36 // logging is skipped due to exponential backoff. |
| 39 // | 37 // |
| 40 // For external QUIC, EXPECT_QUIC_BUG should be #defined to EXPECT_DFATAL. | 38 // For external QUIC, EXPECT_QUIC_BUG should be #defined to EXPECT_DFATAL. |
| 41 #define EXPECT_QUIC_BUG EXPECT_DFATAL | 39 #define EXPECT_QUIC_BUG EXPECT_DFATAL |
| 42 | 40 |
| 43 namespace net { | 41 namespace net { |
| 44 | 42 |
| 45 namespace test { | 43 namespace test { |
| 46 | 44 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 185 |
| 188 // When constructed, checks that all QUIC flags have their correct default | 186 // When constructed, checks that all QUIC flags have their correct default |
| 189 // values and when destructed, restores those values. | 187 // values and when destructed, restores those values. |
| 190 class QuicFlagSaver { | 188 class QuicFlagSaver { |
| 191 public: | 189 public: |
| 192 QuicFlagSaver(); | 190 QuicFlagSaver(); |
| 193 ~QuicFlagSaver(); | 191 ~QuicFlagSaver(); |
| 194 }; | 192 }; |
| 195 | 193 |
| 196 // Compute SHA-1 hash of the supplied std::string. | 194 // Compute SHA-1 hash of the supplied std::string. |
| 197 std::string Sha1Hash(base::StringPiece data); | 195 std::string Sha1Hash(QuicStringPiece data); |
| 198 | 196 |
| 199 // Simple random number generator used to compute random numbers suitable | 197 // Simple random number generator used to compute random numbers suitable |
| 200 // for pseudo-randomly dropping packets in tests. It works by computing | 198 // for pseudo-randomly dropping packets in tests. It works by computing |
| 201 // the sha1 hash of the current seed, and using the first 64 bits as | 199 // the sha1 hash of the current seed, and using the first 64 bits as |
| 202 // the next random number, and the next seed. | 200 // the next random number, and the next seed. |
| 203 class SimpleRandom : public QuicRandom { | 201 class SimpleRandom : public QuicRandom { |
| 204 public: | 202 public: |
| 205 SimpleRandom() : seed_(0) {} | 203 SimpleRandom() : seed_(0) {} |
| 206 ~SimpleRandom() override {} | 204 ~SimpleRandom() override {} |
| 207 | 205 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 QuicStreamOffset offset, | 496 QuicStreamOffset offset, |
| 499 bool fin, | 497 bool fin, |
| 500 QuicReferenceCountedPointer<QuicAckListenerInterface>)); | 498 QuicReferenceCountedPointer<QuicAckListenerInterface>)); |
| 501 | 499 |
| 502 MOCK_METHOD3(SendRstStream, | 500 MOCK_METHOD3(SendRstStream, |
| 503 void(QuicStreamId stream_id, | 501 void(QuicStreamId stream_id, |
| 504 QuicRstStreamErrorCode error, | 502 QuicRstStreamErrorCode error, |
| 505 QuicStreamOffset bytes_written)); | 503 QuicStreamOffset bytes_written)); |
| 506 | 504 |
| 507 MOCK_METHOD2(OnStreamHeaders, | 505 MOCK_METHOD2(OnStreamHeaders, |
| 508 void(QuicStreamId stream_id, base::StringPiece headers_data)); | 506 void(QuicStreamId stream_id, QuicStringPiece headers_data)); |
| 509 MOCK_METHOD2(OnStreamHeadersPriority, | 507 MOCK_METHOD2(OnStreamHeadersPriority, |
| 510 void(QuicStreamId stream_id, SpdyPriority priority)); | 508 void(QuicStreamId stream_id, SpdyPriority priority)); |
| 511 MOCK_METHOD3(OnStreamHeadersComplete, | 509 MOCK_METHOD3(OnStreamHeadersComplete, |
| 512 void(QuicStreamId stream_id, bool fin, size_t frame_len)); | 510 void(QuicStreamId stream_id, bool fin, size_t frame_len)); |
| 513 MOCK_METHOD0(IsCryptoHandshakeConfirmed, bool()); | 511 MOCK_METHOD0(IsCryptoHandshakeConfirmed, bool()); |
| 514 | 512 |
| 515 using QuicSession::ActivateStream; | 513 using QuicSession::ActivateStream; |
| 516 | 514 |
| 517 // Returns a QuicConsumedData that indicates all of |data| (and |fin| if set) | 515 // Returns a QuicConsumedData that indicates all of |data| (and |fin| if set) |
| 518 // has been consumed. | 516 // has been consumed. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 QuicStreamOffset offset, | 557 QuicStreamOffset offset, |
| 560 bool fin, | 558 bool fin, |
| 561 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener)); | 559 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener)); |
| 562 | 560 |
| 563 MOCK_METHOD3(SendRstStream, | 561 MOCK_METHOD3(SendRstStream, |
| 564 void(QuicStreamId stream_id, | 562 void(QuicStreamId stream_id, |
| 565 QuicRstStreamErrorCode error, | 563 QuicRstStreamErrorCode error, |
| 566 QuicStreamOffset bytes_written)); | 564 QuicStreamOffset bytes_written)); |
| 567 | 565 |
| 568 MOCK_METHOD2(OnStreamHeaders, | 566 MOCK_METHOD2(OnStreamHeaders, |
| 569 void(QuicStreamId stream_id, StringPiece headers_data)); | 567 void(QuicStreamId stream_id, QuicStringPiece headers_data)); |
| 570 MOCK_METHOD2(OnStreamHeadersPriority, | 568 MOCK_METHOD2(OnStreamHeadersPriority, |
| 571 void(QuicStreamId stream_id, SpdyPriority priority)); | 569 void(QuicStreamId stream_id, SpdyPriority priority)); |
| 572 MOCK_METHOD3(OnStreamHeadersComplete, | 570 MOCK_METHOD3(OnStreamHeadersComplete, |
| 573 void(QuicStreamId stream_id, bool fin, size_t frame_len)); | 571 void(QuicStreamId stream_id, bool fin, size_t frame_len)); |
| 574 MOCK_METHOD4(OnStreamHeaderList, | 572 MOCK_METHOD4(OnStreamHeaderList, |
| 575 void(QuicStreamId stream_id, | 573 void(QuicStreamId stream_id, |
| 576 bool fin, | 574 bool fin, |
| 577 size_t frame_len, | 575 size_t frame_len, |
| 578 const QuicHeaderList& header_list)); | 576 const QuicHeaderList& header_list)); |
| 579 MOCK_METHOD0(IsCryptoHandshakeConfirmed, bool()); | 577 MOCK_METHOD0(IsCryptoHandshakeConfirmed, bool()); |
| 580 MOCK_METHOD2(OnPromiseHeaders, | 578 MOCK_METHOD2(OnPromiseHeaders, |
| 581 void(QuicStreamId stream_id, StringPiece headers_data)); | 579 void(QuicStreamId stream_id, QuicStringPiece headers_data)); |
| 582 MOCK_METHOD3(OnPromiseHeadersComplete, | 580 MOCK_METHOD3(OnPromiseHeadersComplete, |
| 583 void(QuicStreamId stream_id, | 581 void(QuicStreamId stream_id, |
| 584 QuicStreamId promised_stream_id, | 582 QuicStreamId promised_stream_id, |
| 585 size_t frame_len)); | 583 size_t frame_len)); |
| 586 MOCK_METHOD4(OnPromiseHeaderList, | 584 MOCK_METHOD4(OnPromiseHeaderList, |
| 587 void(QuicStreamId stream_id, | 585 void(QuicStreamId stream_id, |
| 588 QuicStreamId promised_stream_id, | 586 QuicStreamId promised_stream_id, |
| 589 size_t frame_len, | 587 size_t frame_len, |
| 590 const QuicHeaderList& header_list)); | 588 const QuicHeaderList& header_list)); |
| 591 // Methods taking non-copyable types like SpdyHeaderBlock by value cannot be | 589 // Methods taking non-copyable types like SpdyHeaderBlock by value cannot be |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 for (auto p : container) { | 972 for (auto p : container) { |
| 975 total_size += p.first.size() + p.second.size(); | 973 total_size += p.first.size() + p.second.size(); |
| 976 l.OnHeader(p.first, p.second); | 974 l.OnHeader(p.first, p.second); |
| 977 } | 975 } |
| 978 l.OnHeaderBlockEnd(total_size); | 976 l.OnHeaderBlockEnd(total_size); |
| 979 return l; | 977 return l; |
| 980 } | 978 } |
| 981 | 979 |
| 982 // Utility function that returns an QuicIOVector object wrapped around |str|. | 980 // Utility function that returns an QuicIOVector object wrapped around |str|. |
| 983 // // |str|'s data is stored in |iov|. | 981 // // |str|'s data is stored in |iov|. |
| 984 inline QuicIOVector MakeIOVector(base::StringPiece str, struct iovec* iov) { | 982 inline QuicIOVector MakeIOVector(QuicStringPiece str, struct iovec* iov) { |
| 985 iov->iov_base = const_cast<char*>(str.data()); | 983 iov->iov_base = const_cast<char*>(str.data()); |
| 986 iov->iov_len = static_cast<size_t>(str.size()); | 984 iov->iov_len = static_cast<size_t>(str.size()); |
| 987 QuicIOVector quic_iov(iov, 1, str.size()); | 985 QuicIOVector quic_iov(iov, 1, str.size()); |
| 988 return quic_iov; | 986 return quic_iov; |
| 989 } | 987 } |
| 990 | 988 |
| 991 } // namespace test | 989 } // namespace test |
| 992 } // namespace net | 990 } // namespace net |
| 993 | 991 |
| 994 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 992 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
| OLD | NEW |