diff options
author | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-07 13:34:40 +0000 |
---|---|---|
committer | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-07 13:34:40 +0000 |
commit | 605749c4bcf265ae95ebf32d4e009dba77bbfbfe (patch) | |
tree | 6697886ebdbb58d1512766b1699e23adc66b0e72 /net/base/host_cache_unittest.cc | |
parent | 4d29285d95193a12ce2797fdcef10a9ac837a782 (diff) | |
download | chromium_src-605749c4bcf265ae95ebf32d4e009dba77bbfbfe.zip chromium_src-605749c4bcf265ae95ebf32d4e009dba77bbfbfe.tar.gz chromium_src-605749c4bcf265ae95ebf32d4e009dba77bbfbfe.tar.bz2 |
HostResolver now adds AI_CANONNAME to the hint flags if a requester needs the information.
Requests which want the canonical name should be treated differently from requests that do not for the same host in both the HostCache as well as in the HostResolver when combining multiple outstanding requests into a job.
The motivation for this is that Kerberos SPN's for a web server are typically generated using the canonical name of the server rather than a DNS alias (both Firefox and IE have this behavior).
BUG=29862
TEST=net_unittests
Review URL: http://codereview.chromium.org/1566012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43826 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/host_cache_unittest.cc')
-rw-r--r-- | net/base/host_cache_unittest.cc | 87 |
1 files changed, 71 insertions, 16 deletions
diff --git a/net/base/host_cache_unittest.cc b/net/base/host_cache_unittest.cc index 141cfde..2ed47ab 100644 --- a/net/base/host_cache_unittest.cc +++ b/net/base/host_cache_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -20,7 +20,7 @@ const base::TimeDelta kFailureEntryTTL = base::TimeDelta::FromSeconds(0); // Builds a key for |hostname|, defaulting the address family to unspecified. HostCache::Key Key(const std::string& hostname) { - return HostCache::Key(hostname, ADDRESS_FAMILY_UNSPECIFIED); + return HostCache::Key(hostname, ADDRESS_FAMILY_UNSPECIFIED, 0); } } // namespace @@ -276,8 +276,8 @@ TEST(HostCacheTest, AddressFamilyIsPartOfKey) { // t=0. base::TimeTicks now; - HostCache::Key key1("foobar.com", ADDRESS_FAMILY_UNSPECIFIED); - HostCache::Key key2("foobar.com", ADDRESS_FAMILY_IPV4); + HostCache::Key key1("foobar.com", ADDRESS_FAMILY_UNSPECIFIED, 0); + HostCache::Key key2("foobar.com", ADDRESS_FAMILY_IPV4, 0); const HostCache::Entry* entry1 = NULL; // Entry for key1 const HostCache::Entry* entry2 = NULL; // Entry for key2 @@ -303,6 +303,42 @@ TEST(HostCacheTest, AddressFamilyIsPartOfKey) { EXPECT_NE(entry1, entry2); } +// Tests that the same hostname can be duplicated in the cache, so long as +// the HostResolverFlags differ. +TEST(HostCacheTest, HostResolverFlagsArePartOfKey) { + HostCache cache(kMaxCacheEntries, kSuccessEntryTTL, kFailureEntryTTL); + + // t=0. + base::TimeTicks now; + + HostCache::Key key1("foobar.com", ADDRESS_FAMILY_IPV4, 0); + HostCache::Key key2("foobar.com", ADDRESS_FAMILY_IPV4, + HOST_RESOLVER_FLAGS_CANONNAME); + + const HostCache::Entry* entry1 = NULL; // Entry for key1 + const HostCache::Entry* entry2 = NULL; // Entry for key2 + + EXPECT_EQ(0U, cache.size()); + + // Add an entry for ("foobar.com", IPV4, NONE) at t=0. + EXPECT_TRUE(cache.Lookup(key1, base::TimeTicks()) == NULL); + cache.Set(key1, OK, AddressList(), now); + entry1 = cache.Lookup(key1, base::TimeTicks()); + EXPECT_FALSE(entry1 == NULL); + EXPECT_EQ(1U, cache.size()); + + // Add an entry for ("foobar.com", IPV4, CANONNAME) at t=0. + EXPECT_TRUE(cache.Lookup(key2, base::TimeTicks()) == NULL); + cache.Set(key2, OK, AddressList(), now); + entry2 = cache.Lookup(key2, base::TimeTicks()); + EXPECT_FALSE(entry2 == NULL); + EXPECT_EQ(2U, cache.size()); + + // Even though the hostnames were the same, we should have two unique + // entries (because the HostResolverFlags differ). + EXPECT_NE(entry1, entry2); +} + TEST(HostCacheTest, NoCache) { // Disable caching. HostCache cache(0, kSuccessEntryTTL, kFailureEntryTTL); @@ -353,33 +389,52 @@ TEST(HostCacheTest, KeyComparators) { int expected_comparison; } tests[] = { { - HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED), - HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED), + HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED, 0), + HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED, 0), 0 }, { - HostCache::Key("host1", ADDRESS_FAMILY_IPV4), - HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED), + HostCache::Key("host1", ADDRESS_FAMILY_IPV4, 0), + HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED, 0), 1 }, { - HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED), - HostCache::Key("host1", ADDRESS_FAMILY_IPV4), + HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED, 0), + HostCache::Key("host1", ADDRESS_FAMILY_IPV4, 0), -1 }, { - HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED), - HostCache::Key("host2", ADDRESS_FAMILY_UNSPECIFIED), + HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED, 0), + HostCache::Key("host2", ADDRESS_FAMILY_UNSPECIFIED, 0), + -1 + }, + { + HostCache::Key("host1", ADDRESS_FAMILY_IPV4, 0), + HostCache::Key("host2", ADDRESS_FAMILY_UNSPECIFIED, 0), + 1 + }, + { + HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED, 0), + HostCache::Key("host2", ADDRESS_FAMILY_IPV4, 0), + -1 + }, + { + HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED, 0), + HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED, + HOST_RESOLVER_FLAGS_CANONNAME), -1 }, { - HostCache::Key("host1", ADDRESS_FAMILY_IPV4), - HostCache::Key("host2", ADDRESS_FAMILY_UNSPECIFIED), + HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED, + HOST_RESOLVER_FLAGS_CANONNAME), + HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED, 0), 1 }, { - HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED), - HostCache::Key("host2", ADDRESS_FAMILY_IPV4), + HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED, + HOST_RESOLVER_FLAGS_CANONNAME), + HostCache::Key("host2", ADDRESS_FAMILY_UNSPECIFIED, + HOST_RESOLVER_FLAGS_CANONNAME), -1 }, }; |