| 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 <iostream> | 6 #include <iostream> |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 LOG(FATAL); | 191 LOG(FATAL); |
| 192 } | 192 } |
| 193 | 193 |
| 194 virtual void OnPriority(SpdyStreamId stream_id, | 194 virtual void OnPriority(SpdyStreamId stream_id, |
| 195 SpdyStreamId parent_stream_id, | 195 SpdyStreamId parent_stream_id, |
| 196 uint8 weight, | 196 uint8 weight, |
| 197 bool exclusive) OVERRIDE { | 197 bool exclusive) OVERRIDE { |
| 198 // Do nothing. | 198 // Do nothing. |
| 199 } | 199 } |
| 200 | 200 |
| 201 virtual bool OnUnknownFrame(SpdyStreamId stream_id, |
| 202 int frame_type) override { |
| 203 LOG(FATAL); |
| 204 return false; |
| 205 } |
| 206 |
| 201 char* ReleaseBuffer() { | 207 char* ReleaseBuffer() { |
| 202 CHECK(finished_); | 208 CHECK(finished_); |
| 203 return buffer_.release(); | 209 return buffer_.release(); |
| 204 } | 210 } |
| 205 | 211 |
| 206 virtual void OnWindowUpdate(SpdyStreamId stream_id, | 212 virtual void OnWindowUpdate(SpdyStreamId stream_id, |
| 207 uint32 delta_window_size) OVERRIDE { | 213 uint32 delta_window_size) OVERRIDE { |
| 208 LOG(FATAL); | 214 LOG(FATAL); |
| 209 } | 215 } |
| 210 | 216 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 headers_frame_count_(0), | 248 headers_frame_count_(0), |
| 243 push_promise_frame_count_(0), | 249 push_promise_frame_count_(0), |
| 244 goaway_count_(0), | 250 goaway_count_(0), |
| 245 setting_count_(0), | 251 setting_count_(0), |
| 246 settings_ack_sent_(0), | 252 settings_ack_sent_(0), |
| 247 settings_ack_received_(0), | 253 settings_ack_received_(0), |
| 248 continuation_count_(0), | 254 continuation_count_(0), |
| 249 altsvc_count_(0), | 255 altsvc_count_(0), |
| 250 priority_count_(0), | 256 priority_count_(0), |
| 251 test_altsvc_ir_(0), | 257 test_altsvc_ir_(0), |
| 258 on_unknown_frame_result_(false), |
| 252 last_window_update_stream_(0), | 259 last_window_update_stream_(0), |
| 253 last_window_update_delta_(0), | 260 last_window_update_delta_(0), |
| 254 last_push_promise_stream_(0), | 261 last_push_promise_stream_(0), |
| 255 last_push_promise_promised_stream_(0), | 262 last_push_promise_promised_stream_(0), |
| 256 data_bytes_(0), | 263 data_bytes_(0), |
| 257 fin_frame_count_(0), | 264 fin_frame_count_(0), |
| 258 fin_opaque_data_(), | 265 fin_opaque_data_(), |
| 259 fin_flag_count_(0), | 266 fin_flag_count_(0), |
| 260 zero_length_data_frame_count_(0), | 267 zero_length_data_frame_count_(0), |
| 261 control_frame_header_data_count_(0), | 268 control_frame_header_data_count_(0), |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 test_altsvc_ir_.set_max_age(max_age); | 438 test_altsvc_ir_.set_max_age(max_age); |
| 432 test_altsvc_ir_.set_port(port); | 439 test_altsvc_ir_.set_port(port); |
| 433 test_altsvc_ir_.set_protocol_id(protocol_id.as_string()); | 440 test_altsvc_ir_.set_protocol_id(protocol_id.as_string()); |
| 434 test_altsvc_ir_.set_host(host.as_string()); | 441 test_altsvc_ir_.set_host(host.as_string()); |
| 435 if (origin.length() > 0) { | 442 if (origin.length() > 0) { |
| 436 test_altsvc_ir_.set_origin(origin.as_string()); | 443 test_altsvc_ir_.set_origin(origin.as_string()); |
| 437 } | 444 } |
| 438 ++altsvc_count_; | 445 ++altsvc_count_; |
| 439 } | 446 } |
| 440 | 447 |
| 448 virtual void OnPriority(SpdyStreamId stream_id, |
| 449 SpdyStreamId parent_stream_id, |
| 450 uint8 weight, |
| 451 bool exclusive) OVERRIDE { |
| 452 ++priority_count_; |
| 453 } |
| 454 |
| 455 virtual bool OnUnknownFrame(SpdyStreamId stream_id, int frame_type) override { |
| 456 DLOG(INFO) << "Unknown frame type " << frame_type; |
| 457 return on_unknown_frame_result_; |
| 458 } |
| 459 |
| 441 virtual void OnSendCompressedFrame(SpdyStreamId stream_id, | 460 virtual void OnSendCompressedFrame(SpdyStreamId stream_id, |
| 442 SpdyFrameType type, | 461 SpdyFrameType type, |
| 443 size_t payload_len, | 462 size_t payload_len, |
| 444 size_t frame_len) OVERRIDE { | 463 size_t frame_len) OVERRIDE { |
| 445 last_payload_len_ = payload_len; | 464 last_payload_len_ = payload_len; |
| 446 last_frame_len_ = frame_len; | 465 last_frame_len_ = frame_len; |
| 447 } | 466 } |
| 448 | 467 |
| 449 virtual void OnPriority(SpdyStreamId stream_id, | |
| 450 SpdyStreamId parent_stream_id, | |
| 451 uint8 weight, | |
| 452 bool exclusive) OVERRIDE { | |
| 453 ++priority_count_; | |
| 454 } | |
| 455 | |
| 456 virtual void OnReceiveCompressedFrame(SpdyStreamId stream_id, | 468 virtual void OnReceiveCompressedFrame(SpdyStreamId stream_id, |
| 457 SpdyFrameType type, | 469 SpdyFrameType type, |
| 458 size_t frame_len) OVERRIDE { | 470 size_t frame_len) OVERRIDE { |
| 459 last_frame_len_ = frame_len; | 471 last_frame_len_ = frame_len; |
| 460 } | 472 } |
| 461 | 473 |
| 462 // Convenience function which runs a framer simulation with particular input. | 474 // Convenience function which runs a framer simulation with particular input. |
| 463 void SimulateInFramer(const unsigned char* input, size_t size) { | 475 void SimulateInFramer(const unsigned char* input, size_t size) { |
| 464 framer_.set_enable_compression(use_compression_); | 476 framer_.set_enable_compression(use_compression_); |
| 465 framer_.set_visitor(this); | 477 framer_.set_visitor(this); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 int headers_frame_count_; | 528 int headers_frame_count_; |
| 517 int push_promise_frame_count_; | 529 int push_promise_frame_count_; |
| 518 int goaway_count_; | 530 int goaway_count_; |
| 519 int setting_count_; | 531 int setting_count_; |
| 520 int settings_ack_sent_; | 532 int settings_ack_sent_; |
| 521 int settings_ack_received_; | 533 int settings_ack_received_; |
| 522 int continuation_count_; | 534 int continuation_count_; |
| 523 int altsvc_count_; | 535 int altsvc_count_; |
| 524 int priority_count_; | 536 int priority_count_; |
| 525 SpdyAltSvcIR test_altsvc_ir_; | 537 SpdyAltSvcIR test_altsvc_ir_; |
| 538 bool on_unknown_frame_result_; |
| 526 SpdyStreamId last_window_update_stream_; | 539 SpdyStreamId last_window_update_stream_; |
| 527 uint32 last_window_update_delta_; | 540 uint32 last_window_update_delta_; |
| 528 SpdyStreamId last_push_promise_stream_; | 541 SpdyStreamId last_push_promise_stream_; |
| 529 SpdyStreamId last_push_promise_promised_stream_; | 542 SpdyStreamId last_push_promise_promised_stream_; |
| 530 int data_bytes_; | 543 int data_bytes_; |
| 531 int fin_frame_count_; // The count of RST_STREAM type frames received. | 544 int fin_frame_count_; // The count of RST_STREAM type frames received. |
| 532 std::string fin_opaque_data_; | 545 std::string fin_opaque_data_; |
| 533 int fin_flag_count_; // The count of frames with the FIN flag set. | 546 int fin_flag_count_; // The count of frames with the FIN flag set. |
| 534 int zero_length_data_frame_count_; // The count of zero-length data frames. | 547 int zero_length_data_frame_count_; // The count of zero-length data frames. |
| 535 int control_frame_header_data_count_; // The count of chunks received. | 548 int control_frame_header_data_count_; // The count of chunks received. |
| (...skipping 2983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3519 EXPECT_EQ(1, visitor.error_count_); | 3532 EXPECT_EQ(1, visitor.error_count_); |
| 3520 } else { | 3533 } else { |
| 3521 // In SPDY 4+, duplicate settings are allowed; | 3534 // In SPDY 4+, duplicate settings are allowed; |
| 3522 // each setting replaces the previous value for that setting. | 3535 // each setting replaces the previous value for that setting. |
| 3523 EXPECT_EQ(3, visitor.setting_count_); | 3536 EXPECT_EQ(3, visitor.setting_count_); |
| 3524 EXPECT_EQ(0, visitor.error_count_); | 3537 EXPECT_EQ(0, visitor.error_count_); |
| 3525 EXPECT_EQ(1, visitor.settings_ack_sent_); | 3538 EXPECT_EQ(1, visitor.settings_ack_sent_); |
| 3526 } | 3539 } |
| 3527 } | 3540 } |
| 3528 | 3541 |
| 3542 // Tests handling of SETTINGS frame with a setting we don't recognize. |
| 3543 TEST_P(SpdyFramerTest, ReadUnknownSettingsId) { |
| 3544 SpdyFramer framer(spdy_version_); |
| 3545 |
| 3546 const unsigned char kV2FrameData[] = { |
| 3547 0x80, spdy_version_ch_, 0x00, 0x04, |
| 3548 0x00, 0x00, 0x00, 0x1C, |
| 3549 0x00, 0x00, 0x00, 0x01, |
| 3550 0x10, 0x00, 0x00, 0x00, // 1st Setting |
| 3551 0x00, 0x00, 0x00, 0x02, |
| 3552 }; |
| 3553 const unsigned char kV3FrameData[] = { |
| 3554 0x80, spdy_version_ch_, 0x00, 0x04, |
| 3555 0x00, 0x00, 0x00, 0x1C, |
| 3556 0x00, 0x00, 0x00, 0x01, |
| 3557 0x00, 0x00, 0x00, 0x10, // 1st Setting |
| 3558 0x00, 0x00, 0x00, 0x02, |
| 3559 }; |
| 3560 const unsigned char kV4FrameData[] = { |
| 3561 0x00, 0x06, 0x04, 0x00, |
| 3562 0x00, 0x00, 0x00, 0x00, |
| 3563 0x00, 0x10, // 1st Setting |
| 3564 0x00, 0x00, 0x00, 0x02, |
| 3565 }; |
| 3566 |
| 3567 TestSpdyVisitor visitor(spdy_version_); |
| 3568 visitor.use_compression_ = false; |
| 3569 if (IsSpdy2()) { |
| 3570 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); |
| 3571 } else if (IsSpdy3()) { |
| 3572 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); |
| 3573 } else { |
| 3574 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); |
| 3575 } |
| 3576 |
| 3577 if (!IsSpdy4()) { |
| 3578 EXPECT_EQ(0, visitor.setting_count_); |
| 3579 EXPECT_EQ(1, visitor.error_count_); |
| 3580 } else { |
| 3581 // In SPDY 4+, we ignore unknown settings because of extensions. |
| 3582 EXPECT_EQ(0, visitor.setting_count_); |
| 3583 EXPECT_EQ(0, visitor.error_count_); |
| 3584 } |
| 3585 } |
| 3586 |
| 3529 // Tests handling of SETTINGS frame with entries out of order. | 3587 // Tests handling of SETTINGS frame with entries out of order. |
| 3530 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { | 3588 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { |
| 3531 SpdyFramer framer(spdy_version_); | 3589 SpdyFramer framer(spdy_version_); |
| 3532 | 3590 |
| 3533 const unsigned char kV2FrameData[] = { | 3591 const unsigned char kV2FrameData[] = { |
| 3534 0x80, spdy_version_ch_, 0x00, 0x04, | 3592 0x80, spdy_version_ch_, 0x00, 0x04, |
| 3535 0x00, 0x00, 0x00, 0x1C, | 3593 0x00, 0x00, 0x00, 0x1C, |
| 3536 0x00, 0x00, 0x00, 0x03, | 3594 0x00, 0x00, 0x00, 0x03, |
| 3537 0x02, 0x00, 0x00, 0x00, // 1st Setting | 3595 0x02, 0x00, 0x00, 0x00, // 1st Setting |
| 3538 0x00, 0x00, 0x00, 0x02, | 3596 0x00, 0x00, 0x00, 0x02, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3573 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); | 3631 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); |
| 3574 } | 3632 } |
| 3575 | 3633 |
| 3576 if (!IsSpdy4()) { | 3634 if (!IsSpdy4()) { |
| 3577 EXPECT_EQ(1, visitor.setting_count_); | 3635 EXPECT_EQ(1, visitor.setting_count_); |
| 3578 EXPECT_EQ(1, visitor.error_count_); | 3636 EXPECT_EQ(1, visitor.error_count_); |
| 3579 } else { | 3637 } else { |
| 3580 // In SPDY 4+, settings are allowed in any order. | 3638 // In SPDY 4+, settings are allowed in any order. |
| 3581 EXPECT_EQ(3, visitor.setting_count_); | 3639 EXPECT_EQ(3, visitor.setting_count_); |
| 3582 EXPECT_EQ(0, visitor.error_count_); | 3640 EXPECT_EQ(0, visitor.error_count_); |
| 3583 // EXPECT_EQ(1, visitor.settings_ack_count_); | |
| 3584 } | 3641 } |
| 3585 } | 3642 } |
| 3586 | 3643 |
| 3587 TEST_P(SpdyFramerTest, ProcessSettingsAckFrame) { | 3644 TEST_P(SpdyFramerTest, ProcessSettingsAckFrame) { |
| 3588 if (spdy_version_ <= SPDY3) { | 3645 if (spdy_version_ <= SPDY3) { |
| 3589 return; | 3646 return; |
| 3590 } | 3647 } |
| 3591 SpdyFramer framer(spdy_version_); | 3648 SpdyFramer framer(spdy_version_); |
| 3592 | 3649 |
| 3593 const unsigned char kFrameData[] = { | 3650 const unsigned char kFrameData[] = { |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4118 TEST_P(SpdyFramerTest, ReadGarbage) { | 4175 TEST_P(SpdyFramerTest, ReadGarbage) { |
| 4119 SpdyFramer framer(spdy_version_); | 4176 SpdyFramer framer(spdy_version_); |
| 4120 unsigned char garbage_frame[256]; | 4177 unsigned char garbage_frame[256]; |
| 4121 memset(garbage_frame, ~0, sizeof(garbage_frame)); | 4178 memset(garbage_frame, ~0, sizeof(garbage_frame)); |
| 4122 TestSpdyVisitor visitor(spdy_version_); | 4179 TestSpdyVisitor visitor(spdy_version_); |
| 4123 visitor.use_compression_ = false; | 4180 visitor.use_compression_ = false; |
| 4124 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); | 4181 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); |
| 4125 EXPECT_EQ(1, visitor.error_count_); | 4182 EXPECT_EQ(1, visitor.error_count_); |
| 4126 } | 4183 } |
| 4127 | 4184 |
| 4185 TEST_P(SpdyFramerTest, ReadUnknownExtensionFrame) { |
| 4186 if (spdy_version_ <= SPDY3) { |
| 4187 return; |
| 4188 } |
| 4189 SpdyFramer framer(spdy_version_); |
| 4190 |
| 4191 // The unrecognized frame type should still have a valid length. |
| 4192 const unsigned char unknown_frame[] = { |
| 4193 0x00, 0x08, 0xff, 0xff, |
| 4194 0xff, 0xff, 0xff, 0xff, |
| 4195 0xff, 0xff, 0xff, 0xff, |
| 4196 0xff, 0xff, 0xff, 0xff, |
| 4197 }; |
| 4198 TestSpdyVisitor visitor(spdy_version_); |
| 4199 |
| 4200 // Simulate the case where the stream id validation checks out. |
| 4201 visitor.on_unknown_frame_result_ = true; |
| 4202 visitor.use_compression_ = false; |
| 4203 visitor.SimulateInFramer(unknown_frame, arraysize(unknown_frame)); |
| 4204 EXPECT_EQ(0, visitor.error_count_); |
| 4205 |
| 4206 // Follow it up with a valid control frame to make sure we handle |
| 4207 // subsequent frames correctly. |
| 4208 SpdySettingsIR settings_ir; |
| 4209 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 1), |
| 4210 false, // persist |
| 4211 false, // persisted |
| 4212 10); |
| 4213 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSettings(settings_ir)); |
| 4214 visitor.SimulateInFramer( |
| 4215 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 4216 control_frame->size()); |
| 4217 EXPECT_EQ(0, visitor.error_count_); |
| 4218 EXPECT_EQ(1u, static_cast<unsigned>(visitor.setting_count_)); |
| 4219 EXPECT_EQ(1u, static_cast<unsigned>(visitor.settings_ack_sent_)); |
| 4220 } |
| 4221 |
| 4128 TEST_P(SpdyFramerTest, ReadGarbageWithValidLength) { | 4222 TEST_P(SpdyFramerTest, ReadGarbageWithValidLength) { |
| 4129 if (!IsSpdy4()) { | 4223 if (!IsSpdy4()) { |
| 4130 return; | 4224 return; |
| 4131 } | 4225 } |
| 4132 SpdyFramer framer(spdy_version_); | 4226 SpdyFramer framer(spdy_version_); |
| 4133 const unsigned char kFrameData[] = { | 4227 const unsigned char kFrameData[] = { |
| 4134 0x00, 0x10, 0xff, 0xff, | 4228 0x00, 0x08, 0xff, 0xff, |
| 4135 0xff, 0xff, 0xff, 0xff, | 4229 0xff, 0xff, 0xff, 0xff, |
| 4136 0xff, 0xff, 0xff, 0xff, | 4230 0xff, 0xff, 0xff, 0xff, |
| 4137 0xff, 0xff, 0xff, 0xff, | 4231 0xff, 0xff, 0xff, 0xff, |
| 4138 }; | 4232 }; |
| 4139 TestSpdyVisitor visitor(spdy_version_); | 4233 TestSpdyVisitor visitor(spdy_version_); |
| 4140 visitor.use_compression_ = false; | 4234 visitor.use_compression_ = false; |
| 4141 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); | 4235 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); |
| 4142 EXPECT_EQ(1, visitor.error_count_); | 4236 EXPECT_EQ(1, visitor.error_count_); |
| 4143 } | 4237 } |
| 4144 | 4238 |
| (...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5422 EXPECT_EQ(4u, framer.MapWeightToPriority(109)); | 5516 EXPECT_EQ(4u, framer.MapWeightToPriority(109)); |
| 5423 EXPECT_EQ(4u, framer.MapWeightToPriority(74)); | 5517 EXPECT_EQ(4u, framer.MapWeightToPriority(74)); |
| 5424 EXPECT_EQ(5u, framer.MapWeightToPriority(73)); | 5518 EXPECT_EQ(5u, framer.MapWeightToPriority(73)); |
| 5425 EXPECT_EQ(5u, framer.MapWeightToPriority(37)); | 5519 EXPECT_EQ(5u, framer.MapWeightToPriority(37)); |
| 5426 EXPECT_EQ(6u, framer.MapWeightToPriority(36)); | 5520 EXPECT_EQ(6u, framer.MapWeightToPriority(36)); |
| 5427 EXPECT_EQ(6u, framer.MapWeightToPriority(1)); | 5521 EXPECT_EQ(6u, framer.MapWeightToPriority(1)); |
| 5428 EXPECT_EQ(7u, framer.MapWeightToPriority(0)); | 5522 EXPECT_EQ(7u, framer.MapWeightToPriority(0)); |
| 5429 } | 5523 } |
| 5430 | 5524 |
| 5431 } // namespace net | 5525 } // namespace net |
| OLD | NEW |