| Index: net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc
|
| diff --git a/content/browser/net/sqlite_persistent_cookie_store_unittest.cc b/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc
|
| similarity index 88%
|
| rename from content/browser/net/sqlite_persistent_cookie_store_unittest.cc
|
| rename to net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc
|
| index af7859a26a9f1695dc4e8aa7a809245b2ebfad18..fc043293c27211f746ecfd041aebf312e34817b0 100644
|
| --- a/content/browser/net/sqlite_persistent_cookie_store_unittest.cc
|
| +++ b/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "content/browser/net/sqlite_persistent_cookie_store.h"
|
| +#include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
|
|
|
| #include <map>
|
| #include <set>
|
| @@ -11,15 +11,14 @@
|
| #include "base/callback.h"
|
| #include "base/files/file_util.h"
|
| #include "base/files/scoped_temp_dir.h"
|
| +#include "base/location.h"
|
| #include "base/memory/ref_counted.h"
|
| -#include "base/message_loop/message_loop.h"
|
| #include "base/sequenced_task_runner.h"
|
| #include "base/stl_util.h"
|
| #include "base/synchronization/waitable_event.h"
|
| #include "base/test/sequenced_worker_pool_owner.h"
|
| #include "base/threading/sequenced_worker_pool.h"
|
| #include "base/time/time.h"
|
| -#include "content/public/browser/cookie_store_factory.h"
|
| #include "crypto/encryptor.h"
|
| #include "crypto/symmetric_key.h"
|
| #include "net/cookies/canonical_cookie.h"
|
| @@ -31,13 +30,13 @@
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "url/gurl.h"
|
|
|
| -namespace content {
|
| +namespace net {
|
|
|
| namespace {
|
|
|
| const base::FilePath::CharType kCookieFilename[] = FILE_PATH_LITERAL("Cookies");
|
|
|
| -class CookieCryptor : public net::CookieCryptoDelegate {
|
| +class CookieCryptor : public CookieCryptoDelegate {
|
| public:
|
| CookieCryptor();
|
| bool EncryptString(const std::string& plaintext,
|
| @@ -69,7 +68,7 @@ bool CookieCryptor::DecryptString(const std::string& ciphertext,
|
|
|
| } // namespace
|
|
|
| -typedef std::vector<net::CanonicalCookie*> CanonicalCookieVector;
|
| +typedef std::vector<CanonicalCookie*> CanonicalCookieVector;
|
|
|
| class SQLitePersistentCookieStoreTest : public testing::Test {
|
| public:
|
| @@ -106,17 +105,25 @@ class SQLitePersistentCookieStoreTest : public testing::Test {
|
| }
|
|
|
| scoped_refptr<base::SequencedTaskRunner> background_task_runner() {
|
| - return pool_owner_->pool()->GetSequencedTaskRunner(
|
| - pool_owner_->pool()->GetNamedSequenceToken("background"));
|
| + if (!background_task_runner_.get()) {
|
| + background_task_runner_ = pool_owner_->pool()->GetSequencedTaskRunner(
|
| + pool_owner_->pool()->GetNamedSequenceToken("background"));
|
| + }
|
| + return background_task_runner_;
|
| }
|
|
|
| scoped_refptr<base::SequencedTaskRunner> client_task_runner() {
|
| - return pool_owner_->pool()->GetSequencedTaskRunner(
|
| - pool_owner_->pool()->GetNamedSequenceToken("client"));
|
| + if (!client_task_runner_.get()) {
|
| + client_task_runner_ = pool_owner_->pool()->GetSequencedTaskRunner(
|
| + pool_owner_->pool()->GetNamedSequenceToken("client"));
|
| + }
|
| + return client_task_runner_;
|
| }
|
|
|
| void DestroyStore() {
|
| - store_ = NULL;
|
| + store_ = nullptr;
|
| + background_task_runner_ = nullptr;
|
| + client_task_runner_ = nullptr;
|
| // Make sure we wait until the destructor has run by shutting down the pool
|
| // resetting the owner (whose destructor blocks on the pool completion).
|
| pool_owner_->pool()->Shutdown();
|
| @@ -136,7 +143,6 @@ class SQLitePersistentCookieStoreTest : public testing::Test {
|
| client_task_runner(),
|
| background_task_runner(),
|
| restore_old_session_cookies,
|
| - NULL,
|
| cookie_crypto_delegate_.get());
|
| Load(cookies);
|
| }
|
| @@ -159,9 +165,9 @@ class SQLitePersistentCookieStoreTest : public testing::Test {
|
| const std::string& domain,
|
| const std::string& path,
|
| const base::Time& creation) {
|
| - store_->AddCookie(net::CanonicalCookie(
|
| + store_->AddCookie(CanonicalCookie(
|
| GURL(), name, value, domain, path, creation, creation, creation, false,
|
| - false, false, net::COOKIE_PRIORITY_DEFAULT));
|
| + false, false, COOKIE_PRIORITY_DEFAULT));
|
| }
|
|
|
| void AddCookieWithExpiration(const std::string& name,
|
| @@ -170,9 +176,9 @@ class SQLitePersistentCookieStoreTest : public testing::Test {
|
| const std::string& path,
|
| const base::Time& creation,
|
| const base::Time& expiration) {
|
| - store_->AddCookie(net::CanonicalCookie(
|
| + store_->AddCookie(CanonicalCookie(
|
| GURL(), name, value, domain, path, creation, expiration, creation,
|
| - false, false, false, net::COOKIE_PRIORITY_DEFAULT));
|
| + false, false, false, COOKIE_PRIORITY_DEFAULT));
|
| }
|
|
|
| std::string ReadRawDBContents() {
|
| @@ -191,15 +197,16 @@ class SQLitePersistentCookieStoreTest : public testing::Test {
|
| }
|
|
|
| protected:
|
| - base::MessageLoop main_loop_;
|
| scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_;
|
| + scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
|
| + scoped_refptr<base::SequencedTaskRunner> client_task_runner_;
|
| base::WaitableEvent loaded_event_;
|
| base::WaitableEvent key_loaded_event_;
|
| base::WaitableEvent db_thread_event_;
|
| CanonicalCookieVector cookies_;
|
| base::ScopedTempDir temp_dir_;
|
| scoped_refptr<SQLitePersistentCookieStore> store_;
|
| - scoped_ptr<net::CookieCryptoDelegate> cookie_crypto_delegate_;
|
| + scoped_ptr<CookieCryptoDelegate> cookie_crypto_delegate_;
|
| };
|
|
|
| TEST_F(SQLitePersistentCookieStoreTest, TestInvalidMetaTableRecovery) {
|
| @@ -300,7 +307,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestSessionCookiesDeletedOnStartup) {
|
| temp_dir_.path().Append(kCookieFilename),
|
| client_task_runner(),
|
| background_task_runner(),
|
| - false, NULL, NULL);
|
| + false, nullptr);
|
|
|
| // Posting a blocking task to db_thread_ makes sure that the DB thread waits
|
| // until both Load and Flush have been posted to its task queue.
|
| @@ -336,7 +343,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestSessionCookiesDeletedOnStartup) {
|
| temp_dir_.path().Append(kCookieFilename),
|
| client_task_runner(),
|
| background_task_runner(),
|
| - true, NULL, NULL);
|
| + true, nullptr);
|
| store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded,
|
| base::Unretained(this)));
|
| loaded_event_.Wait();
|
| @@ -362,7 +369,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestLoadCookiesForKey) {
|
| temp_dir_.path().Append(kCookieFilename),
|
| client_task_runner(),
|
| background_task_runner(),
|
| - false, NULL, NULL);
|
| + false, nullptr);
|
|
|
| // Posting a blocking task to db_thread_ makes sure that the DB thread waits
|
| // until both Load and LoadCookiesForKey have been posted to its task queue.
|
| @@ -447,10 +454,10 @@ TEST_F(SQLitePersistentCookieStoreTest, TestLoadOldSessionCookies) {
|
| InitializeStore(false, true);
|
|
|
| // Add a session cookie.
|
| - store_->AddCookie(net::CanonicalCookie(GURL(), "C", "D", "sessioncookie.com",
|
| - "/", base::Time::Now(), base::Time(),
|
| - base::Time::Now(), false, false, false,
|
| - net::COOKIE_PRIORITY_DEFAULT));
|
| + store_->AddCookie(CanonicalCookie(GURL(), "C", "D", "sessioncookie.com",
|
| + "/", base::Time::Now(), base::Time(),
|
| + base::Time::Now(), false, false, false,
|
| + COOKIE_PRIORITY_DEFAULT));
|
|
|
| // Force the store to write its data to the disk.
|
| DestroyStore();
|
| @@ -464,7 +471,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestLoadOldSessionCookies) {
|
| ASSERT_STREQ("sessioncookie.com", cookies[0]->Domain().c_str());
|
| ASSERT_STREQ("C", cookies[0]->Name().c_str());
|
| ASSERT_STREQ("D", cookies[0]->Value().c_str());
|
| - ASSERT_EQ(net::COOKIE_PRIORITY_DEFAULT, cookies[0]->Priority());
|
| + ASSERT_EQ(COOKIE_PRIORITY_DEFAULT, cookies[0]->Priority());
|
|
|
| STLDeleteElements(&cookies);
|
| }
|
| @@ -474,10 +481,10 @@ TEST_F(SQLitePersistentCookieStoreTest, TestDontLoadOldSessionCookies) {
|
| InitializeStore(false, true);
|
|
|
| // Add a session cookie.
|
| - store_->AddCookie(net::CanonicalCookie(GURL(), "C", "D", "sessioncookie.com",
|
| - "/", base::Time::Now(), base::Time(),
|
| - base::Time::Now(), false, false, false,
|
| - net::COOKIE_PRIORITY_DEFAULT));
|
| + store_->AddCookie(CanonicalCookie(GURL(), "C", "D", "sessioncookie.com",
|
| + "/", base::Time::Now(), base::Time(),
|
| + base::Time::Now(), false, false, false,
|
| + COOKIE_PRIORITY_DEFAULT));
|
|
|
| // Force the store to write its data to the disk.
|
| DestroyStore();
|
| @@ -504,16 +511,16 @@ TEST_F(SQLitePersistentCookieStoreTest, PersistIsPersistent) {
|
| static const char kPersistentName[] = "persistent";
|
|
|
| // Add a session cookie.
|
| - store_->AddCookie(net::CanonicalCookie(
|
| + store_->AddCookie(CanonicalCookie(
|
| GURL(), kSessionName, "val", "sessioncookie.com", "/", base::Time::Now(),
|
| base::Time(), base::Time::Now(), false, false, false,
|
| - net::COOKIE_PRIORITY_DEFAULT));
|
| + COOKIE_PRIORITY_DEFAULT));
|
| // Add a persistent cookie.
|
| - store_->AddCookie(net::CanonicalCookie(
|
| + 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, net::COOKIE_PRIORITY_DEFAULT));
|
| + false, false, false, COOKIE_PRIORITY_DEFAULT));
|
|
|
| // Force the store to write its data to the disk.
|
| DestroyStore();
|
| @@ -524,14 +531,14 @@ TEST_F(SQLitePersistentCookieStoreTest, PersistIsPersistent) {
|
| CreateAndLoad(false, true, &cookies);
|
| ASSERT_EQ(2U, cookies.size());
|
|
|
| - std::map<std::string, net::CanonicalCookie*> cookie_map;
|
| + std::map<std::string, CanonicalCookie*> cookie_map;
|
| for (CanonicalCookieVector::const_iterator it = cookies.begin();
|
| it != cookies.end();
|
| ++it) {
|
| cookie_map[(*it)->Name()] = *it;
|
| }
|
|
|
| - std::map<std::string, net::CanonicalCookie*>::const_iterator it =
|
| + std::map<std::string, CanonicalCookie*>::const_iterator it =
|
| cookie_map.find(kSessionName);
|
| ASSERT_TRUE(it != cookie_map.end());
|
| EXPECT_FALSE(cookie_map[kSessionName]->IsPersistent());
|
| @@ -554,25 +561,25 @@ TEST_F(SQLitePersistentCookieStoreTest, PriorityIsPersistent) {
|
| InitializeStore(false, true);
|
|
|
| // Add a low-priority persistent cookie.
|
| - store_->AddCookie(net::CanonicalCookie(
|
| + store_->AddCookie(CanonicalCookie(
|
| 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, net::COOKIE_PRIORITY_LOW));
|
| + false, false, false, COOKIE_PRIORITY_LOW));
|
|
|
| // Add a medium-priority persistent cookie.
|
| - store_->AddCookie(net::CanonicalCookie(
|
| + 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, net::COOKIE_PRIORITY_MEDIUM));
|
| + false, false, false, COOKIE_PRIORITY_MEDIUM));
|
|
|
| // Add a high-priority peristent cookie.
|
| - store_->AddCookie(net::CanonicalCookie(
|
| + 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, net::COOKIE_PRIORITY_HIGH));
|
| + false, false, false, COOKIE_PRIORITY_HIGH));
|
|
|
| // Force the store to write its data to the disk.
|
| DestroyStore();
|
| @@ -584,7 +591,7 @@ TEST_F(SQLitePersistentCookieStoreTest, PriorityIsPersistent) {
|
| ASSERT_EQ(3U, cookies.size());
|
|
|
| // Put the cookies into a map, by name, so we can easily find them.
|
| - std::map<std::string, net::CanonicalCookie*> cookie_map;
|
| + std::map<std::string, CanonicalCookie*> cookie_map;
|
| for (CanonicalCookieVector::const_iterator it = cookies.begin();
|
| it != cookies.end();
|
| ++it) {
|
| @@ -592,18 +599,18 @@ TEST_F(SQLitePersistentCookieStoreTest, PriorityIsPersistent) {
|
| }
|
|
|
| // Validate that each cookie has the correct priority.
|
| - std::map<std::string, net::CanonicalCookie*>::const_iterator it =
|
| + std::map<std::string, CanonicalCookie*>::const_iterator it =
|
| cookie_map.find(kLowName);
|
| ASSERT_TRUE(it != cookie_map.end());
|
| - EXPECT_EQ(net::COOKIE_PRIORITY_LOW, cookie_map[kLowName]->Priority());
|
| + EXPECT_EQ(COOKIE_PRIORITY_LOW, cookie_map[kLowName]->Priority());
|
|
|
| it = cookie_map.find(kMediumName);
|
| ASSERT_TRUE(it != cookie_map.end());
|
| - EXPECT_EQ(net::COOKIE_PRIORITY_MEDIUM, cookie_map[kMediumName]->Priority());
|
| + EXPECT_EQ(COOKIE_PRIORITY_MEDIUM, cookie_map[kMediumName]->Priority());
|
|
|
| it = cookie_map.find(kHighName);
|
| ASSERT_TRUE(it != cookie_map.end());
|
| - EXPECT_EQ(net::COOKIE_PRIORITY_HIGH, cookie_map[kHighName]->Priority());
|
| + EXPECT_EQ(COOKIE_PRIORITY_HIGH, cookie_map[kHighName]->Priority());
|
|
|
| STLDeleteElements(&cookies);
|
| }
|
| @@ -639,8 +646,8 @@ TEST_F(SQLitePersistentCookieStoreTest, UpdateToEncryption) {
|
| STLDeleteElements(&cookies_);
|
| CreateAndLoad(true, false, &cookies);
|
| EXPECT_EQ(2U, cookies_.size());
|
| - net::CanonicalCookie* cookie_name = NULL;
|
| - net::CanonicalCookie* cookie_other = NULL;
|
| + CanonicalCookie* cookie_name = nullptr;
|
| + CanonicalCookie* cookie_other = nullptr;
|
| if (cookies_[0]->Name() == "name") {
|
| cookie_name = cookies_[0];
|
| cookie_other = cookies_[1];
|
| @@ -678,4 +685,4 @@ TEST_F(SQLitePersistentCookieStoreTest, UpdateToEncryption) {
|
| EXPECT_EQ(contents.find("something456ABC"), std::string::npos);
|
| }
|
|
|
| -} // namespace content
|
| +} // namespace net
|
|
|