OLD | NEW |
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 Loading... |
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 |
OLD | NEW |