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.
4
5#include "net/spdy/write_blocked_list.h"
6
7#include "testing/gtest/include/gtest/gtest.h"
8
9
10namespace net {
11namespace test {
12namespace {
13
14typedef WriteBlockedList<int> IntWriteBlockedList;
15
16TEST(WriteBlockedListTest, GetHighestPriority) {
17  IntWriteBlockedList list;
18  EXPECT_FALSE(list.HasWriteBlockedStreams());
19  list.PushBack(1, 1);
20  EXPECT_TRUE(list.HasWriteBlockedStreams());
21  EXPECT_EQ(1, list.GetHighestPriorityWriteBlockedList());
22  list.PushBack(1, 0);
23  EXPECT_TRUE(list.HasWriteBlockedStreams());
24  EXPECT_EQ(0, list.GetHighestPriorityWriteBlockedList());
25}
26
27TEST(WriteBlockedListTest, HasWriteBlockedStreamsOfGreaterThanPriority) {
28  IntWriteBlockedList list;
29  list.PushBack(1, 4);
30  EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(5));
31  EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(4));
32  list.PushBack(1, 2);
33  EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(3));
34  EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(2));
35}
36
37TEST(WriteBlockedListTest, RemoveStreamFromWriteBlockedList) {
38  IntWriteBlockedList list;
39
40  list.PushBack(1, 4);
41  EXPECT_TRUE(list.HasWriteBlockedStreams());
42
43  list.RemoveStreamFromWriteBlockedList(1, 5);
44  EXPECT_TRUE(list.HasWriteBlockedStreams());
45
46  list.PushBack(2, 4);
47  list.PushBack(1, 4);
48  list.RemoveStreamFromWriteBlockedList(1, 4);
49  list.RemoveStreamFromWriteBlockedList(2, 4);
50  EXPECT_FALSE(list.HasWriteBlockedStreams());
51
52  list.PushBack(1, 7);
53  EXPECT_TRUE(list.HasWriteBlockedStreams());
54}
55
56TEST(WriteBlockedListTest, PopFront) {
57  IntWriteBlockedList list;
58
59  list.PushBack(1, 4);
60  EXPECT_EQ(1u, list.NumBlockedStreams());
61  list.PushBack(2, 4);
62  list.PushBack(1, 4);
63  list.PushBack(3, 4);
64  EXPECT_EQ(4u, list.NumBlockedStreams());
65
66  EXPECT_EQ(1, list.PopFront(4));
67  EXPECT_EQ(2, list.PopFront(4));
68  EXPECT_EQ(1, list.PopFront(4));
69  EXPECT_EQ(1u, list.NumBlockedStreams());
70  EXPECT_EQ(3, list.PopFront(4));
71}
72
73}  // namespace
74}  // namespace test
75}  // namespace net
76