1 // Copyright (c) 2012 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/spdy_credential_state.h"
7 #include "net/base/host_port_pair.h"
8 #include "testing/platform_test.h"
12 class SpdyCredentialStateTest
: public PlatformTest
{
14 SpdyCredentialStateTest()
16 origin1_("https://1.com"),
17 origin2_("https://2.com"),
18 origin3_("https://3.com"),
19 origin4_("https://4.com"),
20 origin5_("https://5.com"),
21 origin6_("https://6.com"),
22 origin11_("https://11.com"),
23 host1_("https://www.1.com:443") {
27 SpdyCredentialState state_
;
37 DISALLOW_COPY_AND_ASSIGN(SpdyCredentialStateTest
);
40 TEST_F(SpdyCredentialStateTest
, HasCredentialReturnsFalseWhenEmpty
) {
41 EXPECT_FALSE(state_
.HasCredential(origin1_
));
42 EXPECT_FALSE(state_
.HasCredential(origin2_
));
43 EXPECT_FALSE(state_
.HasCredential(origin3_
));
46 TEST_F(SpdyCredentialStateTest
, HasCredentialReturnsTrueWhenAdded
) {
47 state_
.SetHasCredential(origin1_
);
48 EXPECT_TRUE(state_
.HasCredential(origin1_
));
49 EXPECT_TRUE(state_
.HasCredential(host1_
));
50 EXPECT_FALSE(state_
.HasCredential(origin11_
));
51 EXPECT_FALSE(state_
.HasCredential(origin2_
));
52 EXPECT_FALSE(state_
.HasCredential(origin3_
));
55 TEST_F(SpdyCredentialStateTest
, SetCredentialAddsToEndOfList
) {
56 EXPECT_EQ(1u, (state_
.SetHasCredential(origin1_
)));
57 EXPECT_EQ(2u, (state_
.SetHasCredential(origin2_
)));
58 EXPECT_EQ(3u, (state_
.SetHasCredential(origin3_
)));
61 TEST_F(SpdyCredentialStateTest
, SetReturnsPositionIfAlreadyInList
) {
62 EXPECT_EQ(1u, (state_
.SetHasCredential(origin1_
)));
63 EXPECT_EQ(2u, (state_
.SetHasCredential(origin2_
)));
64 EXPECT_EQ(1u, (state_
.SetHasCredential(origin1_
)));
65 EXPECT_EQ(2u, (state_
.SetHasCredential(origin2_
)));
68 TEST_F(SpdyCredentialStateTest
, SetReplacesOldestElementWhenFull
) {
69 EXPECT_EQ(1u, (state_
.SetHasCredential(origin1_
)));
70 EXPECT_EQ(2u, (state_
.SetHasCredential(origin2_
)));
71 EXPECT_EQ(3u, (state_
.SetHasCredential(origin3_
)));
72 EXPECT_EQ(4u, (state_
.SetHasCredential(origin4_
)));
73 EXPECT_EQ(1u, (state_
.SetHasCredential(origin5_
)));
74 EXPECT_EQ(2u, (state_
.SetHasCredential(origin6_
)));
75 EXPECT_EQ(3u, (state_
.SetHasCredential(origin1_
)));
76 EXPECT_EQ(4u, (state_
.SetHasCredential(origin2_
)));
79 TEST_F(SpdyCredentialStateTest
, ResizeAddsEmptySpaceAtEnd
) {
80 EXPECT_EQ(1u, (state_
.SetHasCredential(origin1_
)));
81 EXPECT_EQ(2u, (state_
.SetHasCredential(origin2_
)));
82 EXPECT_EQ(3u, (state_
.SetHasCredential(origin3_
)));
83 EXPECT_EQ(4u, (state_
.SetHasCredential(origin4_
)));
85 EXPECT_EQ(1u, (state_
.SetHasCredential(origin1_
)));
86 EXPECT_EQ(2u, (state_
.SetHasCredential(origin2_
)));
87 EXPECT_EQ(3u, (state_
.SetHasCredential(origin3_
)));
88 EXPECT_EQ(4u, (state_
.SetHasCredential(origin4_
)));
89 EXPECT_EQ(5u, (state_
.SetHasCredential(origin5_
)));
90 EXPECT_EQ(6u, (state_
.SetHasCredential(origin6_
)));
93 TEST_F(SpdyCredentialStateTest
, ResizeTrunatesFromEnd
) {
94 EXPECT_EQ(1u, (state_
.SetHasCredential(origin1_
)));
95 EXPECT_EQ(2u, (state_
.SetHasCredential(origin2_
)));
96 EXPECT_EQ(3u, (state_
.SetHasCredential(origin3_
)));
97 EXPECT_EQ(4u, (state_
.SetHasCredential(origin4_
)));
99 EXPECT_TRUE(state_
.HasCredential(origin1_
));
100 EXPECT_TRUE(state_
.HasCredential(origin2_
));
101 EXPECT_FALSE(state_
.HasCredential(origin3_
));
102 EXPECT_FALSE(state_
.HasCredential(origin4_
));
103 EXPECT_EQ(1u, (state_
.SetHasCredential(origin5_
)));
104 EXPECT_EQ(2u, (state_
.SetHasCredential(origin6_
)));