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 82% |
rename from content/browser/net/sqlite_persistent_cookie_store_unittest.cc |
rename to net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc |
index af7859a26a9f1695dc4e8aa7a809245b2ebfad18..6dc3810f8f63501b64be06cca7e5d2af5ed45975 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, |
@@ -50,9 +49,13 @@ class CookieCryptor : public net::CookieCryptoDelegate { |
crypto::Encryptor encryptor_; |
}; |
-CookieCryptor::CookieCryptor() : key_( |
- crypto::SymmetricKey::DeriveKeyFromPassword( |
- crypto::SymmetricKey::AES, "password", "saltiest", 1000, 256)) { |
+CookieCryptor::CookieCryptor() |
+ : key_( |
+ crypto::SymmetricKey::DeriveKeyFromPassword(crypto::SymmetricKey::AES, |
+ "password", |
+ "saltiest", |
+ 1000, |
+ 256)) { |
std::string iv("the iv: 16 bytes"); |
encryptor_.Init(key_.get(), crypto::Encryptor::CBC, iv); |
} |
@@ -69,7 +72,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: |
@@ -77,8 +80,7 @@ class SQLitePersistentCookieStoreTest : public testing::Test { |
: pool_owner_(new base::SequencedWorkerPoolOwner(3, "Background Pool")), |
loaded_event_(false, false), |
key_loaded_event_(false, false), |
- db_thread_event_(false, false) { |
- } |
+ db_thread_event_(false, false) {} |
void OnLoaded(const CanonicalCookieVector& cookies) { |
cookies_ = cookies; |
@@ -100,8 +102,8 @@ class SQLitePersistentCookieStoreTest : public testing::Test { |
void Flush() { |
base::WaitableEvent event(false, false); |
- store_->Flush(base::Bind(&base::WaitableEvent::Signal, |
- base::Unretained(&event))); |
+ store_->Flush( |
+ base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
event.Wait(); |
} |
@@ -116,7 +118,7 @@ class SQLitePersistentCookieStoreTest : public testing::Test { |
} |
void DestroyStore() { |
- store_ = NULL; |
+ store_ = 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(); |
@@ -132,11 +134,8 @@ class SQLitePersistentCookieStoreTest : public testing::Test { |
cookie_crypto_delegate_.reset(new CookieCryptor()); |
store_ = new SQLitePersistentCookieStore( |
- temp_dir_.path().Append(kCookieFilename), |
- client_task_runner(), |
- background_task_runner(), |
- restore_old_session_cookies, |
- NULL, |
+ temp_dir_.path().Append(kCookieFilename), client_task_runner(), |
+ background_task_runner(), restore_old_session_cookies, |
cookie_crypto_delegate_.get()); |
Load(cookies); |
} |
@@ -149,9 +148,7 @@ class SQLitePersistentCookieStoreTest : public testing::Test { |
// We have to create this method to wrap WaitableEvent::Wait, since we cannot |
// bind a non-void returning method as a Closure. |
- void WaitOnDBEvent() { |
- db_thread_event_.Wait(); |
- } |
+ void WaitOnDBEvent() { db_thread_event_.Wait(); } |
// Adds a persistent cookie to store_. |
void AddCookie(const std::string& name, |
@@ -159,9 +156,9 @@ class SQLitePersistentCookieStoreTest : public testing::Test { |
const std::string& domain, |
const std::string& path, |
const base::Time& creation) { |
- store_->AddCookie(net::CanonicalCookie( |
- GURL(), name, value, domain, path, creation, creation, creation, false, |
- false, false, net::COOKIE_PRIORITY_DEFAULT)); |
+ store_->AddCookie(CanonicalCookie(GURL(), name, value, domain, path, |
+ creation, creation, creation, false, |
+ false, false, COOKIE_PRIORITY_DEFAULT)); |
} |
void AddCookieWithExpiration(const std::string& name, |
@@ -170,9 +167,9 @@ class SQLitePersistentCookieStoreTest : public testing::Test { |
const std::string& path, |
const base::Time& creation, |
const base::Time& expiration) { |
- store_->AddCookie(net::CanonicalCookie( |
- GURL(), name, value, domain, path, creation, expiration, creation, |
- false, false, false, net::COOKIE_PRIORITY_DEFAULT)); |
+ store_->AddCookie(CanonicalCookie(GURL(), name, value, domain, path, |
+ creation, expiration, creation, false, |
+ false, false, COOKIE_PRIORITY_DEFAULT)); |
} |
std::string ReadRawDBContents() { |
@@ -191,7 +188,6 @@ class SQLitePersistentCookieStoreTest : public testing::Test { |
} |
protected: |
- base::MessageLoop main_loop_; |
scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_; |
base::WaitableEvent loaded_event_; |
base::WaitableEvent key_loaded_event_; |
@@ -199,7 +195,7 @@ class SQLitePersistentCookieStoreTest : public testing::Test { |
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) { |
@@ -297,24 +293,21 @@ TEST_F(SQLitePersistentCookieStoreTest, TestSessionCookiesDeletedOnStartup) { |
// Load the store a second time. Before the store finishes loading, add a |
// transient cookie and flush it to disk. |
store_ = new SQLitePersistentCookieStore( |
- temp_dir_.path().Append(kCookieFilename), |
- client_task_runner(), |
- background_task_runner(), |
- false, NULL, NULL); |
+ temp_dir_.path().Append(kCookieFilename), client_task_runner(), |
+ background_task_runner(), 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. |
background_task_runner()->PostTask( |
- FROM_HERE, |
- base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, |
- base::Unretained(this))); |
+ FROM_HERE, base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, |
+ base::Unretained(this))); |
store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, |
base::Unretained(this))); |
t += base::TimeDelta::FromInternalValue(10); |
AddCookieWithExpiration("A", "B", "c.com", "/", t, base::Time()); |
base::WaitableEvent event(false, false); |
- store_->Flush(base::Bind(&base::WaitableEvent::Signal, |
- base::Unretained(&event))); |
+ store_->Flush( |
+ base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
// Now the DB-thread queue contains: |
// (active:) |
@@ -333,10 +326,8 @@ TEST_F(SQLitePersistentCookieStoreTest, TestSessionCookiesDeletedOnStartup) { |
// store should contain exactly 4 cookies: the 3 persistent, and "c.com", |
// which was added during the second cookie store load. |
store_ = new SQLitePersistentCookieStore( |
- temp_dir_.path().Append(kCookieFilename), |
- client_task_runner(), |
- background_task_runner(), |
- true, NULL, NULL); |
+ temp_dir_.path().Append(kCookieFilename), client_task_runner(), |
+ background_task_runner(), true, nullptr); |
store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, |
base::Unretained(this))); |
loaded_event_.Wait(); |
@@ -359,26 +350,22 @@ TEST_F(SQLitePersistentCookieStoreTest, TestLoadCookiesForKey) { |
DestroyStore(); |
store_ = new SQLitePersistentCookieStore( |
- temp_dir_.path().Append(kCookieFilename), |
- client_task_runner(), |
- background_task_runner(), |
- false, NULL, NULL); |
+ temp_dir_.path().Append(kCookieFilename), client_task_runner(), |
+ background_task_runner(), 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. |
background_task_runner()->PostTask( |
- FROM_HERE, |
- base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, |
- base::Unretained(this))); |
+ FROM_HERE, base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, |
+ base::Unretained(this))); |
store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, |
base::Unretained(this))); |
- store_->LoadCookiesForKey("aaa.com", |
- base::Bind(&SQLitePersistentCookieStoreTest::OnKeyLoaded, |
- base::Unretained(this))); |
+ store_->LoadCookiesForKey( |
+ "aaa.com", base::Bind(&SQLitePersistentCookieStoreTest::OnKeyLoaded, |
+ base::Unretained(this))); |
background_task_runner()->PostTask( |
- FROM_HERE, |
- base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, |
- base::Unretained(this))); |
+ FROM_HERE, base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, |
+ base::Unretained(this))); |
// Now the DB-thread queue contains: |
// (active:) |
@@ -392,8 +379,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestLoadCookiesForKey) { |
ASSERT_EQ(loaded_event_.IsSignaled(), false); |
std::set<std::string> cookies_loaded; |
for (CanonicalCookieVector::const_iterator it = cookies_.begin(); |
- it != cookies_.end(); |
- ++it) { |
+ it != cookies_.end(); ++it) { |
cookies_loaded.insert((*it)->Domain().c_str()); |
} |
STLDeleteElements(&cookies_); |
@@ -405,13 +391,11 @@ TEST_F(SQLitePersistentCookieStoreTest, TestLoadCookiesForKey) { |
db_thread_event_.Signal(); |
loaded_event_.Wait(); |
for (CanonicalCookieVector::const_iterator it = cookies_.begin(); |
- it != cookies_.end(); |
- ++it) { |
+ it != cookies_.end(); ++it) { |
cookies_loaded.insert((*it)->Domain().c_str()); |
} |
ASSERT_EQ(4U, cookies_loaded.size()); |
- ASSERT_EQ(cookies_loaded.find("foo.bar") != cookies_loaded.end(), |
- true); |
+ ASSERT_EQ(cookies_loaded.find("foo.bar") != cookies_loaded.end(), true); |
ASSERT_EQ(cookies_loaded.find("www.bbb.com") != cookies_loaded.end(), true); |
STLDeleteElements(&cookies_); |
} |
@@ -447,10 +431,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 +448,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 +458,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 +488,16 @@ TEST_F(SQLitePersistentCookieStoreTest, PersistIsPersistent) { |
static const char kPersistentName[] = "persistent"; |
// Add a session cookie. |
- store_->AddCookie(net::CanonicalCookie( |
- GURL(), kSessionName, "val", "sessioncookie.com", "/", base::Time::Now(), |
- base::Time(), base::Time::Now(), false, false, false, |
- net::COOKIE_PRIORITY_DEFAULT)); |
+ store_->AddCookie(CanonicalCookie(GURL(), kSessionName, "val", |
+ "sessioncookie.com", "/", base::Time::Now(), |
+ base::Time(), base::Time::Now(), false, |
+ false, false, 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 +508,13 @@ 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) { |
+ 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 +537,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,26 +567,25 @@ 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) { |
+ it != cookies.end(); ++it) { |
cookie_map[(*it)->Name()] = *it; |
} |
// 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 +621,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]; |
@@ -664,7 +646,7 @@ TEST_F(SQLitePersistentCookieStoreTest, UpdateToEncryption) { |
"WHERE host_key = 'foo.bar'")); |
while (smt.Step()) { |
resultcount++; |
- for (int i=0; i < smt.ColumnCount(); i++) { |
+ for (int i = 0; i < smt.ColumnCount(); i++) { |
EXPECT_EQ(smt.ColumnString(i).find("value"), std::string::npos); |
EXPECT_EQ(smt.ColumnString(i).find("something"), std::string::npos); |
} |
@@ -678,4 +660,4 @@ TEST_F(SQLitePersistentCookieStoreTest, UpdateToEncryption) { |
EXPECT_EQ(contents.find("something456ABC"), std::string::npos); |
} |
-} // namespace content |
+} // namespace net |