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 "net/cookies/cookie_constants.h" | 8 #include "net/cookies/cookie_constants.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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 "A=2; First-Party-Only; path=/foo/bar", | 400 "A=2; First-Party-Only; path=/foo/bar", |
401 creation_time, options)); | 401 creation_time, options)); |
402 options.set_first_party_url(secure_url_with_path); | 402 options.set_first_party_url(secure_url_with_path); |
403 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url_with_path, options)); | 403 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url_with_path, options)); |
404 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); | 404 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); |
405 options.set_first_party_url(secure_url); | 405 options.set_first_party_url(secure_url); |
406 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url_with_path, options)); | 406 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url_with_path, options)); |
407 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); | 407 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); |
408 } | 408 } |
409 | 409 |
| 410 TEST(CanonicalCookieTest, PartialCompare) { |
| 411 GURL url("http://www.example.com"); |
| 412 base::Time creation_time = base::Time::Now(); |
| 413 CookieOptions options; |
| 414 scoped_ptr<CanonicalCookie> cookie( |
| 415 CanonicalCookie::Create(url, "a=b", creation_time, options)); |
| 416 scoped_ptr<CanonicalCookie> cookie_different_path( |
| 417 CanonicalCookie::Create(url, "a=b; path=/foo", creation_time, options)); |
| 418 scoped_ptr<CanonicalCookie> cookie_different_value( |
| 419 CanonicalCookie::Create(url, "a=c", creation_time, options)); |
| 420 |
| 421 // Cookie is equivalent to itself. |
| 422 EXPECT_FALSE(cookie->PartialCompare(*cookie)); |
| 423 |
| 424 // Changing the path affects the ordering. |
| 425 EXPECT_TRUE(cookie->PartialCompare(*cookie_different_path)); |
| 426 EXPECT_FALSE(cookie_different_path->PartialCompare(*cookie)); |
| 427 |
| 428 // Changing the value does not affect the ordering. |
| 429 EXPECT_FALSE(cookie->PartialCompare(*cookie_different_value)); |
| 430 EXPECT_FALSE(cookie_different_value->PartialCompare(*cookie)); |
| 431 |
| 432 // Cookies identical for PartialCompare() are equivalent. |
| 433 EXPECT_TRUE(cookie->IsEquivalent(*cookie_different_value)); |
| 434 EXPECT_TRUE(cookie->IsEquivalent(*cookie)); |
| 435 } |
| 436 |
| 437 TEST(CanonicalCookieTest, FullCompare) { |
| 438 GURL url("http://www.example.com"); |
| 439 base::Time creation_time = base::Time::Now(); |
| 440 CookieOptions options; |
| 441 scoped_ptr<CanonicalCookie> cookie( |
| 442 CanonicalCookie::Create(url, "a=b", creation_time, options)); |
| 443 scoped_ptr<CanonicalCookie> cookie_different_path( |
| 444 CanonicalCookie::Create(url, "a=b; path=/foo", creation_time, options)); |
| 445 scoped_ptr<CanonicalCookie> cookie_different_value( |
| 446 CanonicalCookie::Create(url, "a=c", creation_time, options)); |
| 447 |
| 448 // Cookie is equivalent to itself. |
| 449 EXPECT_FALSE(cookie->FullCompare(*cookie)); |
| 450 |
| 451 // Changing the path affects the ordering. |
| 452 EXPECT_TRUE(cookie->FullCompare(*cookie_different_path)); |
| 453 EXPECT_FALSE(cookie_different_path->FullCompare(*cookie)); |
| 454 |
| 455 // Changing the value affects the ordering. |
| 456 EXPECT_TRUE(cookie->FullCompare(*cookie_different_value)); |
| 457 EXPECT_FALSE(cookie_different_value->FullCompare(*cookie)); |
| 458 |
| 459 // FullCompare() implies PartialCompare(). |
| 460 auto check_consistency = |
| 461 [](const CanonicalCookie& a, const CanonicalCookie& b) { |
| 462 if (a.FullCompare(b)) |
| 463 EXPECT_FALSE(b.PartialCompare(a)); |
| 464 else if (b.FullCompare(a)) |
| 465 EXPECT_FALSE(a.PartialCompare(b)); |
| 466 }; |
| 467 |
| 468 check_consistency(*cookie, *cookie_different_path); |
| 469 check_consistency(*cookie, *cookie_different_value); |
| 470 check_consistency(*cookie_different_path, *cookie_different_value); |
| 471 } |
| 472 |
410 } // namespace net | 473 } // namespace net |
OLD | NEW |