Fix infinite recursion on hiding panel when created during fullscreen mode.
[chromium-blink-merge.git] / net / spdy / hpack_entry_test.cc
blob422190be52d9cd8767d9e2f9de007ed66f6228d3
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 const char kName[] = "headername";
18 const uint32 kNameStringLength = arraysize(kName) - 1;
19 const char kValue[] = "Header Value";
20 const uint32 kValueStringLength = arraysize(kValue) - 1;
22 // Make sure a default-constructed entry is still valid and starts off
23 // empty, unreferenced, and untouched.
24 TEST(HpackEntryTest, DefaultConstructor) {
25 HpackEntry entry;
26 EXPECT_TRUE(entry.name().empty());
27 EXPECT_TRUE(entry.value().empty());
28 EXPECT_FALSE(entry.IsReferenced());
29 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
30 EXPECT_EQ(HpackEntry::kSizeOverhead, entry.Size());
33 // Make sure a non-default-constructed HpackEntry starts off with
34 // copies of the given name and value, and unreferenced and untouched.
35 TEST(HpackEntryTest, NormalConstructor) {
36 string name = kName;
37 string value = kValue;
38 HpackEntry entry(name, value);
39 EXPECT_EQ(name, entry.name());
40 EXPECT_EQ(value, entry.value());
42 ++name[0];
43 ++value[0];
44 EXPECT_NE(name, entry.name());
45 EXPECT_NE(value, entry.name());
47 EXPECT_FALSE(entry.IsReferenced());
48 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
49 EXPECT_EQ(
50 kNameStringLength + kValueStringLength + HpackEntry::kSizeOverhead,
51 entry.Size());
54 // Make sure twiddling the referenced bit doesn't affect the touch
55 // count when it's kUntouched.
56 TEST(HpackEntryTest, IsReferencedUntouched) {
57 HpackEntry entry(kName, kValue);
58 EXPECT_FALSE(entry.IsReferenced());
59 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
61 entry.SetReferenced(true);
62 EXPECT_TRUE(entry.IsReferenced());
63 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
65 entry.SetReferenced(false);
66 EXPECT_FALSE(entry.IsReferenced());
67 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
70 // Make sure changing the touch count doesn't affect the referenced
71 // bit when it's false.
72 TEST(HpackEntryTest, TouchCountNotReferenced) {
73 HpackEntry entry(kName, kValue);
74 EXPECT_FALSE(entry.IsReferenced());
75 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
77 entry.AddTouches(0);
78 EXPECT_FALSE(entry.IsReferenced());
79 EXPECT_EQ(0u, entry.TouchCount());
81 entry.AddTouches(255);
82 EXPECT_FALSE(entry.IsReferenced());
83 EXPECT_EQ(255u, entry.TouchCount());
85 // Assumes kUntouched is 1 + max touch count.
86 entry.AddTouches(HpackEntry::kUntouched - 256);
87 EXPECT_FALSE(entry.IsReferenced());
88 EXPECT_EQ(HpackEntry::kUntouched - 1, entry.TouchCount());
90 entry.ClearTouches();
91 EXPECT_FALSE(entry.IsReferenced());
92 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
95 // Make sure changing the touch count doesn't affect the referenced
96 // bit when it's true.
97 TEST(HpackEntryTest, TouchCountReferenced) {
98 HpackEntry entry(kName, kValue);
99 entry.SetReferenced(true);
100 EXPECT_TRUE(entry.IsReferenced());
101 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
103 entry.AddTouches(0);
104 EXPECT_TRUE(entry.IsReferenced());
105 EXPECT_EQ(0u, entry.TouchCount());
107 entry.AddTouches(255);
108 EXPECT_TRUE(entry.IsReferenced());
109 EXPECT_EQ(255u, entry.TouchCount());
111 // Assumes kUntouched is 1 + max touch count.
112 entry.AddTouches(HpackEntry::kUntouched - 256);
113 EXPECT_TRUE(entry.IsReferenced());
114 EXPECT_EQ(HpackEntry::kUntouched - 1, entry.TouchCount());
116 entry.ClearTouches();
117 EXPECT_TRUE(entry.IsReferenced());
118 EXPECT_EQ(HpackEntry::kUntouched, entry.TouchCount());
121 // Make sure equality takes into account all entry fields.
122 TEST(HpackEntryTest, Equals) {
123 HpackEntry entry1(kName, kValue);
124 HpackEntry entry2(kName, kValue);
125 EXPECT_TRUE(entry1.Equals(entry2));
127 entry2.SetReferenced(true);
128 EXPECT_FALSE(entry1.Equals(entry2));
129 entry2.SetReferenced(false);
130 EXPECT_TRUE(entry1.Equals(entry2));
132 entry2.AddTouches(0);
133 EXPECT_FALSE(entry1.Equals(entry2));
134 entry2.ClearTouches();
135 EXPECT_TRUE(entry1.Equals(entry2));
137 entry2.AddTouches(1);
138 EXPECT_FALSE(entry1.Equals(entry2));
139 entry2.ClearTouches();
140 EXPECT_TRUE(entry1.Equals(entry2));
142 HpackEntry entry3(kName, string(kValue) + kValue);
143 EXPECT_FALSE(entry1.Equals(entry3));
145 HpackEntry entry4(string(kName) + kName, kValue);
146 EXPECT_FALSE(entry1.Equals(entry4));
149 } // namespace
151 } // namespace net