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

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: s/IncludeForRequest/IncludeForRequestURL/ 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
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..c21a39395d225e202d753cb66879b2a55318d101 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));
erikwright (departed) 2012/12/05 19:43:36 indent (also further in this method).
markusheintz_ 2012/12/06 10:10:43 Done Sorry, I renamed the Include.. method and fo
+ 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,
erikwright (departed) 2012/12/05 19:43:36 is it legal to set a path that is not equal to or
markusheintz_ 2012/12/06 10:10:43 The path of the URL "http://www.example.com" is "/
erikwright (departed) 2012/12/11 14:09:21 No, I was confused, I meant not a parent, but your
+ 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,
erikwright (departed) 2012/12/05 19:43:36 Same question. Presumably insecure URLs can't set
markusheintz_ 2012/12/06 10:10:43 The way I read the spec is: It is possible to set
+ 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 inlucded if the include httponly flag
erikwright (departed) 2012/12/05 19:43:36 inlucded (typo)
markusheintz_ 2012/12/06 10:10:43 Done.
+ // is set on the cookie options.
+ options.set_include_httponly();
+ cookie.reset(
+ CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, options));
erikwright (departed) 2012/12/05 19:43:36 Same question about the options - do we use the op
markusheintz_ 2012/12/06 10:10:43 Yes we use the options to prevent an HttpOnly cook
+ EXPECT_TRUE(cookie->IsHttpOnly());
+ EXPECT_TRUE(cookie->IncludeForRequestURL(url, options));
+ options.set_exclude_httponly();
+ EXPECT_FALSE(cookie->IncludeForRequestURL(url, options));
+}
+
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698