1 // Copyright 2014 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/quic/quic_write_blocked_list.h"
7 #include "testing/gtest/include/gtest/gtest.h"
13 TEST(QuicWriteBlockedListTest
, PriorityOrder
) {
14 QuicWriteBlockedList write_blocked_list
;
16 // Mark streams blocked in roughly reverse priority order, and
17 // verify that streams are sorted.
18 write_blocked_list
.PushBack(40,
19 QuicWriteBlockedList::kLowestPriority
);
20 write_blocked_list
.PushBack(23,
21 QuicWriteBlockedList::kHighestPriority
);
22 write_blocked_list
.PushBack(17,
23 QuicWriteBlockedList::kHighestPriority
);
24 write_blocked_list
.PushBack(kHeadersStreamId
,
25 QuicWriteBlockedList::kHighestPriority
);
26 write_blocked_list
.PushBack(kCryptoStreamId
,
27 QuicWriteBlockedList::kHighestPriority
);
29 EXPECT_EQ(5u, write_blocked_list
.NumBlockedStreams());
30 EXPECT_TRUE(write_blocked_list
.HasWriteBlockedStreams());
31 // The Crypto stream is highest priority.
32 EXPECT_EQ(kCryptoStreamId
, write_blocked_list
.PopFront());
33 // Followed by the Headers stream.
34 EXPECT_EQ(kHeadersStreamId
, write_blocked_list
.PopFront());
35 // Streams with same priority are popped in the order they were inserted.
36 EXPECT_EQ(23u, write_blocked_list
.PopFront());
37 EXPECT_EQ(17u, write_blocked_list
.PopFront());
38 // Low priority stream appears last.
39 EXPECT_EQ(40u, write_blocked_list
.PopFront());
41 EXPECT_EQ(0u, write_blocked_list
.NumBlockedStreams());
42 EXPECT_FALSE(write_blocked_list
.HasWriteBlockedStreams());
45 TEST(QuicWriteBlockedListTest
, CryptoStream
) {
46 QuicWriteBlockedList write_blocked_list
;
47 write_blocked_list
.PushBack(kCryptoStreamId
,
48 QuicWriteBlockedList::kHighestPriority
);
50 EXPECT_EQ(1u, write_blocked_list
.NumBlockedStreams());
51 EXPECT_TRUE(write_blocked_list
.HasWriteBlockedStreams());
52 EXPECT_EQ(kCryptoStreamId
, write_blocked_list
.PopFront());
53 EXPECT_EQ(0u, write_blocked_list
.NumBlockedStreams());
54 EXPECT_FALSE(write_blocked_list
.HasWriteBlockedStreams());
57 TEST(QuicWriteBlockedListTest
, HeadersStream
) {
58 QuicWriteBlockedList write_blocked_list
;
59 write_blocked_list
.PushBack(kHeadersStreamId
,
60 QuicWriteBlockedList::kHighestPriority
);
62 EXPECT_EQ(1u, write_blocked_list
.NumBlockedStreams());
63 EXPECT_TRUE(write_blocked_list
.HasWriteBlockedStreams());
64 EXPECT_EQ(kHeadersStreamId
, write_blocked_list
.PopFront());
65 EXPECT_EQ(0u, write_blocked_list
.NumBlockedStreams());
66 EXPECT_FALSE(write_blocked_list
.HasWriteBlockedStreams());
69 TEST(QuicWriteBlockedListTest
, VerifyHeadersStream
) {
70 QuicWriteBlockedList write_blocked_list
;
71 write_blocked_list
.PushBack(5,
72 QuicWriteBlockedList::kHighestPriority
);
73 write_blocked_list
.PushBack(kHeadersStreamId
,
74 QuicWriteBlockedList::kHighestPriority
);
76 EXPECT_EQ(2u, write_blocked_list
.NumBlockedStreams());
77 EXPECT_TRUE(write_blocked_list
.HasWriteBlockedStreams());
78 // In newer QUIC versions, there is a headers stream which is
79 // higher priority than data streams.
80 EXPECT_EQ(kHeadersStreamId
, write_blocked_list
.PopFront());
81 EXPECT_EQ(5u, write_blocked_list
.PopFront());
82 EXPECT_EQ(0u, write_blocked_list
.NumBlockedStreams());
83 EXPECT_FALSE(write_blocked_list
.HasWriteBlockedStreams());