| 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 |
| 11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "net/spdy/hpack/hpack_constants.h" | 12 #include "net/spdy/hpack/hpack_constants.h" |
| 13 #include "net/spdy/hpack/hpack_decoder.h" | 13 #include "net/spdy/hpack/hpack_decoder.h" |
| 14 #include "net/spdy/hpack/hpack_encoder.h" | 14 #include "net/spdy/hpack/hpack_encoder.h" |
| 15 #include "net/spdy/spdy_test_utils.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 19 namespace test { |
| 18 | 20 |
| 19 using std::map; | 21 using std::map; |
| 20 using std::string; | 22 using std::string; |
| 21 using std::vector; | 23 using std::vector; |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| 25 class HpackRoundTripTest : public ::testing::Test { | 27 class HpackRoundTripTest : public ::testing::Test { |
| 26 protected: | 28 protected: |
| 27 HpackRoundTripTest() | 29 HpackRoundTripTest() |
| 28 : encoder_(ObtainHpackHuffmanTable()), | 30 : encoder_(ObtainHpackHuffmanTable()), |
| 29 decoder_(ObtainHpackHuffmanTable()) {} | 31 decoder_(ObtainHpackHuffmanTable()) {} |
| 30 | 32 |
| 31 void SetUp() override { | 33 void SetUp() override { |
| 32 // Use a small table size to tickle eviction handling. | 34 // Use a small table size to tickle eviction handling. |
| 33 encoder_.ApplyHeaderTableSizeSetting(256); | 35 encoder_.ApplyHeaderTableSizeSetting(256); |
| 34 decoder_.ApplyHeaderTableSizeSetting(256); | 36 decoder_.ApplyHeaderTableSizeSetting(256); |
| 35 } | 37 } |
| 36 | 38 |
| 37 bool RoundTrip(const SpdyHeaderBlock& header_set) { | 39 bool RoundTrip(const SpdyHeaderBlock& header_set) { |
| 38 string encoded; | 40 string encoded; |
| 39 encoder_.EncodeHeaderSet(header_set, &encoded); | 41 encoder_.EncodeHeaderSet(header_set, &encoded); |
| 40 | 42 |
| 41 bool success = decoder_.HandleControlFrameHeadersData(1, encoded.data(), | 43 bool success = decoder_.HandleControlFrameHeadersData(1, encoded.data(), |
| 42 encoded.size()); | 44 encoded.size()); |
| 43 success &= decoder_.HandleControlFrameHeadersComplete(1, nullptr); | 45 success &= decoder_.HandleControlFrameHeadersComplete(1, nullptr); |
| 44 | 46 |
| 45 EXPECT_EQ(header_set, decoder_.decoded_block()); | 47 EXPECT_TRUE(CompareSpdyHeaderBlocks(header_set, decoder_.decoded_block())); |
| 46 return success; | 48 return success; |
| 47 } | 49 } |
| 48 | 50 |
| 49 size_t SampleExponential(size_t mean, size_t sanity_bound) { | 51 size_t SampleExponential(size_t mean, size_t sanity_bound) { |
| 50 return std::min<size_t>(-std::log(base::RandDouble()) * mean, sanity_bound); | 52 return std::min<size_t>(-std::log(base::RandDouble()) * mean, sanity_bound); |
| 51 } | 53 } |
| 52 | 54 |
| 53 HpackEncoder encoder_; | 55 HpackEncoder encoder_; |
| 54 HpackDecoder decoder_; | 56 HpackDecoder decoder_; |
| 55 }; | 57 }; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 value = values[value_index]; | 174 value = values[value_index]; |
| 173 } | 175 } |
| 174 headers[name] = value; | 176 headers[name] = value; |
| 175 } | 177 } |
| 176 EXPECT_TRUE(RoundTrip(headers)); | 178 EXPECT_TRUE(RoundTrip(headers)); |
| 177 } | 179 } |
| 178 } | 180 } |
| 179 | 181 |
| 180 } // namespace | 182 } // namespace |
| 181 | 183 |
| 184 } // namespace test |
| 182 } // namespace net | 185 } // namespace net |
| OLD | NEW |