Chromium Code Reviews| 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)); | |
|
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
| |
| 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, | |
|
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
| |
| 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, | |
|
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
| |
| 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 inlucded if the include httponly flag | |
|
erikwright (departed)
2012/12/05 19:43:36
inlucded (typo)
markusheintz_
2012/12/06 10:10:43
Done.
| |
| 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)); | |
|
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
| |
| 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 |