summaryrefslogtreecommitdiffstats
path: root/net/spdy/spdy_credential_state_unittest.cc
blob: b51292175601665102ba09091ef246d3eef19adc (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
// Copyright (c) 2012 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/spdy_credential_state.h"

#include "net/base/host_port_pair.h"
#include "testing/platform_test.h"

namespace net {

class SpdyCredentialStateTest : public PlatformTest {
 public:
  SpdyCredentialStateTest()
    : state_(4),
      origin1_("https://1.com"),
      origin2_("https://2.com"),
      origin3_("https://3.com"),
      origin4_("https://4.com"),
      origin5_("https://5.com"),
      origin6_("https://6.com"),
      origin11_("https://11.com"),
      host1_("https://www.1.com:443") {
  }

 protected:
  SpdyCredentialState state_;
  const GURL origin1_;
  const GURL origin2_;
  const GURL origin3_;
  const GURL origin4_;
  const GURL origin5_;
  const GURL origin6_;
  const GURL origin11_;
  const GURL host1_;

  DISALLOW_COPY_AND_ASSIGN(SpdyCredentialStateTest);
};

TEST_F(SpdyCredentialStateTest, HasCredentialReturnsFalseWhenEmpty) {
  EXPECT_FALSE(state_.HasCredential(origin1_));
  EXPECT_FALSE(state_.HasCredential(origin2_));
  EXPECT_FALSE(state_.HasCredential(origin3_));
}

TEST_F(SpdyCredentialStateTest, HasCredentialReturnsTrueWhenAdded) {
  state_.SetHasCredential(origin1_);
  EXPECT_TRUE(state_.HasCredential(origin1_));
  EXPECT_TRUE(state_.HasCredential(host1_));
  EXPECT_FALSE(state_.HasCredential(origin11_));
  EXPECT_FALSE(state_.HasCredential(origin2_));
  EXPECT_FALSE(state_.HasCredential(origin3_));
}

TEST_F(SpdyCredentialStateTest, SetCredentialAddsToEndOfList) {
  EXPECT_EQ(1u, (state_.SetHasCredential(origin1_)));
  EXPECT_EQ(2u, (state_.SetHasCredential(origin2_)));
  EXPECT_EQ(3u, (state_.SetHasCredential(origin3_)));
}

TEST_F(SpdyCredentialStateTest, SetReturnsPositionIfAlreadyInList) {
  EXPECT_EQ(1u, (state_.SetHasCredential(origin1_)));
  EXPECT_EQ(2u, (state_.SetHasCredential(origin2_)));
  EXPECT_EQ(1u, (state_.SetHasCredential(origin1_)));
  EXPECT_EQ(2u, (state_.SetHasCredential(origin2_)));
}

TEST_F(SpdyCredentialStateTest, SetReplacesOldestElementWhenFull) {
  EXPECT_EQ(1u, (state_.SetHasCredential(origin1_)));
  EXPECT_EQ(2u, (state_.SetHasCredential(origin2_)));
  EXPECT_EQ(3u, (state_.SetHasCredential(origin3_)));
  EXPECT_EQ(4u, (state_.SetHasCredential(origin4_)));
  EXPECT_EQ(1u, (state_.SetHasCredential(origin5_)));
  EXPECT_EQ(2u, (state_.SetHasCredential(origin6_)));
  EXPECT_EQ(3u, (state_.SetHasCredential(origin1_)));
  EXPECT_EQ(4u, (state_.SetHasCredential(origin2_)));
}

TEST_F(SpdyCredentialStateTest, ResizeAddsEmptySpaceAtEnd) {
  EXPECT_EQ(1u, (state_.SetHasCredential(origin1_)));
  EXPECT_EQ(2u, (state_.SetHasCredential(origin2_)));
  EXPECT_EQ(3u, (state_.SetHasCredential(origin3_)));
  EXPECT_EQ(4u, (state_.SetHasCredential(origin4_)));
  state_.Resize(6);
  EXPECT_EQ(1u, (state_.SetHasCredential(origin1_)));
  EXPECT_EQ(2u, (state_.SetHasCredential(origin2_)));
  EXPECT_EQ(3u, (state_.SetHasCredential(origin3_)));
  EXPECT_EQ(4u, (state_.SetHasCredential(origin4_)));
  EXPECT_EQ(5u, (state_.SetHasCredential(origin5_)));
  EXPECT_EQ(6u, (state_.SetHasCredential(origin6_)));
}

TEST_F(SpdyCredentialStateTest, ResizeTrunatesFromEnd) {
  EXPECT_EQ(1u, (state_.SetHasCredential(origin1_)));
  EXPECT_EQ(2u, (state_.SetHasCredential(origin2_)));
  EXPECT_EQ(3u, (state_.SetHasCredential(origin3_)));
  EXPECT_EQ(4u, (state_.SetHasCredential(origin4_)));
  state_.Resize(2);
  EXPECT_TRUE(state_.HasCredential(origin1_));
  EXPECT_TRUE(state_.HasCredential(origin2_));
  EXPECT_FALSE(state_.HasCredential(origin3_));
  EXPECT_FALSE(state_.HasCredential(origin4_));
  EXPECT_EQ(1u, (state_.SetHasCredential(origin5_)));
  EXPECT_EQ(2u, (state_.SetHasCredential(origin6_)));
}


}  // namespace net