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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 EXPECT_FALSE(it->IsPersistent()); | 458 EXPECT_FALSE(it->IsPersistent()); |
459 // Some CookieStores don't store last access date. | 459 // Some CookieStores don't store last access date. |
460 if (!it->LastAccessDate().is_null()) | 460 if (!it->LastAccessDate().is_null()) |
461 EXPECT_EQ(it->CreationDate(), it->LastAccessDate()); | 461 EXPECT_EQ(it->CreationDate(), it->LastAccessDate()); |
462 EXPECT_TRUE(it->IsSecure()); | 462 EXPECT_TRUE(it->IsSecure()); |
463 EXPECT_FALSE(it->IsHttpOnly()); | 463 EXPECT_FALSE(it->IsHttpOnly()); |
464 | 464 |
465 EXPECT_TRUE(++it == cookies.end()); | 465 EXPECT_TRUE(++it == cookies.end()); |
466 } | 466 } |
467 | 467 |
| 468 // The iOS networking stack uses the iOS cookie parser, which we do not |
| 469 // control. While it is spec-compliant, that does not match the practical |
| 470 // behavior of most UAs in some cases, which we try to replicate. See |
| 471 // https://crbug.com/638389 for more information. |
| 472 TYPED_TEST_P(CookieStoreTest, EmptyKeyTest) { |
| 473 #if !defined(OS_IOS) |
| 474 CookieStore* cs = this->GetCookieStore(); |
| 475 |
| 476 GURL url1("http://foo1.bar.com"); |
| 477 EXPECT_TRUE(this->SetCookie(cs, url1, "foo")); |
| 478 EXPECT_EQ("foo", this->GetCookies(cs, url1)); |
| 479 |
| 480 // Regression tests for https://crbug.com/601786 |
| 481 GURL url2("http://foo2.bar.com"); |
| 482 EXPECT_TRUE(this->SetCookie(cs, url2, "foo")); |
| 483 EXPECT_TRUE(this->SetCookie(cs, url2, "\t")); |
| 484 EXPECT_EQ("", this->GetCookies(cs, url2)); |
| 485 |
| 486 GURL url3("http://foo3.bar.com"); |
| 487 EXPECT_TRUE(this->SetCookie(cs, url3, "foo")); |
| 488 EXPECT_TRUE(this->SetCookie(cs, url3, "=")); |
| 489 EXPECT_EQ("", this->GetCookies(cs, url3)); |
| 490 |
| 491 GURL url4("http://foo4.bar.com"); |
| 492 EXPECT_TRUE(this->SetCookie(cs, url4, "foo")); |
| 493 EXPECT_TRUE(this->SetCookie(cs, url4, "")); |
| 494 EXPECT_EQ("", this->GetCookies(cs, url4)); |
| 495 |
| 496 GURL url5("http://foo5.bar.com"); |
| 497 EXPECT_TRUE(this->SetCookie(cs, url5, "foo")); |
| 498 EXPECT_TRUE(this->SetCookie(cs, url5, "; bar")); |
| 499 EXPECT_EQ("", this->GetCookies(cs, url5)); |
| 500 |
| 501 GURL url6("http://foo6.bar.com"); |
| 502 EXPECT_TRUE(this->SetCookie(cs, url6, "foo")); |
| 503 EXPECT_TRUE(this->SetCookie(cs, url6, " ")); |
| 504 EXPECT_EQ("", this->GetCookies(cs, url6)); |
| 505 #endif |
| 506 } |
| 507 |
468 TYPED_TEST_P(CookieStoreTest, DomainTest) { | 508 TYPED_TEST_P(CookieStoreTest, DomainTest) { |
469 CookieStore* cs = this->GetCookieStore(); | 509 CookieStore* cs = this->GetCookieStore(); |
470 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "A=B")); | 510 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "A=B")); |
471 this->MatchCookieLines("A=B", | 511 this->MatchCookieLines("A=B", |
472 this->GetCookies(cs, this->http_www_google_.url())); | 512 this->GetCookies(cs, this->http_www_google_.url())); |
473 EXPECT_TRUE( | 513 EXPECT_TRUE( |
474 this->SetCookie(cs, this->http_www_google_.url(), | 514 this->SetCookie(cs, this->http_www_google_.url(), |
475 this->http_www_google_.Format("C=D; domain=.%D"))); | 515 this->http_www_google_.Format("C=D; domain=.%D"))); |
476 this->MatchCookieLines("A=B; C=D", | 516 this->MatchCookieLines("A=B; C=D", |
477 this->GetCookies(cs, this->http_www_google_.url())); | 517 this->GetCookies(cs, this->http_www_google_.url())); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 | 595 |
556 // Test that setting a cookie which specifies an invalid domain has | 596 // Test that setting a cookie which specifies an invalid domain has |
557 // no side-effect. An invalid domain in this context is one which does | 597 // no side-effect. An invalid domain in this context is one which does |
558 // not match the originating domain. | 598 // not match the originating domain. |
559 TYPED_TEST_P(CookieStoreTest, InvalidDomainTest) { | 599 TYPED_TEST_P(CookieStoreTest, InvalidDomainTest) { |
560 CookieStore* cs = this->GetCookieStore(); | 600 CookieStore* cs = this->GetCookieStore(); |
561 GURL url_foobar("http://foo.bar.com"); | 601 GURL url_foobar("http://foo.bar.com"); |
562 | 602 |
563 // More specific sub-domain than allowed. | 603 // More specific sub-domain than allowed. |
564 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "a=1; domain=.yo.foo.bar.com")); | 604 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "a=1; domain=.yo.foo.bar.com")); |
| 605 // Regression test for https://crbug.com/601786 |
| 606 EXPECT_FALSE( |
| 607 this->SetCookie(cs, url_foobar, "a=1; domain=.yo.foo.bar.com; domain=")); |
565 | 608 |
566 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "b=2; domain=.foo.com")); | 609 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "b=2; domain=.foo.com")); |
567 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "c=3; domain=.bar.foo.com")); | 610 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "c=3; domain=.bar.foo.com")); |
568 | 611 |
569 // Different TLD, but the rest is a substring. | 612 // Different TLD, but the rest is a substring. |
570 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "d=4; domain=.foo.bar.com.net")); | 613 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "d=4; domain=.foo.bar.com.net")); |
571 | 614 |
572 // A substring that isn't really a parent domain. | 615 // A substring that isn't really a parent domain. |
573 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "e=5; domain=ar.com")); | 616 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "e=5; domain=ar.com")); |
574 | 617 |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 this->MatchCookieLines("A=B; C=D", | 1410 this->MatchCookieLines("A=B; C=D", |
1368 this->GetCookies(cs, this->http_www_google_.url())); | 1411 this->GetCookies(cs, this->http_www_google_.url())); |
1369 // Delete the session cookie. | 1412 // Delete the session cookie. |
1370 this->DeleteSessionCookies(cs); | 1413 this->DeleteSessionCookies(cs); |
1371 // Check that the session cookie has been deleted but not the persistent one. | 1414 // Check that the session cookie has been deleted but not the persistent one. |
1372 EXPECT_EQ("C=D", this->GetCookies(cs, this->http_www_google_.url())); | 1415 EXPECT_EQ("C=D", this->GetCookies(cs, this->http_www_google_.url())); |
1373 } | 1416 } |
1374 | 1417 |
1375 REGISTER_TYPED_TEST_CASE_P(CookieStoreTest, | 1418 REGISTER_TYPED_TEST_CASE_P(CookieStoreTest, |
1376 SetCookieWithDetailsAsync, | 1419 SetCookieWithDetailsAsync, |
| 1420 EmptyKeyTest, |
1377 DomainTest, | 1421 DomainTest, |
1378 DomainWithTrailingDotTest, | 1422 DomainWithTrailingDotTest, |
1379 ValidSubdomainTest, | 1423 ValidSubdomainTest, |
1380 InvalidDomainTest, | 1424 InvalidDomainTest, |
1381 InvalidDomainSameDomainAndRegistry, | 1425 InvalidDomainSameDomainAndRegistry, |
1382 DomainWithoutLeadingDotParentDomain, | 1426 DomainWithoutLeadingDotParentDomain, |
1383 DomainWithoutLeadingDotSameDomain, | 1427 DomainWithoutLeadingDotSameDomain, |
1384 CaseInsensitiveDomainTest, | 1428 CaseInsensitiveDomainTest, |
1385 TestIpAddress, | 1429 TestIpAddress, |
1386 TestIpAddressNoDomainCookies, | 1430 TestIpAddressNoDomainCookies, |
(...skipping 19 matching lines...) Expand all Loading... |
1406 OverwritePersistentCookie, | 1450 OverwritePersistentCookie, |
1407 CookieOrdering, | 1451 CookieOrdering, |
1408 GetAllCookiesAsync, | 1452 GetAllCookiesAsync, |
1409 DeleteCookieAsync, | 1453 DeleteCookieAsync, |
1410 DeleteCanonicalCookieAsync, | 1454 DeleteCanonicalCookieAsync, |
1411 DeleteSessionCookie); | 1455 DeleteSessionCookie); |
1412 | 1456 |
1413 } // namespace net | 1457 } // namespace net |
1414 | 1458 |
1415 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 1459 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
OLD | NEW |