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 #ifndef NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 5 #ifndef NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
6 #define NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 6 #define NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
7 | 7 |
8 #include <cstdint> | |
mmenke
2017/07/05 16:58:50
stdint.h?
Randy Smith (Not in Mondays)
2017/07/08 13:03:26
Done.
| |
8 #include <set> | 9 #include <set> |
9 #include <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/bind.h" | 13 #include "base/bind.h" |
13 #include "base/location.h" | 14 #include "base/location.h" |
14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
16 #include "base/strings/string_tokenizer.h" | 17 #include "base/strings/string_tokenizer.h" |
17 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 const GURL& url, | 220 const GURL& url, |
220 const std::string& cookie_name) { | 221 const std::string& cookie_name) { |
221 DCHECK(cs); | 222 DCHECK(cs); |
222 NoResultCookieCallback callback; | 223 NoResultCookieCallback callback; |
223 cs->DeleteCookieAsync( | 224 cs->DeleteCookieAsync( |
224 url, cookie_name, | 225 url, cookie_name, |
225 base::Bind(&NoResultCookieCallback::Run, base::Unretained(&callback))); | 226 base::Bind(&NoResultCookieCallback::Run, base::Unretained(&callback))); |
226 callback.WaitUntilDone(); | 227 callback.WaitUntilDone(); |
227 } | 228 } |
228 | 229 |
229 int DeleteCanonicalCookie(CookieStore* cs, const CanonicalCookie& cookie) { | 230 uint32_t DeleteCanonicalCookie(CookieStore* cs, |
231 const CanonicalCookie& cookie) { | |
230 DCHECK(cs); | 232 DCHECK(cs); |
231 ResultSavingCookieCallback<int> callback; | 233 ResultSavingCookieCallback<uint32_t> callback; |
232 cs->DeleteCanonicalCookieAsync( | 234 cs->DeleteCanonicalCookieAsync( |
233 cookie, base::Bind(&ResultSavingCookieCallback<int>::Run, | 235 cookie, base::Bind(&ResultSavingCookieCallback<uint32_t>::Run, |
234 base::Unretained(&callback))); | 236 base::Unretained(&callback))); |
235 callback.WaitUntilDone(); | 237 callback.WaitUntilDone(); |
236 return callback.result(); | 238 return callback.result(); |
237 } | 239 } |
238 | 240 |
239 int DeleteCreatedBetween(CookieStore* cs, | 241 uint32_t DeleteCreatedBetween(CookieStore* cs, |
240 const base::Time& delete_begin, | 242 const base::Time& delete_begin, |
241 const base::Time& delete_end) { | 243 const base::Time& delete_end) { |
242 DCHECK(cs); | 244 DCHECK(cs); |
243 ResultSavingCookieCallback<int> callback; | 245 ResultSavingCookieCallback<uint32_t> callback; |
244 cs->DeleteAllCreatedBetweenAsync( | 246 cs->DeleteAllCreatedBetweenAsync( |
245 delete_begin, delete_end, | 247 delete_begin, delete_end, |
246 base::Bind( | 248 base::Bind(&ResultSavingCookieCallback<uint32_t>::Run, |
247 &ResultSavingCookieCallback<int>::Run, | 249 base::Unretained(&callback))); |
248 base::Unretained(&callback))); | |
249 callback.WaitUntilDone(); | 250 callback.WaitUntilDone(); |
250 return callback.result(); | 251 return callback.result(); |
251 } | 252 } |
252 | 253 |
253 int DeleteAllCreatedBetweenWithPredicate( | 254 uint32_t DeleteAllCreatedBetweenWithPredicate( |
254 CookieStore* cs, | 255 CookieStore* cs, |
255 const base::Time delete_begin, | 256 const base::Time delete_begin, |
256 const base::Time delete_end, | 257 const base::Time delete_end, |
257 const CookieStore::CookiePredicate& predicate) { | 258 const CookieStore::CookiePredicate& predicate) { |
258 DCHECK(cs); | 259 DCHECK(cs); |
259 ResultSavingCookieCallback<int> callback; | 260 ResultSavingCookieCallback<uint32_t> callback; |
260 cs->DeleteAllCreatedBetweenWithPredicateAsync( | 261 cs->DeleteAllCreatedBetweenWithPredicateAsync( |
261 delete_begin, delete_end, predicate, | 262 delete_begin, delete_end, predicate, |
262 base::Bind(&ResultSavingCookieCallback<int>::Run, | 263 base::Bind(&ResultSavingCookieCallback<uint32_t>::Run, |
263 base::Unretained(&callback))); | 264 base::Unretained(&callback))); |
264 callback.WaitUntilDone(); | 265 callback.WaitUntilDone(); |
265 return callback.result(); | 266 return callback.result(); |
266 } | 267 } |
267 | 268 |
268 int DeleteSessionCookies(CookieStore* cs) { | 269 uint32_t DeleteSessionCookies(CookieStore* cs) { |
269 DCHECK(cs); | 270 DCHECK(cs); |
270 ResultSavingCookieCallback<int> callback; | 271 ResultSavingCookieCallback<uint32_t> callback; |
271 cs->DeleteSessionCookiesAsync( | 272 cs->DeleteSessionCookiesAsync( |
272 base::Bind( | 273 base::Bind(&ResultSavingCookieCallback<uint32_t>::Run, |
273 &ResultSavingCookieCallback<int>::Run, | 274 base::Unretained(&callback))); |
274 base::Unretained(&callback))); | |
275 callback.WaitUntilDone(); | 275 callback.WaitUntilDone(); |
276 return callback.result(); | 276 return callback.result(); |
277 } | 277 } |
278 | 278 |
279 int DeleteAll(CookieStore* cs) { | 279 uint32_t DeleteAll(CookieStore* cs) { |
280 DCHECK(cs); | 280 DCHECK(cs); |
281 ResultSavingCookieCallback<int> callback; | 281 ResultSavingCookieCallback<uint32_t> callback; |
282 cs->DeleteAllAsync(base::Bind(&ResultSavingCookieCallback<int>::Run, | 282 cs->DeleteAllAsync(base::Bind(&ResultSavingCookieCallback<uint32_t>::Run, |
283 base::Unretained(&callback))); | 283 base::Unretained(&callback))); |
284 callback.WaitUntilDone(); | 284 callback.WaitUntilDone(); |
285 return callback.result(); | 285 return callback.result(); |
286 } | 286 } |
287 | 287 |
288 // Returns the CookieStore for the test - each test only uses one CookieStore. | 288 // Returns the CookieStore for the test - each test only uses one CookieStore. |
289 CookieStore* GetCookieStore() { | 289 CookieStore* GetCookieStore() { |
290 if (!cookie_store_) | 290 if (!cookie_store_) |
291 cookie_store_ = CookieStoreTestTraits::Create(); | 291 cookie_store_ = CookieStoreTestTraits::Create(); |
292 return cookie_store_.get(); | 292 return cookie_store_.get(); |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1209 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), kValidCookieLine)); | 1209 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), kValidCookieLine)); |
1210 EXPECT_EQ("A=B", this->GetCookies(cs, this->http_www_foo_.url())); | 1210 EXPECT_EQ("A=B", this->GetCookies(cs, this->http_www_foo_.url())); |
1211 | 1211 |
1212 // Set a persistent cookie. | 1212 // Set a persistent cookie. |
1213 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), | 1213 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), |
1214 "C=D; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1214 "C=D; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
1215 | 1215 |
1216 EXPECT_EQ(2u, this->GetAllCookies(cs).size()); | 1216 EXPECT_EQ(2u, this->GetAllCookies(cs).size()); |
1217 | 1217 |
1218 // Delete both, and make sure it works | 1218 // Delete both, and make sure it works |
1219 EXPECT_EQ(2, this->DeleteAll(cs)); | 1219 EXPECT_EQ(2u, this->DeleteAll(cs)); |
1220 EXPECT_EQ(0u, this->GetAllCookies(cs).size()); | 1220 EXPECT_EQ(0u, this->GetAllCookies(cs).size()); |
1221 } | 1221 } |
1222 | 1222 |
1223 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) { | 1223 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) { |
1224 CookieStore* cs = this->GetCookieStore(); | 1224 CookieStore* cs = this->GetCookieStore(); |
1225 const base::Time last_month = base::Time::Now() - | 1225 const base::Time last_month = base::Time::Now() - |
1226 base::TimeDelta::FromDays(30); | 1226 base::TimeDelta::FromDays(30); |
1227 const base::Time last_minute = base::Time::Now() - | 1227 const base::Time last_minute = base::Time::Now() - |
1228 base::TimeDelta::FromMinutes(1); | 1228 base::TimeDelta::FromMinutes(1); |
1229 const base::Time next_minute = base::Time::Now() + | 1229 const base::Time next_minute = base::Time::Now() + |
1230 base::TimeDelta::FromMinutes(1); | 1230 base::TimeDelta::FromMinutes(1); |
1231 const base::Time next_month = base::Time::Now() + | 1231 const base::Time next_month = base::Time::Now() + |
1232 base::TimeDelta::FromDays(30); | 1232 base::TimeDelta::FromDays(30); |
1233 | 1233 |
1234 // Add a cookie. | 1234 // Add a cookie. |
1235 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); | 1235 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
1236 // Check that the cookie is in the store. | 1236 // Check that the cookie is in the store. |
1237 this->MatchCookieLines("A=B", | 1237 this->MatchCookieLines("A=B", |
1238 this->GetCookies(cs, this->http_www_foo_.url())); | 1238 this->GetCookies(cs, this->http_www_foo_.url())); |
1239 | 1239 |
1240 // Remove cookies in empty intervals. | 1240 // Remove cookies in empty intervals. |
1241 EXPECT_EQ(0, this->DeleteCreatedBetween(cs, last_month, last_minute)); | 1241 EXPECT_EQ(0u, this->DeleteCreatedBetween(cs, last_month, last_minute)); |
1242 EXPECT_EQ(0, this->DeleteCreatedBetween(cs, next_minute, next_month)); | 1242 EXPECT_EQ(0u, this->DeleteCreatedBetween(cs, next_minute, next_month)); |
1243 // Check that the cookie is still there. | 1243 // Check that the cookie is still there. |
1244 this->MatchCookieLines("A=B", | 1244 this->MatchCookieLines("A=B", |
1245 this->GetCookies(cs, this->http_www_foo_.url())); | 1245 this->GetCookies(cs, this->http_www_foo_.url())); |
1246 | 1246 |
1247 // Remove the cookie with an interval defined by two dates. | 1247 // Remove the cookie with an interval defined by two dates. |
1248 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, next_minute)); | 1248 EXPECT_EQ(1u, this->DeleteCreatedBetween(cs, last_minute, next_minute)); |
1249 // Check that the cookie disappeared. | 1249 // Check that the cookie disappeared. |
1250 this->MatchCookieLines(std::string(), | 1250 this->MatchCookieLines(std::string(), |
1251 this->GetCookies(cs, this->http_www_foo_.url())); | 1251 this->GetCookies(cs, this->http_www_foo_.url())); |
1252 | 1252 |
1253 // Add another cookie. | 1253 // Add another cookie. |
1254 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); | 1254 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
1255 // Check that the cookie is in the store. | 1255 // Check that the cookie is in the store. |
1256 this->MatchCookieLines("C=D", | 1256 this->MatchCookieLines("C=D", |
1257 this->GetCookies(cs, this->http_www_foo_.url())); | 1257 this->GetCookies(cs, this->http_www_foo_.url())); |
1258 | 1258 |
1259 // Remove the cookie with a null ending time. | 1259 // Remove the cookie with a null ending time. |
1260 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, base::Time())); | 1260 EXPECT_EQ(1u, this->DeleteCreatedBetween(cs, last_minute, base::Time())); |
1261 // Check that the cookie disappeared. | 1261 // Check that the cookie disappeared. |
1262 this->MatchCookieLines(std::string(), | 1262 this->MatchCookieLines(std::string(), |
1263 this->GetCookies(cs, this->http_www_foo_.url())); | 1263 this->GetCookies(cs, this->http_www_foo_.url())); |
1264 } | 1264 } |
1265 | 1265 |
1266 namespace { | 1266 namespace { |
1267 static bool CookieHasValue(const std::string& value, | 1267 static bool CookieHasValue(const std::string& value, |
1268 const CanonicalCookie& cookie) { | 1268 const CanonicalCookie& cookie) { |
1269 return cookie.Value() == value; | 1269 return cookie.Value() == value; |
1270 } | 1270 } |
1271 } | 1271 } |
1272 | 1272 |
1273 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenWithPredicate) { | 1273 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenWithPredicate) { |
1274 CookieStore* cs = this->GetCookieStore(); | 1274 CookieStore* cs = this->GetCookieStore(); |
1275 base::Time now = base::Time::Now(); | 1275 base::Time now = base::Time::Now(); |
1276 base::Time last_month = base::Time::Now() - base::TimeDelta::FromDays(30); | 1276 base::Time last_month = base::Time::Now() - base::TimeDelta::FromDays(30); |
1277 base::Time last_minute = base::Time::Now() - base::TimeDelta::FromMinutes(1); | 1277 base::Time last_minute = base::Time::Now() - base::TimeDelta::FromMinutes(1); |
1278 std::string desired_value("B"); | 1278 std::string desired_value("B"); |
1279 | 1279 |
1280 // These 3 cookies match the time range and host. | 1280 // These 3 cookies match the time range and host. |
1281 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); | 1281 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
1282 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); | 1282 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
1283 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "Y=Z")); | 1283 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "Y=Z")); |
1284 EXPECT_TRUE(this->SetCookie(cs, this->https_www_foo_.url(), "E=B")); | 1284 EXPECT_TRUE(this->SetCookie(cs, this->https_www_foo_.url(), "E=B")); |
1285 | 1285 |
1286 // Delete cookies. | 1286 // Delete cookies. |
1287 EXPECT_EQ(2, // Deletes A=B, E=B | 1287 EXPECT_EQ(2u, // Deletes A=B, E=B |
1288 this->DeleteAllCreatedBetweenWithPredicate( | 1288 this->DeleteAllCreatedBetweenWithPredicate( |
1289 cs, now, base::Time::Max(), | 1289 cs, now, base::Time::Max(), |
1290 base::Bind(&CookieHasValue, desired_value))); | 1290 base::Bind(&CookieHasValue, desired_value))); |
1291 | 1291 |
1292 // Check that we deleted the right ones. | 1292 // Check that we deleted the right ones. |
1293 this->MatchCookieLines("C=D;Y=Z", | 1293 this->MatchCookieLines("C=D;Y=Z", |
1294 this->GetCookies(cs, this->https_www_foo_.url())); | 1294 this->GetCookies(cs, this->https_www_foo_.url())); |
1295 | 1295 |
1296 // Now check that using a null predicate will do nothing. | 1296 // Now check that using a null predicate will do nothing. |
1297 EXPECT_EQ(0, this->DeleteAllCreatedBetweenWithPredicate( | 1297 EXPECT_EQ(0u, |
1298 cs, now, base::Time::Max(), CookieStore::CookiePredicate())); | 1298 this->DeleteAllCreatedBetweenWithPredicate( |
1299 cs, now, base::Time::Max(), CookieStore::CookiePredicate())); | |
1299 | 1300 |
1300 // Finally, check that we don't delete cookies when our time range is off. | 1301 // Finally, check that we don't delete cookies when our time range is off. |
1301 desired_value = "D"; | 1302 desired_value = "D"; |
1302 EXPECT_EQ(0, this->DeleteAllCreatedBetweenWithPredicate( | 1303 EXPECT_EQ(0u, this->DeleteAllCreatedBetweenWithPredicate( |
1303 cs, last_month, last_minute, | 1304 cs, last_month, last_minute, |
1304 base::Bind(&CookieHasValue, desired_value))); | 1305 base::Bind(&CookieHasValue, desired_value))); |
1305 this->MatchCookieLines("C=D;Y=Z", | 1306 this->MatchCookieLines("C=D;Y=Z", |
1306 this->GetCookies(cs, this->https_www_foo_.url())); | 1307 this->GetCookies(cs, this->https_www_foo_.url())); |
1307 // Same thing, but with a good time range. | 1308 // Same thing, but with a good time range. |
1308 EXPECT_EQ(1, this->DeleteAllCreatedBetweenWithPredicate( | 1309 EXPECT_EQ(1u, this->DeleteAllCreatedBetweenWithPredicate( |
1309 cs, now, base::Time::Max(), | 1310 cs, now, base::Time::Max(), |
1310 base::Bind(&CookieHasValue, desired_value))); | 1311 base::Bind(&CookieHasValue, desired_value))); |
1311 this->MatchCookieLines("Y=Z", | 1312 this->MatchCookieLines("Y=Z", |
1312 this->GetCookies(cs, this->https_www_foo_.url())); | 1313 this->GetCookies(cs, this->https_www_foo_.url())); |
1313 } | 1314 } |
1314 | 1315 |
1315 TYPED_TEST_P(CookieStoreTest, TestSecure) { | 1316 TYPED_TEST_P(CookieStoreTest, TestSecure) { |
1316 CookieStore* cs = this->GetCookieStore(); | 1317 CookieStore* cs = this->GetCookieStore(); |
1317 | 1318 |
1318 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); | 1319 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
1319 this->MatchCookieLines("A=B", | 1320 this->MatchCookieLines("A=B", |
1320 this->GetCookies(cs, this->http_www_foo_.url())); | 1321 this->GetCookies(cs, this->http_www_foo_.url())); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1433 CookieStore* cs = this->GetCookieStore(); | 1434 CookieStore* cs = this->GetCookieStore(); |
1434 | 1435 |
1435 CookieOptions options; | 1436 CookieOptions options; |
1436 if (!TypeParam::supports_http_only) | 1437 if (!TypeParam::supports_http_only) |
1437 options.set_include_httponly(); | 1438 options.set_include_httponly(); |
1438 EXPECT_TRUE(this->SetCookieWithOptions(cs, url_foo, "a", options)); | 1439 EXPECT_TRUE(this->SetCookieWithOptions(cs, url_foo, "a", options)); |
1439 CookieList list = this->GetAllCookiesForURL(cs, url_foo); | 1440 CookieList list = this->GetAllCookiesForURL(cs, url_foo); |
1440 EXPECT_EQ(1u, list.size()); | 1441 EXPECT_EQ(1u, list.size()); |
1441 EXPECT_EQ("", list[0].Name()); | 1442 EXPECT_EQ("", list[0].Name()); |
1442 EXPECT_EQ("a", list[0].Value()); | 1443 EXPECT_EQ("a", list[0].Value()); |
1443 EXPECT_EQ(1, this->DeleteAll(cs)); | 1444 EXPECT_EQ(1u, this->DeleteAll(cs)); |
1444 | 1445 |
1445 EXPECT_TRUE(this->SetCookieWithOptions(cs, url_foo, "=b", options)); | 1446 EXPECT_TRUE(this->SetCookieWithOptions(cs, url_foo, "=b", options)); |
1446 list = this->GetAllCookiesForURL(cs, url_foo); | 1447 list = this->GetAllCookiesForURL(cs, url_foo); |
1447 EXPECT_EQ(1u, list.size()); | 1448 EXPECT_EQ(1u, list.size()); |
1448 EXPECT_EQ("", list[0].Name()); | 1449 EXPECT_EQ("", list[0].Name()); |
1449 EXPECT_EQ("b", list[0].Value()); | 1450 EXPECT_EQ("b", list[0].Value()); |
1450 EXPECT_EQ(1, this->DeleteAll(cs)); | 1451 EXPECT_EQ(1u, this->DeleteAll(cs)); |
1451 } | 1452 } |
1452 | 1453 |
1453 TYPED_TEST_P(CookieStoreTest, CookieOrdering) { | 1454 TYPED_TEST_P(CookieStoreTest, CookieOrdering) { |
1454 // Put a random set of cookies into a store and make sure they're returned in | 1455 // Put a random set of cookies into a store and make sure they're returned in |
1455 // the right order. | 1456 // the right order. |
1456 // Cookies should be sorted by path length and creation time, as per RFC6265. | 1457 // Cookies should be sorted by path length and creation time, as per RFC6265. |
1457 CookieStore* cs = this->GetCookieStore(); | 1458 CookieStore* cs = this->GetCookieStore(); |
1458 EXPECT_TRUE( | 1459 EXPECT_TRUE( |
1459 this->SetCookie(cs, GURL("http://d.c.b.a.foo.com/aa/x.html"), "c=1")); | 1460 this->SetCookie(cs, GURL("http://d.c.b.a.foo.com/aa/x.html"), "c=1")); |
1460 EXPECT_TRUE(this->SetCookie(cs, GURL("http://b.a.foo.com/aa/bb/cc/x.html"), | 1461 EXPECT_TRUE(this->SetCookie(cs, GURL("http://b.a.foo.com/aa/bb/cc/x.html"), |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1563 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B;Path=/foo")); | 1564 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B;Path=/foo")); |
1564 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=C;Path=/bar")); | 1565 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=C;Path=/bar")); |
1565 EXPECT_EQ(2u, this->GetAllCookies(cs).size()); | 1566 EXPECT_EQ(2u, this->GetAllCookies(cs).size()); |
1566 EXPECT_EQ("A=B", this->GetCookies(cs, this->www_foo_foo_.url())); | 1567 EXPECT_EQ("A=B", this->GetCookies(cs, this->www_foo_foo_.url())); |
1567 EXPECT_EQ("A=C", this->GetCookies(cs, this->www_foo_bar_.url())); | 1568 EXPECT_EQ("A=C", this->GetCookies(cs, this->www_foo_bar_.url())); |
1568 | 1569 |
1569 // Delete the "/foo" cookie, and make sure only it was deleted. | 1570 // Delete the "/foo" cookie, and make sure only it was deleted. |
1570 CookieList cookies = this->GetCookieListWithOptions( | 1571 CookieList cookies = this->GetCookieListWithOptions( |
1571 cs, this->www_foo_foo_.url(), CookieOptions()); | 1572 cs, this->www_foo_foo_.url(), CookieOptions()); |
1572 ASSERT_EQ(1u, cookies.size()); | 1573 ASSERT_EQ(1u, cookies.size()); |
1573 EXPECT_EQ(1, this->DeleteCanonicalCookie(cs, cookies[0])); | 1574 EXPECT_EQ(1u, this->DeleteCanonicalCookie(cs, cookies[0])); |
1574 EXPECT_EQ(1u, this->GetAllCookies(cs).size()); | 1575 EXPECT_EQ(1u, this->GetAllCookies(cs).size()); |
1575 EXPECT_EQ("", this->GetCookies(cs, this->www_foo_foo_.url())); | 1576 EXPECT_EQ("", this->GetCookies(cs, this->www_foo_foo_.url())); |
1576 EXPECT_EQ("A=C", this->GetCookies(cs, this->www_foo_bar_.url())); | 1577 EXPECT_EQ("A=C", this->GetCookies(cs, this->www_foo_bar_.url())); |
1577 | 1578 |
1578 // Deleting the "/foo" cookie again should fail. | 1579 // Deleting the "/foo" cookie again should fail. |
1579 EXPECT_EQ(0, this->DeleteCanonicalCookie(cs, cookies[0])); | 1580 EXPECT_EQ(0u, this->DeleteCanonicalCookie(cs, cookies[0])); |
1580 | 1581 |
1581 // Try to delete the "/bar" cookie after overwriting it with a new cookie. | 1582 // Try to delete the "/bar" cookie after overwriting it with a new cookie. |
1582 cookies = this->GetCookieListWithOptions(cs, this->www_foo_bar_.url(), | 1583 cookies = this->GetCookieListWithOptions(cs, this->www_foo_bar_.url(), |
1583 CookieOptions()); | 1584 CookieOptions()); |
1584 ASSERT_EQ(1u, cookies.size()); | 1585 ASSERT_EQ(1u, cookies.size()); |
1585 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=D;Path=/bar")); | 1586 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=D;Path=/bar")); |
1586 EXPECT_EQ(0, this->DeleteCanonicalCookie(cs, cookies[0])); | 1587 EXPECT_EQ(0u, this->DeleteCanonicalCookie(cs, cookies[0])); |
1587 EXPECT_EQ(1u, this->GetAllCookies(cs).size()); | 1588 EXPECT_EQ(1u, this->GetAllCookies(cs).size()); |
1588 EXPECT_EQ("A=D", this->GetCookies(cs, this->www_foo_bar_.url())); | 1589 EXPECT_EQ("A=D", this->GetCookies(cs, this->www_foo_bar_.url())); |
1589 | 1590 |
1590 // Delete the new "/bar" cookie. | 1591 // Delete the new "/bar" cookie. |
1591 cookies = this->GetCookieListWithOptions(cs, this->www_foo_bar_.url(), | 1592 cookies = this->GetCookieListWithOptions(cs, this->www_foo_bar_.url(), |
1592 CookieOptions()); | 1593 CookieOptions()); |
1593 ASSERT_EQ(1u, cookies.size()); | 1594 ASSERT_EQ(1u, cookies.size()); |
1594 EXPECT_EQ(1, this->DeleteCanonicalCookie(cs, cookies[0])); | 1595 EXPECT_EQ(1u, this->DeleteCanonicalCookie(cs, cookies[0])); |
1595 EXPECT_EQ(0u, this->GetAllCookies(cs).size()); | 1596 EXPECT_EQ(0u, this->GetAllCookies(cs).size()); |
1596 EXPECT_EQ("", this->GetCookies(cs, this->www_foo_bar_.url())); | 1597 EXPECT_EQ("", this->GetCookies(cs, this->www_foo_bar_.url())); |
1597 } | 1598 } |
1598 | 1599 |
1599 TYPED_TEST_P(CookieStoreTest, DeleteSessionCookie) { | 1600 TYPED_TEST_P(CookieStoreTest, DeleteSessionCookie) { |
1600 CookieStore* cs = this->GetCookieStore(); | 1601 CookieStore* cs = this->GetCookieStore(); |
1601 // Create a session cookie and a persistent cookie. | 1602 // Create a session cookie and a persistent cookie. |
1602 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), | 1603 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), |
1603 std::string(kValidCookieLine))); | 1604 std::string(kValidCookieLine))); |
1604 EXPECT_TRUE(this->SetCookie( | 1605 EXPECT_TRUE(this->SetCookie( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1651 EmptyName, | 1652 EmptyName, |
1652 CookieOrdering, | 1653 CookieOrdering, |
1653 GetAllCookiesAsync, | 1654 GetAllCookiesAsync, |
1654 DeleteCookieAsync, | 1655 DeleteCookieAsync, |
1655 DeleteCanonicalCookieAsync, | 1656 DeleteCanonicalCookieAsync, |
1656 DeleteSessionCookie); | 1657 DeleteSessionCookie); |
1657 | 1658 |
1658 } // namespace net | 1659 } // namespace net |
1659 | 1660 |
1660 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 1661 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
OLD | NEW |