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

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

Issue 2848203002: Add a platform implementation of QuicTest and QuicTestWithParam (Closed)
Patch Set: net/quic/platform/impl/quic_test_impl.cc Created 3 years, 7 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
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 "base/macros.h" 6 #include "base/macros.h"
7 #include "net/quic/platform/api/quic_string_piece.h" 7 #include "net/quic/platform/api/quic_string_piece.h"
8 #include "net/quic/platform/api/quic_test.h"
8 #include "net/quic/platform/api/quic_text_utils.h" 9 #include "net/quic/platform/api/quic_text_utils.h"
9 #include "net/test/gtest_util.h" 10 #include "net/test/gtest_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 using std::string; 12 using std::string;
13 using testing::UnorderedElementsAre; 13 using testing::UnorderedElementsAre;
14 using testing::Pair; 14 using testing::Pair;
15 15
16 namespace net { 16 namespace net {
17 namespace test { 17 namespace test {
18 18
19 static std::unique_ptr<QuicHeaderList> FromList( 19 static std::unique_ptr<QuicHeaderList> FromList(
20 const QuicHeaderList::ListType& src) { 20 const QuicHeaderList::ListType& src) {
21 std::unique_ptr<QuicHeaderList> headers(new QuicHeaderList); 21 std::unique_ptr<QuicHeaderList> headers(new QuicHeaderList);
22 headers->OnHeaderBlockStart(); 22 headers->OnHeaderBlockStart();
23 for (const auto& p : src) { 23 for (const auto& p : src) {
24 headers->OnHeader(p.first, p.second); 24 headers->OnHeader(p.first, p.second);
25 } 25 }
26 headers->OnHeaderBlockEnd(0); 26 headers->OnHeaderBlockEnd(0);
27 return headers; 27 return headers;
28 } 28 }
29 29
30 TEST(SpdyUtilsTest, CopyAndValidateHeaders) { 30 class SpdyUtilsTest : public QuicTest {};
31
32 TEST_F(SpdyUtilsTest, CopyAndValidateHeaders) {
31 auto headers = FromList({// All cookie crumbs are joined. 33 auto headers = FromList({// All cookie crumbs are joined.
32 {"cookie", " part 1"}, 34 {"cookie", " part 1"},
33 {"cookie", "part 2 "}, 35 {"cookie", "part 2 "},
34 {"cookie", "part3"}, 36 {"cookie", "part3"},
35 37
36 // Already-delimited headers are passed through. 38 // Already-delimited headers are passed through.
37 {"passed-through", string("foo\0baz", 7)}, 39 {"passed-through", string("foo\0baz", 7)},
38 40
39 // Other headers are joined on \0. 41 // Other headers are joined on \0.
40 {"joined", "value 1"}, 42 {"joined", "value 1"},
(...skipping 18 matching lines...) Expand all
59 EXPECT_THAT(block, 61 EXPECT_THAT(block,
60 UnorderedElementsAre( 62 UnorderedElementsAre(
61 Pair("cookie", " part 1; part 2 ; part3; fin!"), 63 Pair("cookie", " part 1; part 2 ; part3; fin!"),
62 Pair("passed-through", QuicStringPiece("foo\0baz", 7)), 64 Pair("passed-through", QuicStringPiece("foo\0baz", 7)),
63 Pair("joined", QuicStringPiece("value 1\0value 2", 15)), 65 Pair("joined", QuicStringPiece("value 1\0value 2", 15)),
64 Pair("empty", ""), 66 Pair("empty", ""),
65 Pair("empty-joined", QuicStringPiece("\0foo\0\0", 6)))); 67 Pair("empty-joined", QuicStringPiece("\0foo\0\0", 6))));
66 EXPECT_EQ(-1, content_length); 68 EXPECT_EQ(-1, content_length);
67 } 69 }
68 70
69 TEST(SpdyUtilsTest, CopyAndValidateHeadersEmptyName) { 71 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersEmptyName) {
70 auto headers = FromList({{"foo", "foovalue"}, {"", "barvalue"}, {"baz", ""}}); 72 auto headers = FromList({{"foo", "foovalue"}, {"", "barvalue"}, {"baz", ""}});
71 int64_t content_length = -1; 73 int64_t content_length = -1;
72 SpdyHeaderBlock block; 74 SpdyHeaderBlock block;
73 ASSERT_FALSE( 75 ASSERT_FALSE(
74 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 76 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
75 } 77 }
76 78
77 TEST(SpdyUtilsTest, CopyAndValidateHeadersUpperCaseName) { 79 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersUpperCaseName) {
78 auto headers = 80 auto headers =
79 FromList({{"foo", "foovalue"}, {"bar", "barvalue"}, {"bAz", ""}}); 81 FromList({{"foo", "foovalue"}, {"bar", "barvalue"}, {"bAz", ""}});
80 int64_t content_length = -1; 82 int64_t content_length = -1;
81 SpdyHeaderBlock block; 83 SpdyHeaderBlock block;
82 ASSERT_FALSE( 84 ASSERT_FALSE(
83 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 85 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
84 } 86 }
85 87
86 TEST(SpdyUtilsTest, CopyAndValidateHeadersMultipleContentLengths) { 88 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMultipleContentLengths) {
87 auto headers = FromList({{"content-length", "9"}, 89 auto headers = FromList({{"content-length", "9"},
88 {"foo", "foovalue"}, 90 {"foo", "foovalue"},
89 {"content-length", "9"}, 91 {"content-length", "9"},
90 {"bar", "barvalue"}, 92 {"bar", "barvalue"},
91 {"baz", ""}}); 93 {"baz", ""}});
92 int64_t content_length = -1; 94 int64_t content_length = -1;
93 SpdyHeaderBlock block; 95 SpdyHeaderBlock block;
94 ASSERT_TRUE( 96 ASSERT_TRUE(
95 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 97 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
96 EXPECT_THAT(block, UnorderedElementsAre( 98 EXPECT_THAT(block, UnorderedElementsAre(
97 Pair("foo", "foovalue"), Pair("bar", "barvalue"), 99 Pair("foo", "foovalue"), Pair("bar", "barvalue"),
98 Pair("content-length", QuicStringPiece("9" 100 Pair("content-length", QuicStringPiece("9"
99 "\0" 101 "\0"
100 "9", 102 "9",
101 3)), 103 3)),
102 Pair("baz", ""))); 104 Pair("baz", "")));
103 EXPECT_EQ(9, content_length); 105 EXPECT_EQ(9, content_length);
104 } 106 }
105 107
106 TEST(SpdyUtilsTest, CopyAndValidateHeadersInconsistentContentLengths) { 108 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersInconsistentContentLengths) {
107 auto headers = FromList({{"content-length", "9"}, 109 auto headers = FromList({{"content-length", "9"},
108 {"foo", "foovalue"}, 110 {"foo", "foovalue"},
109 {"content-length", "8"}, 111 {"content-length", "8"},
110 {"bar", "barvalue"}, 112 {"bar", "barvalue"},
111 {"baz", ""}}); 113 {"baz", ""}});
112 int64_t content_length = -1; 114 int64_t content_length = -1;
113 SpdyHeaderBlock block; 115 SpdyHeaderBlock block;
114 ASSERT_FALSE( 116 ASSERT_FALSE(
115 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 117 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
116 } 118 }
117 119
118 TEST(SpdyUtilsTest, CopyAndValidateHeadersLargeContentLength) { 120 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersLargeContentLength) {
119 auto headers = FromList({{"content-length", "9000000000"}, 121 auto headers = FromList({{"content-length", "9000000000"},
120 {"foo", "foovalue"}, 122 {"foo", "foovalue"},
121 {"bar", "barvalue"}, 123 {"bar", "barvalue"},
122 {"baz", ""}}); 124 {"baz", ""}});
123 int64_t content_length = -1; 125 int64_t content_length = -1;
124 SpdyHeaderBlock block; 126 SpdyHeaderBlock block;
125 ASSERT_TRUE( 127 ASSERT_TRUE(
126 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 128 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
127 EXPECT_THAT(block, UnorderedElementsAre( 129 EXPECT_THAT(block, UnorderedElementsAre(
128 Pair("foo", "foovalue"), Pair("bar", "barvalue"), 130 Pair("foo", "foovalue"), Pair("bar", "barvalue"),
129 Pair("content-length", QuicStringPiece("9000000000")), 131 Pair("content-length", QuicStringPiece("9000000000")),
130 Pair("baz", ""))); 132 Pair("baz", "")));
131 EXPECT_EQ(9000000000, content_length); 133 EXPECT_EQ(9000000000, content_length);
132 } 134 }
133 135
134 TEST(SpdyUtilsTest, CopyAndValidateHeadersMultipleValues) { 136 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMultipleValues) {
135 auto headers = FromList({{"foo", "foovalue"}, 137 auto headers = FromList({{"foo", "foovalue"},
136 {"bar", "barvalue"}, 138 {"bar", "barvalue"},
137 {"baz", ""}, 139 {"baz", ""},
138 {"foo", "boo"}, 140 {"foo", "boo"},
139 {"baz", "buzz"}}); 141 {"baz", "buzz"}});
140 int64_t content_length = -1; 142 int64_t content_length = -1;
141 SpdyHeaderBlock block; 143 SpdyHeaderBlock block;
142 ASSERT_TRUE( 144 ASSERT_TRUE(
143 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 145 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
144 EXPECT_THAT(block, UnorderedElementsAre( 146 EXPECT_THAT(block, UnorderedElementsAre(
145 Pair("foo", QuicStringPiece("foovalue\0boo", 12)), 147 Pair("foo", QuicStringPiece("foovalue\0boo", 12)),
146 Pair("bar", "barvalue"), 148 Pair("bar", "barvalue"),
147 Pair("baz", QuicStringPiece("\0buzz", 5)))); 149 Pair("baz", QuicStringPiece("\0buzz", 5))));
148 EXPECT_EQ(-1, content_length); 150 EXPECT_EQ(-1, content_length);
149 } 151 }
150 152
151 TEST(SpdyUtilsTest, CopyAndValidateHeadersMoreThanTwoValues) { 153 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMoreThanTwoValues) {
152 auto headers = FromList({{"set-cookie", "value1"}, 154 auto headers = FromList({{"set-cookie", "value1"},
153 {"set-cookie", "value2"}, 155 {"set-cookie", "value2"},
154 {"set-cookie", "value3"}}); 156 {"set-cookie", "value3"}});
155 int64_t content_length = -1; 157 int64_t content_length = -1;
156 SpdyHeaderBlock block; 158 SpdyHeaderBlock block;
157 ASSERT_TRUE( 159 ASSERT_TRUE(
158 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 160 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
159 EXPECT_THAT( 161 EXPECT_THAT(
160 block, UnorderedElementsAre(Pair( 162 block, UnorderedElementsAre(Pair(
161 "set-cookie", QuicStringPiece("value1\0value2\0value3", 20)))); 163 "set-cookie", QuicStringPiece("value1\0value2\0value3", 20))));
162 EXPECT_EQ(-1, content_length); 164 EXPECT_EQ(-1, content_length);
163 } 165 }
164 166
165 TEST(SpdyUtilsTest, CopyAndValidateHeadersCookie) { 167 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersCookie) {
166 auto headers = FromList({{"foo", "foovalue"}, 168 auto headers = FromList({{"foo", "foovalue"},
167 {"bar", "barvalue"}, 169 {"bar", "barvalue"},
168 {"cookie", "value1"}, 170 {"cookie", "value1"},
169 {"baz", ""}}); 171 {"baz", ""}});
170 int64_t content_length = -1; 172 int64_t content_length = -1;
171 SpdyHeaderBlock block; 173 SpdyHeaderBlock block;
172 ASSERT_TRUE( 174 ASSERT_TRUE(
173 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 175 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
174 EXPECT_THAT(block, UnorderedElementsAre( 176 EXPECT_THAT(block, UnorderedElementsAre(
175 Pair("foo", "foovalue"), Pair("bar", "barvalue"), 177 Pair("foo", "foovalue"), Pair("bar", "barvalue"),
176 Pair("cookie", "value1"), Pair("baz", ""))); 178 Pair("cookie", "value1"), Pair("baz", "")));
177 EXPECT_EQ(-1, content_length); 179 EXPECT_EQ(-1, content_length);
178 } 180 }
179 181
180 TEST(SpdyUtilsTest, CopyAndValidateHeadersMultipleCookies) { 182 TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMultipleCookies) {
181 auto headers = FromList({{"foo", "foovalue"}, 183 auto headers = FromList({{"foo", "foovalue"},
182 {"bar", "barvalue"}, 184 {"bar", "barvalue"},
183 {"cookie", "value1"}, 185 {"cookie", "value1"},
184 {"baz", ""}, 186 {"baz", ""},
185 {"cookie", "value2"}}); 187 {"cookie", "value2"}});
186 int64_t content_length = -1; 188 int64_t content_length = -1;
187 SpdyHeaderBlock block; 189 SpdyHeaderBlock block;
188 ASSERT_TRUE( 190 ASSERT_TRUE(
189 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 191 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
190 EXPECT_THAT(block, UnorderedElementsAre( 192 EXPECT_THAT(block, UnorderedElementsAre(
191 Pair("foo", "foovalue"), Pair("bar", "barvalue"), 193 Pair("foo", "foovalue"), Pair("bar", "barvalue"),
192 Pair("cookie", "value1; value2"), Pair("baz", ""))); 194 Pair("cookie", "value1; value2"), Pair("baz", "")));
193 EXPECT_EQ(-1, content_length); 195 EXPECT_EQ(-1, content_length);
194 } 196 }
195 197
196 TEST(SpdyUtilsTest, GetUrlFromHeaderBlock) { 198 TEST_F(SpdyUtilsTest, GetUrlFromHeaderBlock) {
197 SpdyHeaderBlock headers; 199 SpdyHeaderBlock headers;
198 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); 200 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
199 headers[":scheme"] = "https"; 201 headers[":scheme"] = "https";
200 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); 202 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
201 headers[":authority"] = "www.google.com"; 203 headers[":authority"] = "www.google.com";
202 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); 204 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
203 headers[":path"] = "/index.html"; 205 headers[":path"] = "/index.html";
204 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), 206 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers),
205 "https://www.google.com/index.html"); 207 "https://www.google.com/index.html");
206 headers["key1"] = "value1"; 208 headers["key1"] = "value1";
207 headers["key2"] = "value2"; 209 headers["key2"] = "value2";
208 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), 210 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers),
209 "https://www.google.com/index.html"); 211 "https://www.google.com/index.html");
210 } 212 }
211 213
212 TEST(SpdyUtilsTest, GetHostNameFromHeaderBlock) { 214 TEST_F(SpdyUtilsTest, GetHostNameFromHeaderBlock) {
213 SpdyHeaderBlock headers; 215 SpdyHeaderBlock headers;
214 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), ""); 216 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "");
215 headers[":scheme"] = "https"; 217 headers[":scheme"] = "https";
216 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), ""); 218 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "");
217 headers[":authority"] = "www.google.com"; 219 headers[":authority"] = "www.google.com";
218 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), ""); 220 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "");
219 headers[":path"] = "/index.html"; 221 headers[":path"] = "/index.html";
220 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "www.google.com"); 222 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "www.google.com");
221 headers["key1"] = "value1"; 223 headers["key1"] = "value1";
222 headers["key2"] = "value2"; 224 headers["key2"] = "value2";
223 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "www.google.com"); 225 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "www.google.com");
224 headers[":authority"] = "www.google.com:6666"; 226 headers[":authority"] = "www.google.com:6666";
225 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "www.google.com"); 227 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "www.google.com");
226 headers[":authority"] = "192.168.1.1"; 228 headers[":authority"] = "192.168.1.1";
227 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "192.168.1.1"); 229 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "192.168.1.1");
228 headers[":authority"] = "192.168.1.1:6666"; 230 headers[":authority"] = "192.168.1.1:6666";
229 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "192.168.1.1"); 231 EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "192.168.1.1");
230 } 232 }
231 233
232 TEST(SpdyUtilsTest, PopulateHeaderBlockFromUrl) { 234 TEST_F(SpdyUtilsTest, PopulateHeaderBlockFromUrl) {
233 string url = "https://www.google.com/index.html"; 235 string url = "https://www.google.com/index.html";
234 SpdyHeaderBlock headers; 236 SpdyHeaderBlock headers;
235 EXPECT_TRUE(SpdyUtils::PopulateHeaderBlockFromUrl(url, &headers)); 237 EXPECT_TRUE(SpdyUtils::PopulateHeaderBlockFromUrl(url, &headers));
236 EXPECT_EQ("https", headers[":scheme"].as_string()); 238 EXPECT_EQ("https", headers[":scheme"].as_string());
237 EXPECT_EQ("www.google.com", headers[":authority"].as_string()); 239 EXPECT_EQ("www.google.com", headers[":authority"].as_string());
238 EXPECT_EQ("/index.html", headers[":path"].as_string()); 240 EXPECT_EQ("/index.html", headers[":path"].as_string());
239 } 241 }
240 242
241 TEST(SpdyUtilsTest, PopulateHeaderBlockFromUrlWithNoPath) { 243 TEST_F(SpdyUtilsTest, PopulateHeaderBlockFromUrlWithNoPath) {
242 string url = "https://www.google.com"; 244 string url = "https://www.google.com";
243 SpdyHeaderBlock headers; 245 SpdyHeaderBlock headers;
244 EXPECT_TRUE(SpdyUtils::PopulateHeaderBlockFromUrl(url, &headers)); 246 EXPECT_TRUE(SpdyUtils::PopulateHeaderBlockFromUrl(url, &headers));
245 EXPECT_EQ("https", headers[":scheme"].as_string()); 247 EXPECT_EQ("https", headers[":scheme"].as_string());
246 EXPECT_EQ("www.google.com", headers[":authority"].as_string()); 248 EXPECT_EQ("www.google.com", headers[":authority"].as_string());
247 EXPECT_EQ("/", headers[":path"].as_string()); 249 EXPECT_EQ("/", headers[":path"].as_string());
248 } 250 }
249 251
250 TEST(SpdyUtilsTest, PopulateHeaderBlockFromUrlFails) { 252 TEST_F(SpdyUtilsTest, PopulateHeaderBlockFromUrlFails) {
251 SpdyHeaderBlock headers; 253 SpdyHeaderBlock headers;
252 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/", &headers)); 254 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/", &headers));
253 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/index.html", &headers)); 255 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/index.html", &headers));
254 EXPECT_FALSE( 256 EXPECT_FALSE(
255 SpdyUtils::PopulateHeaderBlockFromUrl("www.google.com/", &headers)); 257 SpdyUtils::PopulateHeaderBlockFromUrl("www.google.com/", &headers));
256 } 258 }
257 259
258 } // namespace test 260 } // namespace test
259 } // namespace net 261 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_write_blocked_list_test.cc ('k') | net/quic/platform/api/quic_endian_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698