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_connection.h" | 5 #include "net/quic/quic_connection.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 3206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3217 // Set up a larger payload than will fit in one packet. | 3217 // Set up a larger payload than will fit in one packet. |
3218 const string payload(connection_.max_packet_length(), 'a'); | 3218 const string payload(connection_.max_packet_length(), 'a'); |
3219 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)).Times(AnyNumber()); | 3219 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)).Times(AnyNumber()); |
3220 | 3220 |
3221 // Now send some packets with no truncation. | 3221 // Now send some packets with no truncation. |
3222 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 3222 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
3223 EXPECT_EQ(payload.size(), | 3223 EXPECT_EQ(payload.size(), |
3224 connection_.SendStreamDataWithString( | 3224 connection_.SendStreamDataWithString( |
3225 3, payload, 0, !kFin, nullptr).bytes_consumed); | 3225 3, payload, 0, !kFin, nullptr).bytes_consumed); |
3226 // Track the size of the second packet here. The overhead will be the largest | 3226 // Track the size of the second packet here. The overhead will be the largest |
3227 // we see in this test, due to the non-truncated CID. | 3227 // we see in this test, due to the non-truncated connection id. |
3228 size_t non_truncated_packet_size = writer_->last_packet_size(); | 3228 size_t non_truncated_packet_size = writer_->last_packet_size(); |
3229 | 3229 |
3230 // Change to a 4 byte CID. | 3230 // Change to a 4 byte connection id. |
3231 QuicConfig config; | 3231 QuicConfig config; |
3232 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 4); | 3232 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 4); |
3233 connection_.SetFromConfig(config); | 3233 connection_.SetFromConfig(config); |
3234 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 3234 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
3235 EXPECT_EQ(payload.size(), | 3235 EXPECT_EQ(payload.size(), |
3236 connection_.SendStreamDataWithString( | 3236 connection_.SendStreamDataWithString( |
3237 3, payload, 0, !kFin, nullptr).bytes_consumed); | 3237 3, payload, 0, !kFin, nullptr).bytes_consumed); |
3238 // Verify that we have 8 fewer bytes than in the non-truncated case. The | 3238 // Verify that we have 8 fewer bytes than in the non-truncated case. The |
3239 // first packet got 4 bytes of extra payload due to the truncation, and the | 3239 // first packet got 4 bytes of extra payload due to the truncation, and the |
3240 // headers here are also 4 byte smaller. | 3240 // headers here are also 4 byte smaller. |
3241 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8); | 3241 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8); |
3242 | 3242 |
3243 | 3243 // Change to a 1 byte connection id. |
3244 // Change to a 1 byte CID. | |
3245 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 1); | 3244 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 1); |
3246 connection_.SetFromConfig(config); | 3245 connection_.SetFromConfig(config); |
3247 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 3246 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
3248 EXPECT_EQ(payload.size(), | 3247 EXPECT_EQ(payload.size(), |
3249 connection_.SendStreamDataWithString( | 3248 connection_.SendStreamDataWithString( |
3250 3, payload, 0, !kFin, nullptr).bytes_consumed); | 3249 3, payload, 0, !kFin, nullptr).bytes_consumed); |
3251 // Just like above, we save 7 bytes on payload, and 7 on truncation. | 3250 // Just like above, we save 7 bytes on payload, and 7 on truncation. |
3252 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 7 * 2); | 3251 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 7 * 2); |
3253 | 3252 |
3254 // Change to a 0 byte CID. | 3253 // Change to a 0 byte connection id. |
3255 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 0); | 3254 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 0); |
3256 connection_.SetFromConfig(config); | 3255 connection_.SetFromConfig(config); |
3257 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 3256 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
3258 EXPECT_EQ(payload.size(), | 3257 EXPECT_EQ(payload.size(), |
3259 connection_.SendStreamDataWithString( | 3258 connection_.SendStreamDataWithString( |
3260 3, payload, 0, !kFin, nullptr).bytes_consumed); | 3259 3, payload, 0, !kFin, nullptr).bytes_consumed); |
3261 // Just like above, we save 8 bytes on payload, and 8 on truncation. | 3260 // Just like above, we save 8 bytes on payload, and 8 on truncation. |
3262 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8 * 2); | 3261 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8 * 2); |
3263 } | 3262 } |
3264 | 3263 |
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4352 // Regression test for b/18594622 | 4351 // Regression test for b/18594622 |
4353 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 4352 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
4354 EXPECT_DFATAL( | 4353 EXPECT_DFATAL( |
4355 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), | 4354 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), |
4356 "Attempt to send empty stream frame"); | 4355 "Attempt to send empty stream frame"); |
4357 } | 4356 } |
4358 | 4357 |
4359 } // namespace | 4358 } // namespace |
4360 } // namespace test | 4359 } // namespace test |
4361 } // namespace net | 4360 } // namespace net |
OLD | NEW |