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/quic_packet_generator.h" | 5 #include "net/quic/quic_packet_generator.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "net/quic/crypto/crypto_protocol.h" | 9 #include "net/quic/crypto/crypto_protocol.h" |
10 #include "net/quic/crypto/null_encrypter.h" | 10 #include "net/quic/crypto/null_encrypter.h" |
11 #include "net/quic/crypto/quic_decrypter.h" | 11 #include "net/quic/crypto/quic_decrypter.h" |
12 #include "net/quic/crypto/quic_encrypter.h" | 12 #include "net/quic/crypto/quic_encrypter.h" |
| 13 #include "net/quic/quic_flags.h" |
13 #include "net/quic/quic_utils.h" | 14 #include "net/quic/quic_utils.h" |
14 #include "net/quic/test_tools/quic_packet_creator_peer.h" | 15 #include "net/quic/test_tools/quic_packet_creator_peer.h" |
15 #include "net/quic/test_tools/quic_packet_generator_peer.h" | 16 #include "net/quic/test_tools/quic_packet_generator_peer.h" |
16 #include "net/quic/test_tools/quic_test_utils.h" | 17 #include "net/quic/test_tools/quic_test_utils.h" |
17 #include "net/quic/test_tools/simple_quic_framer.h" | 18 #include "net/quic/test_tools/simple_quic_framer.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 using base::StringPiece; | 22 using base::StringPiece; |
22 using std::string; | 23 using std::string; |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 generator_.SetShouldSendAck(true, true); | 309 generator_.SetShouldSendAck(true, true); |
309 EXPECT_FALSE(generator_.HasQueuedFrames()); | 310 EXPECT_FALSE(generator_.HasQueuedFrames()); |
310 | 311 |
311 PacketContents contents; | 312 PacketContents contents; |
312 contents.num_ack_frames = 1; | 313 contents.num_ack_frames = 1; |
313 contents.num_feedback_frames = 1; | 314 contents.num_feedback_frames = 1; |
314 contents.num_stop_waiting_frames = 1; | 315 contents.num_stop_waiting_frames = 1; |
315 CheckPacketContains(contents, packet_); | 316 CheckPacketContains(contents, packet_); |
316 } | 317 } |
317 | 318 |
| 319 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_MultipleCalls) { |
| 320 ValueRestore<bool> old_flag(&FLAGS_quic_disallow_multiple_pending_ack_frames, |
| 321 true); |
| 322 |
| 323 // Make sure that calling SetShouldSendAck multiple times does not result in a |
| 324 // crash. Previously this would result in multiple QuicFrames queued in the |
| 325 // packet generator, with all but the last with internal pointers to freed |
| 326 // memory. |
| 327 delegate_.SetCanWriteAnything(); |
| 328 |
| 329 // Only one AckFrame should be created. |
| 330 EXPECT_CALL(delegate_, CreateAckFrame()) |
| 331 .Times(1) |
| 332 .WillOnce(Return(CreateAckFrame())); |
| 333 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
| 334 .Times(1) |
| 335 .WillOnce(SaveArg<0>(&packet_)); |
| 336 |
| 337 generator_.StartBatchOperations(); |
| 338 generator_.SetShouldSendAck(false, false); |
| 339 generator_.SetShouldSendAck(false, false); |
| 340 generator_.FinishBatchOperations(); |
| 341 } |
| 342 |
318 TEST_F(QuicPacketGeneratorTest, AddControlFrame_NotWritable) { | 343 TEST_F(QuicPacketGeneratorTest, AddControlFrame_NotWritable) { |
319 delegate_.SetCanNotWrite(); | 344 delegate_.SetCanNotWrite(); |
320 | 345 |
321 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame())); | 346 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame())); |
322 EXPECT_TRUE(generator_.HasQueuedFrames()); | 347 EXPECT_TRUE(generator_.HasQueuedFrames()); |
323 } | 348 } |
324 | 349 |
325 TEST_F(QuicPacketGeneratorTest, AddControlFrame_OnlyAckWritable) { | 350 TEST_F(QuicPacketGeneratorTest, AddControlFrame_OnlyAckWritable) { |
326 delegate_.SetCanWriteOnlyNonRetransmittable(); | 351 delegate_.SetCanWriteOnlyNonRetransmittable(); |
327 | 352 |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 generator_.SetConnectionIdLength(7); | 996 generator_.SetConnectionIdLength(7); |
972 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length()); | 997 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length()); |
973 generator_.SetConnectionIdLength(8); | 998 generator_.SetConnectionIdLength(8); |
974 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length()); | 999 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length()); |
975 generator_.SetConnectionIdLength(9); | 1000 generator_.SetConnectionIdLength(9); |
976 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length()); | 1001 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length()); |
977 } | 1002 } |
978 | 1003 |
979 } // namespace test | 1004 } // namespace test |
980 } // namespace net | 1005 } // namespace net |
OLD | NEW |