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 <algorithm> | 5 #include <algorithm> |
6 #include <map> | 6 #include <map> |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 class TestQuicVisitor : public ::net::QuicFramerVisitorInterface { | 181 class TestQuicVisitor : public ::net::QuicFramerVisitorInterface { |
182 public: | 182 public: |
183 TestQuicVisitor() | 183 TestQuicVisitor() |
184 : error_count_(0), | 184 : error_count_(0), |
185 version_mismatch_(0), | 185 version_mismatch_(0), |
186 packet_count_(0), | 186 packet_count_(0), |
187 frame_count_(0), | 187 frame_count_(0), |
188 fec_count_(0), | 188 fec_count_(0), |
189 complete_packets_(0), | 189 complete_packets_(0), |
190 revived_packets_(0), | 190 revived_packets_(0), |
191 accept_packet_(true) { | 191 accept_packet_(true), |
| 192 accept_public_header_(true) { |
192 } | 193 } |
193 | 194 |
194 virtual ~TestQuicVisitor() { | 195 virtual ~TestQuicVisitor() { |
195 STLDeleteElements(&stream_frames_); | 196 STLDeleteElements(&stream_frames_); |
196 STLDeleteElements(&ack_frames_); | 197 STLDeleteElements(&ack_frames_); |
197 STLDeleteElements(&congestion_feedback_frames_); | 198 STLDeleteElements(&congestion_feedback_frames_); |
198 STLDeleteElements(&fec_data_); | 199 STLDeleteElements(&fec_data_); |
199 } | 200 } |
200 | 201 |
201 virtual void OnError(QuicFramer* f) OVERRIDE { | 202 virtual void OnError(QuicFramer* f) OVERRIDE { |
(...skipping 23 matching lines...) Expand all Loading... |
225 version_mismatch_++; | 226 version_mismatch_++; |
226 return true; | 227 return true; |
227 } | 228 } |
228 | 229 |
229 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE { | 230 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE { |
230 packet_count_++; | 231 packet_count_++; |
231 header_.reset(new QuicPacketHeader(header)); | 232 header_.reset(new QuicPacketHeader(header)); |
232 return accept_packet_; | 233 return accept_packet_; |
233 } | 234 } |
234 | 235 |
| 236 virtual bool OnUnauthenticatedPublicHeader( |
| 237 const QuicPacketPublicHeader& header) OVERRIDE { |
| 238 public_header_.reset(new QuicPacketPublicHeader(header)); |
| 239 return accept_public_header_; |
| 240 } |
| 241 |
235 virtual bool OnUnauthenticatedHeader( | 242 virtual bool OnUnauthenticatedHeader( |
236 const QuicPacketHeader& header) OVERRIDE { | 243 const QuicPacketHeader& header) OVERRIDE { |
237 return true; | 244 return true; |
238 } | 245 } |
239 | 246 |
240 virtual bool OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE { | 247 virtual bool OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE { |
241 frame_count_++; | 248 frame_count_++; |
242 stream_frames_.push_back(new QuicStreamFrame(frame)); | 249 stream_frames_.push_back(new QuicStreamFrame(frame)); |
243 return true; | 250 return true; |
244 } | 251 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 295 |
289 // Counters from the visitor_ callbacks. | 296 // Counters from the visitor_ callbacks. |
290 int error_count_; | 297 int error_count_; |
291 int version_mismatch_; | 298 int version_mismatch_; |
292 int packet_count_; | 299 int packet_count_; |
293 int frame_count_; | 300 int frame_count_; |
294 int fec_count_; | 301 int fec_count_; |
295 int complete_packets_; | 302 int complete_packets_; |
296 int revived_packets_; | 303 int revived_packets_; |
297 bool accept_packet_; | 304 bool accept_packet_; |
| 305 bool accept_public_header_; |
298 | 306 |
299 scoped_ptr<QuicPacketHeader> header_; | 307 scoped_ptr<QuicPacketHeader> header_; |
| 308 scoped_ptr<QuicPacketPublicHeader> public_header_; |
300 scoped_ptr<QuicPublicResetPacket> public_reset_packet_; | 309 scoped_ptr<QuicPublicResetPacket> public_reset_packet_; |
301 scoped_ptr<QuicVersionNegotiationPacket> version_negotiation_packet_; | 310 scoped_ptr<QuicVersionNegotiationPacket> version_negotiation_packet_; |
302 vector<QuicStreamFrame*> stream_frames_; | 311 vector<QuicStreamFrame*> stream_frames_; |
303 vector<QuicAckFrame*> ack_frames_; | 312 vector<QuicAckFrame*> ack_frames_; |
304 vector<QuicCongestionFeedbackFrame*> congestion_feedback_frames_; | 313 vector<QuicCongestionFeedbackFrame*> congestion_feedback_frames_; |
305 vector<QuicFecData*> fec_data_; | 314 vector<QuicFecData*> fec_data_; |
306 string fec_protected_payload_; | 315 string fec_protected_payload_; |
307 QuicRstStreamFrame rst_stream_frame_; | 316 QuicRstStreamFrame rst_stream_frame_; |
308 QuicConnectionCloseFrame connection_close_frame_; | 317 QuicConnectionCloseFrame connection_close_frame_; |
309 QuicGoAwayFrame goaway_frame_; | 318 QuicGoAwayFrame goaway_frame_; |
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1484 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1493 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
1485 | 1494 |
1486 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1495 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
1487 ASSERT_TRUE(visitor_.header_.get()); | 1496 ASSERT_TRUE(visitor_.header_.get()); |
1488 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); | 1497 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); |
1489 | 1498 |
1490 ASSERT_EQ(0u, visitor_.stream_frames_.size()); | 1499 ASSERT_EQ(0u, visitor_.stream_frames_.size()); |
1491 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1500 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
1492 } | 1501 } |
1493 | 1502 |
| 1503 TEST_P(QuicFramerTest, RejectPublicHeader) { |
| 1504 visitor_.accept_public_header_ = false; |
| 1505 |
| 1506 unsigned char packet[] = { |
| 1507 // public flags (8 byte guid) |
| 1508 0x3C, |
| 1509 // guid |
| 1510 0x10, 0x32, 0x54, 0x76, |
| 1511 0x98, 0xBA, 0xDC, 0xFE, |
| 1512 }; |
| 1513 |
| 1514 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 1515 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1516 |
| 1517 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1518 ASSERT_TRUE(visitor_.public_header_.get()); |
| 1519 ASSERT_FALSE(visitor_.header_.get()); |
| 1520 } |
| 1521 |
1494 TEST_P(QuicFramerTest, RevivedStreamFrame) { | 1522 TEST_P(QuicFramerTest, RevivedStreamFrame) { |
1495 unsigned char payload[] = { | 1523 unsigned char payload[] = { |
1496 // frame type (stream frame with fin) | 1524 // frame type (stream frame with fin) |
1497 0xFF, | 1525 0xFF, |
1498 // stream id | 1526 // stream id |
1499 0x04, 0x03, 0x02, 0x01, | 1527 0x04, 0x03, 0x02, 0x01, |
1500 // offset | 1528 // offset |
1501 0x54, 0x76, 0x10, 0x32, | 1529 0x54, 0x76, 0x10, 0x32, |
1502 0xDC, 0xFE, 0x98, 0xBA, | 1530 0xDC, 0xFE, 0x98, 0xBA, |
1503 // data length | 1531 // data length |
(...skipping 1974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3478 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0); | 3506 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0); |
3479 EXPECT_CALL(visitor, OnPacketComplete()); | 3507 EXPECT_CALL(visitor, OnPacketComplete()); |
3480 | 3508 |
3481 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 3509 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
3482 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 3510 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
3483 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 3511 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
3484 } | 3512 } |
3485 | 3513 |
3486 } // namespace test | 3514 } // namespace test |
3487 } // namespace net | 3515 } // namespace net |
OLD | NEW |