diff options
author | markusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-29 17:32:51 +0000 |
---|---|---|
committer | markusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-29 17:32:51 +0000 |
commit | 0fae3befcd250051300f1794cd4265dcc84606c8 (patch) | |
tree | b40e44975115f2f80aec54cc84b78fe61160c506 /net | |
parent | 3559f879da2707c2c612805406909d35c704feaa (diff) | |
download | chromium_src-0fae3befcd250051300f1794cd4265dcc84606c8.zip chromium_src-0fae3befcd250051300f1794cd4265dcc84606c8.tar.gz chromium_src-0fae3befcd250051300f1794cd4265dcc84606c8.tar.bz2 |
Add unittests to test the "IsOnPath" and "IsDomainMatch methods of the class CannonicalCookie.
BUG=161767
Review URL: https://chromiumcodereview.appspot.com/11414203
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170215 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/cookies/canonical_cookie_unittest.cc | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/net/cookies/canonical_cookie_unittest.cc b/net/cookies/canonical_cookie_unittest.cc index d99bcb9..9951db0 100644 --- a/net/cookies/canonical_cookie_unittest.cc +++ b/net/cookies/canonical_cookie_unittest.cc @@ -193,4 +193,61 @@ TEST(CanonicalCookieTest, IsEquivalent) { EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); } +TEST(CanonicalCookieTest, IsDomainMatch) { + GURL url("http://www.example.com/test/foo.html"); + base::Time creation_time = base::Time::Now(); + CookieOptions options; + + scoped_ptr<CanonicalCookie> cookie( + CanonicalCookie::Create(url, "A=2", creation_time, options)); + EXPECT_TRUE(cookie->IsHostCookie()); + EXPECT_TRUE(cookie->IsDomainMatch("http", "www.example.com")); + EXPECT_TRUE(cookie->IsDomainMatch("https", "www.example.com")); + EXPECT_FALSE(cookie->IsDomainMatch("http", "foo.www.example.com")); + EXPECT_FALSE(cookie->IsDomainMatch("http", "www0.example.com")); + EXPECT_FALSE(cookie->IsDomainMatch("http", "example.com")); + + cookie.reset( + CanonicalCookie::Create(url, "A=2; Domain=www.example.com", creation_time, + options)); + EXPECT_TRUE(cookie->IsDomainCookie()); + EXPECT_TRUE(cookie->IsDomainMatch("http", "www.example.com")); + EXPECT_TRUE(cookie->IsDomainMatch("https", "www.example.com")); + EXPECT_TRUE(cookie->IsDomainMatch("http", "foo.www.example.com")); + EXPECT_FALSE(cookie->IsDomainMatch("http", "www0.example.com")); + EXPECT_FALSE(cookie->IsDomainMatch("http", "example.com")); + + cookie.reset( + CanonicalCookie::Create(url, "A=2; Domain=.www.example.com", + creation_time, options)); + EXPECT_TRUE(cookie->IsDomainMatch("http", "www.example.com")); + EXPECT_TRUE(cookie->IsDomainMatch("https", "www.example.com")); + EXPECT_TRUE(cookie->IsDomainMatch("http", "foo.www.example.com")); + EXPECT_FALSE(cookie->IsDomainMatch("http", "www0.example.com")); + EXPECT_FALSE(cookie->IsDomainMatch("http", "example.com")); +} + +TEST(CanonicalCookieTest, IsOnPath) { + base::Time creation_time = base::Time::Now(); + CookieOptions options; + + scoped_ptr<CanonicalCookie> cookie( + CanonicalCookie::Create(GURL("http://www.example.com"), + "A=2", creation_time, options)); + EXPECT_TRUE(cookie->IsOnPath("/")); + EXPECT_TRUE(cookie->IsOnPath("/test")); + EXPECT_TRUE(cookie->IsOnPath("/test/bar.html")); + + // Test the empty string edge case. + EXPECT_FALSE(cookie->IsOnPath("")); + + cookie.reset( + CanonicalCookie::Create(GURL("http://www.example.com/test/foo.html"), + "A=2", creation_time, options)); + EXPECT_FALSE(cookie->IsOnPath("/")); + EXPECT_TRUE(cookie->IsOnPath("/test")); + EXPECT_TRUE(cookie->IsOnPath("/test/bar.html")); + EXPECT_TRUE(cookie->IsOnPath("/test/sample/bar.html")); +} + } // namespace net |