diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 22:16:53 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 22:16:53 +0000 |
commit | 0a78913b92ee56625e18e91f55c00c22c53c517a (patch) | |
tree | 6c98dd541ffa2fbcb22b522659d95b589717f7ad /net/ftp/ftp_auth_cache_unittest.cc | |
parent | 4fcbf00281b3564d9ae4c42817442bf87b29b6e0 (diff) | |
download | chromium_src-0a78913b92ee56625e18e91f55c00c22c53c517a.zip chromium_src-0a78913b92ee56625e18e91f55c00c22c53c517a.tar.gz chromium_src-0a78913b92ee56625e18e91f55c00c22c53c517a.tar.bz2 |
Enforce maximum number of entries in FtpAuthCache.
TEST=Covered by net_unittests.
BUG=none
Review URL: http://codereview.chromium.org/165167
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23094 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp/ftp_auth_cache_unittest.cc')
-rw-r--r-- | net/ftp/ftp_auth_cache_unittest.cc | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/net/ftp/ftp_auth_cache_unittest.cc b/net/ftp/ftp_auth_cache_unittest.cc index 7f66a60..f74762b 100644 --- a/net/ftp/ftp_auth_cache_unittest.cc +++ b/net/ftp/ftp_auth_cache_unittest.cc @@ -2,8 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "googleurl/src/gurl.h" #include "net/ftp/ftp_auth_cache.h" + +#include "base/string_util.h" +#include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" using net::AuthData; @@ -93,3 +95,29 @@ TEST(FtpAuthCacheTest, NormalizedKey) { cache.Remove(GURL("ftp://HOsT")); EXPECT_EQ(NULL, cache.Lookup(GURL("ftp://host"))); } + +TEST(FtpAuthCacheTest, EvictOldEntries) { + FtpAuthCache cache; + + scoped_refptr<AuthData> auth_data(new AuthData()); + + for (size_t i = 0; i < FtpAuthCache::kMaxEntries; i++) + cache.Add(GURL("ftp://host" + IntToString(i)), auth_data.get()); + + // No entries should be evicted before reaching the limit. + for (size_t i = 0; i < FtpAuthCache::kMaxEntries; i++) { + EXPECT_EQ(auth_data.get(), + cache.Lookup(GURL("ftp://host" + IntToString(i)))); + } + + // Adding one entry should cause eviction of the first entry. + cache.Add(GURL("ftp://last_host"), auth_data.get()); + EXPECT_EQ(NULL, cache.Lookup(GURL("ftp://host0"))); + + // Remaining entries should not get evicted. + for (size_t i = 1; i < FtpAuthCache::kMaxEntries; i++) { + EXPECT_EQ(auth_data.get(), + cache.Lookup(GURL("ftp://host" + IntToString(i)))); + } + EXPECT_EQ(auth_data.get(), cache.Lookup(GURL("ftp://last_host"))); +} |