Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: net/quic/core/quic_packet_creator_test.cc

Issue 2249813002: Create EXPECT_QUIC_BUG macro, and modify QUIC tests to use it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/core/quic_one_block_arena_test.cc ('k') | net/quic/core/quic_packet_generator_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_creator.h" 5 #include "net/quic/core/quic_packet_creator.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 QuicTime::Zero(), 124 QuicTime::Zero(),
125 Perspective::IS_CLIENT), 125 Perspective::IS_CLIENT),
126 connection_id_(2), 126 connection_id_(2),
127 data_("foo"), 127 data_("foo"),
128 creator_(connection_id_, 128 creator_(connection_id_,
129 &client_framer_, 129 &client_framer_,
130 &mock_random_, 130 &mock_random_,
131 &buffer_allocator_, 131 &buffer_allocator_,
132 &delegate_), 132 &delegate_),
133 serialized_packet_(creator_.NoPacket()) { 133 serialized_packet_(creator_.NoPacket()) {
134 FLAGS_quic_always_log_bugs_for_tests = true;
135 creator_.set_connection_id_length(GetParam().connection_id_length); 134 creator_.set_connection_id_length(GetParam().connection_id_length);
136 135
137 creator_.SetEncrypter(ENCRYPTION_INITIAL, new NullEncrypter()); 136 creator_.SetEncrypter(ENCRYPTION_INITIAL, new NullEncrypter());
138 creator_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, new NullEncrypter()); 137 creator_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, new NullEncrypter());
139 client_framer_.set_visitor(&framer_visitor_); 138 client_framer_.set_visitor(&framer_visitor_);
140 client_framer_.set_received_entropy_calculator(&entropy_calculator_); 139 client_framer_.set_received_entropy_calculator(&entropy_calculator_);
141 server_framer_.set_visitor(&framer_visitor_); 140 server_framer_.set_visitor(&framer_visitor_);
142 // TODO(ianswett): Fix this test so it uses a non-null encrypter. 141 // TODO(ianswett): Fix this test so it uses a non-null encrypter.
143 FLAGS_quic_never_write_unencrypted_data = false; 142 FLAGS_quic_never_write_unencrypted_data = false;
144 } 143 }
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, 415 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER,
417 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); 416 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_));
418 // Changing the packet number length with queued frames in the creator 417 // Changing the packet number length with queued frames in the creator
419 // should do nothing. 418 // should do nothing.
420 EXPECT_FALSE(creator_.HasPendingFrames()); 419 EXPECT_FALSE(creator_.HasPendingFrames());
421 QuicFrame ack_frame = QuicFrame(new QuicAckFrame(MakeAckFrame(0u))); 420 QuicFrame ack_frame = QuicFrame(new QuicAckFrame(MakeAckFrame(0u)));
422 creator_.AddSavedFrame(ack_frame); 421 creator_.AddSavedFrame(ack_frame);
423 422
424 // Now change packet number length and expect a QUIC_BUG and no change in 423 // Now change packet number length and expect a QUIC_BUG and no change in
425 // packet number length. 424 // packet number length.
426 EXPECT_DFATAL(creator_.UpdatePacketNumberLength(0, 256), 425 EXPECT_QUIC_BUG(creator_.UpdatePacketNumberLength(0, 256),
427 "Called UpdatePacketNumberLength with 1 queued_frames."); 426 "Called UpdatePacketNumberLength with 1 queued_frames.");
428 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, 427 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER,
429 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); 428 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_));
430 delete ack_frame.ack_frame; 429 delete ack_frame.ack_frame;
431 } 430 }
432 431
433 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithSequenceNumberLength) { 432 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithSequenceNumberLength) {
434 // If the original packet number length, the current packet number 433 // If the original packet number length, the current packet number
435 // length, and the configured send packet number length are different, the 434 // length, and the configured send packet number length are different, the
436 // retransmit must sent with the original length and the others do not change. 435 // retransmit must sent with the original length and the others do not change.
437 if (!FLAGS_quic_simple_packet_number_length) { 436 if (!FLAGS_quic_simple_packet_number_length) {
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 ASSERT_TRUE( 1173 ASSERT_TRUE(
1175 creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame)); 1174 creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame));
1176 ASSERT_TRUE(frame.stream_frame); 1175 ASSERT_TRUE(frame.stream_frame);
1177 size_t consumed = frame.stream_frame->data_length; 1176 size_t consumed = frame.stream_frame->data_length;
1178 EXPECT_EQ(4u, consumed); 1177 EXPECT_EQ(4u, consumed);
1179 EXPECT_TRUE(creator_.HasPendingFrames()); 1178 EXPECT_TRUE(creator_.HasPendingFrames());
1180 EXPECT_EQ(0u, creator_.packet_number()); 1179 EXPECT_EQ(0u, creator_.packet_number());
1181 1180
1182 // Change current path. 1181 // Change current path.
1183 QuicPathId kPathId1 = 1; 1182 QuicPathId kPathId1 = 1;
1184 EXPECT_DFATAL(creator_.SetCurrentPath(kPathId1, 1, 0), 1183 EXPECT_QUIC_BUG(creator_.SetCurrentPath(kPathId1, 1, 0),
1185 "Unable to change paths when a packet is under construction"); 1184 "Unable to change paths when a packet is under construction");
1186 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 1185 EXPECT_CALL(delegate_, OnSerializedPacket(_))
1187 .Times(1) 1186 .Times(1)
1188 .WillRepeatedly( 1187 .WillRepeatedly(
1189 Invoke(this, &QuicPacketCreatorTest::ClearSerializedPacket)); 1188 Invoke(this, &QuicPacketCreatorTest::ClearSerializedPacket));
1190 creator_.Flush(); 1189 creator_.Flush();
1191 EXPECT_FALSE(creator_.HasPendingFrames()); 1190 EXPECT_FALSE(creator_.HasPendingFrames());
1192 creator_.SetCurrentPath(kPathId1, 1, 0); 1191 creator_.SetCurrentPath(kPathId1, 1, 0);
1193 EXPECT_EQ(kPathId1, QuicPacketCreatorPeer::GetCurrentPath(&creator_)); 1192 EXPECT_EQ(kPathId1, QuicPacketCreatorPeer::GetCurrentPath(&creator_));
1194 EXPECT_FALSE(creator_.HasPendingFrames()); 1193 EXPECT_FALSE(creator_.HasPendingFrames());
1195 EXPECT_EQ(0u, creator_.packet_number()); 1194 EXPECT_EQ(0u, creator_.packet_number());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 // Verify serialized data packet's path id. 1301 // Verify serialized data packet's path id.
1303 EXPECT_EQ(kPathId1, serialized_packet_.path_id); 1302 EXPECT_EQ(kPathId1, serialized_packet_.path_id);
1304 DeleteSerializedPacket(); 1303 DeleteSerializedPacket();
1305 } 1304 }
1306 1305
1307 TEST_P(QuicPacketCreatorTest, AddUnencryptedStreamDataClosesConnection) { 1306 TEST_P(QuicPacketCreatorTest, AddUnencryptedStreamDataClosesConnection) {
1308 FLAGS_quic_never_write_unencrypted_data = true; 1307 FLAGS_quic_never_write_unencrypted_data = true;
1309 EXPECT_CALL(delegate_, OnUnrecoverableError(_, _, _)); 1308 EXPECT_CALL(delegate_, OnUnrecoverableError(_, _, _));
1310 QuicStreamFrame stream_frame(kHeadersStreamId, /*fin=*/false, 0u, 1309 QuicStreamFrame stream_frame(kHeadersStreamId, /*fin=*/false, 0u,
1311 StringPiece()); 1310 StringPiece());
1312 EXPECT_DFATAL(creator_.AddSavedFrame(QuicFrame(&stream_frame)), 1311 EXPECT_QUIC_BUG(creator_.AddSavedFrame(QuicFrame(&stream_frame)),
1313 "Cannot send stream data without encryption."); 1312 "Cannot send stream data without encryption.");
1314 } 1313 }
1315 1314
1316 TEST_P(QuicPacketCreatorTest, ChloTooLarge) { 1315 TEST_P(QuicPacketCreatorTest, ChloTooLarge) {
1317 CryptoHandshakeMessage message; 1316 CryptoHandshakeMessage message;
1318 message.set_tag(kCHLO); 1317 message.set_tag(kCHLO);
1319 message.set_minimum_size(kMaxPacketSize); 1318 message.set_minimum_size(kMaxPacketSize);
1320 CryptoFramer framer; 1319 CryptoFramer framer;
1321 std::unique_ptr<QuicData> message_data; 1320 std::unique_ptr<QuicData> message_data;
1322 message_data.reset(framer.ConstructHandshakeMessage(message)); 1321 message_data.reset(framer.ConstructHandshakeMessage(message));
1323 1322
1324 struct iovec iov; 1323 struct iovec iov;
1325 QuicIOVector data_iovec(::net::MakeIOVector( 1324 QuicIOVector data_iovec(::net::MakeIOVector(
1326 StringPiece(message_data->data(), message_data->length()), &iov)); 1325 StringPiece(message_data->data(), message_data->length()), &iov));
1327 QuicFrame frame; 1326 QuicFrame frame;
1328 EXPECT_CALL(delegate_, 1327 EXPECT_CALL(delegate_,
1329 OnUnrecoverableError(QUIC_CRYPTO_CHLO_TOO_LARGE, _, _)); 1328 OnUnrecoverableError(QUIC_CRYPTO_CHLO_TOO_LARGE, _, _));
1330 EXPECT_DFATAL( 1329 EXPECT_QUIC_BUG(
1331 creator_.ConsumeData(1u, data_iovec, 0u, 0u, false, false, &frame), 1330 creator_.ConsumeData(1u, data_iovec, 0u, 0u, false, false, &frame),
1332 "Client hello won't fit in a single packet."); 1331 "Client hello won't fit in a single packet.");
1333 } 1332 }
1334 1333
1335 } // namespace 1334 } // namespace
1336 } // namespace test 1335 } // namespace test
1337 } // namespace net 1336 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_one_block_arena_test.cc ('k') | net/quic/core/quic_packet_generator_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698