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

Side by Side Diff: net/spdy/core/spdy_header_indexing_test.cc

Issue 2846983003: Remove unused HeaderIndexing class. (Closed)
Patch Set: Created 3 years, 7 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/core/spdy_header_indexing.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/spdy/core/spdy_header_indexing.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "net/spdy/platform/api/spdy_ptr_util.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/platform_test.h"
11
12 namespace net {
13
14 namespace test {
15
16 class HeaderIndexingPeer {
17 public:
18 HeaderIndexingPeer() : hi_() {}
19
20 void CreateTestInit() {
21 SpdyString input[] = {"key1", "key2", "key3"};
22 hi_.indexing_set_ =
23 HeaderIndexing::HeaderSet(input, input + arraysize(input));
24 hi_.tracking_set_ =
25 HeaderIndexing::HeaderSet(input, input + arraysize(input));
26 }
27
28 bool ShouldIndex(SpdyStringPiece header) {
29 return hi_.ShouldIndex(header, "");
30 }
31
32 void CreateInitIndexingHeaders() { hi_.CreateInitIndexingHeaders(); }
33
34 void TryInsert(SpdyString&& header) {
35 hi_.TryInsertHeader(std::move(header), &(hi_.indexing_set_),
36 hi_.indexing_set_bound_);
37 }
38
39 bool InTrackingSet(const SpdyString& str) {
40 return hi_.tracking_set_.find(str) != hi_.tracking_set_.end();
41 }
42
43 size_t indexing_set_size() const { return hi_.indexing_set_.size(); }
44
45 size_t tracking_set_size() const { return hi_.tracking_set_.size(); }
46
47 HeaderIndexing::HeaderSet* indexing_set() { return &(hi_.indexing_set_); }
48
49 HeaderIndexing::HeaderSet* tracking_set() { return &(hi_.tracking_set_); }
50
51 private:
52 HeaderIndexing hi_;
53 };
54
55 class SpdyHeaderIndexingTest : public ::testing::Test {
56 protected:
57 SpdyHeaderIndexingTest() {
58 FLAGS_gfe_spdy_indexing_set_bound = 3;
59 FLAGS_gfe_spdy_tracking_set_bound = 4;
60 hi_ = SpdyMakeUnique<HeaderIndexingPeer>();
61 hi_->CreateTestInit();
62 }
63 void SetUp() override {
64 EXPECT_EQ(3u, hi_->indexing_set_size());
65 EXPECT_EQ(3u, hi_->tracking_set_size());
66 }
67 std::unique_ptr<HeaderIndexingPeer> hi_;
68 };
69
70 TEST_F(SpdyHeaderIndexingTest, TestTryInsertHeader) {
71 SpdyString key("key4");
72 hi_->TryInsert(std::move(key));
73 EXPECT_EQ(3u, hi_->indexing_set_size());
74 EXPECT_TRUE(hi_->ShouldIndex("key4"));
75 }
76
77 TEST_F(SpdyHeaderIndexingTest, TestShouldIndex) {
78 SpdyString key3 = "key3";
79 SpdyString key4 = "key4";
80 SpdyString key5 = "key5";
81 // Cache hit.
82 EXPECT_TRUE(hi_->ShouldIndex(key3));
83 EXPECT_EQ(3u, hi_->indexing_set_size());
84 EXPECT_EQ(3u, hi_->tracking_set_size());
85
86 // Cache miss. Add to tracking set.
87 EXPECT_FALSE(hi_->ShouldIndex(key4));
88 EXPECT_EQ(3u, hi_->indexing_set_size());
89 EXPECT_EQ(4u, hi_->tracking_set_size());
90 EXPECT_TRUE(hi_->InTrackingSet(key4));
91 // Cache miss. Add to indexing set by kicking one entry out.
92 EXPECT_FALSE(hi_->ShouldIndex(key4));
93 EXPECT_EQ(3u, hi_->indexing_set_size());
94 EXPECT_EQ(4u, hi_->tracking_set_size());
95 EXPECT_TRUE(hi_->InTrackingSet(key4));
96 // Cache hit.
97 EXPECT_TRUE(hi_->ShouldIndex(key4));
98
99 // Cache miss. Add to tracking set by kicking one entry out.
100 EXPECT_FALSE(hi_->ShouldIndex(key5));
101 EXPECT_EQ(3u, hi_->indexing_set_size());
102 EXPECT_EQ(4u, hi_->tracking_set_size());
103 EXPECT_TRUE(hi_->ShouldIndex(key4));
104 EXPECT_TRUE(hi_->InTrackingSet(key5));
105 // Cache miss. Add to indexing set by kicking one entry out.
106 EXPECT_FALSE(hi_->ShouldIndex(key5));
107 EXPECT_EQ(3u, hi_->indexing_set_size());
108 EXPECT_EQ(4u, hi_->tracking_set_size());
109 EXPECT_TRUE(hi_->ShouldIndex(key5));
110 EXPECT_TRUE(hi_->InTrackingSet(key5));
111 }
112
113 TEST_F(SpdyHeaderIndexingTest, TestSetInit) {
114 hi_->CreateInitIndexingHeaders();
115 EXPECT_EQ(100u, hi_->indexing_set_size());
116 EXPECT_EQ(100u, hi_->tracking_set_size());
117 EXPECT_TRUE(hi_->ShouldIndex(":status"));
118 EXPECT_TRUE(hi_->InTrackingSet(":status"));
119 EXPECT_FALSE(hi_->InTrackingSet("NotValid"));
120 EXPECT_FALSE(hi_->ShouldIndex("NotValid"));
121 }
122
123 } // namespace test
124
125 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/core/spdy_header_indexing.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698