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

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

Issue 14208017: Add cookie priority to the cookie database. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unittests and rebase onto Sam's change. Created 7 years, 8 months 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
Index: content/browser/net/sqlite_persistent_cookie_store_unittest.cc
diff --git a/content/browser/net/sqlite_persistent_cookie_store_unittest.cc b/content/browser/net/sqlite_persistent_cookie_store_unittest.cc
index 8a72fcfea53e5c336e18044148a3fc62e0808652..a5940ca3da5580ce9115a575d1103aaf348092f9 100644
--- a/content/browser/net/sqlite_persistent_cookie_store_unittest.cc
+++ b/content/browser/net/sqlite_persistent_cookie_store_unittest.cc
@@ -331,6 +331,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::PRIORITY_DEFAULT, cookies[0]->Priority());
STLDeleteElements(&cookies);
}
@@ -380,11 +381,15 @@ TEST_F(SQLitePersistentCookieStoreTest, PersistIsPersistent) {
store_->AddCookie(
net::CanonicalCookie(
GURL(), kPersistentName, "val", "sessioncookie.com", "/",
- base::Time::Now() - base::TimeDelta::FromDays(1), base::Time::Now(),
+ base::Time::Now() - base::TimeDelta::FromDays(1),
+ base::Time::Now() + base::TimeDelta::FromDays(1),
base::Time::Now(), false, false,
net::PRIORITY_DEFAULT));
- // Create a store that loads session cookie and test that the the IsPersistent
+ // Force the store to write its data to the disk.
+ DestroyStore();
Roger McFarlane (Chromium) 2013/04/18 18:54:29 This seemed to be missing from the test (on compar
+
+ // Create a store that loads session cookie and test that the IsPersistent
// attribute is restored.
CanonicalCookieVector cookies;
CreateAndLoad(true, &cookies);
@@ -409,4 +414,89 @@ TEST_F(SQLitePersistentCookieStoreTest, PersistIsPersistent) {
STLDeleteElements(&cookies);
}
+TEST_F(SQLitePersistentCookieStoreTest, PriorityIsPersistent) {
+ static const char kLowName[] = "low";
+ static const char kMediumName[] = "medium";
+ static const char kHighName[] = "high";
+ static const char kDefaultName[] = "default";
+ static const char kCookieDomain[] = "sessioncookie.com";
+ static const char kCookieValue[] = "value";
+ static const char kCookiePath[] = "/";
+
+ InitializeStore(true);
+
+ // Add a low-priority persistent cookie.
+ store_->AddCookie(
+ net::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,
+ net::PRIORITY_LOW));
+
+ // Add a medium-priority persistent cookie.
+ store_->AddCookie(
+ net::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,
+ net::PRIORITY_MEDIUM));
+
+ // Add a high-priority peristent cookie.
+ store_->AddCookie(
+ net::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,
+ net::PRIORITY_HIGH));
+
+ // Add a default-priority persistent cookie.
erikwright (departed) 2013/04/18 19:34:05 I would remove this one - it's not testing anythin
Roger McFarlane (Chromium) 2013/04/19 20:53:03 Done.
+ store_->AddCookie(
+ net::CanonicalCookie(
+ GURL(), kDefaultName, kCookieValue, kCookieDomain, kCookiePath,
+ base::Time::Now() - base::TimeDelta::FromMinutes(4),
+ base::Time::Now() + base::TimeDelta::FromDays(1),
+ base::Time::Now(), false, false,
+ net::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(true, &cookies);
+ ASSERT_EQ(4U, cookies.size());
+
+ // Put the cookies into a map, by name, so we can easily find them.
+ std::map<std::string, net::CanonicalCookie*> cookie_map;
+ for (CanonicalCookieVector::const_iterator it = cookies.begin();
+ 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 =
+ cookie_map.find(kLowName);
+ ASSERT_TRUE(it != cookie_map.end());
+ EXPECT_EQ(net::PRIORITY_LOW, cookie_map[kLowName]->Priority());
+
+ it = cookie_map.find(kMediumName);
+ ASSERT_TRUE(it != cookie_map.end());
+ EXPECT_EQ(net::PRIORITY_MEDIUM, cookie_map[kMediumName]->Priority());
+
+ it = cookie_map.find(kHighName);
+ ASSERT_TRUE(it != cookie_map.end());
+ EXPECT_EQ(net::PRIORITY_HIGH, cookie_map[kHighName]->Priority());
+
+ it = cookie_map.find(kDefaultName);
+ ASSERT_TRUE(it != cookie_map.end());
+ EXPECT_EQ(net::PRIORITY_DEFAULT, cookie_map[kDefaultName]->Priority());
+
+ STLDeleteElements(&cookies);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698