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 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 // not a domain cookie. | 521 // not a domain cookie. |
522 this->MatchCookieLines( | 522 this->MatchCookieLines( |
523 std::string(), | 523 std::string(), |
524 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.com/"))); | 524 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.com/"))); |
525 if (TypeParam::supports_non_dotted_domains) { | 525 if (TypeParam::supports_non_dotted_domains) { |
526 this->MatchCookieLines(std::string(), | 526 this->MatchCookieLines(std::string(), |
527 this->GetCookies(cs.get(), GURL("http://.com/"))); | 527 this->GetCookies(cs.get(), GURL("http://.com/"))); |
528 } | 528 } |
529 } | 529 } |
530 | 530 |
531 { | 531 if (TypeParam::supports_non_dotted_domains) { |
532 // Exact matches between the domain attribute and the host are treated as | 532 // Exact matches between the domain attribute and the host are treated as |
533 // host cookies, not domain cookies. | 533 // host cookies, not domain cookies. |
534 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 534 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
535 GURL url("http://com/"); | 535 GURL url("http://com/"); |
536 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1; domain=com")); | 536 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1; domain=com")); |
537 | 537 |
538 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); | 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 | 539 // Make sure it doesn't show up for a normal .com, it should be a host |
540 // not a domain cookie. | 540 // not a domain cookie. |
541 this->MatchCookieLines( | 541 this->MatchCookieLines( |
542 std::string(), | 542 std::string(), |
543 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.com/"))); | 543 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.com/"))); |
544 if (TypeParam::supports_non_dotted_domains) { | 544 this->MatchCookieLines(std::string(), |
545 this->MatchCookieLines(std::string(), | 545 this->GetCookies(cs.get(), GURL("http://.com/"))); |
546 this->GetCookies(cs.get(), GURL("http://.com/"))); | |
547 } | |
548 } | 546 } |
549 | 547 |
550 { | 548 { |
551 // http://com. should be treated the same as http://com. | 549 // http://com. should be treated the same as http://com. |
552 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 550 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
553 GURL url("http://com./index.html"); | 551 GURL url("http://com./index.html"); |
554 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); | 552 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); |
555 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); | 553 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); |
556 this->MatchCookieLines( | 554 this->MatchCookieLines( |
557 std::string(), | 555 std::string(), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 } | 588 } |
591 | 589 |
592 { // Intranet URLs should only be able to set host cookies. | 590 { // Intranet URLs should only be able to set host cookies. |
593 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 591 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
594 GURL url("http://b"); | 592 GURL url("http://b"); |
595 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); | 593 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); |
596 EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=.b")); | 594 EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=.b")); |
597 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); | 595 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); |
598 } | 596 } |
599 | 597 |
600 { | 598 if (TypeParam::supports_non_dotted_domains) { |
601 // Exact matches between the domain attribute and an intranet host are | 599 // Exact matches between the domain attribute and an intranet host are |
602 // treated as host cookies, not domain cookies. | 600 // treated as host cookies, not domain cookies. |
603 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 601 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
604 GURL url("http://b/"); | 602 GURL url("http://b/"); |
605 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1; domain=b")); | 603 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1; domain=b")); |
606 | 604 |
607 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); | 605 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 | 606 // Make sure it doesn't show up for an intranet subdomain, it should be a |
609 // host not a domain cookie. | 607 // host not a domain cookie. |
610 this->MatchCookieLines( | 608 this->MatchCookieLines( |
611 std::string(), | 609 std::string(), |
612 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.b/"))); | 610 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.b/"))); |
613 if (TypeParam::supports_non_dotted_domains) { | 611 this->MatchCookieLines(std::string(), |
614 this->MatchCookieLines(std::string(), | 612 this->GetCookies(cs.get(), GURL("http://.b/"))); |
615 this->GetCookies(cs.get(), GURL("http://.b/"))); | |
616 } | |
617 } | 613 } |
618 } | 614 } |
619 | 615 |
620 // Test reading/writing cookies when the domain ends with a period, | 616 // Test reading/writing cookies when the domain ends with a period, |
621 // as in "www.google.com." | 617 // as in "www.google.com." |
622 TYPED_TEST_P(CookieStoreTest, TestHostEndsWithDot) { | 618 TYPED_TEST_P(CookieStoreTest, TestHostEndsWithDot) { |
623 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 619 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
624 GURL url("http://www.google.com"); | 620 GURL url("http://www.google.com"); |
625 GURL url_with_dot("http://www.google.com."); | 621 GURL url_with_dot("http://www.google.com."); |
626 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); | 622 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, | 1275 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, |
1280 ThreadCheckGetCookies, | 1276 ThreadCheckGetCookies, |
1281 ThreadCheckGetCookiesWithOptions, | 1277 ThreadCheckGetCookiesWithOptions, |
1282 ThreadCheckSetCookieWithOptions, | 1278 ThreadCheckSetCookieWithOptions, |
1283 ThreadCheckDeleteCookie, | 1279 ThreadCheckDeleteCookie, |
1284 ThreadCheckDeleteSessionCookies); | 1280 ThreadCheckDeleteSessionCookies); |
1285 | 1281 |
1286 } // namespace net | 1282 } // namespace net |
1287 | 1283 |
1288 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 1284 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
OLD | NEW |