Sort unlaunched apps on app list start page by apps grid order.
[chromium-blink-merge.git] / net / spdy / write_blocked_list_test.cc
blobedb309e818b1b82d385bebcd046049821436bb43
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 {
13 class WriteBlockedListPeer {
14 public:
15 static std::deque<int>* GetWriteBlockedList(
16 int i,
17 net::WriteBlockedList<int>* list) {
18 return &list->write_blocked_lists_[i];
22 } // namespace
24 namespace net {
25 namespace test {
26 namespace {
27 typedef WriteBlockedList<int> IntWriteBlockedList;
29 TEST(WriteBlockedListTest, GetHighestPriority) {
30 IntWriteBlockedList list;
31 EXPECT_FALSE(list.HasWriteBlockedStreams());
32 list.PushBack(1, 1);
33 EXPECT_TRUE(list.HasWriteBlockedStreams());
34 EXPECT_EQ(1, list.GetHighestPriorityWriteBlockedList());
35 list.PushBack(1, 0);
36 EXPECT_TRUE(list.HasWriteBlockedStreams());
37 EXPECT_EQ(0, list.GetHighestPriorityWriteBlockedList());
40 TEST(WriteBlockedListTest, HasWriteBlockedStreamsOfGreaterThanPriority) {
41 IntWriteBlockedList list;
42 list.PushBack(1, 4);
43 EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(5));
44 EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(4));
45 list.PushBack(1, 2);
46 EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(3));
47 EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(2));
50 TEST(WriteBlockedListTest, RemoveStreamFromWriteBlockedList) {
51 IntWriteBlockedList list;
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(WriteBlockedListTest, PopFront) {
70 IntWriteBlockedList list;
72 list.PushBack(1, 4);
73 EXPECT_EQ(1u, list.NumBlockedStreams());
74 list.PushBack(2, 4);
75 list.PushBack(1, 4);
76 list.PushBack(3, 4);
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;
89 list.PushBack(1, 1);
90 list.PushBack(2, 2);
91 list.PushBack(3, 3);
92 list.PushBack(1, 3);
93 list.PushBack(1, 3);
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());
106 // Redundant update.
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());
128 } // namespace
129 } // namespace test
130 } // namespace net