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"
14 class WriteBlockedListPeer
{
16 static std::deque
<int>* GetWriteBlockedList(int i
,
17 WriteBlockedList
<int>* list
) {
18 return &list
->write_blocked_lists_
[i
];
24 typedef WriteBlockedList
<int> IntWriteBlockedList
;
26 class WriteBlockedListTest
: public ::testing::TestWithParam
<bool> {
28 WriteBlockedListTest() : list(GetParam()) {}
30 IntWriteBlockedList list
;
33 TEST_P(WriteBlockedListTest
, GetHighestPriority
) {
34 EXPECT_FALSE(list
.HasWriteBlockedStreams());
36 EXPECT_TRUE(list
.HasWriteBlockedStreams());
37 EXPECT_EQ(1, list
.GetHighestPriorityWriteBlockedList());
39 EXPECT_TRUE(list
.HasWriteBlockedStreams());
40 EXPECT_EQ(0, list
.GetHighestPriorityWriteBlockedList());
43 TEST_P(WriteBlockedListTest
, HasWriteBlockedStreamsOfGreaterThanPriority
) {
45 EXPECT_TRUE(list
.HasWriteBlockedStreamsGreaterThanPriority(5));
46 EXPECT_FALSE(list
.HasWriteBlockedStreamsGreaterThanPriority(4));
48 EXPECT_TRUE(list
.HasWriteBlockedStreamsGreaterThanPriority(3));
49 EXPECT_FALSE(list
.HasWriteBlockedStreamsGreaterThanPriority(2));
52 TEST_P(WriteBlockedListTest
, RemoveStreamFromWriteBlockedList
) {
54 EXPECT_TRUE(list
.HasWriteBlockedStreams());
56 list
.RemoveStreamFromWriteBlockedList(1, 5);
57 EXPECT_TRUE(list
.HasWriteBlockedStreams());
61 list
.RemoveStreamFromWriteBlockedList(1, 4);
62 list
.RemoveStreamFromWriteBlockedList(2, 4);
63 EXPECT_FALSE(list
.HasWriteBlockedStreams());
66 EXPECT_TRUE(list
.HasWriteBlockedStreams());
69 TEST_P(WriteBlockedListTest
, PopFront
) {
71 EXPECT_EQ(1u, list
.NumBlockedStreams());
76 EXPECT_EQ(3u, list
.NumBlockedStreams());
78 EXPECT_EQ(4u, list
.NumBlockedStreams());
81 EXPECT_EQ(1, list
.PopFront(4));
82 EXPECT_EQ(2, list
.PopFront(4));
83 EXPECT_EQ(1, list
.PopFront(4));
85 EXPECT_EQ(1, list
.PopFront(4));
87 EXPECT_EQ(1u, list
.NumBlockedStreams());
88 EXPECT_EQ(3, list
.PopFront(4));
91 TEST_P(WriteBlockedListTest
, UpdateStreamPriorityInWriteBlockedList
) {
96 list
.PushBack(1, 3); // Re-prioritizes stream 1 at priority 3.
97 list
.PushBack(1, 3); // No effect.
98 EXPECT_EQ(3u, list
.NumBlockedStreams());
99 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
100 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(2, &list
)->size());
101 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(3, &list
)->size());
103 list
.UpdateStreamPriorityInWriteBlockedList(1, 3, 2);
104 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
105 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list
)->size());
106 list
.UpdateStreamPriorityInWriteBlockedList(3, 3, 1);
107 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
108 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(3, &list
)->size());
111 list
.UpdateStreamPriorityInWriteBlockedList(1, 2, 2);
112 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list
)->size());
114 // No entries for given stream_id / old_priority pair.
115 list
.UpdateStreamPriorityInWriteBlockedList(4, 4, 1);
116 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
117 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list
)->size());
118 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(4, &list
)->size());
120 EXPECT_EQ(3, list
.PopFront(1));
121 EXPECT_EQ(2, list
.PopFront(2));
122 EXPECT_EQ(1, list
.PopFront(2));
123 EXPECT_EQ(0u, list
.NumBlockedStreams());
130 EXPECT_EQ(5u, list
.NumBlockedStreams());
131 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
132 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(2, &list
)->size());
133 EXPECT_EQ(3u, WriteBlockedListPeer::GetWriteBlockedList(3, &list
)->size());
135 list
.UpdateStreamPriorityInWriteBlockedList(1, 1, 2);
136 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
137 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list
)->size());
138 list
.UpdateStreamPriorityInWriteBlockedList(3, 3, 1);
139 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
140 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(3, &list
)->size());
143 list
.UpdateStreamPriorityInWriteBlockedList(1, 3, 3);
144 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(3, &list
)->size());
146 // No entries for given stream_id / old_priority pair.
147 list
.UpdateStreamPriorityInWriteBlockedList(4, 4, 1);
148 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
149 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list
)->size());
150 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(4, &list
)->size());
152 // Update multiple entries.
153 list
.UpdateStreamPriorityInWriteBlockedList(1, 3, 4);
154 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(3, &list
)->size());
155 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(4, &list
)->size());
157 EXPECT_EQ(3, list
.PopFront(1));
158 EXPECT_EQ(2, list
.PopFront(2));
159 EXPECT_EQ(1, list
.PopFront(2));
160 EXPECT_EQ(1, list
.PopFront(4));
161 EXPECT_EQ(0u, list
.NumBlockedStreams());