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 #include "net/quic/core/quic_packet_generator.h" | 5 #include "net/quic/core/quic_packet_generator.h" |
6 | 6 |
7 #include <cstdint> | 7 #include <cstdint> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "net/quic/core/crypto/crypto_protocol.h" | 12 #include "net/quic/core/crypto/crypto_protocol.h" |
13 #include "net/quic/core/crypto/null_encrypter.h" | 13 #include "net/quic/core/crypto/null_encrypter.h" |
14 #include "net/quic/core/crypto/quic_decrypter.h" | 14 #include "net/quic/core/crypto/quic_decrypter.h" |
15 #include "net/quic/core/crypto/quic_encrypter.h" | 15 #include "net/quic/core/crypto/quic_encrypter.h" |
16 #include "net/quic/core/quic_simple_buffer_allocator.h" | 16 #include "net/quic/core/quic_simple_buffer_allocator.h" |
17 #include "net/quic/core/quic_utils.h" | 17 #include "net/quic/core/quic_utils.h" |
18 #include "net/quic/platform/api/quic_socket_address.h" | 18 #include "net/quic/platform/api/quic_socket_address.h" |
| 19 #include "net/quic/platform/api/quic_string_piece.h" |
19 #include "net/quic/test_tools/quic_packet_creator_peer.h" | 20 #include "net/quic/test_tools/quic_packet_creator_peer.h" |
20 #include "net/quic/test_tools/quic_packet_generator_peer.h" | 21 #include "net/quic/test_tools/quic_packet_generator_peer.h" |
21 #include "net/quic/test_tools/quic_test_utils.h" | 22 #include "net/quic/test_tools/quic_test_utils.h" |
22 #include "net/quic/test_tools/simple_quic_framer.h" | 23 #include "net/quic/test_tools/simple_quic_framer.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 using base::StringPiece; | |
27 using std::string; | 27 using std::string; |
28 using testing::InSequence; | 28 using testing::InSequence; |
29 using testing::Return; | 29 using testing::Return; |
30 using testing::StrictMock; | 30 using testing::StrictMock; |
31 using testing::_; | 31 using testing::_; |
32 | 32 |
33 namespace net { | 33 namespace net { |
34 namespace test { | 34 namespace test { |
35 namespace { | 35 namespace { |
36 | 36 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 195 } |
196 | 196 |
197 QuicIOVector CreateData(size_t len) { | 197 QuicIOVector CreateData(size_t len) { |
198 data_array_.reset(new char[len]); | 198 data_array_.reset(new char[len]); |
199 memset(data_array_.get(), '?', len); | 199 memset(data_array_.get(), '?', len); |
200 iov_.iov_base = data_array_.get(); | 200 iov_.iov_base = data_array_.get(); |
201 iov_.iov_len = len; | 201 iov_.iov_len = len; |
202 return QuicIOVector(&iov_, 1, len); | 202 return QuicIOVector(&iov_, 1, len); |
203 } | 203 } |
204 | 204 |
205 QuicIOVector MakeIOVectorFromStringPiece(StringPiece s) { | 205 QuicIOVector MakeIOVectorFromStringPiece(QuicStringPiece s) { |
206 return MakeIOVector(s, &iov_); | 206 return MakeIOVector(s, &iov_); |
207 } | 207 } |
208 | 208 |
209 QuicFramer framer_; | 209 QuicFramer framer_; |
210 SimpleBufferAllocator buffer_allocator_; | 210 SimpleBufferAllocator buffer_allocator_; |
211 StrictMock<MockDelegate> delegate_; | 211 StrictMock<MockDelegate> delegate_; |
212 QuicPacketGenerator generator_; | 212 QuicPacketGenerator generator_; |
213 QuicPacketCreator* creator_; | 213 QuicPacketCreator* creator_; |
214 SimpleQuicFramer simple_framer_; | 214 SimpleQuicFramer simple_framer_; |
215 std::vector<SerializedPacket> packets_; | 215 std::vector<SerializedPacket> packets_; |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 "packet_number_length 1 is too small " | 846 "packet_number_length 1 is too small " |
847 "for least_unacked_delta: 1001"); | 847 "for least_unacked_delta: 1001"); |
848 } | 848 } |
849 | 849 |
850 // Regression test for b/31486443. | 850 // Regression test for b/31486443. |
851 TEST_F(QuicPacketGeneratorTest, ConnectionCloseFrameLargerThanPacketSize) { | 851 TEST_F(QuicPacketGeneratorTest, ConnectionCloseFrameLargerThanPacketSize) { |
852 delegate_.SetCanWriteAnything(); | 852 delegate_.SetCanWriteAnything(); |
853 QuicConnectionCloseFrame* frame = new QuicConnectionCloseFrame(); | 853 QuicConnectionCloseFrame* frame = new QuicConnectionCloseFrame(); |
854 frame->error_code = QUIC_PACKET_WRITE_ERROR; | 854 frame->error_code = QUIC_PACKET_WRITE_ERROR; |
855 char buf[2000]; | 855 char buf[2000]; |
856 StringPiece error_details(buf, 2000); | 856 QuicStringPiece error_details(buf, 2000); |
857 frame->error_details = error_details.as_string(); | 857 frame->error_details = error_details.as_string(); |
858 EXPECT_CALL(delegate_, | 858 EXPECT_CALL(delegate_, |
859 OnUnrecoverableError(QUIC_FAILED_TO_SERIALIZE_PACKET, | 859 OnUnrecoverableError(QUIC_FAILED_TO_SERIALIZE_PACKET, |
860 "Single frame cannot fit into a packet", _)); | 860 "Single frame cannot fit into a packet", _)); |
861 EXPECT_QUIC_BUG(generator_.AddControlFrame(QuicFrame(frame)), ""); | 861 EXPECT_QUIC_BUG(generator_.AddControlFrame(QuicFrame(frame)), ""); |
862 EXPECT_TRUE(generator_.HasQueuedFrames()); | 862 EXPECT_TRUE(generator_.HasQueuedFrames()); |
863 } | 863 } |
864 | 864 |
865 } // namespace test | 865 } // namespace test |
866 } // namespace net | 866 } // namespace net |
OLD | NEW |