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

Unified Diff: net/cookies/parsed_cookie_unittest.cc

Issue 14113014: Adding Priority field to cookies. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed enums PRIORITY_* to COOKIE_PRIORITY_*. 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
« no previous file with comments | « net/cookies/parsed_cookie.cc ('k') | net/net.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cookies/parsed_cookie_unittest.cc
diff --git a/net/cookies/parsed_cookie_unittest.cc b/net/cookies/parsed_cookie_unittest.cc
index 57de115a2796878359cb86edd30439f9d017aa7c..ad4aba65d79c440d0705022de998f3d2c9eaa8b1 100644
--- a/net/cookies/parsed_cookie_unittest.cc
+++ b/net/cookies/parsed_cookie_unittest.cc
@@ -4,17 +4,12 @@
#include <string>
+#include "net/cookies/cookie_constants.h"
#include "net/cookies/parsed_cookie.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
-namespace {
-
-class ParsedCookieTest : public testing::Test { };
-
-} // namespace
-
TEST(ParsedCookieTest, TestBasic) {
ParsedCookie pc("a=b");
EXPECT_TRUE(pc.IsValid());
@@ -74,10 +69,11 @@ TEST(ParsedCookieTest, TestNameless) {
EXPECT_EQ("/", pc.Path());
EXPECT_EQ("", pc.Name());
EXPECT_EQ("BLAHHH", pc.Value());
+ EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
}
TEST(ParsedCookieTest, TestAttributeCase) {
- ParsedCookie pc("BLAHHH; Path=/; sECuRe; httpONLY");
+ ParsedCookie pc("BLAHHH; Path=/; sECuRe; httpONLY; pRIoRitY=hIgH");
EXPECT_TRUE(pc.IsValid());
EXPECT_TRUE(pc.IsSecure());
EXPECT_TRUE(pc.IsHttpOnly());
@@ -85,7 +81,8 @@ TEST(ParsedCookieTest, TestAttributeCase) {
EXPECT_EQ("/", pc.Path());
EXPECT_EQ("", pc.Name());
EXPECT_EQ("BLAHHH", pc.Value());
- EXPECT_EQ(3U, pc.NumberOfAttributes());
+ EXPECT_EQ(COOKIE_PRIORITY_HIGH, pc.Priority());
+ EXPECT_EQ(4U, pc.NumberOfAttributes());
}
TEST(ParsedCookieTest, TestDoubleQuotedNameless) {
@@ -96,6 +93,7 @@ TEST(ParsedCookieTest, TestDoubleQuotedNameless) {
EXPECT_EQ("/", pc.Path());
EXPECT_EQ("", pc.Name());
EXPECT_EQ("\"BLA\\\"HHH\"", pc.Value());
+ EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
EXPECT_EQ(2U, pc.NumberOfAttributes());
}
@@ -104,6 +102,7 @@ TEST(ParsedCookieTest, QuoteOffTheEnd) {
EXPECT_TRUE(pc.IsValid());
EXPECT_EQ("a", pc.Name());
EXPECT_EQ("\"B", pc.Value());
+ EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
EXPECT_EQ(0U, pc.NumberOfAttributes());
}
@@ -112,6 +111,7 @@ TEST(ParsedCookieTest, MissingName) {
EXPECT_TRUE(pc.IsValid());
EXPECT_EQ("", pc.Name());
EXPECT_EQ("ABC", pc.Value());
+ EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
EXPECT_EQ(0U, pc.NumberOfAttributes());
}
@@ -122,6 +122,7 @@ TEST(ParsedCookieTest, MissingValue) {
EXPECT_EQ("", pc.Value());
EXPECT_TRUE(pc.HasPath());
EXPECT_EQ("/wee", pc.Path());
+ EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
EXPECT_EQ(1U, pc.NumberOfAttributes());
}
@@ -134,6 +135,7 @@ TEST(ParsedCookieTest, Whitespace) {
EXPECT_FALSE(pc.HasDomain());
EXPECT_TRUE(pc.IsSecure());
EXPECT_TRUE(pc.IsHttpOnly());
+ EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
// We parse anything between ; as attributes, so we end up with two
// attributes with an empty string name and value.
EXPECT_EQ(4U, pc.NumberOfAttributes());
@@ -147,6 +149,7 @@ TEST(ParsedCookieTest, MultipleEquals) {
EXPECT_FALSE(pc.HasDomain());
EXPECT_TRUE(pc.IsSecure());
EXPECT_TRUE(pc.IsHttpOnly());
+ EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
EXPECT_EQ(4U, pc.NumberOfAttributes());
}
@@ -161,6 +164,7 @@ TEST(ParsedCookieTest, QuotedTrailingWhitespace) {
EXPECT_TRUE(pc.HasExpires());
EXPECT_TRUE(pc.HasPath());
EXPECT_EQ("/", pc.Path());
+ EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
EXPECT_EQ(2U, pc.NumberOfAttributes());
}
@@ -174,6 +178,7 @@ TEST(ParsedCookieTest, TrailingWhitespace) {
EXPECT_TRUE(pc.HasExpires());
EXPECT_TRUE(pc.HasPath());
EXPECT_EQ("/", pc.Path());
+ EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
EXPECT_EQ(2U, pc.NumberOfAttributes());
}
@@ -249,10 +254,10 @@ TEST(ParsedCookieTest, ParseTokensAndValues) {
TEST(ParsedCookieTest, SerializeCookieLine) {
const char input[] = "ANCUUID=zohNumRKgI0oxyhSsV3Z7D ; "
"expires=Sun, 18-Apr-2027 21:06:29 GMT ; "
- "path=/ ; ";
+ "path=/ ; priority=low ; ";
const char output[] = "ANCUUID=zohNumRKgI0oxyhSsV3Z7D; "
"expires=Sun, 18-Apr-2027 21:06:29 GMT; "
- "path=/";
+ "path=/; priority=low";
ParsedCookie pc(input);
EXPECT_EQ(output, pc.ToCookieLine());
}
@@ -331,9 +336,11 @@ TEST(ParsedCookieTest, SetAttributes) {
EXPECT_TRUE(pc.SetMaxAge("12345"));
EXPECT_TRUE(pc.SetIsSecure(true));
EXPECT_TRUE(pc.SetIsHttpOnly(true));
+ EXPECT_TRUE(pc.SetIsHttpOnly(true));
+ EXPECT_TRUE(pc.SetPriority("HIGH"));
EXPECT_EQ("name=value; domain=domain.com; path=/; "
"expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; "
- "httponly",
+ "httponly; priority=HIGH",
pc.ToCookieLine());
EXPECT_TRUE(pc.HasDomain());
EXPECT_TRUE(pc.HasPath());
@@ -341,6 +348,7 @@ TEST(ParsedCookieTest, SetAttributes) {
EXPECT_TRUE(pc.HasMaxAge());
EXPECT_TRUE(pc.IsSecure());
EXPECT_TRUE(pc.IsHttpOnly());
+ EXPECT_EQ(COOKIE_PRIORITY_HIGH, pc.Priority());
// Clear one attribute from the middle.
EXPECT_TRUE(pc.SetPath("/foo"));
@@ -351,7 +359,14 @@ TEST(ParsedCookieTest, SetAttributes) {
EXPECT_TRUE(pc.IsHttpOnly());
EXPECT_EQ("name=value; domain=domain.com; path=/foo; "
"expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; "
- "httponly",
+ "httponly; priority=HIGH",
+ pc.ToCookieLine());
+
+ // Set priority to medium.
+ EXPECT_TRUE(pc.SetPriority("medium"));
+ EXPECT_EQ("name=value; domain=domain.com; path=/foo; "
+ "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; "
+ "httponly; priority=medium",
pc.ToCookieLine());
// Clear the rest and change the name and value.
@@ -363,6 +378,7 @@ TEST(ParsedCookieTest, SetAttributes) {
EXPECT_TRUE(pc.SetIsHttpOnly(false));
EXPECT_TRUE(pc.SetName("name2"));
EXPECT_TRUE(pc.SetValue("value2"));
+ EXPECT_TRUE(pc.SetPriority(std::string()));
EXPECT_FALSE(pc.HasDomain());
EXPECT_FALSE(pc.HasPath());
EXPECT_FALSE(pc.HasExpires());
@@ -372,4 +388,38 @@ TEST(ParsedCookieTest, SetAttributes) {
EXPECT_EQ("name2=value2", pc.ToCookieLine());
}
+TEST(ParsedCookieTest, SetPriority) {
+ ParsedCookie pc("name=value");
+ EXPECT_TRUE(pc.IsValid());
+
+ EXPECT_EQ("name=value", pc.ToCookieLine());
+ EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
+
+ // Test each priority, expect case-insensitive compare.
+ EXPECT_TRUE(pc.SetPriority("high"));
+ EXPECT_EQ("name=value; priority=high", pc.ToCookieLine());
+ EXPECT_EQ(COOKIE_PRIORITY_HIGH, pc.Priority());
+
+ EXPECT_TRUE(pc.SetPriority("mEDium"));
+ EXPECT_EQ("name=value; priority=mEDium", pc.ToCookieLine());
+ EXPECT_EQ(COOKIE_PRIORITY_MEDIUM, pc.Priority());
+
+ EXPECT_TRUE(pc.SetPriority("LOW"));
+ EXPECT_EQ("name=value; priority=LOW", pc.ToCookieLine());
+ EXPECT_EQ(COOKIE_PRIORITY_LOW, pc.Priority());
+
+ // Interpret invalid priority values as COOKIE_PRIORITY_DEFAULT.
+ EXPECT_TRUE(pc.SetPriority("Blah"));
+ EXPECT_EQ("name=value; priority=Blah", pc.ToCookieLine());
+ EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
+
+ EXPECT_TRUE(pc.SetPriority("lowerest"));
+ EXPECT_EQ("name=value; priority=lowerest", pc.ToCookieLine());
+ EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
+
+ EXPECT_TRUE(pc.SetPriority(""));
+ EXPECT_EQ("name=value", pc.ToCookieLine());
+ EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
+}
+
} // namespace net
« no previous file with comments | « net/cookies/parsed_cookie.cc ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698