| 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_framer.h" | 5 #include "net/quic/quic_framer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 accept_packet_(true), | 169 accept_packet_(true), |
| 170 accept_public_header_(true) { | 170 accept_public_header_(true) { |
| 171 } | 171 } |
| 172 | 172 |
| 173 ~TestQuicVisitor() override { | 173 ~TestQuicVisitor() override { |
| 174 stream_frames_.clear(); | 174 stream_frames_.clear(); |
| 175 STLDeleteElements(&ack_frames_); | 175 STLDeleteElements(&ack_frames_); |
| 176 STLDeleteElements(&stop_waiting_frames_); | 176 STLDeleteElements(&stop_waiting_frames_); |
| 177 STLDeleteElements(&ping_frames_); | 177 STLDeleteElements(&ping_frames_); |
| 178 STLDeleteElements(&fec_data_); | 178 STLDeleteElements(&fec_data_); |
| 179 STLDeleteElements(&stream_data_); | |
| 180 } | 179 } |
| 181 | 180 |
| 182 void OnError(QuicFramer* f) override { | 181 void OnError(QuicFramer* f) override { |
| 183 DVLOG(1) << "QuicFramer Error: " << QuicUtils::ErrorToString(f->error()) | 182 DVLOG(1) << "QuicFramer Error: " << QuicUtils::ErrorToString(f->error()) |
| 184 << " (" << f->error() << ")"; | 183 << " (" << f->error() << ")"; |
| 185 ++error_count_; | 184 ++error_count_; |
| 186 } | 185 } |
| 187 | 186 |
| 188 void OnPacket() override {} | 187 void OnPacket() override {} |
| 189 | 188 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 217 void OnDecryptedPacket(EncryptionLevel level) override {} | 216 void OnDecryptedPacket(EncryptionLevel level) override {} |
| 218 | 217 |
| 219 bool OnPacketHeader(const QuicPacketHeader& header) override { | 218 bool OnPacketHeader(const QuicPacketHeader& header) override { |
| 220 ++packet_count_; | 219 ++packet_count_; |
| 221 header_.reset(new QuicPacketHeader(header)); | 220 header_.reset(new QuicPacketHeader(header)); |
| 222 return accept_packet_; | 221 return accept_packet_; |
| 223 } | 222 } |
| 224 | 223 |
| 225 bool OnStreamFrame(const QuicStreamFrame& frame) override { | 224 bool OnStreamFrame(const QuicStreamFrame& frame) override { |
| 226 ++frame_count_; | 225 ++frame_count_; |
| 227 // Save a copy of the data so it is valid after the packet is processed. | 226 stream_frames_.push_back(new QuicStreamFrame(frame)); |
| 228 stream_data_.push_back(frame.GetDataAsString()); | |
| 229 QuicStreamFrame stream_frame(frame); | |
| 230 // Make sure that the stream frame points to this data. | |
| 231 stream_frame.data.Clear(); | |
| 232 stream_frame.data.Append(const_cast<char*>(stream_data_.back()->data()), | |
| 233 stream_data_.back()->size()); | |
| 234 stream_frames_.push_back(stream_frame); | |
| 235 return true; | 227 return true; |
| 236 } | 228 } |
| 237 | 229 |
| 238 void OnFecProtectedPayload(StringPiece payload) override { | 230 void OnFecProtectedPayload(StringPiece payload) override { |
| 239 fec_protected_payload_ = payload.as_string(); | 231 fec_protected_payload_ = payload.as_string(); |
| 240 } | 232 } |
| 241 | 233 |
| 242 bool OnAckFrame(const QuicAckFrame& frame) override { | 234 bool OnAckFrame(const QuicAckFrame& frame) override { |
| 243 ++frame_count_; | 235 ++frame_count_; |
| 244 ack_frames_.push_back(new QuicAckFrame(frame)); | 236 ack_frames_.push_back(new QuicAckFrame(frame)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 int fec_count_; | 289 int fec_count_; |
| 298 int complete_packets_; | 290 int complete_packets_; |
| 299 int revived_packets_; | 291 int revived_packets_; |
| 300 bool accept_packet_; | 292 bool accept_packet_; |
| 301 bool accept_public_header_; | 293 bool accept_public_header_; |
| 302 | 294 |
| 303 scoped_ptr<QuicPacketHeader> header_; | 295 scoped_ptr<QuicPacketHeader> header_; |
| 304 scoped_ptr<QuicPacketPublicHeader> public_header_; | 296 scoped_ptr<QuicPacketPublicHeader> public_header_; |
| 305 scoped_ptr<QuicPublicResetPacket> public_reset_packet_; | 297 scoped_ptr<QuicPublicResetPacket> public_reset_packet_; |
| 306 scoped_ptr<QuicVersionNegotiationPacket> version_negotiation_packet_; | 298 scoped_ptr<QuicVersionNegotiationPacket> version_negotiation_packet_; |
| 307 vector<QuicStreamFrame> stream_frames_; | 299 vector<QuicStreamFrame*> stream_frames_; |
| 308 vector<QuicAckFrame*> ack_frames_; | 300 vector<QuicAckFrame*> ack_frames_; |
| 309 vector<QuicStopWaitingFrame*> stop_waiting_frames_; | 301 vector<QuicStopWaitingFrame*> stop_waiting_frames_; |
| 310 vector<QuicPingFrame*> ping_frames_; | 302 vector<QuicPingFrame*> ping_frames_; |
| 311 vector<QuicFecData*> fec_data_; | 303 vector<QuicFecData*> fec_data_; |
| 312 string fec_protected_payload_; | 304 string fec_protected_payload_; |
| 313 QuicRstStreamFrame rst_stream_frame_; | 305 QuicRstStreamFrame rst_stream_frame_; |
| 314 QuicConnectionCloseFrame connection_close_frame_; | 306 QuicConnectionCloseFrame connection_close_frame_; |
| 315 QuicGoAwayFrame goaway_frame_; | 307 QuicGoAwayFrame goaway_frame_; |
| 316 QuicWindowUpdateFrame window_update_frame_; | 308 QuicWindowUpdateFrame window_update_frame_; |
| 317 QuicBlockedFrame blocked_frame_; | 309 QuicBlockedFrame blocked_frame_; |
| 318 vector<string*> stream_data_; | |
| 319 }; | 310 }; |
| 320 | 311 |
| 321 class QuicFramerTest : public ::testing::TestWithParam<QuicVersion> { | 312 class QuicFramerTest : public ::testing::TestWithParam<QuicVersion> { |
| 322 public: | 313 public: |
| 323 QuicFramerTest() | 314 QuicFramerTest() |
| 324 : encrypter_(new test::TestEncrypter()), | 315 : encrypter_(new test::TestEncrypter()), |
| 325 decrypter_(new test::TestDecrypter()), | 316 decrypter_(new test::TestDecrypter()), |
| 326 start_(QuicTime::Zero().Add(QuicTime::Delta::FromMicroseconds(0x10))), | 317 start_(QuicTime::Zero().Add(QuicTime::Delta::FromMicroseconds(0x10))), |
| 327 framer_(QuicSupportedVersions(), start_, true) { | 318 framer_(QuicSupportedVersions(), start_, true) { |
| 328 version_ = GetParam(); | 319 version_ = GetParam(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 size_t len, | 399 size_t len, |
| 409 string expected_error, | 400 string expected_error, |
| 410 QuicErrorCode error_code) { | 401 QuicErrorCode error_code) { |
| 411 QuicEncryptedPacket encrypted(AsChars(packet), len, false); | 402 QuicEncryptedPacket encrypted(AsChars(packet), len, false); |
| 412 EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len; | 403 EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len; |
| 413 EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; | 404 EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; |
| 414 EXPECT_EQ(error_code, framer_.error()) << "len: " << len; | 405 EXPECT_EQ(error_code, framer_.error()) << "len: " << len; |
| 415 } | 406 } |
| 416 | 407 |
| 417 // Checks if the supplied string matches data in the supplied StreamFrame. | 408 // Checks if the supplied string matches data in the supplied StreamFrame. |
| 418 void CheckStreamFrameData(string str, const QuicStreamFrame& frame) { | 409 void CheckStreamFrameData(string str, QuicStreamFrame* frame) { |
| 419 scoped_ptr<string> frame_data(frame.GetDataAsString()); | 410 scoped_ptr<string> frame_data(frame->GetDataAsString()); |
| 420 EXPECT_EQ(str, *frame_data); | 411 EXPECT_EQ(str, *frame_data); |
| 421 } | 412 } |
| 422 | 413 |
| 423 void CheckStreamFrameBoundaries(unsigned char* packet, | 414 void CheckStreamFrameBoundaries(unsigned char* packet, |
| 424 size_t stream_id_size, | 415 size_t stream_id_size, |
| 425 bool include_version) { | 416 bool include_version) { |
| 426 // Now test framing boundaries. | 417 // Now test framing boundaries. |
| 427 for (size_t i = kQuicFrameTypeSize; i < GetMinStreamFrameSize(); ++i) { | 418 for (size_t i = kQuicFrameTypeSize; i < GetMinStreamFrameSize(); ++i) { |
| 428 string expected_error; | 419 string expected_error; |
| 429 if (i < kQuicFrameTypeSize + stream_id_size) { | 420 if (i < kQuicFrameTypeSize + stream_id_size) { |
| (...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1258 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 1268 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1259 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1269 | 1260 |
| 1270 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1261 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1271 ASSERT_TRUE(visitor_.header_.get()); | 1262 ASSERT_TRUE(visitor_.header_.get()); |
| 1272 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); | 1263 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); |
| 1273 | 1264 |
| 1274 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | 1265 ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1275 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1266 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1276 EXPECT_EQ(static_cast<uint64>(0x01020304), | 1267 EXPECT_EQ(static_cast<uint64>(0x01020304), |
| 1277 visitor_.stream_frames_[0].stream_id); | 1268 visitor_.stream_frames_[0]->stream_id); |
| 1278 EXPECT_TRUE(visitor_.stream_frames_[0].fin); | 1269 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1279 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), visitor_.stream_frames_[0].offset); | 1270 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), |
| 1271 visitor_.stream_frames_[0]->offset); |
| 1280 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | 1272 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); |
| 1281 | 1273 |
| 1282 // Now test framing boundaries. | 1274 // Now test framing boundaries. |
| 1283 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, !kIncludeVersion); | 1275 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, !kIncludeVersion); |
| 1284 } | 1276 } |
| 1285 | 1277 |
| 1286 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { | 1278 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { |
| 1287 unsigned char packet[] = { | 1279 unsigned char packet[] = { |
| 1288 // public flags (8 byte connection_id) | 1280 // public flags (8 byte connection_id) |
| 1289 0x3C, | 1281 0x3C, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1313 | 1305 |
| 1314 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1306 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 1315 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1307 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1316 | 1308 |
| 1317 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1309 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1318 ASSERT_TRUE(visitor_.header_.get()); | 1310 ASSERT_TRUE(visitor_.header_.get()); |
| 1319 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); | 1311 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); |
| 1320 | 1312 |
| 1321 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | 1313 ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1322 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1314 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1323 EXPECT_EQ(GG_UINT64_C(0x00020304), visitor_.stream_frames_[0].stream_id); | 1315 EXPECT_EQ(GG_UINT64_C(0x00020304), visitor_.stream_frames_[0]->stream_id); |
| 1324 EXPECT_TRUE(visitor_.stream_frames_[0].fin); | 1316 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1325 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), visitor_.stream_frames_[0].offset); | 1317 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), |
| 1318 visitor_.stream_frames_[0]->offset); |
| 1326 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | 1319 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); |
| 1327 | 1320 |
| 1328 // Now test framing boundaries. | 1321 // Now test framing boundaries. |
| 1329 const size_t stream_id_size = 3; | 1322 const size_t stream_id_size = 3; |
| 1330 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); | 1323 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); |
| 1331 } | 1324 } |
| 1332 | 1325 |
| 1333 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { | 1326 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { |
| 1334 unsigned char packet[] = { | 1327 unsigned char packet[] = { |
| 1335 // public flags (8 byte connection_id) | 1328 // public flags (8 byte connection_id) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1361 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1354 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 1362 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1355 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1363 | 1356 |
| 1364 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1357 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1365 ASSERT_TRUE(visitor_.header_.get()); | 1358 ASSERT_TRUE(visitor_.header_.get()); |
| 1366 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); | 1359 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); |
| 1367 | 1360 |
| 1368 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | 1361 ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1369 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1362 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1370 EXPECT_EQ(static_cast<uint64>(0x00000304), | 1363 EXPECT_EQ(static_cast<uint64>(0x00000304), |
| 1371 visitor_.stream_frames_[0].stream_id); | 1364 visitor_.stream_frames_[0]->stream_id); |
| 1372 EXPECT_TRUE(visitor_.stream_frames_[0].fin); | 1365 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1373 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), visitor_.stream_frames_[0].offset); | 1366 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), |
| 1367 visitor_.stream_frames_[0]->offset); |
| 1374 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | 1368 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); |
| 1375 | 1369 |
| 1376 // Now test framing boundaries. | 1370 // Now test framing boundaries. |
| 1377 const size_t stream_id_size = 2; | 1371 const size_t stream_id_size = 2; |
| 1378 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); | 1372 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); |
| 1379 } | 1373 } |
| 1380 | 1374 |
| 1381 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { | 1375 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { |
| 1382 unsigned char packet[] = { | 1376 unsigned char packet[] = { |
| 1383 // public flags (8 byte connection_id) | 1377 // public flags (8 byte connection_id) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1409 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1403 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 1410 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1404 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1411 | 1405 |
| 1412 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1406 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1413 ASSERT_TRUE(visitor_.header_.get()); | 1407 ASSERT_TRUE(visitor_.header_.get()); |
| 1414 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); | 1408 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); |
| 1415 | 1409 |
| 1416 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | 1410 ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1417 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1411 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1418 EXPECT_EQ(static_cast<uint64>(0x00000004), | 1412 EXPECT_EQ(static_cast<uint64>(0x00000004), |
| 1419 visitor_.stream_frames_[0].stream_id); | 1413 visitor_.stream_frames_[0]->stream_id); |
| 1420 EXPECT_TRUE(visitor_.stream_frames_[0].fin); | 1414 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1421 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), visitor_.stream_frames_[0].offset); | 1415 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), |
| 1416 visitor_.stream_frames_[0]->offset); |
| 1422 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | 1417 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); |
| 1423 | 1418 |
| 1424 // Now test framing boundaries. | 1419 // Now test framing boundaries. |
| 1425 const size_t stream_id_size = 1; | 1420 const size_t stream_id_size = 1; |
| 1426 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); | 1421 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); |
| 1427 } | 1422 } |
| 1428 | 1423 |
| 1429 TEST_P(QuicFramerTest, StreamFrameWithVersion) { | 1424 TEST_P(QuicFramerTest, StreamFrameWithVersion) { |
| 1430 unsigned char packet[] = { | 1425 unsigned char packet[] = { |
| 1431 // public flags (version, 8 byte connection_id) | 1426 // public flags (version, 8 byte connection_id) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1461 | 1456 |
| 1462 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1457 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1463 ASSERT_TRUE(visitor_.header_.get()); | 1458 ASSERT_TRUE(visitor_.header_.get()); |
| 1464 EXPECT_TRUE(visitor_.header_->public_header.version_flag); | 1459 EXPECT_TRUE(visitor_.header_->public_header.version_flag); |
| 1465 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]); | 1460 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]); |
| 1466 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion)); | 1461 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion)); |
| 1467 | 1462 |
| 1468 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | 1463 ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1469 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1464 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1470 EXPECT_EQ(static_cast<uint64>(0x01020304), | 1465 EXPECT_EQ(static_cast<uint64>(0x01020304), |
| 1471 visitor_.stream_frames_[0].stream_id); | 1466 visitor_.stream_frames_[0]->stream_id); |
| 1472 EXPECT_TRUE(visitor_.stream_frames_[0].fin); | 1467 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1473 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), visitor_.stream_frames_[0].offset); | 1468 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), |
| 1469 visitor_.stream_frames_[0]->offset); |
| 1474 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | 1470 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); |
| 1475 | 1471 |
| 1476 // Now test framing boundaries. | 1472 // Now test framing boundaries. |
| 1477 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, kIncludeVersion); | 1473 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, kIncludeVersion); |
| 1478 } | 1474 } |
| 1479 | 1475 |
| 1480 TEST_P(QuicFramerTest, RejectPacket) { | 1476 TEST_P(QuicFramerTest, RejectPacket) { |
| 1481 visitor_.accept_packet_ = false; | 1477 visitor_.accept_packet_ = false; |
| 1482 | 1478 |
| 1483 unsigned char packet[] = { | 1479 unsigned char packet[] = { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 EXPECT_TRUE(visitor_.header_->entropy_flag); | 1575 EXPECT_TRUE(visitor_.header_->entropy_flag); |
| 1580 EXPECT_EQ(1 << (header.packet_sequence_number % 8), | 1576 EXPECT_EQ(1 << (header.packet_sequence_number % 8), |
| 1581 visitor_.header_->entropy_hash); | 1577 visitor_.header_->entropy_hash); |
| 1582 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), | 1578 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), |
| 1583 visitor_.header_->packet_sequence_number); | 1579 visitor_.header_->packet_sequence_number); |
| 1584 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); | 1580 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); |
| 1585 EXPECT_EQ(0x00u, visitor_.header_->fec_group); | 1581 EXPECT_EQ(0x00u, visitor_.header_->fec_group); |
| 1586 | 1582 |
| 1587 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | 1583 ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1588 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1584 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1589 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0].stream_id); | 1585 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id); |
| 1590 EXPECT_TRUE(visitor_.stream_frames_[0].fin); | 1586 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1591 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), visitor_.stream_frames_[0].offset); | 1587 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), |
| 1588 visitor_.stream_frames_[0]->offset); |
| 1592 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | 1589 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); |
| 1593 } | 1590 } |
| 1594 | 1591 |
| 1595 TEST_P(QuicFramerTest, StreamFrameInFecGroup) { | 1592 TEST_P(QuicFramerTest, StreamFrameInFecGroup) { |
| 1596 unsigned char packet[] = { | 1593 unsigned char packet[] = { |
| 1597 // public flags (8 byte connection_id) | 1594 // public flags (8 byte connection_id) |
| 1598 0x3C, | 1595 0x3C, |
| 1599 // connection_id | 1596 // connection_id |
| 1600 0x10, 0x32, 0x54, 0x76, | 1597 0x10, 0x32, 0x54, 0x76, |
| 1601 0x98, 0xBA, 0xDC, 0xFE, | 1598 0x98, 0xBA, 0xDC, 0xFE, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 const size_t fec_offset = | 1631 const size_t fec_offset = |
| 1635 GetStartOfFecProtectedData(PACKET_8BYTE_CONNECTION_ID, | 1632 GetStartOfFecProtectedData(PACKET_8BYTE_CONNECTION_ID, |
| 1636 !kIncludeVersion, | 1633 !kIncludeVersion, |
| 1637 PACKET_6BYTE_SEQUENCE_NUMBER); | 1634 PACKET_6BYTE_SEQUENCE_NUMBER); |
| 1638 EXPECT_EQ( | 1635 EXPECT_EQ( |
| 1639 string(AsChars(packet) + fec_offset, arraysize(packet) - fec_offset), | 1636 string(AsChars(packet) + fec_offset, arraysize(packet) - fec_offset), |
| 1640 visitor_.fec_protected_payload_); | 1637 visitor_.fec_protected_payload_); |
| 1641 | 1638 |
| 1642 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | 1639 ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1643 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1640 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1644 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0].stream_id); | 1641 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id); |
| 1645 EXPECT_TRUE(visitor_.stream_frames_[0].fin); | 1642 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1646 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), visitor_.stream_frames_[0].offset); | 1643 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), |
| 1644 visitor_.stream_frames_[0]->offset); |
| 1647 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | 1645 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); |
| 1648 } | 1646 } |
| 1649 | 1647 |
| 1650 TEST_P(QuicFramerTest, AckFrameTwoTimestamp) { | 1648 TEST_P(QuicFramerTest, AckFrameTwoTimestamp) { |
| 1651 unsigned char packet[] = { | 1649 unsigned char packet[] = { |
| 1652 // public flags (8 byte connection_id) | 1650 // public flags (8 byte connection_id) |
| 1653 0x3C, | 1651 0x3C, |
| 1654 // connection_id | 1652 // connection_id |
| 1655 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 1653 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 1656 // packet sequence number | 1654 // packet sequence number |
| (...skipping 2579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4236 EXPECT_CALL(visitor, OnPacketComplete()); | 4234 EXPECT_CALL(visitor, OnPacketComplete()); |
| 4237 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); | 4235 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); |
| 4238 | 4236 |
| 4239 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 4237 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 4240 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 4238 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 4241 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 4239 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4242 } | 4240 } |
| 4243 | 4241 |
| 4244 } // namespace test | 4242 } // namespace test |
| 4245 } // namespace net | 4243 } // namespace net |
| OLD | NEW |