| OLD | NEW |
| 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_header_table.h" | 5 #include "net/spdy/hpack/hpack_header_table.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "net/spdy/hpack/hpack_constants.h" | 13 #include "net/spdy/hpack/hpack_constants.h" |
| 14 #include "net/spdy/hpack/hpack_entry.h" | 14 #include "net/spdy/hpack/hpack_entry.h" |
| 15 #include "net/spdy/spdy_flags.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 { |
| 18 | 19 |
| 19 using base::StringPiece; | 20 using base::StringPiece; |
| 20 using std::distance; | 21 using std::distance; |
| 21 using std::string; | 22 using std::string; |
| 22 | 23 |
| 23 namespace test { | 24 namespace test { |
| 24 | 25 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 EXPECT_EQ(entry2, | 252 EXPECT_EQ(entry2, |
| 252 table_.GetByNameAndValue(first_static_entry->name(), "Value Four")); | 253 table_.GetByNameAndValue(first_static_entry->name(), "Value Four")); |
| 253 | 254 |
| 254 // Evict |entry2|. Queries by its name & value are not found. | 255 // Evict |entry2|. Queries by its name & value are not found. |
| 255 peer_.Evict(1); | 256 peer_.Evict(1); |
| 256 EXPECT_EQ(NULL, | 257 EXPECT_EQ(NULL, |
| 257 table_.GetByNameAndValue(first_static_entry->name(), "Value Four")); | 258 table_.GetByNameAndValue(first_static_entry->name(), "Value Four")); |
| 258 } | 259 } |
| 259 | 260 |
| 260 TEST_F(HpackHeaderTableTest, SetSizes) { | 261 TEST_F(HpackHeaderTableTest, SetSizes) { |
| 262 FLAGS_chromium_reloadable_flag_increase_hpack_table_size = true; |
| 261 string key = "key", value = "value"; | 263 string key = "key", value = "value"; |
| 262 const HpackEntry* entry1 = table_.TryAddEntry(key, value); | 264 const HpackEntry* entry1 = table_.TryAddEntry(key, value); |
| 263 const HpackEntry* entry2 = table_.TryAddEntry(key, value); | 265 const HpackEntry* entry2 = table_.TryAddEntry(key, value); |
| 266 const HpackEntry* entry3 = table_.TryAddEntry(key, value); |
| 267 |
| 268 // Set exactly large enough. No Evictions. |
| 269 size_t max_size = entry1->Size() + entry2->Size() + entry3->Size(); |
| 270 table_.SetMaxSize(max_size); |
| 271 EXPECT_EQ(3u, peer_.dynamic_entries().size()); |
| 272 |
| 273 // Set just too small. One eviction. |
| 274 max_size = entry1->Size() + entry2->Size() + entry3->Size() - 1; |
| 275 table_.SetMaxSize(max_size); |
| 276 EXPECT_EQ(2u, peer_.dynamic_entries().size()); |
| 277 |
| 278 // Changing SETTINGS_HEADER_TABLE_SIZE. |
| 279 EXPECT_EQ(kDefaultHeaderTableSizeSetting, table_.settings_size_bound()); |
| 280 // In production, the size passed to SetSettingsHeaderTableSize is never |
| 281 // larger than table_.settings_size_bound(). |
| 282 table_.SetSettingsHeaderTableSize(kDefaultHeaderTableSizeSetting * 3 + 1); |
| 283 EXPECT_EQ(kDefaultHeaderTableSizeSetting * 3 + 1, table_.max_size()); |
| 284 |
| 285 // SETTINGS_HEADER_TABLE_SIZE upper-bounds |table_.max_size()|, |
| 286 // and will force evictions. |
| 287 max_size = entry3->Size() - 1; |
| 288 table_.SetSettingsHeaderTableSize(max_size); |
| 289 EXPECT_EQ(max_size, table_.max_size()); |
| 290 EXPECT_EQ(max_size, table_.settings_size_bound()); |
| 291 EXPECT_EQ(0u, peer_.dynamic_entries().size()); |
| 292 } |
| 293 |
| 294 TEST_F(HpackHeaderTableTest, SetSizesOld) { |
| 295 FLAGS_chromium_reloadable_flag_increase_hpack_table_size = false; |
| 296 |
| 297 string key = "key", value = "value"; |
| 298 const HpackEntry* entry1 = table_.TryAddEntry(key, value); |
| 299 const HpackEntry* entry2 = table_.TryAddEntry(key, value); |
| 264 const HpackEntry* entry3 = table_.TryAddEntry(key, value); | 300 const HpackEntry* entry3 = table_.TryAddEntry(key, value); |
| 265 | 301 |
| 266 // Set exactly large enough. No Evictions. | 302 // Set exactly large enough. No Evictions. |
| 267 size_t max_size = entry1->Size() + entry2->Size() + entry3->Size(); | 303 size_t max_size = entry1->Size() + entry2->Size() + entry3->Size(); |
| 268 table_.SetMaxSize(max_size); | 304 table_.SetMaxSize(max_size); |
| 269 EXPECT_EQ(3u, peer_.dynamic_entries().size()); | 305 EXPECT_EQ(3u, peer_.dynamic_entries().size()); |
| 270 | 306 |
| 271 // Set just too small. One eviction. | 307 // Set just too small. One eviction. |
| 272 max_size = entry1->Size() + entry2->Size() + entry3->Size() - 1; | 308 max_size = entry1->Size() + entry2->Size() + entry3->Size() - 1; |
| 273 table_.SetMaxSize(max_size); | 309 table_.SetMaxSize(max_size); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 HpackHeaderTable::EntryHasher hasher; | 477 HpackHeaderTable::EntryHasher hasher; |
| 442 EXPECT_EQ(hasher(&entry1), hasher(&entry2)); | 478 EXPECT_EQ(hasher(&entry1), hasher(&entry2)); |
| 443 | 479 |
| 444 HpackHeaderTable::EntriesEq eq; | 480 HpackHeaderTable::EntriesEq eq; |
| 445 EXPECT_TRUE(eq(&entry1, &entry2)); | 481 EXPECT_TRUE(eq(&entry1, &entry2)); |
| 446 } | 482 } |
| 447 | 483 |
| 448 } // namespace | 484 } // namespace |
| 449 | 485 |
| 450 } // namespace net | 486 } // namespace net |
| OLD | NEW |