Chromium Code Reviews| Index: net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc |
| diff --git a/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc b/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc |
| index 2166be022a1fe061dc7a242dd4938a94e5606bde..90392bb864948c21aa3739f92e8c156edc74d8e4 100644 |
| --- a/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc |
| +++ b/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc |
| @@ -168,9 +168,9 @@ class SQLitePersistentCookieStoreTest : public testing::Test { |
| const std::string& domain, |
| const std::string& path, |
| const base::Time& creation) { |
| - store_->AddCookie(CanonicalCookie(GURL(), name, value, domain, path, |
| - creation, creation, creation, false, |
| - false, false, COOKIE_PRIORITY_DEFAULT)); |
| + store_->AddCookie(CanonicalCookie( |
| + GURL(), name, value, domain, path, creation, creation, creation, false, |
| + false, COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
| } |
| void AddCookieWithExpiration(const std::string& name, |
| @@ -179,9 +179,9 @@ class SQLitePersistentCookieStoreTest : public testing::Test { |
| const std::string& path, |
| const base::Time& creation, |
| const base::Time& expiration) { |
| - store_->AddCookie(CanonicalCookie(GURL(), name, value, domain, path, |
| - creation, expiration, creation, false, |
| - false, false, COOKIE_PRIORITY_DEFAULT)); |
| + store_->AddCookie(CanonicalCookie( |
| + GURL(), name, value, domain, path, creation, expiration, creation, |
| + false, false, COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
| } |
| std::string ReadRawDBContents() { |
| @@ -442,10 +442,10 @@ TEST_F(SQLitePersistentCookieStoreTest, TestLoadOldSessionCookies) { |
| InitializeStore(false, true); |
| // Add a session cookie. |
| - store_->AddCookie(CanonicalCookie(GURL(), "C", "D", "sessioncookie.com", "/", |
| - base::Time::Now(), base::Time(), |
| - base::Time::Now(), false, false, false, |
| - COOKIE_PRIORITY_DEFAULT)); |
| + store_->AddCookie(CanonicalCookie( |
| + GURL(), "C", "D", "sessioncookie.com", "/", base::Time::Now(), |
| + base::Time(), base::Time::Now(), false, false, COOKIE_SAME_SITE_DEFAULT, |
| + COOKIE_PRIORITY_DEFAULT)); |
| // Force the store to write its data to the disk. |
| DestroyStore(); |
| @@ -469,10 +469,10 @@ TEST_F(SQLitePersistentCookieStoreTest, TestDontLoadOldSessionCookies) { |
| InitializeStore(false, true); |
| // Add a session cookie. |
| - store_->AddCookie(CanonicalCookie(GURL(), "C", "D", "sessioncookie.com", "/", |
| - base::Time::Now(), base::Time(), |
| - base::Time::Now(), false, false, false, |
| - COOKIE_PRIORITY_DEFAULT)); |
| + store_->AddCookie(CanonicalCookie( |
| + GURL(), "C", "D", "sessioncookie.com", "/", base::Time::Now(), |
| + base::Time(), base::Time::Now(), false, false, COOKIE_SAME_SITE_DEFAULT, |
| + COOKIE_PRIORITY_DEFAULT)); |
| // Force the store to write its data to the disk. |
| DestroyStore(); |
| @@ -499,16 +499,16 @@ TEST_F(SQLitePersistentCookieStoreTest, PersistIsPersistent) { |
| static const char kPersistentName[] = "persistent"; |
| // Add a session cookie. |
| - store_->AddCookie(CanonicalCookie(GURL(), kSessionName, "val", |
| - "sessioncookie.com", "/", base::Time::Now(), |
| - base::Time(), base::Time::Now(), false, |
| - false, false, COOKIE_PRIORITY_DEFAULT)); |
| + store_->AddCookie(CanonicalCookie( |
| + GURL(), kSessionName, "val", "sessioncookie.com", "/", base::Time::Now(), |
| + base::Time(), base::Time::Now(), false, false, COOKIE_SAME_SITE_DEFAULT, |
| + COOKIE_PRIORITY_DEFAULT)); |
| // Add a persistent cookie. |
| store_->AddCookie(CanonicalCookie( |
| GURL(), kPersistentName, "val", "sessioncookie.com", "/", |
| base::Time::Now() - base::TimeDelta::FromDays(1), |
| base::Time::Now() + base::TimeDelta::FromDays(1), base::Time::Now(), |
| - false, false, false, COOKIE_PRIORITY_DEFAULT)); |
| + false, false, COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
| // Force the store to write its data to the disk. |
| DestroyStore(); |
| @@ -552,21 +552,21 @@ TEST_F(SQLitePersistentCookieStoreTest, PriorityIsPersistent) { |
| GURL(), kLowName, kCookieValue, kCookieDomain, kCookiePath, |
| base::Time::Now() - base::TimeDelta::FromMinutes(1), |
| base::Time::Now() + base::TimeDelta::FromDays(1), base::Time::Now(), |
| - false, false, false, COOKIE_PRIORITY_LOW)); |
| + false, false, COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_LOW)); |
| // Add a medium-priority persistent cookie. |
| store_->AddCookie(CanonicalCookie( |
| GURL(), kMediumName, kCookieValue, kCookieDomain, kCookiePath, |
| base::Time::Now() - base::TimeDelta::FromMinutes(2), |
| base::Time::Now() + base::TimeDelta::FromDays(1), base::Time::Now(), |
| - false, false, false, COOKIE_PRIORITY_MEDIUM)); |
| + false, false, COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_MEDIUM)); |
| // Add a high-priority peristent cookie. |
| store_->AddCookie(CanonicalCookie( |
| GURL(), kHighName, kCookieValue, kCookieDomain, kCookiePath, |
| base::Time::Now() - base::TimeDelta::FromMinutes(3), |
| base::Time::Now() + base::TimeDelta::FromDays(1), base::Time::Now(), |
| - false, false, false, COOKIE_PRIORITY_HIGH)); |
| + false, false, COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_HIGH)); |
| // Force the store to write its data to the disk. |
| DestroyStore(); |
| @@ -601,6 +601,70 @@ TEST_F(SQLitePersistentCookieStoreTest, PriorityIsPersistent) { |
| STLDeleteElements(&cookies); |
| } |
| +TEST_F(SQLitePersistentCookieStoreTest, SameSiteIsPersistent) { |
| + static const char kNoneName[] = "none"; |
| + static const char kLaxName[] = "lax"; |
| + static const char kStrictName[] = "strict"; |
| + static const char kCookieDomain[] = "sessioncookie.com"; |
| + static const char kCookieValue[] = "value"; |
| + static const char kCookiePath[] = "/"; |
|
mmenke
2016/03/11 18:08:31
I think the preference is not to use "static" in t
|
| + |
| + InitializeStore(false, true); |
| + |
| + // Add a non-samesite cookie. |
| + store_->AddCookie(CanonicalCookie( |
| + GURL(), kNoneName, kCookieValue, kCookieDomain, kCookiePath, |
| + base::Time::Now() - base::TimeDelta::FromMinutes(1), |
| + base::Time::Now() + base::TimeDelta::FromDays(1), base::Time::Now(), |
| + false, false, COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT)); |
| + |
| + // Add a lax-samesite persistent cookie. |
| + store_->AddCookie(CanonicalCookie( |
| + GURL(), kLaxName, kCookieValue, kCookieDomain, kCookiePath, |
| + base::Time::Now() - base::TimeDelta::FromMinutes(2), |
| + base::Time::Now() + base::TimeDelta::FromDays(1), base::Time::Now(), |
| + false, false, COOKIE_SAME_SITE_LAX, COOKIE_PRIORITY_DEFAULT)); |
| + |
| + // Add a strict-samesite peristent cookie. |
| + store_->AddCookie(CanonicalCookie( |
| + GURL(), kStrictName, kCookieValue, kCookieDomain, kCookiePath, |
| + base::Time::Now() - base::TimeDelta::FromMinutes(3), |
| + base::Time::Now() + base::TimeDelta::FromDays(1), base::Time::Now(), |
| + false, false, COOKIE_SAME_SITE_STRICT, COOKIE_PRIORITY_DEFAULT)); |
| + |
| + // Force the store to write its data to the disk. |
| + DestroyStore(); |
| + |
| + // Create a store that loads session cookie and test that the priority |
| + // attribute values are restored. |
| + CanonicalCookieVector cookies; |
| + CreateAndLoad(false, true, &cookies); |
| + ASSERT_EQ(3U, cookies.size()); |
| + |
| + // Put the cookies into a map, by name, so we can easily find them. |
|
mmenke
2016/03/11 18:08:31
nit: --"we"
Mike West
2016/03/14 10:18:54
1. Ugh. I continue to not like this rule. :/
2. Th
mmenke
2016/03/14 20:14:50
Up to you.
|
| + std::map<std::string, CanonicalCookie*> cookie_map; |
| + for (CanonicalCookieVector::const_iterator it = cookies.begin(); |
| + it != cookies.end(); ++it) { |
| + cookie_map[(*it)->Name()] = *it; |
| + } |
|
mmenke
2016/03/11 18:08:31
optional: Suggest just using a range loop, and ma
Mike West
2016/03/14 10:18:54
Done.
|
| + |
| + // Validate that each cookie has the correct samesite. |
|
mmenke
2016/03/11 18:08:31
SameSite?
Mike West
2016/03/14 10:18:54
Indeed.
|
| + std::map<std::string, CanonicalCookie*>::const_iterator it = |
| + cookie_map.find(kNoneName); |
| + ASSERT_TRUE(it != cookie_map.end()); |
|
mmenke
2016/03/11 18:08:31
Combining these two lines seems a little simpler,
Mike West
2016/03/14 10:18:54
Yup. Makes sense.
|
| + EXPECT_EQ(COOKIE_SAME_SITE_NONE, cookie_map[kNoneName]->SameSite()); |
| + |
| + it = cookie_map.find(kLaxName); |
| + ASSERT_TRUE(it != cookie_map.end()); |
| + EXPECT_EQ(COOKIE_SAME_SITE_LAX, cookie_map[kLaxName]->SameSite()); |
| + |
| + it = cookie_map.find(kStrictName); |
| + ASSERT_TRUE(it != cookie_map.end()); |
| + EXPECT_EQ(COOKIE_SAME_SITE_STRICT, cookie_map[kStrictName]->SameSite()); |
| + |
| + STLDeleteElements(&cookies); |
| +} |
| + |
| TEST_F(SQLitePersistentCookieStoreTest, UpdateToEncryption) { |
| CanonicalCookieVector cookies; |