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"
9 #include "testing/gtest/include/gtest/gtest.h"
13 class WriteBlockedListPeer
{
15 static std::deque
<int>* GetWriteBlockedList(
17 net::WriteBlockedList
<int>* list
) {
18 return &list
->write_blocked_lists_
[i
];
27 typedef WriteBlockedList
<int> IntWriteBlockedList
;
29 class WriteBlockedListTest
: public ::testing::TestWithParam
<bool> {
31 WriteBlockedListTest() : list(GetParam()) {}
33 IntWriteBlockedList list
;
36 TEST_P(WriteBlockedListTest
, GetHighestPriority
) {
37 EXPECT_FALSE(list
.HasWriteBlockedStreams());
39 EXPECT_TRUE(list
.HasWriteBlockedStreams());
40 EXPECT_EQ(1, list
.GetHighestPriorityWriteBlockedList());
42 EXPECT_TRUE(list
.HasWriteBlockedStreams());
43 EXPECT_EQ(0, list
.GetHighestPriorityWriteBlockedList());
46 TEST_P(WriteBlockedListTest
, HasWriteBlockedStreamsOfGreaterThanPriority
) {
48 EXPECT_TRUE(list
.HasWriteBlockedStreamsGreaterThanPriority(5));
49 EXPECT_FALSE(list
.HasWriteBlockedStreamsGreaterThanPriority(4));
51 EXPECT_TRUE(list
.HasWriteBlockedStreamsGreaterThanPriority(3));
52 EXPECT_FALSE(list
.HasWriteBlockedStreamsGreaterThanPriority(2));
55 TEST_P(WriteBlockedListTest
, RemoveStreamFromWriteBlockedList
) {
57 EXPECT_TRUE(list
.HasWriteBlockedStreams());
59 list
.RemoveStreamFromWriteBlockedList(1, 5);
60 EXPECT_TRUE(list
.HasWriteBlockedStreams());
64 list
.RemoveStreamFromWriteBlockedList(1, 4);
65 list
.RemoveStreamFromWriteBlockedList(2, 4);
66 EXPECT_FALSE(list
.HasWriteBlockedStreams());
69 EXPECT_TRUE(list
.HasWriteBlockedStreams());
72 TEST_P(WriteBlockedListTest
, PopFront
) {
74 EXPECT_EQ(1u, list
.NumBlockedStreams());
79 EXPECT_EQ(3u, list
.NumBlockedStreams());
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));
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
) {
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());
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());
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());
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());