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 |
11 using base::StringPiece; | 11 using base::StringPiece; |
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 TEST(SpdyUtilsTest, SerializeAndParseHeaders) { | 19 TEST(SpdyUtilsTest, SerializeAndParseHeaders) { |
20 // Creates a SpdyHeaderBlock with some key->value pairs, serializes it, then | 20 // Creates a SpdyHeaderBlock with some key->value pairs, serializes it, then |
21 // parses the serialized output and verifies that the end result is the same | 21 // parses the serialized output and verifies that the end result is the same |
22 // as the headers that the test started with. | 22 // as the headers that the test started with. |
23 | 23 |
24 SpdyHeaderBlock input_headers; | 24 SpdyHeaderBlock input_headers; |
25 input_headers[":pseudo1"] = "pseudo value1"; | 25 input_headers[":pseudo1"] = "pseudo value1"; |
26 input_headers[":pseudo2"] = "pseudo value2"; | 26 input_headers[":pseudo2"] = "pseudo value2"; |
27 input_headers["key1"] = "value1"; | 27 input_headers["key1"] = "value1"; |
28 const int kContentLength = 1234; | 28 const int64_t kContentLength = 1234; |
29 input_headers["content-length"] = base::IntToString(kContentLength); | 29 input_headers["content-length"] = base::Int64ToString(kContentLength); |
30 input_headers["key2"] = "value2"; | 30 input_headers["key2"] = "value2"; |
31 | 31 |
32 // Serialize the header block. | 32 // Serialize the header block. |
| 33 string serialized_headers = |
| 34 SpdyUtils::SerializeUncompressedHeaders(input_headers); |
| 35 |
| 36 // Take the serialized header block, and parse back into SpdyHeaderBlock. |
| 37 SpdyHeaderBlock output_headers; |
| 38 int64_t content_length = -1; |
| 39 ASSERT_TRUE(SpdyUtils::ParseHeaders(serialized_headers.data(), |
| 40 serialized_headers.size(), |
| 41 &content_length, &output_headers)); |
| 42 |
| 43 // Should be back to the original headers. |
| 44 EXPECT_EQ(content_length, kContentLength); |
| 45 EXPECT_EQ(output_headers, input_headers); |
| 46 } |
| 47 |
| 48 TEST(SpdyUtilsTest, SerializeAndParseHeadersLargeContentLength) { |
| 49 // Creates a SpdyHeaderBlock with some key->value pairs, serializes it, then |
| 50 // parses the serialized output and verifies that the end result is the same |
| 51 // as the headers that the test started with. |
| 52 |
| 53 SpdyHeaderBlock input_headers; |
| 54 input_headers[":pseudo1"] = "pseudo value1"; |
| 55 input_headers[":pseudo2"] = "pseudo value2"; |
| 56 input_headers["key1"] = "value1"; |
| 57 const int64_t kContentLength = 12345678900; |
| 58 input_headers["content-length"] = base::Int64ToString(kContentLength); |
| 59 input_headers["key2"] = "value2"; |
| 60 |
| 61 // Serialize the header block. |
33 string serialized_headers = | 62 string serialized_headers = |
34 SpdyUtils::SerializeUncompressedHeaders(input_headers); | 63 SpdyUtils::SerializeUncompressedHeaders(input_headers); |
35 | 64 |
36 // Take the serialized header block, and parse back into SpdyHeaderBlock. | 65 // Take the serialized header block, and parse back into SpdyHeaderBlock. |
37 SpdyHeaderBlock output_headers; | 66 SpdyHeaderBlock output_headers; |
38 int64_t content_length = -1; | 67 int64_t content_length = -1; |
39 ASSERT_TRUE(SpdyUtils::ParseHeaders(serialized_headers.data(), | 68 ASSERT_TRUE(SpdyUtils::ParseHeaders(serialized_headers.data(), |
40 serialized_headers.size(), | 69 serialized_headers.size(), |
41 &content_length, &output_headers)); | 70 &content_length, &output_headers)); |
42 | 71 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 headers[":scheme"] = "https"; | 334 headers[":scheme"] = "https"; |
306 EXPECT_FALSE(SpdyUtils::UrlIsValid(headers)); | 335 EXPECT_FALSE(SpdyUtils::UrlIsValid(headers)); |
307 headers[":authority"] = "www.google.com"; | 336 headers[":authority"] = "www.google.com"; |
308 EXPECT_FALSE(SpdyUtils::UrlIsValid(headers)); | 337 EXPECT_FALSE(SpdyUtils::UrlIsValid(headers)); |
309 headers[":path"] = "/index.html"; | 338 headers[":path"] = "/index.html"; |
310 EXPECT_TRUE(SpdyUtils::UrlIsValid(headers)); | 339 EXPECT_TRUE(SpdyUtils::UrlIsValid(headers)); |
311 } | 340 } |
312 | 341 |
313 } // namespace test | 342 } // namespace test |
314 } // namespace net | 343 } // namespace net |
OLD | NEW |