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

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

Issue 2963763003: In QUIC, send data is copied to streams rather than frames. Protected by FLAGS_quic_reloadable_flag… (Closed)
Patch Set: Rebase Created 3 years, 5 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_packet_generator.cc ('k') | net/quic/core/quic_session.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/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/platform/api/quic_string_piece.h"
20 #include "net/quic/platform/api/quic_test.h" 20 #include "net/quic/platform/api/quic_test.h"
21 #include "net/quic/test_tools/mock_random.h" 21 #include "net/quic/test_tools/mock_random.h"
22 #include "net/quic/test_tools/quic_packet_creator_peer.h" 22 #include "net/quic/test_tools/quic_packet_creator_peer.h"
23 #include "net/quic/test_tools/quic_packet_generator_peer.h" 23 #include "net/quic/test_tools/quic_packet_generator_peer.h"
24 #include "net/quic/test_tools/quic_test_utils.h" 24 #include "net/quic/test_tools/quic_test_utils.h"
25 #include "net/quic/test_tools/simple_data_producer.h"
25 #include "net/quic/test_tools/simple_quic_framer.h" 26 #include "net/quic/test_tools/simple_quic_framer.h"
26 27
27 using std::string; 28 using std::string;
28 using testing::InSequence; 29 using testing::InSequence;
29 using testing::Return; 30 using testing::Return;
30 using testing::StrictMock; 31 using testing::StrictMock;
31 using testing::_; 32 using testing::_;
32 33
33 namespace net { 34 namespace net {
34 namespace test { 35 namespace test {
(...skipping 27 matching lines...) Expand all
62 } 63 }
63 64
64 // Use this when only ack frames should be allowed to be written. 65 // Use this when only ack frames should be allowed to be written.
65 void SetCanWriteOnlyNonRetransmittable() { 66 void SetCanWriteOnlyNonRetransmittable() {
66 EXPECT_CALL(*this, ShouldGeneratePacket(_, _)) 67 EXPECT_CALL(*this, ShouldGeneratePacket(_, _))
67 .WillRepeatedly(Return(false)); 68 .WillRepeatedly(Return(false));
68 EXPECT_CALL(*this, ShouldGeneratePacket(NO_RETRANSMITTABLE_DATA, _)) 69 EXPECT_CALL(*this, ShouldGeneratePacket(NO_RETRANSMITTABLE_DATA, _))
69 .WillRepeatedly(Return(true)); 70 .WillRepeatedly(Return(true));
70 } 71 }
71 72
73 void SaveStreamData(QuicStreamId id,
74 QuicIOVector iov,
75 size_t iov_offset,
76 QuicStreamOffset offset,
77 QuicByteCount data_length) override {
78 producer_.SaveStreamData(id, iov, iov_offset, offset, data_length);
79 }
80 bool WriteStreamData(QuicStreamId id,
81 QuicStreamOffset offset,
82 QuicByteCount data_length,
83 QuicDataWriter* writer) override {
84 return producer_.WriteStreamData(id, offset, data_length, writer);
85 }
86
72 private: 87 private:
88 SimpleDataProducer producer_;
89
73 DISALLOW_COPY_AND_ASSIGN(MockDelegate); 90 DISALLOW_COPY_AND_ASSIGN(MockDelegate);
74 }; 91 };
75 92
76 // Simple struct for describing the contents of a packet. 93 // Simple struct for describing the contents of a packet.
77 // Useful in conjunction with a SimpleQuicFrame for validating that a packet 94 // Useful in conjunction with a SimpleQuicFrame for validating that a packet
78 // contains the expected frames. 95 // contains the expected frames.
79 struct PacketContents { 96 struct PacketContents {
80 PacketContents() 97 PacketContents()
81 : num_ack_frames(0), 98 : num_ack_frames(0),
82 num_connection_close_frames(0), 99 num_connection_close_frames(0),
(...skipping 26 matching lines...) Expand all
109 Perspective::IS_CLIENT), 126 Perspective::IS_CLIENT),
110 generator_(42, 127 generator_(42,
111 &framer_, 128 &framer_,
112 &random_generator_, 129 &random_generator_,
113 &buffer_allocator_, 130 &buffer_allocator_,
114 &delegate_), 131 &delegate_),
115 creator_(QuicPacketGeneratorPeer::GetPacketCreator(&generator_)) { 132 creator_(QuicPacketGeneratorPeer::GetPacketCreator(&generator_)) {
116 creator_->SetEncrypter(ENCRYPTION_FORWARD_SECURE, 133 creator_->SetEncrypter(ENCRYPTION_FORWARD_SECURE,
117 new NullEncrypter(Perspective::IS_CLIENT)); 134 new NullEncrypter(Perspective::IS_CLIENT));
118 creator_->set_encryption_level(ENCRYPTION_FORWARD_SECURE); 135 creator_->set_encryption_level(ENCRYPTION_FORWARD_SECURE);
136 generator_.SetDelegateSavesData(
137 FLAGS_quic_reloadable_flag_quic_stream_owns_data);
119 } 138 }
120 139
121 ~QuicPacketGeneratorTest() override { 140 ~QuicPacketGeneratorTest() override {
122 for (SerializedPacket& packet : packets_) { 141 for (SerializedPacket& packet : packets_) {
123 delete[] packet.encrypted_buffer; 142 delete[] packet.encrypted_buffer;
124 ClearSerializedPacket(&packet); 143 ClearSerializedPacket(&packet);
125 } 144 }
126 } 145 }
127 146
128 void SavePacket(SerializedPacket* packet) { 147 void SavePacket(SerializedPacket* packet) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 StrictMock<MockDelegate> delegate_; 240 StrictMock<MockDelegate> delegate_;
222 QuicPacketGenerator generator_; 241 QuicPacketGenerator generator_;
223 QuicPacketCreator* creator_; 242 QuicPacketCreator* creator_;
224 SimpleQuicFramer simple_framer_; 243 SimpleQuicFramer simple_framer_;
225 std::vector<SerializedPacket> packets_; 244 std::vector<SerializedPacket> packets_;
226 QuicAckFrame ack_frame_; 245 QuicAckFrame ack_frame_;
227 246
228 private: 247 private:
229 std::unique_ptr<char[]> data_array_; 248 std::unique_ptr<char[]> data_array_;
230 struct iovec iov_; 249 struct iovec iov_;
250 SimpleDataProducer producer_;
231 }; 251 };
232 252
233 class MockDebugDelegate : public QuicPacketCreator::DebugDelegate { 253 class MockDebugDelegate : public QuicPacketCreator::DebugDelegate {
234 public: 254 public:
235 MOCK_METHOD1(OnFrameAddedToPacket, void(const QuicFrame&)); 255 MOCK_METHOD1(OnFrameAddedToPacket, void(const QuicFrame&));
236 }; 256 };
237 257
238 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_NotWritable) { 258 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_NotWritable) {
239 delegate_.SetCanNotWrite(); 259 delegate_.SetCanNotWrite();
240 260
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 for (size_t i = 2; i < packets_.size(); ++i) { 1060 for (size_t i = 2; i < packets_.size(); ++i) {
1041 // Following packets only have paddings. 1061 // Following packets only have paddings.
1042 contents.num_stream_frames = 0; 1062 contents.num_stream_frames = 0;
1043 contents.num_padding_frames = 1; 1063 contents.num_padding_frames = 1;
1044 CheckPacketContains(contents, i); 1064 CheckPacketContains(contents, i);
1045 } 1065 }
1046 } 1066 }
1047 1067
1048 } // namespace test 1068 } // namespace test
1049 } // namespace net 1069 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_packet_generator.cc ('k') | net/quic/core/quic_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698