OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
| 7 #include "net/cookies/cookie_constants.h" |
7 #include "net/cookies/parsed_cookie.h" | 8 #include "net/cookies/parsed_cookie.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
9 | 10 |
10 namespace net { | 11 namespace net { |
11 | 12 |
12 namespace { | |
13 | |
14 class ParsedCookieTest : public testing::Test { }; | |
15 | |
16 } // namespace | |
17 | |
18 TEST(ParsedCookieTest, TestBasic) { | 13 TEST(ParsedCookieTest, TestBasic) { |
19 ParsedCookie pc("a=b"); | 14 ParsedCookie pc("a=b"); |
20 EXPECT_TRUE(pc.IsValid()); | 15 EXPECT_TRUE(pc.IsValid()); |
21 EXPECT_FALSE(pc.IsSecure()); | 16 EXPECT_FALSE(pc.IsSecure()); |
22 EXPECT_EQ("a", pc.Name()); | 17 EXPECT_EQ("a", pc.Name()); |
23 EXPECT_EQ("b", pc.Value()); | 18 EXPECT_EQ("b", pc.Value()); |
24 } | 19 } |
25 | 20 |
26 TEST(ParsedCookieTest, TestQuoted) { | 21 TEST(ParsedCookieTest, TestQuoted) { |
27 // These are some quoting cases which the major browsers all | 22 // These are some quoting cases which the major browsers all |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 62 } |
68 | 63 |
69 TEST(ParsedCookieTest, TestNameless) { | 64 TEST(ParsedCookieTest, TestNameless) { |
70 ParsedCookie pc("BLAHHH; path=/; secure;"); | 65 ParsedCookie pc("BLAHHH; path=/; secure;"); |
71 EXPECT_TRUE(pc.IsValid()); | 66 EXPECT_TRUE(pc.IsValid()); |
72 EXPECT_TRUE(pc.IsSecure()); | 67 EXPECT_TRUE(pc.IsSecure()); |
73 EXPECT_TRUE(pc.HasPath()); | 68 EXPECT_TRUE(pc.HasPath()); |
74 EXPECT_EQ("/", pc.Path()); | 69 EXPECT_EQ("/", pc.Path()); |
75 EXPECT_EQ("", pc.Name()); | 70 EXPECT_EQ("", pc.Name()); |
76 EXPECT_EQ("BLAHHH", pc.Value()); | 71 EXPECT_EQ("BLAHHH", pc.Value()); |
| 72 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
77 } | 73 } |
78 | 74 |
79 TEST(ParsedCookieTest, TestAttributeCase) { | 75 TEST(ParsedCookieTest, TestAttributeCase) { |
80 ParsedCookie pc("BLAHHH; Path=/; sECuRe; httpONLY"); | 76 ParsedCookie pc("BLAHHH; Path=/; sECuRe; httpONLY; pRIoRitY=hIgH"); |
81 EXPECT_TRUE(pc.IsValid()); | 77 EXPECT_TRUE(pc.IsValid()); |
82 EXPECT_TRUE(pc.IsSecure()); | 78 EXPECT_TRUE(pc.IsSecure()); |
83 EXPECT_TRUE(pc.IsHttpOnly()); | 79 EXPECT_TRUE(pc.IsHttpOnly()); |
84 EXPECT_TRUE(pc.HasPath()); | 80 EXPECT_TRUE(pc.HasPath()); |
85 EXPECT_EQ("/", pc.Path()); | 81 EXPECT_EQ("/", pc.Path()); |
86 EXPECT_EQ("", pc.Name()); | 82 EXPECT_EQ("", pc.Name()); |
87 EXPECT_EQ("BLAHHH", pc.Value()); | 83 EXPECT_EQ("BLAHHH", pc.Value()); |
88 EXPECT_EQ(3U, pc.NumberOfAttributes()); | 84 EXPECT_EQ(COOKIE_PRIORITY_HIGH, pc.Priority()); |
| 85 EXPECT_EQ(4U, pc.NumberOfAttributes()); |
89 } | 86 } |
90 | 87 |
91 TEST(ParsedCookieTest, TestDoubleQuotedNameless) { | 88 TEST(ParsedCookieTest, TestDoubleQuotedNameless) { |
92 ParsedCookie pc("\"BLA\\\"HHH\"; path=/; secure;"); | 89 ParsedCookie pc("\"BLA\\\"HHH\"; path=/; secure;"); |
93 EXPECT_TRUE(pc.IsValid()); | 90 EXPECT_TRUE(pc.IsValid()); |
94 EXPECT_TRUE(pc.IsSecure()); | 91 EXPECT_TRUE(pc.IsSecure()); |
95 EXPECT_TRUE(pc.HasPath()); | 92 EXPECT_TRUE(pc.HasPath()); |
96 EXPECT_EQ("/", pc.Path()); | 93 EXPECT_EQ("/", pc.Path()); |
97 EXPECT_EQ("", pc.Name()); | 94 EXPECT_EQ("", pc.Name()); |
98 EXPECT_EQ("\"BLA\\\"HHH\"", pc.Value()); | 95 EXPECT_EQ("\"BLA\\\"HHH\"", pc.Value()); |
| 96 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
99 EXPECT_EQ(2U, pc.NumberOfAttributes()); | 97 EXPECT_EQ(2U, pc.NumberOfAttributes()); |
100 } | 98 } |
101 | 99 |
102 TEST(ParsedCookieTest, QuoteOffTheEnd) { | 100 TEST(ParsedCookieTest, QuoteOffTheEnd) { |
103 ParsedCookie pc("a=\"B"); | 101 ParsedCookie pc("a=\"B"); |
104 EXPECT_TRUE(pc.IsValid()); | 102 EXPECT_TRUE(pc.IsValid()); |
105 EXPECT_EQ("a", pc.Name()); | 103 EXPECT_EQ("a", pc.Name()); |
106 EXPECT_EQ("\"B", pc.Value()); | 104 EXPECT_EQ("\"B", pc.Value()); |
| 105 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
107 EXPECT_EQ(0U, pc.NumberOfAttributes()); | 106 EXPECT_EQ(0U, pc.NumberOfAttributes()); |
108 } | 107 } |
109 | 108 |
110 TEST(ParsedCookieTest, MissingName) { | 109 TEST(ParsedCookieTest, MissingName) { |
111 ParsedCookie pc("=ABC"); | 110 ParsedCookie pc("=ABC"); |
112 EXPECT_TRUE(pc.IsValid()); | 111 EXPECT_TRUE(pc.IsValid()); |
113 EXPECT_EQ("", pc.Name()); | 112 EXPECT_EQ("", pc.Name()); |
114 EXPECT_EQ("ABC", pc.Value()); | 113 EXPECT_EQ("ABC", pc.Value()); |
| 114 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
115 EXPECT_EQ(0U, pc.NumberOfAttributes()); | 115 EXPECT_EQ(0U, pc.NumberOfAttributes()); |
116 } | 116 } |
117 | 117 |
118 TEST(ParsedCookieTest, MissingValue) { | 118 TEST(ParsedCookieTest, MissingValue) { |
119 ParsedCookie pc("ABC=; path = /wee"); | 119 ParsedCookie pc("ABC=; path = /wee"); |
120 EXPECT_TRUE(pc.IsValid()); | 120 EXPECT_TRUE(pc.IsValid()); |
121 EXPECT_EQ("ABC", pc.Name()); | 121 EXPECT_EQ("ABC", pc.Name()); |
122 EXPECT_EQ("", pc.Value()); | 122 EXPECT_EQ("", pc.Value()); |
123 EXPECT_TRUE(pc.HasPath()); | 123 EXPECT_TRUE(pc.HasPath()); |
124 EXPECT_EQ("/wee", pc.Path()); | 124 EXPECT_EQ("/wee", pc.Path()); |
| 125 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
125 EXPECT_EQ(1U, pc.NumberOfAttributes()); | 126 EXPECT_EQ(1U, pc.NumberOfAttributes()); |
126 } | 127 } |
127 | 128 |
128 TEST(ParsedCookieTest, Whitespace) { | 129 TEST(ParsedCookieTest, Whitespace) { |
129 ParsedCookie pc(" A = BC ;secure;;; httponly"); | 130 ParsedCookie pc(" A = BC ;secure;;; httponly"); |
130 EXPECT_TRUE(pc.IsValid()); | 131 EXPECT_TRUE(pc.IsValid()); |
131 EXPECT_EQ("A", pc.Name()); | 132 EXPECT_EQ("A", pc.Name()); |
132 EXPECT_EQ("BC", pc.Value()); | 133 EXPECT_EQ("BC", pc.Value()); |
133 EXPECT_FALSE(pc.HasPath()); | 134 EXPECT_FALSE(pc.HasPath()); |
134 EXPECT_FALSE(pc.HasDomain()); | 135 EXPECT_FALSE(pc.HasDomain()); |
135 EXPECT_TRUE(pc.IsSecure()); | 136 EXPECT_TRUE(pc.IsSecure()); |
136 EXPECT_TRUE(pc.IsHttpOnly()); | 137 EXPECT_TRUE(pc.IsHttpOnly()); |
| 138 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
137 // We parse anything between ; as attributes, so we end up with two | 139 // We parse anything between ; as attributes, so we end up with two |
138 // attributes with an empty string name and value. | 140 // attributes with an empty string name and value. |
139 EXPECT_EQ(4U, pc.NumberOfAttributes()); | 141 EXPECT_EQ(4U, pc.NumberOfAttributes()); |
140 } | 142 } |
141 TEST(ParsedCookieTest, MultipleEquals) { | 143 TEST(ParsedCookieTest, MultipleEquals) { |
142 ParsedCookie pc(" A=== BC ;secure;;; httponly"); | 144 ParsedCookie pc(" A=== BC ;secure;;; httponly"); |
143 EXPECT_TRUE(pc.IsValid()); | 145 EXPECT_TRUE(pc.IsValid()); |
144 EXPECT_EQ("A", pc.Name()); | 146 EXPECT_EQ("A", pc.Name()); |
145 EXPECT_EQ("== BC", pc.Value()); | 147 EXPECT_EQ("== BC", pc.Value()); |
146 EXPECT_FALSE(pc.HasPath()); | 148 EXPECT_FALSE(pc.HasPath()); |
147 EXPECT_FALSE(pc.HasDomain()); | 149 EXPECT_FALSE(pc.HasDomain()); |
148 EXPECT_TRUE(pc.IsSecure()); | 150 EXPECT_TRUE(pc.IsSecure()); |
149 EXPECT_TRUE(pc.IsHttpOnly()); | 151 EXPECT_TRUE(pc.IsHttpOnly()); |
| 152 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
150 EXPECT_EQ(4U, pc.NumberOfAttributes()); | 153 EXPECT_EQ(4U, pc.NumberOfAttributes()); |
151 } | 154 } |
152 | 155 |
153 TEST(ParsedCookieTest, QuotedTrailingWhitespace) { | 156 TEST(ParsedCookieTest, QuotedTrailingWhitespace) { |
154 ParsedCookie pc("ANCUUID=\"zohNumRKgI0oxyhSsV3Z7D\" ; " | 157 ParsedCookie pc("ANCUUID=\"zohNumRKgI0oxyhSsV3Z7D\" ; " |
155 "expires=Sun, 18-Apr-2027 21:06:29 GMT ; " | 158 "expires=Sun, 18-Apr-2027 21:06:29 GMT ; " |
156 "path=/ ; "); | 159 "path=/ ; "); |
157 EXPECT_TRUE(pc.IsValid()); | 160 EXPECT_TRUE(pc.IsValid()); |
158 EXPECT_EQ("ANCUUID", pc.Name()); | 161 EXPECT_EQ("ANCUUID", pc.Name()); |
159 // Stripping whitespace after the quotes matches all other major browsers. | 162 // Stripping whitespace after the quotes matches all other major browsers. |
160 EXPECT_EQ("\"zohNumRKgI0oxyhSsV3Z7D\"", pc.Value()); | 163 EXPECT_EQ("\"zohNumRKgI0oxyhSsV3Z7D\"", pc.Value()); |
161 EXPECT_TRUE(pc.HasExpires()); | 164 EXPECT_TRUE(pc.HasExpires()); |
162 EXPECT_TRUE(pc.HasPath()); | 165 EXPECT_TRUE(pc.HasPath()); |
163 EXPECT_EQ("/", pc.Path()); | 166 EXPECT_EQ("/", pc.Path()); |
| 167 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
164 EXPECT_EQ(2U, pc.NumberOfAttributes()); | 168 EXPECT_EQ(2U, pc.NumberOfAttributes()); |
165 } | 169 } |
166 | 170 |
167 TEST(ParsedCookieTest, TrailingWhitespace) { | 171 TEST(ParsedCookieTest, TrailingWhitespace) { |
168 ParsedCookie pc("ANCUUID=zohNumRKgI0oxyhSsV3Z7D ; " | 172 ParsedCookie pc("ANCUUID=zohNumRKgI0oxyhSsV3Z7D ; " |
169 "expires=Sun, 18-Apr-2027 21:06:29 GMT ; " | 173 "expires=Sun, 18-Apr-2027 21:06:29 GMT ; " |
170 "path=/ ; "); | 174 "path=/ ; "); |
171 EXPECT_TRUE(pc.IsValid()); | 175 EXPECT_TRUE(pc.IsValid()); |
172 EXPECT_EQ("ANCUUID", pc.Name()); | 176 EXPECT_EQ("ANCUUID", pc.Name()); |
173 EXPECT_EQ("zohNumRKgI0oxyhSsV3Z7D", pc.Value()); | 177 EXPECT_EQ("zohNumRKgI0oxyhSsV3Z7D", pc.Value()); |
174 EXPECT_TRUE(pc.HasExpires()); | 178 EXPECT_TRUE(pc.HasExpires()); |
175 EXPECT_TRUE(pc.HasPath()); | 179 EXPECT_TRUE(pc.HasPath()); |
176 EXPECT_EQ("/", pc.Path()); | 180 EXPECT_EQ("/", pc.Path()); |
| 181 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
177 EXPECT_EQ(2U, pc.NumberOfAttributes()); | 182 EXPECT_EQ(2U, pc.NumberOfAttributes()); |
178 } | 183 } |
179 | 184 |
180 TEST(ParsedCookieTest, TooManyPairs) { | 185 TEST(ParsedCookieTest, TooManyPairs) { |
181 std::string blankpairs; | 186 std::string blankpairs; |
182 blankpairs.resize(ParsedCookie::kMaxPairs - 1, ';'); | 187 blankpairs.resize(ParsedCookie::kMaxPairs - 1, ';'); |
183 | 188 |
184 ParsedCookie pc1(blankpairs + "secure"); | 189 ParsedCookie pc1(blankpairs + "secure"); |
185 EXPECT_TRUE(pc1.IsValid()); | 190 EXPECT_TRUE(pc1.IsValid()); |
186 EXPECT_TRUE(pc1.IsSecure()); | 191 EXPECT_TRUE(pc1.IsSecure()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 ParsedCookie::ParseValueString("fs!!@;helloworld")); | 247 ParsedCookie::ParseValueString("fs!!@;helloworld")); |
243 EXPECT_EQ("hello world\tgood", | 248 EXPECT_EQ("hello world\tgood", |
244 ParsedCookie::ParseValueString("hello world\tgood\rbye")); | 249 ParsedCookie::ParseValueString("hello world\tgood\rbye")); |
245 EXPECT_EQ("A=B=C", | 250 EXPECT_EQ("A=B=C", |
246 ParsedCookie::ParseValueString("A=B=C;D=E")); | 251 ParsedCookie::ParseValueString("A=B=C;D=E")); |
247 } | 252 } |
248 | 253 |
249 TEST(ParsedCookieTest, SerializeCookieLine) { | 254 TEST(ParsedCookieTest, SerializeCookieLine) { |
250 const char input[] = "ANCUUID=zohNumRKgI0oxyhSsV3Z7D ; " | 255 const char input[] = "ANCUUID=zohNumRKgI0oxyhSsV3Z7D ; " |
251 "expires=Sun, 18-Apr-2027 21:06:29 GMT ; " | 256 "expires=Sun, 18-Apr-2027 21:06:29 GMT ; " |
252 "path=/ ; "; | 257 "path=/ ; priority=low ; "; |
253 const char output[] = "ANCUUID=zohNumRKgI0oxyhSsV3Z7D; " | 258 const char output[] = "ANCUUID=zohNumRKgI0oxyhSsV3Z7D; " |
254 "expires=Sun, 18-Apr-2027 21:06:29 GMT; " | 259 "expires=Sun, 18-Apr-2027 21:06:29 GMT; " |
255 "path=/"; | 260 "path=/; priority=low"; |
256 ParsedCookie pc(input); | 261 ParsedCookie pc(input); |
257 EXPECT_EQ(output, pc.ToCookieLine()); | 262 EXPECT_EQ(output, pc.ToCookieLine()); |
258 } | 263 } |
259 | 264 |
260 | 265 |
261 TEST(ParsedCookieTest, SetNameAndValue) { | 266 TEST(ParsedCookieTest, SetNameAndValue) { |
262 ParsedCookie empty((std::string())); | 267 ParsedCookie empty((std::string())); |
263 EXPECT_FALSE(empty.IsValid()); | 268 EXPECT_FALSE(empty.IsValid()); |
264 EXPECT_FALSE(empty.SetDomain("foobar.com")); | 269 EXPECT_FALSE(empty.SetDomain("foobar.com")); |
265 EXPECT_TRUE(empty.SetName("name")); | 270 EXPECT_TRUE(empty.SetName("name")); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 EXPECT_EQ("name=value", pc.ToCookieLine()); | 329 EXPECT_EQ("name=value", pc.ToCookieLine()); |
325 EXPECT_TRUE(pc.IsValid()); | 330 EXPECT_TRUE(pc.IsValid()); |
326 | 331 |
327 // Set all other attributes and check that they are appended in order. | 332 // Set all other attributes and check that they are appended in order. |
328 EXPECT_TRUE(pc.SetDomain("domain.com")); | 333 EXPECT_TRUE(pc.SetDomain("domain.com")); |
329 EXPECT_TRUE(pc.SetPath("/")); | 334 EXPECT_TRUE(pc.SetPath("/")); |
330 EXPECT_TRUE(pc.SetExpires("Sun, 18-Apr-2027 21:06:29 GMT")); | 335 EXPECT_TRUE(pc.SetExpires("Sun, 18-Apr-2027 21:06:29 GMT")); |
331 EXPECT_TRUE(pc.SetMaxAge("12345")); | 336 EXPECT_TRUE(pc.SetMaxAge("12345")); |
332 EXPECT_TRUE(pc.SetIsSecure(true)); | 337 EXPECT_TRUE(pc.SetIsSecure(true)); |
333 EXPECT_TRUE(pc.SetIsHttpOnly(true)); | 338 EXPECT_TRUE(pc.SetIsHttpOnly(true)); |
| 339 EXPECT_TRUE(pc.SetIsHttpOnly(true)); |
| 340 EXPECT_TRUE(pc.SetPriority("HIGH")); |
334 EXPECT_EQ("name=value; domain=domain.com; path=/; " | 341 EXPECT_EQ("name=value; domain=domain.com; path=/; " |
335 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " | 342 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " |
336 "httponly", | 343 "httponly; priority=HIGH", |
337 pc.ToCookieLine()); | 344 pc.ToCookieLine()); |
338 EXPECT_TRUE(pc.HasDomain()); | 345 EXPECT_TRUE(pc.HasDomain()); |
339 EXPECT_TRUE(pc.HasPath()); | 346 EXPECT_TRUE(pc.HasPath()); |
340 EXPECT_TRUE(pc.HasExpires()); | 347 EXPECT_TRUE(pc.HasExpires()); |
341 EXPECT_TRUE(pc.HasMaxAge()); | 348 EXPECT_TRUE(pc.HasMaxAge()); |
342 EXPECT_TRUE(pc.IsSecure()); | 349 EXPECT_TRUE(pc.IsSecure()); |
343 EXPECT_TRUE(pc.IsHttpOnly()); | 350 EXPECT_TRUE(pc.IsHttpOnly()); |
| 351 EXPECT_EQ(COOKIE_PRIORITY_HIGH, pc.Priority()); |
344 | 352 |
345 // Clear one attribute from the middle. | 353 // Clear one attribute from the middle. |
346 EXPECT_TRUE(pc.SetPath("/foo")); | 354 EXPECT_TRUE(pc.SetPath("/foo")); |
347 EXPECT_TRUE(pc.HasDomain()); | 355 EXPECT_TRUE(pc.HasDomain()); |
348 EXPECT_TRUE(pc.HasPath()); | 356 EXPECT_TRUE(pc.HasPath()); |
349 EXPECT_TRUE(pc.HasExpires()); | 357 EXPECT_TRUE(pc.HasExpires()); |
350 EXPECT_TRUE(pc.IsSecure()); | 358 EXPECT_TRUE(pc.IsSecure()); |
351 EXPECT_TRUE(pc.IsHttpOnly()); | 359 EXPECT_TRUE(pc.IsHttpOnly()); |
352 EXPECT_EQ("name=value; domain=domain.com; path=/foo; " | 360 EXPECT_EQ("name=value; domain=domain.com; path=/foo; " |
353 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " | 361 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " |
354 "httponly", | 362 "httponly; priority=HIGH", |
| 363 pc.ToCookieLine()); |
| 364 |
| 365 // Set priority to medium. |
| 366 EXPECT_TRUE(pc.SetPriority("medium")); |
| 367 EXPECT_EQ("name=value; domain=domain.com; path=/foo; " |
| 368 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " |
| 369 "httponly; priority=medium", |
355 pc.ToCookieLine()); | 370 pc.ToCookieLine()); |
356 | 371 |
357 // Clear the rest and change the name and value. | 372 // Clear the rest and change the name and value. |
358 EXPECT_TRUE(pc.SetDomain(std::string())); | 373 EXPECT_TRUE(pc.SetDomain(std::string())); |
359 EXPECT_TRUE(pc.SetPath(std::string())); | 374 EXPECT_TRUE(pc.SetPath(std::string())); |
360 EXPECT_TRUE(pc.SetExpires(std::string())); | 375 EXPECT_TRUE(pc.SetExpires(std::string())); |
361 EXPECT_TRUE(pc.SetMaxAge(std::string())); | 376 EXPECT_TRUE(pc.SetMaxAge(std::string())); |
362 EXPECT_TRUE(pc.SetIsSecure(false)); | 377 EXPECT_TRUE(pc.SetIsSecure(false)); |
363 EXPECT_TRUE(pc.SetIsHttpOnly(false)); | 378 EXPECT_TRUE(pc.SetIsHttpOnly(false)); |
364 EXPECT_TRUE(pc.SetName("name2")); | 379 EXPECT_TRUE(pc.SetName("name2")); |
365 EXPECT_TRUE(pc.SetValue("value2")); | 380 EXPECT_TRUE(pc.SetValue("value2")); |
| 381 EXPECT_TRUE(pc.SetPriority(std::string())); |
366 EXPECT_FALSE(pc.HasDomain()); | 382 EXPECT_FALSE(pc.HasDomain()); |
367 EXPECT_FALSE(pc.HasPath()); | 383 EXPECT_FALSE(pc.HasPath()); |
368 EXPECT_FALSE(pc.HasExpires()); | 384 EXPECT_FALSE(pc.HasExpires()); |
369 EXPECT_FALSE(pc.HasMaxAge()); | 385 EXPECT_FALSE(pc.HasMaxAge()); |
370 EXPECT_FALSE(pc.IsSecure()); | 386 EXPECT_FALSE(pc.IsSecure()); |
371 EXPECT_FALSE(pc.IsHttpOnly()); | 387 EXPECT_FALSE(pc.IsHttpOnly()); |
372 EXPECT_EQ("name2=value2", pc.ToCookieLine()); | 388 EXPECT_EQ("name2=value2", pc.ToCookieLine()); |
373 } | 389 } |
374 | 390 |
| 391 TEST(ParsedCookieTest, SetPriority) { |
| 392 ParsedCookie pc("name=value"); |
| 393 EXPECT_TRUE(pc.IsValid()); |
| 394 |
| 395 EXPECT_EQ("name=value", pc.ToCookieLine()); |
| 396 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
| 397 |
| 398 // Test each priority, expect case-insensitive compare. |
| 399 EXPECT_TRUE(pc.SetPriority("high")); |
| 400 EXPECT_EQ("name=value; priority=high", pc.ToCookieLine()); |
| 401 EXPECT_EQ(COOKIE_PRIORITY_HIGH, pc.Priority()); |
| 402 |
| 403 EXPECT_TRUE(pc.SetPriority("mEDium")); |
| 404 EXPECT_EQ("name=value; priority=mEDium", pc.ToCookieLine()); |
| 405 EXPECT_EQ(COOKIE_PRIORITY_MEDIUM, pc.Priority()); |
| 406 |
| 407 EXPECT_TRUE(pc.SetPriority("LOW")); |
| 408 EXPECT_EQ("name=value; priority=LOW", pc.ToCookieLine()); |
| 409 EXPECT_EQ(COOKIE_PRIORITY_LOW, pc.Priority()); |
| 410 |
| 411 // Interpret invalid priority values as COOKIE_PRIORITY_DEFAULT. |
| 412 EXPECT_TRUE(pc.SetPriority("Blah")); |
| 413 EXPECT_EQ("name=value; priority=Blah", pc.ToCookieLine()); |
| 414 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
| 415 |
| 416 EXPECT_TRUE(pc.SetPriority("lowerest")); |
| 417 EXPECT_EQ("name=value; priority=lowerest", pc.ToCookieLine()); |
| 418 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
| 419 |
| 420 EXPECT_TRUE(pc.SetPriority("")); |
| 421 EXPECT_EQ("name=value", pc.ToCookieLine()); |
| 422 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
| 423 } |
| 424 |
375 } // namespace net | 425 } // namespace net |
OLD | NEW |