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

Side by Side Diff: net/spdy/hpack/hpack_round_trip_test.cc

Issue 1273743002: Add CompareSpdyHeaderBlocks() test helper method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « net/spdy/hpack/hpack_decoder_test.cc ('k') | net/spdy/spdy_test_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « net/spdy/hpack/hpack_decoder_test.cc ('k') | net/spdy/spdy_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698