summaryrefslogtreecommitdiffstats
path: root/net/spdy/write_blocked_list_test.cc
blob: 20a1b7e43d009710852a12604b595f6869714e7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/spdy/write_blocked_list.h"

#include <deque>

#include "testing/gtest/include/gtest/gtest.h"

namespace net {
namespace test {

class WriteBlockedListPeer {
 public:
  static std::deque<int>* GetWriteBlockedList(int i,
                                              WriteBlockedList<int>* list) {
    return &list->write_blocked_lists_[i];
  }
};

namespace {

typedef WriteBlockedList<int> IntWriteBlockedList;

class WriteBlockedListTest : public ::testing::Test {
 public:
  IntWriteBlockedList list;
};

TEST_F(WriteBlockedListTest, GetHighestPriority) {
  EXPECT_FALSE(list.HasWriteBlockedStreams());
  list.PushBack(1, 1);
  EXPECT_TRUE(list.HasWriteBlockedStreams());
  EXPECT_EQ(1, list.GetHighestPriorityWriteBlockedList());
  list.PushBack(1, 0);
  EXPECT_TRUE(list.HasWriteBlockedStreams());
  EXPECT_EQ(0, list.GetHighestPriorityWriteBlockedList());
}

TEST_F(WriteBlockedListTest, HasWriteBlockedStreamsOfGreaterThanPriority) {
  list.PushBack(1, 4);
  EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(5));
  EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(4));
  list.PushBack(2, 2);
  EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(3));
  EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(2));
}

TEST_F(WriteBlockedListTest, RemoveStreamFromWriteBlockedList) {
  list.PushBack(1, 4);
  EXPECT_TRUE(list.HasWriteBlockedStreams());

  list.RemoveStreamFromWriteBlockedList(1, 5);
  EXPECT_TRUE(list.HasWriteBlockedStreams());

  list.PushBack(2, 4);
  list.PushBack(1, 4);
  list.RemoveStreamFromWriteBlockedList(1, 4);
  list.RemoveStreamFromWriteBlockedList(2, 4);
  EXPECT_FALSE(list.HasWriteBlockedStreams());

  list.PushBack(1, 7);
  EXPECT_TRUE(list.HasWriteBlockedStreams());
}

TEST_F(WriteBlockedListTest, PopFront) {
  list.PushBack(1, 4);
  EXPECT_EQ(1u, list.NumBlockedStreams());
  list.PushBack(2, 4);
  list.PushBack(1, 4);
  list.PushBack(3, 4);
  EXPECT_EQ(3u, list.NumBlockedStreams());

  EXPECT_EQ(1, list.PopFront(4));
  EXPECT_EQ(2, list.PopFront(4));
  EXPECT_EQ(1u, list.NumBlockedStreams());
  EXPECT_EQ(3, list.PopFront(4));
}

TEST_F(WriteBlockedListTest, UpdateStreamPriorityInWriteBlockedList) {
  list.PushBack(1, 1);
  list.PushBack(2, 2);
  list.PushBack(3, 3);
  list.PushBack(1, 3);  // Re-prioritizes stream 1 at priority 3.
  list.PushBack(1, 3);  // No effect.
  EXPECT_EQ(3u, list.NumBlockedStreams());
  EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
  EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
  EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());

  list.UpdateStreamPriorityInWriteBlockedList(1, 3, 2);
  EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
  EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
  list.UpdateStreamPriorityInWriteBlockedList(3, 3, 1);
  EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
  EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(3, &list)->size());

  // Redundant update.
  list.UpdateStreamPriorityInWriteBlockedList(1, 2, 2);
  EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());

  // No entries for given stream_id / old_priority pair.
  list.UpdateStreamPriorityInWriteBlockedList(4, 4, 1);
  EXPECT_EQ(1u, WriteBlockedListPeer::GetWriteBlockedList(1, &list)->size());
  EXPECT_EQ(2u, WriteBlockedListPeer::GetWriteBlockedList(2, &list)->size());
  EXPECT_EQ(0u, WriteBlockedListPeer::GetWriteBlockedList(4, &list)->size());

  EXPECT_EQ(3, list.PopFront(1));
  EXPECT_EQ(2, list.PopFront(2));
  EXPECT_EQ(1, list.PopFront(2));
  EXPECT_EQ(0u, list.NumBlockedStreams());
}

}  // namespace

}  // namespace test
}  // namespace net