Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Unified Diff: chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc

Issue 8533013: SessionRestore: Store session cookies and restore them if chrome crashes or auto-restarts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/net/sqlite_persistent_cookie_store.cc ('k') | chrome/browser/profiles/profile.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc
diff --git a/chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc b/chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc
index 98f7163b4d5f0482ba179e202905c742fd3f554c..1b6efdd3194a3edb54d2e9e08cbb00438cfef941 100644
--- a/chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc
+++ b/chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc
@@ -61,7 +61,7 @@ class SQLitePersistentCookieStoreTest : public testing::Test {
io_thread_.Start();
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
store_ = new SQLitePersistentCookieStore(
- temp_dir_.path().Append(chrome::kCookieFilename));
+ temp_dir_.path().Append(chrome::kCookieFilename), false);
std::vector<net::CookieMonster::CanonicalCookie*> cookies;
Load(&cookies);
ASSERT_EQ(0u, cookies.size());
@@ -131,7 +131,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestPersistance) {
// Make sure we wait until the destructor has run.
ASSERT_TRUE(helper->Run());
store_ = new SQLitePersistentCookieStore(
- temp_dir_.path().Append(chrome::kCookieFilename));
+ temp_dir_.path().Append(chrome::kCookieFilename), false);
// Reload and test for persistence
Load(&cookies);
@@ -148,7 +148,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestPersistance) {
STLDeleteContainerPointers(cookies.begin(), cookies.end());
cookies.clear();
store_ = new SQLitePersistentCookieStore(
- temp_dir_.path().Append(chrome::kCookieFilename));
+ temp_dir_.path().Append(chrome::kCookieFilename), false);
// Reload and check if the cookie has been removed.
Load(&cookies);
@@ -186,7 +186,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestLoadCookiesForKey) {
ASSERT_TRUE(helper->Run());
store_ = new SQLitePersistentCookieStore(
- temp_dir_.path().Append(chrome::kCookieFilename));
+ temp_dir_.path().Append(chrome::kCookieFilename), false);
// 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.
BrowserThread::PostTask(
@@ -302,3 +302,163 @@ TEST_F(SQLitePersistentCookieStoreTest, TestFlushCompletionCallback) {
ASSERT_EQ(1, counter->callback_count());
}
+
+// Test loading old session cookies from the disk.
+TEST_F(SQLitePersistentCookieStoreTest, TestLoadOldSessionCookies) {
+ std::vector<net::CookieMonster::CanonicalCookie*> cookies;
+
+ // Use a separate cookie store for this test.
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ store_ = new SQLitePersistentCookieStore(
+ temp_dir.path().Append(chrome::kCookieFilename), true);
+ // Make sure the database is initialized.
+ Load(&cookies);
+ ASSERT_EQ(0u, cookies.size());
+
+ // Add a session cookie.
+ store_->AddCookie(
+ net::CookieMonster::CanonicalCookie(
+ GURL(), "C", "D", "http://sessioncookie.com", "/", std::string(),
+ std::string(), base::Time::Now(), base::Time::Now(),
+ base::Time::Now(), false, false, true, false /*is_persistent*/));
+
+ // Force the store to write its data to the disk.
+ store_ = NULL;
+ scoped_refptr<base::ThreadTestHelper> helper(
+ new base::ThreadTestHelper(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)));
+ // Make sure we wait until the destructor has run.
+ ASSERT_TRUE(helper->Run());
+
+ // Create a store that loads session cookies.
+ store_ = new SQLitePersistentCookieStore(
+ temp_dir.path().Append(chrome::kCookieFilename), true);
+
+ // Reload and test that the session cookie was loaded.
+ Load(&cookies);
+ ASSERT_EQ(1U, cookies.size());
+ ASSERT_STREQ("http://sessioncookie.com", cookies[0]->Domain().c_str());
+ ASSERT_STREQ("C", cookies[0]->Name().c_str());
+ ASSERT_STREQ("D", cookies[0]->Value().c_str());
+}
+
+// Test loading old session cookies from the disk.
+TEST_F(SQLitePersistentCookieStoreTest, TestDontLoadOldSessionCookies) {
+ std::vector<net::CookieMonster::CanonicalCookie*> cookies;
+ // Use a separate cookie store for this test.
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ store_ = new SQLitePersistentCookieStore(
+ temp_dir.path().Append(chrome::kCookieFilename), true);
+ // Make sure the database is initialized.
+ Load(&cookies);
+ ASSERT_EQ(0u, cookies.size());
+
+ // Add a session cookie.
+ store_->AddCookie(
+ net::CookieMonster::CanonicalCookie(
+ GURL(), "C", "D", "http://sessioncookie.com", "/", std::string(),
+ std::string(), base::Time::Now(), base::Time::Now(),
+ base::Time::Now(), false, false, true, false /*is_persistent*/));
+
+ // Force the store to write its data to the disk.
+ store_ = NULL;
+ scoped_refptr<base::ThreadTestHelper> helper(
+ new base::ThreadTestHelper(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)));
+ // Make sure we wait until the destructor has run.
+ ASSERT_TRUE(helper->Run());
+
+ // Create a store that doesn't load old session cookies.
+ store_ = new SQLitePersistentCookieStore(
+ temp_dir.path().Append(chrome::kCookieFilename), false);
+
+ // Reload and test that the session cookie was not loaded.
+ Load(&cookies);
+ ASSERT_EQ(0U, cookies.size());
+
+ // The store should also delete the session cookie. Wait until that has been
+ // done.
+ store_ = NULL;
+ helper = new base::ThreadTestHelper(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB));
+ ASSERT_TRUE(helper->Run());
+
+ // Create a store that loads old session cookies.
+ store_ = new SQLitePersistentCookieStore(
+ temp_dir.path().Append(chrome::kCookieFilename), true);
+
+ // Reload and test that the session cookie is gone.
+ Load(&cookies);
+ ASSERT_EQ(0U, cookies.size());
+}
+
+TEST_F(SQLitePersistentCookieStoreTest, PersistHasExpiresAndIsPersistent) {
+ std::vector<net::CookieMonster::CanonicalCookie*> cookies;
+
+ // Use a separate cookie store for this test.
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ store_ = new SQLitePersistentCookieStore(
+ temp_dir.path().Append(chrome::kCookieFilename), true);
+ // Make sure the database is initialized.
+ Load(&cookies);
+ ASSERT_EQ(0u, cookies.size());
+
+ // Add a session cookie with has_expires = false, and another session cookie
+ // with has_expires = true.
+ store_->AddCookie(
+ net::CookieMonster::CanonicalCookie(
+ GURL(), "session-hasexpires", "val", "http://sessioncookie.com", "/",
+ std::string(), std::string(),
+ base::Time::Now() - base::TimeDelta::FromDays(3), base::Time::Now(),
+ base::Time::Now(), false, false, true /* has_expires */,
+ false /* is_persistent */));
+ store_->AddCookie(
+ net::CookieMonster::CanonicalCookie(
+ GURL(), "session-noexpires", "val", "http://sessioncookie.com", "/",
+ std::string(), std::string(),
+ base::Time::Now() - base::TimeDelta::FromDays(2), base::Time::Now(),
+ base::Time::Now(), false, false, false /* has_expires */,
+ false /* is_persistent */));
+ // Add a persistent cookie.
+ store_->AddCookie(
+ net::CookieMonster::CanonicalCookie(
+ GURL(), "persistent", "val", "http://sessioncookie.com", "/",
+ std::string(), std::string(),
+ base::Time::Now() - base::TimeDelta::FromDays(1), base::Time::Now(),
+ base::Time::Now(), false, false, true /* has_expires */,
+ true /* is_persistent */));
+
+ // Force the store to write its data to the disk.
+ store_ = NULL;
+ scoped_refptr<base::ThreadTestHelper> helper(
+ new base::ThreadTestHelper(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)));
+ // Make sure we wait until the destructor has run.
+ ASSERT_TRUE(helper->Run());
+
+ // Create a store that loads session cookies.
+ store_ = new SQLitePersistentCookieStore(
+ temp_dir.path().Append(chrome::kCookieFilename), true);
+
+ // Reload and test that the the DoesExpire and IsPersistent attributes are
+ // restored.
+ Load(&cookies);
+ ASSERT_EQ(3U, cookies.size());
+
+ std::map<std::string, net::CookieMonster::CanonicalCookie*> cookie_map;
+ std::vector<net::CookieMonster::CanonicalCookie*>::const_iterator it;
+ for (it = cookies.begin(); it != cookies.end(); ++it)
+ cookie_map[(*it)->Name()] = *it;
+
+ EXPECT_TRUE(cookie_map["session-hasexpires"]->DoesExpire());
+ EXPECT_FALSE(cookie_map["session-hasexpires"]->IsPersistent());
+
+ EXPECT_FALSE(cookie_map["session-noexpires"]->DoesExpire());
+ EXPECT_FALSE(cookie_map["session-noexpires"]->IsPersistent());
+
+ EXPECT_TRUE(cookie_map["persistent"]->DoesExpire());
+ EXPECT_TRUE(cookie_map["persistent"]->IsPersistent());
+}
« no previous file with comments | « chrome/browser/net/sqlite_persistent_cookie_store.cc ('k') | chrome/browser/profiles/profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698