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 #ifndef NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 5 #ifndef NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
6 #define NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 6 #define NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 } | 508 } |
509 | 509 |
510 // Test host cookies, and setting of cookies on TLD. | 510 // Test host cookies, and setting of cookies on TLD. |
511 TYPED_TEST_P(CookieStoreTest, TestNonDottedAndTLD) { | 511 TYPED_TEST_P(CookieStoreTest, TestNonDottedAndTLD) { |
512 { | 512 { |
513 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 513 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
514 GURL url("http://com/"); | 514 GURL url("http://com/"); |
515 // Allow setting on "com", (but only as a host cookie). | 515 // Allow setting on "com", (but only as a host cookie). |
516 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); | 516 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); |
517 EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=.com")); | 517 EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=.com")); |
518 EXPECT_FALSE(this->SetCookie(cs.get(), url, "c=3; domain=com")); | 518 |
519 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); | 519 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); |
520 // Make sure it doesn't show up for a normal .com, it should be a host | 520 // Make sure it doesn't show up for a normal .com, it should be a host |
521 // not a domain cookie. | 521 // not a domain cookie. |
| 522 this->MatchCookieLines( |
| 523 std::string(), |
| 524 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.com/"))); |
| 525 if (TypeParam::supports_non_dotted_domains) { |
| 526 this->MatchCookieLines(std::string(), |
| 527 this->GetCookies(cs.get(), GURL("http://.com/"))); |
| 528 } |
| 529 } |
| 530 |
| 531 { |
| 532 // Exact matches between the domain attribute and the host are treated as |
| 533 // host cookies, not domain cookies. |
| 534 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
| 535 GURL url("http://com/"); |
| 536 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1; domain=com")); |
| 537 |
| 538 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); |
| 539 // Make sure it doesn't show up for a normal .com, it should be a host |
| 540 // not a domain cookie. |
522 this->MatchCookieLines( | 541 this->MatchCookieLines( |
523 std::string(), | 542 std::string(), |
524 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.com/"))); | 543 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.com/"))); |
525 if (TypeParam::supports_non_dotted_domains) { | 544 if (TypeParam::supports_non_dotted_domains) { |
526 this->MatchCookieLines(std::string(), | 545 this->MatchCookieLines(std::string(), |
527 this->GetCookies(cs.get(), GURL("http://.com/"))); | 546 this->GetCookies(cs.get(), GURL("http://.com/"))); |
528 } | 547 } |
529 } | 548 } |
530 | 549 |
531 { | 550 { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 this->MatchCookieLines( | 587 this->MatchCookieLines( |
569 std::string(), | 588 std::string(), |
570 this->GetCookies(cs.get(), GURL("http://something-else.uk"))); | 589 this->GetCookies(cs.get(), GURL("http://something-else.uk"))); |
571 } | 590 } |
572 | 591 |
573 { // Intranet URLs should only be able to set host cookies. | 592 { // Intranet URLs should only be able to set host cookies. |
574 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 593 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
575 GURL url("http://b"); | 594 GURL url("http://b"); |
576 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); | 595 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); |
577 EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=.b")); | 596 EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=.b")); |
578 EXPECT_FALSE(this->SetCookie(cs.get(), url, "c=3; domain=b")); | |
579 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); | 597 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); |
580 } | 598 } |
| 599 |
| 600 { |
| 601 // Exact matches between the domain attribute and an intranet host are |
| 602 // treated as host cookies, not domain cookies. |
| 603 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
| 604 GURL url("http://b/"); |
| 605 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1; domain=b")); |
| 606 |
| 607 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); |
| 608 // Make sure it doesn't show up for an intranet subdomain, it should be a |
| 609 // host not a domain cookie. |
| 610 this->MatchCookieLines( |
| 611 std::string(), |
| 612 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.b/"))); |
| 613 if (TypeParam::supports_non_dotted_domains) { |
| 614 this->MatchCookieLines(std::string(), |
| 615 this->GetCookies(cs.get(), GURL("http://.b/"))); |
| 616 } |
| 617 } |
581 } | 618 } |
582 | 619 |
583 // Test reading/writing cookies when the domain ends with a period, | 620 // Test reading/writing cookies when the domain ends with a period, |
584 // as in "www.google.com." | 621 // as in "www.google.com." |
585 TYPED_TEST_P(CookieStoreTest, TestHostEndsWithDot) { | 622 TYPED_TEST_P(CookieStoreTest, TestHostEndsWithDot) { |
586 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 623 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
587 GURL url("http://www.google.com"); | 624 GURL url("http://www.google.com"); |
588 GURL url_with_dot("http://www.google.com."); | 625 GURL url_with_dot("http://www.google.com."); |
589 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); | 626 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); |
590 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); | 627 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1242 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, | 1279 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, |
1243 ThreadCheckGetCookies, | 1280 ThreadCheckGetCookies, |
1244 ThreadCheckGetCookiesWithOptions, | 1281 ThreadCheckGetCookiesWithOptions, |
1245 ThreadCheckSetCookieWithOptions, | 1282 ThreadCheckSetCookieWithOptions, |
1246 ThreadCheckDeleteCookie, | 1283 ThreadCheckDeleteCookie, |
1247 ThreadCheckDeleteSessionCookies); | 1284 ThreadCheckDeleteSessionCookies); |
1248 | 1285 |
1249 } // namespace net | 1286 } // namespace net |
1250 | 1287 |
1251 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 1288 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
OLD | NEW |