Changed GPU Service traces to use nestable async traces.
[chromium-blink-merge.git] / net / spdy / write_blocked_list_test.cc
blob50c3f351cf9cf300806354ab79b67e993f1b805a
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"
7 #include <deque>
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace net {
12 namespace test {
14 class WriteBlockedListPeer {
15 public:
16 static std::deque<int>* GetWriteBlockedList(int i,
17 WriteBlockedList<int>* list) {
18 return &list->write_blocked_lists_[i];
22 namespace {
24 typedef WriteBlockedList<int> IntWriteBlockedList;
26 class WriteBlockedListTest : public ::testing::TestWithParam<bool> {
27 public:
28 WriteBlockedListTest() : list(GetParam()) {}
30 IntWriteBlockedList list;
33 TEST_P(WriteBlockedListTest, GetHighestPriority) {
34 EXPECT_FALSE(list.HasWriteBlockedStreams());
35 list.PushBack(1, 1);
36 EXPECT_TRUE(list.HasWriteBlockedStreams());
37 EXPECT_EQ(1, list.GetHighestPriorityWriteBlockedList());
38 list.PushBack(1, 0);
39 EXPECT_TRUE(list.HasWriteBlockedStreams());
40 EXPECT_EQ(0, list.GetHighestPriorityWriteBlockedList());
43 TEST_P(WriteBlockedListTest, HasWriteBlockedStreamsOfGreaterThanPriority) {
44 list.PushBack(1, 4);
45 EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(5));
46 EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(4));
47 list.PushBack(2, 2);
48 EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(3));
49 EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(2));
52 TEST_P(WriteBlockedListTest, RemoveStreamFromWriteBlockedList) {
53 list.PushBack(1, 4);
54 EXPECT_TRUE(list.HasWriteBlockedStreams());
56 list.RemoveStreamFromWriteBlockedList(1, 5);
57 EXPECT_TRUE(list.HasWriteBlockedStreams());
59 list.PushBack(2, 4);
60 list.PushBack(1, 4);
61 list.RemoveStreamFromWriteBlockedList(1, 4);
62 list.RemoveStreamFromWriteBlockedList(2, 4);
63 EXPECT_FALSE(list.HasWriteBlockedStreams());
65 list.PushBack(1, 7);
66 EXPECT_TRUE(list.HasWriteBlockedStreams());
69 TEST_P(WriteBlockedListTest, PopFront) {
70 list.PushBack(1, 4);
71 EXPECT_EQ(1u, list.NumBlockedStreams());
72 list.PushBack(2, 4);
73 list.PushBack(1, 4);
74 list.PushBack(3, 4);
75 if (GetParam()) {
76 EXPECT_EQ(3u, list.NumBlockedStreams());
77 } else {
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));
84 if (!GetParam()) {
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) {
92 if (GetParam()) {
93 list.PushBack(1, 1);
94 list.PushBack(2, 2);
95 list.PushBack(3, 3);
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());
110 // Redundant update.
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());
124 } else {
125 list.PushBack(1, 1);
126 list.PushBack(2, 2);
127 list.PushBack(3, 3);
128 list.PushBack(1, 3);
129 list.PushBack(1, 3);
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());
142 // Redundant update.
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());
165 } // namespace
167 } // namespace test
168 } // namespace net