Telemetry: Add a script to check and enable reading MSRs on Linux.
[chromium-blink-merge.git] / net / spdy / write_blocked_list_test.cc
blob20a1b7e43d009710852a12604b595f6869714e7c
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::Test {
27 public:
28 IntWriteBlockedList list;
31 TEST_F(WriteBlockedListTest, GetHighestPriority) {
32 EXPECT_FALSE(list.HasWriteBlockedStreams());
33 list.PushBack(1, 1);
34 EXPECT_TRUE(list.HasWriteBlockedStreams());
35 EXPECT_EQ(1, list.GetHighestPriorityWriteBlockedList());
36 list.PushBack(1, 0);
37 EXPECT_TRUE(list.HasWriteBlockedStreams());
38 EXPECT_EQ(0, list.GetHighestPriorityWriteBlockedList());
41 TEST_F(WriteBlockedListTest, HasWriteBlockedStreamsOfGreaterThanPriority) {
42 list.PushBack(1, 4);
43 EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(5));
44 EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(4));
45 list.PushBack(2, 2);
46 EXPECT_TRUE(list.HasWriteBlockedStreamsGreaterThanPriority(3));
47 EXPECT_FALSE(list.HasWriteBlockedStreamsGreaterThanPriority(2));
50 TEST_F(WriteBlockedListTest, RemoveStreamFromWriteBlockedList) {
51 list.PushBack(1, 4);
52 EXPECT_TRUE(list.HasWriteBlockedStreams());
54 list.RemoveStreamFromWriteBlockedList(1, 5);
55 EXPECT_TRUE(list.HasWriteBlockedStreams());
57 list.PushBack(2, 4);
58 list.PushBack(1, 4);
59 list.RemoveStreamFromWriteBlockedList(1, 4);
60 list.RemoveStreamFromWriteBlockedList(2, 4);
61 EXPECT_FALSE(list.HasWriteBlockedStreams());
63 list.PushBack(1, 7);
64 EXPECT_TRUE(list.HasWriteBlockedStreams());
67 TEST_F(WriteBlockedListTest, PopFront) {
68 list.PushBack(1, 4);
69 EXPECT_EQ(1u, list.NumBlockedStreams());
70 list.PushBack(2, 4);
71 list.PushBack(1, 4);
72 list.PushBack(3, 4);
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) {
82 list.PushBack(1, 1);
83 list.PushBack(2, 2);
84 list.PushBack(3, 3);
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());
99 // Redundant update.
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());
115 } // namespace
117 } // namespace test
118 } // namespace net