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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "net/spdy/spdy_framer.h" | 10 #include "net/spdy/spdy_framer.h" |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 } | 517 } |
518 | 518 |
519 void AddSpdySettingFromWireFormat(SettingsMap* settings, | 519 void AddSpdySettingFromWireFormat(SettingsMap* settings, |
520 uint32 key, | 520 uint32 key, |
521 uint32 value) { | 521 uint32 value) { |
522 SettingsFlagsAndId flags_and_id = | 522 SettingsFlagsAndId flags_and_id = |
523 SettingsFlagsAndId::FromWireFormat(spdy_version_, key); | 523 SettingsFlagsAndId::FromWireFormat(spdy_version_, key); |
524 SpdySettingsIds id = static_cast<SpdySettingsIds>(flags_and_id.id()); | 524 SpdySettingsIds id = static_cast<SpdySettingsIds>(flags_and_id.id()); |
525 SpdySettingsFlags flags = | 525 SpdySettingsFlags flags = |
526 static_cast<SpdySettingsFlags>(flags_and_id.flags()); | 526 static_cast<SpdySettingsFlags>(flags_and_id.flags()); |
| 527 CHECK(settings->find(id) == settings->end()); |
527 settings->insert(std::make_pair(id, SettingsFlagsAndValue(flags, value))); | 528 settings->insert(std::make_pair(id, SettingsFlagsAndValue(flags, value))); |
528 } | 529 } |
529 | 530 |
530 bool IsSpdy2() { return spdy_version_ == SPDY2; } | 531 bool IsSpdy2() { return spdy_version_ == SPDY2; } |
531 | 532 |
532 // Version of SPDY protocol to be used. | 533 // Version of SPDY protocol to be used. |
533 unsigned char spdy_version_; | 534 unsigned char spdy_version_; |
534 }; | 535 }; |
535 | 536 |
536 // All tests are run with two different SPDY versions: SPDY/2 and SPDY/3. | 537 // All tests are run with two different SPDY versions: SPDY/2 and SPDY/3. |
(...skipping 2033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2570 reinterpret_cast<unsigned char*>(control_frame->data() + framed_data), | 2571 reinterpret_cast<unsigned char*>(control_frame->data() + framed_data), |
2571 to_read); | 2572 to_read); |
2572 unframed_data -= to_read; | 2573 unframed_data -= to_read; |
2573 framed_data += to_read; | 2574 framed_data += to_read; |
2574 } | 2575 } |
2575 EXPECT_EQ(0, visitor.error_count_); | 2576 EXPECT_EQ(0, visitor.error_count_); |
2576 EXPECT_EQ(settings.size() * 2, static_cast<unsigned>(visitor.setting_count_)); | 2577 EXPECT_EQ(settings.size() * 2, static_cast<unsigned>(visitor.setting_count_)); |
2577 EXPECT_EQ(2, visitor.settings_frame_count_); | 2578 EXPECT_EQ(2, visitor.settings_frame_count_); |
2578 } | 2579 } |
2579 | 2580 |
| 2581 // Tests handling of SETTINGS frame with duplicate entries. |
| 2582 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { |
| 2583 SpdyFramer framer(spdy_version_); |
| 2584 |
| 2585 const unsigned char kV2FrameData[] = { |
| 2586 0x80, spdy_version_, 0x00, 0x04, |
| 2587 0x00, 0x00, 0x00, 0x1C, |
| 2588 0x00, 0x00, 0x00, 0x03, |
| 2589 0x01, 0x00, 0x00, 0x00, // 1st Setting |
| 2590 0x00, 0x00, 0x00, 0x02, |
| 2591 0x01, 0x00, 0x00, 0x00, // 2nd (duplicate) Setting |
| 2592 0x00, 0x00, 0x00, 0x03, |
| 2593 0x03, 0x00, 0x00, 0x00, // 3rd (unprocessed) Setting |
| 2594 0x00, 0x00, 0x00, 0x03, |
| 2595 }; |
| 2596 |
| 2597 const unsigned char kV3FrameData[] = { |
| 2598 0x80, spdy_version_, 0x00, 0x04, |
| 2599 0x00, 0x00, 0x00, 0x1C, |
| 2600 0x00, 0x00, 0x00, 0x03, |
| 2601 0x00, 0x00, 0x00, 0x01, // 1st Setting |
| 2602 0x00, 0x00, 0x00, 0x02, |
| 2603 0x00, 0x00, 0x00, 0x01, // 2nd (duplicate) Setting |
| 2604 0x00, 0x00, 0x00, 0x03, |
| 2605 0x00, 0x00, 0x00, 0x03, // 3rd (unprocessed) Setting |
| 2606 0x00, 0x00, 0x00, 0x03, |
| 2607 }; |
| 2608 |
| 2609 TestSpdyVisitor visitor(spdy_version_); |
| 2610 visitor.use_compression_ = false; |
| 2611 if (IsSpdy2()) { |
| 2612 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); |
| 2613 } else { |
| 2614 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); |
| 2615 } |
| 2616 EXPECT_EQ(1, visitor.error_count_); |
| 2617 EXPECT_EQ(1, visitor.setting_count_); |
| 2618 EXPECT_EQ(1, visitor.settings_frame_count_); |
| 2619 } |
| 2620 |
| 2621 // Tests handling of SETTINGS frame with entries out of order. |
| 2622 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { |
| 2623 SpdyFramer framer(spdy_version_); |
| 2624 |
| 2625 const unsigned char kV2FrameData[] = { |
| 2626 0x80, spdy_version_, 0x00, 0x04, |
| 2627 0x00, 0x00, 0x00, 0x1C, |
| 2628 0x00, 0x00, 0x00, 0x03, |
| 2629 0x02, 0x00, 0x00, 0x00, // 1st Setting |
| 2630 0x00, 0x00, 0x00, 0x02, |
| 2631 0x01, 0x00, 0x00, 0x00, // 2nd (out of order) Setting |
| 2632 0x00, 0x00, 0x00, 0x03, |
| 2633 0x03, 0x00, 0x00, 0x00, // 3rd (unprocessed) Setting |
| 2634 0x00, 0x00, 0x00, 0x03, |
| 2635 }; |
| 2636 |
| 2637 const unsigned char kV3FrameData[] = { |
| 2638 0x80, spdy_version_, 0x00, 0x04, |
| 2639 0x00, 0x00, 0x00, 0x1C, |
| 2640 0x00, 0x00, 0x00, 0x03, |
| 2641 0x00, 0x00, 0x00, 0x02, // 1st Setting |
| 2642 0x00, 0x00, 0x00, 0x02, |
| 2643 0x00, 0x00, 0x00, 0x01, // 2nd (out of order) Setting |
| 2644 0x00, 0x00, 0x00, 0x03, |
| 2645 0x00, 0x00, 0x01, 0x03, // 3rd (unprocessed) Setting |
| 2646 0x00, 0x00, 0x00, 0x03, |
| 2647 }; |
| 2648 |
| 2649 TestSpdyVisitor visitor(spdy_version_); |
| 2650 visitor.use_compression_ = false; |
| 2651 if (IsSpdy2()) { |
| 2652 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); |
| 2653 } else { |
| 2654 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); |
| 2655 } |
| 2656 EXPECT_EQ(1, visitor.error_count_); |
| 2657 EXPECT_EQ(1, visitor.setting_count_); |
| 2658 EXPECT_EQ(1, visitor.settings_frame_count_); |
| 2659 } |
| 2660 |
2580 TEST_P(SpdyFramerTest, ReadCredentialFrame) { | 2661 TEST_P(SpdyFramerTest, ReadCredentialFrame) { |
2581 SpdyCredential credential; | 2662 SpdyCredential credential; |
2582 credential.slot = 3; | 2663 credential.slot = 3; |
2583 credential.proof = "proof"; | 2664 credential.proof = "proof"; |
2584 credential.certs.push_back("a cert"); | 2665 credential.certs.push_back("a cert"); |
2585 credential.certs.push_back("another cert"); | 2666 credential.certs.push_back("another cert"); |
2586 credential.certs.push_back("final cert"); | 2667 credential.certs.push_back("final cert"); |
2587 SpdyFramer framer(spdy_version_); | 2668 SpdyFramer framer(spdy_version_); |
2588 scoped_ptr<SpdyFrame> control_frame( | 2669 scoped_ptr<SpdyFrame> control_frame( |
2589 framer.CreateCredentialFrame(credential)); | 2670 framer.CreateCredentialFrame(credential)); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2961 const uint32 kWireFormat = htonl(IsSpdy2() ? 0x04030201 : 0x01020304); | 3042 const uint32 kWireFormat = htonl(IsSpdy2() ? 0x04030201 : 0x01020304); |
2962 | 3043 |
2963 SettingsFlagsAndId id_and_flags = | 3044 SettingsFlagsAndId id_and_flags = |
2964 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); | 3045 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); |
2965 EXPECT_EQ(kId, id_and_flags.id()); | 3046 EXPECT_EQ(kId, id_and_flags.id()); |
2966 EXPECT_EQ(kFlags, id_and_flags.flags()); | 3047 EXPECT_EQ(kFlags, id_and_flags.flags()); |
2967 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); | 3048 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); |
2968 } | 3049 } |
2969 | 3050 |
2970 } // namespace net | 3051 } // namespace net |
OLD | NEW |