Sort unlaunched apps on app list start page by apps grid order.
[chromium-blink-merge.git] / net / spdy / hpack_entry_test.cc
blob0a9a0a251c6eb03eb9831e78b5840f5f09a660b5
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
3 // found in the LICENSE file.
5 #include "net/spdy/hpack_entry.h"
7 #include <string>
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace net {
13 namespace {
15 using std::string;
17 class HpackEntryTest : public ::testing::Test {
18 protected:
19 HpackEntryTest()
20 : name_("header-name"),
21 value_("header value"),
22 total_insertions_(0),
23 table_size_(0) {}
25 // These builders maintain the same external table invariants that a "real"
26 // table (ie HpackHeaderTable) would.
27 HpackEntry StaticEntry() {
28 return HpackEntry(name_, value_, true, total_insertions_++);
30 HpackEntry DynamicEntry() {
31 ++table_size_;
32 size_t index = total_insertions_++;
33 return HpackEntry(name_, value_, false, index);
35 void DropEntry() { --table_size_; }
37 size_t IndexOf(const HpackEntry& entry) const {
38 if (entry.IsStatic()) {
39 return 1 + entry.InsertionIndex() + table_size_;
40 } else {
41 return total_insertions_ - entry.InsertionIndex();
45 size_t Size() {
46 return name_.size() + value_.size() + HpackEntry::kSizeOverhead;
49 string name_, value_;
51 private:
52 // Referenced by HpackEntry instances.
53 size_t total_insertions_;
54 size_t table_size_;
57 TEST_F(HpackEntryTest, StaticConstructor) {
58 HpackEntry entry(StaticEntry());
60 EXPECT_EQ(name_, entry.name());
61 EXPECT_EQ(value_, entry.value());
62 EXPECT_TRUE(entry.IsStatic());
63 EXPECT_EQ(1u, IndexOf(entry));
64 EXPECT_EQ(Size(), entry.Size());
67 TEST_F(HpackEntryTest, DynamicConstructor) {
68 HpackEntry entry(DynamicEntry());
70 EXPECT_EQ(name_, entry.name());
71 EXPECT_EQ(value_, entry.value());
72 EXPECT_FALSE(entry.IsStatic());
73 EXPECT_EQ(1u, IndexOf(entry));
74 EXPECT_EQ(Size(), entry.Size());
77 TEST_F(HpackEntryTest, LookupConstructor) {
78 HpackEntry entry(name_, value_);
80 EXPECT_EQ(name_, entry.name());
81 EXPECT_EQ(value_, entry.value());
82 EXPECT_FALSE(entry.IsStatic());
83 EXPECT_EQ(0u, IndexOf(entry));
84 EXPECT_EQ(Size(), entry.Size());
87 TEST_F(HpackEntryTest, DefaultConstructor) {
88 HpackEntry entry;
90 EXPECT_TRUE(entry.name().empty());
91 EXPECT_TRUE(entry.value().empty());
92 EXPECT_EQ(HpackEntry::kSizeOverhead, entry.Size());
95 TEST_F(HpackEntryTest, IndexUpdate) {
96 HpackEntry static1(StaticEntry());
97 HpackEntry static2(StaticEntry());
99 EXPECT_EQ(1u, IndexOf(static1));
100 EXPECT_EQ(2u, IndexOf(static2));
102 HpackEntry dynamic1(DynamicEntry());
103 HpackEntry dynamic2(DynamicEntry());
105 EXPECT_EQ(1u, IndexOf(dynamic2));
106 EXPECT_EQ(2u, IndexOf(dynamic1));
107 EXPECT_EQ(3u, IndexOf(static1));
108 EXPECT_EQ(4u, IndexOf(static2));
110 DropEntry(); // Drops |dynamic1|.
112 EXPECT_EQ(1u, IndexOf(dynamic2));
113 EXPECT_EQ(2u, IndexOf(static1));
114 EXPECT_EQ(3u, IndexOf(static2));
116 HpackEntry dynamic3(DynamicEntry());
118 EXPECT_EQ(1u, IndexOf(dynamic3));
119 EXPECT_EQ(2u, IndexOf(dynamic2));
120 EXPECT_EQ(3u, IndexOf(static1));
121 EXPECT_EQ(4u, IndexOf(static2));
124 } // namespace
126 } // namespace net