| 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" |
| 11 #include "net/spdy/hpack_output_stream.h" | 11 #include "net/spdy/hpack_output_stream.h" |
| 12 #include "net/spdy/mock_spdy_framer_visitor.h" | 12 #include "net/spdy/mock_spdy_framer_visitor.h" |
| 13 #include "net/spdy/spdy_frame_builder.h" | 13 #include "net/spdy/spdy_frame_builder.h" |
| 14 #include "net/spdy/spdy_frame_reader.h" |
| 14 #include "net/spdy/spdy_framer.h" | 15 #include "net/spdy/spdy_framer.h" |
| 15 #include "net/spdy/spdy_protocol.h" | 16 #include "net/spdy/spdy_protocol.h" |
| 16 #include "net/spdy/spdy_test_utils.h" | 17 #include "net/spdy/spdy_test_utils.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/platform_test.h" | 19 #include "testing/platform_test.h" |
| 19 | 20 |
| 20 using base::StringPiece; | 21 using base::StringPiece; |
| 21 using std::string; | 22 using std::string; |
| 22 using std::max; | 23 using std::max; |
| 23 using std::min; | 24 using std::min; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 DISALLOW_COPY_AND_ASSIGN(DecompressionVisitor); | 215 DISALLOW_COPY_AND_ASSIGN(DecompressionVisitor); |
| 215 }; | 216 }; |
| 216 | 217 |
| 217 private: | 218 private: |
| 218 DISALLOW_COPY_AND_ASSIGN(SpdyFramerTestUtil); | 219 DISALLOW_COPY_AND_ASSIGN(SpdyFramerTestUtil); |
| 219 }; | 220 }; |
| 220 | 221 |
| 221 class TestSpdyVisitor : public SpdyFramerVisitorInterface, | 222 class TestSpdyVisitor : public SpdyFramerVisitorInterface, |
| 222 public SpdyFramerDebugVisitorInterface { | 223 public SpdyFramerDebugVisitorInterface { |
| 223 public: | 224 public: |
| 225 // This is larger than our max frame size because header blocks that |
| 226 // are too long can spill over into CONTINUATION frames. |
| 224 static const size_t kDefaultHeaderBufferSize = 16 * 1024 * 1024; | 227 static const size_t kDefaultHeaderBufferSize = 16 * 1024 * 1024; |
| 225 | 228 |
| 226 explicit TestSpdyVisitor(SpdyMajorVersion version) | 229 explicit TestSpdyVisitor(SpdyMajorVersion version) |
| 227 : framer_(version), | 230 : framer_(version), |
| 228 use_compression_(false), | 231 use_compression_(false), |
| 229 error_count_(0), | 232 error_count_(0), |
| 230 syn_frame_count_(0), | 233 syn_frame_count_(0), |
| 231 syn_reply_frame_count_(0), | 234 syn_reply_frame_count_(0), |
| 232 headers_frame_count_(0), | 235 headers_frame_count_(0), |
| 236 push_promise_frame_count_(0), |
| 233 goaway_count_(0), | 237 goaway_count_(0), |
| 234 setting_count_(0), | 238 setting_count_(0), |
| 235 settings_ack_sent_(0), | 239 settings_ack_sent_(0), |
| 236 settings_ack_received_(0), | 240 settings_ack_received_(0), |
| 237 continuation_count_(0), | 241 continuation_count_(0), |
| 238 last_window_update_stream_(0), | 242 last_window_update_stream_(0), |
| 239 last_window_update_delta_(0), | 243 last_window_update_delta_(0), |
| 240 last_push_promise_stream_(0), | 244 last_push_promise_stream_(0), |
| 241 last_push_promise_promised_stream_(0), | 245 last_push_promise_promised_stream_(0), |
| 242 data_bytes_(0), | 246 data_bytes_(0), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 253 header_buffer_length_(0), | 257 header_buffer_length_(0), |
| 254 header_buffer_size_(kDefaultHeaderBufferSize), | 258 header_buffer_size_(kDefaultHeaderBufferSize), |
| 255 header_stream_id_(-1), | 259 header_stream_id_(-1), |
| 256 header_control_type_(DATA), | 260 header_control_type_(DATA), |
| 257 header_buffer_valid_(false) { | 261 header_buffer_valid_(false) { |
| 258 } | 262 } |
| 259 | 263 |
| 260 virtual void OnError(SpdyFramer* f) OVERRIDE { | 264 virtual void OnError(SpdyFramer* f) OVERRIDE { |
| 261 LOG(INFO) << "SpdyFramer Error: " | 265 LOG(INFO) << "SpdyFramer Error: " |
| 262 << SpdyFramer::ErrorCodeToString(f->error_code()); | 266 << SpdyFramer::ErrorCodeToString(f->error_code()); |
| 263 error_count_++; | 267 ++error_count_; |
| 264 } | 268 } |
| 265 | 269 |
| 266 virtual void OnDataFrameHeader(SpdyStreamId stream_id, | 270 virtual void OnDataFrameHeader(SpdyStreamId stream_id, |
| 267 size_t length, | 271 size_t length, |
| 268 bool fin) OVERRIDE { | 272 bool fin) OVERRIDE { |
| 269 data_frame_count_++; | 273 ++data_frame_count_; |
| 270 header_stream_id_ = stream_id; | 274 header_stream_id_ = stream_id; |
| 271 } | 275 } |
| 272 | 276 |
| 273 virtual void OnStreamFrameData(SpdyStreamId stream_id, | 277 virtual void OnStreamFrameData(SpdyStreamId stream_id, |
| 274 const char* data, | 278 const char* data, |
| 275 size_t len, | 279 size_t len, |
| 276 bool fin) OVERRIDE { | 280 bool fin) OVERRIDE { |
| 277 EXPECT_EQ(header_stream_id_, stream_id); | 281 EXPECT_EQ(header_stream_id_, stream_id); |
| 278 if (len == 0) | 282 if (len == 0) |
| 279 ++zero_length_data_frame_count_; | 283 ++zero_length_data_frame_count_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 293 size_t len) OVERRIDE { | 297 size_t len) OVERRIDE { |
| 294 ++control_frame_header_data_count_; | 298 ++control_frame_header_data_count_; |
| 295 CHECK_EQ(header_stream_id_, stream_id); | 299 CHECK_EQ(header_stream_id_, stream_id); |
| 296 if (len == 0) { | 300 if (len == 0) { |
| 297 ++zero_length_control_frame_header_data_count_; | 301 ++zero_length_control_frame_header_data_count_; |
| 298 // Indicates end-of-header-block. | 302 // Indicates end-of-header-block. |
| 299 headers_.clear(); | 303 headers_.clear(); |
| 300 CHECK(header_buffer_valid_); | 304 CHECK(header_buffer_valid_); |
| 301 size_t parsed_length = framer_.ParseHeaderBlockInBuffer( | 305 size_t parsed_length = framer_.ParseHeaderBlockInBuffer( |
| 302 header_buffer_.get(), header_buffer_length_, &headers_); | 306 header_buffer_.get(), header_buffer_length_, &headers_); |
| 303 DCHECK_EQ(header_buffer_length_, parsed_length); | 307 LOG_IF(DFATAL, header_buffer_length_ != parsed_length) |
| 308 << "Check failed: header_buffer_length_ == parsed_length " |
| 309 << "(" << header_buffer_length_ << " vs. " << parsed_length << ")"; |
| 304 return true; | 310 return true; |
| 305 } | 311 } |
| 306 const size_t available = header_buffer_size_ - header_buffer_length_; | 312 const size_t available = header_buffer_size_ - header_buffer_length_; |
| 307 if (len > available) { | 313 if (len > available) { |
| 308 header_buffer_valid_ = false; | 314 header_buffer_valid_ = false; |
| 309 return false; | 315 return false; |
| 310 } | 316 } |
| 311 memcpy(header_buffer_.get() + header_buffer_length_, header_data, len); | 317 memcpy(header_buffer_.get() + header_buffer_length_, header_data, len); |
| 312 header_buffer_length_ += len; | 318 header_buffer_length_ += len; |
| 313 return true; | 319 return true; |
| 314 } | 320 } |
| 315 | 321 |
| 316 virtual void OnSynStream(SpdyStreamId stream_id, | 322 virtual void OnSynStream(SpdyStreamId stream_id, |
| 317 SpdyStreamId associated_stream_id, | 323 SpdyStreamId associated_stream_id, |
| 318 SpdyPriority priority, | 324 SpdyPriority priority, |
| 319 bool fin, | 325 bool fin, |
| 320 bool unidirectional) OVERRIDE { | 326 bool unidirectional) OVERRIDE { |
| 321 syn_frame_count_++; | 327 ++syn_frame_count_; |
| 322 InitHeaderStreaming(SYN_STREAM, stream_id); | 328 InitHeaderStreaming(SYN_STREAM, stream_id); |
| 323 if (fin) { | 329 if (fin) { |
| 324 fin_flag_count_++; | 330 ++fin_flag_count_; |
| 325 } | 331 } |
| 326 } | 332 } |
| 327 | 333 |
| 328 virtual void OnSynReply(SpdyStreamId stream_id, bool fin) OVERRIDE { | 334 virtual void OnSynReply(SpdyStreamId stream_id, bool fin) OVERRIDE { |
| 329 syn_reply_frame_count_++; | 335 ++syn_reply_frame_count_; |
| 330 InitHeaderStreaming(SYN_REPLY, stream_id); | 336 InitHeaderStreaming(SYN_REPLY, stream_id); |
| 331 if (fin) { | 337 if (fin) { |
| 332 fin_flag_count_++; | 338 ++fin_flag_count_; |
| 333 } | 339 } |
| 334 } | 340 } |
| 335 | 341 |
| 336 virtual void OnRstStream(SpdyStreamId stream_id, | 342 virtual void OnRstStream(SpdyStreamId stream_id, |
| 337 SpdyRstStreamStatus status) OVERRIDE { | 343 SpdyRstStreamStatus status) OVERRIDE { |
| 338 fin_frame_count_++; | 344 ++fin_frame_count_; |
| 339 } | 345 } |
| 340 | 346 |
| 341 virtual bool OnRstStreamFrameData(const char* rst_stream_data, | 347 virtual bool OnRstStreamFrameData(const char* rst_stream_data, |
| 342 size_t len) OVERRIDE { | 348 size_t len) OVERRIDE { |
| 343 if ((rst_stream_data != NULL) && (len > 0)) { | 349 if ((rst_stream_data != NULL) && (len > 0)) { |
| 344 fin_opaque_data_ += std::string(rst_stream_data, len); | 350 fin_opaque_data_ += std::string(rst_stream_data, len); |
| 345 } | 351 } |
| 346 return true; | 352 return true; |
| 347 } | 353 } |
| 348 | 354 |
| 349 virtual void OnSetting(SpdySettingsIds id, | 355 virtual void OnSetting(SpdySettingsIds id, |
| 350 uint8 flags, | 356 uint8 flags, |
| 351 uint32 value) OVERRIDE { | 357 uint32 value) OVERRIDE { |
| 352 setting_count_++; | 358 ++setting_count_; |
| 353 } | 359 } |
| 354 | 360 |
| 355 virtual void OnSettingsAck() OVERRIDE { | 361 virtual void OnSettingsAck() OVERRIDE { |
| 356 DCHECK_GE(4, framer_.protocol_version()); | 362 DCHECK_LT(SPDY3, framer_.protocol_version()); |
| 357 settings_ack_received_++; | 363 ++settings_ack_received_; |
| 358 } | 364 } |
| 359 | 365 |
| 360 virtual void OnSettingsEnd() OVERRIDE { | 366 virtual void OnSettingsEnd() OVERRIDE { |
| 361 if (framer_.protocol_version() < 4) { return; } | 367 if (framer_.protocol_version() <= SPDY3) { return; } |
| 362 settings_ack_sent_++; | 368 ++settings_ack_sent_; |
| 363 } | 369 } |
| 364 | 370 |
| 365 virtual void OnPing(SpdyPingId unique_id, bool is_ack) OVERRIDE { | 371 virtual void OnPing(SpdyPingId unique_id, bool is_ack) OVERRIDE { |
| 366 DLOG(FATAL); | 372 DLOG(FATAL); |
| 367 } | 373 } |
| 368 | 374 |
| 369 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id, | 375 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id, |
| 370 SpdyGoAwayStatus status) OVERRIDE { | 376 SpdyGoAwayStatus status) OVERRIDE { |
| 371 goaway_count_++; | 377 ++goaway_count_; |
| 372 } | 378 } |
| 373 | 379 |
| 374 virtual void OnHeaders(SpdyStreamId stream_id, bool fin, bool end) OVERRIDE { | 380 virtual void OnHeaders(SpdyStreamId stream_id, bool fin, bool end) OVERRIDE { |
| 375 headers_frame_count_++; | 381 ++headers_frame_count_; |
| 376 InitHeaderStreaming(HEADERS, stream_id); | 382 InitHeaderStreaming(HEADERS, stream_id); |
| 377 if (fin) { | 383 if (fin) { |
| 378 fin_flag_count_++; | 384 ++fin_flag_count_; |
| 379 } | 385 } |
| 380 } | 386 } |
| 381 | 387 |
| 382 virtual void OnWindowUpdate(SpdyStreamId stream_id, | 388 virtual void OnWindowUpdate(SpdyStreamId stream_id, |
| 383 uint32 delta_window_size) OVERRIDE { | 389 uint32 delta_window_size) OVERRIDE { |
| 384 last_window_update_stream_ = stream_id; | 390 last_window_update_stream_ = stream_id; |
| 385 last_window_update_delta_ = delta_window_size; | 391 last_window_update_delta_ = delta_window_size; |
| 386 } | 392 } |
| 387 | 393 |
| 388 virtual void OnPushPromise(SpdyStreamId stream_id, | 394 virtual void OnPushPromise(SpdyStreamId stream_id, |
| 389 SpdyStreamId promised_stream_id, | 395 SpdyStreamId promised_stream_id, |
| 390 bool end) OVERRIDE { | 396 bool end) OVERRIDE { |
| 397 ++push_promise_frame_count_; |
| 391 InitHeaderStreaming(PUSH_PROMISE, stream_id); | 398 InitHeaderStreaming(PUSH_PROMISE, stream_id); |
| 392 last_push_promise_stream_ = stream_id; | 399 last_push_promise_stream_ = stream_id; |
| 393 last_push_promise_promised_stream_ = promised_stream_id; | 400 last_push_promise_promised_stream_ = promised_stream_id; |
| 394 } | 401 } |
| 395 | 402 |
| 396 virtual void OnContinuation(SpdyStreamId stream_id, bool end) OVERRIDE { | 403 virtual void OnContinuation(SpdyStreamId stream_id, bool end) OVERRIDE { |
| 397 continuation_count_++; | 404 ++continuation_count_; |
| 398 } | 405 } |
| 399 | 406 |
| 400 virtual void OnSendCompressedFrame(SpdyStreamId stream_id, | 407 virtual void OnSendCompressedFrame(SpdyStreamId stream_id, |
| 401 SpdyFrameType type, | 408 SpdyFrameType type, |
| 402 size_t payload_len, | 409 size_t payload_len, |
| 403 size_t frame_len) OVERRIDE { | 410 size_t frame_len) OVERRIDE { |
| 404 last_payload_len_ = payload_len; | 411 last_payload_len_ = payload_len; |
| 405 last_frame_len_ = frame_len; | 412 last_frame_len_ = frame_len; |
| 406 } | 413 } |
| 407 | 414 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 } | 461 } |
| 455 | 462 |
| 456 SpdyFramer framer_; | 463 SpdyFramer framer_; |
| 457 bool use_compression_; | 464 bool use_compression_; |
| 458 | 465 |
| 459 // Counters from the visitor callbacks. | 466 // Counters from the visitor callbacks. |
| 460 int error_count_; | 467 int error_count_; |
| 461 int syn_frame_count_; | 468 int syn_frame_count_; |
| 462 int syn_reply_frame_count_; | 469 int syn_reply_frame_count_; |
| 463 int headers_frame_count_; | 470 int headers_frame_count_; |
| 471 int push_promise_frame_count_; |
| 464 int goaway_count_; | 472 int goaway_count_; |
| 465 int setting_count_; | 473 int setting_count_; |
| 466 int settings_ack_sent_; | 474 int settings_ack_sent_; |
| 467 int settings_ack_received_; | 475 int settings_ack_received_; |
| 468 int continuation_count_; | 476 int continuation_count_; |
| 469 SpdyStreamId last_window_update_stream_; | 477 SpdyStreamId last_window_update_stream_; |
| 470 uint32 last_window_update_delta_; | 478 uint32 last_window_update_delta_; |
| 471 SpdyStreamId last_push_promise_stream_; | 479 SpdyStreamId last_push_promise_stream_; |
| 472 SpdyStreamId last_push_promise_promised_stream_; | 480 SpdyStreamId last_push_promise_promised_stream_; |
| 473 int data_bytes_; | 481 int data_bytes_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 485 // Header block streaming state: | 493 // Header block streaming state: |
| 486 scoped_ptr<char[]> header_buffer_; | 494 scoped_ptr<char[]> header_buffer_; |
| 487 size_t header_buffer_length_; | 495 size_t header_buffer_length_; |
| 488 size_t header_buffer_size_; | 496 size_t header_buffer_size_; |
| 489 SpdyStreamId header_stream_id_; | 497 SpdyStreamId header_stream_id_; |
| 490 SpdyFrameType header_control_type_; | 498 SpdyFrameType header_control_type_; |
| 491 bool header_buffer_valid_; | 499 bool header_buffer_valid_; |
| 492 SpdyHeaderBlock headers_; | 500 SpdyHeaderBlock headers_; |
| 493 }; | 501 }; |
| 494 | 502 |
| 495 // Retrieves serialized headers from SYN_STREAM frame. | 503 // Retrieves serialized headers from a HEADERS or SYN_STREAM frame. |
| 496 // Does not check that the given frame is a SYN_STREAM. | |
| 497 base::StringPiece GetSerializedHeaders(const SpdyFrame* frame, | 504 base::StringPiece GetSerializedHeaders(const SpdyFrame* frame, |
| 498 const SpdyFramer& framer) { | 505 const SpdyFramer& framer) { |
| 499 return base::StringPiece(frame->data() + framer.GetSynStreamMinimumSize(), | 506 SpdyFrameReader reader(frame->data(), frame->size()); |
| 500 frame->size() - framer.GetSynStreamMinimumSize()); | 507 reader.Seek(2); // Seek past the frame length. |
| 508 SpdyFrameType frame_type; |
| 509 if (framer.protocol_version() > SPDY3) { |
| 510 uint8 serialized_type; |
| 511 reader.ReadUInt8(&serialized_type); |
| 512 frame_type = SpdyConstants::ParseFrameType(framer.protocol_version(), |
| 513 serialized_type); |
| 514 DCHECK_EQ(HEADERS, frame_type); |
| 515 uint8 flags; |
| 516 reader.ReadUInt8(&flags); |
| 517 if (flags & HEADERS_FLAG_PRIORITY) { |
| 518 frame_type = SYN_STREAM; |
| 519 } |
| 520 } else { |
| 521 uint16 serialized_type; |
| 522 reader.ReadUInt16(&serialized_type); |
| 523 frame_type = SpdyConstants::ParseFrameType(framer.protocol_version(), |
| 524 serialized_type); |
| 525 DCHECK(frame_type == HEADERS || |
| 526 frame_type == SYN_STREAM) << frame_type; |
| 527 } |
| 528 |
| 529 if (frame_type == SYN_STREAM) { |
| 530 return StringPiece(frame->data() + framer.GetSynStreamMinimumSize(), |
| 531 frame->size() - framer.GetSynStreamMinimumSize()); |
| 532 } else { |
| 533 return StringPiece(frame->data() + framer.GetHeadersMinimumSize(), |
| 534 frame->size() - framer.GetHeadersMinimumSize()); |
| 535 } |
| 501 } | 536 } |
| 502 | 537 |
| 503 } // namespace test | 538 } // namespace test |
| 504 | 539 |
| 505 } // namespace net | 540 } // namespace net |
| 506 | 541 |
| 507 using net::test::SetFrameLength; | 542 using net::test::SetFrameLength; |
| 508 using net::test::SetFrameFlags; | 543 using net::test::SetFrameFlags; |
| 509 using net::test::CompareCharArraysWithHexError; | 544 using net::test::CompareCharArraysWithHexError; |
| 510 using net::test::SpdyFramerTestUtil; | 545 using net::test::SpdyFramerTestUtil; |
| 511 using net::test::TestSpdyVisitor; | 546 using net::test::TestSpdyVisitor; |
| 512 using net::test::GetSerializedHeaders; | 547 using net::test::GetSerializedHeaders; |
| 513 | 548 |
| 514 namespace net { | 549 namespace net { |
| 515 | 550 |
| 516 class SpdyFramerTest : public ::testing::TestWithParam<SpdyMajorVersion> { | 551 class SpdyFramerTest : public ::testing::TestWithParam<SpdyMajorVersion> { |
| 517 protected: | 552 protected: |
| 518 virtual void SetUp() { | 553 virtual void SetUp() { |
| 519 spdy_version_ = GetParam(); | 554 spdy_version_ = GetParam(); |
| 520 spdy_version_ch_ = static_cast<unsigned char>(spdy_version_); | 555 spdy_version_ch_ = static_cast<unsigned char>( |
| 556 SpdyConstants::SerializeMajorVersion(spdy_version_)); |
| 521 } | 557 } |
| 522 | 558 |
| 523 void CompareFrame(const string& description, | 559 void CompareFrame(const string& description, |
| 524 const SpdyFrame& actual_frame, | 560 const SpdyFrame& actual_frame, |
| 525 const unsigned char* expected, | 561 const unsigned char* expected, |
| 526 const int expected_len) { | 562 const int expected_len) { |
| 527 const unsigned char* actual = | 563 const unsigned char* actual = |
| 528 reinterpret_cast<const unsigned char*>(actual_frame.data()); | 564 reinterpret_cast<const unsigned char*>(actual_frame.data()); |
| 529 CompareCharArraysWithHexError( | 565 CompareCharArraysWithHexError( |
| 530 description, actual, actual_frame.size(), expected, expected_len); | 566 description, actual, actual_frame.size(), expected, expected_len); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 702 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 667 EXPECT_GT(frame->size(), framer.ProcessInput(frame->data(), frame->size())); | 703 EXPECT_GT(frame->size(), framer.ProcessInput(frame->data(), frame->size())); |
| 668 EXPECT_TRUE(framer.HasError()); | 704 EXPECT_TRUE(framer.HasError()); |
| 669 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 705 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 670 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 706 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 671 } | 707 } |
| 672 | 708 |
| 673 // Test that if we receive a PUSH_PROMISE with stream ID zero, we signal an | 709 // Test that if we receive a PUSH_PROMISE with stream ID zero, we signal an |
| 674 // error (but don't crash). | 710 // error (but don't crash). |
| 675 TEST_P(SpdyFramerTest, PushPromiseWithStreamIdZero) { | 711 TEST_P(SpdyFramerTest, PushPromiseWithStreamIdZero) { |
| 676 if (spdy_version_ < SPDY4) { | 712 if (spdy_version_ <= SPDY3) { |
| 677 return; | 713 return; |
| 678 } | 714 } |
| 679 | 715 |
| 680 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 716 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 681 SpdyFramer framer(spdy_version_); | 717 SpdyFramer framer(spdy_version_); |
| 682 framer.set_visitor(&visitor); | 718 framer.set_visitor(&visitor); |
| 683 | 719 |
| 684 SpdyPushPromiseIR push_promise(0, 4); | 720 SpdyPushPromiseIR push_promise(0, 4); |
| 685 push_promise.SetHeader("alpha", "beta"); | 721 push_promise.SetHeader("alpha", "beta"); |
| 686 scoped_ptr<SpdySerializedFrame> frame( | 722 scoped_ptr<SpdySerializedFrame> frame( |
| 687 framer.SerializePushPromise(push_promise)); | 723 framer.SerializePushPromise(push_promise)); |
| 688 ASSERT_TRUE(frame.get() != NULL); | 724 ASSERT_TRUE(frame.get() != NULL); |
| 689 | 725 |
| 690 // We shouldn't have to read the whole frame before we signal an error. | 726 // We shouldn't have to read the whole frame before we signal an error. |
| 691 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 727 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 692 EXPECT_GT(frame->size(), framer.ProcessInput(frame->data(), frame->size())); | 728 EXPECT_GT(frame->size(), framer.ProcessInput(frame->data(), frame->size())); |
| 693 EXPECT_TRUE(framer.HasError()); | 729 EXPECT_TRUE(framer.HasError()); |
| 694 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 730 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 695 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 731 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 696 } | 732 } |
| 697 | 733 |
| 698 // Test that if we receive a PUSH_PROMISE with promised stream ID zero, we | 734 // Test that if we receive a PUSH_PROMISE with promised stream ID zero, we |
| 699 // signal an error (but don't crash). | 735 // signal an error (but don't crash). |
| 700 TEST_P(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) { | 736 TEST_P(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) { |
| 701 if (spdy_version_ < SPDY4) { | 737 if (spdy_version_ <= SPDY3) { |
| 702 return; | 738 return; |
| 703 } | 739 } |
| 704 | 740 |
| 705 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 741 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 706 SpdyFramer framer(spdy_version_); | 742 SpdyFramer framer(spdy_version_); |
| 707 framer.set_visitor(&visitor); | 743 framer.set_visitor(&visitor); |
| 708 | 744 |
| 709 SpdyPushPromiseIR push_promise(3, 0); | 745 SpdyPushPromiseIR push_promise(3, 0); |
| 710 push_promise.SetHeader("alpha", "beta"); | 746 push_promise.SetHeader("alpha", "beta"); |
| 711 scoped_ptr<SpdySerializedFrame> frame( | 747 scoped_ptr<SpdySerializedFrame> frame( |
| 712 framer.SerializePushPromise(push_promise)); | 748 framer.SerializePushPromise(push_promise)); |
| 713 ASSERT_TRUE(frame.get() != NULL); | 749 ASSERT_TRUE(frame.get() != NULL); |
| 714 | 750 |
| 715 // We shouldn't have to read the whole frame before we signal an error. | 751 // We shouldn't have to read the whole frame before we signal an error. |
| 716 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 752 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 717 EXPECT_GT(frame->size(), framer.ProcessInput(frame->data(), frame->size())); | 753 EXPECT_GT(frame->size(), framer.ProcessInput(frame->data(), frame->size())); |
| 718 EXPECT_TRUE(framer.HasError()); | 754 EXPECT_TRUE(framer.HasError()); |
| 719 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 755 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 720 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 756 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 721 } | 757 } |
| 722 | 758 |
| 723 TEST_P(SpdyFramerTest, DuplicateHeader) { | 759 TEST_P(SpdyFramerTest, DuplicateHeader) { |
| 724 if (spdy_version_ >= 4) { | 760 if (spdy_version_ > SPDY3) { |
| 725 // TODO(jgraettinger): Punting on this because we haven't determined | 761 // TODO(jgraettinger): Punting on this because we haven't determined |
| 726 // whether duplicate HPACK headers other than Cookie are an error. | 762 // whether duplicate HPACK headers other than Cookie are an error. |
| 727 // If they are, this will need to be updated to use HpackOutputStream. | 763 // If they are, this will need to be updated to use HpackOutputStream. |
| 728 return; | 764 return; |
| 729 } | 765 } |
| 730 SpdyFramer framer(spdy_version_); | 766 SpdyFramer framer(spdy_version_); |
| 731 // Frame builder with plentiful buffer size. | 767 // Frame builder with plentiful buffer size. |
| 732 SpdyFrameBuilder frame(1024); | 768 SpdyFrameBuilder frame(1024, spdy_version_); |
| 733 if (spdy_version_ < 4) { | 769 if (spdy_version_ <= SPDY3) { |
| 734 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE); | 770 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE); |
| 735 frame.WriteUInt32(3); // stream_id | 771 frame.WriteUInt32(3); // stream_id |
| 736 frame.WriteUInt32(0); // associated stream id | 772 frame.WriteUInt32(0); // associated stream id |
| 737 frame.WriteUInt16(0); // Priority. | 773 frame.WriteUInt16(0); // Priority. |
| 738 } else { | 774 } else { |
| 739 frame.WriteFramePrefix(framer, HEADERS, HEADERS_FLAG_PRIORITY, 3); | 775 frame.BeginNewFrame(framer, HEADERS, HEADERS_FLAG_PRIORITY, 3); |
| 740 frame.WriteUInt32(framer.GetHighestPriority()); | 776 frame.WriteUInt32(framer.GetHighestPriority()); |
| 741 } | 777 } |
| 742 | 778 |
| 743 if (IsSpdy2()) { | 779 if (IsSpdy2()) { |
| 744 frame.WriteUInt16(2); // Number of headers. | 780 frame.WriteUInt16(2); // Number of headers. |
| 745 frame.WriteString("name"); | 781 frame.WriteString("name"); |
| 746 frame.WriteString("value1"); | 782 frame.WriteString("value1"); |
| 747 frame.WriteString("name"); | 783 frame.WriteString("name"); |
| 748 frame.WriteString("value2"); | 784 frame.WriteString("value2"); |
| 749 } else { | 785 } else { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 763 GetSerializedHeaders(control_frame.get(), framer); | 799 GetSerializedHeaders(control_frame.get(), framer); |
| 764 // This should fail because duplicate headers are verboten by the spec. | 800 // This should fail because duplicate headers are verboten by the spec. |
| 765 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.data(), | 801 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.data(), |
| 766 serialized_headers.size(), | 802 serialized_headers.size(), |
| 767 &new_headers)); | 803 &new_headers)); |
| 768 } | 804 } |
| 769 | 805 |
| 770 TEST_P(SpdyFramerTest, MultiValueHeader) { | 806 TEST_P(SpdyFramerTest, MultiValueHeader) { |
| 771 SpdyFramer framer(spdy_version_); | 807 SpdyFramer framer(spdy_version_); |
| 772 // Frame builder with plentiful buffer size. | 808 // Frame builder with plentiful buffer size. |
| 773 SpdyFrameBuilder frame(1024); | 809 SpdyFrameBuilder frame(1024, spdy_version_); |
| 774 if (spdy_version_ < 4) { | 810 if (spdy_version_ <= SPDY3) { |
| 775 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE); | 811 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE); |
| 776 frame.WriteUInt32(3); // stream_id | 812 frame.WriteUInt32(3); // stream_id |
| 777 frame.WriteUInt32(0); // associated stream id | 813 frame.WriteUInt32(0); // associated stream id |
| 778 frame.WriteUInt16(0); // Priority. | 814 frame.WriteUInt16(0); // Priority. |
| 779 } else { | 815 } else { |
| 780 frame.WriteFramePrefix(framer, | 816 frame.BeginNewFrame(framer, |
| 781 HEADERS, | 817 HEADERS, |
| 782 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, | 818 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, |
| 783 3); | 819 3); |
| 784 frame.WriteUInt32(framer.GetHighestPriority()); | 820 frame.WriteUInt32(framer.GetHighestPriority()); |
| 785 } | 821 } |
| 786 | 822 |
| 787 string value("value1\0value2", 13); | 823 string value("value1\0value2", 13); |
| 788 if (IsSpdy2()) { | 824 if (IsSpdy2()) { |
| 789 frame.WriteUInt16(1); // Number of headers. | 825 frame.WriteUInt16(1); // Number of headers. |
| 790 frame.WriteString("name"); | 826 frame.WriteString("name"); |
| 791 frame.WriteString(value); | 827 frame.WriteString(value); |
| 792 } else if (spdy_version_ >= 4) { | 828 } else if (spdy_version_ > SPDY3) { |
| 793 HpackOutputStream output_stream(1024); | 829 // TODO(jgraettinger): If this pattern appears again, move to test class. |
| 794 output_stream.AppendLiteralHeaderNoIndexingWithName("name", value); | 830 std::map<string, string> header_set; |
| 831 header_set["name"] = value; |
| 795 string buffer; | 832 string buffer; |
| 796 output_stream.TakeString(&buffer); | 833 HpackEncoder encoder(ObtainHpackHuffmanTable()); |
| 834 encoder.EncodeHeaderSetWithoutCompression(header_set, &buffer); |
| 797 frame.WriteBytes(&buffer[0], buffer.size()); | 835 frame.WriteBytes(&buffer[0], buffer.size()); |
| 798 } else { | 836 } else { |
| 799 frame.WriteUInt32(1); // Number of headers. | 837 frame.WriteUInt32(1); // Number of headers. |
| 800 frame.WriteStringPiece32("name"); | 838 frame.WriteStringPiece32("name"); |
| 801 frame.WriteStringPiece32(value); | 839 frame.WriteStringPiece32(value); |
| 802 } | 840 } |
| 803 // write the length | 841 // write the length |
| 804 frame.RewriteLength(framer); | 842 frame.RewriteLength(framer); |
| 805 | 843 |
| 806 framer.set_enable_compression(false); | 844 framer.set_enable_compression(false); |
| 807 scoped_ptr<SpdyFrame> control_frame(frame.take()); | 845 scoped_ptr<SpdyFrame> control_frame(frame.take()); |
| 808 | 846 |
| 809 TestSpdyVisitor visitor(spdy_version_); | 847 TestSpdyVisitor visitor(spdy_version_); |
| 810 visitor.use_compression_ = false; | 848 visitor.use_compression_ = false; |
| 811 visitor.SimulateInFramer( | 849 visitor.SimulateInFramer( |
| 812 reinterpret_cast<unsigned char*>(control_frame->data()), | 850 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 813 control_frame->size()); | 851 control_frame->size()); |
| 814 | 852 |
| 815 EXPECT_THAT(visitor.headers_, ElementsAre( | 853 EXPECT_THAT(visitor.headers_, ElementsAre( |
| 816 Pair("name", value))); | 854 Pair("name", value))); |
| 817 } | 855 } |
| 818 | 856 |
| 819 TEST_P(SpdyFramerTest, BasicCompression) { | 857 TEST_P(SpdyFramerTest, BasicCompression) { |
| 820 if (spdy_version_ >= 4) { | 858 if (spdy_version_ > SPDY3) { |
| 821 // Deflate compression doesn't apply to HPACK. | 859 // Deflate compression doesn't apply to HPACK. |
| 822 return; | 860 return; |
| 823 } | 861 } |
| 824 scoped_ptr<TestSpdyVisitor> visitor(new TestSpdyVisitor(spdy_version_)); | 862 scoped_ptr<TestSpdyVisitor> visitor(new TestSpdyVisitor(spdy_version_)); |
| 825 SpdyFramer framer(spdy_version_); | 863 SpdyFramer framer(spdy_version_); |
| 826 framer.set_debug_visitor(visitor.get()); | 864 framer.set_debug_visitor(visitor.get()); |
| 827 SpdySynStreamIR syn_stream(1); | 865 SpdySynStreamIR syn_stream(1); |
| 828 syn_stream.set_priority(1); | 866 syn_stream.set_priority(1); |
| 829 syn_stream.SetHeader("server", "SpdyServer 1.0"); | 867 syn_stream.SetHeader("server", "SpdyServer 1.0"); |
| 830 syn_stream.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); | 868 syn_stream.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 0xde, 0xad, 0xbe, 0xef, | 993 0xde, 0xad, 0xbe, 0xef, |
| 956 0xde, 0xad, 0xbe, 0xef, | 994 0xde, 0xad, 0xbe, 0xef, |
| 957 | 995 |
| 958 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | 996 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 |
| 959 0x00, 0x00, 0x00, 0x04, | 997 0x00, 0x00, 0x00, 0x04, |
| 960 0xde, 0xad, 0xbe, 0xef, | 998 0xde, 0xad, 0xbe, 0xef, |
| 961 | 999 |
| 962 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #1 | 1000 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #1 |
| 963 0x00, 0x00, 0x00, 0x08, | 1001 0x00, 0x00, 0x00, 0x08, |
| 964 0x00, 0x00, 0x00, 0x01, | 1002 0x00, 0x00, 0x00, 0x01, |
| 965 0x00, 0x00, 0x00, 0x00, | 1003 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL |
| 966 | 1004 |
| 967 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 | 1005 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 |
| 968 0x00, 0x00, 0x00, 0x00, | 1006 0x00, 0x00, 0x00, 0x00, |
| 969 | 1007 |
| 970 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 | 1008 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 |
| 971 0x00, 0x00, 0x00, 0x08, | 1009 0x00, 0x00, 0x00, 0x08, |
| 972 0x00, 0x00, 0x00, 0x03, | 1010 0x00, 0x00, 0x00, 0x03, |
| 973 0x00, 0x00, 0x00, 0x00, | 1011 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL |
| 974 }; | 1012 }; |
| 975 | 1013 |
| 976 const unsigned char kV3Input[] = { | 1014 const unsigned char kV3Input[] = { |
| 977 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 | 1015 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 |
| 978 0x00, 0x00, 0x00, 0x1a, | 1016 0x00, 0x00, 0x00, 0x1a, |
| 979 0x00, 0x00, 0x00, 0x01, | 1017 0x00, 0x00, 0x00, 0x01, |
| 980 0x00, 0x00, 0x00, 0x00, | 1018 0x00, 0x00, 0x00, 0x00, |
| 981 0x00, 0x00, 0x00, 0x00, | 1019 0x00, 0x00, 0x00, 0x00, |
| 982 0x00, 0x01, 0x00, 0x00, | 1020 0x00, 0x01, 0x00, 0x00, |
| 983 0x00, 0x02, 'h', 'h', | 1021 0x00, 0x02, 'h', 'h', |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1014 0xde, 0xad, 0xbe, 0xef, | 1052 0xde, 0xad, 0xbe, 0xef, |
| 1015 0xde, 0xad, 0xbe, 0xef, | 1053 0xde, 0xad, 0xbe, 0xef, |
| 1016 | 1054 |
| 1017 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | 1055 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 |
| 1018 0x00, 0x00, 0x00, 0x04, | 1056 0x00, 0x00, 0x00, 0x04, |
| 1019 0xde, 0xad, 0xbe, 0xef, | 1057 0xde, 0xad, 0xbe, 0xef, |
| 1020 | 1058 |
| 1021 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #1 | 1059 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #1 |
| 1022 0x00, 0x00, 0x00, 0x08, | 1060 0x00, 0x00, 0x00, 0x08, |
| 1023 0x00, 0x00, 0x00, 0x01, | 1061 0x00, 0x00, 0x00, 0x01, |
| 1024 0x00, 0x00, 0x00, 0x00, | 1062 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL |
| 1025 | 1063 |
| 1026 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 | 1064 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 |
| 1027 0x00, 0x00, 0x00, 0x00, | 1065 0x00, 0x00, 0x00, 0x00, |
| 1028 | 1066 |
| 1029 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 | 1067 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 |
| 1030 0x00, 0x00, 0x00, 0x08, | 1068 0x00, 0x00, 0x00, 0x08, |
| 1031 0x00, 0x00, 0x00, 0x03, | 1069 0x00, 0x00, 0x00, 0x03, |
| 1032 0x00, 0x00, 0x00, 0x00, | 1070 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL |
| 1033 }; | 1071 }; |
| 1034 | 1072 |
| 1035 // SYN_STREAM doesn't exist in SPDY4, so instead we send | 1073 // SYN_STREAM doesn't exist in SPDY4, so instead we send |
| 1036 // HEADERS frames with PRIORITY and END_HEADERS set. | 1074 // HEADERS frames with PRIORITY and END_HEADERS set. |
| 1037 const unsigned char kV4Input[] = { | 1075 const unsigned char kV4Input[] = { |
| 1038 0x00, 0x05, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS | 1076 0x00, 0x05, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS |
| 1039 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1077 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 1040 0x00, 0x00, 0x00, 0x00, // Priority 0 | 1078 0x00, 0x00, 0x00, 0x00, // Priority 0 |
| 1041 0x82, // :method: GET | 1079 0x82, // :method: GET |
| 1042 | 1080 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1059 0x00, 0x00, 0x00, 0x03, | 1097 0x00, 0x00, 0x00, 0x03, |
| 1060 0xde, 0xad, 0xbe, 0xef, | 1098 0xde, 0xad, 0xbe, 0xef, |
| 1061 0xde, 0xad, 0xbe, 0xef, | 1099 0xde, 0xad, 0xbe, 0xef, |
| 1062 | 1100 |
| 1063 0x00, 0x04, 0x00, 0x00, // DATA on Stream #1 | 1101 0x00, 0x04, 0x00, 0x00, // DATA on Stream #1 |
| 1064 0x00, 0x00, 0x00, 0x01, | 1102 0x00, 0x00, 0x00, 0x01, |
| 1065 0xde, 0xad, 0xbe, 0xef, | 1103 0xde, 0xad, 0xbe, 0xef, |
| 1066 | 1104 |
| 1067 0x00, 0x04, 0x03, 0x00, // RST_STREAM on Stream #1 | 1105 0x00, 0x04, 0x03, 0x00, // RST_STREAM on Stream #1 |
| 1068 0x00, 0x00, 0x00, 0x01, | 1106 0x00, 0x00, 0x00, 0x01, |
| 1069 0x00, 0x00, 0x00, 0x00, | 1107 0x00, 0x00, 0x00, 0x08, // RST_STREAM_CANCEL |
| 1070 | 1108 |
| 1071 0x00, 0x00, 0x00, 0x00, // DATA on Stream #3 | 1109 0x00, 0x00, 0x00, 0x00, // DATA on Stream #3 |
| 1072 0x00, 0x00, 0x00, 0x03, | 1110 0x00, 0x00, 0x00, 0x03, |
| 1073 | 1111 |
| 1074 0x00, 0x0f, 0x03, 0x00, // RST_STREAM on Stream #3 | 1112 0x00, 0x0f, 0x03, 0x00, // RST_STREAM on Stream #3 |
| 1075 0x00, 0x00, 0x00, 0x03, | 1113 0x00, 0x00, 0x00, 0x03, |
| 1076 0x00, 0x00, 0x00, 0x00, | 1114 0x00, 0x00, 0x00, 0x08, // RST_STREAM_CANCEL |
| 1077 0x52, 0x45, 0x53, 0x45, // opaque data | 1115 0x52, 0x45, 0x53, 0x45, // opaque data |
| 1078 0x54, 0x53, 0x54, 0x52, | 1116 0x54, 0x53, 0x54, 0x52, |
| 1079 0x45, 0x41, 0x4d, | 1117 0x45, 0x41, 0x4d, |
| 1080 }; | 1118 }; |
| 1081 | 1119 |
| 1082 TestSpdyVisitor visitor(spdy_version_); | 1120 TestSpdyVisitor visitor(spdy_version_); |
| 1083 if (IsSpdy2()) { | 1121 if (IsSpdy2()) { |
| 1084 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); | 1122 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); |
| 1085 } else if (IsSpdy3()) { | 1123 } else if (IsSpdy3()) { |
| 1086 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); | 1124 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 EXPECT_EQ(0, visitor.headers_frame_count_); | 1323 EXPECT_EQ(0, visitor.headers_frame_count_); |
| 1286 } | 1324 } |
| 1287 EXPECT_EQ(0, visitor.data_bytes_); | 1325 EXPECT_EQ(0, visitor.data_bytes_); |
| 1288 EXPECT_EQ(0, visitor.fin_frame_count_); | 1326 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1289 EXPECT_EQ(1, visitor.fin_flag_count_); | 1327 EXPECT_EQ(1, visitor.fin_flag_count_); |
| 1290 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 1328 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
| 1291 EXPECT_EQ(0, visitor.data_frame_count_); | 1329 EXPECT_EQ(0, visitor.data_frame_count_); |
| 1292 } | 1330 } |
| 1293 | 1331 |
| 1294 TEST_P(SpdyFramerTest, HeaderCompression) { | 1332 TEST_P(SpdyFramerTest, HeaderCompression) { |
| 1295 if (spdy_version_ >= 4) { | 1333 if (spdy_version_ > SPDY3) { |
| 1296 // Deflate compression doesn't apply to HPACK. | 1334 // Deflate compression doesn't apply to HPACK. |
| 1297 return; | 1335 return; |
| 1298 } | 1336 } |
| 1299 SpdyFramer send_framer(spdy_version_); | 1337 SpdyFramer send_framer(spdy_version_); |
| 1300 SpdyFramer recv_framer(spdy_version_); | 1338 SpdyFramer recv_framer(spdy_version_); |
| 1301 | 1339 |
| 1302 send_framer.set_enable_compression(true); | 1340 send_framer.set_enable_compression(true); |
| 1303 recv_framer.set_enable_compression(true); | 1341 recv_framer.set_enable_compression(true); |
| 1304 | 1342 |
| 1305 const char kHeader1[] = "header1"; | 1343 const char kHeader1[] = "header1"; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 const char kValue1[] = "value1"; | 1407 const char kValue1[] = "value1"; |
| 1370 const char kValue2[] = "value2"; | 1408 const char kValue2[] = "value2"; |
| 1371 | 1409 |
| 1372 SpdySynStreamIR syn_stream(1); | 1410 SpdySynStreamIR syn_stream(1); |
| 1373 syn_stream.SetHeader(kHeader1, kValue1); | 1411 syn_stream.SetHeader(kHeader1, kValue1); |
| 1374 syn_stream.SetHeader(kHeader2, kValue2); | 1412 syn_stream.SetHeader(kHeader2, kValue2); |
| 1375 scoped_ptr<SpdyFrame> syn_frame(send_framer.SerializeSynStream(syn_stream)); | 1413 scoped_ptr<SpdyFrame> syn_frame(send_framer.SerializeSynStream(syn_stream)); |
| 1376 EXPECT_TRUE(syn_frame.get() != NULL); | 1414 EXPECT_TRUE(syn_frame.get() != NULL); |
| 1377 | 1415 |
| 1378 StringPiece bytes = "this is a test test test test test!"; | 1416 StringPiece bytes = "this is a test test test test test!"; |
| 1379 net::SpdyDataIR data_ir(1, bytes); | 1417 SpdyDataIR data_ir(1, bytes); |
| 1380 data_ir.set_fin(true); | 1418 data_ir.set_fin(true); |
| 1381 scoped_ptr<SpdyFrame> send_frame(send_framer.SerializeData(data_ir)); | 1419 scoped_ptr<SpdyFrame> send_frame(send_framer.SerializeData(data_ir)); |
| 1382 EXPECT_TRUE(send_frame.get() != NULL); | 1420 EXPECT_TRUE(send_frame.get() != NULL); |
| 1383 | 1421 |
| 1384 // Run the inputs through the framer. | 1422 // Run the inputs through the framer. |
| 1385 TestSpdyVisitor visitor(spdy_version_); | 1423 TestSpdyVisitor visitor(spdy_version_); |
| 1386 visitor.use_compression_ = true; | 1424 visitor.use_compression_ = true; |
| 1387 const unsigned char* data; | 1425 const unsigned char* data; |
| 1388 data = reinterpret_cast<const unsigned char*>(syn_frame->data()); | 1426 data = reinterpret_cast<const unsigned char*>(syn_frame->data()); |
| 1389 visitor.SimulateInFramer(data, syn_frame->size()); | 1427 visitor.SimulateInFramer(data, syn_frame->size()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1413 const char kValue1[] = "value1"; | 1451 const char kValue1[] = "value1"; |
| 1414 const char kValue2[] = "value2"; | 1452 const char kValue2[] = "value2"; |
| 1415 | 1453 |
| 1416 SpdySynStreamIR syn_stream(1); | 1454 SpdySynStreamIR syn_stream(1); |
| 1417 syn_stream.SetHeader(kHeader1, kValue1); | 1455 syn_stream.SetHeader(kHeader1, kValue1); |
| 1418 syn_stream.SetHeader(kHeader2, kValue2); | 1456 syn_stream.SetHeader(kHeader2, kValue2); |
| 1419 scoped_ptr<SpdyFrame> syn_frame(send_framer.SerializeSynStream(syn_stream)); | 1457 scoped_ptr<SpdyFrame> syn_frame(send_framer.SerializeSynStream(syn_stream)); |
| 1420 EXPECT_TRUE(syn_frame.get() != NULL); | 1458 EXPECT_TRUE(syn_frame.get() != NULL); |
| 1421 | 1459 |
| 1422 const char bytes[] = "this is a test test test test test!"; | 1460 const char bytes[] = "this is a test test test test test!"; |
| 1423 net::SpdyDataIR data_ir(1, StringPiece(bytes, arraysize(bytes))); | 1461 SpdyDataIR data_ir(1, StringPiece(bytes, arraysize(bytes))); |
| 1424 data_ir.set_fin(true); | 1462 data_ir.set_fin(true); |
| 1425 scoped_ptr<SpdyFrame> send_frame(send_framer.SerializeData(data_ir)); | 1463 scoped_ptr<SpdyFrame> send_frame(send_framer.SerializeData(data_ir)); |
| 1426 EXPECT_TRUE(send_frame.get() != NULL); | 1464 EXPECT_TRUE(send_frame.get() != NULL); |
| 1427 | 1465 |
| 1428 // Run the inputs through the framer. | 1466 // Run the inputs through the framer. |
| 1429 TestSpdyVisitor visitor(spdy_version_); | 1467 TestSpdyVisitor visitor(spdy_version_); |
| 1430 visitor.use_compression_ = true; | 1468 visitor.use_compression_ = true; |
| 1431 const unsigned char* data; | 1469 const unsigned char* data; |
| 1432 data = reinterpret_cast<const unsigned char*>(syn_frame->data()); | 1470 data = reinterpret_cast<const unsigned char*>(syn_frame->data()); |
| 1433 for (size_t idx = 0; idx < syn_frame->size(); ++idx) { | 1471 for (size_t idx = 0; idx < syn_frame->size(); ++idx) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1447 EXPECT_EQ(arraysize(bytes), static_cast<unsigned>(visitor.data_bytes_)); | 1485 EXPECT_EQ(arraysize(bytes), static_cast<unsigned>(visitor.data_bytes_)); |
| 1448 EXPECT_EQ(0, visitor.fin_frame_count_); | 1486 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1449 EXPECT_EQ(0, visitor.fin_flag_count_); | 1487 EXPECT_EQ(0, visitor.fin_flag_count_); |
| 1450 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 1488 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
| 1451 EXPECT_EQ(1, visitor.data_frame_count_); | 1489 EXPECT_EQ(1, visitor.data_frame_count_); |
| 1452 } | 1490 } |
| 1453 | 1491 |
| 1454 TEST_P(SpdyFramerTest, WindowUpdateFrame) { | 1492 TEST_P(SpdyFramerTest, WindowUpdateFrame) { |
| 1455 SpdyFramer framer(spdy_version_); | 1493 SpdyFramer framer(spdy_version_); |
| 1456 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( | 1494 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( |
| 1457 net::SpdyWindowUpdateIR(1, 0x12345678))); | 1495 SpdyWindowUpdateIR(1, 0x12345678))); |
| 1458 | 1496 |
| 1459 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678"; | 1497 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678"; |
| 1460 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1498 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 1461 0x80, spdy_version_ch_, 0x00, 0x09, | 1499 0x80, spdy_version_ch_, 0x00, 0x09, |
| 1462 0x00, 0x00, 0x00, 0x08, | 1500 0x00, 0x00, 0x00, 0x08, |
| 1463 0x00, 0x00, 0x00, 0x01, | 1501 0x00, 0x00, 0x00, 0x01, |
| 1464 0x12, 0x34, 0x56, 0x78 | 1502 0x12, 0x34, 0x56, 0x78 |
| 1465 }; | 1503 }; |
| 1466 const unsigned char kV4FrameData[] = { | 1504 const unsigned char kV4FrameData[] = { |
| 1467 0x00, 0x04, 0x08, 0x00, | 1505 0x00, 0x04, 0x08, 0x00, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1500 if (IsSpdy4()) { | 1538 if (IsSpdy4()) { |
| 1501 CompareFrame( | 1539 CompareFrame( |
| 1502 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1540 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1503 } else { | 1541 } else { |
| 1504 CompareFrame( | 1542 CompareFrame( |
| 1505 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1543 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1506 } | 1544 } |
| 1507 | 1545 |
| 1508 SpdyDataIR data_header_ir(1); | 1546 SpdyDataIR data_header_ir(1); |
| 1509 data_header_ir.SetDataShallow(base::StringPiece(bytes, strlen(bytes))); | 1547 data_header_ir.SetDataShallow(base::StringPiece(bytes, strlen(bytes))); |
| 1510 frame.reset(framer.SerializeDataFrameHeader(data_header_ir)); | 1548 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField( |
| 1549 data_header_ir)); |
| 1511 CompareCharArraysWithHexError( | 1550 CompareCharArraysWithHexError( |
| 1512 kDescription, | 1551 kDescription, |
| 1513 reinterpret_cast<const unsigned char*>(frame->data()), | 1552 reinterpret_cast<const unsigned char*>(frame->data()), |
| 1553 framer.GetDataFrameMinimumSize(), |
| 1554 IsSpdy4() ? kV4FrameData : kV3FrameData, |
| 1555 framer.GetDataFrameMinimumSize()); |
| 1556 } |
| 1557 |
| 1558 { |
| 1559 const char kDescription[] = "'hello' data frame with more padding, no FIN"; |
| 1560 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 1561 0x00, 0x00, 0x00, 0x01, |
| 1562 0x00, 0x00, 0x00, 0x05, |
| 1563 'h', 'e', 'l', 'l', |
| 1564 'o' |
| 1565 }; |
| 1566 |
| 1567 const unsigned char kV4FrameData[] = { |
| 1568 0x01, 0x0b, 0x00, 0x30, // Length = 267. PAD_HIGH and PAD_LOW set. |
| 1569 0x00, 0x00, 0x00, 0x01, |
| 1570 0x01, 0x04, // Pad Low and Pad High fields. |
| 1571 'h', 'e', 'l', 'l', // Data |
| 1572 'o', |
| 1573 // Padding of 260 zeros (so both PAD_HIGH and PAD_LOW fields are used). |
| 1574 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1575 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1576 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1577 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1578 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1579 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1580 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1581 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1582 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1583 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1584 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1585 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1586 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1587 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1588 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1589 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1590 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1591 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1592 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1593 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1594 }; |
| 1595 const char bytes[] = "hello"; |
| 1596 |
| 1597 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
| 1598 // 260 zeros and the pad low/high fields make the overall padding to be 262 |
| 1599 // bytes. |
| 1600 data_ir.set_padding_len(262); |
| 1601 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1602 if (IsSpdy4()) { |
| 1603 CompareFrame( |
| 1604 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1605 } else { |
| 1606 CompareFrame( |
| 1607 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1608 } |
| 1609 |
| 1610 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); |
| 1611 CompareCharArraysWithHexError( |
| 1612 kDescription, |
| 1613 reinterpret_cast<const unsigned char*>(frame->data()), |
| 1514 framer.GetDataFrameMinimumSize(), | 1614 framer.GetDataFrameMinimumSize(), |
| 1515 IsSpdy4() ? kV4FrameData : kV3FrameData, | 1615 IsSpdy4() ? kV4FrameData : kV3FrameData, |
| 1516 framer.GetDataFrameMinimumSize()); | 1616 framer.GetDataFrameMinimumSize()); |
| 1517 } | 1617 } |
| 1518 | 1618 |
| 1519 { | 1619 { |
| 1520 const char kDescription[] = "'hello' data frame with padding, no FIN"; | 1620 const char kDescription[] = "'hello' data frame with few padding, no FIN"; |
| 1521 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1621 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 1522 0x00, 0x00, 0x00, 0x01, | 1622 0x00, 0x00, 0x00, 0x01, |
| 1523 0x00, 0x00, 0x00, 0x05, | 1623 0x00, 0x00, 0x00, 0x05, |
| 1524 'h', 'e', 'l', 'l', | 1624 'h', 'e', 'l', 'l', |
| 1525 'o' | 1625 'o' |
| 1526 }; | 1626 }; |
| 1527 | 1627 |
| 1528 const unsigned char kV4FrameData[] = { | 1628 const unsigned char kV4FrameData[] = { |
| 1529 0x00, 0x0d, 0x00, 0x10, // Length = 13. PAD_LOW set. | 1629 0x00, 0x0d, 0x00, 0x10, // Length = 13. PAD_LOW set. |
| 1530 0x00, 0x00, 0x00, 0x01, | 1630 0x00, 0x00, 0x00, 0x01, |
| 1531 0x07, // Pad Low field. | 1631 0x07, // Pad Low field. |
| 1532 'h', 'e', 'l', 'l', // Data | 1632 'h', 'e', 'l', 'l', // Data |
| 1533 'o', | 1633 'o', |
| 1534 '0', '0', '0', '0', // Padding | 1634 '0', '0', '0', '0', // Padding |
| 1535 '0', '0', '0' | 1635 '0', '0', '0' |
| 1536 }; | 1636 }; |
| 1537 const char bytes[] = "hello"; | 1637 const char bytes[] = "hello"; |
| 1538 | 1638 |
| 1539 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); | 1639 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
| 1540 // 7 zeros and the pad low field make the overal padding to be 8 bytes. | 1640 // 7 zeros and the pad low field make the overall padding to be 8 bytes. |
| 1541 data_ir.set_padding_len(8); | 1641 data_ir.set_padding_len(8); |
| 1542 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1642 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1543 if (IsSpdy4()) { | 1643 if (IsSpdy4()) { |
| 1544 CompareFrame( | 1644 CompareFrame( |
| 1545 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1645 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1546 } else { | 1646 } else { |
| 1547 CompareFrame( | 1647 CompareFrame( |
| 1548 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1648 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1549 } | 1649 } |
| 1550 } | 1650 } |
| 1551 | 1651 |
| 1552 { | 1652 { |
| 1653 const char kDescription[] = |
| 1654 "'hello' data frame with 1 byte padding, no FIN"; |
| 1655 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 1656 0x00, 0x00, 0x00, 0x01, |
| 1657 0x00, 0x00, 0x00, 0x05, |
| 1658 'h', 'e', 'l', 'l', |
| 1659 'o' |
| 1660 }; |
| 1661 |
| 1662 const unsigned char kV4FrameData[] = { |
| 1663 0x00, 0x06, 0x00, 0x10, // Length = 6. PAD_LOW set. |
| 1664 0x00, 0x00, 0x00, 0x01, |
| 1665 0x00, // Pad Low field. |
| 1666 'h', 'e', 'l', 'l', // Data |
| 1667 'o', |
| 1668 }; |
| 1669 const char bytes[] = "hello"; |
| 1670 |
| 1671 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
| 1672 // The pad low field itself is used for the 1-byte padding and no padding |
| 1673 // payload is needed. |
| 1674 data_ir.set_padding_len(1); |
| 1675 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1676 if (IsSpdy4()) { |
| 1677 CompareFrame( |
| 1678 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1679 } else { |
| 1680 CompareFrame( |
| 1681 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1682 } |
| 1683 |
| 1684 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); |
| 1685 CompareCharArraysWithHexError( |
| 1686 kDescription, |
| 1687 reinterpret_cast<const unsigned char*>(frame->data()), |
| 1688 framer.GetDataFrameMinimumSize(), |
| 1689 IsSpdy4() ? kV4FrameData : kV3FrameData, |
| 1690 framer.GetDataFrameMinimumSize()); |
| 1691 } |
| 1692 |
| 1693 { |
| 1553 const char kDescription[] = "Data frame with negative data byte, no FIN"; | 1694 const char kDescription[] = "Data frame with negative data byte, no FIN"; |
| 1554 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1695 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 1555 0x00, 0x00, 0x00, 0x01, | 1696 0x00, 0x00, 0x00, 0x01, |
| 1556 0x00, 0x00, 0x00, 0x01, | 1697 0x00, 0x00, 0x00, 0x01, |
| 1557 0xff | 1698 0xff |
| 1558 }; | 1699 }; |
| 1559 const unsigned char kV4FrameData[] = { | 1700 const unsigned char kV4FrameData[] = { |
| 1560 0x00, 0x01, 0x00, 0x00, | 1701 0x00, 0x01, 0x00, 0x00, |
| 1561 0x00, 0x00, 0x00, 0x01, | 1702 0x00, 0x00, 0x00, 0x01, |
| 1562 0xff | 1703 0xff |
| 1563 }; | 1704 }; |
| 1564 net::SpdyDataIR data_ir(1, StringPiece("\xff", 1)); | 1705 SpdyDataIR data_ir(1, StringPiece("\xff", 1)); |
| 1565 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1706 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1566 if (IsSpdy4()) { | 1707 if (IsSpdy4()) { |
| 1567 CompareFrame( | 1708 CompareFrame( |
| 1568 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1709 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1569 } else { | 1710 } else { |
| 1570 CompareFrame( | 1711 CompareFrame( |
| 1571 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1712 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1572 } | 1713 } |
| 1573 } | 1714 } |
| 1574 | 1715 |
| 1575 { | 1716 { |
| 1576 const char kDescription[] = "'hello' data frame, with FIN"; | 1717 const char kDescription[] = "'hello' data frame, with FIN"; |
| 1577 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1718 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 1578 0x00, 0x00, 0x00, 0x01, | 1719 0x00, 0x00, 0x00, 0x01, |
| 1579 0x01, 0x00, 0x00, 0x05, | 1720 0x01, 0x00, 0x00, 0x05, |
| 1580 'h', 'e', 'l', 'l', | 1721 'h', 'e', 'l', 'l', |
| 1581 'o' | 1722 'o' |
| 1582 }; | 1723 }; |
| 1583 const unsigned char kV4FrameData[] = { | 1724 const unsigned char kV4FrameData[] = { |
| 1584 0x00, 0x05, 0x00, 0x01, | 1725 0x00, 0x05, 0x00, 0x01, |
| 1585 0x00, 0x00, 0x00, 0x01, | 1726 0x00, 0x00, 0x00, 0x01, |
| 1586 'h', 'e', 'l', 'l', | 1727 'h', 'e', 'l', 'l', |
| 1587 'o' | 1728 'o' |
| 1588 }; | 1729 }; |
| 1589 net::SpdyDataIR data_ir(1, StringPiece("hello", 5)); | 1730 SpdyDataIR data_ir(1, StringPiece("hello", 5)); |
| 1590 data_ir.set_fin(true); | 1731 data_ir.set_fin(true); |
| 1591 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1732 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1592 if (IsSpdy4()) { | 1733 if (IsSpdy4()) { |
| 1593 CompareFrame( | 1734 CompareFrame( |
| 1594 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1735 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1595 } else { | 1736 } else { |
| 1596 CompareFrame( | 1737 CompareFrame( |
| 1597 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1738 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1598 } | 1739 } |
| 1599 } | 1740 } |
| 1600 | 1741 |
| 1601 { | 1742 { |
| 1602 const char kDescription[] = "Empty data frame"; | 1743 const char kDescription[] = "Empty data frame"; |
| 1603 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1744 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 1604 0x00, 0x00, 0x00, 0x01, | 1745 0x00, 0x00, 0x00, 0x01, |
| 1605 0x00, 0x00, 0x00, 0x00, | 1746 0x00, 0x00, 0x00, 0x00, |
| 1606 }; | 1747 }; |
| 1607 const unsigned char kV4FrameData[] = { | 1748 const unsigned char kV4FrameData[] = { |
| 1608 0x00, 0x00, 0x00, 0x00, | 1749 0x00, 0x00, 0x00, 0x00, |
| 1609 0x00, 0x00, 0x00, 0x01, | 1750 0x00, 0x00, 0x00, 0x01, |
| 1610 }; | 1751 }; |
| 1611 net::SpdyDataIR data_ir(1, StringPiece()); | 1752 SpdyDataIR data_ir(1, StringPiece()); |
| 1612 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1753 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1613 if (IsSpdy4()) { | 1754 if (IsSpdy4()) { |
| 1614 CompareFrame( | 1755 CompareFrame( |
| 1615 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1756 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1616 } else { | 1757 } else { |
| 1617 CompareFrame( | 1758 CompareFrame( |
| 1618 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1759 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1619 } | 1760 } |
| 1761 |
| 1762 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); |
| 1763 CompareCharArraysWithHexError( |
| 1764 kDescription, |
| 1765 reinterpret_cast<const unsigned char*>(frame->data()), |
| 1766 framer.GetDataFrameMinimumSize(), |
| 1767 IsSpdy4() ? kV4FrameData : kV3FrameData, |
| 1768 framer.GetDataFrameMinimumSize()); |
| 1620 } | 1769 } |
| 1621 | 1770 |
| 1622 { | 1771 { |
| 1623 const char kDescription[] = "Data frame with max stream ID"; | 1772 const char kDescription[] = "Data frame with max stream ID"; |
| 1624 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1773 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 1625 0x7f, 0xff, 0xff, 0xff, | 1774 0x7f, 0xff, 0xff, 0xff, |
| 1626 0x01, 0x00, 0x00, 0x05, | 1775 0x01, 0x00, 0x00, 0x05, |
| 1627 'h', 'e', 'l', 'l', | 1776 'h', 'e', 'l', 'l', |
| 1628 'o' | 1777 'o' |
| 1629 }; | 1778 }; |
| 1630 const unsigned char kV4FrameData[] = { | 1779 const unsigned char kV4FrameData[] = { |
| 1631 0x00, 0x05, 0x00, 0x01, | 1780 0x00, 0x05, 0x00, 0x01, |
| 1632 0x7f, 0xff, 0xff, 0xff, | 1781 0x7f, 0xff, 0xff, 0xff, |
| 1633 'h', 'e', 'l', 'l', | 1782 'h', 'e', 'l', 'l', |
| 1634 'o' | 1783 'o' |
| 1635 }; | 1784 }; |
| 1636 net::SpdyDataIR data_ir(0x7fffffff, "hello"); | 1785 SpdyDataIR data_ir(0x7fffffff, "hello"); |
| 1637 data_ir.set_fin(true); | 1786 data_ir.set_fin(true); |
| 1638 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1787 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1639 if (IsSpdy4()) { | 1788 if (IsSpdy4()) { |
| 1640 CompareFrame( | 1789 CompareFrame( |
| 1641 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1790 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1642 } else { | 1791 } else { |
| 1643 CompareFrame( | 1792 CompareFrame( |
| 1644 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1793 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1645 } | 1794 } |
| 1646 } | 1795 } |
| 1647 | 1796 |
| 1648 if (!IsSpdy4()) { | 1797 if (!IsSpdy4()) { |
| 1649 // This test does not apply to SPDY 4 because the max frame size is smaller | 1798 // This test does not apply to SPDY 4 because the max frame size is smaller |
| 1650 // than 4MB. | 1799 // than 4MB. |
| 1651 const char kDescription[] = "Large data frame"; | 1800 const char kDescription[] = "Large data frame"; |
| 1652 const int kDataSize = 4 * 1024 * 1024; // 4 MB | 1801 const int kDataSize = 4 * 1024 * 1024; // 4 MB |
| 1653 const string kData(kDataSize, 'A'); | 1802 const string kData(kDataSize, 'A'); |
| 1654 const unsigned char kFrameHeader[] = { | 1803 const unsigned char kFrameHeader[] = { |
| 1655 0x00, 0x00, 0x00, 0x01, | 1804 0x00, 0x00, 0x00, 0x01, |
| 1656 0x01, 0x40, 0x00, 0x00, | 1805 0x01, 0x40, 0x00, 0x00, |
| 1657 }; | 1806 }; |
| 1658 | 1807 |
| 1659 const int kFrameSize = arraysize(kFrameHeader) + kDataSize; | 1808 const int kFrameSize = arraysize(kFrameHeader) + kDataSize; |
| 1660 scoped_ptr<unsigned char[]> expected_frame_data( | 1809 scoped_ptr<unsigned char[]> expected_frame_data( |
| 1661 new unsigned char[kFrameSize]); | 1810 new unsigned char[kFrameSize]); |
| 1662 memcpy(expected_frame_data.get(), kFrameHeader, arraysize(kFrameHeader)); | 1811 memcpy(expected_frame_data.get(), kFrameHeader, arraysize(kFrameHeader)); |
| 1663 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); | 1812 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); |
| 1664 | 1813 |
| 1665 net::SpdyDataIR data_ir(1, StringPiece(kData.data(), kData.size())); | 1814 SpdyDataIR data_ir(1, StringPiece(kData.data(), kData.size())); |
| 1666 data_ir.set_fin(true); | 1815 data_ir.set_fin(true); |
| 1667 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1816 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1668 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize); | 1817 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize); |
| 1669 } | 1818 } |
| 1670 } | 1819 } |
| 1671 | 1820 |
| 1672 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { | 1821 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { |
| 1673 SpdyFramer framer(spdy_version_); | 1822 SpdyFramer framer(spdy_version_); |
| 1674 framer.set_enable_compression(false); | 1823 framer.set_enable_compression(false); |
| 1675 | 1824 |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2129 0x00, 0x00, 0x00, 0x08, | 2278 0x00, 0x00, 0x00, 0x08, |
| 2130 0x00, 0x00, 0x00, 0x01, | 2279 0x00, 0x00, 0x00, 0x01, |
| 2131 0x00, 0x00, 0x00, 0x01, | 2280 0x00, 0x00, 0x00, 0x01, |
| 2132 }; | 2281 }; |
| 2133 const unsigned char kV4FrameData[] = { | 2282 const unsigned char kV4FrameData[] = { |
| 2134 0x00, 0x07, 0x03, 0x00, | 2283 0x00, 0x07, 0x03, 0x00, |
| 2135 0x00, 0x00, 0x00, 0x01, | 2284 0x00, 0x00, 0x00, 0x01, |
| 2136 0x00, 0x00, 0x00, 0x01, | 2285 0x00, 0x00, 0x00, 0x01, |
| 2137 0x52, 0x53, 0x54 | 2286 0x52, 0x53, 0x54 |
| 2138 }; | 2287 }; |
| 2139 net::SpdyRstStreamIR rst_stream(1, RST_STREAM_PROTOCOL_ERROR, "RST"); | 2288 SpdyRstStreamIR rst_stream(1, RST_STREAM_PROTOCOL_ERROR, "RST"); |
| 2140 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); | 2289 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); |
| 2141 if (IsSpdy4()) { | 2290 if (IsSpdy4()) { |
| 2142 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2291 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2143 } else { | 2292 } else { |
| 2144 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2293 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2145 } | 2294 } |
| 2146 } | 2295 } |
| 2147 | 2296 |
| 2148 { | 2297 { |
| 2149 const char kDescription[] = "RST_STREAM frame with max stream ID"; | 2298 const char kDescription[] = "RST_STREAM frame with max stream ID"; |
| 2150 const unsigned char kV3FrameData[] = { // Also applies for V2. | 2299 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 2151 0x80, spdy_version_ch_, 0x00, 0x03, | 2300 0x80, spdy_version_ch_, 0x00, 0x03, |
| 2152 0x00, 0x00, 0x00, 0x08, | 2301 0x00, 0x00, 0x00, 0x08, |
| 2153 0x7f, 0xff, 0xff, 0xff, | 2302 0x7f, 0xff, 0xff, 0xff, |
| 2154 0x00, 0x00, 0x00, 0x01, | 2303 0x00, 0x00, 0x00, 0x01, |
| 2155 }; | 2304 }; |
| 2156 const unsigned char kV4FrameData[] = { | 2305 const unsigned char kV4FrameData[] = { |
| 2157 0x00, 0x04, 0x03, 0x00, | 2306 0x00, 0x04, 0x03, 0x00, |
| 2158 0x7f, 0xff, 0xff, 0xff, | 2307 0x7f, 0xff, 0xff, 0xff, |
| 2159 0x00, 0x00, 0x00, 0x01, | 2308 0x00, 0x00, 0x00, 0x01, |
| 2160 }; | 2309 }; |
| 2161 net::SpdyRstStreamIR rst_stream(0x7FFFFFFF, | 2310 SpdyRstStreamIR rst_stream(0x7FFFFFFF, |
| 2162 RST_STREAM_PROTOCOL_ERROR, | 2311 RST_STREAM_PROTOCOL_ERROR, |
| 2163 ""); | 2312 ""); |
| 2164 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); | 2313 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); |
| 2165 if (IsSpdy4()) { | 2314 if (IsSpdy4()) { |
| 2166 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2315 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2167 } else { | 2316 } else { |
| 2168 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2317 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2169 } | 2318 } |
| 2170 } | 2319 } |
| 2171 | 2320 |
| 2172 { | 2321 { |
| 2173 const char kDescription[] = "RST_STREAM frame with max status code"; | 2322 const char kDescription[] = "RST_STREAM frame with max status code"; |
| 2174 const unsigned char kV3FrameData[] = { // Also applies for V2. | 2323 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 2175 0x80, spdy_version_ch_, 0x00, 0x03, | 2324 0x80, spdy_version_ch_, 0x00, 0x03, |
| 2176 0x00, 0x00, 0x00, 0x08, | 2325 0x00, 0x00, 0x00, 0x08, |
| 2177 0x7f, 0xff, 0xff, 0xff, | 2326 0x7f, 0xff, 0xff, 0xff, |
| 2178 0x00, 0x00, 0x00, 0x06, | 2327 0x00, 0x00, 0x00, 0x06, |
| 2179 }; | 2328 }; |
| 2180 const unsigned char kV4FrameData[] = { | 2329 const unsigned char kV4FrameData[] = { |
| 2181 0x00, 0x04, 0x03, 0x00, | 2330 0x00, 0x04, 0x03, 0x00, |
| 2182 0x7f, 0xff, 0xff, 0xff, | 2331 0x7f, 0xff, 0xff, 0xff, |
| 2183 0x00, 0x00, 0x00, 0x06, | 2332 0x00, 0x00, 0x00, 0x06, |
| 2184 }; | 2333 }; |
| 2185 net::SpdyRstStreamIR rst_stream(0x7FFFFFFF, | 2334 SpdyRstStreamIR rst_stream(0x7FFFFFFF, |
| 2186 RST_STREAM_INTERNAL_ERROR, | 2335 RST_STREAM_INTERNAL_ERROR, |
| 2187 ""); | 2336 ""); |
| 2188 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); | 2337 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); |
| 2189 if (IsSpdy4()) { | 2338 if (IsSpdy4()) { |
| 2190 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2339 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2191 } else { | 2340 } else { |
| 2192 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2341 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2193 } | 2342 } |
| 2194 } | 2343 } |
| 2195 } | 2344 } |
| 2196 | 2345 |
| 2197 TEST_P(SpdyFramerTest, CreateSettings) { | 2346 TEST_P(SpdyFramerTest, CreateSettings) { |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2673 0x00, 0x00, 0x00, 0x08, | 2822 0x00, 0x00, 0x00, 0x08, |
| 2674 0x00, 0x00, 0x00, 0x01, | 2823 0x00, 0x00, 0x00, 0x01, |
| 2675 0x00, 0x00, 0x00, 0x01, | 2824 0x00, 0x00, 0x00, 0x01, |
| 2676 }; | 2825 }; |
| 2677 const unsigned char kV4FrameData[] = { | 2826 const unsigned char kV4FrameData[] = { |
| 2678 0x00, 0x04, 0x08, 0x00, | 2827 0x00, 0x04, 0x08, 0x00, |
| 2679 0x00, 0x00, 0x00, 0x01, | 2828 0x00, 0x00, 0x00, 0x01, |
| 2680 0x00, 0x00, 0x00, 0x01, | 2829 0x00, 0x00, 0x00, 0x01, |
| 2681 }; | 2830 }; |
| 2682 scoped_ptr<SpdyFrame> frame( | 2831 scoped_ptr<SpdyFrame> frame( |
| 2683 framer.SerializeWindowUpdate(net::SpdyWindowUpdateIR(1, 1))); | 2832 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 1))); |
| 2684 if (IsSpdy4()) { | 2833 if (IsSpdy4()) { |
| 2685 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2834 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2686 } else { | 2835 } else { |
| 2687 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2836 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2688 } | 2837 } |
| 2689 } | 2838 } |
| 2690 | 2839 |
| 2691 { | 2840 { |
| 2692 const char kDescription[] = "WINDOW_UPDATE frame with max stream ID"; | 2841 const char kDescription[] = "WINDOW_UPDATE frame with max stream ID"; |
| 2693 const unsigned char kV3FrameData[] = { // Also applies for V2. | 2842 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 2694 0x80, spdy_version_ch_, 0x00, 0x09, | 2843 0x80, spdy_version_ch_, 0x00, 0x09, |
| 2695 0x00, 0x00, 0x00, 0x08, | 2844 0x00, 0x00, 0x00, 0x08, |
| 2696 0x7f, 0xff, 0xff, 0xff, | 2845 0x7f, 0xff, 0xff, 0xff, |
| 2697 0x00, 0x00, 0x00, 0x01, | 2846 0x00, 0x00, 0x00, 0x01, |
| 2698 }; | 2847 }; |
| 2699 const unsigned char kV4FrameData[] = { | 2848 const unsigned char kV4FrameData[] = { |
| 2700 0x00, 0x04, 0x08, 0x00, | 2849 0x00, 0x04, 0x08, 0x00, |
| 2701 0x7f, 0xff, 0xff, 0xff, | 2850 0x7f, 0xff, 0xff, 0xff, |
| 2702 0x00, 0x00, 0x00, 0x01, | 2851 0x00, 0x00, 0x00, 0x01, |
| 2703 }; | 2852 }; |
| 2704 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( | 2853 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( |
| 2705 net::SpdyWindowUpdateIR(0x7FFFFFFF, 1))); | 2854 SpdyWindowUpdateIR(0x7FFFFFFF, 1))); |
| 2706 if (IsSpdy4()) { | 2855 if (IsSpdy4()) { |
| 2707 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2856 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2708 } else { | 2857 } else { |
| 2709 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2858 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2710 } | 2859 } |
| 2711 } | 2860 } |
| 2712 | 2861 |
| 2713 { | 2862 { |
| 2714 const char kDescription[] = "WINDOW_UPDATE frame with max window delta"; | 2863 const char kDescription[] = "WINDOW_UPDATE frame with max window delta"; |
| 2715 const unsigned char kV3FrameData[] = { // Also applies for V2. | 2864 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 2716 0x80, spdy_version_ch_, 0x00, 0x09, | 2865 0x80, spdy_version_ch_, 0x00, 0x09, |
| 2717 0x00, 0x00, 0x00, 0x08, | 2866 0x00, 0x00, 0x00, 0x08, |
| 2718 0x00, 0x00, 0x00, 0x01, | 2867 0x00, 0x00, 0x00, 0x01, |
| 2719 0x7f, 0xff, 0xff, 0xff, | 2868 0x7f, 0xff, 0xff, 0xff, |
| 2720 }; | 2869 }; |
| 2721 const unsigned char kV4FrameData[] = { | 2870 const unsigned char kV4FrameData[] = { |
| 2722 0x00, 0x04, 0x08, 0x00, | 2871 0x00, 0x04, 0x08, 0x00, |
| 2723 0x00, 0x00, 0x00, 0x01, | 2872 0x00, 0x00, 0x00, 0x01, |
| 2724 0x7f, 0xff, 0xff, 0xff, | 2873 0x7f, 0xff, 0xff, 0xff, |
| 2725 }; | 2874 }; |
| 2726 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( | 2875 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( |
| 2727 net::SpdyWindowUpdateIR(1, 0x7FFFFFFF))); | 2876 SpdyWindowUpdateIR(1, 0x7FFFFFFF))); |
| 2728 if (IsSpdy4()) { | 2877 if (IsSpdy4()) { |
| 2729 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2878 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2730 } else { | 2879 } else { |
| 2731 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2880 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2732 } | 2881 } |
| 2733 } | 2882 } |
| 2734 } | 2883 } |
| 2735 | 2884 |
| 2736 TEST_P(SpdyFramerTest, SerializeBlocked) { | 2885 TEST_P(SpdyFramerTest, SerializeBlocked) { |
| 2737 if (spdy_version_ < SPDY4) { | 2886 if (spdy_version_ < SPDY4) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2762 | 2911 |
| 2763 scoped_ptr<SpdySerializedFrame> frame_serialized( | 2912 scoped_ptr<SpdySerializedFrame> frame_serialized( |
| 2764 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); | 2913 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); |
| 2765 SpdyBlockedIR blocked_ir(kStreamId); | 2914 SpdyBlockedIR blocked_ir(kStreamId); |
| 2766 scoped_ptr<SpdySerializedFrame> frame_created( | 2915 scoped_ptr<SpdySerializedFrame> frame_created( |
| 2767 framer.SerializeFrame(blocked_ir)); | 2916 framer.SerializeFrame(blocked_ir)); |
| 2768 | 2917 |
| 2769 CompareFrames(kDescription, *frame_serialized, *frame_created); | 2918 CompareFrames(kDescription, *frame_serialized, *frame_created); |
| 2770 } | 2919 } |
| 2771 | 2920 |
| 2772 TEST_P(SpdyFramerTest, CreatePushPromise) { | 2921 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { |
| 2773 if (spdy_version_ < SPDY4) { | 2922 if (spdy_version_ < SPDY4) { |
| 2774 return; | 2923 return; |
| 2775 } | 2924 } |
| 2776 | 2925 |
| 2777 SpdyFramer framer(spdy_version_); | 2926 SpdyFramer framer(spdy_version_); |
| 2778 | 2927 framer.set_enable_compression(false); |
| 2779 const char kDescription[] = "PUSH_PROMISE frame"; | 2928 const char kDescription[] = "PUSH_PROMISE frame"; |
| 2780 | 2929 |
| 2781 const unsigned char kFrameData[] = { | 2930 const unsigned char kFrameData[] = { |
| 2782 0x00, 0x16, 0x05, 0x04, // PUSH_PROMISE: END_HEADERS | 2931 0x00, 0x16, 0x05, 0x04, // PUSH_PROMISE: END_HEADERS |
| 2783 0x00, 0x00, 0x00, 0x2a, // Stream 42 | 2932 0x00, 0x00, 0x00, 0x2a, // Stream 42 |
| 2784 0x00, 0x00, 0x00, 0x39, // Promised stream 57 | 2933 0x00, 0x00, 0x00, 0x39, // Promised stream 57 |
| 2785 0x40, 0x03, 0x62, 0x61, // @.ba | 2934 0x40, 0x03, 0x62, 0x61, // @.ba |
| 2786 0x72, 0x03, 0x66, 0x6f, // r.fo | 2935 0x72, 0x03, 0x66, 0x6f, // r.fo |
| 2787 0x6f, 0x40, 0x03, 0x66, // o@.f | 2936 0x6f, 0x40, 0x03, 0x66, // o@.f |
| 2788 0x6f, 0x6f, 0x03, 0x62, // oo.b | 2937 0x6f, 0x6f, 0x03, 0x62, // oo.b |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2881 // produced by rand(), so adding, removing or running single tests | 3030 // produced by rand(), so adding, removing or running single tests |
| 2882 // alters this value. The best we can do is assert that it happens | 3031 // alters this value. The best we can do is assert that it happens |
| 2883 // at least twice. | 3032 // at least twice. |
| 2884 EXPECT_LE(2, visitor.control_frame_header_data_count_); | 3033 EXPECT_LE(2, visitor.control_frame_header_data_count_); |
| 2885 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3034 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 2886 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 3035 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
| 2887 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 3036 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
| 2888 } | 3037 } |
| 2889 | 3038 |
| 2890 TEST_P(SpdyFramerTest, ControlFrameAtMaxSizeLimit) { | 3039 TEST_P(SpdyFramerTest, ControlFrameAtMaxSizeLimit) { |
| 2891 if (spdy_version_ >= 4) { | 3040 if (spdy_version_ > SPDY3) { |
| 2892 // TODO(jgraettinger): This test setup doesn't work with HPACK. | 3041 // TODO(jgraettinger): This test setup doesn't work with HPACK. |
| 2893 return; | 3042 return; |
| 2894 } | 3043 } |
| 2895 // First find the size of the header value in order to just reach the control | 3044 // First find the size of the header value in order to just reach the control |
| 2896 // frame max size. | 3045 // frame max size. |
| 2897 SpdyFramer framer(spdy_version_); | 3046 SpdyFramer framer(spdy_version_); |
| 2898 framer.set_enable_compression(false); | 3047 framer.set_enable_compression(false); |
| 2899 SpdySynStreamIR syn_stream(1); | 3048 SpdySynStreamIR syn_stream(1); |
| 2900 syn_stream.set_priority(1); | 3049 syn_stream.set_priority(1); |
| 2901 syn_stream.SetHeader("aa", ""); | 3050 syn_stream.SetHeader("aa", ""); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2916 control_frame->size()); | 3065 control_frame->size()); |
| 2917 EXPECT_TRUE(visitor.header_buffer_valid_); | 3066 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 2918 EXPECT_EQ(0, visitor.error_count_); | 3067 EXPECT_EQ(0, visitor.error_count_); |
| 2919 EXPECT_EQ(1, visitor.syn_frame_count_); | 3068 EXPECT_EQ(1, visitor.syn_frame_count_); |
| 2920 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3069 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 2921 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 3070 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
| 2922 EXPECT_LT(kBigValueSize, visitor.header_buffer_length_); | 3071 EXPECT_LT(kBigValueSize, visitor.header_buffer_length_); |
| 2923 } | 3072 } |
| 2924 | 3073 |
| 2925 TEST_P(SpdyFramerTest, ControlFrameTooLarge) { | 3074 TEST_P(SpdyFramerTest, ControlFrameTooLarge) { |
| 2926 if (spdy_version_ >= 4) { | 3075 if (spdy_version_ > SPDY3) { |
| 2927 // TODO(jgraettinger): This test setup doesn't work with HPACK. | 3076 // TODO(jgraettinger): This test setup doesn't work with HPACK. |
| 2928 return; | 3077 return; |
| 2929 } | 3078 } |
| 2930 // First find the size of the header value in order to just reach the control | 3079 // First find the size of the header value in order to just reach the control |
| 2931 // frame max size. | 3080 // frame max size. |
| 2932 SpdyFramer framer(spdy_version_); | 3081 SpdyFramer framer(spdy_version_); |
| 2933 framer.set_enable_compression(false); | 3082 framer.set_enable_compression(false); |
| 2934 SpdySynStreamIR syn_stream(1); | 3083 SpdySynStreamIR syn_stream(1); |
| 2935 syn_stream.SetHeader("aa", ""); | 3084 syn_stream.SetHeader("aa", ""); |
| 2936 syn_stream.set_priority(1); | 3085 syn_stream.set_priority(1); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2956 control_frame->size()); | 3105 control_frame->size()); |
| 2957 EXPECT_FALSE(visitor.header_buffer_valid_); | 3106 EXPECT_FALSE(visitor.header_buffer_valid_); |
| 2958 EXPECT_EQ(1, visitor.error_count_); | 3107 EXPECT_EQ(1, visitor.error_count_); |
| 2959 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE, | 3108 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE, |
| 2960 visitor.framer_.error_code()) | 3109 visitor.framer_.error_code()) |
| 2961 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3110 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 2962 EXPECT_EQ(0, visitor.syn_frame_count_); | 3111 EXPECT_EQ(0, visitor.syn_frame_count_); |
| 2963 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3112 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 2964 } | 3113 } |
| 2965 | 3114 |
| 3115 TEST_P(SpdyFramerTest, TooLargeHeadersFrameUsesContinuation) { |
| 3116 if (spdy_version_ < SPDY4) { |
| 3117 return; |
| 3118 } |
| 3119 SpdyFramer framer(spdy_version_); |
| 3120 framer.set_enable_compression(false); |
| 3121 SpdyHeadersIR headers(1); |
| 3122 |
| 3123 // Exact payload length will change with HPACK, but this should be long |
| 3124 // enough to cause an overflow. |
| 3125 const size_t kBigValueSize = framer.GetControlFrameBufferMaxSize(); |
| 3126 string big_value(kBigValueSize, 'x'); |
| 3127 headers.SetHeader("aa", big_value.c_str()); |
| 3128 scoped_ptr<SpdyFrame> control_frame(framer.SerializeHeaders(headers)); |
| 3129 EXPECT_TRUE(control_frame.get() != NULL); |
| 3130 EXPECT_GT(control_frame->size(), framer.GetControlFrameBufferMaxSize()); |
| 3131 |
| 3132 TestSpdyVisitor visitor(spdy_version_); |
| 3133 visitor.SimulateInFramer( |
| 3134 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 3135 control_frame->size()); |
| 3136 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 3137 EXPECT_EQ(0, visitor.error_count_); |
| 3138 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3139 EXPECT_EQ(1, visitor.continuation_count_); |
| 3140 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3141 } |
| 3142 |
| 3143 TEST_P(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { |
| 3144 if (spdy_version_ < SPDY4) { |
| 3145 return; |
| 3146 } |
| 3147 SpdyFramer framer(spdy_version_); |
| 3148 framer.set_enable_compression(false); |
| 3149 SpdyPushPromiseIR push_promise(1, 2); |
| 3150 |
| 3151 // Exact payload length will change with HPACK, but this should be long |
| 3152 // enough to cause an overflow. |
| 3153 const size_t kBigValueSize = framer.GetControlFrameBufferMaxSize(); |
| 3154 string big_value(kBigValueSize, 'x'); |
| 3155 push_promise.SetHeader("aa", big_value.c_str()); |
| 3156 scoped_ptr<SpdyFrame> control_frame( |
| 3157 framer.SerializePushPromise(push_promise)); |
| 3158 EXPECT_TRUE(control_frame.get() != NULL); |
| 3159 EXPECT_GT(control_frame->size(), framer.GetControlFrameBufferMaxSize()); |
| 3160 |
| 3161 TestSpdyVisitor visitor(spdy_version_); |
| 3162 visitor.SimulateInFramer( |
| 3163 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 3164 control_frame->size()); |
| 3165 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 3166 EXPECT_EQ(0, visitor.error_count_); |
| 3167 EXPECT_EQ(1, visitor.push_promise_frame_count_); |
| 3168 EXPECT_EQ(1, visitor.continuation_count_); |
| 3169 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3170 } |
| 3171 |
| 2966 // Check that the framer stops delivering header data chunks once the visitor | 3172 // Check that the framer stops delivering header data chunks once the visitor |
| 2967 // declares it doesn't want any more. This is important to guard against | 3173 // declares it doesn't want any more. This is important to guard against |
| 2968 // "zip bomb" types of attacks. | 3174 // "zip bomb" types of attacks. |
| 2969 TEST_P(SpdyFramerTest, ControlFrameMuchTooLarge) { | 3175 TEST_P(SpdyFramerTest, ControlFrameMuchTooLarge) { |
| 2970 const size_t kHeaderBufferChunks = 4; | 3176 const size_t kHeaderBufferChunks = 4; |
| 2971 const size_t kHeaderBufferSize = | 3177 const size_t kHeaderBufferSize = |
| 2972 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks; | 3178 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks; |
| 2973 const size_t kBigValueSize = kHeaderBufferSize * 2; | 3179 const size_t kBigValueSize = kHeaderBufferSize * 2; |
| 2974 string big_value(kBigValueSize, 'x'); | 3180 string big_value(kBigValueSize, 'x'); |
| 2975 SpdyFramer framer(spdy_version_); | 3181 SpdyFramer framer(spdy_version_); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3000 // at least kHeaderBufferChunks + 1. | 3206 // at least kHeaderBufferChunks + 1. |
| 3001 EXPECT_LE(kHeaderBufferChunks + 1, | 3207 EXPECT_LE(kHeaderBufferChunks + 1, |
| 3002 static_cast<unsigned>(visitor.control_frame_header_data_count_)); | 3208 static_cast<unsigned>(visitor.control_frame_header_data_count_)); |
| 3003 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 3209 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 3004 | 3210 |
| 3005 // The framer should not have sent half-close to the visitor. | 3211 // The framer should not have sent half-close to the visitor. |
| 3006 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 3212 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
| 3007 } | 3213 } |
| 3008 | 3214 |
| 3009 TEST_P(SpdyFramerTest, DecompressCorruptHeaderBlock) { | 3215 TEST_P(SpdyFramerTest, DecompressCorruptHeaderBlock) { |
| 3010 if (spdy_version_ >= 4) { | 3216 if (spdy_version_ > SPDY3) { |
| 3011 // Deflate compression doesn't apply to HPACK. | 3217 // Deflate compression doesn't apply to HPACK. |
| 3012 return; | 3218 return; |
| 3013 } | 3219 } |
| 3014 SpdyFramer framer(spdy_version_); | 3220 SpdyFramer framer(spdy_version_); |
| 3015 framer.set_enable_compression(false); | 3221 framer.set_enable_compression(false); |
| 3016 // Construct a SYN_STREAM control frame without compressing the header block, | 3222 // Construct a SYN_STREAM control frame without compressing the header block, |
| 3017 // and have the framer try to decompress it. This will cause the framer to | 3223 // and have the framer try to decompress it. This will cause the framer to |
| 3018 // deal with a decompression error. | 3224 // deal with a decompression error. |
| 3019 SpdySynStreamIR syn_stream(1); | 3225 SpdySynStreamIR syn_stream(1); |
| 3020 syn_stream.set_priority(1); | 3226 syn_stream.set_priority(1); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3079 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { | 3285 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { |
| 3080 SpdyFramer framer(spdy_version_); | 3286 SpdyFramer framer(spdy_version_); |
| 3081 SpdySettingsIR settings_ir; | 3287 SpdySettingsIR settings_ir; |
| 3082 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSettings(settings_ir)); | 3288 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSettings(settings_ir)); |
| 3083 SetFrameLength(control_frame.get(), 0, spdy_version_); | 3289 SetFrameLength(control_frame.get(), 0, spdy_version_); |
| 3084 TestSpdyVisitor visitor(spdy_version_); | 3290 TestSpdyVisitor visitor(spdy_version_); |
| 3085 visitor.use_compression_ = false; | 3291 visitor.use_compression_ = false; |
| 3086 visitor.SimulateInFramer( | 3292 visitor.SimulateInFramer( |
| 3087 reinterpret_cast<unsigned char*>(control_frame->data()), | 3293 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 3088 framer.GetControlFrameHeaderSize()); | 3294 framer.GetControlFrameHeaderSize()); |
| 3089 if (spdy_version_ < 4) { | 3295 if (spdy_version_ <= SPDY3) { |
| 3090 // Should generate an error, since zero-len settings frames are unsupported. | 3296 // Should generate an error, since zero-len settings frames are unsupported. |
| 3091 EXPECT_EQ(1, visitor.error_count_); | 3297 EXPECT_EQ(1, visitor.error_count_); |
| 3092 } else { | 3298 } else { |
| 3093 // Zero-len settings frames are permitted as of SPDY 4. | 3299 // Zero-len settings frames are permitted as of SPDY 4. |
| 3094 EXPECT_EQ(0, visitor.error_count_); | 3300 EXPECT_EQ(0, visitor.error_count_); |
| 3095 } | 3301 } |
| 3096 } | 3302 } |
| 3097 | 3303 |
| 3098 // Tests handling of SETTINGS frames with invalid length. | 3304 // Tests handling of SETTINGS frames with invalid length. |
| 3099 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { | 3305 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3141 control_frame->size()); | 3347 control_frame->size()); |
| 3142 TestSpdyVisitor visitor(spdy_version_); | 3348 TestSpdyVisitor visitor(spdy_version_); |
| 3143 visitor.use_compression_ = false; | 3349 visitor.use_compression_ = false; |
| 3144 | 3350 |
| 3145 // Read all at once. | 3351 // Read all at once. |
| 3146 visitor.SimulateInFramer( | 3352 visitor.SimulateInFramer( |
| 3147 reinterpret_cast<unsigned char*>(control_frame->data()), | 3353 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 3148 control_frame->size()); | 3354 control_frame->size()); |
| 3149 EXPECT_EQ(0, visitor.error_count_); | 3355 EXPECT_EQ(0, visitor.error_count_); |
| 3150 EXPECT_EQ(3, visitor.setting_count_); | 3356 EXPECT_EQ(3, visitor.setting_count_); |
| 3151 if (spdy_version_ >= 4) { | 3357 if (spdy_version_ > SPDY3) { |
| 3152 EXPECT_EQ(1, visitor.settings_ack_sent_); | 3358 EXPECT_EQ(1, visitor.settings_ack_sent_); |
| 3153 } | 3359 } |
| 3154 | 3360 |
| 3155 // Read data in small chunks. | 3361 // Read data in small chunks. |
| 3156 size_t framed_data = 0; | 3362 size_t framed_data = 0; |
| 3157 size_t unframed_data = control_frame->size(); | 3363 size_t unframed_data = control_frame->size(); |
| 3158 size_t kReadChunkSize = 5; // Read five bytes at a time. | 3364 size_t kReadChunkSize = 5; // Read five bytes at a time. |
| 3159 while (unframed_data > 0) { | 3365 while (unframed_data > 0) { |
| 3160 size_t to_read = min(kReadChunkSize, unframed_data); | 3366 size_t to_read = min(kReadChunkSize, unframed_data); |
| 3161 visitor.SimulateInFramer( | 3367 visitor.SimulateInFramer( |
| 3162 reinterpret_cast<unsigned char*>(control_frame->data() + framed_data), | 3368 reinterpret_cast<unsigned char*>(control_frame->data() + framed_data), |
| 3163 to_read); | 3369 to_read); |
| 3164 unframed_data -= to_read; | 3370 unframed_data -= to_read; |
| 3165 framed_data += to_read; | 3371 framed_data += to_read; |
| 3166 } | 3372 } |
| 3167 EXPECT_EQ(0, visitor.error_count_); | 3373 EXPECT_EQ(0, visitor.error_count_); |
| 3168 EXPECT_EQ(3 * 2, visitor.setting_count_); | 3374 EXPECT_EQ(3 * 2, visitor.setting_count_); |
| 3169 if (spdy_version_ >= 4) { | 3375 if (spdy_version_ > SPDY3) { |
| 3170 EXPECT_EQ(2, visitor.settings_ack_sent_); | 3376 EXPECT_EQ(2, visitor.settings_ack_sent_); |
| 3171 } | 3377 } |
| 3172 } | 3378 } |
| 3173 | 3379 |
| 3174 // Tests handling of SETTINGS frame with duplicate entries. | 3380 // Tests handling of SETTINGS frame with duplicate entries. |
| 3175 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { | 3381 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { |
| 3176 SpdyFramer framer(spdy_version_); | 3382 SpdyFramer framer(spdy_version_); |
| 3177 | 3383 |
| 3178 const unsigned char kV2FrameData[] = { | 3384 const unsigned char kV2FrameData[] = { |
| 3179 0x80, spdy_version_ch_, 0x00, 0x04, | 3385 0x80, spdy_version_ch_, 0x00, 0x04, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3282 EXPECT_EQ(1, visitor.error_count_); | 3488 EXPECT_EQ(1, visitor.error_count_); |
| 3283 } else { | 3489 } else { |
| 3284 // In SPDY 4+, settings are allowed in any order. | 3490 // In SPDY 4+, settings are allowed in any order. |
| 3285 EXPECT_EQ(3, visitor.setting_count_); | 3491 EXPECT_EQ(3, visitor.setting_count_); |
| 3286 EXPECT_EQ(0, visitor.error_count_); | 3492 EXPECT_EQ(0, visitor.error_count_); |
| 3287 // EXPECT_EQ(1, visitor.settings_ack_count_); | 3493 // EXPECT_EQ(1, visitor.settings_ack_count_); |
| 3288 } | 3494 } |
| 3289 } | 3495 } |
| 3290 | 3496 |
| 3291 TEST_P(SpdyFramerTest, ProcessSettingsAckFrame) { | 3497 TEST_P(SpdyFramerTest, ProcessSettingsAckFrame) { |
| 3292 if (spdy_version_ < 4) { | 3498 if (spdy_version_ <= SPDY3) { |
| 3293 return; | 3499 return; |
| 3294 } | 3500 } |
| 3295 SpdyFramer framer(spdy_version_); | 3501 SpdyFramer framer(spdy_version_); |
| 3296 | 3502 |
| 3297 const unsigned char kFrameData[] = { | 3503 const unsigned char kFrameData[] = { |
| 3298 0x00, 0x00, 0x04, 0x01, | 3504 0x00, 0x00, 0x04, 0x01, |
| 3299 0x00, 0x00, 0x00, 0x00, | 3505 0x00, 0x00, 0x00, 0x00, |
| 3300 }; | 3506 }; |
| 3301 | 3507 |
| 3302 TestSpdyVisitor visitor(spdy_version_); | 3508 TestSpdyVisitor visitor(spdy_version_); |
| 3303 visitor.use_compression_ = false; | 3509 visitor.use_compression_ = false; |
| 3304 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 3510 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 3305 | 3511 |
| 3306 EXPECT_EQ(0, visitor.error_count_); | 3512 EXPECT_EQ(0, visitor.error_count_); |
| 3307 EXPECT_EQ(0, visitor.setting_count_); | 3513 EXPECT_EQ(0, visitor.setting_count_); |
| 3308 EXPECT_EQ(1, visitor.settings_ack_received_); | 3514 EXPECT_EQ(1, visitor.settings_ack_received_); |
| 3309 } | 3515 } |
| 3310 | 3516 |
| 3311 | 3517 |
| 3312 TEST_P(SpdyFramerTest, ProcessDataFrameWithPadding) { | 3518 TEST_P(SpdyFramerTest, ProcessDataFrameWithPadding) { |
| 3313 if (spdy_version_ < 4) { | 3519 if (spdy_version_ <= SPDY3) { |
| 3314 return; | 3520 return; |
| 3315 } | 3521 } |
| 3316 | 3522 |
| 3317 const int kPaddingLen = 512; // So we get two bytes for padding length field. | 3523 const int kPaddingLen = 512; // So we get two bytes for padding length field. |
| 3318 const char data_payload[] = "hello"; | 3524 const char data_payload[] = "hello"; |
| 3319 | 3525 |
| 3320 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3526 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3321 SpdyFramer framer(spdy_version_); | 3527 SpdyFramer framer(spdy_version_); |
| 3322 framer.set_visitor(&visitor); | 3528 framer.set_visitor(&visitor); |
| 3323 | 3529 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3373 // Send rest of the padding payload. | 3579 // Send rest of the padding payload. |
| 3374 EXPECT_CALL(visitor, OnStreamFrameData(1, NULL, 410, false)); | 3580 EXPECT_CALL(visitor, OnStreamFrameData(1, NULL, 410, false)); |
| 3375 CHECK_EQ(410u, framer.ProcessInput(frame->data() + bytes_consumed, 410)); | 3581 CHECK_EQ(410u, framer.ProcessInput(frame->data() + bytes_consumed, 410)); |
| 3376 CHECK_EQ(framer.state(), SpdyFramer::SPDY_RESET); | 3582 CHECK_EQ(framer.state(), SpdyFramer::SPDY_RESET); |
| 3377 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3583 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
| 3378 } | 3584 } |
| 3379 | 3585 |
| 3380 TEST_P(SpdyFramerTest, ReadWindowUpdate) { | 3586 TEST_P(SpdyFramerTest, ReadWindowUpdate) { |
| 3381 SpdyFramer framer(spdy_version_); | 3587 SpdyFramer framer(spdy_version_); |
| 3382 scoped_ptr<SpdyFrame> control_frame( | 3588 scoped_ptr<SpdyFrame> control_frame( |
| 3383 framer.SerializeWindowUpdate(net::SpdyWindowUpdateIR(1, 2))); | 3589 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); |
| 3384 TestSpdyVisitor visitor(spdy_version_); | 3590 TestSpdyVisitor visitor(spdy_version_); |
| 3385 visitor.SimulateInFramer( | 3591 visitor.SimulateInFramer( |
| 3386 reinterpret_cast<unsigned char*>(control_frame->data()), | 3592 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 3387 control_frame->size()); | 3593 control_frame->size()); |
| 3388 EXPECT_EQ(1u, visitor.last_window_update_stream_); | 3594 EXPECT_EQ(1u, visitor.last_window_update_stream_); |
| 3389 EXPECT_EQ(2u, visitor.last_window_update_delta_); | 3595 EXPECT_EQ(2u, visitor.last_window_update_delta_); |
| 3390 } | 3596 } |
| 3391 | 3597 |
| 3392 TEST_P(SpdyFramerTest, ReceiveCredentialFrame) { | 3598 TEST_P(SpdyFramerTest, ReceiveCredentialFrame) { |
| 3393 if (!IsSpdy3()) { | 3599 if (!IsSpdy3()) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3437 't', 0x00, 0x00, 0x00, | 3643 't', 0x00, 0x00, 0x00, |
| 3438 0x0A, 'f', 'i', 'n', | 3644 0x0A, 'f', 'i', 'n', |
| 3439 'a', 'l', ' ', 'c', | 3645 'a', 'l', ' ', 'c', |
| 3440 'e', 'r', 't', | 3646 'e', 'r', 't', |
| 3441 }; | 3647 }; |
| 3442 TestSpdyVisitor visitor(spdy_version_); | 3648 TestSpdyVisitor visitor(spdy_version_); |
| 3443 visitor.use_compression_ = false; | 3649 visitor.use_compression_ = false; |
| 3444 string multiple_frame_data(reinterpret_cast<const char*>(kV3FrameData), | 3650 string multiple_frame_data(reinterpret_cast<const char*>(kV3FrameData), |
| 3445 arraysize(kV3FrameData)); | 3651 arraysize(kV3FrameData)); |
| 3446 scoped_ptr<SpdyFrame> control_frame( | 3652 scoped_ptr<SpdyFrame> control_frame( |
| 3447 framer.SerializeWindowUpdate(net::SpdyWindowUpdateIR(1, 2))); | 3653 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); |
| 3448 multiple_frame_data.append(string(control_frame->data(), | 3654 multiple_frame_data.append(string(control_frame->data(), |
| 3449 control_frame->size())); | 3655 control_frame->size())); |
| 3450 visitor.SimulateInFramer( | 3656 visitor.SimulateInFramer( |
| 3451 reinterpret_cast<unsigned const char*>(multiple_frame_data.data()), | 3657 reinterpret_cast<unsigned const char*>(multiple_frame_data.data()), |
| 3452 multiple_frame_data.length()); | 3658 multiple_frame_data.length()); |
| 3453 EXPECT_EQ(0, visitor.error_count_); | 3659 EXPECT_EQ(0, visitor.error_count_); |
| 3454 EXPECT_EQ(1u, visitor.last_window_update_stream_); | 3660 EXPECT_EQ(1u, visitor.last_window_update_stream_); |
| 3455 EXPECT_EQ(2u, visitor.last_window_update_delta_); | 3661 EXPECT_EQ(2u, visitor.last_window_update_delta_); |
| 3456 } | 3662 } |
| 3457 | 3663 |
| 3458 TEST_P(SpdyFramerTest, CreateContinuation) { | 3664 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) { |
| 3459 if (spdy_version_ < SPDY4) { | 3665 if (spdy_version_ < SPDY4) { |
| 3460 return; | 3666 return; |
| 3461 } | 3667 } |
| 3462 | 3668 |
| 3463 SpdyFramer framer(spdy_version_); | 3669 SpdyFramer framer(spdy_version_); |
| 3464 | 3670 framer.set_enable_compression(false); |
| 3465 const char kDescription[] = "CONTINUATION frame"; | 3671 const char kDescription[] = "CONTINUATION frame"; |
| 3466 | 3672 |
| 3467 const unsigned char kFrameData[] = { | 3673 const unsigned char kFrameData[] = { |
| 3468 0x00, 0x12, 0x09, 0x00, // CONTINUATION | 3674 0x00, 0x12, 0x09, 0x00, // CONTINUATION |
| 3469 0x00, 0x00, 0x00, 0x2a, // Stream 42 | 3675 0x00, 0x00, 0x00, 0x2a, // Stream 42 |
| 3470 0x40, 0x03, 0x62, 0x61, // @.ba | 3676 0x40, 0x03, 0x62, 0x61, // @.ba |
| 3471 0x72, 0x03, 0x66, 0x6f, // r.fo | 3677 0x72, 0x03, 0x66, 0x6f, // r.fo |
| 3472 0x6f, 0x40, 0x03, 0x66, // o@.f | 3678 0x6f, 0x40, 0x03, 0x66, // o@.f |
| 3473 0x6f, 0x6f, 0x03, 0x62, // oo.b | 3679 0x6f, 0x6f, 0x03, 0x62, // oo.b |
| 3474 0x61, 0x72, // ar | 3680 0x61, 0x72, // ar |
| 3475 }; | 3681 }; |
| 3476 | 3682 |
| 3477 SpdyContinuationIR continuation(42); | 3683 SpdyContinuationIR continuation(42); |
| 3478 continuation.SetHeader("bar", "foo"); | 3684 continuation.SetHeader("bar", "foo"); |
| 3479 continuation.SetHeader("foo", "bar"); | 3685 continuation.SetHeader("foo", "bar"); |
| 3480 scoped_ptr<SpdySerializedFrame> frame( | 3686 scoped_ptr<SpdySerializedFrame> frame( |
| 3481 framer.SerializeContinuation(continuation)); | 3687 framer.SerializeContinuation(continuation)); |
| 3482 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 3688 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 3483 } | 3689 } |
| 3484 | 3690 |
| 3485 TEST_P(SpdyFramerTest, ReadCompressedPushPromise) { | 3691 TEST_P(SpdyFramerTest, ReadCompressedPushPromise) { |
| 3486 if (spdy_version_ < 4) { | 3692 if (spdy_version_ <= SPDY3) { |
| 3487 return; | 3693 return; |
| 3488 } | 3694 } |
| 3489 | 3695 |
| 3490 SpdyFramer framer(spdy_version_); | 3696 SpdyFramer framer(spdy_version_); |
| 3491 SpdyPushPromiseIR push_promise(42, 57); | 3697 SpdyPushPromiseIR push_promise(42, 57); |
| 3492 push_promise.SetHeader("foo", "bar"); | 3698 push_promise.SetHeader("foo", "bar"); |
| 3493 push_promise.SetHeader("bar", "foofoo"); | 3699 push_promise.SetHeader("bar", "foofoo"); |
| 3494 SpdyHeaderBlock headers = push_promise.name_value_block(); | 3700 SpdyHeaderBlock headers = push_promise.name_value_block(); |
| 3495 scoped_ptr<SpdySerializedFrame> frame( | 3701 scoped_ptr<SpdySerializedFrame> frame( |
| 3496 framer.SerializePushPromise(push_promise)); | 3702 framer.SerializePushPromise(push_promise)); |
| 3497 EXPECT_TRUE(frame.get() != NULL); | 3703 EXPECT_TRUE(frame.get() != NULL); |
| 3498 TestSpdyVisitor visitor(spdy_version_); | 3704 TestSpdyVisitor visitor(spdy_version_); |
| 3499 visitor.use_compression_ = true; | 3705 visitor.use_compression_ = true; |
| 3500 visitor.SimulateInFramer( | 3706 visitor.SimulateInFramer( |
| 3501 reinterpret_cast<unsigned char*>(frame->data()), | 3707 reinterpret_cast<unsigned char*>(frame->data()), |
| 3502 frame->size()); | 3708 frame->size()); |
| 3503 EXPECT_EQ(42u, visitor.last_push_promise_stream_); | 3709 EXPECT_EQ(42u, visitor.last_push_promise_stream_); |
| 3504 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); | 3710 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); |
| 3505 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 3711 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
| 3506 } | 3712 } |
| 3507 | 3713 |
| 3508 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { | 3714 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { |
| 3509 if (spdy_version_ < 4) { | 3715 if (spdy_version_ <= SPDY3) { |
| 3510 return; | 3716 return; |
| 3511 } | 3717 } |
| 3512 | 3718 |
| 3513 const unsigned char kInput[] = { | 3719 const unsigned char kInput[] = { |
| 3514 0x00, 0x10, 0x01, 0x00, // HEADERS | 3720 0x00, 0x10, 0x01, 0x00, // HEADERS |
| 3515 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3721 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3516 0x40, 0x06, 0x43, 0x6f, | 3722 0x40, 0x06, 0x43, 0x6f, |
| 3517 0x6f, 0x6b, 0x69, 0x65, | 3723 0x6f, 0x6b, 0x69, 0x65, |
| 3518 0x07, 0x66, 0x6f, 0x6f, | 3724 0x07, 0x66, 0x6f, 0x6f, |
| 3519 0x3d, 0x62, 0x61, 0x72, | 3725 0x3d, 0x62, 0x61, 0x72, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3544 EXPECT_EQ(2, visitor.continuation_count_); | 3750 EXPECT_EQ(2, visitor.continuation_count_); |
| 3545 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3751 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3546 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 3752 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
| 3547 | 3753 |
| 3548 EXPECT_THAT(visitor.headers_, ElementsAre( | 3754 EXPECT_THAT(visitor.headers_, ElementsAre( |
| 3549 Pair("Cookie", "foo=bar; baz=bing; "), | 3755 Pair("Cookie", "foo=bar; baz=bing; "), |
| 3550 Pair("name", "value"))); | 3756 Pair("name", "value"))); |
| 3551 } | 3757 } |
| 3552 | 3758 |
| 3553 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndFin) { | 3759 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndFin) { |
| 3554 if (spdy_version_ < 4) { | 3760 if (spdy_version_ <= SPDY3) { |
| 3555 return; | 3761 return; |
| 3556 } | 3762 } |
| 3557 | 3763 |
| 3558 const unsigned char kInput[] = { | 3764 const unsigned char kInput[] = { |
| 3559 0x00, 0x10, 0x01, 0x01, // HEADERS: FIN | 3765 0x00, 0x10, 0x01, 0x01, // HEADERS: FIN |
| 3560 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3766 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3561 0x40, 0x06, 0x43, 0x6f, | 3767 0x40, 0x06, 0x43, 0x6f, |
| 3562 0x6f, 0x6b, 0x69, 0x65, | 3768 0x6f, 0x6b, 0x69, 0x65, |
| 3563 0x07, 0x66, 0x6f, 0x6f, | 3769 0x07, 0x66, 0x6f, 0x6f, |
| 3564 0x3d, 0x62, 0x61, 0x72, | 3770 0x3d, 0x62, 0x61, 0x72, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3590 EXPECT_EQ(1, visitor.fin_flag_count_); | 3796 EXPECT_EQ(1, visitor.fin_flag_count_); |
| 3591 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3797 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3592 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 3798 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
| 3593 | 3799 |
| 3594 EXPECT_THAT(visitor.headers_, ElementsAre( | 3800 EXPECT_THAT(visitor.headers_, ElementsAre( |
| 3595 Pair("Cookie", "foo=bar; baz=bing; "), | 3801 Pair("Cookie", "foo=bar; baz=bing; "), |
| 3596 Pair("name", "value"))); | 3802 Pair("name", "value"))); |
| 3597 } | 3803 } |
| 3598 | 3804 |
| 3599 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { | 3805 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { |
| 3600 if (spdy_version_ < 4) { | 3806 if (spdy_version_ <= SPDY3) { |
| 3601 return; | 3807 return; |
| 3602 } | 3808 } |
| 3603 | 3809 |
| 3604 const unsigned char kInput[] = { | 3810 const unsigned char kInput[] = { |
| 3605 0x00, 0x14, 0x05, 0x00, // PUSH_PROMISE | 3811 0x00, 0x14, 0x05, 0x00, // PUSH_PROMISE |
| 3606 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3812 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3607 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 | 3813 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 |
| 3608 0x40, 0x06, 0x43, 0x6f, | 3814 0x40, 0x06, 0x43, 0x6f, |
| 3609 0x6f, 0x6b, 0x69, 0x65, | 3815 0x6f, 0x6b, 0x69, 0x65, |
| 3610 0x07, 0x66, 0x6f, 0x6f, | 3816 0x07, 0x66, 0x6f, 0x6f, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3637 EXPECT_EQ(2, visitor.continuation_count_); | 3843 EXPECT_EQ(2, visitor.continuation_count_); |
| 3638 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3844 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3639 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 3845 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
| 3640 | 3846 |
| 3641 EXPECT_THAT(visitor.headers_, ElementsAre( | 3847 EXPECT_THAT(visitor.headers_, ElementsAre( |
| 3642 Pair("Cookie", "foo=bar; baz=bing; "), | 3848 Pair("Cookie", "foo=bar; baz=bing; "), |
| 3643 Pair("name", "value"))); | 3849 Pair("name", "value"))); |
| 3644 } | 3850 } |
| 3645 | 3851 |
| 3646 TEST_P(SpdyFramerTest, ReadContinuationWithWrongStreamId) { | 3852 TEST_P(SpdyFramerTest, ReadContinuationWithWrongStreamId) { |
| 3647 if (spdy_version_ < 4) { | 3853 if (spdy_version_ <= SPDY3) { |
| 3648 return; | 3854 return; |
| 3649 } | 3855 } |
| 3650 | 3856 |
| 3651 const unsigned char kInput[] = { | 3857 const unsigned char kInput[] = { |
| 3652 0x00, 0x10, 0x01, 0x00, // HEADERS | 3858 0x00, 0x10, 0x01, 0x00, // HEADERS |
| 3653 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3859 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3654 0x40, 0x06, 0x43, 0x6f, | 3860 0x40, 0x06, 0x43, 0x6f, |
| 3655 0x6f, 0x6b, 0x69, 0x65, | 3861 0x6f, 0x6b, 0x69, 0x65, |
| 3656 0x07, 0x66, 0x6f, 0x6f, | 3862 0x07, 0x66, 0x6f, 0x6f, |
| 3657 0x3d, 0x62, 0x61, 0x72, | 3863 0x3d, 0x62, 0x61, 0x72, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3673 EXPECT_EQ(1, visitor.error_count_); | 3879 EXPECT_EQ(1, visitor.error_count_); |
| 3674 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 3880 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 3675 visitor.framer_.error_code()) | 3881 visitor.framer_.error_code()) |
| 3676 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3882 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3677 EXPECT_EQ(1, visitor.headers_frame_count_); | 3883 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3678 EXPECT_EQ(0, visitor.continuation_count_); | 3884 EXPECT_EQ(0, visitor.continuation_count_); |
| 3679 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3885 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3680 } | 3886 } |
| 3681 | 3887 |
| 3682 TEST_P(SpdyFramerTest, ReadContinuationOutOfOrder) { | 3888 TEST_P(SpdyFramerTest, ReadContinuationOutOfOrder) { |
| 3683 if (spdy_version_ < 4) { | 3889 if (spdy_version_ <= SPDY3) { |
| 3684 return; | 3890 return; |
| 3685 } | 3891 } |
| 3686 | 3892 |
| 3687 const unsigned char kInput[] = { | 3893 const unsigned char kInput[] = { |
| 3688 0x00, 0x10, 0x09, 0x00, // CONTINUATION | 3894 0x00, 0x10, 0x09, 0x00, // CONTINUATION |
| 3689 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3895 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3690 0x40, 0x06, 0x43, 0x6f, | 3896 0x40, 0x06, 0x43, 0x6f, |
| 3691 0x6f, 0x6b, 0x69, 0x65, | 3897 0x6f, 0x6b, 0x69, 0x65, |
| 3692 0x07, 0x66, 0x6f, 0x6f, | 3898 0x07, 0x66, 0x6f, 0x6f, |
| 3693 0x3d, 0x62, 0x61, 0x72, | 3899 0x3d, 0x62, 0x61, 0x72, |
| 3694 }; | 3900 }; |
| 3695 | 3901 |
| 3696 SpdyFramer framer(spdy_version_); | 3902 SpdyFramer framer(spdy_version_); |
| 3697 TestSpdyVisitor visitor(spdy_version_); | 3903 TestSpdyVisitor visitor(spdy_version_); |
| 3698 framer.set_visitor(&visitor); | 3904 framer.set_visitor(&visitor); |
| 3699 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3905 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3700 | 3906 |
| 3701 EXPECT_EQ(1, visitor.error_count_); | 3907 EXPECT_EQ(1, visitor.error_count_); |
| 3702 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, | 3908 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, |
| 3703 visitor.framer_.error_code()) | 3909 visitor.framer_.error_code()) |
| 3704 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3910 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3705 EXPECT_EQ(0, visitor.continuation_count_); | 3911 EXPECT_EQ(0, visitor.continuation_count_); |
| 3706 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3912 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3707 } | 3913 } |
| 3708 | 3914 |
| 3709 TEST_P(SpdyFramerTest, ExpectContinuationReceiveData) { | 3915 TEST_P(SpdyFramerTest, ExpectContinuationReceiveData) { |
| 3710 if (spdy_version_ < 4) { | 3916 if (spdy_version_ <= SPDY3) { |
| 3711 return; | 3917 return; |
| 3712 } | 3918 } |
| 3713 | 3919 |
| 3714 const unsigned char kInput[] = { | 3920 const unsigned char kInput[] = { |
| 3715 0x00, 0x10, 0x01, 0x00, // HEADERS | 3921 0x00, 0x10, 0x01, 0x00, // HEADERS |
| 3716 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3922 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3717 0x40, 0x06, 0x43, 0x6f, | 3923 0x40, 0x06, 0x43, 0x6f, |
| 3718 0x6f, 0x6b, 0x69, 0x65, | 3924 0x6f, 0x6b, 0x69, 0x65, |
| 3719 0x07, 0x66, 0x6f, 0x6f, | 3925 0x07, 0x66, 0x6f, 0x6f, |
| 3720 0x3d, 0x62, 0x61, 0x72, | 3926 0x3d, 0x62, 0x61, 0x72, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3733 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, | 3939 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, |
| 3734 visitor.framer_.error_code()) | 3940 visitor.framer_.error_code()) |
| 3735 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3941 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3736 EXPECT_EQ(1, visitor.headers_frame_count_); | 3942 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3737 EXPECT_EQ(0, visitor.continuation_count_); | 3943 EXPECT_EQ(0, visitor.continuation_count_); |
| 3738 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3944 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3739 EXPECT_EQ(0, visitor.data_frame_count_); | 3945 EXPECT_EQ(0, visitor.data_frame_count_); |
| 3740 } | 3946 } |
| 3741 | 3947 |
| 3742 TEST_P(SpdyFramerTest, ExpectContinuationReceiveControlFrame) { | 3948 TEST_P(SpdyFramerTest, ExpectContinuationReceiveControlFrame) { |
| 3743 if (spdy_version_ < 4) { | 3949 if (spdy_version_ <= SPDY3) { |
| 3744 return; | 3950 return; |
| 3745 } | 3951 } |
| 3746 | 3952 |
| 3747 const unsigned char kInput[] = { | 3953 const unsigned char kInput[] = { |
| 3748 0x00, 0x10, 0x01, 0x00, // HEADERS | 3954 0x00, 0x10, 0x01, 0x00, // HEADERS |
| 3749 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3955 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3750 0x40, 0x06, 0x43, 0x6f, | 3956 0x40, 0x06, 0x43, 0x6f, |
| 3751 0x6f, 0x6b, 0x69, 0x65, | 3957 0x6f, 0x6b, 0x69, 0x65, |
| 3752 0x07, 0x66, 0x6f, 0x6f, | 3958 0x07, 0x66, 0x6f, 0x6f, |
| 3753 0x3d, 0x62, 0x61, 0x72, | 3959 0x3d, 0x62, 0x61, 0x72, |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3926 SpdyFramer::StatusCodeToString(RST_STREAM_REFUSED_STREAM)); | 4132 SpdyFramer::StatusCodeToString(RST_STREAM_REFUSED_STREAM)); |
| 3927 EXPECT_STREQ("UNSUPPORTED_VERSION", | 4133 EXPECT_STREQ("UNSUPPORTED_VERSION", |
| 3928 SpdyFramer::StatusCodeToString(RST_STREAM_UNSUPPORTED_VERSION)); | 4134 SpdyFramer::StatusCodeToString(RST_STREAM_UNSUPPORTED_VERSION)); |
| 3929 EXPECT_STREQ("CANCEL", | 4135 EXPECT_STREQ("CANCEL", |
| 3930 SpdyFramer::StatusCodeToString(RST_STREAM_CANCEL)); | 4136 SpdyFramer::StatusCodeToString(RST_STREAM_CANCEL)); |
| 3931 EXPECT_STREQ("INTERNAL_ERROR", | 4137 EXPECT_STREQ("INTERNAL_ERROR", |
| 3932 SpdyFramer::StatusCodeToString(RST_STREAM_INTERNAL_ERROR)); | 4138 SpdyFramer::StatusCodeToString(RST_STREAM_INTERNAL_ERROR)); |
| 3933 EXPECT_STREQ("FLOW_CONTROL_ERROR", | 4139 EXPECT_STREQ("FLOW_CONTROL_ERROR", |
| 3934 SpdyFramer::StatusCodeToString(RST_STREAM_FLOW_CONTROL_ERROR)); | 4140 SpdyFramer::StatusCodeToString(RST_STREAM_FLOW_CONTROL_ERROR)); |
| 3935 EXPECT_STREQ("UNKNOWN_STATUS", | 4141 EXPECT_STREQ("UNKNOWN_STATUS", |
| 3936 SpdyFramer::StatusCodeToString(RST_STREAM_NUM_STATUS_CODES)); | 4142 SpdyFramer::StatusCodeToString(-1)); |
| 3937 } | 4143 } |
| 3938 | 4144 |
| 3939 TEST_P(SpdyFramerTest, FrameTypeToStringTest) { | 4145 TEST_P(SpdyFramerTest, FrameTypeToStringTest) { |
| 3940 EXPECT_STREQ("DATA", | 4146 EXPECT_STREQ("DATA", |
| 3941 SpdyFramer::FrameTypeToString(DATA)); | 4147 SpdyFramer::FrameTypeToString(DATA)); |
| 3942 EXPECT_STREQ("SYN_STREAM", | 4148 EXPECT_STREQ("SYN_STREAM", |
| 3943 SpdyFramer::FrameTypeToString(SYN_STREAM)); | 4149 SpdyFramer::FrameTypeToString(SYN_STREAM)); |
| 3944 EXPECT_STREQ("SYN_REPLY", | 4150 EXPECT_STREQ("SYN_REPLY", |
| 3945 SpdyFramer::FrameTypeToString(SYN_REPLY)); | 4151 SpdyFramer::FrameTypeToString(SYN_REPLY)); |
| 3946 EXPECT_STREQ("RST_STREAM", | 4152 EXPECT_STREQ("RST_STREAM", |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3990 EXPECT_CALL(visitor, OnError(_)); | 4196 EXPECT_CALL(visitor, OnError(_)); |
| 3991 framer.ProcessInput("HTTP/1.0", 8); | 4197 framer.ProcessInput("HTTP/1.0", 8); |
| 3992 EXPECT_TRUE(framer.probable_http_response()); | 4198 EXPECT_TRUE(framer.probable_http_response()); |
| 3993 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4199 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 3994 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, framer.error_code()) | 4200 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, framer.error_code()) |
| 3995 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4201 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3996 } | 4202 } |
| 3997 } | 4203 } |
| 3998 | 4204 |
| 3999 TEST_P(SpdyFramerTest, DataFrameFlagsV2V3) { | 4205 TEST_P(SpdyFramerTest, DataFrameFlagsV2V3) { |
| 4000 if (spdy_version_ >= 4) { | 4206 if (spdy_version_ > SPDY3) { |
| 4001 return; | 4207 return; |
| 4002 } | 4208 } |
| 4003 | 4209 |
| 4004 for (int flags = 0; flags < 256; ++flags) { | 4210 for (int flags = 0; flags < 256; ++flags) { |
| 4005 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4211 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4006 | 4212 |
| 4007 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4213 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4008 SpdyFramer framer(spdy_version_); | 4214 SpdyFramer framer(spdy_version_); |
| 4009 framer.set_visitor(&visitor); | 4215 framer.set_visitor(&visitor); |
| 4010 | 4216 |
| 4011 net::SpdyDataIR data_ir(1, StringPiece("hello", 5)); | 4217 SpdyDataIR data_ir(1, StringPiece("hello", 5)); |
| 4012 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 4218 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 4013 SetFrameFlags(frame.get(), flags, spdy_version_); | 4219 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4014 | 4220 |
| 4015 if (flags & ~DATA_FLAG_FIN) { | 4221 if (flags & ~DATA_FLAG_FIN) { |
| 4016 EXPECT_CALL(visitor, OnError(_)); | 4222 EXPECT_CALL(visitor, OnError(_)); |
| 4017 } else { | 4223 } else { |
| 4018 EXPECT_CALL(visitor, OnDataFrameHeader(1, 5, flags & DATA_FLAG_FIN)); | 4224 EXPECT_CALL(visitor, OnDataFrameHeader(1, 5, flags & DATA_FLAG_FIN)); |
| 4019 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 5, false)); | 4225 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 5, false)); |
| 4020 if (flags & DATA_FLAG_FIN) { | 4226 if (flags & DATA_FLAG_FIN) { |
| 4021 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); | 4227 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); |
| 4022 } | 4228 } |
| 4023 } | 4229 } |
| 4024 | 4230 |
| 4025 framer.ProcessInput(frame->data(), frame->size()); | 4231 framer.ProcessInput(frame->data(), frame->size()); |
| 4026 if (flags & ~DATA_FLAG_FIN) { | 4232 if (flags & ~DATA_FLAG_FIN) { |
| 4027 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4233 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4028 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, | 4234 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, |
| 4029 framer.error_code()) | 4235 framer.error_code()) |
| 4030 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4236 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4031 } else { | 4237 } else { |
| 4032 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4238 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4033 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4239 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4034 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4240 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4035 } | 4241 } |
| 4036 } | 4242 } |
| 4037 } | 4243 } |
| 4038 | 4244 |
| 4039 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { | 4245 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { |
| 4040 if (spdy_version_ < 4) { | 4246 if (spdy_version_ <= SPDY3) { |
| 4041 return; | 4247 return; |
| 4042 } | 4248 } |
| 4043 | 4249 |
| 4044 uint8 valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT | | 4250 uint8 valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT | |
| 4045 DATA_FLAG_PAD_LOW | DATA_FLAG_PAD_HIGH; | 4251 DATA_FLAG_PAD_LOW | DATA_FLAG_PAD_HIGH; |
| 4046 | 4252 |
| 4047 for (int flags = 0; flags < 256; ++flags) { | 4253 for (int flags = 0; flags < 256; ++flags) { |
| 4048 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4254 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4049 | 4255 |
| 4050 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4256 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4051 SpdyFramer framer(spdy_version_); | 4257 SpdyFramer framer(spdy_version_); |
| 4052 framer.set_visitor(&visitor); | 4258 framer.set_visitor(&visitor); |
| 4053 | 4259 |
| 4054 net::SpdyDataIR data_ir(1, StringPiece("hello", 5)); | 4260 SpdyDataIR data_ir(1, StringPiece("hello", 5)); |
| 4055 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 4261 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 4056 SetFrameFlags(frame.get(), flags, spdy_version_); | 4262 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4057 | 4263 |
| 4058 if (flags & ~valid_data_flags) { | 4264 if (flags & ~valid_data_flags) { |
| 4059 EXPECT_CALL(visitor, OnError(_)); | 4265 EXPECT_CALL(visitor, OnError(_)); |
| 4060 } else { | 4266 } else { |
| 4061 EXPECT_CALL(visitor, OnDataFrameHeader(1, 5, flags & DATA_FLAG_FIN)); | 4267 EXPECT_CALL(visitor, OnDataFrameHeader(1, 5, flags & DATA_FLAG_FIN)); |
| 4062 if ((flags & DATA_FLAG_PAD_LOW) || (flags & DATA_FLAG_PAD_HIGH)) { | 4268 if ((flags & DATA_FLAG_PAD_LOW) || (flags & DATA_FLAG_PAD_HIGH)) { |
| 4063 // Expect Error since we don't set pad_high and pad_low in payload. | 4269 // Expect Error since we don't set pad_high and pad_low in payload. |
| 4064 EXPECT_CALL(visitor, OnError(_)); | 4270 EXPECT_CALL(visitor, OnError(_)); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4203 } | 4409 } |
| 4204 | 4410 |
| 4205 TEST_P(SpdyFramerTest, RstStreamFrameFlags) { | 4411 TEST_P(SpdyFramerTest, RstStreamFrameFlags) { |
| 4206 for (int flags = 0; flags < 256; ++flags) { | 4412 for (int flags = 0; flags < 256; ++flags) { |
| 4207 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4413 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4208 | 4414 |
| 4209 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4415 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4210 SpdyFramer framer(spdy_version_); | 4416 SpdyFramer framer(spdy_version_); |
| 4211 framer.set_visitor(&visitor); | 4417 framer.set_visitor(&visitor); |
| 4212 | 4418 |
| 4213 net::SpdyRstStreamIR rst_stream(13, RST_STREAM_CANCEL, ""); | 4419 SpdyRstStreamIR rst_stream(13, RST_STREAM_CANCEL, ""); |
| 4214 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); | 4420 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); |
| 4215 SetFrameFlags(frame.get(), flags, spdy_version_); | 4421 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4216 | 4422 |
| 4217 if (flags != 0) { | 4423 if (flags != 0) { |
| 4218 EXPECT_CALL(visitor, OnError(_)); | 4424 EXPECT_CALL(visitor, OnError(_)); |
| 4219 } else { | 4425 } else { |
| 4220 EXPECT_CALL(visitor, OnRstStream(13, RST_STREAM_CANCEL)); | 4426 EXPECT_CALL(visitor, OnRstStream(13, RST_STREAM_CANCEL)); |
| 4221 } | 4427 } |
| 4222 | 4428 |
| 4223 framer.ProcessInput(frame->data(), frame->size()); | 4429 framer.ProcessInput(frame->data(), frame->size()); |
| 4224 if (flags != 0) { | 4430 if (flags != 0) { |
| 4225 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4431 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4226 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4432 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 4227 framer.error_code()) | 4433 framer.error_code()) |
| 4228 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4434 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4229 } else { | 4435 } else { |
| 4230 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4436 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4231 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4437 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4232 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4438 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4233 } | 4439 } |
| 4234 } | 4440 } |
| 4235 } | 4441 } |
| 4236 | 4442 |
| 4237 TEST_P(SpdyFramerTest, SettingsFrameFlagsOldFormat) { | 4443 TEST_P(SpdyFramerTest, SettingsFrameFlagsOldFormat) { |
| 4238 if (spdy_version_ >= 4) { return; } | 4444 if (spdy_version_ > SPDY3) { return; } |
| 4239 for (int flags = 0; flags < 256; ++flags) { | 4445 for (int flags = 0; flags < 256; ++flags) { |
| 4240 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4446 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4241 | 4447 |
| 4242 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4448 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4243 SpdyFramer framer(spdy_version_); | 4449 SpdyFramer framer(spdy_version_); |
| 4244 framer.set_visitor(&visitor); | 4450 framer.set_visitor(&visitor); |
| 4245 | 4451 |
| 4246 SpdySettingsIR settings_ir; | 4452 SpdySettingsIR settings_ir; |
| 4247 settings_ir.AddSetting(SETTINGS_UPLOAD_BANDWIDTH, | 4453 settings_ir.AddSetting(SETTINGS_UPLOAD_BANDWIDTH, |
| 4248 false, | 4454 false, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 4269 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4475 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4270 } else { | 4476 } else { |
| 4271 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4477 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4272 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4478 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4273 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4479 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4274 } | 4480 } |
| 4275 } | 4481 } |
| 4276 } | 4482 } |
| 4277 | 4483 |
| 4278 TEST_P(SpdyFramerTest, SettingsFrameFlags) { | 4484 TEST_P(SpdyFramerTest, SettingsFrameFlags) { |
| 4279 if (spdy_version_ < 4) { return; } | 4485 if (spdy_version_ <= SPDY3) { return; } |
| 4280 for (int flags = 0; flags < 256; ++flags) { | 4486 for (int flags = 0; flags < 256; ++flags) { |
| 4281 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4487 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4282 | 4488 |
| 4283 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4489 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4284 SpdyFramer framer(spdy_version_); | 4490 SpdyFramer framer(spdy_version_); |
| 4285 framer.set_visitor(&visitor); | 4491 framer.set_visitor(&visitor); |
| 4286 | 4492 |
| 4287 SpdySettingsIR settings_ir; | 4493 SpdySettingsIR settings_ir; |
| 4288 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 0, 16); | 4494 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 0, 16); |
| 4289 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); | 4495 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4415 for (int flags = 0; flags < 256; ++flags) { | 4621 for (int flags = 0; flags < 256; ++flags) { |
| 4416 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4622 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4417 | 4623 |
| 4418 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4624 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4419 SpdyFramer framer(spdy_version_); | 4625 SpdyFramer framer(spdy_version_); |
| 4420 framer.set_visitor(&visitor); | 4626 framer.set_visitor(&visitor); |
| 4421 | 4627 |
| 4422 scoped_ptr<SpdyFrame> frame(framer.SerializePing(SpdyPingIR(42))); | 4628 scoped_ptr<SpdyFrame> frame(framer.SerializePing(SpdyPingIR(42))); |
| 4423 SetFrameFlags(frame.get(), flags, spdy_version_); | 4629 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4424 | 4630 |
| 4425 if (spdy_version_ >= SPDY4 && | 4631 if (spdy_version_ > SPDY3 && |
| 4426 flags == PING_FLAG_ACK) { | 4632 flags == PING_FLAG_ACK) { |
| 4427 EXPECT_CALL(visitor, OnPing(42, true)); | 4633 EXPECT_CALL(visitor, OnPing(42, true)); |
| 4428 } else if (flags == 0) { | 4634 } else if (flags == 0) { |
| 4429 EXPECT_CALL(visitor, OnPing(42, false)); | 4635 EXPECT_CALL(visitor, OnPing(42, false)); |
| 4430 } else { | 4636 } else { |
| 4431 EXPECT_CALL(visitor, OnError(_)); | 4637 EXPECT_CALL(visitor, OnError(_)); |
| 4432 } | 4638 } |
| 4433 | 4639 |
| 4434 framer.ProcessInput(frame->data(), frame->size()); | 4640 framer.ProcessInput(frame->data(), frame->size()); |
| 4435 if ((spdy_version_ >= SPDY4 && flags == PING_FLAG_ACK) || | 4641 if ((spdy_version_ > SPDY3 && flags == PING_FLAG_ACK) || |
| 4436 flags == 0) { | 4642 flags == 0) { |
| 4437 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4643 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4438 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4644 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4439 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4645 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4440 } else { | 4646 } else { |
| 4441 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4647 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4442 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4648 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 4443 framer.error_code()) | 4649 framer.error_code()) |
| 4444 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4650 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4445 } | 4651 } |
| 4446 } | 4652 } |
| 4447 } | 4653 } |
| 4448 | 4654 |
| 4449 TEST_P(SpdyFramerTest, WindowUpdateFrameFlags) { | 4655 TEST_P(SpdyFramerTest, WindowUpdateFrameFlags) { |
| 4450 for (int flags = 0; flags < 256; ++flags) { | 4656 for (int flags = 0; flags < 256; ++flags) { |
| 4451 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4657 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4452 | 4658 |
| 4453 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4659 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4454 SpdyFramer framer(spdy_version_); | 4660 SpdyFramer framer(spdy_version_); |
| 4455 framer.set_visitor(&visitor); | 4661 framer.set_visitor(&visitor); |
| 4456 | 4662 |
| 4457 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( | 4663 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( |
| 4458 net::SpdyWindowUpdateIR(4, 1024))); | 4664 SpdyWindowUpdateIR(4, 1024))); |
| 4459 SetFrameFlags(frame.get(), flags, spdy_version_); | 4665 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4460 | 4666 |
| 4461 if (flags != 0) { | 4667 if (flags != 0) { |
| 4462 EXPECT_CALL(visitor, OnError(_)); | 4668 EXPECT_CALL(visitor, OnError(_)); |
| 4463 } else { | 4669 } else { |
| 4464 EXPECT_CALL(visitor, OnWindowUpdate(4, 1024)); | 4670 EXPECT_CALL(visitor, OnWindowUpdate(4, 1024)); |
| 4465 } | 4671 } |
| 4466 | 4672 |
| 4467 framer.ProcessInput(frame->data(), frame->size()); | 4673 framer.ProcessInput(frame->data(), frame->size()); |
| 4468 if (flags != 0) { | 4674 if (flags != 0) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4616 | 4822 |
| 4617 SettingsFlagsAndId id_and_flags = | 4823 SettingsFlagsAndId id_and_flags = |
| 4618 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); | 4824 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); |
| 4619 EXPECT_EQ(kId, id_and_flags.id()); | 4825 EXPECT_EQ(kId, id_and_flags.id()); |
| 4620 EXPECT_EQ(kFlags, id_and_flags.flags()); | 4826 EXPECT_EQ(kFlags, id_and_flags.flags()); |
| 4621 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); | 4827 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); |
| 4622 } | 4828 } |
| 4623 | 4829 |
| 4624 // Test handling of a RST_STREAM with out-of-bounds status codes. | 4830 // Test handling of a RST_STREAM with out-of-bounds status codes. |
| 4625 TEST_P(SpdyFramerTest, RstStreamStatusBounds) { | 4831 TEST_P(SpdyFramerTest, RstStreamStatusBounds) { |
| 4626 DCHECK_GE(0xff, RST_STREAM_NUM_STATUS_CODES); | 4832 const unsigned char kRstStreamStatusTooLow = 0x00; |
| 4627 | 4833 const unsigned char kRstStreamStatusTooHigh = 0xff; |
| 4628 const unsigned char kV3RstStreamInvalid[] = { | 4834 const unsigned char kV3RstStreamInvalid[] = { |
| 4629 0x80, spdy_version_ch_, 0x00, 0x03, | 4835 0x80, spdy_version_ch_, 0x00, 0x03, |
| 4630 0x00, 0x00, 0x00, 0x08, | 4836 0x00, 0x00, 0x00, 0x08, |
| 4631 0x00, 0x00, 0x00, 0x01, | 4837 0x00, 0x00, 0x00, 0x01, |
| 4632 0x00, 0x00, 0x00, RST_STREAM_INVALID | 4838 0x00, 0x00, 0x00, kRstStreamStatusTooLow |
| 4633 }; | 4839 }; |
| 4634 const unsigned char kV4RstStreamInvalid[] = { | 4840 const unsigned char kV4RstStreamInvalid[] = { |
| 4635 0x00, 0x04, 0x03, 0x00, | 4841 0x00, 0x04, 0x03, 0x00, |
| 4636 0x00, 0x00, 0x00, 0x01, | 4842 0x00, 0x00, 0x00, 0x01, |
| 4637 0x00, 0x00, 0x00, RST_STREAM_INVALID | 4843 0x00, 0x00, 0x00, kRstStreamStatusTooLow |
| 4638 }; | 4844 }; |
| 4639 | 4845 |
| 4640 const unsigned char kV3RstStreamNumStatusCodes[] = { | 4846 const unsigned char kV3RstStreamNumStatusCodes[] = { |
| 4641 0x80, spdy_version_ch_, 0x00, 0x03, | 4847 0x80, spdy_version_ch_, 0x00, 0x03, |
| 4642 0x00, 0x00, 0x00, 0x08, | 4848 0x00, 0x00, 0x00, 0x08, |
| 4643 0x00, 0x00, 0x00, 0x01, | 4849 0x00, 0x00, 0x00, 0x01, |
| 4644 0x00, 0x00, 0x00, RST_STREAM_NUM_STATUS_CODES | 4850 0x00, 0x00, 0x00, kRstStreamStatusTooHigh |
| 4645 }; | 4851 }; |
| 4646 const unsigned char kV4RstStreamNumStatusCodes[] = { | 4852 const unsigned char kV4RstStreamNumStatusCodes[] = { |
| 4647 0x00, 0x04, 0x03, 0x00, | 4853 0x00, 0x04, 0x03, 0x00, |
| 4648 0x00, 0x00, 0x00, 0x01, | 4854 0x00, 0x00, 0x00, 0x01, |
| 4649 0x00, 0x00, 0x00, RST_STREAM_NUM_STATUS_CODES | 4855 0x00, 0x00, 0x00, kRstStreamStatusTooHigh |
| 4650 }; | 4856 }; |
| 4651 | 4857 |
| 4652 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4858 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4653 SpdyFramer framer(spdy_version_); | 4859 SpdyFramer framer(spdy_version_); |
| 4654 framer.set_visitor(&visitor); | 4860 framer.set_visitor(&visitor); |
| 4655 | 4861 |
| 4656 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); | |
| 4657 if (IsSpdy4()) { | 4862 if (IsSpdy4()) { |
| 4863 EXPECT_CALL(visitor, OnError(_)); |
| 4658 framer.ProcessInput(reinterpret_cast<const char*>(kV4RstStreamInvalid), | 4864 framer.ProcessInput(reinterpret_cast<const char*>(kV4RstStreamInvalid), |
| 4659 arraysize(kV4RstStreamInvalid)); | 4865 arraysize(kV4RstStreamInvalid)); |
| 4866 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4867 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 4868 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4660 } else { | 4869 } else { |
| 4870 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); |
| 4661 framer.ProcessInput(reinterpret_cast<const char*>(kV3RstStreamInvalid), | 4871 framer.ProcessInput(reinterpret_cast<const char*>(kV3RstStreamInvalid), |
| 4662 arraysize(kV3RstStreamInvalid)); | 4872 arraysize(kV3RstStreamInvalid)); |
| 4873 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4874 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4875 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4663 } | 4876 } |
| 4664 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | |
| 4665 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | |
| 4666 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
| 4667 | 4877 |
| 4668 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); | 4878 |
| 4879 framer.Reset(); |
| 4880 |
| 4669 if (IsSpdy4()) { | 4881 if (IsSpdy4()) { |
| 4882 EXPECT_CALL(visitor, OnError(_)); |
| 4670 framer.ProcessInput( | 4883 framer.ProcessInput( |
| 4671 reinterpret_cast<const char*>(kV4RstStreamNumStatusCodes), | 4884 reinterpret_cast<const char*>(kV4RstStreamNumStatusCodes), |
| 4672 arraysize(kV4RstStreamNumStatusCodes)); | 4885 arraysize(kV4RstStreamNumStatusCodes)); |
| 4886 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4887 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 4888 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4673 } else { | 4889 } else { |
| 4890 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); |
| 4674 framer.ProcessInput( | 4891 framer.ProcessInput( |
| 4675 reinterpret_cast<const char*>(kV3RstStreamNumStatusCodes), | 4892 reinterpret_cast<const char*>(kV3RstStreamNumStatusCodes), |
| 4676 arraysize(kV3RstStreamNumStatusCodes)); | 4893 arraysize(kV3RstStreamNumStatusCodes)); |
| 4894 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4895 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4896 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4677 } | 4897 } |
| 4678 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | |
| 4679 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | |
| 4680 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
| 4681 } | 4898 } |
| 4682 | 4899 |
| 4683 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. | 4900 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. |
| 4684 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) { | 4901 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) { |
| 4685 const unsigned char kV2FrameData[] = { | 4902 const unsigned char kV2FrameData[] = { |
| 4686 0x80, spdy_version_ch_, 0x00, 0x07, | 4903 0x80, spdy_version_ch_, 0x00, 0x07, |
| 4687 0x00, 0x00, 0x00, 0x04, | 4904 0x00, 0x00, 0x00, 0x04, |
| 4688 0xff, 0xff, 0xff, 0xff, | 4905 0xff, 0xff, 0xff, 0xff, |
| 4689 }; | 4906 }; |
| 4690 const unsigned char kV3FrameData[] = { | 4907 const unsigned char kV3FrameData[] = { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4736 SpdyBlockedIR blocked_ir(0); | 4953 SpdyBlockedIR blocked_ir(0); |
| 4737 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); | 4954 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); |
| 4738 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); | 4955 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); |
| 4739 | 4956 |
| 4740 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4957 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4741 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4958 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4742 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4959 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4743 } | 4960 } |
| 4744 | 4961 |
| 4745 } // namespace net | 4962 } // namespace net |
| OLD | NEW |