| OLD | NEW |
| 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/spdy_utils.h" | 4 #include "net/quic/spdy_utils.h" |
| 5 | 5 |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/string_piece.h" | 8 #include "base/strings/string_piece.h" |
| 9 #include "net/test/gtest_util.h" | 9 #include "net/test/gtest_util.h" |
| 10 | 10 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 {"foo", "foovalue"}, | 158 {"foo", "foovalue"}, |
| 159 {"content-length", "9"}, | 159 {"content-length", "9"}, |
| 160 {"bar", "barvalue"}, | 160 {"bar", "barvalue"}, |
| 161 {"baz", ""}}); | 161 {"baz", ""}}); |
| 162 int64_t content_length = -1; | 162 int64_t content_length = -1; |
| 163 SpdyHeaderBlock block; | 163 SpdyHeaderBlock block; |
| 164 ASSERT_TRUE( | 164 ASSERT_TRUE( |
| 165 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); | 165 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); |
| 166 EXPECT_THAT(block, UnorderedElementsAre( | 166 EXPECT_THAT(block, UnorderedElementsAre( |
| 167 Pair("foo", "foovalue"), Pair("bar", "barvalue"), | 167 Pair("foo", "foovalue"), Pair("bar", "barvalue"), |
| 168 Pair("content-length", StringPiece("9\09", 3)), | 168 Pair("content-length", StringPiece("9" |
| 169 "\0" |
| 170 "9", |
| 171 3)), |
| 169 Pair("baz", ""))); | 172 Pair("baz", ""))); |
| 170 EXPECT_EQ(9, content_length); | 173 EXPECT_EQ(9, content_length); |
| 171 } | 174 } |
| 172 | 175 |
| 173 TEST(SpdyUtilsTest, CopyAndValidateHeadersInconsistentContentLengths) { | 176 TEST(SpdyUtilsTest, CopyAndValidateHeadersInconsistentContentLengths) { |
| 174 auto headers = FromList({{"content-length", "9"}, | 177 auto headers = FromList({{"content-length", "9"}, |
| 175 {"foo", "foovalue"}, | 178 {"foo", "foovalue"}, |
| 176 {"content-length", "8"}, | 179 {"content-length", "8"}, |
| 177 {"bar", "barvalue"}, | 180 {"bar", "barvalue"}, |
| 178 {"baz", ""}}); | 181 {"baz", ""}}); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 192 SpdyHeaderBlock block; | 195 SpdyHeaderBlock block; |
| 193 ASSERT_TRUE( | 196 ASSERT_TRUE( |
| 194 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); | 197 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); |
| 195 EXPECT_THAT( | 198 EXPECT_THAT( |
| 196 block, UnorderedElementsAre(Pair("foo", StringPiece("foovalue\0boo", 12)), | 199 block, UnorderedElementsAre(Pair("foo", StringPiece("foovalue\0boo", 12)), |
| 197 Pair("bar", "barvalue"), | 200 Pair("bar", "barvalue"), |
| 198 Pair("baz", StringPiece("\0buzz", 5)))); | 201 Pair("baz", StringPiece("\0buzz", 5)))); |
| 199 EXPECT_EQ(-1, content_length); | 202 EXPECT_EQ(-1, content_length); |
| 200 } | 203 } |
| 201 | 204 |
| 205 TEST(SpdyUtilsTest, CopyAndValidateHeadersCookie) { |
| 206 auto headers = FromList({{"foo", "foovalue"}, |
| 207 {"bar", "barvalue"}, |
| 208 {"cookie", "value1"}, |
| 209 {"baz", ""}}); |
| 210 int64_t content_length = -1; |
| 211 SpdyHeaderBlock block; |
| 212 ASSERT_TRUE( |
| 213 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); |
| 214 EXPECT_THAT(block, UnorderedElementsAre( |
| 215 Pair("foo", "foovalue"), Pair("bar", "barvalue"), |
| 216 Pair("cookie", "value1"), Pair("baz", ""))); |
| 217 EXPECT_EQ(-1, content_length); |
| 218 } |
| 219 |
| 220 TEST(SpdyUtilsTest, CopyAndValidateHeadersMultipleCookies) { |
| 221 auto headers = FromList({{"foo", "foovalue"}, |
| 222 {"bar", "barvalue"}, |
| 223 {"cookie", "value1"}, |
| 224 {"baz", ""}, |
| 225 {"cookie", "value2"}}); |
| 226 int64_t content_length = -1; |
| 227 SpdyHeaderBlock block; |
| 228 ASSERT_TRUE( |
| 229 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); |
| 230 EXPECT_THAT(block, UnorderedElementsAre( |
| 231 Pair("foo", "foovalue"), Pair("bar", "barvalue"), |
| 232 Pair("cookie", "value1; value2"), Pair("baz", ""))); |
| 233 EXPECT_EQ(-1, content_length); |
| 234 } |
| 235 |
| 202 TEST(SpdyUtilsTest, GetUrlFromHeaderBlock) { | 236 TEST(SpdyUtilsTest, GetUrlFromHeaderBlock) { |
| 203 SpdyHeaderBlock headers; | 237 SpdyHeaderBlock headers; |
| 204 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); | 238 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); |
| 205 headers[":scheme"] = "https"; | 239 headers[":scheme"] = "https"; |
| 206 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); | 240 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); |
| 207 headers[":authority"] = "www.google.com"; | 241 headers[":authority"] = "www.google.com"; |
| 208 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); | 242 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); |
| 209 headers[":path"] = "/index.html"; | 243 headers[":path"] = "/index.html"; |
| 210 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), | 244 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), |
| 211 "https://www.google.com/index.html"); | 245 "https://www.google.com/index.html"); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 241 headers[":scheme"] = "https"; | 275 headers[":scheme"] = "https"; |
| 242 EXPECT_FALSE(SpdyUtils::UrlIsValid(headers)); | 276 EXPECT_FALSE(SpdyUtils::UrlIsValid(headers)); |
| 243 headers[":authority"] = "www.google.com"; | 277 headers[":authority"] = "www.google.com"; |
| 244 EXPECT_FALSE(SpdyUtils::UrlIsValid(headers)); | 278 EXPECT_FALSE(SpdyUtils::UrlIsValid(headers)); |
| 245 headers[":path"] = "/index.html"; | 279 headers[":path"] = "/index.html"; |
| 246 EXPECT_TRUE(SpdyUtils::UrlIsValid(headers)); | 280 EXPECT_TRUE(SpdyUtils::UrlIsValid(headers)); |
| 247 } | 281 } |
| 248 | 282 |
| 249 } // namespace test | 283 } // namespace test |
| 250 } // namespace net | 284 } // namespace net |
| OLD | NEW |