| 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 2c9b7a1197d3b0a6ed4c5d26de169d5695614782..b70877da038934ce5d9ffa629f4e6329038b6627 100644
|
| --- a/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc
|
| +++ b/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc
|
| @@ -167,27 +167,25 @@ class SQLitePersistentCookieStoreTest : public testing::Test {
|
| void WaitOnDBEvent() { db_thread_event_.Wait(); }
|
|
|
| // Adds a persistent cookie to store_.
|
| - void AddCookie(const GURL& url,
|
| - const std::string& name,
|
| + void AddCookie(const std::string& name,
|
| const std::string& value,
|
| const std::string& domain,
|
| const std::string& path,
|
| const base::Time& creation) {
|
| store_->AddCookie(*CanonicalCookie::Create(
|
| - url, name, value, domain, path, creation, creation, false, false,
|
| - CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
|
| + name, value, domain, path, creation, creation, base::Time(), false,
|
| + false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
|
| }
|
|
|
| - void AddCookieWithExpiration(const GURL& url,
|
| - const std::string& name,
|
| + void AddCookieWithExpiration(const std::string& name,
|
| const std::string& value,
|
| const std::string& domain,
|
| const std::string& path,
|
| const base::Time& creation,
|
| const base::Time& expiration) {
|
| store_->AddCookie(*CanonicalCookie::Create(
|
| - url, name, value, domain, path, creation, expiration, false, false,
|
| - CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
|
| + name, value, domain, path, creation, expiration, base::Time(), false,
|
| + false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
|
| }
|
|
|
| std::string ReadRawDBContents() {
|
| @@ -217,8 +215,7 @@ class SQLitePersistentCookieStoreTest : public testing::Test {
|
|
|
| TEST_F(SQLitePersistentCookieStoreTest, TestInvalidMetaTableRecovery) {
|
| InitializeStore(false, false);
|
| - AddCookie(GURL("http://foo.bar"), "A", "B", std::string(), "/",
|
| - base::Time::Now());
|
| + AddCookie("A", "B", "foo.bar", "/", base::Time::Now());
|
| DestroyStore();
|
|
|
| // Load up the store and verify that it has good data in it.
|
| @@ -246,8 +243,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestInvalidMetaTableRecovery) {
|
| ASSERT_EQ(0U, cookies.size());
|
|
|
| // Verify that, after, recovery, the database persists properly.
|
| - AddCookie(GURL("http://foo.bar"), "X", "Y", std::string(), "/",
|
| - base::Time::Now());
|
| + AddCookie("X", "Y", "foo.bar", "/", base::Time::Now());
|
| DestroyStore();
|
| CreateAndLoad(false, false, &cookies);
|
| ASSERT_EQ(1U, cookies.size());
|
| @@ -260,8 +256,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestInvalidMetaTableRecovery) {
|
| // Test if data is stored as expected in the SQLite database.
|
| TEST_F(SQLitePersistentCookieStoreTest, TestPersistance) {
|
| InitializeStore(false, false);
|
| - AddCookie(GURL("http://foo.bar"), "A", "B", std::string(), "/",
|
| - base::Time::Now());
|
| + AddCookie("A", "B", "foo.bar", "/", base::Time::Now());
|
| // Replace the store effectively destroying the current one and forcing it
|
| // to write its data to disk. Then we can see if after loading it again it
|
| // is still there.
|
| @@ -291,28 +286,23 @@ TEST_F(SQLitePersistentCookieStoreTest, TestSessionCookiesDeletedOnStartup) {
|
|
|
| // Add persistent cookies.
|
| base::Time t = base::Time::Now();
|
| - AddCookie(GURL("http://a1.com"), "A", "B", std::string(), "/", t);
|
| + AddCookie("A", "B", "a1.com", "/", t);
|
| t += base::TimeDelta::FromInternalValue(10);
|
| - AddCookie(GURL("http://a2.com"), "A", "B", std::string(), "/", t);
|
| + AddCookie("A", "B", "a2.com", "/", t);
|
| t += base::TimeDelta::FromInternalValue(10);
|
| - AddCookie(GURL("http://a3.com"), "A", "B", std::string(), "/", t);
|
| + AddCookie("A", "B", "a3.com", "/", t);
|
|
|
| // Add transient cookies.
|
| t += base::TimeDelta::FromInternalValue(10);
|
| - AddCookieWithExpiration(GURL("http://b1.com"), "A", "B", std::string(), "/",
|
| - t, base::Time());
|
| + AddCookieWithExpiration("A", "B", "b1.com", "/", t, base::Time());
|
| t += base::TimeDelta::FromInternalValue(10);
|
| - AddCookieWithExpiration(GURL("http://b2.com"), "A", "B", std::string(), "/",
|
| - t, base::Time());
|
| + AddCookieWithExpiration("A", "B", "b2.com", "/", t, base::Time());
|
| t += base::TimeDelta::FromInternalValue(10);
|
| - AddCookieWithExpiration(GURL("http://b3.com"), "A", "B", std::string(), "/",
|
| - t, base::Time());
|
| + AddCookieWithExpiration("A", "B", "b3.com", "/", t, base::Time());
|
| t += base::TimeDelta::FromInternalValue(10);
|
| - AddCookieWithExpiration(GURL("http://b4.com"), "A", "B", std::string(), "/",
|
| - t, base::Time());
|
| + AddCookieWithExpiration("A", "B", "b4.com", "/", t, base::Time());
|
| t += base::TimeDelta::FromInternalValue(10);
|
| - AddCookieWithExpiration(GURL("http://b5.com"), "A", "B", std::string(), "/",
|
| - t, base::Time());
|
| + AddCookieWithExpiration("A", "B", "b5.com", "/", t, base::Time());
|
| DestroyStore();
|
|
|
| // Load the store a second time. Before the store finishes loading, add a
|
| @@ -329,8 +319,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestSessionCookiesDeletedOnStartup) {
|
| store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded,
|
| base::Unretained(this)));
|
| t += base::TimeDelta::FromInternalValue(10);
|
| - AddCookieWithExpiration(GURL("http://c.com"), "A", "B", std::string(), "/", t,
|
| - base::Time());
|
| + AddCookieWithExpiration("A", "B", "c.com", "/", t, base::Time());
|
| base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
|
| base::WaitableEvent::InitialState::NOT_SIGNALED);
|
| store_->Flush(
|
| @@ -367,13 +356,13 @@ TEST_F(SQLitePersistentCookieStoreTest, TestSessionCookiesDeletedOnStartup) {
|
| TEST_F(SQLitePersistentCookieStoreTest, TestLoadCookiesForKey) {
|
| InitializeStore(false, false);
|
| base::Time t = base::Time::Now();
|
| - AddCookie(GURL("http://foo.bar"), "A", "B", std::string(), "/", t);
|
| + AddCookie("A", "B", "foo.bar", "/", t);
|
| t += base::TimeDelta::FromInternalValue(10);
|
| - AddCookie(GURL("http://www.aaa.com"), "A", "B", std::string(), "/", t);
|
| + AddCookie("A", "B", "www.aaa.com", "/", t);
|
| t += base::TimeDelta::FromInternalValue(10);
|
| - AddCookie(GURL("http://travel.aaa.com"), "A", "B", std::string(), "/", t);
|
| + AddCookie("A", "B", "travel.aaa.com", "/", t);
|
| t += base::TimeDelta::FromInternalValue(10);
|
| - AddCookie(GURL("http://www.bbb.com"), "A", "B", std::string(), "/", t);
|
| + AddCookie("A", "B", "www.bbb.com", "/", t);
|
| DestroyStore();
|
|
|
| store_ = new SQLitePersistentCookieStore(
|
| @@ -443,7 +432,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestFlush) {
|
| base::Time t = base::Time::Now() + base::TimeDelta::FromMicroseconds(c);
|
| std::string name(1, c);
|
| std::string value(1000, c);
|
| - AddCookie(GURL("http://foo.bar"), name, value, std::string(), "/", t);
|
| + AddCookie(name, value, "foo.bar", "/", t);
|
| }
|
|
|
| Flush();
|
| @@ -459,9 +448,9 @@ TEST_F(SQLitePersistentCookieStoreTest, TestLoadOldSessionCookies) {
|
|
|
| // Add a session cookie.
|
| store_->AddCookie(*CanonicalCookie::Create(
|
| - GURL("http://sessioncookie.com"), "C", "D", std::string(), "/",
|
| - base::Time::Now(), base::Time(), false, false,
|
| - CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
|
| + "C", "D", "sessioncookie.com", "/", base::Time::Now(), base::Time(),
|
| + base::Time(), false, false, CookieSameSite::DEFAULT_MODE,
|
| + COOKIE_PRIORITY_DEFAULT));
|
|
|
| // Force the store to write its data to the disk.
|
| DestroyStore();
|
| @@ -486,9 +475,9 @@ TEST_F(SQLitePersistentCookieStoreTest, TestDontLoadOldSessionCookies) {
|
|
|
| // Add a session cookie.
|
| store_->AddCookie(*CanonicalCookie::Create(
|
| - GURL("http://sessioncookie.com"), "C", "D", std::string(), "/",
|
| - base::Time::Now(), base::Time(), false, false,
|
| - CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
|
| + "C", "D", "sessioncookie.com", "/", base::Time::Now(), base::Time(),
|
| + base::Time(), false, false, CookieSameSite::DEFAULT_MODE,
|
| + COOKIE_PRIORITY_DEFAULT));
|
|
|
| // Force the store to write its data to the disk.
|
| DestroyStore();
|
| @@ -516,15 +505,15 @@ TEST_F(SQLitePersistentCookieStoreTest, PersistIsPersistent) {
|
|
|
| // Add a session cookie.
|
| store_->AddCookie(*CanonicalCookie::Create(
|
| - GURL("http://sessioncookie.com"), kSessionName, "val", std::string(), "/",
|
| - base::Time::Now(), base::Time(), false, false,
|
| - CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
|
| + kSessionName, "val", "sessioncookie.com", "/", base::Time::Now(),
|
| + base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE,
|
| + COOKIE_PRIORITY_DEFAULT));
|
| // Add a persistent cookie.
|
| store_->AddCookie(*CanonicalCookie::Create(
|
| - GURL("http://sessioncookie.com"), kPersistentName, "val", std::string(),
|
| - "/", base::Time::Now() - base::TimeDelta::FromDays(1),
|
| - base::Time::Now() + base::TimeDelta::FromDays(1), false, false,
|
| - CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
|
| + kPersistentName, "val", "sessioncookie.com", "/",
|
| + base::Time::Now() - base::TimeDelta::FromDays(1),
|
| + base::Time::Now() + base::TimeDelta::FromDays(1), base::Time(), false,
|
| + false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
|
|
|
| // Force the store to write its data to the disk.
|
| DestroyStore();
|
| @@ -551,7 +540,7 @@ TEST_F(SQLitePersistentCookieStoreTest, PersistIsPersistent) {
|
| }
|
|
|
| TEST_F(SQLitePersistentCookieStoreTest, PriorityIsPersistent) {
|
| - static const char kURL[] = "http://sessioncookie.com";
|
| + static const char kDomain[] = "sessioncookie.com";
|
| static const char kLowName[] = "low";
|
| static const char kMediumName[] = "medium";
|
| static const char kHighName[] = "high";
|
| @@ -562,24 +551,24 @@ TEST_F(SQLitePersistentCookieStoreTest, PriorityIsPersistent) {
|
|
|
| // Add a low-priority persistent cookie.
|
| store_->AddCookie(*CanonicalCookie::Create(
|
| - GURL(kURL), kLowName, kCookieValue, std::string(), kCookiePath,
|
| + kLowName, kCookieValue, kDomain, kCookiePath,
|
| base::Time::Now() - base::TimeDelta::FromMinutes(1),
|
| - base::Time::Now() + base::TimeDelta::FromDays(1), false, false,
|
| - CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_LOW));
|
| + base::Time::Now() + base::TimeDelta::FromDays(1), base::Time(), false,
|
| + false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_LOW));
|
|
|
| // Add a medium-priority persistent cookie.
|
| store_->AddCookie(*CanonicalCookie::Create(
|
| - GURL(kURL), kMediumName, kCookieValue, std::string(), kCookiePath,
|
| + kMediumName, kCookieValue, kDomain, kCookiePath,
|
| base::Time::Now() - base::TimeDelta::FromMinutes(2),
|
| - base::Time::Now() + base::TimeDelta::FromDays(1), false, false,
|
| - CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_MEDIUM));
|
| + base::Time::Now() + base::TimeDelta::FromDays(1), base::Time(), false,
|
| + false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_MEDIUM));
|
|
|
| // Add a high-priority peristent cookie.
|
| store_->AddCookie(*CanonicalCookie::Create(
|
| - GURL(kURL), kHighName, kCookieValue, std::string(), kCookiePath,
|
| + kHighName, kCookieValue, kDomain, kCookiePath,
|
| base::Time::Now() - base::TimeDelta::FromMinutes(3),
|
| - base::Time::Now() + base::TimeDelta::FromDays(1), false, false,
|
| - CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_HIGH));
|
| + base::Time::Now() + base::TimeDelta::FromDays(1), base::Time(), false,
|
| + false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_HIGH));
|
|
|
| // Force the store to write its data to the disk.
|
| DestroyStore();
|
| @@ -612,7 +601,7 @@ TEST_F(SQLitePersistentCookieStoreTest, PriorityIsPersistent) {
|
| }
|
|
|
| TEST_F(SQLitePersistentCookieStoreTest, SameSiteIsPersistent) {
|
| - const char kURL[] = "http://sessioncookie.com";
|
| + const char kDomain[] = "sessioncookie.com";
|
| const char kNoneName[] = "none";
|
| const char kLaxName[] = "lax";
|
| const char kStrictName[] = "strict";
|
| @@ -623,24 +612,24 @@ TEST_F(SQLitePersistentCookieStoreTest, SameSiteIsPersistent) {
|
|
|
| // Add a non-samesite cookie.
|
| store_->AddCookie(*CanonicalCookie::Create(
|
| - GURL(kURL), kNoneName, kCookieValue, std::string(), kCookiePath,
|
| + kNoneName, kCookieValue, kDomain, kCookiePath,
|
| base::Time::Now() - base::TimeDelta::FromMinutes(1),
|
| - base::Time::Now() + base::TimeDelta::FromDays(1), false, false,
|
| - CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT));
|
| + base::Time::Now() + base::TimeDelta::FromDays(1), base::Time(), false,
|
| + false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT));
|
|
|
| // Add a lax-samesite persistent cookie.
|
| store_->AddCookie(*CanonicalCookie::Create(
|
| - GURL(kURL), kLaxName, kCookieValue, std::string(), kCookiePath,
|
| + kLaxName, kCookieValue, kDomain, kCookiePath,
|
| base::Time::Now() - base::TimeDelta::FromMinutes(2),
|
| - base::Time::Now() + base::TimeDelta::FromDays(1), false, false,
|
| - CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT));
|
| + base::Time::Now() + base::TimeDelta::FromDays(1), base::Time(), false,
|
| + false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT));
|
|
|
| // Add a strict-samesite persistent cookie.
|
| store_->AddCookie(*CanonicalCookie::Create(
|
| - GURL(kURL), kStrictName, kCookieValue, std::string(), kCookiePath,
|
| + kStrictName, kCookieValue, kDomain, kCookiePath,
|
| base::Time::Now() - base::TimeDelta::FromMinutes(3),
|
| - base::Time::Now() + base::TimeDelta::FromDays(1), false, false,
|
| - CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT));
|
| + base::Time::Now() + base::TimeDelta::FromDays(1), base::Time(), false,
|
| + false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT));
|
|
|
| // Force the store to write its data to the disk.
|
| DestroyStore();
|
| @@ -674,8 +663,7 @@ TEST_F(SQLitePersistentCookieStoreTest, UpdateToEncryption) {
|
|
|
| // Create unencrypted cookie store and write something to it.
|
| InitializeStore(false, false);
|
| - AddCookie(GURL("http://foo.bar"), "name", "value123XYZ", std::string(), "/",
|
| - base::Time::Now());
|
| + AddCookie("name", "value123XYZ", "foo.bar", "/", base::Time::Now());
|
| DestroyStore();
|
|
|
| // Verify that "value" is visible in the file. This is necessary in order to
|
| @@ -694,10 +682,9 @@ TEST_F(SQLitePersistentCookieStoreTest, UpdateToEncryption) {
|
|
|
| // Make sure we can update existing cookie and add new cookie as encrypted.
|
| store_->DeleteCookie(*(cookies[0]));
|
| - AddCookie(GURL("http://foo.bar"), "name", "encrypted_value123XYZ",
|
| - std::string(), "/", base::Time::Now());
|
| - AddCookie(GURL("http://foo.bar"), "other", "something456ABC", std::string(),
|
| - "/", base::Time::Now() + base::TimeDelta::FromInternalValue(10));
|
| + AddCookie("name", "encrypted_value123XYZ", "foo.bar", "/", base::Time::Now());
|
| + AddCookie("other", "something456ABC", "foo.bar", "/",
|
| + base::Time::Now() + base::TimeDelta::FromInternalValue(10));
|
| DestroyStore();
|
| cookies.clear();
|
| CreateAndLoad(true, false, &cookies);
|
| @@ -746,8 +733,7 @@ TEST_F(SQLitePersistentCookieStoreTest, UpdateFromEncryption) {
|
|
|
| // Create unencrypted cookie store and write something to it.
|
| InitializeStore(true, false);
|
| - AddCookie(GURL("http://foo.bar"), "name", "value123XYZ", std::string(), "/",
|
| - base::Time::Now());
|
| + AddCookie("name", "value123XYZ", "foo.bar", "/", base::Time::Now());
|
| DestroyStore();
|
|
|
| // Verify that "value" is not visible in the file.
|
| @@ -766,10 +752,9 @@ TEST_F(SQLitePersistentCookieStoreTest, UpdateFromEncryption) {
|
| // Make sure we can update existing cookie and it writes unencrypted.
|
| cookie_crypto_delegate_->should_encrypt_ = false;
|
| store_->DeleteCookie(*(cookies[0]));
|
| - AddCookie(GURL("http://foo.bar"), "name", "plaintext_value123XYZ",
|
| - std::string(), "/", base::Time::Now());
|
| - AddCookie(GURL("http://foo.bar"), "other", "something456ABC", std::string(),
|
| - "/", base::Time::Now() + base::TimeDelta::FromInternalValue(10));
|
| + AddCookie("name", "plaintext_value123XYZ", "foo.bar", "/", base::Time::Now());
|
| + AddCookie("other", "something456ABC", "foo.bar", "/",
|
| + base::Time::Now() + base::TimeDelta::FromInternalValue(10));
|
| DestroyStore();
|
| cookies.clear();
|
| CreateAndLoad(true, false, &cookies);
|
| @@ -805,8 +790,7 @@ void WasCalledWithNoCookies(
|
| TEST_F(SQLitePersistentCookieStoreTest, EmptyLoadAfterClose) {
|
| // Create unencrypted cookie store and write something to it.
|
| InitializeStore(false, false);
|
| - AddCookie(GURL("http://foo.bar"), "name", "value123XYZ", std::string(), "/",
|
| - base::Time::Now());
|
| + AddCookie("name", "value123XYZ", "foo.bar", "/", base::Time::Now());
|
| DestroyStore();
|
|
|
| // Create the cookie store, but immediately close it.
|
|
|