OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <cmath> | 5 #include <cmath> |
6 #include <ctime> | 6 #include <ctime> |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 bool success = decoder_.HandleControlFrameHeadersData( | 41 bool success = decoder_.HandleControlFrameHeadersData( |
42 1, encoded.data(), encoded.size()); | 42 1, encoded.data(), encoded.size()); |
43 success &= decoder_.HandleControlFrameHeadersComplete(1); | 43 success &= decoder_.HandleControlFrameHeadersComplete(1); |
44 | 44 |
45 EXPECT_EQ(header_set, decoder_.decoded_block()); | 45 EXPECT_EQ(header_set, decoder_.decoded_block()); |
46 return success; | 46 return success; |
47 } | 47 } |
48 | 48 |
49 size_t SampleExponential(size_t mean, size_t sanity_bound) { | 49 size_t SampleExponential(size_t mean, size_t sanity_bound) { |
50 return std::min<size_t>(-std::log(base::RandDouble()) * mean, | 50 return std::min<size_t>(-std::log(base::RandDouble()) * mean, sanity_bound); |
51 sanity_bound); | |
52 } | 51 } |
53 | 52 |
54 HpackEncoder encoder_; | 53 HpackEncoder encoder_; |
55 HpackDecoder decoder_; | 54 HpackDecoder decoder_; |
56 }; | 55 }; |
57 | 56 |
58 TEST_F(HpackRoundTripTest, ResponseFixtures) { | 57 TEST_F(HpackRoundTripTest, ResponseFixtures) { |
59 { | 58 { |
60 map<string, string> headers; | 59 map<string, string> headers; |
61 headers[":status"] = "302"; | 60 headers[":status"] = "302"; |
(...skipping 10 matching lines...) Expand all Loading... |
72 headers["location"] = "https://www.example.com"; | 71 headers["location"] = "https://www.example.com"; |
73 EXPECT_TRUE(RoundTrip(headers)); | 72 EXPECT_TRUE(RoundTrip(headers)); |
74 } | 73 } |
75 { | 74 { |
76 map<string, string> headers; | 75 map<string, string> headers; |
77 headers[":status"] = "200"; | 76 headers[":status"] = "200"; |
78 headers["cache-control"] = "private"; | 77 headers["cache-control"] = "private"; |
79 headers["content-encoding"] = "gzip"; | 78 headers["content-encoding"] = "gzip"; |
80 headers["date"] = "Mon, 21 Oct 2013 20:13:22 GMT"; | 79 headers["date"] = "Mon, 21 Oct 2013 20:13:22 GMT"; |
81 headers["location"] = "https://www.example.com"; | 80 headers["location"] = "https://www.example.com"; |
82 headers["set-cookie"] = "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU;" | 81 headers["set-cookie"] = |
| 82 "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU;" |
83 " max-age=3600; version=1"; | 83 " max-age=3600; version=1"; |
84 EXPECT_TRUE(RoundTrip(headers)); | 84 EXPECT_TRUE(RoundTrip(headers)); |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 TEST_F(HpackRoundTripTest, RequestFixtures) { | 88 TEST_F(HpackRoundTripTest, RequestFixtures) { |
89 { | 89 { |
90 map<string, string> headers; | 90 map<string, string> headers; |
91 headers[":authority"] = "www.example.com"; | 91 headers[":authority"] = "www.example.com"; |
92 headers[":method"] = "GET"; | 92 headers[":method"] = "GET"; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 size_t value_index = SampleExponential(20, 200); | 150 size_t value_index = SampleExponential(20, 200); |
151 | 151 |
152 string name, value; | 152 string name, value; |
153 if (name_index >= names.size()) { | 153 if (name_index >= names.size()) { |
154 names.push_back(base::RandBytesAsString(1 + SampleExponential(5, 30))); | 154 names.push_back(base::RandBytesAsString(1 + SampleExponential(5, 30))); |
155 name = names.back(); | 155 name = names.back(); |
156 } else { | 156 } else { |
157 name = names[name_index]; | 157 name = names[name_index]; |
158 } | 158 } |
159 if (value_index >= values.size()) { | 159 if (value_index >= values.size()) { |
160 values.push_back(base::RandBytesAsString( | 160 values.push_back( |
161 1 + SampleExponential(15, 75))); | 161 base::RandBytesAsString(1 + SampleExponential(15, 75))); |
162 value = values.back(); | 162 value = values.back(); |
163 } else { | 163 } else { |
164 value = values[value_index]; | 164 value = values[value_index]; |
165 } | 165 } |
166 headers[name] = value; | 166 headers[name] = value; |
167 } | 167 } |
168 EXPECT_TRUE(RoundTrip(headers)); | 168 EXPECT_TRUE(RoundTrip(headers)); |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 } // namespace | 172 } // namespace |
173 | 173 |
174 } // namespace net | 174 } // namespace net |
OLD | NEW |