Port Android relocation packer to chromium build
[chromium-blink-merge.git] / net / spdy / write_blocked_list_test.cc
blobef5ea5084182b949e65e313c19a619277ea93bef
1 // Copyright 2013 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/write_blocked_list.h"
7 #include <deque>
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace {
13 class WriteBlockedListPeer {
14 public:
15 static std::deque<int>* GetWriteBlockedList(
16 int i,
17 net::WriteBlockedList<int>* list) {
18 return &list->write_blocked_lists_[i];
22 } // namespace
24 namespace net {
25 namespace test {
26 namespace {
27 typedef WriteBlockedList<int> IntWriteBlockedList;
29 class WriteBlockedListTest : public ::testing::TestWithParam<bool> {
30 public:
31 WriteBlockedListTest() : list(GetParam()) {}
33 IntWriteBlockedList list;
36 TEST_P(WriteBlockedListTest, GetHighestPriority) {
37 EXPECT_FALSE(list.HasWriteBlockedStreams());
38 list.PushBack(1, 1);
39 EXPECT_TRUE(list.HasWriteBlockedStreams());
40 EXPECT_EQ(1, list.GetHighestPriorityWriteBlockedList());
41 list.PushBack(1, 0);
42 EXPECT_TRUE(list.HasWriteBlockedStreams());
43 EXPECT_EQ(0, list.GetHighestPriorityWriteBlockedList());
46 TEST_P(WriteBlockedListTest, HasWriteBlockedStreamsOfGreaterThanPriority) {
47 list.PushBack(1, 4);
48 EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(5));
49 EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(4));
50 list.PushBack(2, 2);
51 EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(3));
52 EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(2));
55 TEST_P(WriteBlockedListTest, RemoveStreamFromWriteBlockedList) {
56 list.PushBack(1, 4);
57 EXPECT_TRUE(list.HasWriteBlockedStreams());
59 list.RemoveStreamFromWriteBlockedList(1, 5);
60 EXPECT_TRUE(list.HasWriteBlockedStreams());
62 list.PushBack(2, 4);
63 list.PushBack(1, 4);
64 list.RemoveStreamFromWriteBlockedList(1, 4);
65 list.RemoveStreamFromWriteBlockedList(2, 4);
66 EXPECT_FALSE(list.HasWriteBlockedStreams());
68 list.PushBack(1, 7);
69 EXPECT_TRUE(list.HasWriteBlockedStreams());
72 TEST_P(WriteBlockedListTest, PopFront) {
73 list.PushBack(1, 4);
74 EXPECT_EQ(1u, list.NumBlockedStreams());
75 list.PushBack(2, 4);
76 list.PushBack(1, 4);
77 list.PushBack(3, 4);
78 if (GetParam()) {
79 EXPECT_EQ(3u, list.NumBlockedStreams());
80 } else {
81 EXPECT_EQ(4u, list.NumBlockedStreams());
84 EXPECT_EQ(1, list.PopFront(4));
85 EXPECT_EQ(2, list.PopFront(4));
86 EXPECT_EQ(1, list.PopFront(4));
87 if (!GetParam()) {
88 EXPECT_EQ(1, list.PopFront(4));
90 EXPECT_EQ(1u, list.NumBlockedStreams());
91 EXPECT_EQ(3, list.PopFront(4));
94 TEST_P(WriteBlockedListTest, UpdateStreamPriorityInWriteBlockedList) {
95 if (GetParam()) {
96 list.PushBack(1, 1);
97 list.PushBack(2, 2);
98 list.PushBack(3, 3);
99 list.PushBack(1, 3); // Re-prioritizes stream 1 at priority 3.
100 list.PushBack(1, 3); // No effect.
101 EXPECT_EQ(3u, list.NumBlockedStreams());
102 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
103 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
104 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());
106 list.UpdateStreamPriorityInWriteBlockedList(1, 3, 2);
107 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
108 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
109 list.UpdateStreamPriorityInWriteBlockedList(3, 3, 1);
110 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
111 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());
113 // Redundant update.
114 list.UpdateStreamPriorityInWriteBlockedList(1, 2, 2);
115 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
117 // No entries for given stream_id / old_priority pair.
118 list.UpdateStreamPriorityInWriteBlockedList(4, 4, 1);
119 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
120 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
121 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(4, &list)->size());
123 EXPECT_EQ(3, list.PopFront(1));
124 EXPECT_EQ(2, list.PopFront(2));
125 EXPECT_EQ(1, list.PopFront(2));
126 EXPECT_EQ(0u, list.NumBlockedStreams());
127 } else {
128 list.PushBack(1, 1);
129 list.PushBack(2, 2);
130 list.PushBack(3, 3);
131 list.PushBack(1, 3);
132 list.PushBack(1, 3);
133 EXPECT_EQ(5u, list.NumBlockedStreams());
134 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
135 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
136 EXPECT_EQ(3u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());
138 list.UpdateStreamPriorityInWriteBlockedList(1, 1, 2);
139 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
140 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
141 list.UpdateStreamPriorityInWriteBlockedList(3, 3, 1);
142 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
143 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());
145 // Redundant update.
146 list.UpdateStreamPriorityInWriteBlockedList(1, 3, 3);
147 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());
149 // No entries for given stream_id / old_priority pair.
150 list.UpdateStreamPriorityInWriteBlockedList(4, 4, 1);
151 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
152 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
153 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(4, &list)->size());
155 // Update multiple entries.
156 list.UpdateStreamPriorityInWriteBlockedList(1, 3, 4);
157 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());
158 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(4, &list)->size());
160 EXPECT_EQ(3, list.PopFront(1));
161 EXPECT_EQ(2, list.PopFront(2));
162 EXPECT_EQ(1, list.PopFront(2));
163 EXPECT_EQ(1, list.PopFront(4));
164 EXPECT_EQ(0u, list.NumBlockedStreams());
168 } // namespace
169 } // namespace test
170 } // namespace net