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::Test
{
28 IntWriteBlockedList list
;
31 TEST_F(WriteBlockedListTest
, GetHighestPriority
) {
32 EXPECT_FALSE(list
.HasWriteBlockedStreams());
34 EXPECT_TRUE(list
.HasWriteBlockedStreams());
35 EXPECT_EQ(1, list
.GetHighestPriorityWriteBlockedList());
37 EXPECT_TRUE(list
.HasWriteBlockedStreams());
38 EXPECT_EQ(0, list
.GetHighestPriorityWriteBlockedList());
41 TEST_F(WriteBlockedListTest
, HasWriteBlockedStreamsOfGreaterThanPriority
) {
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_F(WriteBlockedListTest
, RemoveStreamFromWriteBlockedList
) {
52 EXPECT_TRUE(list
.HasWriteBlockedStreams());
54 list
.RemoveStreamFromWriteBlockedList(1, 5);
55 EXPECT_TRUE(list
.HasWriteBlockedStreams());
59 list
.RemoveStreamFromWriteBlockedList(1, 4);
60 list
.RemoveStreamFromWriteBlockedList(2, 4);
61 EXPECT_FALSE(list
.HasWriteBlockedStreams());
64 EXPECT_TRUE(list
.HasWriteBlockedStreams());
67 TEST_F(WriteBlockedListTest
, PopFront
) {
69 EXPECT_EQ(1u, list
.NumBlockedStreams());
73 EXPECT_EQ(3u, list
.NumBlockedStreams());
75 EXPECT_EQ(1, list
.PopFront(4));
76 EXPECT_EQ(2, list
.PopFront(4));
77 EXPECT_EQ(1u, list
.NumBlockedStreams());
78 EXPECT_EQ(3, list
.PopFront(4));
81 TEST_F(WriteBlockedListTest
, UpdateStreamPriorityInWriteBlockedList
) {
85 list
.PushBack(1, 3); // Re-prioritizes stream 1 at priority 3.
86 list
.PushBack(1, 3); // No effect.
87 EXPECT_EQ(3u, list
.NumBlockedStreams());
88 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
89 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(2, &list
)->size());
90 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(3, &list
)->size());
92 list
.UpdateStreamPriorityInWriteBlockedList(1, 3, 2);
93 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
94 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list
)->size());
95 list
.UpdateStreamPriorityInWriteBlockedList(3, 3, 1);
96 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
97 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(3, &list
)->size());
100 list
.UpdateStreamPriorityInWriteBlockedList(1, 2, 2);
101 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list
)->size());
103 // No entries for given stream_id / old_priority pair.
104 list
.UpdateStreamPriorityInWriteBlockedList(4, 4, 1);
105 EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list
)->size());
106 EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list
)->size());
107 EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(4, &list
)->size());
109 EXPECT_EQ(3, list
.PopFront(1));
110 EXPECT_EQ(2, list
.PopFront(2));
111 EXPECT_EQ(1, list
.PopFront(2));
112 EXPECT_EQ(0u, list
.NumBlockedStreams());