Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Unified Diff: net/cookies/canonical_cookie_unittest.cc

Issue 11308272: Add IncludeForRequestURL method to CanonicalCookie (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/cookies/canonical_cookie.cc ('k') | net/cookies/cookie_monster.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cookies/canonical_cookie_unittest.cc
diff --git a/net/cookies/canonical_cookie_unittest.cc b/net/cookies/canonical_cookie_unittest.cc
index b46a3f2fa7950ab1b125f58190e02934f666d6ba..14907313628e42ec6a345a5846c0a99589c44dac 100644
--- a/net/cookies/canonical_cookie_unittest.cc
+++ b/net/cookies/canonical_cookie_unittest.cc
@@ -250,4 +250,48 @@ TEST(CanonicalCookieTest, IsOnPath) {
EXPECT_TRUE(cookie->IsOnPath("/test/sample/bar.html"));
}
+TEST(CanonicalCookieTest, IncludeForRequestURL) {
+ GURL url("http://www.example.com");
+ base::Time creation_time = base::Time::Now();
+ CookieOptions options;
+
+ scoped_ptr<CanonicalCookie> cookie(
+ CanonicalCookie::Create(url, "A=2", creation_time, options));
+ EXPECT_TRUE(cookie->IncludeForRequestURL(url, options));
+ EXPECT_TRUE(cookie->IncludeForRequestURL(
+ GURL("http://www.example.com/foo/bar"), options));
+ EXPECT_TRUE(cookie->IncludeForRequestURL(
+ GURL("https://www.example.com/foo/bar"), options));
+ EXPECT_FALSE(cookie->IncludeForRequestURL(GURL("https://sub.example.com"),
+ options));
+ EXPECT_FALSE(cookie->IncludeForRequestURL(GURL("https://sub.www.example.com"),
+ options));
+
+ // Test that cookie with a cookie path that does not match the url path are
+ // not included.
+ cookie.reset(CanonicalCookie::Create(url, "A=2; Path=/foo/bar", creation_time,
+ options));
+ EXPECT_FALSE(cookie->IncludeForRequestURL(url, options));
+ EXPECT_TRUE(cookie->IncludeForRequestURL(
+ GURL("http://www.example.com/foo/bar/index.html"), options));
+
+ // Test that a secure cookie is not included for a non secure URL.
+ GURL secure_url("https://www.example.com");
+ cookie.reset(CanonicalCookie::Create(secure_url, "A=2; Secure", creation_time,
+ options));
+ EXPECT_TRUE(cookie->IsSecure());
+ EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options));
+ EXPECT_FALSE(cookie->IncludeForRequestURL(url, options));
+
+ // Test that http only cookies are only included if the include httponly flag
+ // is set on the cookie options.
+ options.set_include_httponly();
+ cookie.reset(
+ CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, options));
+ EXPECT_TRUE(cookie->IsHttpOnly());
+ EXPECT_TRUE(cookie->IncludeForRequestURL(url, options));
+ options.set_exclude_httponly();
+ EXPECT_FALSE(cookie->IncludeForRequestURL(url, options));
+}
+
} // namespace net
« no previous file with comments | « net/cookies/canonical_cookie.cc ('k') | net/cookies/cookie_monster.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698