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

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

Issue 1354773002: Avoid string construction overhead for lookup-only HpackEntry objects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit: return feels weird in a constructor. Created 5 years, 2 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.cc ('k') | net/spdy/hpack/hpack_entry.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 "net/spdy/hpack/hpack_encoder.h" 5 #include "net/spdy/hpack/hpack_encoder.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 const HpackEntry* cookie_a_; 154 const HpackEntry* cookie_a_;
155 const HpackEntry* cookie_c_; 155 const HpackEntry* cookie_c_;
156 156
157 HpackOutputStream expected_; 157 HpackOutputStream expected_;
158 }; 158 };
159 159
160 TEST_F(HpackEncoderTest, SingleDynamicIndex) { 160 TEST_F(HpackEncoderTest, SingleDynamicIndex) {
161 ExpectIndex(IndexOf(key_2_)); 161 ExpectIndex(IndexOf(key_2_));
162 162
163 SpdyHeaderBlock headers; 163 SpdyHeaderBlock headers;
164 headers[key_2_->name()] = key_2_->value(); 164 headers[key_2_->name().as_string()] = key_2_->value().as_string();
165 CompareWithExpectedEncoding(headers); 165 CompareWithExpectedEncoding(headers);
166 } 166 }
167 167
168 TEST_F(HpackEncoderTest, SingleStaticIndex) { 168 TEST_F(HpackEncoderTest, SingleStaticIndex) {
169 ExpectIndex(IndexOf(static_)); 169 ExpectIndex(IndexOf(static_));
170 170
171 SpdyHeaderBlock headers; 171 SpdyHeaderBlock headers;
172 headers[static_->name()] = static_->value(); 172 headers[static_->name().as_string()] = static_->value().as_string();
173 CompareWithExpectedEncoding(headers); 173 CompareWithExpectedEncoding(headers);
174 } 174 }
175 175
176 TEST_F(HpackEncoderTest, SingleStaticIndexTooLarge) { 176 TEST_F(HpackEncoderTest, SingleStaticIndexTooLarge) {
177 peer_.table()->SetMaxSize(1); // Also evicts all fixtures. 177 peer_.table()->SetMaxSize(1); // Also evicts all fixtures.
178 ExpectIndex(IndexOf(static_)); 178 ExpectIndex(IndexOf(static_));
179 179
180 SpdyHeaderBlock headers; 180 SpdyHeaderBlock headers;
181 headers[static_->name()] = static_->value(); 181 headers[static_->name().as_string()] = static_->value().as_string();
182 CompareWithExpectedEncoding(headers); 182 CompareWithExpectedEncoding(headers);
183 183
184 EXPECT_EQ(0u, peer_.table_peer().dynamic_entries()->size()); 184 EXPECT_EQ(0u, peer_.table_peer().dynamic_entries()->size());
185 } 185 }
186 186
187 TEST_F(HpackEncoderTest, SingleLiteralWithIndexName) { 187 TEST_F(HpackEncoderTest, SingleLiteralWithIndexName) {
188 ExpectIndexedLiteral(key_2_, "value3"); 188 ExpectIndexedLiteral(key_2_, "value3");
189 189
190 SpdyHeaderBlock headers; 190 SpdyHeaderBlock headers;
191 headers[key_2_->name()] = "value3"; 191 headers[key_2_->name().as_string()] = "value3";
192 CompareWithExpectedEncoding(headers); 192 CompareWithExpectedEncoding(headers);
193 193
194 // A new entry was inserted and added to the reference set. 194 // A new entry was inserted and added to the reference set.
195 HpackEntry* new_entry = &peer_.table_peer().dynamic_entries()->front(); 195 HpackEntry* new_entry = &peer_.table_peer().dynamic_entries()->front();
196 EXPECT_EQ(new_entry->name(), key_2_->name()); 196 EXPECT_EQ(new_entry->name(), key_2_->name());
197 EXPECT_EQ(new_entry->value(), "value3"); 197 EXPECT_EQ(new_entry->value(), "value3");
198 } 198 }
199 199
200 TEST_F(HpackEncoderTest, SingleLiteralWithLiteralName) { 200 TEST_F(HpackEncoderTest, SingleLiteralWithLiteralName) {
201 ExpectIndexedLiteral("key3", "value3"); 201 ExpectIndexedLiteral("key3", "value3");
(...skipping 21 matching lines...) Expand all
223 EXPECT_EQ(0u, peer_.table_peer().dynamic_entries()->size()); 223 EXPECT_EQ(0u, peer_.table_peer().dynamic_entries()->size());
224 } 224 }
225 225
226 TEST_F(HpackEncoderTest, EmitThanEvict) { 226 TEST_F(HpackEncoderTest, EmitThanEvict) {
227 // |key_1_| is toggled and placed into the reference set, 227 // |key_1_| is toggled and placed into the reference set,
228 // and then immediately evicted by "key3". 228 // and then immediately evicted by "key3".
229 ExpectIndex(IndexOf(key_1_)); 229 ExpectIndex(IndexOf(key_1_));
230 ExpectIndexedLiteral("key3", "value3"); 230 ExpectIndexedLiteral("key3", "value3");
231 231
232 SpdyHeaderBlock headers; 232 SpdyHeaderBlock headers;
233 headers[key_1_->name()] = key_1_->value(); 233 headers[key_1_->name().as_string()] = key_1_->value().as_string();
234 headers["key3"] = "value3"; 234 headers["key3"] = "value3";
235 CompareWithExpectedEncoding(headers); 235 CompareWithExpectedEncoding(headers);
236 } 236 }
237 237
238 TEST_F(HpackEncoderTest, CookieHeaderIsCrumbled) { 238 TEST_F(HpackEncoderTest, CookieHeaderIsCrumbled) {
239 ExpectIndex(IndexOf(cookie_a_)); 239 ExpectIndex(IndexOf(cookie_a_));
240 ExpectIndex(IndexOf(cookie_c_)); 240 ExpectIndex(IndexOf(cookie_c_));
241 ExpectIndexedLiteral(peer_.table()->GetByName("cookie"), "e=ff"); 241 ExpectIndexedLiteral(peer_.table()->GetByName("cookie"), "e=ff");
242 242
243 SpdyHeaderBlock headers; 243 SpdyHeaderBlock headers;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 expected_.AppendUint32(62); 456 expected_.AppendUint32(62);
457 expected_.AppendPrefix(kStringLiteralIdentityEncoded); 457 expected_.AppendPrefix(kStringLiteralIdentityEncoded);
458 expected_.AppendUint32(3); 458 expected_.AppendUint32(3);
459 expected_.AppendBytes("bar"); 459 expected_.AppendBytes("bar");
460 CompareWithExpectedEncoding(headers); 460 CompareWithExpectedEncoding(headers);
461 } 461 }
462 462
463 } // namespace 463 } // namespace
464 464
465 } // namespace net 465 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/hpack/hpack_decoder.cc ('k') | net/spdy/hpack/hpack_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698