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

Side by Side Diff: net/quic/quic_packet_generator_test.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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/quic_packet_generator.cc ('k') | net/quic/quic_protocol.h » ('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/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"
(...skipping 25 matching lines...) Expand all
36 36
37 class MockDelegate : public QuicPacketGenerator::DelegateInterface { 37 class MockDelegate : public QuicPacketGenerator::DelegateInterface {
38 public: 38 public:
39 MockDelegate() {} 39 MockDelegate() {}
40 ~MockDelegate() override {} 40 ~MockDelegate() override {}
41 41
42 MOCK_METHOD3(ShouldGeneratePacket, 42 MOCK_METHOD3(ShouldGeneratePacket,
43 bool(TransmissionType transmission_type, 43 bool(TransmissionType transmission_type,
44 HasRetransmittableData retransmittable, 44 HasRetransmittableData retransmittable,
45 IsHandshake handshake)); 45 IsHandshake handshake));
46 MOCK_METHOD0(CreateAckFrame, QuicAckFrame*()); 46 MOCK_METHOD1(PopulateAckFrame, void(QuicAckFrame*));
47 MOCK_METHOD0(CreateStopWaitingFrame, QuicStopWaitingFrame*()); 47 MOCK_METHOD1(PopulateStopWaitingFrame, void(QuicStopWaitingFrame*));
48 MOCK_METHOD1(OnSerializedPacket, void(const SerializedPacket& packet)); 48 MOCK_METHOD1(OnSerializedPacket, void(const SerializedPacket& packet));
49 MOCK_METHOD2(CloseConnection, void(QuicErrorCode, bool)); 49 MOCK_METHOD2(CloseConnection, void(QuicErrorCode, bool));
50 50
51 void SetCanWriteAnything() { 51 void SetCanWriteAnything() {
52 EXPECT_CALL(*this, ShouldGeneratePacket(NOT_RETRANSMISSION, _, _)) 52 EXPECT_CALL(*this, ShouldGeneratePacket(NOT_RETRANSMISSION, _, _))
53 .WillRepeatedly(Return(true)); 53 .WillRepeatedly(Return(true));
54 EXPECT_CALL(*this, ShouldGeneratePacket(NOT_RETRANSMISSION, 54 EXPECT_CALL(*this, ShouldGeneratePacket(NOT_RETRANSMISSION,
55 NO_RETRANSMITTABLE_DATA, _)) 55 NO_RETRANSMITTABLE_DATA, _))
56 .WillRepeatedly(Return(true)); 56 .WillRepeatedly(Return(true));
57 } 57 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 delete packet5_.packet; 130 delete packet5_.packet;
131 delete packet5_.retransmittable_frames; 131 delete packet5_.retransmittable_frames;
132 delete packet6_.packet; 132 delete packet6_.packet;
133 delete packet6_.retransmittable_frames; 133 delete packet6_.retransmittable_frames;
134 delete packet7_.packet; 134 delete packet7_.packet;
135 delete packet7_.retransmittable_frames; 135 delete packet7_.retransmittable_frames;
136 delete packet8_.packet; 136 delete packet8_.packet;
137 delete packet8_.retransmittable_frames; 137 delete packet8_.retransmittable_frames;
138 } 138 }
139 139
140 QuicAckFrame* CreateAckFrame() {
141 // TODO(rch): Initialize this so it can be verified later.
142 return new QuicAckFrame(MakeAckFrame(0));
143 }
144
145 QuicStopWaitingFrame* CreateStopWaitingFrame() {
146 QuicStopWaitingFrame* frame = new QuicStopWaitingFrame();
147 frame->entropy_hash = 0;
148 frame->least_unacked = 0;
149 return frame;
150 }
151
152 QuicRstStreamFrame* CreateRstStreamFrame() { 140 QuicRstStreamFrame* CreateRstStreamFrame() {
153 return new QuicRstStreamFrame(1, QUIC_STREAM_NO_ERROR, 0); 141 return new QuicRstStreamFrame(1, QUIC_STREAM_NO_ERROR, 0);
154 } 142 }
155 143
156 QuicGoAwayFrame* CreateGoAwayFrame() { 144 QuicGoAwayFrame* CreateGoAwayFrame() {
157 return new QuicGoAwayFrame(QUIC_NO_ERROR, 1, string()); 145 return new QuicGoAwayFrame(QUIC_NO_ERROR, 1, string());
158 } 146 }
159 147
160 void CheckPacketContains(const PacketContents& contents, 148 void CheckPacketContains(const PacketContents& contents,
161 const SerializedPacket& packet) { 149 const SerializedPacket& packet) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 EXPECT_TRUE(generator_.HasQueuedFrames()); 237 EXPECT_TRUE(generator_.HasQueuedFrames());
250 } 238 }
251 239
252 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_WritableAndShouldNotFlush) { 240 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_WritableAndShouldNotFlush) {
253 StrictMock<MockDebugDelegate> debug_delegate; 241 StrictMock<MockDebugDelegate> debug_delegate;
254 242
255 generator_.set_debug_delegate(&debug_delegate); 243 generator_.set_debug_delegate(&debug_delegate);
256 delegate_.SetCanWriteOnlyNonRetransmittable(); 244 delegate_.SetCanWriteOnlyNonRetransmittable();
257 generator_.StartBatchOperations(); 245 generator_.StartBatchOperations();
258 246
259 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame())); 247 EXPECT_CALL(delegate_, PopulateAckFrame(_));
260 EXPECT_CALL(debug_delegate, OnFrameAddedToPacket(_)).Times(1); 248 EXPECT_CALL(debug_delegate, OnFrameAddedToPacket(_)).Times(1);
261 249
262 generator_.SetShouldSendAck(false); 250 generator_.SetShouldSendAck(false);
263 EXPECT_TRUE(generator_.HasQueuedFrames()); 251 EXPECT_TRUE(generator_.HasQueuedFrames());
264 } 252 }
265 253
266 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_WritableAndShouldFlush) { 254 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_WritableAndShouldFlush) {
267 delegate_.SetCanWriteOnlyNonRetransmittable(); 255 delegate_.SetCanWriteOnlyNonRetransmittable();
268 256
269 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame())); 257 EXPECT_CALL(delegate_, PopulateAckFrame(_));
270 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet_)); 258 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet_));
271 259
272 generator_.SetShouldSendAck(false); 260 generator_.SetShouldSendAck(false);
273 EXPECT_FALSE(generator_.HasQueuedFrames()); 261 EXPECT_FALSE(generator_.HasQueuedFrames());
274 262
275 PacketContents contents; 263 PacketContents contents;
276 contents.num_ack_frames = 1; 264 contents.num_ack_frames = 1;
277 CheckPacketContains(contents, packet_); 265 CheckPacketContains(contents, packet_);
278 } 266 }
279 267
280 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_MultipleCalls) { 268 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_MultipleCalls) {
281 // Make sure that calling SetShouldSendAck multiple times does not result in a 269 // Make sure that calling SetShouldSendAck multiple times does not result in a
282 // crash. Previously this would result in multiple QuicFrames queued in the 270 // crash. Previously this would result in multiple QuicFrames queued in the
283 // packet generator, with all but the last with internal pointers to freed 271 // packet generator, with all but the last with internal pointers to freed
284 // memory. 272 // memory.
285 delegate_.SetCanWriteAnything(); 273 delegate_.SetCanWriteAnything();
286 274
287 // Only one AckFrame should be created. 275 // Only one AckFrame should be created.
288 EXPECT_CALL(delegate_, CreateAckFrame()) 276 EXPECT_CALL(delegate_, PopulateAckFrame(_)).Times(1);
289 .Times(1)
290 .WillOnce(Return(CreateAckFrame()));
291 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 277 EXPECT_CALL(delegate_, OnSerializedPacket(_))
292 .Times(1) 278 .Times(1)
293 .WillOnce(SaveArg<0>(&packet_)); 279 .WillOnce(SaveArg<0>(&packet_));
294 280
295 generator_.StartBatchOperations(); 281 generator_.StartBatchOperations();
296 generator_.SetShouldSendAck(false); 282 generator_.SetShouldSendAck(false);
297 generator_.SetShouldSendAck(false); 283 generator_.SetShouldSendAck(false);
298 generator_.FinishBatchOperations(); 284 generator_.FinishBatchOperations();
299 } 285 }
300 286
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 // Enable FEC. 850 // Enable FEC.
865 creator_->set_max_packets_per_fec_group(2); 851 creator_->set_max_packets_per_fec_group(2);
866 852
867 // Queue control frames in generator. 853 // Queue control frames in generator.
868 delegate_.SetCanNotWrite(); 854 delegate_.SetCanNotWrite();
869 generator_.SetShouldSendAck(true); 855 generator_.SetShouldSendAck(true);
870 delegate_.SetCanWriteAnything(); 856 delegate_.SetCanWriteAnything();
871 generator_.StartBatchOperations(); 857 generator_.StartBatchOperations();
872 858
873 // Set up frames to write into the creator when control frames are written. 859 // Set up frames to write into the creator when control frames are written.
874 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame())); 860 EXPECT_CALL(delegate_, PopulateAckFrame(_));
875 EXPECT_CALL(delegate_, CreateStopWaitingFrame()).WillOnce( 861 EXPECT_CALL(delegate_, PopulateStopWaitingFrame(_));
876 Return(CreateStopWaitingFrame()));
877 862
878 // Generator should have queued control frames, and creator should be empty. 863 // Generator should have queued control frames, and creator should be empty.
879 EXPECT_TRUE(generator_.HasQueuedFrames()); 864 EXPECT_TRUE(generator_.HasQueuedFrames());
880 EXPECT_FALSE(creator_->HasPendingFrames()); 865 EXPECT_FALSE(creator_->HasPendingFrames());
881 EXPECT_FALSE(creator_->IsFecProtected()); 866 EXPECT_FALSE(creator_->IsFecProtected());
882 867
883 // Queue protected data for sending. Should cause queued frames to be flushed. 868 // Queue protected data for sending. Should cause queued frames to be flushed.
884 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( 869 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(
885 SaveArg<0>(&packet_)); 870 SaveArg<0>(&packet_));
886 QuicConsumedData consumed = generator_.ConsumeData(7, CreateData(1u), 0, true, 871 QuicConsumedData consumed = generator_.ConsumeData(7, CreateData(1u), 0, true,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 1004
1020 generator_.SetShouldSendAck(false); 1005 generator_.SetShouldSendAck(false);
1021 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame())); 1006 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame()));
1022 EXPECT_TRUE(generator_.HasQueuedFrames()); 1007 EXPECT_TRUE(generator_.HasQueuedFrames());
1023 1008
1024 delegate_.SetCanWriteAnything(); 1009 delegate_.SetCanWriteAnything();
1025 1010
1026 generator_.StartBatchOperations(); 1011 generator_.StartBatchOperations();
1027 1012
1028 // When the first write operation is invoked, the ack frame will be returned. 1013 // When the first write operation is invoked, the ack frame will be returned.
1029 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame())); 1014 EXPECT_CALL(delegate_, PopulateAckFrame(_));
1030 1015
1031 // Send some data and a control frame 1016 // Send some data and a control frame
1032 generator_.ConsumeData(3, MakeIOVector("quux"), 7, false, MAY_FEC_PROTECT, 1017 generator_.ConsumeData(3, MakeIOVector("quux"), 7, false, MAY_FEC_PROTECT,
1033 nullptr); 1018 nullptr);
1034 generator_.AddControlFrame(QuicFrame(CreateGoAwayFrame())); 1019 generator_.AddControlFrame(QuicFrame(CreateGoAwayFrame()));
1035 1020
1036 // All five frames will be flushed out in a single packet. 1021 // All five frames will be flushed out in a single packet.
1037 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet_)); 1022 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet_));
1038 generator_.FinishBatchOperations(); 1023 generator_.FinishBatchOperations();
1039 EXPECT_FALSE(generator_.HasQueuedFrames()); 1024 EXPECT_FALSE(generator_.HasQueuedFrames());
(...skipping 11 matching lines...) Expand all
1051 1036
1052 generator_.SetShouldSendAck(false); 1037 generator_.SetShouldSendAck(false);
1053 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame())); 1038 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame()));
1054 EXPECT_TRUE(generator_.HasQueuedFrames()); 1039 EXPECT_TRUE(generator_.HasQueuedFrames());
1055 1040
1056 delegate_.SetCanWriteAnything(); 1041 delegate_.SetCanWriteAnything();
1057 1042
1058 generator_.StartBatchOperations(); 1043 generator_.StartBatchOperations();
1059 1044
1060 // When the first write operation is invoked, the ack frame will be returned. 1045 // When the first write operation is invoked, the ack frame will be returned.
1061 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame())); 1046 EXPECT_CALL(delegate_, PopulateAckFrame(_));
1062 1047
1063 { 1048 {
1064 InSequence dummy; 1049 InSequence dummy;
1065 // All five frames will be flushed out in a single packet 1050 // All five frames will be flushed out in a single packet
1066 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( 1051 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(
1067 SaveArg<0>(&packet_)); 1052 SaveArg<0>(&packet_));
1068 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( 1053 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(
1069 SaveArg<0>(&packet2_)); 1054 SaveArg<0>(&packet2_));
1070 } 1055 }
1071 1056
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 generator_.SetConnectionIdLength(7); 1097 generator_.SetConnectionIdLength(7);
1113 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length()); 1098 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length());
1114 generator_.SetConnectionIdLength(8); 1099 generator_.SetConnectionIdLength(8);
1115 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length()); 1100 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length());
1116 generator_.SetConnectionIdLength(9); 1101 generator_.SetConnectionIdLength(9);
1117 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length()); 1102 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length());
1118 } 1103 }
1119 1104
1120 } // namespace test 1105 } // namespace test
1121 } // namespace net 1106 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_packet_generator.cc ('k') | net/quic/quic_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698