OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_crypto_stream.h" | 5 #include "net/quic/quic_crypto_stream.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "net/quic/crypto/crypto_handshake.h" | 11 #include "net/quic/crypto/crypto_handshake.h" |
12 #include "net/quic/crypto/crypto_protocol.h" | 12 #include "net/quic/crypto/crypto_protocol.h" |
13 #include "net/quic/quic_flags.h" | 13 #include "net/quic/quic_flags.h" |
14 #include "net/quic/test_tools/crypto_test_utils.h" | 14 #include "net/quic/test_tools/crypto_test_utils.h" |
15 #include "net/quic/test_tools/quic_test_utils.h" | 15 #include "net/quic/test_tools/quic_test_utils.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 using std::string; | 19 using std::string; |
20 using std::vector; | 20 using std::vector; |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 namespace test { | 23 namespace test { |
24 namespace { | 24 namespace { |
25 | 25 |
26 class MockQuicCryptoStream : public QuicCryptoStream { | 26 class MockQuicCryptoStream : public QuicCryptoStream { |
27 public: | 27 public: |
28 explicit MockQuicCryptoStream(QuicSession* session) | 28 explicit MockQuicCryptoStream(QuicSession* session) |
29 : QuicCryptoStream(session) { | 29 : QuicCryptoStream(session) {} |
30 } | |
31 | 30 |
32 virtual void OnHandshakeMessage( | 31 virtual void OnHandshakeMessage( |
33 const CryptoHandshakeMessage& message) OVERRIDE { | 32 const CryptoHandshakeMessage& message) OVERRIDE { |
34 messages_.push_back(message); | 33 messages_.push_back(message); |
35 } | 34 } |
36 | 35 |
37 vector<CryptoHandshakeMessage>* messages() { | 36 vector<CryptoHandshakeMessage>* messages() { return &messages_; } |
38 return &messages_; | |
39 } | |
40 | 37 |
41 private: | 38 private: |
42 vector<CryptoHandshakeMessage> messages_; | 39 vector<CryptoHandshakeMessage> messages_; |
43 | 40 |
44 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoStream); | 41 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoStream); |
45 }; | 42 }; |
46 | 43 |
47 class QuicCryptoStreamTest : public ::testing::Test { | 44 class QuicCryptoStreamTest : public ::testing::Test { |
48 public: | 45 public: |
49 QuicCryptoStreamTest() | 46 QuicCryptoStreamTest() |
(...skipping 21 matching lines...) Expand all Loading... |
71 private: | 68 private: |
72 DISALLOW_COPY_AND_ASSIGN(QuicCryptoStreamTest); | 69 DISALLOW_COPY_AND_ASSIGN(QuicCryptoStreamTest); |
73 }; | 70 }; |
74 | 71 |
75 TEST_F(QuicCryptoStreamTest, NotInitiallyConected) { | 72 TEST_F(QuicCryptoStreamTest, NotInitiallyConected) { |
76 EXPECT_FALSE(stream_.encryption_established()); | 73 EXPECT_FALSE(stream_.encryption_established()); |
77 EXPECT_FALSE(stream_.handshake_confirmed()); | 74 EXPECT_FALSE(stream_.handshake_confirmed()); |
78 } | 75 } |
79 | 76 |
80 TEST_F(QuicCryptoStreamTest, ProcessRawData) { | 77 TEST_F(QuicCryptoStreamTest, ProcessRawData) { |
81 EXPECT_EQ(message_data_->length(), | 78 EXPECT_EQ( |
82 stream_.ProcessRawData(message_data_->data(), | 79 message_data_->length(), |
83 message_data_->length())); | 80 stream_.ProcessRawData(message_data_->data(), message_data_->length())); |
84 ASSERT_EQ(1u, stream_.messages()->size()); | 81 ASSERT_EQ(1u, stream_.messages()->size()); |
85 const CryptoHandshakeMessage& message = (*stream_.messages())[0]; | 82 const CryptoHandshakeMessage& message = (*stream_.messages())[0]; |
86 EXPECT_EQ(kSHLO, message.tag()); | 83 EXPECT_EQ(kSHLO, message.tag()); |
87 EXPECT_EQ(2u, message.tag_value_map().size()); | 84 EXPECT_EQ(2u, message.tag_value_map().size()); |
88 EXPECT_EQ("abc", CryptoTestUtils::GetValueForTag(message, 1)); | 85 EXPECT_EQ("abc", CryptoTestUtils::GetValueForTag(message, 1)); |
89 EXPECT_EQ("def", CryptoTestUtils::GetValueForTag(message, 2)); | 86 EXPECT_EQ("def", CryptoTestUtils::GetValueForTag(message, 2)); |
90 } | 87 } |
91 | 88 |
92 TEST_F(QuicCryptoStreamTest, ProcessBadData) { | 89 TEST_F(QuicCryptoStreamTest, ProcessBadData) { |
93 string bad(message_data_->data(), message_data_->length()); | 90 string bad(message_data_->data(), message_data_->length()); |
94 const int kFirstTagIndex = sizeof(uint32) + // message tag | 91 const int kFirstTagIndex = sizeof(uint32) + // message tag |
95 sizeof(uint16) + // number of tag-value pairs | 92 sizeof(uint16) + // number of tag-value pairs |
96 sizeof(uint16); // padding | 93 sizeof(uint16); // padding |
97 EXPECT_EQ(1, bad[kFirstTagIndex]); | 94 EXPECT_EQ(1, bad[kFirstTagIndex]); |
98 bad[kFirstTagIndex] = 0x7F; // out of order tag | 95 bad[kFirstTagIndex] = 0x7F; // out of order tag |
99 | 96 |
100 EXPECT_CALL(*connection_, | 97 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_CRYPTO_TAGS_OUT_OF_ORDER)); |
101 SendConnectionClose(QUIC_CRYPTO_TAGS_OUT_OF_ORDER)); | |
102 EXPECT_EQ(0u, stream_.ProcessRawData(bad.data(), bad.length())); | 98 EXPECT_EQ(0u, stream_.ProcessRawData(bad.data(), bad.length())); |
103 } | 99 } |
104 | 100 |
105 TEST_F(QuicCryptoStreamTest, NoFlowControl) { | 101 TEST_F(QuicCryptoStreamTest, NoFlowControl) { |
106 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control_2, true); | 102 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control_2, true); |
107 EXPECT_FALSE(stream_.flow_controller()->IsEnabled()); | 103 EXPECT_FALSE(stream_.flow_controller()->IsEnabled()); |
108 } | 104 } |
109 | 105 |
110 } // namespace | 106 } // namespace |
111 } // namespace test | 107 } // namespace test |
112 } // namespace net | 108 } // namespace net |
OLD | NEW |