| 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 16 matching lines...) Expand all Loading... |
| 27 HpackRoundTripTest() | 27 HpackRoundTripTest() |
| 28 : encoder_(ObtainHpackHuffmanTable()), | 28 : encoder_(ObtainHpackHuffmanTable()), |
| 29 decoder_(ObtainHpackHuffmanTable()) {} | 29 decoder_(ObtainHpackHuffmanTable()) {} |
| 30 | 30 |
| 31 void SetUp() override { | 31 void SetUp() override { |
| 32 // Use a small table size to tickle eviction handling. | 32 // Use a small table size to tickle eviction handling. |
| 33 encoder_.ApplyHeaderTableSizeSetting(256); | 33 encoder_.ApplyHeaderTableSizeSetting(256); |
| 34 decoder_.ApplyHeaderTableSizeSetting(256); | 34 decoder_.ApplyHeaderTableSizeSetting(256); |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool RoundTrip(const map<string, string>& header_set) { | 37 bool RoundTrip(const SpdyHeaderBlock& header_set) { |
| 38 string encoded; | 38 string encoded; |
| 39 encoder_.EncodeHeaderSet(header_set, &encoded); | 39 encoder_.EncodeHeaderSet(header_set, &encoded); |
| 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, |
| 51 sanity_bound); | 51 sanity_bound); |
| 52 } | 52 } |
| 53 | 53 |
| 54 HpackEncoder encoder_; | 54 HpackEncoder encoder_; |
| 55 HpackDecoder decoder_; | 55 HpackDecoder decoder_; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 TEST_F(HpackRoundTripTest, ResponseFixtures) { | 58 TEST_F(HpackRoundTripTest, ResponseFixtures) { |
| 59 { | 59 { |
| 60 map<string, string> headers; | 60 SpdyHeaderBlock headers; |
| 61 headers[":status"] = "302"; | 61 headers[":status"] = "302"; |
| 62 headers["cache-control"] = "private"; | 62 headers["cache-control"] = "private"; |
| 63 headers["date"] = "Mon, 21 Oct 2013 20:13:21 GMT"; | 63 headers["date"] = "Mon, 21 Oct 2013 20:13:21 GMT"; |
| 64 headers["location"] = "https://www.example.com"; | 64 headers["location"] = "https://www.example.com"; |
| 65 EXPECT_TRUE(RoundTrip(headers)); | 65 EXPECT_TRUE(RoundTrip(headers)); |
| 66 } | 66 } |
| 67 { | 67 { |
| 68 map<string, string> headers; | 68 SpdyHeaderBlock headers; |
| 69 headers[":status"] = "200"; | 69 headers[":status"] = "200"; |
| 70 headers["cache-control"] = "private"; | 70 headers["cache-control"] = "private"; |
| 71 headers["date"] = "Mon, 21 Oct 2013 20:13:21 GMT"; | 71 headers["date"] = "Mon, 21 Oct 2013 20:13:21 GMT"; |
| 72 headers["location"] = "https://www.example.com"; | 72 headers["location"] = "https://www.example.com"; |
| 73 EXPECT_TRUE(RoundTrip(headers)); | 73 EXPECT_TRUE(RoundTrip(headers)); |
| 74 } | 74 } |
| 75 { | 75 { |
| 76 map<string, string> headers; | 76 SpdyHeaderBlock headers; |
| 77 headers[":status"] = "200"; | 77 headers[":status"] = "200"; |
| 78 headers["cache-control"] = "private"; | 78 headers["cache-control"] = "private"; |
| 79 headers["content-encoding"] = "gzip"; | 79 headers["content-encoding"] = "gzip"; |
| 80 headers["date"] = "Mon, 21 Oct 2013 20:13:22 GMT"; | 80 headers["date"] = "Mon, 21 Oct 2013 20:13:22 GMT"; |
| 81 headers["location"] = "https://www.example.com"; | 81 headers["location"] = "https://www.example.com"; |
| 82 headers["set-cookie"] = "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU;" | 82 headers["set-cookie"] = "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU;" |
| 83 " max-age=3600; version=1"; | 83 " max-age=3600; version=1"; |
| 84 headers["multivalue"] = string("foo\0bar", 7); | 84 headers["multivalue"] = string("foo\0bar", 7); |
| 85 EXPECT_TRUE(RoundTrip(headers)); | 85 EXPECT_TRUE(RoundTrip(headers)); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 TEST_F(HpackRoundTripTest, RequestFixtures) { | 89 TEST_F(HpackRoundTripTest, RequestFixtures) { |
| 90 { | 90 { |
| 91 map<string, string> headers; | 91 SpdyHeaderBlock headers; |
| 92 headers[":authority"] = "www.example.com"; | 92 headers[":authority"] = "www.example.com"; |
| 93 headers[":method"] = "GET"; | 93 headers[":method"] = "GET"; |
| 94 headers[":path"] = "/"; | 94 headers[":path"] = "/"; |
| 95 headers[":scheme"] = "http"; | 95 headers[":scheme"] = "http"; |
| 96 headers["cookie"] = "baz=bing; foo=bar"; | 96 headers["cookie"] = "baz=bing; foo=bar"; |
| 97 EXPECT_TRUE(RoundTrip(headers)); | 97 EXPECT_TRUE(RoundTrip(headers)); |
| 98 } | 98 } |
| 99 { | 99 { |
| 100 map<string, string> headers; | 100 SpdyHeaderBlock headers; |
| 101 headers[":authority"] = "www.example.com"; | 101 headers[":authority"] = "www.example.com"; |
| 102 headers[":method"] = "GET"; | 102 headers[":method"] = "GET"; |
| 103 headers[":path"] = "/"; | 103 headers[":path"] = "/"; |
| 104 headers[":scheme"] = "http"; | 104 headers[":scheme"] = "http"; |
| 105 headers["cache-control"] = "no-cache"; | 105 headers["cache-control"] = "no-cache"; |
| 106 headers["cookie"] = "foo=bar; spam=eggs"; | 106 headers["cookie"] = "foo=bar; spam=eggs"; |
| 107 EXPECT_TRUE(RoundTrip(headers)); | 107 EXPECT_TRUE(RoundTrip(headers)); |
| 108 } | 108 } |
| 109 { | 109 { |
| 110 map<string, string> headers; | 110 SpdyHeaderBlock headers; |
| 111 headers[":authority"] = "www.example.com"; | 111 headers[":authority"] = "www.example.com"; |
| 112 headers[":method"] = "GET"; | 112 headers[":method"] = "GET"; |
| 113 headers[":path"] = "/index.html"; | 113 headers[":path"] = "/index.html"; |
| 114 headers[":scheme"] = "https"; | 114 headers[":scheme"] = "https"; |
| 115 headers["custom-key"] = "custom-value"; | 115 headers["custom-key"] = "custom-value"; |
| 116 headers["cookie"] = "baz=bing; fizzle=fazzle; garbage"; | 116 headers["cookie"] = "baz=bing; fizzle=fazzle; garbage"; |
| 117 headers["multivalue"] = string("foo\0bar", 7); | 117 headers["multivalue"] = string("foo\0bar", 7); |
| 118 EXPECT_TRUE(RoundTrip(headers)); | 118 EXPECT_TRUE(RoundTrip(headers)); |
| 119 } | 119 } |
| 120 } | 120 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 137 values.push_back("404"); | 137 values.push_back("404"); |
| 138 values.push_back(""); | 138 values.push_back(""); |
| 139 values.push_back("baz=bing; foo=bar; garbage"); | 139 values.push_back("baz=bing; foo=bar; garbage"); |
| 140 values.push_back("baz=bing; fizzle=fazzle; garbage"); | 140 values.push_back("baz=bing; fizzle=fazzle; garbage"); |
| 141 | 141 |
| 142 int seed = std::time(NULL); | 142 int seed = std::time(NULL); |
| 143 LOG(INFO) << "Seeding with srand(" << seed << ")"; | 143 LOG(INFO) << "Seeding with srand(" << seed << ")"; |
| 144 srand(seed); | 144 srand(seed); |
| 145 | 145 |
| 146 for (size_t i = 0; i != 2000; ++i) { | 146 for (size_t i = 0; i != 2000; ++i) { |
| 147 map<string, string> headers; | 147 SpdyHeaderBlock headers; |
| 148 | 148 |
| 149 size_t header_count = 1 + SampleExponential(7, 50); | 149 size_t header_count = 1 + SampleExponential(7, 50); |
| 150 for (size_t j = 0; j != header_count; ++j) { | 150 for (size_t j = 0; j != header_count; ++j) { |
| 151 size_t name_index = SampleExponential(20, 200); | 151 size_t name_index = SampleExponential(20, 200); |
| 152 size_t value_index = SampleExponential(20, 200); | 152 size_t value_index = SampleExponential(20, 200); |
| 153 | 153 |
| 154 string name, value; | 154 string name, value; |
| 155 if (name_index >= names.size()) { | 155 if (name_index >= names.size()) { |
| 156 names.push_back(base::RandBytesAsString(1 + SampleExponential(5, 30))); | 156 names.push_back(base::RandBytesAsString(1 + SampleExponential(5, 30))); |
| 157 name = names.back(); | 157 name = names.back(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 173 } | 173 } |
| 174 headers[name] = value; | 174 headers[name] = value; |
| 175 } | 175 } |
| 176 EXPECT_TRUE(RoundTrip(headers)); | 176 EXPECT_TRUE(RoundTrip(headers)); |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| 180 } // namespace | 180 } // namespace |
| 181 | 181 |
| 182 } // namespace net | 182 } // namespace net |
| OLD | NEW |