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 TEST(WriteBlockedListTest
, GetHighestPriority
) {
30 IntWriteBlockedList list
;
31 EXPECT_FALSE(list
.HasWriteBlockedStreams());
33 EXPECT_TRUE(list
.HasWriteBlockedStreams());
34 EXPECT_EQ(1, list
.GetHighestPriorityWriteBlockedList());
36 EXPECT_TRUE(list
.HasWriteBlockedStreams());
37 EXPECT_EQ(0, list
.GetHighestPriorityWriteBlockedList());
40 TEST(WriteBlockedListTest
, HasWriteBlockedStreamsOfGreaterThanPriority
) {
41 IntWriteBlockedList list
;
43 EXPECT_TRUE(list
.HasWriteBlockedStreamsGreaterThanPriority(5));
44 EXPECT_FALSE(list
.HasWriteBlockedStreamsGreaterThanPriority(4));
46 EXPECT_TRUE(list
.HasWriteBlockedStreamsGreaterThanPriority(3));
47 EXPECT_FALSE(list
.HasWriteBlockedStreamsGreaterThanPriority(2));
50 TEST(WriteBlockedListTest
, RemoveStreamFromWriteBlockedList
) {
51 IntWriteBlockedList list
;
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(WriteBlockedListTest
, PopFront
) {
70 IntWriteBlockedList list
;
73 EXPECT_EQ(1u, list
.NumBlockedStreams());
77 EXPECT_EQ(4u, list
.NumBlockedStreams());
79 EXPECT_EQ(1, list
.PopFront(4));
80 EXPECT_EQ(2, list
.PopFront(4));
81 EXPECT_EQ(1, list
.PopFront(4));
82 EXPECT_EQ(1u, list
.NumBlockedStreams());
83 EXPECT_EQ(3, list
.PopFront(4));
86 TEST(WriteBlockedListTest
, UpdateStreamPriorityInWriteBlockedList
) {
87 IntWriteBlockedList list
;
94 EXPECT_EQ(5u, list
.NumBlockedStreams());
95 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
96 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(2, &list
)->size());
97 EXPECT_EQ(3u, WriteBlockedListPeer::GetWriteBlockedList(3, &list
)->size());
99 list
.UpdateStreamPriorityInWriteBlockedList(1, 1, 2);
100 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
101 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list
)->size());
102 list
.UpdateStreamPriorityInWriteBlockedList(3, 3, 1);
103 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
104 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(3, &list
)->size());
107 list
.UpdateStreamPriorityInWriteBlockedList(1, 3, 3);
108 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(3, &list
)->size());
110 // No entries for given stream_id / old_priority pair.
111 list
.UpdateStreamPriorityInWriteBlockedList(4, 4, 1);
112 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
113 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list
)->size());
114 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(4, &list
)->size());
116 // Update multiple entries.
117 list
.UpdateStreamPriorityInWriteBlockedList(1, 3, 4);
118 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(3, &list
)->size());
119 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(4, &list
)->size());
121 EXPECT_EQ(3, list
.PopFront(1));
122 EXPECT_EQ(2, list
.PopFront(2));
123 EXPECT_EQ(1, list
.PopFront(2));
124 EXPECT_EQ(1, list
.PopFront(4));
125 EXPECT_EQ(0u, list
.NumBlockedStreams());