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 "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 245 |
246 TYPED_TEST_P(CookieStoreTest, TypeTest) { | 246 TYPED_TEST_P(CookieStoreTest, TypeTest) { |
247 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 247 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
248 EXPECT_EQ(cs->GetCookieMonster(), | 248 EXPECT_EQ(cs->GetCookieMonster(), |
249 (TypeParam::is_cookie_monster) ? | 249 (TypeParam::is_cookie_monster) ? |
250 static_cast<CookieMonster*>(cs.get()) : NULL); | 250 static_cast<CookieMonster*>(cs.get()) : NULL); |
251 } | 251 } |
252 | 252 |
253 TYPED_TEST_P(CookieStoreTest, DomainTest) { | 253 TYPED_TEST_P(CookieStoreTest, DomainTest) { |
254 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 254 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
255 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "A=B")); | 255 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); |
256 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); | 256 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); |
257 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | 257 EXPECT_TRUE(this->SetCookie( |
258 "C=D; domain=.google.izzle")); | 258 cs.get(), this->url_google_, "C=D; domain=.google.izzle")); |
259 this->MatchCookieLines("A=B; C=D", this->GetCookies(cs, this->url_google_)); | 259 this->MatchCookieLines("A=B; C=D", |
| 260 this->GetCookies(cs.get(), this->url_google_)); |
260 | 261 |
261 // Verify that A=B was set as a host cookie rather than a domain | 262 // Verify that A=B was set as a host cookie rather than a domain |
262 // cookie -- should not be accessible from a sub sub-domain. | 263 // cookie -- should not be accessible from a sub sub-domain. |
263 this->MatchCookieLines("C=D", | 264 this->MatchCookieLines( |
264 this->GetCookies(cs, GURL("http://foo.www.google.izzle"))); | 265 "C=D", this->GetCookies(cs.get(), GURL("http://foo.www.google.izzle"))); |
265 | 266 |
266 // Test and make sure we find domain cookies on the same domain. | 267 // Test and make sure we find domain cookies on the same domain. |
267 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | 268 EXPECT_TRUE(this->SetCookie( |
268 "E=F; domain=.www.google.izzle")); | 269 cs.get(), this->url_google_, "E=F; domain=.www.google.izzle")); |
269 this->MatchCookieLines("A=B; C=D; E=F", | 270 this->MatchCookieLines("A=B; C=D; E=F", |
270 this->GetCookies(cs, this->url_google_)); | 271 this->GetCookies(cs.get(), this->url_google_)); |
271 | 272 |
272 // Test setting a domain= that doesn't start w/ a dot, should | 273 // Test setting a domain= that doesn't start w/ a dot, should |
273 // treat it as a domain cookie, as if there was a pre-pended dot. | 274 // treat it as a domain cookie, as if there was a pre-pended dot. |
274 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | 275 EXPECT_TRUE(this->SetCookie( |
275 "G=H; domain=www.google.izzle")); | 276 cs.get(), this->url_google_, "G=H; domain=www.google.izzle")); |
276 this->MatchCookieLines("A=B; C=D; E=F; G=H", | 277 this->MatchCookieLines("A=B; C=D; E=F; G=H", |
277 this->GetCookies(cs, this->url_google_)); | 278 this->GetCookies(cs.get(), this->url_google_)); |
278 | 279 |
279 // Test domain enforcement, should fail on a sub-domain or something too deep. | 280 // Test domain enforcement, should fail on a sub-domain or something too deep. |
280 EXPECT_FALSE(this->SetCookie(cs, this->url_google_, "I=J; domain=.izzle")); | 281 EXPECT_FALSE( |
| 282 this->SetCookie(cs.get(), this->url_google_, "I=J; domain=.izzle")); |
281 this->MatchCookieLines(std::string(), | 283 this->MatchCookieLines(std::string(), |
282 this->GetCookies(cs, GURL("http://a.izzle"))); | 284 this->GetCookies(cs.get(), GURL("http://a.izzle"))); |
283 EXPECT_FALSE(this->SetCookie( | 285 EXPECT_FALSE(this->SetCookie( |
284 cs, this->url_google_, "K=L; domain=.bla.www.google.izzle")); | 286 cs.get(), this->url_google_, "K=L; domain=.bla.www.google.izzle")); |
285 this->MatchCookieLines("C=D; E=F; G=H", | 287 this->MatchCookieLines( |
286 this->GetCookies(cs, GURL("http://bla.www.google.izzle"))); | 288 "C=D; E=F; G=H", |
| 289 this->GetCookies(cs.get(), GURL("http://bla.www.google.izzle"))); |
287 this->MatchCookieLines("A=B; C=D; E=F; G=H", | 290 this->MatchCookieLines("A=B; C=D; E=F; G=H", |
288 this->GetCookies(cs, this->url_google_)); | 291 this->GetCookies(cs.get(), this->url_google_)); |
289 } | 292 } |
290 | 293 |
291 // FireFox recognizes domains containing trailing periods as valid. | 294 // FireFox recognizes domains containing trailing periods as valid. |
292 // IE and Safari do not. Assert the expected policy here. | 295 // IE and Safari do not. Assert the expected policy here. |
293 TYPED_TEST_P(CookieStoreTest, DomainWithTrailingDotTest) { | 296 TYPED_TEST_P(CookieStoreTest, DomainWithTrailingDotTest) { |
294 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 297 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
295 EXPECT_FALSE(this->SetCookie(cs, this->url_google_, | 298 EXPECT_FALSE(this->SetCookie( |
296 "a=1; domain=.www.google.com.")); | 299 cs.get(), this->url_google_, "a=1; domain=.www.google.com.")); |
297 EXPECT_FALSE(this->SetCookie(cs, this->url_google_, | 300 EXPECT_FALSE(this->SetCookie( |
298 "b=2; domain=.www.google.com..")); | 301 cs.get(), this->url_google_, "b=2; domain=.www.google.com..")); |
299 this->MatchCookieLines(std::string(), | 302 this->MatchCookieLines(std::string(), |
300 this->GetCookies(cs, this->url_google_)); | 303 this->GetCookies(cs.get(), this->url_google_)); |
301 } | 304 } |
302 | 305 |
303 // Test that cookies can bet set on higher level domains. | 306 // Test that cookies can bet set on higher level domains. |
304 // http://b/issue?id=896491 | 307 // http://b/issue?id=896491 |
305 TYPED_TEST_P(CookieStoreTest, ValidSubdomainTest) { | 308 TYPED_TEST_P(CookieStoreTest, ValidSubdomainTest) { |
306 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 309 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
307 GURL url_abcd("http://a.b.c.d.com"); | 310 GURL url_abcd("http://a.b.c.d.com"); |
308 GURL url_bcd("http://b.c.d.com"); | 311 GURL url_bcd("http://b.c.d.com"); |
309 GURL url_cd("http://c.d.com"); | 312 GURL url_cd("http://c.d.com"); |
310 GURL url_d("http://d.com"); | 313 GURL url_d("http://d.com"); |
311 | 314 |
312 EXPECT_TRUE(this->SetCookie(cs, url_abcd, "a=1; domain=.a.b.c.d.com")); | 315 EXPECT_TRUE(this->SetCookie(cs.get(), url_abcd, "a=1; domain=.a.b.c.d.com")); |
313 EXPECT_TRUE(this->SetCookie(cs, url_abcd, "b=2; domain=.b.c.d.com")); | 316 EXPECT_TRUE(this->SetCookie(cs.get(), url_abcd, "b=2; domain=.b.c.d.com")); |
314 EXPECT_TRUE(this->SetCookie(cs, url_abcd, "c=3; domain=.c.d.com")); | 317 EXPECT_TRUE(this->SetCookie(cs.get(), url_abcd, "c=3; domain=.c.d.com")); |
315 EXPECT_TRUE(this->SetCookie(cs, url_abcd, "d=4; domain=.d.com")); | 318 EXPECT_TRUE(this->SetCookie(cs.get(), url_abcd, "d=4; domain=.d.com")); |
316 | 319 |
317 this->MatchCookieLines("a=1; b=2; c=3; d=4", this->GetCookies(cs, url_abcd)); | 320 this->MatchCookieLines("a=1; b=2; c=3; d=4", |
318 this->MatchCookieLines("b=2; c=3; d=4", this->GetCookies(cs, url_bcd)); | 321 this->GetCookies(cs.get(), url_abcd)); |
319 this->MatchCookieLines("c=3; d=4", this->GetCookies(cs, url_cd)); | 322 this->MatchCookieLines("b=2; c=3; d=4", this->GetCookies(cs.get(), url_bcd)); |
320 this->MatchCookieLines("d=4", this->GetCookies(cs, url_d)); | 323 this->MatchCookieLines("c=3; d=4", this->GetCookies(cs.get(), url_cd)); |
| 324 this->MatchCookieLines("d=4", this->GetCookies(cs.get(), url_d)); |
321 | 325 |
322 // Check that the same cookie can exist on different sub-domains. | 326 // Check that the same cookie can exist on different sub-domains. |
323 EXPECT_TRUE(this->SetCookie(cs, url_bcd, "X=bcd; domain=.b.c.d.com")); | 327 EXPECT_TRUE(this->SetCookie(cs.get(), url_bcd, "X=bcd; domain=.b.c.d.com")); |
324 EXPECT_TRUE(this->SetCookie(cs, url_bcd, "X=cd; domain=.c.d.com")); | 328 EXPECT_TRUE(this->SetCookie(cs.get(), url_bcd, "X=cd; domain=.c.d.com")); |
325 this->MatchCookieLines("b=2; c=3; d=4; X=bcd; X=cd", | 329 this->MatchCookieLines("b=2; c=3; d=4; X=bcd; X=cd", |
326 this->GetCookies(cs, url_bcd)); | 330 this->GetCookies(cs.get(), url_bcd)); |
327 this->MatchCookieLines("c=3; d=4; X=cd", this->GetCookies(cs, url_cd)); | 331 this->MatchCookieLines("c=3; d=4; X=cd", this->GetCookies(cs.get(), url_cd)); |
328 } | 332 } |
329 | 333 |
330 // Test that setting a cookie which specifies an invalid domain has | 334 // Test that setting a cookie which specifies an invalid domain has |
331 // no side-effect. An invalid domain in this context is one which does | 335 // no side-effect. An invalid domain in this context is one which does |
332 // not match the originating domain. | 336 // not match the originating domain. |
333 // http://b/issue?id=896472 | 337 // http://b/issue?id=896472 |
334 TYPED_TEST_P(CookieStoreTest, InvalidDomainTest) { | 338 TYPED_TEST_P(CookieStoreTest, InvalidDomainTest) { |
335 { | 339 { |
336 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 340 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
337 GURL url_foobar("http://foo.bar.com"); | 341 GURL url_foobar("http://foo.bar.com"); |
338 | 342 |
339 // More specific sub-domain than allowed. | 343 // More specific sub-domain than allowed. |
340 EXPECT_FALSE(this->SetCookie(cs, url_foobar, | 344 EXPECT_FALSE( |
341 "a=1; domain=.yo.foo.bar.com")); | 345 this->SetCookie(cs.get(), url_foobar, "a=1; domain=.yo.foo.bar.com")); |
342 | 346 |
343 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "b=2; domain=.foo.com")); | 347 EXPECT_FALSE(this->SetCookie(cs.get(), url_foobar, "b=2; domain=.foo.com")); |
344 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "c=3; domain=.bar.foo.com")); | 348 EXPECT_FALSE( |
| 349 this->SetCookie(cs.get(), url_foobar, "c=3; domain=.bar.foo.com")); |
345 | 350 |
346 // Different TLD, but the rest is a substring. | 351 // Different TLD, but the rest is a substring. |
347 EXPECT_FALSE(this->SetCookie(cs, url_foobar, | 352 EXPECT_FALSE( |
348 "d=4; domain=.foo.bar.com.net")); | 353 this->SetCookie(cs.get(), url_foobar, "d=4; domain=.foo.bar.com.net")); |
349 | 354 |
350 // A substring that isn't really a parent domain. | 355 // A substring that isn't really a parent domain. |
351 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "e=5; domain=ar.com")); | 356 EXPECT_FALSE(this->SetCookie(cs.get(), url_foobar, "e=5; domain=ar.com")); |
352 | 357 |
353 // Completely invalid domains: | 358 // Completely invalid domains: |
354 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "f=6; domain=.")); | 359 EXPECT_FALSE(this->SetCookie(cs.get(), url_foobar, "f=6; domain=.")); |
355 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "g=7; domain=/")); | 360 EXPECT_FALSE(this->SetCookie(cs.get(), url_foobar, "g=7; domain=/")); |
356 EXPECT_FALSE(this->SetCookie(cs, url_foobar, | 361 EXPECT_FALSE(this->SetCookie( |
357 "h=8; domain=http://foo.bar.com")); | 362 cs.get(), url_foobar, "h=8; domain=http://foo.bar.com")); |
358 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "i=9; domain=..foo.bar.com")); | 363 EXPECT_FALSE( |
359 EXPECT_FALSE(this->SetCookie(cs, url_foobar, "j=10; domain=..bar.com")); | 364 this->SetCookie(cs.get(), url_foobar, "i=9; domain=..foo.bar.com")); |
| 365 EXPECT_FALSE( |
| 366 this->SetCookie(cs.get(), url_foobar, "j=10; domain=..bar.com")); |
360 | 367 |
361 // Make sure there isn't something quirky in the domain canonicalization | 368 // Make sure there isn't something quirky in the domain canonicalization |
362 // that supports full URL semantics. | 369 // that supports full URL semantics. |
363 EXPECT_FALSE(this->SetCookie(cs, url_foobar, | 370 EXPECT_FALSE(this->SetCookie( |
364 "k=11; domain=.foo.bar.com?blah")); | 371 cs.get(), url_foobar, "k=11; domain=.foo.bar.com?blah")); |
365 EXPECT_FALSE(this->SetCookie(cs, url_foobar, | 372 EXPECT_FALSE(this->SetCookie( |
366 "l=12; domain=.foo.bar.com/blah")); | 373 cs.get(), url_foobar, "l=12; domain=.foo.bar.com/blah")); |
367 EXPECT_FALSE(this->SetCookie(cs, url_foobar, | 374 EXPECT_FALSE( |
368 "m=13; domain=.foo.bar.com:80")); | 375 this->SetCookie(cs.get(), url_foobar, "m=13; domain=.foo.bar.com:80")); |
369 EXPECT_FALSE(this->SetCookie(cs, url_foobar, | 376 EXPECT_FALSE( |
370 "n=14; domain=.foo.bar.com:")); | 377 this->SetCookie(cs.get(), url_foobar, "n=14; domain=.foo.bar.com:")); |
371 EXPECT_FALSE(this->SetCookie(cs, url_foobar, | 378 EXPECT_FALSE( |
372 "o=15; domain=.foo.bar.com#sup")); | 379 this->SetCookie(cs.get(), url_foobar, "o=15; domain=.foo.bar.com#sup")); |
373 | 380 |
374 this->MatchCookieLines(std::string(), this->GetCookies(cs, url_foobar)); | 381 this->MatchCookieLines(std::string(), |
| 382 this->GetCookies(cs.get(), url_foobar)); |
375 } | 383 } |
376 | 384 |
377 { | 385 { |
378 // Make sure the cookie code hasn't gotten its subdomain string handling | 386 // Make sure the cookie code hasn't gotten its subdomain string handling |
379 // reversed, missed a suffix check, etc. It's important here that the two | 387 // reversed, missed a suffix check, etc. It's important here that the two |
380 // hosts below have the same domain + registry. | 388 // hosts below have the same domain + registry. |
381 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 389 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
382 GURL url_foocom("http://foo.com.com"); | 390 GURL url_foocom("http://foo.com.com"); |
383 EXPECT_FALSE(this->SetCookie(cs, url_foocom, | 391 EXPECT_FALSE( |
384 "a=1; domain=.foo.com.com.com")); | 392 this->SetCookie(cs.get(), url_foocom, "a=1; domain=.foo.com.com.com")); |
385 this->MatchCookieLines(std::string(), this->GetCookies(cs, url_foocom)); | 393 this->MatchCookieLines(std::string(), |
| 394 this->GetCookies(cs.get(), url_foocom)); |
386 } | 395 } |
387 } | 396 } |
388 | 397 |
389 // Test the behavior of omitting dot prefix from domain, should | 398 // Test the behavior of omitting dot prefix from domain, should |
390 // function the same as FireFox. | 399 // function the same as FireFox. |
391 // http://b/issue?id=889898 | 400 // http://b/issue?id=889898 |
392 TYPED_TEST_P(CookieStoreTest, DomainWithoutLeadingDotTest) { | 401 TYPED_TEST_P(CookieStoreTest, DomainWithoutLeadingDotTest) { |
393 { // The omission of dot results in setting a domain cookie. | 402 { // The omission of dot results in setting a domain cookie. |
394 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 403 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
395 GURL url_hosted("http://manage.hosted.filefront.com"); | 404 GURL url_hosted("http://manage.hosted.filefront.com"); |
396 GURL url_filefront("http://www.filefront.com"); | 405 GURL url_filefront("http://www.filefront.com"); |
397 EXPECT_TRUE(this->SetCookie(cs, url_hosted, | 406 EXPECT_TRUE( |
398 "sawAd=1; domain=filefront.com")); | 407 this->SetCookie(cs.get(), url_hosted, "sawAd=1; domain=filefront.com")); |
399 this->MatchCookieLines("sawAd=1", this->GetCookies(cs, url_hosted)); | 408 this->MatchCookieLines("sawAd=1", this->GetCookies(cs.get(), url_hosted)); |
400 this->MatchCookieLines("sawAd=1", this->GetCookies(cs, url_filefront)); | 409 this->MatchCookieLines("sawAd=1", |
| 410 this->GetCookies(cs.get(), url_filefront)); |
401 } | 411 } |
402 | 412 |
403 { // Even when the domains match exactly, don't consider it host cookie. | 413 { // Even when the domains match exactly, don't consider it host cookie. |
404 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 414 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
405 GURL url("http://www.google.com"); | 415 GURL url("http://www.google.com"); |
406 EXPECT_TRUE(this->SetCookie(cs, url, "a=1; domain=www.google.com")); | 416 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1; domain=www.google.com")); |
407 this->MatchCookieLines("a=1", this->GetCookies(cs, url)); | 417 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); |
408 this->MatchCookieLines("a=1", | |
409 this->GetCookies(cs, GURL("http://sub.www.google.com"))); | |
410 this->MatchCookieLines( | 418 this->MatchCookieLines( |
411 std::string(), this->GetCookies(cs, GURL("http://something-else.com"))); | 419 "a=1", this->GetCookies(cs.get(), GURL("http://sub.www.google.com"))); |
| 420 this->MatchCookieLines( |
| 421 std::string(), |
| 422 this->GetCookies(cs.get(), GURL("http://something-else.com"))); |
412 } | 423 } |
413 } | 424 } |
414 | 425 |
415 // Test that the domain specified in cookie string is treated case-insensitive | 426 // Test that the domain specified in cookie string is treated case-insensitive |
416 // http://b/issue?id=896475. | 427 // http://b/issue?id=896475. |
417 TYPED_TEST_P(CookieStoreTest, CaseInsensitiveDomainTest) { | 428 TYPED_TEST_P(CookieStoreTest, CaseInsensitiveDomainTest) { |
418 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 429 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
419 GURL url("http://www.google.com"); | 430 GURL url("http://www.google.com"); |
420 EXPECT_TRUE(this->SetCookie(cs, url, "a=1; domain=.GOOGLE.COM")); | 431 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1; domain=.GOOGLE.COM")); |
421 EXPECT_TRUE(this->SetCookie(cs, url, "b=2; domain=.wWw.gOOgLE.coM")); | 432 EXPECT_TRUE(this->SetCookie(cs.get(), url, "b=2; domain=.wWw.gOOgLE.coM")); |
422 this->MatchCookieLines("a=1; b=2", this->GetCookies(cs, url)); | 433 this->MatchCookieLines("a=1; b=2", this->GetCookies(cs.get(), url)); |
423 } | 434 } |
424 | 435 |
425 TYPED_TEST_P(CookieStoreTest, TestIpAddress) { | 436 TYPED_TEST_P(CookieStoreTest, TestIpAddress) { |
426 GURL url_ip("http://1.2.3.4/weee"); | 437 GURL url_ip("http://1.2.3.4/weee"); |
427 { | 438 { |
428 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 439 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
429 EXPECT_TRUE(this->SetCookie(cs, url_ip, kValidCookieLine)); | 440 EXPECT_TRUE(this->SetCookie(cs.get(), url_ip, kValidCookieLine)); |
430 this->MatchCookieLines("A=B", this->GetCookies(cs, url_ip)); | 441 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), url_ip)); |
431 } | 442 } |
432 | 443 |
433 { // IP addresses should not be able to set domain cookies. | 444 { // IP addresses should not be able to set domain cookies. |
434 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 445 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
435 EXPECT_FALSE(this->SetCookie(cs, url_ip, "b=2; domain=.1.2.3.4")); | 446 EXPECT_FALSE(this->SetCookie(cs.get(), url_ip, "b=2; domain=.1.2.3.4")); |
436 EXPECT_FALSE(this->SetCookie(cs, url_ip, "c=3; domain=.3.4")); | 447 EXPECT_FALSE(this->SetCookie(cs.get(), url_ip, "c=3; domain=.3.4")); |
437 this->MatchCookieLines(std::string(), this->GetCookies(cs, url_ip)); | 448 this->MatchCookieLines(std::string(), this->GetCookies(cs.get(), url_ip)); |
438 // It should be allowed to set a cookie if domain= matches the IP address | 449 // It should be allowed to set a cookie if domain= matches the IP address |
439 // exactly. This matches IE/Firefox, even though it seems a bit wrong. | 450 // exactly. This matches IE/Firefox, even though it seems a bit wrong. |
440 EXPECT_FALSE(this->SetCookie(cs, url_ip, "b=2; domain=1.2.3.3")); | 451 EXPECT_FALSE(this->SetCookie(cs.get(), url_ip, "b=2; domain=1.2.3.3")); |
441 this->MatchCookieLines(std::string(), this->GetCookies(cs, url_ip)); | 452 this->MatchCookieLines(std::string(), this->GetCookies(cs.get(), url_ip)); |
442 EXPECT_TRUE(this->SetCookie(cs, url_ip, "b=2; domain=1.2.3.4")); | 453 EXPECT_TRUE(this->SetCookie(cs.get(), url_ip, "b=2; domain=1.2.3.4")); |
443 this->MatchCookieLines("b=2", this->GetCookies(cs, url_ip)); | 454 this->MatchCookieLines("b=2", this->GetCookies(cs.get(), url_ip)); |
444 } | 455 } |
445 } | 456 } |
446 | 457 |
447 // Test host cookies, and setting of cookies on TLD. | 458 // Test host cookies, and setting of cookies on TLD. |
448 TYPED_TEST_P(CookieStoreTest, TestNonDottedAndTLD) { | 459 TYPED_TEST_P(CookieStoreTest, TestNonDottedAndTLD) { |
449 { | 460 { |
450 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 461 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
451 GURL url("http://com/"); | 462 GURL url("http://com/"); |
452 // Allow setting on "com", (but only as a host cookie). | 463 // Allow setting on "com", (but only as a host cookie). |
453 EXPECT_TRUE(this->SetCookie(cs, url, "a=1")); | 464 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); |
454 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=.com")); | 465 EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=.com")); |
455 EXPECT_FALSE(this->SetCookie(cs, url, "c=3; domain=com")); | 466 EXPECT_FALSE(this->SetCookie(cs.get(), url, "c=3; domain=com")); |
456 this->MatchCookieLines("a=1", this->GetCookies(cs, url)); | 467 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); |
457 // Make sure it doesn't show up for a normal .com, it should be a host | 468 // Make sure it doesn't show up for a normal .com, it should be a host |
458 // not a domain cookie. | 469 // not a domain cookie. |
459 this->MatchCookieLines( | 470 this->MatchCookieLines( |
460 std::string(), | 471 std::string(), |
461 this->GetCookies(cs, GURL("http://hopefully-no-cookies.com/"))); | 472 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.com/"))); |
462 if (TypeParam::supports_non_dotted_domains) { | 473 if (TypeParam::supports_non_dotted_domains) { |
463 this->MatchCookieLines(std::string(), | 474 this->MatchCookieLines(std::string(), |
464 this->GetCookies(cs, GURL("http://.com/"))); | 475 this->GetCookies(cs.get(), GURL("http://.com/"))); |
465 } | 476 } |
466 } | 477 } |
467 | 478 |
468 { | 479 { |
469 // http://com. should be treated the same as http://com. | 480 // http://com. should be treated the same as http://com. |
470 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 481 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
471 GURL url("http://com./index.html"); | 482 GURL url("http://com./index.html"); |
472 if (TypeParam::supports_trailing_dots) { | 483 if (TypeParam::supports_trailing_dots) { |
473 EXPECT_TRUE(this->SetCookie(cs, url, "a=1")); | 484 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); |
474 this->MatchCookieLines("a=1", this->GetCookies(cs, url)); | 485 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); |
475 this->MatchCookieLines( | 486 this->MatchCookieLines( |
476 std::string(), | 487 std::string(), |
477 this->GetCookies(cs, GURL("http://hopefully-no-cookies.com./"))); | 488 this->GetCookies(cs.get(), |
| 489 GURL("http://hopefully-no-cookies.com./"))); |
478 } else { | 490 } else { |
479 EXPECT_FALSE(this->SetCookie(cs, url, "a=1")); | 491 EXPECT_FALSE(this->SetCookie(cs.get(), url, "a=1")); |
480 } | 492 } |
481 } | 493 } |
482 | 494 |
483 { // Should not be able to set host cookie from a subdomain. | 495 { // Should not be able to set host cookie from a subdomain. |
484 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 496 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
485 GURL url("http://a.b"); | 497 GURL url("http://a.b"); |
486 EXPECT_FALSE(this->SetCookie(cs, url, "a=1; domain=.b")); | 498 EXPECT_FALSE(this->SetCookie(cs.get(), url, "a=1; domain=.b")); |
487 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=b")); | 499 EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=b")); |
488 this->MatchCookieLines(std::string(), this->GetCookies(cs, url)); | 500 this->MatchCookieLines(std::string(), this->GetCookies(cs.get(), url)); |
489 } | 501 } |
490 | 502 |
491 { // Same test as above, but explicitly on a known TLD (com). | 503 { // Same test as above, but explicitly on a known TLD (com). |
492 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 504 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
493 GURL url("http://google.com"); | 505 GURL url("http://google.com"); |
494 EXPECT_FALSE(this->SetCookie(cs, url, "a=1; domain=.com")); | 506 EXPECT_FALSE(this->SetCookie(cs.get(), url, "a=1; domain=.com")); |
495 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=com")); | 507 EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=com")); |
496 this->MatchCookieLines(std::string(), this->GetCookies(cs, url)); | 508 this->MatchCookieLines(std::string(), this->GetCookies(cs.get(), url)); |
497 } | 509 } |
498 | 510 |
499 { // Make sure can't set cookie on TLD which is dotted. | 511 { // Make sure can't set cookie on TLD which is dotted. |
500 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 512 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
501 GURL url("http://google.co.uk"); | 513 GURL url("http://google.co.uk"); |
502 EXPECT_FALSE(this->SetCookie(cs, url, "a=1; domain=.co.uk")); | 514 EXPECT_FALSE(this->SetCookie(cs.get(), url, "a=1; domain=.co.uk")); |
503 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=.uk")); | 515 EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=.uk")); |
504 this->MatchCookieLines(std::string(), this->GetCookies(cs, url)); | 516 this->MatchCookieLines(std::string(), this->GetCookies(cs.get(), url)); |
505 this->MatchCookieLines( | 517 this->MatchCookieLines( |
506 std::string(), | 518 std::string(), |
507 this->GetCookies(cs, GURL("http://something-else.co.uk"))); | 519 this->GetCookies(cs.get(), GURL("http://something-else.co.uk"))); |
508 this->MatchCookieLines( | 520 this->MatchCookieLines( |
509 std::string(), this->GetCookies(cs, GURL("http://something-else.uk"))); | 521 std::string(), |
| 522 this->GetCookies(cs.get(), GURL("http://something-else.uk"))); |
510 } | 523 } |
511 | 524 |
512 { // Intranet URLs should only be able to set host cookies. | 525 { // Intranet URLs should only be able to set host cookies. |
513 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 526 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
514 GURL url("http://b"); | 527 GURL url("http://b"); |
515 EXPECT_TRUE(this->SetCookie(cs, url, "a=1")); | 528 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); |
516 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=.b")); | 529 EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=.b")); |
517 EXPECT_FALSE(this->SetCookie(cs, url, "c=3; domain=b")); | 530 EXPECT_FALSE(this->SetCookie(cs.get(), url, "c=3; domain=b")); |
518 this->MatchCookieLines("a=1", this->GetCookies(cs, url)); | 531 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); |
519 } | 532 } |
520 } | 533 } |
521 | 534 |
522 // Test reading/writing cookies when the domain ends with a period, | 535 // Test reading/writing cookies when the domain ends with a period, |
523 // as in "www.google.com." | 536 // as in "www.google.com." |
524 TYPED_TEST_P(CookieStoreTest, TestHostEndsWithDot) { | 537 TYPED_TEST_P(CookieStoreTest, TestHostEndsWithDot) { |
525 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 538 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
526 GURL url("http://www.google.com"); | 539 GURL url("http://www.google.com"); |
527 GURL url_with_dot("http://www.google.com."); | 540 GURL url_with_dot("http://www.google.com."); |
528 EXPECT_TRUE(this->SetCookie(cs, url, "a=1")); | 541 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); |
529 this->MatchCookieLines("a=1", this->GetCookies(cs, url)); | 542 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); |
530 | 543 |
531 if (TypeParam::supports_trailing_dots) { | 544 if (TypeParam::supports_trailing_dots) { |
532 // Do not share cookie space with the dot version of domain. | 545 // Do not share cookie space with the dot version of domain. |
533 // Note: this is not what FireFox does, but it _is_ what IE+Safari do. | 546 // Note: this is not what FireFox does, but it _is_ what IE+Safari do. |
534 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=.www.google.com.")); | 547 EXPECT_FALSE( |
535 this->MatchCookieLines("a=1", this->GetCookies(cs, url)); | 548 this->SetCookie(cs.get(), url, "b=2; domain=.www.google.com.")); |
| 549 this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); |
536 | 550 |
537 EXPECT_TRUE(this->SetCookie(cs, url_with_dot, "b=2; domain=.google.com.")); | 551 EXPECT_TRUE( |
538 this->MatchCookieLines("b=2", this->GetCookies(cs, url_with_dot)); | 552 this->SetCookie(cs.get(), url_with_dot, "b=2; domain=.google.com.")); |
| 553 this->MatchCookieLines("b=2", this->GetCookies(cs.get(), url_with_dot)); |
539 } else { | 554 } else { |
540 EXPECT_TRUE(this->SetCookie(cs, url, "b=2; domain=.www.google.com.")); | 555 EXPECT_TRUE(this->SetCookie(cs.get(), url, "b=2; domain=.www.google.com.")); |
541 EXPECT_FALSE(this->SetCookie(cs, url_with_dot, "b=2; domain=.google.com.")); | 556 EXPECT_FALSE( |
| 557 this->SetCookie(cs.get(), url_with_dot, "b=2; domain=.google.com.")); |
542 } | 558 } |
543 | 559 |
544 // Make sure there weren't any side effects. | 560 // Make sure there weren't any side effects. |
545 this->MatchCookieLines( | 561 this->MatchCookieLines( |
546 std::string(), | 562 std::string(), |
547 this->GetCookies(cs, GURL("http://hopefully-no-cookies.com/"))); | 563 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.com/"))); |
548 this->MatchCookieLines(std::string(), | 564 this->MatchCookieLines(std::string(), |
549 this->GetCookies(cs, GURL("http://.com/"))); | 565 this->GetCookies(cs.get(), GURL("http://.com/"))); |
550 } | 566 } |
551 | 567 |
552 TYPED_TEST_P(CookieStoreTest, InvalidScheme) { | 568 TYPED_TEST_P(CookieStoreTest, InvalidScheme) { |
553 if (!TypeParam::filters_schemes) | 569 if (!TypeParam::filters_schemes) |
554 return; | 570 return; |
555 | 571 |
556 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 572 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
557 EXPECT_FALSE(this->SetCookie(cs, GURL(kUrlFtp), kValidCookieLine)); | 573 EXPECT_FALSE(this->SetCookie(cs.get(), GURL(kUrlFtp), kValidCookieLine)); |
558 } | 574 } |
559 | 575 |
560 TYPED_TEST_P(CookieStoreTest, InvalidScheme_Read) { | 576 TYPED_TEST_P(CookieStoreTest, InvalidScheme_Read) { |
561 if (!TypeParam::filters_schemes) | 577 if (!TypeParam::filters_schemes) |
562 return; | 578 return; |
563 | 579 |
564 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 580 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
565 EXPECT_TRUE(this->SetCookie(cs, GURL(kUrlGoogle), kValidDomainCookieLine)); | 581 EXPECT_TRUE( |
566 this->MatchCookieLines(std::string(), this->GetCookies(cs, GURL(kUrlFtp))); | 582 this->SetCookie(cs.get(), GURL(kUrlGoogle), kValidDomainCookieLine)); |
| 583 this->MatchCookieLines(std::string(), |
| 584 this->GetCookies(cs.get(), GURL(kUrlFtp))); |
567 } | 585 } |
568 | 586 |
569 TYPED_TEST_P(CookieStoreTest, PathTest) { | 587 TYPED_TEST_P(CookieStoreTest, PathTest) { |
570 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 588 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
571 std::string url("http://www.google.izzle"); | 589 std::string url("http://www.google.izzle"); |
572 EXPECT_TRUE(this->SetCookie(cs, GURL(url), "A=B; path=/wee")); | 590 EXPECT_TRUE(this->SetCookie(cs.get(), GURL(url), "A=B; path=/wee")); |
573 this->MatchCookieLines("A=B", this->GetCookies(cs, GURL(url + "/wee"))); | 591 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), GURL(url + "/wee"))); |
574 this->MatchCookieLines("A=B", this->GetCookies(cs, GURL(url + "/wee/"))); | |
575 this->MatchCookieLines("A=B", this->GetCookies(cs, GURL(url + "/wee/war"))); | |
576 this->MatchCookieLines("A=B", | 592 this->MatchCookieLines("A=B", |
577 this->GetCookies(cs, GURL(url + "/wee/war/more/more"))); | 593 this->GetCookies(cs.get(), GURL(url + "/wee/"))); |
| 594 this->MatchCookieLines("A=B", |
| 595 this->GetCookies(cs.get(), GURL(url + "/wee/war"))); |
| 596 this->MatchCookieLines( |
| 597 "A=B", this->GetCookies(cs.get(), GURL(url + "/wee/war/more/more"))); |
578 if (!TypeParam::has_path_prefix_bug) | 598 if (!TypeParam::has_path_prefix_bug) |
579 this->MatchCookieLines(std::string(), | 599 this->MatchCookieLines(std::string(), |
580 this->GetCookies(cs, GURL(url + "/weehee"))); | 600 this->GetCookies(cs.get(), GURL(url + "/weehee"))); |
581 this->MatchCookieLines(std::string(), this->GetCookies(cs, GURL(url + "/"))); | 601 this->MatchCookieLines(std::string(), |
| 602 this->GetCookies(cs.get(), GURL(url + "/"))); |
582 | 603 |
583 // If we add a 0 length path, it should default to / | 604 // If we add a 0 length path, it should default to / |
584 EXPECT_TRUE(this->SetCookie(cs, GURL(url), "A=C; path=")); | 605 EXPECT_TRUE(this->SetCookie(cs.get(), GURL(url), "A=C; path=")); |
585 this->MatchCookieLines("A=B; A=C", this->GetCookies(cs, GURL(url + "/wee"))); | 606 this->MatchCookieLines("A=B; A=C", |
586 this->MatchCookieLines("A=C", this->GetCookies(cs, GURL(url + "/"))); | 607 this->GetCookies(cs.get(), GURL(url + "/wee"))); |
| 608 this->MatchCookieLines("A=C", this->GetCookies(cs.get(), GURL(url + "/"))); |
587 } | 609 } |
588 | 610 |
589 TYPED_TEST_P(CookieStoreTest, EmptyExpires) { | 611 TYPED_TEST_P(CookieStoreTest, EmptyExpires) { |
590 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 612 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
591 CookieOptions options; | 613 CookieOptions options; |
592 if (!TypeParam::supports_http_only) | 614 if (!TypeParam::supports_http_only) |
593 options.set_include_httponly(); | 615 options.set_include_httponly(); |
594 GURL url("http://www7.ipdl.inpit.go.jp/Tokujitu/tjkta.ipdl?N0000=108"); | 616 GURL url("http://www7.ipdl.inpit.go.jp/Tokujitu/tjkta.ipdl?N0000=108"); |
595 std::string set_cookie_line = | 617 std::string set_cookie_line = |
596 "ACSTM=20130308043820420042; path=/; domain=ipdl.inpit.go.jp; Expires="; | 618 "ACSTM=20130308043820420042; path=/; domain=ipdl.inpit.go.jp; Expires="; |
597 std::string cookie_line = "ACSTM=20130308043820420042"; | 619 std::string cookie_line = "ACSTM=20130308043820420042"; |
598 | 620 |
599 this->SetCookieWithOptions( cs, url, set_cookie_line, options); | 621 this->SetCookieWithOptions(cs.get(), url, set_cookie_line, options); |
600 this->MatchCookieLines(cookie_line, | 622 this->MatchCookieLines(cookie_line, |
601 this->GetCookiesWithOptions(cs, url, options)); | 623 this->GetCookiesWithOptions(cs.get(), url, options)); |
602 | 624 |
603 options.set_server_time(base::Time::Now() - base::TimeDelta::FromHours(1)); | 625 options.set_server_time(base::Time::Now() - base::TimeDelta::FromHours(1)); |
604 this->SetCookieWithOptions( cs, url, set_cookie_line, options); | 626 this->SetCookieWithOptions(cs.get(), url, set_cookie_line, options); |
605 this->MatchCookieLines(cookie_line, | 627 this->MatchCookieLines(cookie_line, |
606 this->GetCookiesWithOptions(cs, url, options)); | 628 this->GetCookiesWithOptions(cs.get(), url, options)); |
607 | 629 |
608 options.set_server_time(base::Time::Now() + base::TimeDelta::FromHours(1)); | 630 options.set_server_time(base::Time::Now() + base::TimeDelta::FromHours(1)); |
609 this->SetCookieWithOptions( cs, url, set_cookie_line, options); | 631 this->SetCookieWithOptions(cs.get(), url, set_cookie_line, options); |
610 this->MatchCookieLines(cookie_line, | 632 this->MatchCookieLines(cookie_line, |
611 this->GetCookiesWithOptions(cs, url, options)); | 633 this->GetCookiesWithOptions(cs.get(), url, options)); |
612 } | 634 } |
613 | 635 |
614 TYPED_TEST_P(CookieStoreTest, HttpOnlyTest) { | 636 TYPED_TEST_P(CookieStoreTest, HttpOnlyTest) { |
615 if (!TypeParam::supports_http_only) | 637 if (!TypeParam::supports_http_only) |
616 return; | 638 return; |
617 | 639 |
618 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 640 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
619 CookieOptions options; | 641 CookieOptions options; |
620 options.set_include_httponly(); | 642 options.set_include_httponly(); |
621 | 643 |
622 // Create a httponly cookie. | 644 // Create a httponly cookie. |
623 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->url_google_, "A=B; httponly", | 645 EXPECT_TRUE(this->SetCookieWithOptions( |
624 options)); | 646 cs.get(), this->url_google_, "A=B; httponly", options)); |
625 | 647 |
626 // Check httponly read protection. | 648 // Check httponly read protection. |
627 this->MatchCookieLines(std::string(), | 649 this->MatchCookieLines(std::string(), |
628 this->GetCookies(cs, this->url_google_)); | 650 this->GetCookies(cs.get(), this->url_google_)); |
629 this->MatchCookieLines( | 651 this->MatchCookieLines( |
630 "A=B", this->GetCookiesWithOptions(cs, this->url_google_, options)); | 652 "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options)); |
631 | 653 |
632 // Check httponly overwrite protection. | 654 // Check httponly overwrite protection. |
633 EXPECT_FALSE(this->SetCookie(cs, this->url_google_, "A=C")); | 655 EXPECT_FALSE(this->SetCookie(cs.get(), this->url_google_, "A=C")); |
634 this->MatchCookieLines(std::string(), | 656 this->MatchCookieLines(std::string(), |
635 this->GetCookies(cs, this->url_google_)); | 657 this->GetCookies(cs.get(), this->url_google_)); |
636 this->MatchCookieLines( | 658 this->MatchCookieLines( |
637 "A=B", this->GetCookiesWithOptions(cs, this->url_google_, options)); | 659 "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options)); |
638 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->url_google_, "A=C", | 660 EXPECT_TRUE( |
639 options)); | 661 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=C", options)); |
640 this->MatchCookieLines("A=C", this->GetCookies(cs, this->url_google_)); | 662 this->MatchCookieLines("A=C", this->GetCookies(cs.get(), this->url_google_)); |
641 | 663 |
642 // Check httponly create protection. | 664 // Check httponly create protection. |
643 EXPECT_FALSE(this->SetCookie(cs, this->url_google_, "B=A; httponly")); | 665 EXPECT_FALSE(this->SetCookie(cs.get(), this->url_google_, "B=A; httponly")); |
644 this->MatchCookieLines("A=C", | 666 this->MatchCookieLines( |
645 this->GetCookiesWithOptions(cs, this->url_google_, options)); | 667 "A=C", this->GetCookiesWithOptions(cs.get(), this->url_google_, options)); |
646 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->url_google_, "B=A; httponly", | 668 EXPECT_TRUE(this->SetCookieWithOptions( |
647 options)); | 669 cs.get(), this->url_google_, "B=A; httponly", options)); |
648 this->MatchCookieLines("A=C; B=A", | 670 this->MatchCookieLines( |
649 this->GetCookiesWithOptions(cs, this->url_google_, options)); | 671 "A=C; B=A", |
650 this->MatchCookieLines("A=C", this->GetCookies(cs, this->url_google_)); | 672 this->GetCookiesWithOptions(cs.get(), this->url_google_, options)); |
| 673 this->MatchCookieLines("A=C", this->GetCookies(cs.get(), this->url_google_)); |
651 } | 674 } |
652 | 675 |
653 TYPED_TEST_P(CookieStoreTest, TestCookieDeletion) { | 676 TYPED_TEST_P(CookieStoreTest, TestCookieDeletion) { |
654 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 677 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
655 | 678 |
656 // Create a session cookie. | 679 // Create a session cookie. |
657 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, kValidCookieLine)); | 680 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, kValidCookieLine)); |
658 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); | 681 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); |
659 // Delete it via Max-Age. | 682 // Delete it via Max-Age. |
660 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | 683 EXPECT_TRUE(this->SetCookie(cs.get(), |
| 684 this->url_google_, |
661 std::string(kValidCookieLine) + "; max-age=0")); | 685 std::string(kValidCookieLine) + "; max-age=0")); |
662 this->MatchCookieLineWithTimeout(cs, this->url_google_, std::string()); | 686 this->MatchCookieLineWithTimeout(cs.get(), this->url_google_, std::string()); |
663 | 687 |
664 // Create a session cookie. | 688 // Create a session cookie. |
665 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, kValidCookieLine)); | 689 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, kValidCookieLine)); |
666 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); | 690 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); |
667 // Delete it via Expires. | 691 // Delete it via Expires. |
668 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | 692 EXPECT_TRUE(this->SetCookie(cs.get(), |
| 693 this->url_google_, |
669 std::string(kValidCookieLine) + | 694 std::string(kValidCookieLine) + |
670 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); | 695 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); |
671 this->MatchCookieLines(std::string(), | 696 this->MatchCookieLines(std::string(), |
672 this->GetCookies(cs, this->url_google_)); | 697 this->GetCookies(cs.get(), this->url_google_)); |
673 | 698 |
674 // Create a persistent cookie. | 699 // Create a persistent cookie. |
675 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | 700 EXPECT_TRUE(this->SetCookie( |
676 std::string(kValidCookieLine) + | 701 cs.get(), |
677 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 702 this->url_google_, |
| 703 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
678 | 704 |
679 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); | 705 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); |
680 // Delete it via Max-Age. | 706 // Delete it via Max-Age. |
681 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | 707 EXPECT_TRUE(this->SetCookie(cs.get(), |
| 708 this->url_google_, |
682 std::string(kValidCookieLine) + "; max-age=0")); | 709 std::string(kValidCookieLine) + "; max-age=0")); |
683 this->MatchCookieLineWithTimeout(cs, this->url_google_, std::string()); | 710 this->MatchCookieLineWithTimeout(cs.get(), this->url_google_, std::string()); |
684 | 711 |
685 // Create a persistent cookie. | 712 // Create a persistent cookie. |
686 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | 713 EXPECT_TRUE(this->SetCookie( |
| 714 cs.get(), |
| 715 this->url_google_, |
| 716 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 717 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); |
| 718 // Delete it via Expires. |
| 719 EXPECT_TRUE(this->SetCookie(cs.get(), |
| 720 this->url_google_, |
687 std::string(kValidCookieLine) + | 721 std::string(kValidCookieLine) + |
688 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 722 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); |
689 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); | |
690 // Delete it via Expires. | |
691 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | |
692 std::string(kValidCookieLine) + | |
693 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); | |
694 this->MatchCookieLines(std::string(), | 723 this->MatchCookieLines(std::string(), |
695 this->GetCookies(cs, this->url_google_)); | 724 this->GetCookies(cs.get(), this->url_google_)); |
696 | 725 |
697 // Create a persistent cookie. | 726 // Create a persistent cookie. |
698 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | 727 EXPECT_TRUE(this->SetCookie( |
699 std::string(kValidCookieLine) + | 728 cs.get(), |
700 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 729 this->url_google_, |
701 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); | 730 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 731 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); |
702 // Check that it is not deleted with significant enough clock skew. | 732 // Check that it is not deleted with significant enough clock skew. |
703 base::Time server_time; | 733 base::Time server_time; |
704 EXPECT_TRUE(base::Time::FromString("Sun, 17-Apr-1977 22:50:13 GMT", | 734 EXPECT_TRUE(base::Time::FromString("Sun, 17-Apr-1977 22:50:13 GMT", |
705 &server_time)); | 735 &server_time)); |
706 EXPECT_TRUE(this->SetCookieWithServerTime( | 736 EXPECT_TRUE(this->SetCookieWithServerTime( |
707 cs, this->url_google_, | 737 cs.get(), |
708 std::string(kValidCookieLine) + | 738 this->url_google_, |
709 "; expires=Mon, 18-Apr-1977 22:50:13 GMT", | 739 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT", |
710 server_time)); | 740 server_time)); |
711 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); | 741 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); |
712 | 742 |
713 // Create a persistent cookie. | 743 // Create a persistent cookie. |
714 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | 744 EXPECT_TRUE(this->SetCookie( |
| 745 cs.get(), |
| 746 this->url_google_, |
| 747 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 748 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); |
| 749 // Delete it via Expires, with a unix epoch of 0. |
| 750 EXPECT_TRUE(this->SetCookie(cs.get(), |
| 751 this->url_google_, |
715 std::string(kValidCookieLine) + | 752 std::string(kValidCookieLine) + |
716 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 753 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); |
717 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); | |
718 // Delete it via Expires, with a unix epoch of 0. | |
719 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | |
720 std::string(kValidCookieLine) + | |
721 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); | |
722 this->MatchCookieLines(std::string(), | 754 this->MatchCookieLines(std::string(), |
723 this->GetCookies(cs, this->url_google_)); | 755 this->GetCookies(cs.get(), this->url_google_)); |
724 } | 756 } |
725 | 757 |
726 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) { | 758 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) { |
727 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 759 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
728 const base::Time last_month = base::Time::Now() - | 760 const base::Time last_month = base::Time::Now() - |
729 base::TimeDelta::FromDays(30); | 761 base::TimeDelta::FromDays(30); |
730 const base::Time last_minute = base::Time::Now() - | 762 const base::Time last_minute = base::Time::Now() - |
731 base::TimeDelta::FromMinutes(1); | 763 base::TimeDelta::FromMinutes(1); |
732 const base::Time next_minute = base::Time::Now() + | 764 const base::Time next_minute = base::Time::Now() + |
733 base::TimeDelta::FromMinutes(1); | 765 base::TimeDelta::FromMinutes(1); |
734 const base::Time next_month = base::Time::Now() + | 766 const base::Time next_month = base::Time::Now() + |
735 base::TimeDelta::FromDays(30); | 767 base::TimeDelta::FromDays(30); |
736 | 768 |
737 // Add a cookie. | 769 // Add a cookie. |
738 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "A=B")); | 770 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); |
739 // Check that the cookie is in the store. | 771 // Check that the cookie is in the store. |
740 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); | 772 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); |
741 | 773 |
742 // Remove cookies in empty intervals. | 774 // Remove cookies in empty intervals. |
743 EXPECT_EQ(0, this->DeleteCreatedBetween(cs, last_month, last_minute)); | 775 EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), last_month, last_minute)); |
744 EXPECT_EQ(0, this->DeleteCreatedBetween(cs, next_minute, next_month)); | 776 EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), next_minute, next_month)); |
745 // Check that the cookie is still there. | 777 // Check that the cookie is still there. |
746 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); | 778 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); |
747 | 779 |
748 // Remove the cookie with an interval defined by two dates. | 780 // Remove the cookie with an interval defined by two dates. |
749 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, next_minute)); | 781 EXPECT_EQ(1, this->DeleteCreatedBetween(cs.get(), last_minute, next_minute)); |
750 // Check that the cookie disappeared. | 782 // Check that the cookie disappeared. |
751 this->MatchCookieLines(std::string(), | 783 this->MatchCookieLines(std::string(), |
752 this->GetCookies(cs, this->url_google_)); | 784 this->GetCookies(cs.get(), this->url_google_)); |
753 | 785 |
754 // Add another cookie. | 786 // Add another cookie. |
755 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "C=D")); | 787 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "C=D")); |
756 // Check that the cookie is in the store. | 788 // Check that the cookie is in the store. |
757 this->MatchCookieLines("C=D", this->GetCookies(cs, this->url_google_)); | 789 this->MatchCookieLines("C=D", this->GetCookies(cs.get(), this->url_google_)); |
758 | 790 |
759 // Remove the cookie with a null ending time. | 791 // Remove the cookie with a null ending time. |
760 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, base::Time())); | 792 EXPECT_EQ(1, this->DeleteCreatedBetween(cs.get(), last_minute, base::Time())); |
761 // Check that the cookie disappeared. | 793 // Check that the cookie disappeared. |
762 this->MatchCookieLines(std::string(), | 794 this->MatchCookieLines(std::string(), |
763 this->GetCookies(cs, this->url_google_)); | 795 this->GetCookies(cs.get(), this->url_google_)); |
764 } | 796 } |
765 | 797 |
766 TYPED_TEST_P(CookieStoreTest, TestSecure) { | 798 TYPED_TEST_P(CookieStoreTest, TestSecure) { |
767 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 799 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
768 | 800 |
769 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "A=B")); | 801 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); |
770 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); | 802 this->MatchCookieLines("A=B", |
771 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_secure_)); | 803 this->GetCookies(cs.get(), this->url_google_)); |
| 804 this->MatchCookieLines( |
| 805 "A=B", this->GetCookies(cs.get(), this->url_google_secure_)); |
772 | 806 |
773 EXPECT_TRUE(this->SetCookie(cs, this->url_google_secure_, "A=B; secure")); | 807 EXPECT_TRUE( |
| 808 this->SetCookie(cs.get(), this->url_google_secure_, "A=B; secure")); |
774 // The secure should overwrite the non-secure. | 809 // The secure should overwrite the non-secure. |
775 this->MatchCookieLines(std::string(), | 810 this->MatchCookieLines(std::string(), |
776 this->GetCookies(cs, this->url_google_)); | 811 this->GetCookies(cs.get(), this->url_google_)); |
777 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_secure_)); | 812 this->MatchCookieLines("A=B", |
| 813 this->GetCookies(cs.get(), this->url_google_secure_)); |
778 | 814 |
779 EXPECT_TRUE(this->SetCookie(cs, this->url_google_secure_, "D=E; secure")); | 815 EXPECT_TRUE( |
| 816 this->SetCookie(cs.get(), this->url_google_secure_, "D=E; secure")); |
780 this->MatchCookieLines(std::string(), | 817 this->MatchCookieLines(std::string(), |
781 this->GetCookies(cs, this->url_google_)); | 818 this->GetCookies(cs.get(), this->url_google_)); |
782 this->MatchCookieLines("A=B; D=E", | 819 this->MatchCookieLines("A=B; D=E", |
783 this->GetCookies(cs, this->url_google_secure_)); | 820 this->GetCookies(cs.get(), this->url_google_secure_)); |
784 | 821 |
785 EXPECT_TRUE(this->SetCookie(cs, this->url_google_secure_, "A=B")); | 822 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_secure_, "A=B")); |
786 // The non-secure should overwrite the secure. | 823 // The non-secure should overwrite the secure. |
787 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); | 824 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); |
788 this->MatchCookieLines("D=E; A=B", | 825 this->MatchCookieLines("D=E; A=B", |
789 this->GetCookies(cs, this->url_google_secure_)); | 826 this->GetCookies(cs.get(), this->url_google_secure_)); |
790 } | 827 } |
791 | 828 |
792 static const int kLastAccessThresholdMilliseconds = 200; | 829 static const int kLastAccessThresholdMilliseconds = 200; |
793 | 830 |
794 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling. | 831 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling. |
795 TYPED_TEST_P(CookieStoreTest, NetUtilCookieTest) { | 832 TYPED_TEST_P(CookieStoreTest, NetUtilCookieTest) { |
796 const GURL test_url("http://mojo.jojo.google.izzle/"); | 833 const GURL test_url("http://mojo.jojo.google.izzle/"); |
797 | 834 |
798 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 835 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
799 | 836 |
800 EXPECT_TRUE(this->SetCookie(cs, test_url, "foo=bar")); | 837 EXPECT_TRUE(this->SetCookie(cs.get(), test_url, "foo=bar")); |
801 std::string value = this->GetCookies(cs, test_url); | 838 std::string value = this->GetCookies(cs.get(), test_url); |
802 this->MatchCookieLines("foo=bar", value); | 839 this->MatchCookieLines("foo=bar", value); |
803 | 840 |
804 // test that we can retrieve all cookies: | 841 // test that we can retrieve all cookies: |
805 EXPECT_TRUE(this->SetCookie(cs, test_url, "x=1")); | 842 EXPECT_TRUE(this->SetCookie(cs.get(), test_url, "x=1")); |
806 EXPECT_TRUE(this->SetCookie(cs, test_url, "y=2")); | 843 EXPECT_TRUE(this->SetCookie(cs.get(), test_url, "y=2")); |
807 | 844 |
808 std::string result = this->GetCookies(cs, test_url); | 845 std::string result = this->GetCookies(cs.get(), test_url); |
809 EXPECT_FALSE(result.empty()); | 846 EXPECT_FALSE(result.empty()); |
810 EXPECT_NE(result.find("x=1"), std::string::npos) << result; | 847 EXPECT_NE(result.find("x=1"), std::string::npos) << result; |
811 EXPECT_NE(result.find("y=2"), std::string::npos) << result; | 848 EXPECT_NE(result.find("y=2"), std::string::npos) << result; |
812 } | 849 } |
813 | 850 |
814 TYPED_TEST_P(CookieStoreTest, OverwritePersistentCookie) { | 851 TYPED_TEST_P(CookieStoreTest, OverwritePersistentCookie) { |
815 GURL url_google("http://www.google.com/"); | 852 GURL url_google("http://www.google.com/"); |
816 GURL url_chromium("http://chromium.org"); | 853 GURL url_chromium("http://chromium.org"); |
817 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 854 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
818 | 855 |
819 // Insert a cookie "a" for path "/path1" | 856 // Insert a cookie "a" for path "/path1" |
820 EXPECT_TRUE( | 857 EXPECT_TRUE(this->SetCookie(cs.get(), |
821 this->SetCookie(cs, url_google, "a=val1; path=/path1; " | 858 url_google, |
822 "expires=Mon, 18-Apr-22 22:50:13 GMT")); | 859 "a=val1; path=/path1; " |
| 860 "expires=Mon, 18-Apr-22 22:50:13 GMT")); |
823 | 861 |
824 // Insert a cookie "b" for path "/path1" | 862 // Insert a cookie "b" for path "/path1" |
825 EXPECT_TRUE( | 863 EXPECT_TRUE(this->SetCookie(cs.get(), |
826 this->SetCookie(cs, url_google, "b=val1; path=/path1; " | 864 url_google, |
827 "expires=Mon, 18-Apr-22 22:50:14 GMT")); | 865 "b=val1; path=/path1; " |
| 866 "expires=Mon, 18-Apr-22 22:50:14 GMT")); |
828 | 867 |
829 // Insert a cookie "b" for path "/path1", that is httponly. This should | 868 // Insert a cookie "b" for path "/path1", that is httponly. This should |
830 // overwrite the non-http-only version. | 869 // overwrite the non-http-only version. |
831 CookieOptions allow_httponly; | 870 CookieOptions allow_httponly; |
832 allow_httponly.set_include_httponly(); | 871 allow_httponly.set_include_httponly(); |
833 EXPECT_TRUE( | 872 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), |
834 this->SetCookieWithOptions(cs, url_google, | 873 url_google, |
835 "b=val2; path=/path1; httponly; " | 874 "b=val2; path=/path1; httponly; " |
836 "expires=Mon, 18-Apr-22 22:50:14 GMT", | 875 "expires=Mon, 18-Apr-22 22:50:14 GMT", |
837 allow_httponly)); | 876 allow_httponly)); |
838 | 877 |
839 // Insert a cookie "a" for path "/path1". This should overwrite. | 878 // Insert a cookie "a" for path "/path1". This should overwrite. |
840 EXPECT_TRUE(this->SetCookie(cs, url_google, | 879 EXPECT_TRUE(this->SetCookie(cs.get(), |
| 880 url_google, |
841 "a=val33; path=/path1; " | 881 "a=val33; path=/path1; " |
842 "expires=Mon, 18-Apr-22 22:50:14 GMT")); | 882 "expires=Mon, 18-Apr-22 22:50:14 GMT")); |
843 | 883 |
844 // Insert a cookie "a" for path "/path2". This should NOT overwrite | 884 // Insert a cookie "a" for path "/path2". This should NOT overwrite |
845 // cookie "a", since the path is different. | 885 // cookie "a", since the path is different. |
846 EXPECT_TRUE(this->SetCookie(cs, url_google, | 886 EXPECT_TRUE(this->SetCookie(cs.get(), |
| 887 url_google, |
847 "a=val9; path=/path2; " | 888 "a=val9; path=/path2; " |
848 "expires=Mon, 18-Apr-22 22:50:14 GMT")); | 889 "expires=Mon, 18-Apr-22 22:50:14 GMT")); |
849 | 890 |
850 // Insert a cookie "a" for path "/path1", but this time for "chromium.org". | 891 // Insert a cookie "a" for path "/path1", but this time for "chromium.org". |
851 // Although the name and path match, the hostnames do not, so shouldn't | 892 // Although the name and path match, the hostnames do not, so shouldn't |
852 // overwrite. | 893 // overwrite. |
853 EXPECT_TRUE(this->SetCookie(cs, url_chromium, | 894 EXPECT_TRUE(this->SetCookie(cs.get(), |
| 895 url_chromium, |
854 "a=val99; path=/path1; " | 896 "a=val99; path=/path1; " |
855 "expires=Mon, 18-Apr-22 22:50:14 GMT")); | 897 "expires=Mon, 18-Apr-22 22:50:14 GMT")); |
856 | 898 |
857 if (TypeParam::supports_http_only) { | 899 if (TypeParam::supports_http_only) { |
858 this->MatchCookieLines("a=val33", | 900 this->MatchCookieLines( |
859 this->GetCookies(cs, GURL("http://www.google.com/path1"))); | 901 "a=val33", |
| 902 this->GetCookies(cs.get(), GURL("http://www.google.com/path1"))); |
860 } else { | 903 } else { |
861 this->MatchCookieLines("a=val33; b=val2", | 904 this->MatchCookieLines( |
862 this->GetCookies(cs, GURL("http://www.google.com/path1"))); | 905 "a=val33; b=val2", |
| 906 this->GetCookies(cs.get(), GURL("http://www.google.com/path1"))); |
863 } | 907 } |
864 this->MatchCookieLines("a=val9", | 908 this->MatchCookieLines( |
865 this->GetCookies(cs, GURL("http://www.google.com/path2"))); | 909 "a=val9", |
866 this->MatchCookieLines("a=val99", | 910 this->GetCookies(cs.get(), GURL("http://www.google.com/path2"))); |
867 this->GetCookies(cs, GURL("http://chromium.org/path1"))); | 911 this->MatchCookieLines( |
| 912 "a=val99", this->GetCookies(cs.get(), GURL("http://chromium.org/path1"))); |
868 } | 913 } |
869 | 914 |
870 TYPED_TEST_P(CookieStoreTest, CookieOrdering) { | 915 TYPED_TEST_P(CookieStoreTest, CookieOrdering) { |
871 // Put a random set of cookies into a store and make sure they're returned in | 916 // Put a random set of cookies into a store and make sure they're returned in |
872 // the right order. | 917 // the right order. |
873 // Cookies should be sorted by path length and creation time, as per RFC6265. | 918 // Cookies should be sorted by path length and creation time, as per RFC6265. |
874 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 919 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
875 EXPECT_TRUE(this->SetCookie(cs, GURL("http://d.c.b.a.google.com/aa/x.html"), | 920 EXPECT_TRUE(this->SetCookie( |
876 "c=1")); | 921 cs.get(), GURL("http://d.c.b.a.google.com/aa/x.html"), "c=1")); |
877 EXPECT_TRUE(this->SetCookie(cs, GURL("http://b.a.google.com/aa/bb/cc/x.html"), | 922 EXPECT_TRUE(this->SetCookie(cs.get(), |
| 923 GURL("http://b.a.google.com/aa/bb/cc/x.html"), |
878 "d=1; domain=b.a.google.com")); | 924 "d=1; domain=b.a.google.com")); |
879 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( | 925 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( |
880 TypeParam::creation_time_granularity_in_ms)); | 926 TypeParam::creation_time_granularity_in_ms)); |
881 EXPECT_TRUE(this->SetCookie(cs, GURL("http://b.a.google.com/aa/bb/cc/x.html"), | 927 EXPECT_TRUE(this->SetCookie(cs.get(), |
| 928 GURL("http://b.a.google.com/aa/bb/cc/x.html"), |
882 "a=4; domain=b.a.google.com")); | 929 "a=4; domain=b.a.google.com")); |
883 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( | 930 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( |
884 TypeParam::creation_time_granularity_in_ms)); | 931 TypeParam::creation_time_granularity_in_ms)); |
885 EXPECT_TRUE(this->SetCookie(cs, | 932 EXPECT_TRUE(this->SetCookie(cs.get(), |
886 GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), | 933 GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), |
887 "e=1; domain=c.b.a.google.com")); | 934 "e=1; domain=c.b.a.google.com")); |
888 EXPECT_TRUE(this->SetCookie(cs, | 935 EXPECT_TRUE(this->SetCookie( |
889 GURL("http://d.c.b.a.google.com/aa/bb/x.html"), | 936 cs.get(), GURL("http://d.c.b.a.google.com/aa/bb/x.html"), "b=1")); |
890 "b=1")); | 937 EXPECT_TRUE(this->SetCookie( |
891 EXPECT_TRUE(this->SetCookie(cs, GURL("http://news.bbc.co.uk/midpath/x.html"), | 938 cs.get(), GURL("http://news.bbc.co.uk/midpath/x.html"), "g=10")); |
892 "g=10")); | |
893 EXPECT_EQ("d=1; a=4; e=1; b=1; c=1", | 939 EXPECT_EQ("d=1; a=4; e=1; b=1; c=1", |
894 this->GetCookies(cs, GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"))); | 940 this->GetCookies(cs.get(), |
| 941 GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"))); |
895 } | 942 } |
896 | 943 |
897 TYPED_TEST_P(CookieStoreTest, DeleteSessionCookie) { | 944 TYPED_TEST_P(CookieStoreTest, DeleteSessionCookie) { |
898 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 945 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
899 // Create a session cookie and a persistent cookie. | 946 // Create a session cookie and a persistent cookie. |
900 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | 947 EXPECT_TRUE(this->SetCookie( |
901 std::string(kValidCookieLine))); | 948 cs.get(), this->url_google_, std::string(kValidCookieLine))); |
902 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | 949 EXPECT_TRUE(this->SetCookie(cs.get(), |
| 950 this->url_google_, |
903 "C=D; path=/; domain=google.izzle;" | 951 "C=D; path=/; domain=google.izzle;" |
904 "expires=Mon, 18-Apr-22 22:50:13 GMT")); | 952 "expires=Mon, 18-Apr-22 22:50:13 GMT")); |
905 this->MatchCookieLines("A=B; C=D", | 953 this->MatchCookieLines("A=B; C=D", |
906 this->GetCookies(cs, this->url_google_)); | 954 this->GetCookies(cs.get(), this->url_google_)); |
907 // Delete the session cookie. | 955 // Delete the session cookie. |
908 this->DeleteSessionCookies(cs); | 956 this->DeleteSessionCookies(cs.get()); |
909 // Check that the session cookie has been deleted but not the persistent one. | 957 // Check that the session cookie has been deleted but not the persistent one. |
910 EXPECT_EQ("C=D", this->GetCookies(cs, this->url_google_)); | 958 EXPECT_EQ("C=D", this->GetCookies(cs.get(), this->url_google_)); |
911 } | 959 } |
912 | 960 |
913 REGISTER_TYPED_TEST_CASE_P(CookieStoreTest, | 961 REGISTER_TYPED_TEST_CASE_P(CookieStoreTest, |
914 TypeTest, | 962 TypeTest, |
915 DomainTest, | 963 DomainTest, |
916 DomainWithTrailingDotTest, | 964 DomainWithTrailingDotTest, |
917 ValidSubdomainTest, | 965 ValidSubdomainTest, |
918 InvalidDomainTest, | 966 InvalidDomainTest, |
919 DomainWithoutLeadingDotTest, | 967 DomainWithoutLeadingDotTest, |
920 CaseInsensitiveDomainTest, | 968 CaseInsensitiveDomainTest, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 Thread other_thread_; | 1049 Thread other_thread_; |
1002 }; | 1050 }; |
1003 | 1051 |
1004 TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest); | 1052 TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest); |
1005 | 1053 |
1006 // TODO(ycxiao): Eventually, we will need to create a separate thread, create | 1054 // TODO(ycxiao): Eventually, we will need to create a separate thread, create |
1007 // the cookie store on that thread (or at least its store, i.e., the DB | 1055 // the cookie store on that thread (or at least its store, i.e., the DB |
1008 // thread). | 1056 // thread). |
1009 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookies) { | 1057 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookies) { |
1010 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 1058 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
1011 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "A=B")); | 1059 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); |
1012 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); | 1060 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); |
1013 StringResultCookieCallback callback(&this->other_thread_); | 1061 StringResultCookieCallback callback(&this->other_thread_); |
1014 base::Closure task = base::Bind( | 1062 base::Closure task = base::Bind( |
1015 &net::MultiThreadedCookieStoreTest<TypeParam>::GetCookiesTask, | 1063 &net::MultiThreadedCookieStoreTest<TypeParam>::GetCookiesTask, |
1016 base::Unretained(this), | 1064 base::Unretained(this), |
1017 cs, this->url_google_, &callback); | 1065 cs, this->url_google_, &callback); |
1018 this->RunOnOtherThread(task); | 1066 this->RunOnOtherThread(task); |
1019 EXPECT_TRUE(callback.did_run()); | 1067 EXPECT_TRUE(callback.did_run()); |
1020 EXPECT_EQ("A=B", callback.result()); | 1068 EXPECT_EQ("A=B", callback.result()); |
1021 } | 1069 } |
1022 | 1070 |
1023 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookiesWithOptions) { | 1071 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookiesWithOptions) { |
1024 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 1072 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
1025 CookieOptions options; | 1073 CookieOptions options; |
1026 if (!TypeParam::supports_http_only) | 1074 if (!TypeParam::supports_http_only) |
1027 options.set_include_httponly(); | 1075 options.set_include_httponly(); |
1028 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "A=B")); | 1076 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); |
1029 this->MatchCookieLines("A=B", | 1077 this->MatchCookieLines( |
1030 this->GetCookiesWithOptions(cs, this->url_google_, options)); | 1078 "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options)); |
1031 StringResultCookieCallback callback(&this->other_thread_); | 1079 StringResultCookieCallback callback(&this->other_thread_); |
1032 base::Closure task = base::Bind( | 1080 base::Closure task = base::Bind( |
1033 &net::MultiThreadedCookieStoreTest<TypeParam>::GetCookiesWithOptionsTask, | 1081 &net::MultiThreadedCookieStoreTest<TypeParam>::GetCookiesWithOptionsTask, |
1034 base::Unretained(this), | 1082 base::Unretained(this), |
1035 cs, this->url_google_, options, &callback); | 1083 cs, this->url_google_, options, &callback); |
1036 this->RunOnOtherThread(task); | 1084 this->RunOnOtherThread(task); |
1037 EXPECT_TRUE(callback.did_run()); | 1085 EXPECT_TRUE(callback.did_run()); |
1038 EXPECT_EQ("A=B", callback.result()); | 1086 EXPECT_EQ("A=B", callback.result()); |
1039 } | 1087 } |
1040 | 1088 |
1041 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckSetCookieWithOptions) { | 1089 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckSetCookieWithOptions) { |
1042 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 1090 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
1043 CookieOptions options; | 1091 CookieOptions options; |
1044 if (!TypeParam::supports_http_only) | 1092 if (!TypeParam::supports_http_only) |
1045 options.set_include_httponly(); | 1093 options.set_include_httponly(); |
1046 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->url_google_, "A=B", | 1094 EXPECT_TRUE( |
1047 options)); | 1095 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); |
1048 BoolResultCookieCallback callback(&this->other_thread_); | 1096 BoolResultCookieCallback callback(&this->other_thread_); |
1049 base::Closure task = base::Bind( | 1097 base::Closure task = base::Bind( |
1050 &net::MultiThreadedCookieStoreTest<TypeParam>::SetCookieWithOptionsTask, | 1098 &net::MultiThreadedCookieStoreTest<TypeParam>::SetCookieWithOptionsTask, |
1051 base::Unretained(this), | 1099 base::Unretained(this), |
1052 cs, this->url_google_, "A=B", options, &callback); | 1100 cs, this->url_google_, "A=B", options, &callback); |
1053 this->RunOnOtherThread(task); | 1101 this->RunOnOtherThread(task); |
1054 EXPECT_TRUE(callback.did_run()); | 1102 EXPECT_TRUE(callback.did_run()); |
1055 EXPECT_TRUE(callback.result()); | 1103 EXPECT_TRUE(callback.result()); |
1056 } | 1104 } |
1057 | 1105 |
1058 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteCookie) { | 1106 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteCookie) { |
1059 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 1107 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
1060 CookieOptions options; | 1108 CookieOptions options; |
1061 if (!TypeParam::supports_http_only) | 1109 if (!TypeParam::supports_http_only) |
1062 options.set_include_httponly(); | 1110 options.set_include_httponly(); |
1063 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->url_google_, "A=B", | 1111 EXPECT_TRUE( |
1064 options)); | 1112 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); |
1065 this->DeleteCookie(cs, this->url_google_, "A"); | 1113 this->DeleteCookie(cs.get(), this->url_google_, "A"); |
1066 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->url_google_, "A=B", | 1114 EXPECT_TRUE( |
1067 options)); | 1115 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); |
1068 NoResultCookieCallback callback(&this->other_thread_); | 1116 NoResultCookieCallback callback(&this->other_thread_); |
1069 base::Closure task = base::Bind( | 1117 base::Closure task = base::Bind( |
1070 &net::MultiThreadedCookieStoreTest<TypeParam>::DeleteCookieTask, | 1118 &net::MultiThreadedCookieStoreTest<TypeParam>::DeleteCookieTask, |
1071 base::Unretained(this), | 1119 base::Unretained(this), |
1072 cs, this->url_google_, "A", &callback); | 1120 cs, this->url_google_, "A", &callback); |
1073 this->RunOnOtherThread(task); | 1121 this->RunOnOtherThread(task); |
1074 EXPECT_TRUE(callback.did_run()); | 1122 EXPECT_TRUE(callback.did_run()); |
1075 } | 1123 } |
1076 | 1124 |
1077 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteSessionCookies) { | 1125 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteSessionCookies) { |
1078 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 1126 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
1079 CookieOptions options; | 1127 CookieOptions options; |
1080 if (!TypeParam::supports_http_only) | 1128 if (!TypeParam::supports_http_only) |
1081 options.set_include_httponly(); | 1129 options.set_include_httponly(); |
1082 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->url_google_, | 1130 EXPECT_TRUE( |
1083 "A=B", options)); | 1131 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); |
1084 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->url_google_, | 1132 EXPECT_TRUE( |
1085 "B=C; expires=Mon, 18-Apr-22 22:50:13 GMT", options)); | 1133 this->SetCookieWithOptions(cs.get(), |
1086 EXPECT_EQ(1, this->DeleteSessionCookies(cs)); | 1134 this->url_google_, |
1087 EXPECT_EQ(0, this->DeleteSessionCookies(cs)); | 1135 "B=C; expires=Mon, 18-Apr-22 22:50:13 GMT", |
1088 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->url_google_, | 1136 options)); |
1089 "A=B", options)); | 1137 EXPECT_EQ(1, this->DeleteSessionCookies(cs.get())); |
| 1138 EXPECT_EQ(0, this->DeleteSessionCookies(cs.get())); |
| 1139 EXPECT_TRUE( |
| 1140 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); |
1090 IntResultCookieCallback callback(&this->other_thread_); | 1141 IntResultCookieCallback callback(&this->other_thread_); |
1091 base::Closure task = base::Bind( | 1142 base::Closure task = base::Bind( |
1092 &net::MultiThreadedCookieStoreTest<TypeParam>::DeleteSessionCookiesTask, | 1143 &net::MultiThreadedCookieStoreTest<TypeParam>::DeleteSessionCookiesTask, |
1093 base::Unretained(this), | 1144 base::Unretained(this), |
1094 cs, &callback); | 1145 cs, &callback); |
1095 this->RunOnOtherThread(task); | 1146 this->RunOnOtherThread(task); |
1096 EXPECT_TRUE(callback.did_run()); | 1147 EXPECT_TRUE(callback.did_run()); |
1097 EXPECT_EQ(1, callback.result()); | 1148 EXPECT_EQ(1, callback.result()); |
1098 } | 1149 } |
1099 | 1150 |
1100 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, | 1151 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, |
1101 ThreadCheckGetCookies, | 1152 ThreadCheckGetCookies, |
1102 ThreadCheckGetCookiesWithOptions, | 1153 ThreadCheckGetCookiesWithOptions, |
1103 ThreadCheckSetCookieWithOptions, | 1154 ThreadCheckSetCookieWithOptions, |
1104 ThreadCheckDeleteCookie, | 1155 ThreadCheckDeleteCookie, |
1105 ThreadCheckDeleteSessionCookies); | 1156 ThreadCheckDeleteSessionCookies); |
1106 | 1157 |
1107 } // namespace net | 1158 } // namespace net |
1108 | 1159 |
1109 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 1160 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
OLD | NEW |