Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: net/quic/core/spdy_utils_test.cc

Issue 2964583002: Landing Recent QUIC changes until Jun 27 19:50:48 2017 +0000 (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/core/spdy_utils.cc ('k') | net/quic/platform/api/quic_logging.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "net/quic/core/spdy_utils.h" 4 #include "net/quic/core/spdy_utils.h"
5 5
6 #include <memory> 6 #include <memory>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "net/quic/platform/api/quic_flag_utils.h"
10 #include "net/quic/platform/api/quic_flags.h"
9 #include "net/quic/platform/api/quic_string_piece.h" 11 #include "net/quic/platform/api/quic_string_piece.h"
10 #include "net/quic/platform/api/quic_test.h"
11 #include "net/quic/platform/api/quic_text_utils.h" 12 #include "net/quic/platform/api/quic_text_utils.h"
12 #include "net/test/gtest_util.h" 13 #include "net/test/gtest_util.h"
13 14
14 using std::string; 15 using std::string;
15 using testing::UnorderedElementsAre; 16 using testing::UnorderedElementsAre;
16 using testing::Pair; 17 using testing::Pair;
17 18
18 namespace net { 19 namespace net {
19 namespace test { 20 namespace test {
20 21
21 static std::unique_ptr<QuicHeaderList> FromList( 22 static std::unique_ptr<QuicHeaderList> FromList(
22 const QuicHeaderList::ListType& src) { 23 const QuicHeaderList::ListType& src) {
23 std::unique_ptr<QuicHeaderList> headers(new QuicHeaderList); 24 std::unique_ptr<QuicHeaderList> headers(new QuicHeaderList);
24 headers->OnHeaderBlockStart(); 25 headers->OnHeaderBlockStart();
25 for (const auto& p : src) { 26 for (const auto& p : src) {
26 headers->OnHeader(p.first, p.second); 27 headers->OnHeader(p.first, p.second);
27 } 28 }
28 headers->OnHeaderBlockEnd(0, 0); 29 headers->OnHeaderBlockEnd(0, 0);
29 return headers; 30 return headers;
30 } 31 }
31 32
32 class SpdyUtilsTest : public QuicTest {}; 33 TEST(CopyAndValidateHeaders, NormalUsage) {
33
34 TEST_F(SpdyUtilsTest, CopyAndValidateHeaders) {
35 auto headers = FromList({// All cookie crumbs are joined. 34 auto headers = FromList({// All cookie crumbs are joined.
36 {"cookie", " part 1"}, 35 {"cookie", " part 1"},
37 {"cookie", "part 2 "}, 36 {"cookie", "part 2 "},
38 {"cookie", "part3"}, 37 {"cookie", "part3"},
39 38
40 // Already-delimited headers are passed through. 39 // Already-delimited headers are passed through.
41 {"passed-through", string("foo\0baz", 7)}, 40 {"passed-through", string("foo\0baz", 7)},
42 41
43 // Other headers are joined on \0. 42 // Other headers are joined on \0.
44 {"joined", "value 1"}, 43 {"joined", "value 1"},
(...skipping 18 matching lines...) Expand all
63 EXPECT_THAT(block, 62 EXPECT_THAT(block,
64 UnorderedElementsAre( 63 UnorderedElementsAre(
65 Pair("cookie", " part 1; part 2 ; part3; fin!"), 64 Pair("cookie", " part 1; part 2 ; part3; fin!"),
66 Pair("passed-through", QuicStringPiece("foo\0baz", 7)), 65 Pair("passed-through", QuicStringPiece("foo\0baz", 7)),
67 Pair("joined", QuicStringPiece("value 1\0value 2", 15)), 66 Pair("joined", QuicStringPiece("value 1\0value 2", 15)),
68 Pair("empty", ""), 67 Pair("empty", ""),
69 Pair("empty-joined", QuicStringPiece("\0foo\0\0", 6)))); 68 Pair("empty-joined", QuicStringPiece("\0foo\0\0", 6))));
70 EXPECT_EQ(-1, content_length); 69 EXPECT_EQ(-1, content_length);
71 } 70 }
72 71
73 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersEmptyName) { 72 TEST(CopyAndValidateHeaders, EmptyName) {
74 auto headers = FromList({{"foo", "foovalue"}, {"", "barvalue"}, {"baz", ""}}); 73 auto headers = FromList({{"foo", "foovalue"}, {"", "barvalue"}, {"baz", ""}});
75 int64_t content_length = -1; 74 int64_t content_length = -1;
76 SpdyHeaderBlock block; 75 SpdyHeaderBlock block;
77 ASSERT_FALSE( 76 ASSERT_FALSE(
78 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 77 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
79 } 78 }
80 79
81 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersUpperCaseName) { 80 TEST(CopyAndValidateHeaders, UpperCaseName) {
82 auto headers = 81 auto headers =
83 FromList({{"foo", "foovalue"}, {"bar", "barvalue"}, {"bAz", ""}}); 82 FromList({{"foo", "foovalue"}, {"bar", "barvalue"}, {"bAz", ""}});
84 int64_t content_length = -1; 83 int64_t content_length = -1;
85 SpdyHeaderBlock block; 84 SpdyHeaderBlock block;
86 ASSERT_FALSE( 85 ASSERT_FALSE(
87 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 86 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
88 } 87 }
89 88
90 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMultipleContentLengths) { 89 TEST(CopyAndValidateHeaders, MultipleContentLengths) {
91 auto headers = FromList({{"content-length", "9"}, 90 auto headers = FromList({{"content-length", "9"},
92 {"foo", "foovalue"}, 91 {"foo", "foovalue"},
93 {"content-length", "9"}, 92 {"content-length", "9"},
94 {"bar", "barvalue"}, 93 {"bar", "barvalue"},
95 {"baz", ""}}); 94 {"baz", ""}});
96 int64_t content_length = -1; 95 int64_t content_length = -1;
97 SpdyHeaderBlock block; 96 SpdyHeaderBlock block;
98 ASSERT_TRUE( 97 ASSERT_TRUE(
99 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 98 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
100 EXPECT_THAT(block, UnorderedElementsAre( 99 EXPECT_THAT(block, UnorderedElementsAre(
101 Pair("foo", "foovalue"), Pair("bar", "barvalue"), 100 Pair("foo", "foovalue"), Pair("bar", "barvalue"),
102 Pair("content-length", QuicStringPiece("9" 101 Pair("content-length", QuicStringPiece("9"
103 "\0" 102 "\0"
104 "9", 103 "9",
105 3)), 104 3)),
106 Pair("baz", ""))); 105 Pair("baz", "")));
107 EXPECT_EQ(9, content_length); 106 EXPECT_EQ(9, content_length);
108 } 107 }
109 108
110 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersInconsistentContentLengths) { 109 TEST(CopyAndValidateHeaders, InconsistentContentLengths) {
111 auto headers = FromList({{"content-length", "9"}, 110 auto headers = FromList({{"content-length", "9"},
112 {"foo", "foovalue"}, 111 {"foo", "foovalue"},
113 {"content-length", "8"}, 112 {"content-length", "8"},
114 {"bar", "barvalue"}, 113 {"bar", "barvalue"},
115 {"baz", ""}}); 114 {"baz", ""}});
116 int64_t content_length = -1; 115 int64_t content_length = -1;
117 SpdyHeaderBlock block; 116 SpdyHeaderBlock block;
118 ASSERT_FALSE( 117 ASSERT_FALSE(
119 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 118 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
120 } 119 }
121 120
122 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersLargeContentLength) { 121 TEST(CopyAndValidateHeaders, LargeContentLength) {
123 auto headers = FromList({{"content-length", "9000000000"}, 122 auto headers = FromList({{"content-length", "9000000000"},
124 {"foo", "foovalue"}, 123 {"foo", "foovalue"},
125 {"bar", "barvalue"}, 124 {"bar", "barvalue"},
126 {"baz", ""}}); 125 {"baz", ""}});
127 int64_t content_length = -1; 126 int64_t content_length = -1;
128 SpdyHeaderBlock block; 127 SpdyHeaderBlock block;
129 ASSERT_TRUE( 128 ASSERT_TRUE(
130 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 129 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
131 EXPECT_THAT(block, UnorderedElementsAre( 130 EXPECT_THAT(block, UnorderedElementsAre(
132 Pair("foo", "foovalue"), Pair("bar", "barvalue"), 131 Pair("foo", "foovalue"), Pair("bar", "barvalue"),
133 Pair("content-length", QuicStringPiece("9000000000")), 132 Pair("content-length", QuicStringPiece("9000000000")),
134 Pair("baz", ""))); 133 Pair("baz", "")));
135 EXPECT_EQ(9000000000, content_length); 134 EXPECT_EQ(9000000000, content_length);
136 } 135 }
137 136
138 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMultipleValues) { 137 TEST(CopyAndValidateHeaders, MultipleValues) {
139 auto headers = FromList({{"foo", "foovalue"}, 138 auto headers = FromList({{"foo", "foovalue"},
140 {"bar", "barvalue"}, 139 {"bar", "barvalue"},
141 {"baz", ""}, 140 {"baz", ""},
142 {"foo", "boo"}, 141 {"foo", "boo"},
143 {"baz", "buzz"}}); 142 {"baz", "buzz"}});
144 int64_t content_length = -1; 143 int64_t content_length = -1;
145 SpdyHeaderBlock block; 144 SpdyHeaderBlock block;
146 ASSERT_TRUE( 145 ASSERT_TRUE(
147 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 146 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
148 EXPECT_THAT(block, UnorderedElementsAre( 147 EXPECT_THAT(block, UnorderedElementsAre(
149 Pair("foo", QuicStringPiece("foovalue\0boo", 12)), 148 Pair("foo", QuicStringPiece("foovalue\0boo", 12)),
150 Pair("bar", "barvalue"), 149 Pair("bar", "barvalue"),
151 Pair("baz", QuicStringPiece("\0buzz", 5)))); 150 Pair("baz", QuicStringPiece("\0buzz", 5))));
152 EXPECT_EQ(-1, content_length); 151 EXPECT_EQ(-1, content_length);
153 } 152 }
154 153
155 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMoreThanTwoValues) { 154 TEST(CopyAndValidateHeaders, MoreThanTwoValues) {
156 auto headers = FromList({{"set-cookie", "value1"}, 155 auto headers = FromList({{"set-cookie", "value1"},
157 {"set-cookie", "value2"}, 156 {"set-cookie", "value2"},
158 {"set-cookie", "value3"}}); 157 {"set-cookie", "value3"}});
159 int64_t content_length = -1; 158 int64_t content_length = -1;
160 SpdyHeaderBlock block; 159 SpdyHeaderBlock block;
161 ASSERT_TRUE( 160 ASSERT_TRUE(
162 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 161 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
163 EXPECT_THAT( 162 EXPECT_THAT(
164 block, UnorderedElementsAre(Pair( 163 block, UnorderedElementsAre(Pair(
165 "set-cookie", QuicStringPiece("value1\0value2\0value3", 20)))); 164 "set-cookie", QuicStringPiece("value1\0value2\0value3", 20))));
166 EXPECT_EQ(-1, content_length); 165 EXPECT_EQ(-1, content_length);
167 } 166 }
168 167
169 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersCookie) { 168 TEST(CopyAndValidateHeaders, Cookie) {
170 auto headers = FromList({{"foo", "foovalue"}, 169 auto headers = FromList({{"foo", "foovalue"},
171 {"bar", "barvalue"}, 170 {"bar", "barvalue"},
172 {"cookie", "value1"}, 171 {"cookie", "value1"},
173 {"baz", ""}}); 172 {"baz", ""}});
174 int64_t content_length = -1; 173 int64_t content_length = -1;
175 SpdyHeaderBlock block; 174 SpdyHeaderBlock block;
176 ASSERT_TRUE( 175 ASSERT_TRUE(
177 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 176 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
178 EXPECT_THAT(block, UnorderedElementsAre( 177 EXPECT_THAT(block, UnorderedElementsAre(
179 Pair("foo", "foovalue"), Pair("bar", "barvalue"), 178 Pair("foo", "foovalue"), Pair("bar", "barvalue"),
180 Pair("cookie", "value1"), Pair("baz", ""))); 179 Pair("cookie", "value1"), Pair("baz", "")));
181 EXPECT_EQ(-1, content_length); 180 EXPECT_EQ(-1, content_length);
182 } 181 }
183 182
184 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMultipleCookies) { 183 TEST(CopyAndValidateHeaders, MultipleCookies) {
185 auto headers = FromList({{"foo", "foovalue"}, 184 auto headers = FromList({{"foo", "foovalue"},
186 {"bar", "barvalue"}, 185 {"bar", "barvalue"},
187 {"cookie", "value1"}, 186 {"cookie", "value1"},
188 {"baz", ""}, 187 {"baz", ""},
189 {"cookie", "value2"}}); 188 {"cookie", "value2"}});
190 int64_t content_length = -1; 189 int64_t content_length = -1;
191 SpdyHeaderBlock block; 190 SpdyHeaderBlock block;
192 ASSERT_TRUE( 191 ASSERT_TRUE(
193 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 192 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
194 EXPECT_THAT(block, UnorderedElementsAre( 193 EXPECT_THAT(block, UnorderedElementsAre(
195 Pair("foo", "foovalue"), Pair("bar", "barvalue"), 194 Pair("foo", "foovalue"), Pair("bar", "barvalue"),
196 Pair("cookie", "value1; value2"), Pair("baz", ""))); 195 Pair("cookie", "value1; value2"), Pair("baz", "")));
197 EXPECT_EQ(-1, content_length); 196 EXPECT_EQ(-1, content_length);
198 } 197 }
199 198
200 TEST_F(SpdyUtilsTest, GetUrlFromHeaderBlock) { 199 TEST(CopyAndValidateTrailers, SimplestValidList) {
200 // Verify that the simplest trailers are valid: just a final byte offset that
201 // gets parsed successfully.
202 auto trailers = FromList({{kFinalOffsetHeaderKey, "1234"}});
203 size_t final_byte_offset = 0;
204 SpdyHeaderBlock block;
205 EXPECT_TRUE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
206 &block));
207 EXPECT_EQ(1234u, final_byte_offset);
208 }
209
210 TEST(CopyAndValidateTrailers, EmptyTrailerList) {
211 // An empty trailer list will fail as required key kFinalOffsetHeaderKey is
212 // not present.
213 QuicHeaderList trailers;
214 size_t final_byte_offset = 0;
215 SpdyHeaderBlock block;
216 EXPECT_FALSE(
217 SpdyUtils::CopyAndValidateTrailers(trailers, &final_byte_offset, &block));
218 }
219
220 TEST(CopyAndValidateTrailers, FinalByteOffsetNotPresent) {
221 // Validation fails if required kFinalOffsetHeaderKey is not present, even if
222 // the rest of the header block is valid.
223 auto trailers = FromList({{"key", "value"}});
224 size_t final_byte_offset = 0;
225 SpdyHeaderBlock block;
226 EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
227 &block));
228 }
229
230 TEST(CopyAndValidateTrailers, EmptyName) {
231 // Trailer validation will fail with an empty header key, in an otherwise
232 // valid block of trailers.
233 auto trailers = FromList({{"", "value"}, {kFinalOffsetHeaderKey, "1234"}});
234 size_t final_byte_offset = 0;
235 SpdyHeaderBlock block;
236 EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
237 &block));
238 }
239
240 TEST(CopyAndValidateTrailers, PseudoHeaderInTrailers) {
241 // Pseudo headers are illegal in trailers.
242 auto trailers =
243 FromList({{":pseudo_key", "value"}, {kFinalOffsetHeaderKey, "1234"}});
244 size_t final_byte_offset = 0;
245 SpdyHeaderBlock block;
246 EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
247 &block));
248 }
249
250 TEST(CopyAndValidateTrailers, DuplicateTrailers) {
251 // Duplicate trailers are allowed, and their values are concatenated into a
252 // single string delimted with '\0'. Some of the duplicate headers
253 // deliberately have an empty value.
254 FLAGS_quic_reloadable_flag_quic_handle_duplicate_trailers = true;
255 auto trailers = FromList({{"key", "value0"},
256 {"key", "value1"},
257 {"key", ""},
258 {"key", ""},
259 {"key", "value2"},
260 {"key", ""},
261 {kFinalOffsetHeaderKey, "1234"},
262 {"other_key", "value"},
263 {"key", "non_contiguous_duplicate"}});
264 size_t final_byte_offset = 0;
265 SpdyHeaderBlock block;
266 EXPECT_TRUE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
267 &block));
268 EXPECT_THAT(
269 block,
270 UnorderedElementsAre(
271 Pair("key",
272 QuicStringPiece(
273 "value0\0value1\0\0\0value2\0\0non_contiguous_duplicate",
274 48)),
275 Pair("other_key", "value")));
276 }
277
278 TEST(CopyAndValidateTrailers, DuplicateCookies) {
279 // Duplicate cookie headers in trailers should be concatenated into a single
280 // "; " delimted string.
281 FLAGS_quic_reloadable_flag_quic_handle_duplicate_trailers = true;
282 auto headers = FromList({{"cookie", " part 1"},
283 {"cookie", "part 2 "},
284 {"cookie", "part3"},
285 {"key", "value"},
286 {kFinalOffsetHeaderKey, "1234"},
287 {"cookie", " non_contiguous_cookie!"}});
288
289 size_t final_byte_offset = 0;
290 SpdyHeaderBlock block;
291 EXPECT_TRUE(
292 SpdyUtils::CopyAndValidateTrailers(*headers, &final_byte_offset, &block));
293 EXPECT_THAT(
294 block,
295 UnorderedElementsAre(
296 Pair("cookie", " part 1; part 2 ; part3; non_contiguous_cookie!"),
297 Pair("key", "value")));
298 }
299
300 TEST(GetUrlFromHeaderBlock, Basic) {
201 SpdyHeaderBlock headers; 301 SpdyHeaderBlock headers;
202 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); 302 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
203 headers[":scheme"] = "https"; 303 headers[":scheme"] = "https";
204 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); 304 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
205 headers[":authority"] = "www.google.com"; 305 headers[":authority"] = "www.google.com";
206 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); 306 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
207 headers[":path"] = "/index.html"; 307 headers[":path"] = "/index.html";
208 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), 308 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers),
209 "https://www.google.com/index.html"); 309 "https://www.google.com/index.html");
210 headers["key1"] = "value1"; 310 headers["key1"] = "value1";
211 headers["key2"] = "value2"; 311 headers["key2"] = "value2";
212 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), 312 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers),
213 "https://www.google.com/index.html"); 313 "https://www.google.com/index.html");
214 } 314 }
215 315
216 TEST_F(SpdyUtilsTest, GetHostNameFromHeaderBlock) { 316 TEST(GetHostNameFromHeaderBlock, NormalUsage) {
217 SpdyHeaderBlock headers; 317 SpdyHeaderBlock headers;
218 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), ""); 318 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "");
219 headers[":scheme"] = "https"; 319 headers[":scheme"] = "https";
220 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), ""); 320 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "");
221 headers[":authority"] = "www.google.com"; 321 headers[":authority"] = "www.google.com";
222 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), ""); 322 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "");
223 headers[":path"] = "/index.html"; 323 headers[":path"] = "/index.html";
224 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "www.google.com"); 324 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "www.google.com");
225 headers["key1"] = "value1"; 325 headers["key1"] = "value1";
226 headers["key2"] = "value2"; 326 headers["key2"] = "value2";
227 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "www.google.com"); 327 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "www.google.com");
228 headers[":authority"] = "www.google.com:6666"; 328 headers[":authority"] = "www.google.com:6666";
229 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "www.google.com"); 329 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "www.google.com");
230 headers[":authority"] = "192.168.1.1"; 330 headers[":authority"] = "192.168.1.1";
231 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "192.168.1.1"); 331 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "192.168.1.1");
232 headers[":authority"] = "192.168.1.1:6666"; 332 headers[":authority"] = "192.168.1.1:6666";
233 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "192.168.1.1"); 333 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "192.168.1.1");
234 } 334 }
235 335
236 TEST_F(SpdyUtilsTest, PopulateHeaderBlockFromUrl) { 336 TEST(PopulateHeaderBlockFromUrl, NormalUsage) {
237 string url = "https://www.google.com/index.html"; 337 string url = "https://www.google.com/index.html";
238 SpdyHeaderBlock headers; 338 SpdyHeaderBlock headers;
239 EXPECT_TRUE(SpdyUtils::PopulateHeaderBlockFromUrl(url, &headers)); 339 EXPECT_TRUE(SpdyUtils::PopulateHeaderBlockFromUrl(url, &headers));
240 EXPECT_EQ("https", headers[":scheme"].as_string()); 340 EXPECT_EQ("https", headers[":scheme"].as_string());
241 EXPECT_EQ("www.google.com", headers[":authority"].as_string()); 341 EXPECT_EQ("www.google.com", headers[":authority"].as_string());
242 EXPECT_EQ("/index.html", headers[":path"].as_string()); 342 EXPECT_EQ("/index.html", headers[":path"].as_string());
243 } 343 }
244 344
245 TEST_F(SpdyUtilsTest, PopulateHeaderBlockFromUrlWithNoPath) { 345 TEST(PopulateHeaderBlockFromUrl, UrlWithNoPath) {
246 string url = "https://www.google.com"; 346 string url = "https://www.google.com";
247 SpdyHeaderBlock headers; 347 SpdyHeaderBlock headers;
248 EXPECT_TRUE(SpdyUtils::PopulateHeaderBlockFromUrl(url, &headers)); 348 EXPECT_TRUE(SpdyUtils::PopulateHeaderBlockFromUrl(url, &headers));
249 EXPECT_EQ("https", headers[":scheme"].as_string()); 349 EXPECT_EQ("https", headers[":scheme"].as_string());
250 EXPECT_EQ("www.google.com", headers[":authority"].as_string()); 350 EXPECT_EQ("www.google.com", headers[":authority"].as_string());
251 EXPECT_EQ("/", headers[":path"].as_string()); 351 EXPECT_EQ("/", headers[":path"].as_string());
252 } 352 }
253 353
254 TEST_F(SpdyUtilsTest, PopulateHeaderBlockFromUrlFails) { 354 TEST(PopulateHeaderBlockFromUrl, Failure) {
255 SpdyHeaderBlock headers; 355 SpdyHeaderBlock headers;
256 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/", &headers)); 356 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/", &headers));
257 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/index.html", &headers)); 357 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/index.html", &headers));
258 EXPECT_FALSE( 358 EXPECT_FALSE(
259 SpdyUtils::PopulateHeaderBlockFromUrl("www.google.com/", &headers)); 359 SpdyUtils::PopulateHeaderBlockFromUrl("www.google.com/", &headers));
260 } 360 }
261 361
262 } // namespace test 362 } // namespace test
263 } // namespace net 363 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/spdy_utils.cc ('k') | net/quic/platform/api/quic_logging.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698