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

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

Issue 2832973003: Split net/spdy into core and chromium subdirectories. (Closed)
Patch Set: Fix some more build rules. Created 3 years, 8 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/spdy_header_indexing.cc ('k') | net/spdy/spdy_headers_handler_interface.h » ('j') | 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/spdy_header_indexing.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/platform_test.h"
10
11 namespace net {
12
13 namespace test {
14
15 class HeaderIndexingPeer {
16 public:
17 HeaderIndexingPeer() : hi_() {}
18
19 void CreateTestInit() {
20 SpdyString input[] = {"key1", "key2", "key3"};
21 hi_.indexing_set_ =
22 HeaderIndexing::HeaderSet(input, input + arraysize(input));
23 hi_.tracking_set_ =
24 HeaderIndexing::HeaderSet(input, input + arraysize(input));
25 }
26
27 bool ShouldIndex(SpdyStringPiece header) {
28 return hi_.ShouldIndex(header, "");
29 }
30
31 void CreateInitIndexingHeaders() { hi_.CreateInitIndexingHeaders(); }
32
33 void TryInsert(SpdyString&& header) {
34 hi_.TryInsertHeader(std::move(header), &(hi_.indexing_set_),
35 hi_.indexing_set_bound_);
36 }
37
38 bool InTrackingSet(const SpdyString& str) {
39 return hi_.tracking_set_.find(str) != hi_.tracking_set_.end();
40 }
41
42 size_t indexing_set_size() const { return hi_.indexing_set_.size(); }
43
44 size_t tracking_set_size() const { return hi_.tracking_set_.size(); }
45
46 HeaderIndexing::HeaderSet* indexing_set() { return &(hi_.indexing_set_); }
47
48 HeaderIndexing::HeaderSet* tracking_set() { return &(hi_.tracking_set_); }
49
50 private:
51 HeaderIndexing hi_;
52 };
53
54 class SpdyHeaderIndexingTest : public ::testing::Test {
55 protected:
56 SpdyHeaderIndexingTest() {
57 FLAGS_gfe_spdy_indexing_set_bound = 3;
58 FLAGS_gfe_spdy_tracking_set_bound = 4;
59 hi_ = base::MakeUnique<HeaderIndexingPeer>();
60 hi_->CreateTestInit();
61 }
62 void SetUp() override {
63 EXPECT_EQ(3u, hi_->indexing_set_size());
64 EXPECT_EQ(3u, hi_->tracking_set_size());
65 }
66 std::unique_ptr<HeaderIndexingPeer> hi_;
67 };
68
69 TEST_F(SpdyHeaderIndexingTest, TestTryInsertHeader) {
70 SpdyString key("key4");
71 hi_->TryInsert(std::move(key));
72 EXPECT_EQ(3u, hi_->indexing_set_size());
73 EXPECT_TRUE(hi_->ShouldIndex("key4"));
74 }
75
76 TEST_F(SpdyHeaderIndexingTest, TestShouldIndex) {
77 SpdyString key3 = "key3";
78 SpdyString key4 = "key4";
79 SpdyString key5 = "key5";
80 // Cache hit.
81 EXPECT_TRUE(hi_->ShouldIndex(key3));
82 EXPECT_EQ(3u, hi_->indexing_set_size());
83 EXPECT_EQ(3u, hi_->tracking_set_size());
84
85 // Cache miss. Add to tracking set.
86 EXPECT_FALSE(hi_->ShouldIndex(key4));
87 EXPECT_EQ(3u, hi_->indexing_set_size());
88 EXPECT_EQ(4u, hi_->tracking_set_size());
89 EXPECT_TRUE(hi_->InTrackingSet(key4));
90 // Cache miss. Add to indexing set by kicking one entry out.
91 EXPECT_FALSE(hi_->ShouldIndex(key4));
92 EXPECT_EQ(3u, hi_->indexing_set_size());
93 EXPECT_EQ(4u, hi_->tracking_set_size());
94 EXPECT_TRUE(hi_->InTrackingSet(key4));
95 // Cache hit.
96 EXPECT_TRUE(hi_->ShouldIndex(key4));
97
98 // Cache miss. Add to tracking set by kicking one entry out.
99 EXPECT_FALSE(hi_->ShouldIndex(key5));
100 EXPECT_EQ(3u, hi_->indexing_set_size());
101 EXPECT_EQ(4u, hi_->tracking_set_size());
102 EXPECT_TRUE(hi_->ShouldIndex(key4));
103 EXPECT_TRUE(hi_->InTrackingSet(key5));
104 // Cache miss. Add to indexing set by kicking one entry out.
105 EXPECT_FALSE(hi_->ShouldIndex(key5));
106 EXPECT_EQ(3u, hi_->indexing_set_size());
107 EXPECT_EQ(4u, hi_->tracking_set_size());
108 EXPECT_TRUE(hi_->ShouldIndex(key5));
109 EXPECT_TRUE(hi_->InTrackingSet(key5));
110 }
111
112 TEST_F(SpdyHeaderIndexingTest, TestSetInit) {
113 hi_->CreateInitIndexingHeaders();
114 EXPECT_EQ(100u, hi_->indexing_set_size());
115 EXPECT_EQ(100u, hi_->tracking_set_size());
116 EXPECT_TRUE(hi_->ShouldIndex(":status"));
117 EXPECT_TRUE(hi_->InTrackingSet(":status"));
118 EXPECT_FALSE(hi_->InTrackingSet("NotValid"));
119 EXPECT_FALSE(hi_->ShouldIndex("NotValid"));
120 }
121
122 } // namespace test
123
124 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_header_indexing.cc ('k') | net/spdy/spdy_headers_handler_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698