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 <map> | |
8 #include <string> | 7 #include <string> |
| 8 #include <vector> |
9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" |
10 #include "net/quic/quic_utils.h" | 11 #include "net/quic/quic_utils.h" |
11 #include "net/quic/test_tools/quic_test_utils.h" | 12 #include "net/quic/test_tools/quic_test_utils.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 using std::map; | |
16 using std::string; | 16 using std::string; |
| 17 using std::vector; |
17 | 18 |
18 namespace net { | 19 namespace net { |
19 namespace test { | 20 namespace test { |
20 namespace { | 21 namespace { |
21 | 22 |
22 class MockQuicCryptoStream : public QuicCryptoStream { | 23 class MockQuicCryptoStream : public QuicCryptoStream { |
23 public: | 24 public: |
24 explicit MockQuicCryptoStream(QuicSession* session) | 25 explicit MockQuicCryptoStream(QuicSession* session) |
25 : QuicCryptoStream(session) { | 26 : QuicCryptoStream(session) { |
26 } | 27 } |
27 | 28 |
28 void OnHandshakeMessage(const CryptoHandshakeMessage& message) { | 29 void OnHandshakeMessage(const CryptoHandshakeMessage& message) { |
29 message_tags_.push_back(message.tag); | 30 messages_.push_back(message); |
30 message_maps_.push_back(map<CryptoTag, string>()); | |
31 CryptoTagValueMap::const_iterator it = message.tag_value_map.begin(); | |
32 while (it != message.tag_value_map.end()) { | |
33 message_maps_.back()[it->first] = it->second.as_string(); | |
34 ++it; | |
35 } | |
36 } | 31 } |
37 | 32 |
38 std::vector<CryptoTag>* message_tags() { | 33 vector<CryptoHandshakeMessage>* messages() { |
39 return &message_tags_; | 34 return &messages_; |
40 } | |
41 | |
42 std::vector<std::map<CryptoTag, string> >* message_maps() { | |
43 return &message_maps_; | |
44 } | 35 } |
45 | 36 |
46 private: | 37 private: |
47 std::vector<CryptoTag> message_tags_; | 38 vector<CryptoHandshakeMessage> messages_; |
48 std::vector<std::map<CryptoTag, string> > message_maps_; | |
49 | 39 |
50 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoStream); | 40 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoStream); |
51 }; | 41 }; |
52 | 42 |
53 class QuicCryptoStreamTest : public ::testing::Test { | 43 class QuicCryptoStreamTest : public ::testing::Test { |
54 public: | 44 public: |
55 QuicCryptoStreamTest() | 45 QuicCryptoStreamTest() |
56 : addr_(IPAddressNumber(), 1), | 46 : addr_(IPAddressNumber(), 1), |
57 connection_(new MockConnection(1, addr_)), | 47 connection_(new MockConnection(1, addr_)), |
58 session_(connection_, true), | 48 session_(connection_, true), |
(...skipping 28 matching lines...) Expand all Loading... |
87 TEST_F(QuicCryptoStreamTest, OnErrorClosesConnection) { | 77 TEST_F(QuicCryptoStreamTest, OnErrorClosesConnection) { |
88 CryptoFramer framer; | 78 CryptoFramer framer; |
89 EXPECT_CALL(session_, ConnectionClose(QUIC_NO_ERROR, false)); | 79 EXPECT_CALL(session_, ConnectionClose(QUIC_NO_ERROR, false)); |
90 stream_.OnError(&framer); | 80 stream_.OnError(&framer); |
91 } | 81 } |
92 | 82 |
93 TEST_F(QuicCryptoStreamTest, ProcessData) { | 83 TEST_F(QuicCryptoStreamTest, ProcessData) { |
94 EXPECT_EQ(message_data_->length(), | 84 EXPECT_EQ(message_data_->length(), |
95 stream_.ProcessData(message_data_->data(), | 85 stream_.ProcessData(message_data_->data(), |
96 message_data_->length())); | 86 message_data_->length())); |
97 ASSERT_EQ(1u, stream_.message_tags()->size()); | 87 ASSERT_EQ(1u, stream_.messages()->size()); |
98 EXPECT_EQ(kSHLO, (*stream_.message_tags())[0]); | 88 EXPECT_EQ(kSHLO, (*stream_.messages())[0].tag); |
99 EXPECT_EQ(2u, (*stream_.message_maps())[0].size()); | 89 EXPECT_EQ(2u, (*stream_.messages())[0].tag_value_map.size()); |
100 EXPECT_EQ("abc", (*stream_.message_maps())[0][1]); | 90 EXPECT_EQ("abc", (*stream_.messages())[0].tag_value_map[1]); |
101 EXPECT_EQ("def", (*stream_.message_maps())[0][2]); | 91 EXPECT_EQ("def", (*stream_.messages())[0].tag_value_map[2]); |
102 } | 92 } |
103 | 93 |
104 TEST_F(QuicCryptoStreamTest, ProcessBadData) { | 94 TEST_F(QuicCryptoStreamTest, ProcessBadData) { |
105 string bad(message_data_->data(), message_data_->length()); | 95 string bad(message_data_->data(), message_data_->length()); |
106 bad[6] = 0x7F; // out of order tag | 96 bad[6] = 0x7F; // out of order tag |
107 | 97 |
108 EXPECT_CALL(*connection_, | 98 EXPECT_CALL(*connection_, |
109 SendConnectionClose(QUIC_CRYPTO_TAGS_OUT_OF_ORDER)); | 99 SendConnectionClose(QUIC_CRYPTO_TAGS_OUT_OF_ORDER)); |
110 EXPECT_EQ(0u, stream_.ProcessData(bad.data(), bad.length())); | 100 EXPECT_EQ(0u, stream_.ProcessData(bad.data(), bad.length())); |
111 } | 101 } |
112 | 102 |
113 } // namespace | 103 } // namespace |
114 } // namespace test | 104 } // namespace test |
115 } // namespace net | 105 } // namespace net |
OLD | NEW |