OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/ftp/ftp_auth_cache.h" | 5 #include "net/ftp/ftp_auth_cache.h" |
6 | 6 |
| 7 #include "base/string_number_conversions.h" |
7 #include "base/string_util.h" | 8 #include "base/string_util.h" |
8 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 using net::FtpAuthCache; | 12 using net::FtpAuthCache; |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 const string16 kBogus(ASCIIToUTF16("bogus")); | 16 const string16 kBogus(ASCIIToUTF16("bogus")); |
16 const string16 kOthername(ASCIIToUTF16("othername")); | 17 const string16 kOthername(ASCIIToUTF16("othername")); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 EXPECT_TRUE(cache.Lookup(GURL("ftp://host"))); | 126 EXPECT_TRUE(cache.Lookup(GURL("ftp://host"))); |
126 | 127 |
127 // Auth data matches, should remove. | 128 // Auth data matches, should remove. |
128 cache.Remove(GURL("ftp://host"), kUsername, kPassword); | 129 cache.Remove(GURL("ftp://host"), kUsername, kPassword); |
129 EXPECT_TRUE(cache.Lookup(GURL("ftp://host")) == NULL); | 130 EXPECT_TRUE(cache.Lookup(GURL("ftp://host")) == NULL); |
130 } | 131 } |
131 | 132 |
132 TEST(FtpAuthCacheTest, EvictOldEntries) { | 133 TEST(FtpAuthCacheTest, EvictOldEntries) { |
133 FtpAuthCache cache; | 134 FtpAuthCache cache; |
134 | 135 |
135 for (size_t i = 0; i < FtpAuthCache::kMaxEntries; i++) | 136 for (size_t i = 0; i < FtpAuthCache::kMaxEntries; i++) { |
136 cache.Add(GURL("ftp://host" + IntToString(i)), kUsername, kPassword); | 137 cache.Add(GURL("ftp://host" + base::IntToString(i)), |
| 138 kUsername, kPassword); |
| 139 } |
137 | 140 |
138 // No entries should be evicted before reaching the limit. | 141 // No entries should be evicted before reaching the limit. |
139 for (size_t i = 0; i < FtpAuthCache::kMaxEntries; i++) { | 142 for (size_t i = 0; i < FtpAuthCache::kMaxEntries; i++) { |
140 EXPECT_TRUE(cache.Lookup(GURL("ftp://host" + IntToString(i)))); | 143 EXPECT_TRUE(cache.Lookup(GURL("ftp://host" + base::IntToString(i)))); |
141 } | 144 } |
142 | 145 |
143 // Adding one entry should cause eviction of the first entry. | 146 // Adding one entry should cause eviction of the first entry. |
144 cache.Add(GURL("ftp://last_host"), kUsername, kPassword); | 147 cache.Add(GURL("ftp://last_host"), kUsername, kPassword); |
145 EXPECT_TRUE(cache.Lookup(GURL("ftp://host0")) == NULL); | 148 EXPECT_TRUE(cache.Lookup(GURL("ftp://host0")) == NULL); |
146 | 149 |
147 // Remaining entries should not get evicted. | 150 // Remaining entries should not get evicted. |
148 for (size_t i = 1; i < FtpAuthCache::kMaxEntries; i++) { | 151 for (size_t i = 1; i < FtpAuthCache::kMaxEntries; i++) { |
149 EXPECT_TRUE(cache.Lookup(GURL("ftp://host" + IntToString(i)))); | 152 EXPECT_TRUE(cache.Lookup(GURL("ftp://host" + base::IntToString(i)))); |
150 } | 153 } |
151 EXPECT_TRUE(cache.Lookup(GURL("ftp://last_host"))); | 154 EXPECT_TRUE(cache.Lookup(GURL("ftp://last_host"))); |
152 } | 155 } |
OLD | NEW |