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 // Test enforcement around setting secure cookies. |
| 469 TYPED_TEST_P(CookieStoreTest, SetCookieWithDetailsSecureEnforcement) { |
| 470 CookieStore* cs = this->GetCookieStore(); |
| 471 GURL http_url(this->http_www_google_.url()); |
| 472 std::string http_domain(http_url.host()); |
| 473 GURL https_url(this->https_www_google_.url()); |
| 474 std::string https_domain(https_url.host()); |
| 475 |
| 476 // Confirm that setting the secure attribute on an HTTP URL fails, but |
| 477 // the other combinations work. |
| 478 EXPECT_TRUE(this->SetCookieWithDetails( |
| 479 cs, http_url, "A", "B", http_domain, "/", base::Time::Now(), base::Time(), |
| 480 base::Time(), false, false, CookieSameSite::NO_RESTRICTION, |
| 481 COOKIE_PRIORITY_DEFAULT)); |
| 482 EXPECT_FALSE(this->SetCookieWithDetails( |
| 483 cs, http_url, "A", "B", http_domain, "/", base::Time::Now(), base::Time(), |
| 484 base::Time(), true, false, CookieSameSite::NO_RESTRICTION, |
| 485 COOKIE_PRIORITY_DEFAULT)); |
| 486 EXPECT_TRUE(this->SetCookieWithDetails( |
| 487 cs, https_url, "A", "B", https_domain, "/", base::Time::Now(), |
| 488 base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION, |
| 489 COOKIE_PRIORITY_DEFAULT)); |
| 490 EXPECT_TRUE(this->SetCookieWithDetails( |
| 491 cs, https_url, "A", "B", https_domain, "/", base::Time::Now(), |
| 492 base::Time(), base::Time(), true, false, CookieSameSite::NO_RESTRICTION, |
| 493 COOKIE_PRIORITY_DEFAULT)); |
| 494 } |
| 495 |
468 // The iOS networking stack uses the iOS cookie parser, which we do not | 496 // 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 | 497 // 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 | 498 // behavior of most UAs in some cases, which we try to replicate. See |
471 // https://crbug.com/638389 for more information. | 499 // https://crbug.com/638389 for more information. |
472 TYPED_TEST_P(CookieStoreTest, EmptyKeyTest) { | 500 TYPED_TEST_P(CookieStoreTest, EmptyKeyTest) { |
473 #if !defined(OS_IOS) | 501 #if !defined(OS_IOS) |
474 CookieStore* cs = this->GetCookieStore(); | 502 CookieStore* cs = this->GetCookieStore(); |
475 | 503 |
476 GURL url1("http://foo1.bar.com"); | 504 GURL url1("http://foo1.bar.com"); |
477 EXPECT_TRUE(this->SetCookie(cs, url1, "foo")); | 505 EXPECT_TRUE(this->SetCookie(cs, url1, "foo")); |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1416 this->MatchCookieLines("A=B; C=D", | 1444 this->MatchCookieLines("A=B; C=D", |
1417 this->GetCookies(cs, this->http_www_google_.url())); | 1445 this->GetCookies(cs, this->http_www_google_.url())); |
1418 // Delete the session cookie. | 1446 // Delete the session cookie. |
1419 this->DeleteSessionCookies(cs); | 1447 this->DeleteSessionCookies(cs); |
1420 // Check that the session cookie has been deleted but not the persistent one. | 1448 // Check that the session cookie has been deleted but not the persistent one. |
1421 EXPECT_EQ("C=D", this->GetCookies(cs, this->http_www_google_.url())); | 1449 EXPECT_EQ("C=D", this->GetCookies(cs, this->http_www_google_.url())); |
1422 } | 1450 } |
1423 | 1451 |
1424 REGISTER_TYPED_TEST_CASE_P(CookieStoreTest, | 1452 REGISTER_TYPED_TEST_CASE_P(CookieStoreTest, |
1425 SetCookieWithDetailsAsync, | 1453 SetCookieWithDetailsAsync, |
| 1454 SetCookieWithDetailsSecureEnforcement, |
1426 EmptyKeyTest, | 1455 EmptyKeyTest, |
1427 DomainTest, | 1456 DomainTest, |
1428 DomainWithTrailingDotTest, | 1457 DomainWithTrailingDotTest, |
1429 ValidSubdomainTest, | 1458 ValidSubdomainTest, |
1430 InvalidDomainTest, | 1459 InvalidDomainTest, |
1431 InvalidDomainSameDomainAndRegistry, | 1460 InvalidDomainSameDomainAndRegistry, |
1432 DomainWithoutLeadingDotParentDomain, | 1461 DomainWithoutLeadingDotParentDomain, |
1433 DomainWithoutLeadingDotSameDomain, | 1462 DomainWithoutLeadingDotSameDomain, |
1434 CaseInsensitiveDomainTest, | 1463 CaseInsensitiveDomainTest, |
1435 TestIpAddress, | 1464 TestIpAddress, |
(...skipping 20 matching lines...) Expand all Loading... |
1456 OverwritePersistentCookie, | 1485 OverwritePersistentCookie, |
1457 CookieOrdering, | 1486 CookieOrdering, |
1458 GetAllCookiesAsync, | 1487 GetAllCookiesAsync, |
1459 DeleteCookieAsync, | 1488 DeleteCookieAsync, |
1460 DeleteCanonicalCookieAsync, | 1489 DeleteCanonicalCookieAsync, |
1461 DeleteSessionCookie); | 1490 DeleteSessionCookie); |
1462 | 1491 |
1463 } // namespace net | 1492 } // namespace net |
1464 | 1493 |
1465 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 1494 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
OLD | NEW |