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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/cookies/canonical_cookie.cc ('k') | net/cookies/cookie_monster.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/cookies/canonical_cookie.h" 5 #include "net/cookies/canonical_cookie.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "googleurl/src/gurl.h" 8 #include "googleurl/src/gurl.h"
9 #include "net/cookies/cookie_options.h" 9 #include "net/cookies/cookie_options.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 243
244 cookie.reset( 244 cookie.reset(
245 CanonicalCookie::Create(GURL("http://www.example.com/test/foo.html"), 245 CanonicalCookie::Create(GURL("http://www.example.com/test/foo.html"),
246 "A=2", creation_time, options)); 246 "A=2", creation_time, options));
247 EXPECT_FALSE(cookie->IsOnPath("/")); 247 EXPECT_FALSE(cookie->IsOnPath("/"));
248 EXPECT_TRUE(cookie->IsOnPath("/test")); 248 EXPECT_TRUE(cookie->IsOnPath("/test"));
249 EXPECT_TRUE(cookie->IsOnPath("/test/bar.html")); 249 EXPECT_TRUE(cookie->IsOnPath("/test/bar.html"));
250 EXPECT_TRUE(cookie->IsOnPath("/test/sample/bar.html")); 250 EXPECT_TRUE(cookie->IsOnPath("/test/sample/bar.html"));
251 } 251 }
252 252
253 TEST(CanonicalCookieTest, IncludeForRequestURL) {
254 GURL url("http://www.example.com");
255 base::Time creation_time = base::Time::Now();
256 CookieOptions options;
257
258 scoped_ptr<CanonicalCookie> cookie(
259 CanonicalCookie::Create(url, "A=2", creation_time, options));
260 EXPECT_TRUE(cookie->IncludeForRequestURL(url, options));
261 EXPECT_TRUE(cookie->IncludeForRequestURL(
262 GURL("http://www.example.com/foo/bar"), options));
263 EXPECT_TRUE(cookie->IncludeForRequestURL(
264 GURL("https://www.example.com/foo/bar"), options));
265 EXPECT_FALSE(cookie->IncludeForRequestURL(GURL("https://sub.example.com"),
266 options));
267 EXPECT_FALSE(cookie->IncludeForRequestURL(GURL("https://sub.www.example.com"),
268 options));
269
270 // Test that cookie with a cookie path that does not match the url path are
271 // not included.
272 cookie.reset(CanonicalCookie::Create(url, "A=2; Path=/foo/bar", creation_time,
273 options));
274 EXPECT_FALSE(cookie->IncludeForRequestURL(url, options));
275 EXPECT_TRUE(cookie->IncludeForRequestURL(
276 GURL("http://www.example.com/foo/bar/index.html"), options));
277
278 // Test that a secure cookie is not included for a non secure URL.
279 GURL secure_url("https://www.example.com");
280 cookie.reset(CanonicalCookie::Create(secure_url, "A=2; Secure", creation_time,
281 options));
282 EXPECT_TRUE(cookie->IsSecure());
283 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options));
284 EXPECT_FALSE(cookie->IncludeForRequestURL(url, options));
285
286 // Test that http only cookies are only included if the include httponly flag
287 // is set on the cookie options.
288 options.set_include_httponly();
289 cookie.reset(
290 CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, options));
291 EXPECT_TRUE(cookie->IsHttpOnly());
292 EXPECT_TRUE(cookie->IncludeForRequestURL(url, options));
293 options.set_exclude_httponly();
294 EXPECT_FALSE(cookie->IncludeForRequestURL(url, options));
295 }
296
253 } // namespace net 297 } // namespace net
OLDNEW
« 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