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

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

Issue 2801603003: Add SpdyString alias for std::string in net/spdy. (Closed)
Patch Set: 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_http_stream.cc » ('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 (c) 2016 The Chromium Authors. All rights reserved. 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 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 "net/spdy/spdy_header_indexing.h" 5 #include "net/spdy/spdy_header_indexing.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/platform_test.h" 9 #include "testing/platform_test.h"
10 10
11 namespace net { 11 namespace net {
12 12
13 namespace test { 13 namespace test {
14 14
15 class HeaderIndexingPeer { 15 class HeaderIndexingPeer {
16 public: 16 public:
17 HeaderIndexingPeer() : hi_() {} 17 HeaderIndexingPeer() : hi_() {}
18 18
19 void CreateTestInit() { 19 void CreateTestInit() {
20 std::string input[] = {"key1", "key2", "key3"}; 20 SpdyString input[] = {"key1", "key2", "key3"};
21 hi_.indexing_set_ = 21 hi_.indexing_set_ =
22 HeaderIndexing::HeaderSet(input, input + arraysize(input)); 22 HeaderIndexing::HeaderSet(input, input + arraysize(input));
23 hi_.tracking_set_ = 23 hi_.tracking_set_ =
24 HeaderIndexing::HeaderSet(input, input + arraysize(input)); 24 HeaderIndexing::HeaderSet(input, input + arraysize(input));
25 } 25 }
26 26
27 bool ShouldIndex(SpdyStringPiece header) { 27 bool ShouldIndex(SpdyStringPiece header) {
28 return hi_.ShouldIndex(header, ""); 28 return hi_.ShouldIndex(header, "");
29 } 29 }
30 30
31 void CreateInitIndexingHeaders() { hi_.CreateInitIndexingHeaders(); } 31 void CreateInitIndexingHeaders() { hi_.CreateInitIndexingHeaders(); }
32 32
33 void TryInsert(std::string&& header) { 33 void TryInsert(SpdyString&& header) {
34 hi_.TryInsertHeader(std::move(header), &(hi_.indexing_set_), 34 hi_.TryInsertHeader(std::move(header), &(hi_.indexing_set_),
35 hi_.indexing_set_bound_); 35 hi_.indexing_set_bound_);
36 } 36 }
37 37
38 bool InTrackingSet(const std::string& str) { 38 bool InTrackingSet(const SpdyString& str) {
39 return hi_.tracking_set_.find(str) != hi_.tracking_set_.end(); 39 return hi_.tracking_set_.find(str) != hi_.tracking_set_.end();
40 } 40 }
41 41
42 size_t indexing_set_size() const { return hi_.indexing_set_.size(); } 42 size_t indexing_set_size() const { return hi_.indexing_set_.size(); }
43 43
44 size_t tracking_set_size() const { return hi_.tracking_set_.size(); } 44 size_t tracking_set_size() const { return hi_.tracking_set_.size(); }
45 45
46 HeaderIndexing::HeaderSet* indexing_set() { return &(hi_.indexing_set_); } 46 HeaderIndexing::HeaderSet* indexing_set() { return &(hi_.indexing_set_); }
47 47
48 HeaderIndexing::HeaderSet* tracking_set() { return &(hi_.tracking_set_); } 48 HeaderIndexing::HeaderSet* tracking_set() { return &(hi_.tracking_set_); }
(...skipping 11 matching lines...) Expand all
60 hi_->CreateTestInit(); 60 hi_->CreateTestInit();
61 } 61 }
62 void SetUp() override { 62 void SetUp() override {
63 EXPECT_EQ(3u, hi_->indexing_set_size()); 63 EXPECT_EQ(3u, hi_->indexing_set_size());
64 EXPECT_EQ(3u, hi_->tracking_set_size()); 64 EXPECT_EQ(3u, hi_->tracking_set_size());
65 } 65 }
66 std::unique_ptr<HeaderIndexingPeer> hi_; 66 std::unique_ptr<HeaderIndexingPeer> hi_;
67 }; 67 };
68 68
69 TEST_F(SpdyHeaderIndexingTest, TestTryInsertHeader) { 69 TEST_F(SpdyHeaderIndexingTest, TestTryInsertHeader) {
70 std::string key("key4"); 70 SpdyString key("key4");
71 hi_->TryInsert(std::move(key)); 71 hi_->TryInsert(std::move(key));
72 EXPECT_EQ(3u, hi_->indexing_set_size()); 72 EXPECT_EQ(3u, hi_->indexing_set_size());
73 EXPECT_TRUE(hi_->ShouldIndex("key4")); 73 EXPECT_TRUE(hi_->ShouldIndex("key4"));
74 } 74 }
75 75
76 TEST_F(SpdyHeaderIndexingTest, TestShouldIndex) { 76 TEST_F(SpdyHeaderIndexingTest, TestShouldIndex) {
77 std::string key3 = "key3"; 77 SpdyString key3 = "key3";
78 std::string key4 = "key4"; 78 SpdyString key4 = "key4";
79 std::string key5 = "key5"; 79 SpdyString key5 = "key5";
80 // Cache hit. 80 // Cache hit.
81 EXPECT_TRUE(hi_->ShouldIndex(key3)); 81 EXPECT_TRUE(hi_->ShouldIndex(key3));
82 EXPECT_EQ(3u, hi_->indexing_set_size()); 82 EXPECT_EQ(3u, hi_->indexing_set_size());
83 EXPECT_EQ(3u, hi_->tracking_set_size()); 83 EXPECT_EQ(3u, hi_->tracking_set_size());
84 84
85 // Cache miss. Add to tracking set. 85 // Cache miss. Add to tracking set.
86 EXPECT_FALSE(hi_->ShouldIndex(key4)); 86 EXPECT_FALSE(hi_->ShouldIndex(key4));
87 EXPECT_EQ(3u, hi_->indexing_set_size()); 87 EXPECT_EQ(3u, hi_->indexing_set_size());
88 EXPECT_EQ(4u, hi_->tracking_set_size()); 88 EXPECT_EQ(4u, hi_->tracking_set_size());
89 EXPECT_TRUE(hi_->InTrackingSet(key4)); 89 EXPECT_TRUE(hi_->InTrackingSet(key4));
(...skipping 25 matching lines...) Expand all
115 EXPECT_EQ(100u, hi_->tracking_set_size()); 115 EXPECT_EQ(100u, hi_->tracking_set_size());
116 EXPECT_TRUE(hi_->ShouldIndex(":status")); 116 EXPECT_TRUE(hi_->ShouldIndex(":status"));
117 EXPECT_TRUE(hi_->InTrackingSet(":status")); 117 EXPECT_TRUE(hi_->InTrackingSet(":status"));
118 EXPECT_FALSE(hi_->InTrackingSet("NotValid")); 118 EXPECT_FALSE(hi_->InTrackingSet("NotValid"));
119 EXPECT_FALSE(hi_->ShouldIndex("NotValid")); 119 EXPECT_FALSE(hi_->ShouldIndex("NotValid"));
120 } 120 }
121 121
122 } // namespace test 122 } // namespace test
123 123
124 } // namespace net 124 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_header_indexing.cc ('k') | net/spdy/spdy_http_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698