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
,
21 write_blocked_list
.PushBack(23,
22 QuicWriteBlockedList::kHighestPriority
,
24 write_blocked_list
.PushBack(17,
25 QuicWriteBlockedList::kHighestPriority
,
27 write_blocked_list
.PushBack(kHeadersStreamId
,
28 QuicWriteBlockedList::kHighestPriority
,
30 write_blocked_list
.PushBack(kCryptoStreamId
,
31 QuicWriteBlockedList::kHighestPriority
,
34 EXPECT_EQ(5u, write_blocked_list
.NumBlockedStreams());
35 EXPECT_TRUE(write_blocked_list
.HasWriteBlockedStreams());
36 // The Crypto stream is highest priority.
37 EXPECT_EQ(kCryptoStreamId
, write_blocked_list
.PopFront());
38 // Followed by the Headers stream.
39 EXPECT_EQ(kHeadersStreamId
, write_blocked_list
.PopFront());
40 // Streams with same priority are popped in the order they were inserted.
41 EXPECT_EQ(23u, write_blocked_list
.PopFront());
42 EXPECT_EQ(17u, write_blocked_list
.PopFront());
43 // Low priority stream appears last.
44 EXPECT_EQ(40u, write_blocked_list
.PopFront());
46 EXPECT_EQ(0u, write_blocked_list
.NumBlockedStreams());
47 EXPECT_FALSE(write_blocked_list
.HasWriteBlockedStreams());
50 TEST(QuicWriteBlockedListTest
, CryptoStream
) {
51 QuicWriteBlockedList write_blocked_list
;
52 write_blocked_list
.PushBack(kCryptoStreamId
,
53 QuicWriteBlockedList::kHighestPriority
,
56 EXPECT_EQ(1u, write_blocked_list
.NumBlockedStreams());
57 EXPECT_TRUE(write_blocked_list
.HasWriteBlockedStreams());
58 EXPECT_EQ(kCryptoStreamId
, write_blocked_list
.PopFront());
59 EXPECT_EQ(0u, write_blocked_list
.NumBlockedStreams());
60 EXPECT_FALSE(write_blocked_list
.HasWriteBlockedStreams());
63 TEST(QuicWriteBlockedListTest
, HeadersStream
) {
64 QuicWriteBlockedList write_blocked_list
;
65 write_blocked_list
.PushBack(kHeadersStreamId
,
66 QuicWriteBlockedList::kHighestPriority
,
69 EXPECT_EQ(1u, write_blocked_list
.NumBlockedStreams());
70 EXPECT_TRUE(write_blocked_list
.HasWriteBlockedStreams());
71 EXPECT_EQ(kHeadersStreamId
, write_blocked_list
.PopFront());
72 EXPECT_EQ(0u, write_blocked_list
.NumBlockedStreams());
73 EXPECT_FALSE(write_blocked_list
.HasWriteBlockedStreams());
76 TEST(QuicWriteBlockedListTest
, NoHeadersStreamInVersion12
) {
77 for (int idx
= 0; idx
< 2; ++idx
) {
78 QuicVersion version
= ((idx
== 0) ? QUIC_VERSION_13
: QUIC_VERSION_12
);
79 QuicWriteBlockedList write_blocked_list
;
80 write_blocked_list
.PushBack(5,
81 QuicWriteBlockedList::kHighestPriority
,
83 write_blocked_list
.PushBack(kHeadersStreamId
,
84 QuicWriteBlockedList::kHighestPriority
,
87 EXPECT_EQ(2u, write_blocked_list
.NumBlockedStreams());
88 EXPECT_TRUE(write_blocked_list
.HasWriteBlockedStreams());
89 if (version
> QUIC_VERSION_12
) {
90 // In newer QUIC versions, there is a headers stream which is
91 // higher priority than data streams.
92 EXPECT_EQ(kHeadersStreamId
, write_blocked_list
.PopFront());
93 EXPECT_EQ(5u, write_blocked_list
.PopFront());
95 // In older QUIC versions, there is no reserved headers stream id.
96 EXPECT_EQ(5u, write_blocked_list
.PopFront());
97 EXPECT_EQ(kHeadersStreamId
, write_blocked_list
.PopFront());
99 EXPECT_EQ(0u, write_blocked_list
.NumBlockedStreams());
100 EXPECT_FALSE(write_blocked_list
.HasWriteBlockedStreams());